/*! Function to write the EM fields using the H5hut library. */ void WriteFieldsH5hut(int nspec, Grid3DCU *grid, EMfields3D *EMf, Collective *col, VCtopology3D *vct, int cycle){ #ifdef USEH5HUT H5output file; /* ---------------- */ /* Write the fields */ /* ---------------- */ string filename = col->getSaveDirName() + "/" + col->getSimName(); file.SetNameCycle(filename, cycle); file.OpenFieldsFile("Node", nspec, col->getNxc()+1, col->getNyc()+1, col->getNzc()+1, vct->getCoordinates(), vct->getDivisions(), vct->getComm()); file.WriteFields(EMf->getEx(), "Ex", grid->getNXN(), grid->getNYN(), grid->getNZN()); file.WriteFields(EMf->getEy(), "Ey", grid->getNXN(), grid->getNYN(), grid->getNZN()); file.WriteFields(EMf->getEz(), "Ez", grid->getNXN(), grid->getNYN(), grid->getNZN()); file.WriteFields(EMf->getBx(), "Bx", grid->getNXN(), grid->getNYN(), grid->getNZN()); file.WriteFields(EMf->getBy(), "By", grid->getNXN(), grid->getNYN(), grid->getNZN()); file.WriteFields(EMf->getBz(), "Bz", grid->getNXN(), grid->getNYN(), grid->getNZN()); file.WriteFields(EMf->getBxTot(), "Btx", grid->getNXN(), grid->getNYN(), grid->getNZN()); file.WriteFields(EMf->getByTot(), "Bty", grid->getNXN(), grid->getNYN(), grid->getNZN()); file.WriteFields(EMf->getBzTot(), "Btz", grid->getNXN(), grid->getNYN(), grid->getNZN()); //file.WriteFields(EMf->GetLambda(), "Lambda", grid->getNXN(), grid->getNYN(), grid->getNZN()); for (int is=0; is<nspec; is++) { stringstream ss; ss << is; string s_is = ss.str(); file.WriteFields(EMf->getRHOns(is), "rho_"+ s_is, grid->getNXN(), grid->getNYN(), grid->getNZN()); file.WriteFields(EMf->getJxs(is), "Jx_" + s_is, grid->getNXN(), grid->getNYN(), grid->getNZN()); file.WriteFields(EMf->getJys(is), "Jy_" + s_is, grid->getNXN(), grid->getNYN(), grid->getNZN()); file.WriteFields(EMf->getJzs(is), "Jz_" + s_is, grid->getNXN(), grid->getNYN(), grid->getNZN()); } file.CloseFieldsFile(); //--- SAVE FIELDS IN THE CELLS: // // file.OpenFieldsFile("Cell", nspec, col->getNxc(), col->getNyc(), col->getNzc(), vct->getCoordinates(), vct->getDivisions(), vct->getComm()); // // file.WriteFields(EMf->getExc(), "Exc", grid->getNXC(), grid->getNYC(), grid->getNZC()); // file.WriteFields(EMf->getEyc(), "Eyc", grid->getNXC(), grid->getNYC(), grid->getNZC()); // file.WriteFields(EMf->getEzc(), "Ezc", grid->getNXC(), grid->getNYC(), grid->getNZC()); // file.WriteFields(EMf->getBxc(), "Bxc", grid->getNXC(), grid->getNYC(), grid->getNZC()); // file.WriteFields(EMf->getByc(), "Byc", grid->getNXC(), grid->getNYC(), grid->getNZC()); // file.WriteFields(EMf->getBzc(), "Bzc", grid->getNXC(), grid->getNYC(), grid->getNZC()); // // for (int is=0; is<nspec; is++) { // stringstream ss; // ss << is; // string s_is = ss.str(); // file.WriteFields(EMf->getRHOcs(is), "rhoc_"+ s_is, grid->getNXC(), grid->getNYC(), grid->getNZC()); // } // // file.CloseFieldsFile(); // //--- END SAVE FIELDS IN THE CELLS. #else cout << " ERROR: The input file request the use of the H5hut library, but the code has been compiled using other method. " << endl; cout << " Recompile the code using the H5hut options or change the input file. " << endl; abort(); #endif }
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; }