int TestFieldDG(void){ int test = (1==1); Field f; f.model.m=1; // only one conservative variable f.model.NumFlux=TransportNumFlux; f.model.BoundaryFlux=TestTransportBoundaryFlux; f.model.InitData=TestTransportInitData; f.model.ImposedData=TestTransportImposedData; f.varindex=GenericVarindex; f.interp.interp_param[0]=1; // _M f.interp.interp_param[1]=2; // x direction degree f.interp.interp_param[2]=2; // y direction degree f.interp.interp_param[3]=2; // z direction degree f.interp.interp_param[4]=1; // x direction refinement f.interp.interp_param[5]=1; // y direction refinement f.interp.interp_param[6]=1; // z direction refinement ReadMacroMesh(&(f.macromesh),"test/testcube.msh"); BuildConnectivity(&(f.macromesh)); PrintMacroMesh(&(f.macromesh)); //AffineMapMacroMesh(&(f.macromesh)); PrintMacroMesh(&(f.macromesh)); InitField(&f); CheckMacroMesh(&(f.macromesh),f.interp.interp_param+1); dtField(&f); DisplayField(&f); int yes_compare = 1; int no_compare = 0; PlotField(0,no_compare,&f,"visu.msh"); PlotField(0,yes_compare,&f,"error.msh"); // test the time derivative with the exact solution for(int i=0;i<f.model.m * f.macromesh.nbelems * NPG(f.interp.interp_param+1);i++){ test = test && fabs(4*f.wn[i]-pow(f.dtwn[i],2))<1e-2; assert(test); } return test; };
int TestfieldDG() { int test = true; field f; init_empty_field(&f); f.model.cfl = 0.05; f.model.m = 1; // only one conservative variable f.model.NumFlux = TransNumFlux; f.model.BoundaryFlux = TestTransBoundaryFlux; f.model.InitData = TestTransInitData; f.model.ImposedData = TestTransImposedData; f.model.Source = NULL; f.varindex = GenericVarindex; f.interp.interp_param[0] = 1; // _M f.interp.interp_param[1] = 2; // x direction degree f.interp.interp_param[2] = 2; // y direction degree f.interp.interp_param[3] = 2; // z direction degree f.interp.interp_param[4] = 2; // x direction refinement f.interp.interp_param[5] = 2; // y direction refinement f.interp.interp_param[6] = 2; // z direction refinement ReadMacroMesh(&(f.macromesh), "../test/testcube2.msh"); //ReadMacroMesh(&(f.macromesh),"test/testmacromesh.msh"); BuildConnectivity(&(f.macromesh)); PrintMacroMesh(&(f.macromesh)); //AffineMapMacroMesh(&(f.macromesh)); PrintMacroMesh(&(f.macromesh)); real tnow = 0.0; Initfield(&f); CheckMacroMesh(&(f.macromesh), f.interp.interp_param + 1); dtfield(&f, tnow, f.wn, f.dtwn); Displayfield(&f); /* Plotfield(0, false, &f, NULL, "visu.msh"); */ /* Plotfield(0, true, &f, "error", "error.msh"); */ // Test the time derivative with the exact solution int *raf = f.interp.interp_param + 4; int *deg = f.interp.interp_param + 1; for(int i = 0; i < f.model.m * f.macromesh.nbelems * NPG(raf, deg); i++){ test = test && fabs(4 * f.wn[i] - pow(f.dtwn[i], 2)) < 1e-2; printf("i=%d err=%f \n",i,4 * f.wn[i] - pow(f.dtwn[i], 2)); assert(test); } return test; };
// some unit tests of the macromesh code int TestMacroMesh(void) { MacroMesh m; int param[]={4, 4, 4, 1, 1, 1, 0}; // test gmsh file reading ReadMacroMesh(&m, "test/testmacromesh.msh"); BuildConnectivity(&m); CheckMacroMesh(&m, param); PrintMacroMesh(&m); int test = (m.nbelems == 5); test = (test && m.nbnodes == 50); // test search methods real xphy[3]={1,1.1,0.5}; real xref[3]; test= test && IsInElem(&m,0,xphy,xref); printf("xphy=%f %f %f xref=%f %f %f \n",xphy[0],xphy[1],xphy[2], xref[0],xref[1],xref[2]); xphy[2]=-0.5; test= test && !IsInElem(&m,0,xphy,xref); int num=NumElemFromPoint(&m,xphy,NULL); printf("xphy=%f %f %f is in elem=%d\n",xphy[0],xphy[1],xphy[2],num); test=test && (num == -1); xphy[2]=0.5; num=NumElemFromPoint(&m,xphy,NULL); printf("xphy=%f %f %f is in elem=%d\n",xphy[0],xphy[1],xphy[2],num); test=test && (num == 0); real xphy2[3]={1,0,0.33}; num=NumElemFromPoint(&m,xphy2,NULL); printf("xphy=%f %f %f is in elem=%d\n",xphy2[0],xphy2[1],xphy2[2],num); test=test && (num == 3); return test; }
int TestPoisson(void) { bool test = true; field f; init_empty_field(&f); int vec=1; // num of conservative variables f(vi) for each vi, phi, E, rho, u, // p, e (ou T) f.model.m=_MV+6; f.vmax = _VMAX; // maximal wave speed f.model.NumFlux = VlasovP_Lagrangian_NumFlux; f.model.Source = VlasovP_Lagrangian_Source; //f.model.Source = NULL; f.model.BoundaryFlux = TestPoisson_BoundaryFlux; f.model.InitData = TestPoisson_InitData; f.model.ImposedData = TestPoisson_ImposedData; f.varindex = GenericVarindex; f.pre_dtfield = NULL; f.update_after_rk = NULL; f.interp.interp_param[0] = f.model.m; // _M f.interp.interp_param[1] = 3; // x direction degree f.interp.interp_param[2] = 0; // y direction degree f.interp.interp_param[3] = 0; // z direction degree f.interp.interp_param[4] = 32; // x direction refinement f.interp.interp_param[5] = 1; // y direction refinement f.interp.interp_param[6] = 1; // z direction refinement // read the gmsh file ReadMacroMesh(&(f.macromesh),"../test/testcube.msh"); // try to detect a 2d mesh //bool is1d=Detect1DMacroMesh(&(f.macromesh)); Detect1DMacroMesh(&(f.macromesh)); bool is1d=f.macromesh.is1d; assert(is1d); // mesh preparation BuildConnectivity(&(f.macromesh)); PrintMacroMesh(&(f.macromesh)); //assert(1==2); //AffineMapMacroMesh(&(f.macromesh)); // prepare the initial fields Initfield(&f); f.nb_diags=0; // prudence... CheckMacroMesh(&(f.macromesh),f.interp.interp_param+1); printf("cfl param =%f\n",f.hmin); // time derivative //dtField(&f); //DisplayField(&f); //assert(1==2); // apply the DG scheme // time integration by RK2 scheme // up to final time = 1. /*Compute_electric_field(&f); // check the gradient on every glop for(int ie=0;ie<f.macromesh.nbelems;ie++){ printf("elem %d\n",ie); for(int ipg=0;ipg<NPG(f.interp_param+1);ipg++){ real xref[3],wpg; ref_pg_vol(f.interp_param+1,ipg,xref,&wpg,NULL); printf("Gauss point %d %f %f %f \n",ipg,xref[0],xref[1],xref[2]); int imem=f.varindex(f.interp_param,ie,ipg,_MV+1); printf("gradphi exact=%f gradphinum=%f\n",1-2*xref[0],f.wn[imem]); test=test && (fabs(f.wn[imem]-(1-2*xref[0]))<1e-10); } }*/ //Computation_charge_density(f); SolvePoisson1D(&f,f.wn,1,0.0,0.0,LU,NONE); // check the gradient given by the poisson solver for(int ie=0;ie<f.macromesh.nbelems;ie++){ MacroCell *mcell = f.mcell + ie; for(int ipg=0;ipg<NPG(mcell->raf, mcell->deg);ipg++){ real xref[3],wpg; int *raf = f.interp_param+4; int *deg = f.interp_param+1; ref_pg_vol(raf, deg, ipg, xref, &wpg, NULL); //printf("Gauss point %d %f %f %f \n",ipg,xref[0],xref[1],xref[2]); int imem=f.varindex(f.interp_param, ipg, _MV + 1) + mcell->woffset; // printf("gradphi exact=%f gradphinum=%f rap=%f\n", //1-2*xref[0],f.wn[imem],(1-2*xref[0])/f.wn[imem]); real tolerance; if(sizeof(real) == sizeof(double)) tolerance = 1e-8; else tolerance = 1e-4; test=test && (fabs(f.wn[imem]-(-1+2*xref[0])) < tolerance); } } return test; }
int TestfieldSubCellDGVol() { int test = true; field f; init_empty_field(&f); f.model.cfl = 0.05; f.model.m = 1; // only one conservative variable f.model.NumFlux = TransNumFlux; f.model.BoundaryFlux = TestTransBoundaryFlux; f.model.InitData = TestTransInitData; f.model.ImposedData = TestTransImposedData; f.varindex = GenericVarindex; f.interp.interp_param[0] = 1; // _M f.interp.interp_param[1] = 2; // x direction degree f.interp.interp_param[2] = 2; // y direction degree f.interp.interp_param[3] = 2; // z direction degree f.interp.interp_param[4] = 2; // x direction refinement f.interp.interp_param[5] = 2; // y direction refinement f.interp.interp_param[6] = 1; // z direction refinement ReadMacroMesh(&f.macromesh, "../test/testcube.msh"); //ReadMacroMesh(&f.macromesh,"test/testdisque.msh"); BuildConnectivity(&f.macromesh); PrintMacroMesh(&f.macromesh); //AffineMapMacroMesh(&f.macromesh); PrintMacroMesh(&f.macromesh); Initfield(&f); CheckMacroMesh(&f.macromesh, f.interp.interp_param + 1); real tnow = 0.0; for(int ie = 0;ie < f.macromesh.nbelems; ie++) DGMacroCellInterfaceSlow((void*) (f.mcell+ie), &f, f.wn, f.dtwn); for(int ie = 0; ie < f.macromesh.nbelems; ie++) { DGSubCellInterface((void*) (f.mcell+ie), &f, f.wn, f.dtwn); DGVolume((void*) (f.mcell+ie), &f, f.wn, f.dtwn); DGMass((void*) (f.mcell+ie), &f, f.dtwn); DGSource((void*) (f.mcell+ie), &f, tnow, f.wn, f.dtwn); } /* DGMacroCellInterfaceSlow(&f); */ /* DGSubCellInterface(&f); */ /* DGVolume(&f); */ /* DGMass(&f); */ Displayfield(&f); /* Plotfield(0, false, &f, NULL, "visu.msh"); */ /* Plotfield(0, true, &f, "error", "error.msh"); */ // test the time derivative with the exact solution int *raf = f.interp.interp_param + 4; int *deg = f.interp.interp_param + 1; for(int i=0; i < f.model.m * f.macromesh.nbelems * NPG(raf, deg); i++) { test = test && fabs(4 * f.wn[i] - pow(f.dtwn[i] , 2)) < 1e-2; assert(test); } return test; }
int TestPeriodic(void) { bool test=true; field f; init_empty_field(&f); f.model.m=_INDEX_MAX; // num of conservative variables f.vmax = _VMAX; // maximal wave speed f.model.NumFlux=VlasovP_Lagrangian_NumFlux; f.model.Source = NULL; f.model.BoundaryFlux = TestPeriodic_BoundaryFlux; f.model.InitData = TestPeriodic_InitData; f.model.ImposedData = TestPeriodic_ImposedData; f.varindex=GenericVarindex; f.pre_dtfield=NULL; f.post_dtfield=NULL; f.update_after_rk=NULL; f.model.cfl=0.05; f.interp.interp_param[0]=f.model.m; // _M f.interp.interp_param[1]=3; // x direction degree f.interp.interp_param[2]=0; // y direction degree f.interp.interp_param[3]=0; // z direction degree f.interp.interp_param[4]=10; // x direction refinement f.interp.interp_param[5]=1; // y direction refinement f.interp.interp_param[6]=1; // z direction refinement // read the gmsh file ReadMacroMesh(&(f.macromesh), "test/testcube.msh"); // try to detect a 2d mesh Detect1DMacroMesh(&(f.macromesh)); assert(f.macromesh.is1d); // mesh preparation f.macromesh.period[0]=1; BuildConnectivity(&(f.macromesh)); PrintMacroMesh(&(f.macromesh)); //assert(1==2); //AffineMapMacroMesh(&(f.macromesh)); // prepare the initial fields Initfield(&f); f.nb_diags = 0; // prudence... CheckMacroMesh(&(f.macromesh),f.interp.interp_param+1); printf("cfl param =%f\n",f.hmin); // time derivative //dtField(&f); //DisplayField(&f); //assert(1==2); // apply the DG scheme // time integration by RK2 scheme // up to final time = 1. //RK2(&f,0.5,0.1); f.vmax=_VMAX; real dt = set_dt(&f); RK2(&f,0.5, dt); // save the results and the error Plotfield(0,(1==0),&f,"sol","dgvisu.msh"); Plotfield(0,(1==1),&f,"error","dgerror.msh"); real dd=L2error(&f); real dd_Kinetic=L2_Kinetic_error(&f); printf("erreur kinetic L2=%lf\n",dd_Kinetic); printf("erreur L2=%lf\n",dd); test= test && (dd<3e-3); //SolvePoisson(&f); return test; }
int TestPoisson2d(void) { bool test = true; field f; init_empty_field(&f); int vec=1; // num of conservative variables f(vi) for each vi, phi, E, rho, u, // p, e (ou T) f.model.m=_INDEX_MAX; f.vmax = _VMAX; // maximal wave speed f.model.NumFlux = VlasovP_Lagrangian_NumFlux; f.model.Source = VlasovP_Lagrangian_Source; //f.model.Source = NULL; f.model.BoundaryFlux = TestPoisson_BoundaryFlux; f.model.InitData = TestPoisson_InitData; f.model.ImposedData = TestPoisson_ImposedData; f.model.Source = NULL; f.varindex = GenericVarindex; f.pre_dtfield = NULL; f.update_after_rk = NULL; f.interp.interp_param[0] = f.model.m; // _M f.interp.interp_param[1] = 3; // x direction degree f.interp.interp_param[2] = 3; // y direction degree f.interp.interp_param[3] = 0; // z direction degree f.interp.interp_param[4] = 2; // x direction refinement f.interp.interp_param[5] = 2; // y direction refinement f.interp.interp_param[6] = 1; // z direction refinement // read the gmsh file ReadMacroMesh(&(f.macromesh),"test/testdisque2d.msh"); //ReadMacroMesh(&(f.macromesh),"geo/square.msh"); // try to detect a 2d mesh //bool is1d=Detect1DMacroMesh(&(f.macromesh)); Detect2DMacroMesh(&(f.macromesh)); bool is2d=f.macromesh.is2d; assert(is2d); // mesh preparation BuildConnectivity(&(f.macromesh)); PrintMacroMesh(&(f.macromesh)); //assert(1==2); //AffineMapMacroMesh(&(f.macromesh)); // prepare the initial fields Initfield(&f); f.nb_diags=0; // prudence... CheckMacroMesh(&(f.macromesh),f.interp.interp_param+1); printf("cfl param =%f\n",f.hmin); PoissonSolver ps; InitPoissonSolver(&ps,&f,_INDEX_PHI); SolvePoisson2D(&ps,_Dirichlet_Poisson_BC); real errl2 = L2error(&f); printf("Erreur L2=%f\n",errl2); test = test && (errl2 < 4e-4); printf("Plot...\n"); Plotfield(_INDEX_PHI, false, &f, NULL, "dgvisu.msh"); Plotfield(_INDEX_EX, false, &f, NULL, "dgex.msh"); return test; }