Salome HOME
update CoreFlows
[tools/solverlab.git] / CoreFlows / examples / C / SinglePhase_2DLidDrivenCavity_unstructured.cxx
1 #include "SinglePhase.hxx"
2
3 using namespace std;
4
5 int main(int argc, char** argv)
6 {
7         /* preprocessing: mesh and group creation */
8         cout << "Loading unstructured mesh for test SinglePhase_2DLidDrivenCavity_unstructured()" << endl;
9         double xinf=0.0;
10         double xsup=1.0;
11         double yinf=0.0;
12         double ysup=1.0;
13         Mesh M("resources/BoxWithMeshWithTriangularCells.med");
14         double eps=1.E-6;
15         M.setGroupAtPlan(xsup,0,eps,"wall");
16         M.setGroupAtPlan(xinf,0,eps,"wall");
17         M.setGroupAtPlan(yinf,1,eps,"wall");
18         M.setGroupAtPlan(ysup,1,eps,"MovingWall");
19         int spaceDim = M.getSpaceDimension();
20
21         // physical constants
22         vector<double> viscosite(1)  ;
23         viscosite[0]= 0.025;
24
25         /* set the limit field for each boundary*/
26         LimitField limitWall;
27         map<string, LimitField> boundaryFields;
28         limitWall.bcType=Wall;
29         limitWall.T = 273;
30         limitWall.p = 1e5;
31         limitWall.v_x = vector<double>(1,0);
32         limitWall.v_y = vector<double>(1,0);
33         limitWall.v_z = vector<double>(1,0);
34         boundaryFields["wall"]= limitWall;
35
36         LimitField limitMovingWall;
37         limitMovingWall.bcType=Wall;
38         limitMovingWall.T = 273;
39         limitMovingWall.p = 1e5;
40         limitMovingWall.v_x = vector<double>(1,1);
41         limitMovingWall.v_y = vector<double>(1,0);
42         limitMovingWall.v_z = vector<double>(1,0);
43         boundaryFields["MovingWall"]= limitMovingWall;
44
45
46         SinglePhase  myProblem(Liquid,around1bar300K,spaceDim);
47         int nbPhase = myProblem.getNumberOfPhases();
48         // Prepare for the initial condition
49         int nVar = myProblem.getNumberOfVariables();
50         Vector VV_Constant(nVar);
51         // constant vector
52         VV_Constant(0) = 1e5;
53         VV_Constant(1) = 0;
54         VV_Constant(2) = 0;
55         VV_Constant(3) = 273;
56
57         //Initial field creation
58         cout << "Setting initial data " << endl;
59         myProblem.setInitialFieldConstant(M,VV_Constant);
60
61         //set the boundary conditions
62         myProblem.setBoundaryFields(boundaryFields);
63
64         // physical parameters
65         myProblem.setViscosity(viscosite);
66
67         // set the numerical method
68         myProblem.setNumericalScheme(upwind, Implicit);
69
70         // set the Petsc resolution
71         myProblem.setLinearSolver(GMRES,ILU,true);
72
73         // name file save
74         string fileName = "2DLidDrivenCavity_unstructured";
75
76         // parameters calculation
77         unsigned MaxNbOfTimeStep = 3 ;
78         int freqSave = 1;
79         double cfl = 5;
80         double maxTime = 5;
81         double precision = 1e-8;
82
83         myProblem.setCFL(cfl);
84         myProblem.setPrecision(precision);
85         myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep);
86         myProblem.setTimeMax(maxTime);
87         myProblem.setFreqSave(freqSave);
88         myProblem.setFileName(fileName);
89         myProblem.setNewtonSolver(precision,20);
90         myProblem.saveVelocity();
91
92         // evolution
93         myProblem.initialize();
94
95         bool ok = myProblem.run();
96         if (ok)
97                 cout << "Simulation "<<fileName<<" is successful !" << endl;
98         else
99                 cout << "Simulation "<<fileName<<"  failed ! " << endl;
100
101         cout << "------------ End of calculation !!! -----------" << endl;
102         myProblem.terminate();
103
104         return EXIT_SUCCESS;
105 }