// ============================================================================ // Copyright Jean-Charles LAMBERT - 2007-2016 // Centre de donneeS Astrophysiques de Marseille (CeSAM) // e-mail: Jean-Charles.Lambert@lam.fr // address: Aix Marseille Universite, CNRS, LAM // Laboratoire d'Astrophysique de Marseille // Pole de l'Etoile, site de Chateau-Gombert // 38, rue Frederic Joliot-Curie // 13388 Marseille cedex 13 France // CNRS U.M.R 7326 // ============================================================================ #include #include #include #include #include #include "camr.h" #include "cfortio.h" #include "snapshotramses.h" namespace ramses { const double CAmr::XH = 0.76; const double CAmr::mH = 1.6600000e-24; const double CAmr::kB = 1.3806200e-16; // ============================================================================ // CAmr::CAmr(const std::string _indir, const bool _v) { nbody=0; //pos = mass = vel = NULL; verbose=_v; indir = _indir; infile=""; // keep filename untill last / int found=indir.find_last_of("/"); if (found != (int) std::string::npos && (int) indir.rfind("output_")0) { // remove trailing "/" s_run_index.erase(found,found); } infile = indir + "/amr_" + s_run_index + ".out00001"; testhydrofile = indir + "/hydro_" + s_run_index + ".out00001"; if (verbose) std::cerr << "Run index = " << s_run_index << " infile=[" << infile << "]\n"; } // readHeader if (amr.open(infile)) { readHeader(); amr.close(); } //computeNbody(); //loadData(); } // ============================================================================ // CAmr::~CAmr() { amr.close(); hydro.close(); } // ---------------------------------------------------------------------------- // bool CAmr::isValid() { if (amr.open(infile) && hydro.open(testhydrofile)) { valid=true; //readHeader(); amr.close(); hydro.close(); if (verbose) std::cerr << "ncpu="< (uns::CParticles * particles, const unsigned int req_bits); template int CAmr::loadData (uns::CParticles * particles, const unsigned int req_bits); template int CAmr::loadData(uns::CParticles * particles, const unsigned int req_bits) { int ngridfile [nlevelmax][ncpu+nboundary]; int ngridlevel [nlevelmax][ncpu ]; int ngridbound [nlevelmax][ nboundary]; double xc[3][8]; int ngrida; std::string infile; nbody = 0; bool count_only=false; //if (index==NULL) count_only=true; // loop on all cpus/files for (int icpu=0; icpu ["<0) { amr.skipBlock(2); amr.readDataBlock((char *) &ngridbound); // must convert the following line //ngridfile(ncpu+1:ncpu+nboundary,1:nlevelmax)=ngridbound for (int i=0;i ["<0) { xg = new double[ngrida*ndim]; son= new int [ngrida*twotondim]; if (!count_only) var= new double[ngrida*twotondim*nvarh]; } // Loop over domains for (int j=0; j<(nboundary+ncpu); j++) { if (ngridfile[ilevel][j]>0) { amr.skipBlock(); // Skip grid index amr.skipBlock(); // Skip next index amr.skipBlock(); // Skip prev index // // Read grid center // for (int idim=0;idim0) { // Read hydro variables for (int ind=0;ind0) { // Loop over cells for (int ind=0;ind 2) { pz=xg[2*ngrida+i]+xc[2][ind]-xbound[2]; // z } bool ok_cell = ( !(son[ind*ngrida+i]>0 && ilevel=lmin) && ((px+dx2)>=xmin) && ((py+dx2)>=ymin) && ((ndim<3) || ((pz+dx2)>=zmin)) && ((px-dx2)<=xmax) && ((py-dx2)<=ymax) && ((ndim<3) || ((pz-dx2)<=zmax))); if (ok_cell) { if (!count_only) { bool take=false; if (req_bits&POS_BIT) { particles->pos.push_back(px*header.boxlen); // x particles->pos.push_back(py*header.boxlen); // y if (ndim>2) particles->pos.push_back(pz*header.boxlen); // z else particles->pos.push_back(0.0); // z particles->load_bits |= POS_BIT; take=true; } if (req_bits&VEL_BIT) { particles->vel.push_back(var[1*ngrida*twotondim+ind*ngrida+i]); // vx particles->vel.push_back(var[2*ngrida*twotondim+ind*ngrida+i]); // vy if (ndim>2) particles->vel.push_back(var[3*ngrida*twotondim+ind*ngrida+i]); // vz else particles->vel.push_back(0.0); // vz particles->load_bits |= VEL_BIT; take=true; } // gas density double rho = var[0*ngrida*twotondim+ind*ngrida+i]; if (req_bits&MASS_BIT) { particles->mass.push_back(rho*dx*header.boxlen*dx*header.boxlen*dx*header.boxlen); particles->load_bits |= MASS_BIT; take=true; } if (req_bits&HSML_BIT) { particles->hsml.push_back(dx*header.boxlen); // hsml particles->load_bits |= HSML_BIT; } if (req_bits&RHO_BIT) { particles->rho.push_back(rho); // rho var(i,ind,1) * scale_nH particles->load_bits |= RHO_BIT; } // with RAMSES 2D simulations, variables from var[] array are shifted to the left int offset_2d=-1; if (ndim>2) offset_2d=0; if (req_bits&TEMP_BIT && nvarh>(4+offset_2d)) { double temp=0.0; if (rho!=0.0) { temp=std::max(0.0,var[(4+offset_2d)*ngrida*twotondim+ind*ngrida+i]/rho); } particles->temp.push_back(temp); particles->load_bits |= TEMP_BIT; } if (req_bits&METAL_BIT && nvarh>(5+offset_2d)) { double metal= var[(5+offset_2d)*ngrida*twotondim+ind*ngrida+i]; particles->metal.push_back(metal); particles->load_bits |= METAL_BIT; } if (req_bits&METAL_BIT && nvarh<=5) { double metal= -1.0; // we put -1.0 when no metellicity particles->metal.push_back(metal); particles->load_bits |= METAL_BIT; } if (req_bits&ID_BIT) { particles->id.push_back(-1.); // no id for gas, use "-1" particles->load_bits |= ID_BIT; } if (take|| !req_bits) { // !req_bits for uns_info and siplay=f particles->indexes.push_back(0); // GAS particles particles->ngas++; // One more gas particles } particles->ntot++; // one more total particles // this variable count all particles } nbody++; } else { // if (ilevel>=lmin) { // std::cerr << "Not ok lmin="<