Salome HOME
initial project version
[tools/solverlab.git] / CoreFlows / examples / Python / SinglePhase_2DLidDrivenCavity_unstructured.py
1 #!/usr/bin/env python
2 # -*-coding:utf-8 -*
3
4
5 import CoreFlows as cf
6
7 def SinglePhase_2DLidDrivenCavity_unstructured():
8         spaceDim = 2;
9
10         print( "Loading unstructured mesh " );
11         inputfile="../resources/BoxWithMeshWithTriangularCells.med";    
12  
13     # set the limit field for each boundary
14
15         fixedWallVelocityX=0;
16         fixedWallVelocityY=0;
17         fixedWallTemperature=273;
18
19         movingWallVelocityX=1;
20         movingWallVelocityY=0;
21         movingWallTemperature=273;
22         
23     # physical constants
24
25         viscosite=[0.025];
26
27         myProblem = cf.SinglePhase(cf.Gas,cf.around1bar300K,spaceDim);
28         nVar = myProblem.getNumberOfVariables();
29
30         #Initial field creation
31         print("Building initial data " ); 
32         
33     # Prepare for the initial condition
34     
35         VV_Constant = [0] * nVar
36
37         # constant vector
38         VV_Constant[0] = 1e5;
39         VV_Constant[1] = 0 ;
40         VV_Constant[2] = 0;
41         VV_Constant[3] = 273;
42
43     #Initial field creation
44         print("Setting mesh and initial data" );
45         myProblem.setInitialFieldConstant(inputfile,VV_Constant);
46
47     # Set the boundary conditions
48         myProblem.setWallBoundaryCondition("BAS", fixedWallTemperature, fixedWallVelocityX, fixedWallVelocityY);
49         myProblem.setWallBoundaryCondition("GAUCHE", fixedWallTemperature, fixedWallVelocityX, fixedWallVelocityY);
50         myProblem.setWallBoundaryCondition("DROITE", fixedWallTemperature, fixedWallVelocityX, fixedWallVelocityY);
51         myProblem.setWallBoundaryCondition("HAUT", movingWallTemperature, movingWallVelocityX, movingWallVelocityY);
52
53     # set physical parameters
54         myProblem.setViscosity(viscosite);
55
56     # set the numerical method
57         myProblem.setNumericalScheme(cf.pressureCorrection, cf.Implicit);
58         myProblem.setLinearSolver(cf.GMRES,cf.ILU,True);
59    
60     # name file save
61         fileName = "2DLidDrivenCavityUnstructured";
62
63     # simulation parameters
64         MaxNbOfTimeStep = 3 ;
65         freqSave = 1;
66         cfl = 10;
67         maxTime = 50;
68         precision = 1e-9;
69
70         myProblem.setCFL(cfl);
71         myProblem.setPrecision(precision);
72         myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep);
73         myProblem.setTimeMax(maxTime);
74         myProblem.setFreqSave(freqSave);
75         myProblem.setFileName(fileName);
76         myProblem.setNewtonSolver(precision,20);
77         myProblem.saveConservativeField(True);
78         if(spaceDim>1):
79                 myProblem.saveVelocity();
80                 pass
81
82     # evolution
83         myProblem.initialize();
84
85         ok = myProblem.run();
86         if (ok):
87                 print( "Simulation python " + fileName + " is successful !" );
88                 pass
89         else:
90                 print( "Simulation python " + fileName + "  failed ! " );
91                 pass
92
93         print( "------------ End of calculation !!! -----------" );
94
95         myProblem.terminate();
96         return ok
97
98 if __name__ == """__main__""":
99     SinglePhase_2DLidDrivenCavity_unstructured()