1 //============================================================================
2 // Author : Anouar MEKKAS
4 // Description : Equation de transport lineaire 2D non structure
5 //============================================================================
19 void conditions_initiales(Field& yField)
24 Mesh myMesh=yField.getMesh();
25 int nbCells=myMesh.getNumberOfCells();
26 for (int j=0 ; j<nbCells ; j++)
28 double x = myMesh.getCell(j).x() ;
29 double y = myMesh.getCell(j).y() ;
30 double valX=(x-xcentre)*(x-xcentre);
31 double valY=(y-ycentre)*(y-ycentre);
32 double val=sqrt(valX+valY);
40 void sigma_flux(double VitesseX, double VitesseY, double cfl, const Field& yField, const IntTab indexFacesPerio, double& dt, Field& SumFlux)
42 // Calculation of fluxes
43 Mesh myMesh=yField.getMesh();
44 int nbCells=myMesh.getNumberOfCells();
45 double normU=sqrt(VitesseX*VitesseX+VitesseY*VitesseY);
46 for (int j=0 ; j<nbCells ; j++)
48 Cell Cj=myMesh.getCell(j);
49 int nbFace=Cj.getNumberOfFaces();
51 double minlengthFk=1.E30;
53 int cellCourante,cellAutre;
54 for (int k=0 ; k<nbFace ; k++)
56 int indexFace=Cj.getFacesId()[k];
57 Face Fk=myMesh.getFace(indexFace);
58 double NormalX=Cj.getNormalVector(k,0);
59 double NormalY=Cj.getNormalVector(k,1);
60 double LengthFk = Fk.getMeasure();
61 double UN=VitesseX*NormalX+VitesseY*NormalY;
63 minlengthFk=min(minlengthFk,LengthFk/fabs(UN));
64 minlengthFk=min(minlengthFk,LengthFk/fabs(VitesseX));
65 minlengthFk=min(minlengthFk,LengthFk/fabs(VitesseY));
73 int indexC1=Fk.getCellsId()[0];
74 int indexC2=Fk.getCellsId()[1];
75 /* hypothese: La cellule d'index indexC1 est la cellule courante index j */
78 /* hypothese verifie */
81 } else if ( indexC2 == j )
83 /* hypothese non verifie */
87 // definir la cellule gauche et droite par le prduit vitesse * normale sortante
88 // si u*n>0 : rien a faire sinon inverser la gauche et la droite
90 conc=yField(cellCourante);
92 conc=yField(cellAutre);
95 /* conditions aux limites neumann homogene */
96 if (Fk.getGroupName().compare("GAUCHE")==0 || Fk.getGroupName().compare("DROITE")==0)
99 conc=yField(cellCourante);
103 /* conditions aux limites periodiques */
104 if (Fk.getGroupName().compare("BAS")==0 || Fk.getGroupName().compare("HAUT")==0)
106 int indexFP=indexFacesPerio[indexFace];
107 /* une autre manière de recuperer l'index de la face periodique */
108 //int indexFP=M.getIndexFacePeriodic(indexFace);
109 Face Fp=myMesh.getFace(indexFP);
110 int indexCp=Fp.getCellsId()[0];
112 conc=yField(cellCourante);
114 conc=yField(indexCp);
117 SumF=SumF+UN*LengthFk*conc;
119 dt=cfl*minlengthFk/normU;
120 SumFlux(j)=dt*SumF/Cj.getMeasure();
124 void EquationTransport2D(double tmax, double VitesseX, double VitesseY, double cfl, int freqSortie, const Mesh& myMesh, const string file)
126 /* Initial conditions */
127 cout << "Construction of the initial condition …" << endl;
128 Field yField("Y field",CELLS,myMesh,1) ;
129 conditions_initiales(yField);
132 * MED output of the initial condition at t=0 and iter = 0
136 cout << "Saving the solution at T=" << time << "…" << endl;
137 yField.setTime(time,iter);
138 yField.writeMED(file);
139 yField.writeVTK(file);
140 yField.writeCSV(file);
141 /* --------------------------------------------- */
144 cout << "Resolution of the transport equation with an UPWIND scheme …" << endl;
147 IntTab indexFacesPerio=myMesh.getIndexFacePeriodic();
148 while (iter<ntmax && time <= tmax )
150 Field SumFlux("Fluxes sum",CELLS,myMesh,1) ;
151 sigma_flux(VitesseX,VitesseY,cfl,yField,indexFacesPerio,dt,SumFlux);
152 cout << "-- Iter: " << iter << ", Time: " << time << ", dt: " << dt << endl;
154 /* Advancing time step */
159 // Output every freq iterations
160 if (iter%freqSortie==0)
162 yField.setTime(time,iter);
163 yField.writeMED(file,false);
164 yField.writeVTK(file,false);
165 yField.writeCSV(file);
172 cout << "Resolution of the 2D transport equation:" << endl;
173 cout << "- DOMAIN: SQUARE" << endl;
174 cout << "- MESH: TRIANGULAR, GENERATED WITH SALOME" << endl;
175 cout << "- PERIODIC BC ON TOP AND BOTTOM" << endl;
176 cout << "- HOMOGENEOUS NEUMANN BC ON LEFT AND RIGHT" << endl;
185 cout << "Construction of Cartesian mesh…" << endl;
186 Mesh myMesh("../../tests/ressources/meshSquare.med");
187 string fileOutPut="Exercice2";
188 EquationTransport2D(tmax,VitesseX,VitesseY,cfl,freqSortie,myMesh,fileOutPut);
189 cout << "CDMATH calculation done." << endl;