Пример #1
0
int main(void) {
  field f;
  init_empty_field(&f);

  f.model.cfl = 0.05;
  f.model.m = 3; // only one conservative variable
  f.model.NumFlux = TransNumFlux2dwav;
  f.model.BoundaryFlux = TransBoundaryFlux2dwav;
  f.model.InitData = TransInitData2dwav;
  f.model.ImposedData = TransImposedData2dwav;
  f.varindex = GenericVarindex;

  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] = 4; // x direction refinement
  f.interp.interp_param[5] = 4; // y direction refinement
  f.interp.interp_param[6] = 1; // z direction refinement

  // Read the gmsh file
  ReadMacroMesh(&(f.macromesh), "disquetrou.msh");
  //ReadMacroMesh(&(f.macromesh), "geo/cube.msh");
  // Try to detect a 2d mesh
  Detect2DMacroMesh(&(f.macromesh));
  assert(f.macromesh.is2d);
  //PrintMacroMesh(&(f.macromesh));

  // Mesh preparation
  BuildConnectivity(&(f.macromesh));

  // AffineMapMacroMesh(&(f.macromesh));

  // Prepare the initial fields
  Initfield(&f);

  // prudence...
  CheckMacroMesh(&(f.macromesh), f.interp.interp_param + 1);

  printf("cfl param =%f\n", f.hmin);
 

  // Apply the DG scheme time integration by RK2 scheme up to final
  // time tmax.
  real tmax = 0.5;
  real dt = 0.;
  f.vmax = 0.1;
  if(dt <= 0.0)
    dt = set_dt(&f);
  RK2(&f, tmax, dt);

  // Save the results and the error
  Plotfield(0, false, &f, NULL, "dgvisu.msh");
  Plotfield(0, true, &f, "Error", "dgerror.msh");

  real dd = L2error(&f);
 
  printf("erreur L2=%f\n", dd);
  return 0;
};
Пример #2
0
int TestfieldRK2_2D()
{
  bool test = true;
  field f;
  init_empty_field(&f);

  f.model.cfl = 0.05;
  f.model.m = 1;
  f.model.NumFlux = TransNumFlux2d;
  f.model.BoundaryFlux = TransBoundaryFlux2d;
  f.model.InitData = TransInitData2d;
  f.model.ImposedData = TransImposedData2d;
  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] = 0; // 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/testdisque2d.msh");
  Detect2DMacroMesh(&f.macromesh);
  assert(f.macromesh.is2d);
  BuildConnectivity(&f.macromesh);
  
  Initfield(&f);

  CheckMacroMesh(&f.macromesh, f.interp.interp_param + 1);

  printf("cfl param =%f\n",f.hmin);

  real tmax = 0.1;
  f.vmax=1;
  real dt = 0;
  RK2(&f, tmax, dt);
 
  //Plotfield(0, false, &f, NULL, "dgvisu.msh");
  //Plotfield(0, true, &f, "error", "dgerror.msh");

  real dd = L2error(&f);

  printf("erreur L2=%f\n", dd);

  test = test && (dd < 0.01);

  return test;
}
Пример #3
0
int TestMaxwell2D()
{
  bool test = true;
  field f;
  init_empty_field(&f);

  f.model.cfl = 0.05;  
  f.model.m = 7; // num of conservative variables

  f.model.NumFlux = Maxwell2DNumFlux_uncentered;
  //f.model.NumFlux = Maxwell2DNumFlux_centered;
  f.model.BoundaryFlux = Maxwell2DBoundaryFlux_uncentered;
  f.model.InitData = Maxwell2DInitData;
  f.model.ImposedData = Maxwell2DImposedData;
  f.varindex = GenericVarindex;
  f.model.Source = Maxwell2DSource;
  
  f.interp.interp_param[0] = f.model.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] = 4; // x direction refinement
  f.interp.interp_param[5] = 4; // y direction refinement
  f.interp.interp_param[6] = 1; // z direction refinement

  ReadMacroMesh(&(f.macromesh), "../test/testcube.msh");

  Detect2DMacroMesh(&(f.macromesh));
  assert(f.macromesh.is2d);

  BuildConnectivity(&(f.macromesh));

  char buf[1000];
  sprintf(buf, "-D _M=%d", f.model.m);
  strcat(cl_buildoptions, buf);

  set_source_CL(&f, "Maxwell2DSource");
  sprintf(numflux_cl_name, "%s", "Maxwell2DNumFlux_uncentered");
  sprintf(buf," -D NUMFLUX=");
  strcat(buf, numflux_cl_name);
  strcat(cl_buildoptions, buf);

  sprintf(buf, " -D BOUNDARYFLUX=%s", "Maxwell2DBoundaryFlux_uncentered");
  strcat(cl_buildoptions, buf);

  Initfield(&f);
  
  CheckMacroMesh(&(f.macromesh), f.interp.interp_param + 1);

  real tmax = 0.1;
  f.vmax = 1;
  real dt = set_dt(&f);

#if 0
  // C version
  RK2(&f, tmax, dt);
#else
  // OpenCL version
  CopyfieldtoGPU(&f);
  RK2_CL(&f, tmax, dt, 0, 0, 0);
  CopyfieldtoCPU(&f);
  printf("\nOpenCL Kernel time:\n");
  show_cl_timing(&f);
  printf("\n");
#endif

  // Save the results and the error
  /* Plotfield(0, false, &f, NULL, "dgvisu.msh"); */
  /* Plotfield(0, true, &f, "error", "dgerror.msh"); */

  real dd = L2error(&f);
  real tolerance = 1.1e-2;
  test = test && (dd < tolerance);
  printf("L2 error: %f\n", dd);

  return test;
}
Пример #4
0
int TestCoil2D(void)
{
  bool test = true;
  field f;
  init_empty_field(&f);

  init_empty_field(&f);

  f.model.cfl = 0.2;  
  f.model.m = 7; // num of conservative variables

  f.model.NumFlux = Maxwell2DCleanNumFlux_upwind;
  f.model.BoundaryFlux = Coil2DBoundaryFlux;
  f.model.InitData = Coil2DInitData;
  f.model.ImposedData = Coil2DImposedData;
  f.varindex = GenericVarindex;
    
  f.interp.interp_param[0] = f.model.m;
  f.interp.interp_param[1] = 2; // x direction degree
  f.interp.interp_param[2] = 2; // y direction degree
  f.interp.interp_param[3] = 0; // z direction degree
  f.interp.interp_param[4] = 4; // x direction refinement
  f.interp.interp_param[5] = 4; // y direction refinement
  f.interp.interp_param[6] = 1; // z direction refinement

  // Read the gmsh file
  ReadMacroMesh(&f.macromesh, "../test/testmacromesh.msh");
  // Try to detect a 2d mesh
  Detect2DMacroMesh(&f.macromesh);
  assert(f.macromesh.is2d);

  // Mesh preparation
  BuildConnectivity(&(f.macromesh));

  //AffineMapMacroMesh(&(f.macromesh));
 
  // Prepare the initial fields
  Initfield(&f);
  f.model.Source = Coil2DSource;
  f.pre_dtfield = coil_pre_dtfield;
  //f.dt = 1e-3;
  
  // Prudence...
  CheckMacroMesh(&(f.macromesh), f.interp.interp_param + 1);

  printf("cfl param =%f\n", f.hmin);

  // time derivative
  //dtfield(&f);
  //Displayfield(&f);
 
  // init the particles on a circle
  PIC pic;
  InitPIC(&pic, 100);
  CreateCoil2DParticles(&pic, &f.macromesh);
  PlotParticles(&pic, &f.macromesh);

  f.pic = &pic;

  // time evolution
  real tmax = 0.1;
  f.vmax = 1;
  real dt = set_dt(&f);
  RK2(&f, tmax, dt);
 
  // Save the results and the error
  //Plotfield(2, false, &f, NULL, "dgvisu.msh");
  //Plotfield(2, true, &f, "error", "dgerror.msh");

  real dd = L2error(&f);
  real tolerance = 0.3;
  test = test && (dd < tolerance);
  printf("L2 error: %f\n", dd);

  return test;
}
Пример #5
0
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;

}
Пример #6
0
int TestmEq2(void) {
  bool test = true;
  field f;
  init_empty_field(&f);
 
  int vec = 2;

  f.model.cfl = 0.05;  
  if(vec == 2) {
    f.model.m = 2; // num of conservative variables
  } else {
    f.model.m = 1; // num of conservative variables
  }
  f.model.NumFlux = VecTransNumFlux2d;
  f.model.BoundaryFlux = VecTransBoundaryFlux2d;
  f.model.InitData = VecTransInitData2d;
  f.model.ImposedData = VecTransImposedData2d;
  f.varindex = GenericVarindex;
    
  f.interp.interp_param[0] = f.model.m;
  f.interp.interp_param[1] = 2; // x direction degree
  f.interp.interp_param[2] = 2; // y direction degree
  f.interp.interp_param[3] = 0; // z direction degree
  f.interp.interp_param[4] = 4; // x direction refinement
  f.interp.interp_param[5] = 4; // 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
  Detect2DMacroMesh(&(f.macromesh));
  assert(f.macromesh.is2d);

  // Mesh preparation
  BuildConnectivity(&(f.macromesh));

  //AffineMapMacroMesh(&(f.macromesh));
 
  // Prepare the initial fields
  
  Initfield(&f);
  //f.dt = 1e-3;
  
  // Prudence...
  CheckMacroMesh(&(f.macromesh), f.interp.interp_param + 1);

  printf("cfl param =%f\n", f.hmin);

  // time derivative
  //dtfield(&f);
  //Displayfield(&f);
 
  real tmax = 0.1;
  f.vmax=1;
  real dt = set_dt(&f);
  RK2(&f, tmax, dt);
 
  // Save the results and the error
  Plotfield(0, false, &f, NULL, "dgvisu.msh");
  Plotfield(0, true, &f, "error", "dgerror.msh");

  real dd = L2error(&f);
  real tolerance = 1e-4;
  test = test && (dd < tolerance);
  printf("L2 error: %f\n", dd);

  return test;
};
Пример #7
0
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;
}