Salome HOME
Mesh should be set befor giving input fields
[tools/solverlab.git] / CoreFlows / examples / Python / SinglePhase / SinglePhase_2DWallHeatedChannel_ChangeSect.py
1 #!/usr/bin/env python
2 # -*-coding:utf-8 -*
3
4 import CoreFlows as cf
5 import cdmath as cm
6
7 def SinglePhase_2DWallHeatedChannel_ChangeSect():
8
9         #import themesh
10         print("Reading a mesh with sudden cross-section change for test SinglePhase_2DWallHeatedChannel_ChangeSect()")
11         M=cm.Mesh("../resources/VaryingSectionDuct.med")
12
13     # Prepare the mesh boundaries
14         xinf=0.0;
15         xsup=0.01;
16         yinf=0.0;
17         ysup=0.01;
18         eps=1.E-6;
19         M.setGroupAtPlan(xsup,0,eps,"Wall");
20         M.setGroupAtPlan(xinf,0,eps,"Wall");
21         M.setGroupAtPlan(yinf,1,eps,"Inlet");
22         M.setGroupAtPlan(ysup,1,eps,"Outlet");
23
24         #Nombre de cellules utilisees au depart dans Salome ou Alamos   
25         nx=60
26         ny=60
27         #taille d'une cellule
28         dx = (xsup-xinf)/nx
29         dy = (ysup-yinf)/ny;
30         for i in range(ny/2):
31                  M.setGroupAtFaceByCoords((xsup-xinf)/4,(ysup-yinf)/4+(i+0.5)*dy,0,eps,"Wall");#Paroi verticale intérieure gauche
32                  M.setGroupAtFaceByCoords((xsup-xinf)*3/4,(ysup-yinf)/4+(i+0.5)*dy,0,eps,"Wall");#Paroi verticale intérieure droitee
33         
34         for i in range(nx/4):
35                  M.setGroupAtFaceByCoords((i+0.5)*dx,(ysup-yinf)/4,0,eps,"Wall");#paroi horizontale en bas à gauche
36                  M.setGroupAtFaceByCoords((i+0.5)*dx,(ysup-yinf)*3/4,0,eps,"Wall");#paroi horizontale en haut à gauche
37                  M.setGroupAtFaceByCoords((xsup-xinf)*3/4+(i+0.5)*dx,(ysup-yinf)/4,0,eps,"Wall");#paroi horizontale en bas à droite
38                  M.setGroupAtFaceByCoords((xsup-xinf)*3/4+(i+0.5)*dx,(ysup-yinf)*3/4,0,eps,"Wall");#paroi horizontale en haut à droite
39
40         spaceDim = M.getSpaceDimension();
41
42     # set the limit field for each boundary
43         wallVelocityX=0;
44         wallVelocityY=0;
45         wallTemperature=623;
46         inletVelocityX=0;
47         inletVelocityY=2.5;
48         inletTemperature=563;
49         outletPressure=155e5;
50
51     # physical constants
52         viscosite=[8.85e-5]
53         conductivite=[1000]
54
55         myProblem = cf.SinglePhase(cf.Liquid,cf.around155bars600K,spaceDim);
56         nVar =myProblem.getNumberOfVariables();
57
58     # Prepare for the initial condition
59         VV_Constant =cm.Vector(nVar)
60
61         # constant vector
62         VV_Constant[0] = outletPressure ;
63         VV_Constant[1] = inletVelocityX;
64         VV_Constant[2] = inletVelocityY;
65         VV_Constant[3] = inletTemperature ;
66
67     #Initial field creation
68         print("Building mesh and initial data" );
69         myProblem.setInitialFieldConstant(M,VV_Constant);
70
71     # the boundary conditions
72         myProblem.setOutletBoundaryCondition("Outlet", outletPressure,[xsup,ysup]);
73         myProblem.setInletBoundaryCondition("Inlet", inletTemperature, inletVelocityX, inletVelocityY);
74         myProblem.setWallBoundaryCondition("Wall", wallTemperature, wallVelocityX, wallVelocityY);
75
76     # set physical parameters
77         myProblem.setViscosity(viscosite);
78         myProblem.setConductivity(conductivite);
79
80
81         # set the numerical method
82         myProblem.setNumericalScheme(cf.upwind, cf.Implicit);
83         myProblem.setLinearSolver(cf.GMRES,cf.ILU,True);
84     
85         # name file save
86         fileName = "2DWallHeatedChannel_ChangeSect";
87
88         # parameters calculation
89         MaxNbOfTimeStep = 3 ;
90         freqSave = 1;
91         cfl = 0.5;
92         maxTime = 5000;
93         precision = 1e-6;
94
95         myProblem.setCFL(cfl);
96         myProblem.setPrecision(precision);
97         myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep);
98         myProblem.setTimeMax(maxTime);
99         myProblem.setFreqSave(freqSave);
100         myProblem.setFileName(fileName);
101         myProblem.setNewtonSolver(float('inf'),20);#newton precision should be infinite for staggered scheme!!!
102         myProblem.saveConservativeField(True);
103         if(spaceDim>1):
104                 myProblem.saveVelocity();
105                 pass
106
107         # evolution
108         myProblem.initialize();
109
110         ok = myProblem.run();
111         if (ok):
112                 print( "Simulation python " + fileName + " is successful !" );
113                 pass
114         else:
115                 print( "Simulation python " + fileName + "  failed ! " );
116                 pass
117
118         print( "------------ End of calculation !!! -----------" );
119
120         myProblem.terminate();
121         return ok
122
123 if __name__ == """__main__""":
124     SinglePhase_2DWallHeatedChannel_ChangeSect()