Salome HOME
Minor restructuration
[tools/solverlab.git] / CoreFlows / mainCoreFlows.py
1 #!/usr/bin/env python
2 # -*-coding:utf-8 -*
3
4 import CoreFlows as cf
5 import cdmath as cm
6 import math 
7
8 def main():
9
10         spaceDim = 1;
11     # Prepare for the mesh
12         xinf = 0 ;
13         xsup=4.2;
14         eps=1.E-8
15         M=cm.Mesh("../CoreFlows_src/examples/ressources/BifurcatingFlow2BranchesEqualSections.med")
16         M.getFace(0).setGroupName("Inlet")
17         M.getFace(31).setGroupName("Outlet")
18         #M.setGroupAtPlan(xsup,0,eps,"Outlet");
19         #M.setGroupAtPlan(xinf,0,eps,"Inlet");
20
21     # set the initial field
22
23         initialPressure=155e5;
24         initialVelocityX=5;
25         initialTemperature=573;
26
27    # set the limit field for each boundary
28
29         inletVelocityX=5;
30         inletTemperature=573;
31         outletPressure=155e5
32
33         myProblem = cf.SinglePhase(cf.Liquid,cf.around155bars600K,spaceDim);
34         nVar =  myProblem.getNumberOfVariables();
35
36     # Prepare for the initial condition
37         VV_Constant =[0]*nVar;
38
39         # constant vector
40         VV_Constant[0] = initialPressure ;
41         VV_Constant[1] = initialVelocityX;
42         VV_Constant[2] = initialTemperature ;
43
44
45     #Initial field creation
46         print("Building initial data" ); 
47         myProblem.setInitialFieldConstant( M, VV_Constant);
48
49     # set the boundary conditions
50         myProblem.setInletBoundaryCondition("Inlet", inletTemperature, inletVelocityX);
51         myProblem.setOutletBoundaryCondition("Outlet",outletPressure);
52
53         #set porosity, heat and gravity source
54         Sections=cm.Field("../CoreFlows_src/examples/ressources/BifurcatingFlow2BranchesEqualSections", cm.CELLS,"Section area");
55         heatPowerField=cm.Field("../CoreFlows_src/examples/ressources/BifurcatingFlow2BranchesEqualSections", cm.CELLS,"Heat power");
56         myProblem.setSectionField(Sections);
57         myProblem.setHeatPowerField(heatPowerField)
58         gravite=[-10]
59         myProblem.setGravity(gravite)
60     # set the numerical method
61         myProblem.setNumericalScheme(cf.upwind, cf.Explicit);
62         myProblem.setWellBalancedCorrection(True)    
63
64     # name of result file
65         fileName = "2BranchesHeatedChannels";
66
67     # simulation parameters 
68         MaxNbOfTimeStep = 100000 ;
69         freqSave = 50;
70         cfl = 0.5;
71         maxTime = 500;
72         precision = 1e-5;
73
74         myProblem.setCFL(cfl);
75         myProblem.setPrecision(precision);
76         myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep);
77         myProblem.setTimeMax(maxTime);
78         myProblem.setFreqSave(freqSave);
79         myProblem.setFileName(fileName);
80         myProblem.setNewtonSolver(precision,20);
81         #myProblem.saveConservativeField(True);
82         if(spaceDim>1):
83                 myProblem.saveVelocity();
84                 pass
85  
86     # evolution
87         myProblem.initialize();
88         print("Running python "+ fileName );
89
90         ok = myProblem.run();
91         if (ok):
92                 print( "Simulation python " + fileName + " is successful !" );
93                 pass
94         else:
95                 print( "Simulation python " + fileName + "  failed ! " );
96                 pass
97
98         print( "------------ End of calculation !!! -----------" );
99
100         myProblem.terminate();
101         return ok
102
103 if __name__ == """__main__""":
104     main()