예제 #1
0
void ReadPartclH5hut(int nspec, Particles3Dcomm *part, Collective *col, VCtopology3D *vct, Grid3DCU *grid){
#ifdef USEH5HUT

  H5input infile;
  double L[3] = {col->getLx(), col->getLy(), col->getLz()};

  infile.SetNameCycle(col->getinitfile(), col->getLast_cycle());
  infile.OpenPartclFile(nspec, vct->getCartesian_rank(), vct->getNproc(), vct->getComm());

  for (int s = 0; s < nspec; s++){

    infile.ReadParticles(vct->getCartesian_rank(),
                         vct->getNproc(),      s, 
                         vct->getDivisions(),  L,
                         vct->getComm());

    part[s].allocate(s, infile.get_nops(), col, vct, grid);

    infile.LoadParticles(infile.get_nops(), vct->getCartesian_rank(),
                         vct->getNproc(),      s,
                         vct->getDivisions(),  L,
                         vct->getComm(),
                         part[s].getQall(),
                         part[s].getXall(),
                         part[s].getYall(),
                         part[s].getZall(),
                         part[s].getUall(),
                         part[s].getVall(),
                         part[s].getWall());

  }
  infile.ClosePartclFile();

//--- TEST PARTICLE LECTURE:
//  for (int s = 0; s < nspec; s++){
//    for (int n = 0; n < part[s].getNOP(); n++){
//      double ix = part[s].getX(n);
//      double iy = part[s].getY(n);
//      double iz = part[s].getZ(n);
//      if (ix<=0 || iy<=0 || iz <=0) {
//        cout << " ERROR: This particle has negative position. " << endl;
//        cout << "        n = " << n << "/" << part[s].getNOP();
//        cout << "       ix = " << ix;
//        cout << "       iy = " << iy;
//        cout << "       iz = " << iz;
//      }
//    }
//  }
//--- END TEST

#endif
}
예제 #2
0
파일: h5hut-test.cpp 프로젝트: CmPA/iPic3D
int main (int argc, char *argv[])
{
  int       rank, size;
  int       *perio;
  int       *dimns;
  int       *coord;
  int       cycle0   = 0;
  int       tsave    = 100;
  int       ncycle   = 200;
  int       ndim     = 3;
  int       reorder  = 1;
  int       nspec    = 2;
  int       ntcx     = 64;
  int       ntcy     = 64;
  int       ntcz     = 64;
  int       ntxn;
  int       ntyn;
  int       ntzn;
  double    Lx       = 10.0;
  double    Ly       = 10.0;
  double    Lz       = 10.0;
  double    L[3];
  MPI_Comm  CART_COMM;
  Fields    EMf;
  H5input   file;
  H5output  outfile;
  H5hutpart *myPart;

  /* -------------------------- */
  /* Initialize MPI environment */
  /* -------------------------- */

  perio = new int[ndim];
  dimns = new int[ndim];
  coord = new int[ndim];

  MPI_Init (&argc, &argv);
  MPI_Comm_size  (MPI_COMM_WORLD, &size);
  if (ndim==3) MPI_Dims_create(size, 3, dimns);
  else         MPI_Dims_create(size, 2, dimns);
  MPI_Cart_create(MPI_COMM_WORLD, ndim, dimns, perio, reorder, &CART_COMM);
  MPI_Comm_rank  (CART_COMM,&rank);
  MPI_Cart_coords(CART_COMM, rank, ndim, coord);

  /* ------------------------- */
  /* Set simulation conditions */
  /* ------------------------- */

  ntxn = ntcx + 1;
  ntyn = ntcy + 1;
  ntzn = ntcz + 1;

  int nxc = (ntcx / dimns[0]) + 2;
  int nyc = (ntcy / dimns[1]) + 2;
  int nzc = (ntcz / dimns[2]) + 2;
  int nxn = nxc + 1;
  int nyn = nyc + 1;
  int nzn = nzc + 1;

  L[0] = Lx;
  L[1] = Ly;
  L[2] = Lz;

  /* ------------------ */
  /* Read the particles */
  /* ------------------ */

  file.SetNameCycle("GEMtest", cycle0);

  myPart = new H5hutpart[nspec];

  file.OpenPartclFile(nspec);
  file.ReadParticles(rank, size, dimns, L, CART_COMM);

  for (int s = 0; s < nspec; s++){
    myPart[s].memalloc(file.GetNp(s));

    file.DumpPartclX(myPart[s].getXref(), s);
    file.DumpPartclY(myPart[s].getYref(), s);
    file.DumpPartclZ(myPart[s].getZref(), s);
    file.DumpPartclU(myPart[s].getUref(), s);
    file.DumpPartclV(myPart[s].getVref(), s);
    file.DumpPartclW(myPart[s].getWref(), s);
    file.DumpPartclQ(myPart[s].getQref(), s);
  }
  file.ClosePartclFile();

  /* --------------- */
  /* Read the fields */
  /* --------------- */

  EMf.Init(nspec, nxc, nyc, nzc);

  file.OpenFieldsFile("Node", nspec, ntxn, ntyn, ntzn, coord, dimns, CART_COMM);
  file.ReadFields(EMf.getEx(), "Ex", nxn, nyn, nzn);
  file.ReadFields(EMf.getEy(), "Ey", nxn, nyn, nzn);
  file.ReadFields(EMf.getEz(), "Ez", nxn, nyn, nzn);
  file.ReadFields(EMf.getBx(), "Bx", nxn, nyn, nzn);
  file.ReadFields(EMf.getBy(), "By", nxn, nyn, nzn);
  file.ReadFields(EMf.getBz(), "Bz", nxn, nyn, nzn);
  file.CloseFieldsFile();

  /* -------------------------------------- */
  /* Empty simulation with multiple outputs */
  /* -------------------------------------- */

  for (int t = cycle0; t <= cycle0+ncycle; t++) {

    std::cout << " Cycle: " << t << std::endl;
    /* here goes the computation */

    if (t%tsave==0) {

      outfile.SetNameCycle("Output", t);

      /* ----------- */
      /* Save fields */
      /* ----------- */

      outfile.OpenFieldsFile("Node", nspec, ntxn, ntyn, ntzn, coord, dimns, CART_COMM);
      outfile.WriteFields(EMf.getEx(), "Ex", nxn, nyn, nzn);
      outfile.WriteFields(EMf.getEy(), "Ey", nxn, nyn, nzn);
      outfile.WriteFields(EMf.getEz(), "Ez", nxn, nyn, nzn);
      outfile.WriteFields(EMf.getBx(), "Bx", nxn, nyn, nzn);
      outfile.WriteFields(EMf.getBy(), "By", nxn, nyn, nzn);
      outfile.WriteFields(EMf.getBz(), "Bz", nxn, nyn, nzn);
      outfile.CloseFieldsFile();

      /* -------------- */
      /* Save particles */
      /* -------------- */

      outfile.OpenPartclFile(nspec, CART_COMM);
      for (int i=0; i<nspec; i++) {
        outfile.WriteParticles(i, myPart[i].getNP(),
                                  myPart[i].getQ(),
                                  myPart[i].getX(),
                                  myPart[i].getY(),
                                  myPart[i].getZ(),
                                  myPart[i].getU(),
                                  myPart[i].getV(),
                                  myPart[i].getW(),
                                  CART_COMM);
      }
      outfile.ClosePartclFile();
    }
  }

  std::cout << rank << " : Freeing memory..." << std::endl;

  delete [] myPart;
  delete [] perio;
  delete [] dimns;
  delete [] coord;

  std::cout << rank << " : Finalizing MPI" << std::endl;

  MPI_Finalize();

  return 0;
}