예제 #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
void ReadFieldsH5hut(int nspec, bool readext, EMfields3D *EMf, Collective *col, VCtopology3D *vct, Grid3DCU *grid){
#ifdef USEH5HUT

  H5input infile;

  infile.SetNameCycle(col->getinitfile(), col->getLast_cycle());

  infile.OpenFieldsFile("Node", nspec, col->getNxc()+1,
                                       col->getNyc()+1,
                                       col->getNzc()+1,
                                       vct->getCoordinates(),
                                       vct->getDivisions(),
                                       vct->getComm());

  infile.ReadFields(EMf->getEx(), "Ex", grid->getNXN(), grid->getNYN(), grid->getNZN());
  infile.ReadFields(EMf->getEy(), "Ey", grid->getNXN(), grid->getNYN(), grid->getNZN());
  infile.ReadFields(EMf->getEz(), "Ez", grid->getNXN(), grid->getNYN(), grid->getNZN());
  infile.ReadFields(EMf->getBx(), "Bx", grid->getNXN(), grid->getNYN(), grid->getNZN());
  infile.ReadFields(EMf->getBy(), "By", grid->getNXN(), grid->getNYN(), grid->getNZN());
  infile.ReadFields(EMf->getBz(), "Bz", grid->getNXN(), grid->getNYN(), grid->getNZN());

  if (readext) {
    infile.ReadFields(EMf->getBx_ext(), "Btx", grid->getNXN(), grid->getNYN(), grid->getNZN());
    infile.ReadFields(EMf->getBy_ext(), "Bty", grid->getNXN(), grid->getNYN(), grid->getNZN());
    infile.ReadFields(EMf->getBz_ext(), "Btz", grid->getNXN(), grid->getNYN(), grid->getNZN());
  }

  for (int is = 0; is < nspec; is++){
    std::stringstream  ss;
    ss << is;
    std::string s_is = ss.str();
    infile.ReadFields(EMf->getRHOns(is), "rho_"+s_is, grid->getNXN(), grid->getNYN(), grid->getNZN());
  }

  infile.CloseFieldsFile();

  // initialize B on centers
//  MPI_Barrier(MPI_COMM_WORLD); // This is time-consuming and should be debug code, only!

  // Comm ghost nodes for B-field
  communicateNodeBC(grid->getNXN(), grid->getNYN(), grid->getNZN(), EMf->getBx(), col->bcBx[0],col->bcBx[1],col->bcBx[2],col->bcBx[3],col->bcBx[4],col->bcBx[5], vct);
  communicateNodeBC(grid->getNXN(), grid->getNYN(), grid->getNZN(), EMf->getBy(), col->bcBy[0],col->bcBy[1],col->bcBy[2],col->bcBy[3],col->bcBy[4],col->bcBy[5], vct);
  communicateNodeBC(grid->getNXN(), grid->getNYN(), grid->getNZN(), EMf->getBz(), col->bcBz[0],col->bcBz[1],col->bcBz[2],col->bcBz[3],col->bcBz[4],col->bcBz[5], vct);

  grid->interpN2C(EMf->getBxc(), EMf->getBx());
  grid->interpN2C(EMf->getByc(), EMf->getBy());
  grid->interpN2C(EMf->getBzc(), EMf->getBz());


  // communicate E
  communicateNodeBC(grid->getNXN(), grid->getNYN(), grid->getNZN(), EMf->getEx(), col->bcEx[0],col->bcEx[1],col->bcEx[2],col->bcEx[3],col->bcEx[4],col->bcEx[5], vct);
  communicateNodeBC(grid->getNXN(), grid->getNYN(), grid->getNZN(), EMf->getEy(), col->bcEy[0],col->bcEy[1],col->bcEy[2],col->bcEy[3],col->bcEy[4],col->bcEy[5], vct);
  communicateNodeBC(grid->getNXN(), grid->getNYN(), grid->getNZN(), EMf->getEz(), col->bcEz[0],col->bcEz[1],col->bcEz[2],col->bcEz[3],col->bcEz[4],col->bcEz[5], vct);

  for (int is = 0; is < nspec; is++)
    grid->interpN2C(EMf->getRHOcs(), is, EMf->getRHOns());

//---READ FROM THE CELLS:
//
//  infile.OpenFieldsFile("Cell", nspec, col->getNxc(),
//                                       col->getNyc(),
//                                       col->getNzc(),
//                                       vct->getCoordinates(),
//                                       vct->getDivisions(),
//                                       vct->getComm());
//
//  infile.ReadFields(EMf->getExc(), "Exc", grid->getNXC(), grid->getNYC(), grid->getNZC());
//  infile.ReadFields(EMf->getEyc(), "Eyc", grid->getNXC(), grid->getNYC(), grid->getNZC());
//  infile.ReadFields(EMf->getEzc(), "Ezc", grid->getNXC(), grid->getNYC(), grid->getNZC());
//  infile.ReadFields(EMf->getBxc(), "Bxc", grid->getNXC(), grid->getNYC(), grid->getNZC());
//  infile.ReadFields(EMf->getByc(), "Byc", grid->getNXC(), grid->getNYC(), grid->getNZC());
//  infile.ReadFields(EMf->getBzc(), "Bzc", grid->getNXC(), grid->getNYC(), grid->getNZC());
//
//  for (int is = 0; is < nspec; is++){
//    std::stringstream  ss;
//    ss << is;
//    std::string s_is = ss.str();
//    infile.ReadFields(EMf->getRHOcs(is, 0), "rhoc_"+s_is, grid->getNXC(), grid->getNYC(), grid->getNZC());
//  }
//
//  infile.CloseFieldsFile();
//
//  // initialize B on nodes
//  grid->interpC2N(EMf->getBx(), EMf->getBxc());
//  grid->interpC2N(EMf->getBy(), EMf->getByc());
//  grid->interpC2N(EMf->getBz(), EMf->getBzc());
//
//  for (int is = 0; is < nspec; is++)
//    grid->interpC2N(EMf->getRHOns(), is, EMf->getRHOcs());
//
//---END READ FROM THE CELLS

#endif
}
예제 #3
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;
}