Salome HOME
update CoreFlows
[tools/solverlab.git] / CoreFlows / examples / Python / DriftModel / DriftModel_1DChannelGravity.py
1 #!/usr/bin/env python
2 # -*-coding:utf-8 -*
3
4 import CoreFlows as cf
5
6 def DriftModel_1DChannelGravity():
7
8         spaceDim = 1;
9     # Prepare for the mesh
10         print("Building mesh " );
11         xinf = 0 ;
12         xsup=4.2;
13         nx=50;
14
15     # set the limit field for each boundary
16
17         inletConc=0;
18         inletVelocityX=1;
19         inletEnthalpy=1.3e6;
20         outletPressure=155e5;
21
22     # physical parameters
23         gravite=[-10];
24
25         myProblem = cf.DriftModel(cf.around155bars600K,spaceDim);
26         nVar =  myProblem.getNumberOfVariables();
27
28     # Prepare for the initial condition
29         VV_Constant =[0]*nVar;
30
31         # constant vector
32         VV_Constant[0] = inletConc;
33         VV_Constant[1] = outletPressure ;
34         VV_Constant[2] = inletVelocityX;
35         VV_Constant[3] = 578 ;
36
37
38     #Initial field creation
39         print("Building initial data " ); 
40         myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"inlet","outlet");
41
42     # set the boundary conditions
43         myProblem.setInletEnthalpyBoundaryCondition("inlet",inletEnthalpy,inletConc,inletVelocityX)
44         myProblem.setOutletBoundaryCondition("outlet", outletPressure,[xsup]);
45
46     # set physical parameters
47         myProblem.setGravity(gravite);
48
49     # set the numerical method
50         myProblem.setNumericalScheme(cf.upwind, cf.Implicit);
51         myProblem.setNonLinearFormulation(cf.VFRoe) 
52     
53     # name of result file
54         fileName = "1DChannelGravityUpwindImplicite";
55
56     # simulation parameters 
57         MaxNbOfTimeStep = 3 ;
58         freqSave = 1;
59         cfl = 100;
60         maxTime = 500;
61         precision = 1e-7;
62
63         myProblem.setCFL(cfl);
64         myProblem.setPrecision(precision);
65         myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep);
66         myProblem.setTimeMax(maxTime);
67         myProblem.setFreqSave(freqSave);
68         myProblem.setFileName(fileName);
69         myProblem.saveAllFields(True);
70         myProblem.usePrimitiveVarsInNewton(True);
71  
72     # evolution
73         myProblem.initialize();
74
75         ok = myProblem.run();
76         if (ok):
77                 print( "Simulation python " + fileName + " is successful !" );
78                 pass
79         else:
80                 print( "Simulation python " + fileName + "  failed ! " );
81                 pass
82
83         print( "------------ End of calculation !!! -----------" );
84
85         myProblem.terminate();
86         return ok
87
88 if __name__ == """__main__""":
89     DriftModel_1DChannelGravity()