]> SALOME platform Git repositories - tools/solverlab.git/blob - CDMATH/tests/examples/transport1d/main.cxx
Salome HOME
update CDMATH
[tools/solverlab.git] / CDMATH / tests / examples / transport1d / main.cxx
1 //============================================================================
2 // Author      : Anouar MEKKAS
3 // Version     :
4 // Description : 1D linear transport equation
5 //============================================================================
6
7 #include <iostream>
8 #include <cmath>
9
10 #include "Cell.hxx"
11 #include "Mesh.hxx"
12 #include "Field.hxx"
13
14 using namespace std;
15
16
17 int main( void )
18 {
19   double a=-5.0;
20   double b=5.0;
21   int nx=1000;
22   int ntmax=3;
23   double dx = (b-a)/nx;
24   double pi=3.1415927;
25   // Transport velocity
26   double cfl=0.5;
27   double u=3.;
28   double dt=cfl*dx/u;
29
30   Mesh myMesh(a,b,nx);
31
32   Field conc("Concentration",CELLS,myMesh,1);
33
34   // Initial conditions
35   double sigma=sqrt(0.2);
36   for (int i=0 ; i<myMesh.getNumberOfCells() ; i++)
37   {
38    double x=myMesh.getCell(i).x();
39    conc(i) = 0.5/(sigma*sqrt(2*pi))*exp(-0.5*pow((x/sigma),2));
40   }
41
42   double time=0.;
43   double tmax=3.0;
44   int iter=0;
45
46   cout << "MED post-treatment of the solution at T=" << time << "…" << endl;
47   string fileOutPut="EqTr1D";
48   conc.setTime(time,iter);
49   conc.writeMED(fileOutPut);
50   conc.writeVTK(fileOutPut);
51   conc.writeCSV(fileOutPut);
52   int outputFreq=10;
53
54   // Time loop
55   while (iter<ntmax && time <= tmax )
56   {
57    cout << "-- Iter: " << iter << ", Time: " << time << ", dt: " << dt << endl;
58    conc(0) = conc(0) -u*dt/dx*(conc(0)-conc(myMesh.getNumberOfCells()-1));
59    for (int j=1 ; j<myMesh.getNumberOfCells() ; j++)
60    {
61     conc(j) = conc(j) -u*dt/dx*(conc(j)-conc(j-1));
62    }
63    time+=dt;
64    iter+=1;
65    if (iter%outputFreq==0)
66    {
67        conc.setTime(time,iter);
68        conc.writeMED(fileOutPut,false);
69        conc.writeVTK(fileOutPut,false);
70        conc.writeCSV(fileOutPut);
71    }
72   }
73   cout << "CDMATH calculation done." << endl;
74   return 0;
75 }
76
77