Salome HOME
initial project version
[tools/solverlab.git] / CoreFlows / examples / Python / FiveEqsTwoFluid_2DVidangeReservoir.py
1 #!/usr/bin/env python
2 # -*-coding:utf-8 -*
3
4 import CoreFlows as cf
5 import cdmath as cm
6
7 def FiveEqsTwoFluid_2DVidangeReservoir():
8
9         spaceDim = 2;
10         # Prepare for the mesh
11         print("Building mesh " );
12         xinf = 0 ;
13         xsup=1.0;
14         yinf=0.0;
15         ysup=1.0;
16         nx=50;
17         ny=50; 
18         diametreSortie=(ysup-yinf)/10.#10 percent of the height
19         nsortie=ny*diametreSortie/(ysup-yinf)
20         M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny)
21         # set the limit field for each boundary
22         eps=1e-6;
23         M.setGroupAtPlan(xinf,0,eps,"wall")
24         M.setGroupAtPlan(ysup,1,eps,"inlet")
25         M.setGroupAtPlan(yinf,1,eps,"wall")
26         dy=(ysup-yinf)/ny
27         i=0
28         while i < nsortie:      
29                 M.setGroupAtFaceByCoords(xsup,yinf+(i+0.5)*dy,0,eps,"wall")
30                 i=i+1
31         while i < ny:   
32                 M.setGroupAtFaceByCoords(xsup,yinf+(i+0.5)*dy,0,eps,"wall")
33                 i=i+1
34         
35         
36
37     # set the limit field for each boundary
38         wallVelocityX=[0]*2;
39         wallVelocityY=[0]*2;
40         wallTemperature=300;
41         outletPressure=1e5;
42         inletTemperature=300;
43
44     # set the limit field for each boundary
45         initialAlphaTop=1.;
46         initialAlphaBottom=0.;
47         initialVelocityX=[0]*2;
48         initialVelocityY=[0]*2;
49         initialPressure=1e5;
50         initialTemperature=300;
51
52     # physical constants
53         gravite = [0] * spaceDim
54     
55         gravite[0]=0;
56         gravite[1]=-10;
57
58         myProblem = cf.FiveEqsTwoFluid(cf.around1bar300K,spaceDim);
59         nVar =myProblem.getNumberOfVariables();
60     # Prepare for the initial condition
61         VV_top =cm.Vector(nVar)
62         VV_bottom =cm.Vector(nVar)
63
64         # constant vector
65         VV_top[0] = initialAlphaTop ;
66         VV_top[1] = initialPressure ;
67         VV_top[2] = initialVelocityX[0];
68         VV_top[3] = initialVelocityX[1];
69         VV_top[4] = initialVelocityY[0];
70         VV_top[5] = initialVelocityY[1];
71         VV_top[6] = initialTemperature ;
72
73         VV_bottom[0] = initialAlphaBottom ;
74         VV_bottom[1] = initialPressure ;
75         VV_bottom[2] = initialVelocityX[0];
76         VV_bottom[3] = initialVelocityX[1];
77         VV_bottom[4] = initialVelocityY[0];
78         VV_bottom[5] = initialVelocityY[1];
79         VV_bottom[6] = initialTemperature ;
80
81     #Initial field creation
82         print("Building initial data" );
83         myProblem.setInitialFieldStepFunction( M, VV_bottom, VV_top, .8, 1);
84
85     # the boundary conditions
86         myProblem.setOutletBoundaryCondition("outlet", outletPressure);
87         myProblem.setNeumannBoundaryCondition("inlet");
88         myProblem.setWallBoundaryCondition("wall", wallTemperature,wallVelocityX, wallVelocityY);
89
90     # set physical parameters
91         myProblem.setGravity(gravite);
92
93         # set the numerical method
94         myProblem.setNumericalScheme(cf.upwind, cf.Explicit);
95         #myProblem.setEntropicCorrection(True);
96         myProblem.setNonLinearFormulation(cf.VFFC) 
97
98         # name file save
99         fileName = "2DVidangeReservoir";
100
101         # parameters calculation
102         MaxNbOfTimeStep = 3 ;
103         freqSave = 1;
104         cfl = 0.1;
105         maxTime = 500;
106         precision = 1e-4;
107
108         myProblem.setCFL(cfl);
109         myProblem.setPrecision(precision);
110         myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep);
111         myProblem.setTimeMax(maxTime);
112         myProblem.setFreqSave(freqSave);
113         myProblem.setFileName(fileName);
114         myProblem.setNewtonSolver(precision,20);
115         myProblem.saveVelocity();
116
117         # evolution
118         myProblem.initialize();
119
120         ok = myProblem.run();
121         if (ok):
122                 print( "Simulation python " + fileName + " is successful !" );
123                 pass
124         else:
125                 print( "Simulation python " + fileName + "  failed ! " );
126                 pass
127
128         print( "------------ End of calculation !!! -----------" );
129
130         myProblem.terminate();
131         
132         return ok
133
134 if __name__ == """__main__""":
135     FiveEqsTwoFluid_2DVidangeReservoir()