]> SALOME platform Git repositories - tools/solverlab.git/blob - CoreFlows/examples/Python/FiveEqsTwoFluid/FiveEqsTwoFluid_1DBoilingAssembly.py
Salome HOME
Mesh should be set befor giving input fields
[tools/solverlab.git] / CoreFlows / examples / Python / FiveEqsTwoFluid / FiveEqsTwoFluid_1DBoilingAssembly.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_1DBoilingAssembly():
8
9         spaceDim = 1;
10     # Prepare for the mesh
11         print("Building mesh " );
12         xinf = 0 ;
13         xsup=4.2;
14         nx=50;
15         M=cm.Mesh(xinf,xsup,nx)
16         eps=1e-6;
17         M.setGroupAtPlan(xsup,0,eps,"outlet")
18         M.setGroupAtPlan(xinf,0,eps,"inlet")
19
20     # set the limit field for each boundary
21
22         inletVoidFraction=0;
23         inletVelocityX=[1]*2;
24         inletTemperature=563;
25         outletPressure=155e5;
26
27     # physical constants
28         heatPowerField=cm.Field("heatPowerField", cm.CELLS, M, 1);
29
30         nbCells=M.getNumberOfCells();
31         
32         for i in range (nbCells):
33                 x=M.getCell(i).x();
34                 if (x> (xsup-xinf)/4) and (x< (xsup-xinf)*3/4):
35                         heatPowerField[i]=1e8
36                 else:
37                         heatPowerField[i]=0
38         heatPowerField.writeVTK("heatPowerField",True)          
39                 
40
41         myProblem = cf.FiveEqsTwoFluid(cf.around155bars600K,spaceDim);
42         nVar =  myProblem.getNumberOfVariables();
43
44     # Prepare for the initial condition
45         VV_Constant =[0]*nVar;
46
47         # constant vector
48         VV_Constant[0] = inletVoidFraction;
49         VV_Constant[1] = outletPressure ;
50         VV_Constant[2] = inletVelocityX[0];
51         VV_Constant[3] = inletVelocityX[1];
52         VV_Constant[4] = inletTemperature ;
53
54
55     #Initial field creation
56         print("Building initial data " ); 
57         myProblem.setInitialFieldConstant(M,VV_Constant)
58
59     # set the boundary conditions
60         myProblem.setInletBoundaryCondition("inlet",inletVoidFraction,inletTemperature,inletVelocityX)
61         myProblem.setOutletBoundaryCondition("outlet", outletPressure);
62
63     # set physical parameters
64         myProblem.setHeatPowerField(heatPowerField)
65
66     # set the numerical method
67         myProblem.setNumericalScheme(cf.upwind, cf.Explicit);
68         myProblem.setEntropicCorrection(True);
69         myProblem.setWellBalancedCorrection(True);  
70     
71     # name of result file
72         fileName = "1DBoilingAssembly";
73
74     # simulation parameters 
75         MaxNbOfTimeStep = 3 ;
76         freqSave = 1;
77         cfl = 0.5;
78         maxTime = 500;
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         myProblem.setNewtonSolver(precision,20);
88         #myProblem.saveConservativeField(True);
89         if(spaceDim>1):
90                 myProblem.saveVelocity();
91                 pass
92  
93     # evolution
94         myProblem.initialize();
95         print("Running python "+ fileName );
96
97         ok = myProblem.run();
98         if (ok):
99                 print( "Simulation python " + fileName + " is successful !" );
100                 pass
101         else:
102                 print( "Simulation python " + fileName + "  failed ! " );
103                 pass
104
105         print( "------------ End of calculation !!! -----------" );
106
107         myProblem.terminate();
108         return ok
109
110 if __name__ == """__main__""":
111     FiveEqsTwoFluid_1DBoilingAssembly()