Salome HOME
update CoreFlows
[tools/solverlab.git] / CoreFlows / examples / Python / FiveEqsTwoFluid / FiveEqsTwoFluid_1DVidangeReservoir.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_1DVidangeReservoir():
8  
9         spaceDim = 1;
10     # Prepare for the mesh
11         print("Building mesh " );
12         xinf = 0. ;
13         xsup=1.0;
14         nx=50; 
15         M=cm.Mesh(xinf,xsup,nx)
16         # set the limit field for each boundary
17         eps=1e-6;
18         M.setGroupAtPlan(xinf,0,eps,"wall")
19         M.setGroupAtPlan(xsup,0,eps,"inlet")
20
21     # set the limit field for each boundary
22         wallVelocityX=[0] * 2
23         wallTemperature=300
24
25     # set the limit field for each boundary
26         initialAlphaTop=1;
27         initialAlphaBottom=0.;
28         initialVelocityX=[0]*2;
29         initialPressure=1e5;
30         initialTemperature=300
31
32     # physical constants
33         gravite=[-10];
34
35         myProblem = cf.FiveEqsTwoFluid(cf.around1bar300K,spaceDim);
36         nVar = myProblem.getNumberOfVariables();
37
38     # Prepare for the initial condition
39         VV_top =cm.Vector(nVar)
40         VV_bottom =cm.Vector(nVar)
41
42         # top and bottom vectors
43         VV_top[0] = initialAlphaTop ;
44         VV_top[1] = initialPressure ;
45         VV_top[2] = initialVelocityX[0];
46         VV_top[3] = initialVelocityX[1];
47         VV_top[4] = initialTemperature
48
49         VV_bottom[0] = initialAlphaBottom ;
50         VV_bottom[1] = initialPressure ;
51         VV_bottom[2] = initialVelocityX[0];
52         VV_bottom[3] = initialVelocityX[1];
53         VV_bottom[4] = initialTemperature
54
55     #Initial field creation
56         print("Building initial data " );
57         myProblem.setInitialFieldStepFunction( M, VV_bottom, VV_top, .8, 0);
58
59     # the boundary conditions
60         myProblem.setWallBoundaryCondition("wall",initialTemperature, wallVelocityX);
61         myProblem.setNeumannBoundaryCondition("inlet");
62
63     # set physical parameters
64         myProblem.setGravity(gravite);
65
66     # set the numerical method
67         myProblem.setNumericalScheme(cf.upwind, cf.Explicit);
68         #myProblem.setEntropicCorrection(True);
69         myProblem.setNonLinearFormulation(cf.VFFC) 
70     
71     # name file save
72         fileName = "1DVidangeReservoir";
73
74     # simulation parameters
75         MaxNbOfTimeStep = 3 ;
76         freqSave = 1;
77         cfl = .1;
78         maxTime = 5.;
79         precision = 1e-6;
80
81         myProblem.setCFL(cfl);
82         myProblem.setPrecision(precision);
83         myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep);
84         myProblem.setTimeMax(maxTime);
85         myProblem.setFreqSave(freqSave);
86         myProblem.setFileName(fileName);
87
88     # evolution
89         myProblem.initialize();
90
91         ok = myProblem.run();
92         if (ok):
93                 print( "Simulation python " + fileName + " is successful !" );
94                 pass
95         else:
96                 print( "Simulation python " + fileName + "  failed ! " );
97                 pass
98
99         print( "------------ End of calculation !!! -----------" );
100
101         myProblem.terminate();
102         
103         return ok
104
105
106 if __name__ == """__main__""":
107     FiveEqsTwoFluid_1DVidangeReservoir()