Salome HOME
update CoreFlows
[tools/solverlab.git] / CoreFlows / examples / Python / SinglePhase / SinglePhase_1DDepressurisation.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 SinglePhase_1DDepressurisation():
9
10         spaceDim = 1;
11     # Prepare for the mesh
12         print("Building mesh " );
13         xinf = 0 ;
14         xsup=4.2;
15         nx=50;
16         M=cm.Mesh(xinf,xsup,nx)
17
18     # set the initial field
19         initialPressure=155e5;
20         initialVelocityX=0;
21         initialTemperature=573;
22
23    # set the boundary data for each boundary
24         outletPressure=80e5;
25         wallVelocityX=0;
26         wallTemperature=573;
27
28         myProblem = cf.SinglePhase(cf.Liquid,cf.around155bars600K,spaceDim);
29         nVar =  myProblem.getNumberOfVariables();
30
31     # Prepare for the initial condition
32         VV_Constant =[0]*nVar;
33
34         # constant vector
35         VV_Constant[0] = initialPressure ;
36         VV_Constant[1] = initialVelocityX;
37         VV_Constant[2] = initialTemperature ;
38
39
40     #Initial field creation
41         print("Building initial data" ); 
42         myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"wall","outlet");
43
44     # set the boundary conditions
45         myProblem.setWallBoundaryCondition("wall", wallTemperature, wallVelocityX);
46         myProblem.setOutletBoundaryCondition("outlet", outletPressure,[xsup]);
47
48
49     # set the numerical method
50         myProblem.setNumericalScheme(cf.upwind, cf.Explicit);
51     
52     # name of result file
53         fileName = "1DDepressurisation";
54
55     # simulation parameters 
56         MaxNbOfTimeStep = 3 ;
57         freqSave = 1;
58         cfl = 0.95;
59         maxTime = 500;
60         precision = 1e-6;
61
62         myProblem.setCFL(cfl);
63         myProblem.setPrecision(precision);
64         myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep);
65         myProblem.setTimeMax(maxTime);
66         myProblem.setFreqSave(freqSave);
67         myProblem.setFileName(fileName);
68         myProblem.setNewtonSolver(precision,20);
69         #myProblem.saveConservativeField(True);
70         if(spaceDim>1):
71                 myProblem.saveVelocity();
72                 pass
73  
74     # evolution
75         myProblem.initialize();
76
77         ok = myProblem.run();
78         if (ok):
79                 print( "Simulation python " + fileName + " is successful !" );
80                 pass
81         else:
82                 print( "Simulation python " + fileName + "  failed ! " );
83                 pass
84
85         print( "------------ End of calculation !!! -----------" );
86
87         myProblem.terminate();
88         return ok
89
90 if __name__ == """__main__""":
91     SinglePhase_1DDepressurisation()