1 #include "StationaryDiffusionEquation.hxx"
9 int main(int argc, char** argv)
21 /* Mesh construction */
22 Mesh M(xinf,xsup,nx,yinf,ysup,ny,0); //Regular triangular mesh
24 /* set the limit field for each boundary */
26 M.setGroupAtPlan(xsup,0,eps,"Bord1");
27 M.setGroupAtPlan(xinf,0,eps,"Bord2");
28 M.setGroupAtPlan(ysup,1,eps,"Bord3");
29 M.setGroupAtPlan(yinf,1,eps,"Bord4");
31 /* set the boundary values for each boundary */
37 cout<< "Building of a regular triangular 2D mesh from a square mesh with "<< nx<<"x" <<ny<< " cells"<<endl;
39 /* Create the problem */
40 bool FEComputation=false;
41 StationaryDiffusionEquation myProblem(spaceDim,FEComputation);
44 /* set the boundary conditions */
45 myProblem.setNeumannBoundaryCondition("Bord1");
46 myProblem.setNeumannBoundaryCondition("Bord2");
47 myProblem.setNeumannBoundaryCondition("Bord3");
48 myProblem.setNeumannBoundaryCondition("Bord4");
50 /* Set the right hand side function*/
51 Field my_RHSfield("RHS_field", CELLS, M, 1);
54 for(int i=0; i< M.getNumberOfCells(); i++)
60 my_RHSfield[i]=2*pi*pi*cos(pi*x)*cos(pi*y);//mettre la fonction definie au second membre de l'edp
62 myProblem.setHeatPowerField(my_RHSfield);
63 myProblem.setLinearSolver(GMRES,ILU);
65 /* name the result file */
66 string fileName = "StationnaryDiffusion_2DFV_RegularTriangles_Neumann";
67 myProblem.setFileName(fileName);
69 /* Run the computation */
70 myProblem.initialize();
71 bool ok = myProblem.solveStationaryProblem();
73 cout << "Simulation of "<<fileName<<" failed !" << endl;
76 /********************** Postprocessing and measure od numerical error******************************/
77 Field my_ResultField = myProblem.getOutputTemperatureField();
78 /* The following formulas use the fact that the exact solution is equal the right hand side divided by 2*pi*pi */
79 double max_abs_sol_exacte=max(my_RHSfield.max(),-my_RHSfield.min())/(2*pi*pi);
80 double max_sol_num=my_ResultField.max();
81 double min_sol_num=my_ResultField.min();
83 for(int i=0; i< M.getNumberOfCells() ; i++)
84 if( erreur_abs < abs(my_RHSfield[i]/(2*pi*pi) - my_ResultField[i]) )
85 erreur_abs = abs(my_RHSfield[i]/(2*pi*pi) - my_ResultField[i]);
87 cout<<"Absolute error = max(| exact solution - numerical solution |) = "<<erreur_abs <<endl;
88 cout<<"Relative error = max(| exact solution - numerical solution |)/max(| exact solution |) = "<<erreur_abs/max_abs_sol_exacte<<endl;
89 cout<<"Maximum numerical solution = "<< max_sol_num<< " Minimum numerical solution = "<< min_sol_num << endl;
91 assert( erreur_abs/max_abs_sol_exacte <1.);
93 cout << "Simulation of "<<fileName<<" is successful ! " << endl;
96 cout << "------------ End of calculation !!! -----------" << endl;
97 myProblem.terminate();