From 678963fa6fad93d796eff03d0f1737d4a2d52d54 Mon Sep 17 00:00:00 2001 From: jclamber Date: Wed, 12 Sep 2012 18:52:11 +0000 Subject: [PATCH] ramses in progress... git-svn-id: http://svn.oamp.fr/repos/unsio/trunk@104 ce2cc22f-6084-46ce-a062-084b172ee5dc --- core/src/camr.cc | 348 ++++++++++++++++++++++++++++++++++ core/src/camr.h | 78 ++++++++ core/src/cfortio.cc | 56 ++++++ core/src/cfortio.h | 99 ++++++++++ core/src/cpart.cc | 378 +++++++++++++++++++++++++++++++++++++ core/src/cpart.h | 69 +++++++ core/src/snapshotramses.cc | 260 +++++++++++++++++++++++-- core/src/snapshotramses.h | 4 + core/src/uns.cc | 14 +- core/src/uns.h | 5 + core/src/userselection.cc | 24 ++- core/src/userselection.h | 8 + 12 files changed, 1326 insertions(+), 17 deletions(-) create mode 100644 core/src/camr.cc create mode 100644 core/src/camr.h create mode 100644 core/src/cfortio.cc create mode 100644 core/src/cfortio.h create mode 100644 core/src/cpart.cc create mode 100644 core/src/cpart.h diff --git a/core/src/camr.cc b/core/src/camr.cc new file mode 100644 index 0000000..02a0dcc --- /dev/null +++ b/core/src/camr.cc @@ -0,0 +1,348 @@ +// ============================================================================ +// Copyright Jean-Charles LAMBERT - 2007-2012 +// e-mail: Jean-Charles.Lambert@oamp.fr +// address: Dynamique des galaxies +// 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"; + if (verbose) + std::cerr << "Run index = " << s_run_index << " infile=[" << infile << "]\n"; + } + //computeNbody(); + //loadData(); +} +// ============================================================================ +// +CAmr::~CAmr() +{ +} +// ---------------------------------------------------------------------------- +// +bool CAmr::isValid() +{ + if (amr.open(infile)) { + valid=true; + readHeader(); + amr.close(); + if (verbose) + std::cerr << "ncpu="< ["<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;ind0 && ilevel=lmin) && + ((px+dx2)>=xmin) && + ((py+dx2)>=ymin) && + ((pz+dx2)>=zmin) && + ((px-dx2)<=xmax) && + ((py-dx2)<=ymax) && + ((pz-dx2)<=zmax) ); + if (ok_cell) { + if (!count_only) { +#if 0 + int idx=index[nbody]; + if (idx!=-1) { // it's a valide particle + pos[3*cpt+0] = px; + pos[3*cpt+1] = py; + pos[3*cpt+2] = pz; + rneib[cpt] = dx; + rho[cpt] = var[0*ngrida*twotondim+ind*ngrida+i]; +#if 1 + temp[cpt]= std::max(0.0,var[4*ngrida*twotondim+ind*ngrida+i]/rho[cpt]); + //temp[cpt]= var[4*ngrida*twotondim+ind*ngrida+i]/rho[cpt]; +#else + float p=var[4*ngrida*twotondim+ind*ngrida+i]; // pressure + float alpha=0.28; // fraction of He in mass + float mu=4./(8.-5.*alpha); + float mh=1.67e-24; // proton mass in g + float kb=1.38e-16; // Boltzmann constant in erg.K-1 + temp[cpt]= mu*mh/kb*p/rho[cpt]*1.e14; // Temperature en K + //temp[cpt] /= (11604.5/1000.); // Temperature en Kev + temp[cpt]=std::max((float)0.0,temp[cpt]); + +#endif + cpt++; + } +#else + bool take=false; + if (req_bits&POS_BIT) { + particles->pos.push_back(px); // x + particles->pos.push_back(py); // y + particles->pos.push_back(pz); // z + particles->load_bits |= POS_BIT; + take=true; + } + if (req_bits&VEL_BIT) { + particles->vel.push_back(-666.); // vx + particles->vel.push_back(-666.); // vy + particles->vel.push_back(-666.); // vz + particles->load_bits |= VEL_BIT; + take=true; + } + if (req_bits&MASS_BIT) { + particles->mass.push_back(-666.); + particles->load_bits |= MASS_BIT; + take=true; + } + if (req_bits&HSML_BIT) { + particles->hsml.push_back(dx); // hsml + particles->load_bits |= HSML_BIT; + } + float rho = var[0*ngrida*twotondim+ind*ngrida+i]; + float temp= std::max(0.0,var[4*ngrida*twotondim+ind*ngrida+i]/rho); + if (req_bits&RHO_BIT) { + particles->rho.push_back(rho); // rho var(i,ind,1) * scale_nH + particles->load_bits |= RHO_BIT; + } + if (req_bits&TEMP_BIT) { + particles->temp.push_back(temp); + particles->load_bits |= TEMP_BIT; + } + if (take) { + particles->indexes.push_back(0); // GAS particles + particles->ngas++; // One more gas particles + particles->ntot++; // one more total particles + } +#endif + } + nbody++; + } + } + } + // garbage collecting + delete [] xg; + //delete [] x; + delete [] son; + if (!count_only) + delete [] var; + } + } // ilevel + amr.close(); + hydro.close(); + } //for (int icpu=0 .... + return nbody; +} +} // end of namespace ramses diff --git a/core/src/camr.h b/core/src/camr.h new file mode 100644 index 0000000..bd4dbf0 --- /dev/null +++ b/core/src/camr.h @@ -0,0 +1,78 @@ +// ============================================================================ +// Copyright Jean-Charles LAMBERT - 2007-2012 +// e-mail: Jean-Charles.Lambert@oamp.fr +// address: Dynamique des galaxies +// 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 +// ============================================================================ + +/* + @author Jean-Charles Lambert + */ +#ifndef CAMR_H +#define CAMR_H + +#include +#include +#include +#include +#include +#include "cfortio.h" +#include "snapshotramses.h" + +namespace uns { +class CParticles; +} +namespace ramses { +class CAmr { +public: + CAmr(const std::string,const bool _v=true); + + ~CAmr(); + void setBoundary(float x[8]) { + xmin=x[0]; + xmax=x[1]; + ymin=x[2]; + ymax=x[3]; + zmin=x[4]; + zmax=x[5]; + + if (x[7]==0.) { + lmax= nlevelmax; + } else { + lmax = (int) x[7]; + } + lmin = std::min((int) x[6],lmax-1); + } + bool isValid(); + int loadData(uns::CParticles * particles, + const unsigned int req_bits); + int getNbody() { return nbody;} + +private: + // some variables + + bool verbose,valid; + std::string infile,indir; + int select,nselect; + int nbody; + std::string s_run_index,ordering; + + float xmin,xmax,ymin,ymax,zmin,zmax; + int lmin,lmax; + CFortIO amr, hydro; + int readHeader(); + // amr header variables + static const double XH, mH, kB; + int ncpu, ndim, nx, ny ,nz, nlevelmax, ngridmax, nboundary, ngrid_current; + int twotondim; + double xbound[3]; + // hydro + int nvarh; + double scale_nH; +}; +} // end of namespace +#endif // CAMR_H diff --git a/core/src/cfortio.cc b/core/src/cfortio.cc new file mode 100644 index 0000000..90367ea --- /dev/null +++ b/core/src/cfortio.cc @@ -0,0 +1,56 @@ +// ============================================================================ +// Copyright Jean-Charles LAMBERT - 2007-2012 +// e-mail: Jean-Charles.Lambert@oamp.fr +// address: Dynamique des galaxies +// 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 +// ============================================================================ + +/* + @author Jean-Charles Lambert + */ +#include +#include +#include +#include "cfortio.h" +// ============================================================================ +// +CFortIO::CFortIO() +{ +} +// ============================================================================ +// +CFortIO::~CFortIO() +{ + close(); +} +// ============================================================================ +// +void CFortIO::close() +{ + if (!fake_reading && in.is_open()) { + in.close(); + } +} +// ============================================================================ +// open() : +// open file and return : +int CFortIO::open(const std::string myfile, bool fake,bool _swap) +{ + int ret=1; + fake_reading = fake; + infile = myfile; + swap = _swap; + if (!fake_reading) { + in.clear(); + in.open(myfile.c_str(),std::ios::in | std::ios::binary); + if ( ! in.is_open()) { + std::cerr << "Unable to open file ["< + */ +#ifndef CFORTIO_H +#define CFORTIO_H + +#include +#include +#include +#include + +#define CHAR 1 +class CFortIO +{ +public: + CFortIO(); + ~CFortIO(); + int open(const std::string myfile, bool _fake=false,bool _swap=false); + void close(); + bool good() { + if (!fake_reading) return in.good(); + else return true;} + inline int readDataBlock(char * ptr) { + if (!fake_reading) { + int len1=readFRecord(); + readData(ptr,1,len1); + int len2=readFRecord(); + assert(good() && len1==len2); + return len1; + } else return 1; + } + inline int readData(char * ptr,const size_t size_bytes,const int items) { + if (!fake_reading) { + // get data from file + in.read(ptr,size_bytes*items); + //assert(in.good()); + if (! in.good()) return 0; + + // We SWAP data + if (swap && (size_bytes != CHAR)) { // swapping requested + for (int i=0; i +#include +#include +#include "cpart.h" +namespace ramses { + using namespace std; +// ---------------------------------------------------------------------------- +// READING constructor +CPart::CPart(const std::string _indir, const bool _v) +{ + valid=false; + nbody = 0; + ndm = 0; + ndm_box = 0; + nstar_box = 0; + nselect = 0; + verbose=_v; + indir = _indir; + infile=""; + + // keep filename untill last / + int found=indir.find_last_of("/"); + if (found != (int) string::npos && (int) indir.rfind("output_")0) { // remove trailing "/" + s_run_index.erase(found,found); + } + if (verbose) + std::cerr << "Run index = " << s_run_index << "\n"; + infile = indir + "/part_" + s_run_index + ".out00001"; + if (verbose) + std::cerr << "infile =" << infile <<"\n"; + } +} + +// ---------------------------------------------------------------------------- +// Destructor +CPart::~CPart() +{ + +} +// ---------------------------------------------------------------------------- +// +bool CPart::isValid() +{ + if (part.open(infile)) { + valid=true; + readHeader(); + part.close(); + } + else + valid=false; + return valid; +} + +// ============================================================================ +// readHeader +int CPart::readHeader() +{ + part.readDataBlock((char *) &ncpu); + part.readDataBlock((char *) &ndim); + part.readDataBlock((char *) &npart); + part.skipBlock(); + part.readDataBlock((char *) &nstar); + return 1; +} +// ============================================================================ +// loadData +int CPart::loadData(uns::CParticles * particles, + const unsigned int req_bits, const unsigned int comp_bits) +{ + int offset=0; + for (int i=0; i0) { // || 1) { // there are stars + part.skipBlock(); // skip identity + part.skipBlock(); // skip level + agetmp = new double[npart]; + part.readDataBlock((char *) agetmp); + for (int k=0; k=xmin && tmp[0][k]<=xmax) && + (tmp[1][k]>=ymin && tmp[1][k]<=ymax) && + (tmp[2][k]>=zmin && tmp[2][k]<=zmax)) { + + bool take=false; + for (int l=0;l<3;l++) { + if (req_bits&POS_BIT) { + particles->pos.push_back(tmp[l][k]); + particles->load_bits |= POS_BIT; + take=true; + } + if (req_bits&VEL_BIT) { + particles->vel.push_back(tmp[3+l][k]); + particles->load_bits |= VEL_BIT; + take=true; + } + } + if (req_bits&MASS_BIT) { + particles->mass.push_back(tmp[6][k]); + particles->load_bits |= MASS_BIT; + take=true; + } + if (agetmp[k]!=0 && req_bits&AGE_BIT) { // stars only + particles->age.push_back(agetmp[k]); + particles->load_bits |= AGE_BIT; + } + if (take && agetmp[k]!=0) { + particles->indexes.push_back(4); // save star positions + particles->nstars++; + particles->ntot++; // one more total particles + } + if (take && agetmp[k]==0) { + particles->indexes.push_back(1); // save DM positions + particles->ndm++; + particles->ntot++; // one more total particles + } + + offset++; + //assert(offset<=nselect); + } + } + } + // garbage + delete [] agetmp; + } + else { // there are no stars + if (comp_bits&HALO_BIT) { // DM sel + for (int k=0; k=xmin && tmp[0][k]<=xmax) && + (tmp[1][k]>=ymin && tmp[1][k]<=ymax) && + (tmp[2][k]>=zmin && tmp[2][k]<=zmax)) { + bool take=false; + for (int l=0;l<3;l++) { + if (req_bits&POS_BIT) { + particles->pos.push_back(tmp[l][k]); + take=true; + } + if (req_bits&VEL_BIT) { + particles->vel.push_back(tmp[3+l][k]); + take=true; + } + } + if (req_bits&MASS_BIT) { + particles->mass.push_back(tmp[6][k]); + take=true; + } + if (take) { + particles->indexes.push_back(1); // save DM positions + particles->ndm++; + particles->ntot++; // one more total particles + } + offset++; + //assert(offset<=nselect); + } + } + } + } + // garbage collecting + for (int i=0; i<7; i++) + delete [] tmp[i]; + part.close(); // close current file + } // for ... +#if 0 + int cpt_dm=0; + int cpt_star=0; + bool count_only=false; + + //if (nsel) {;} // remove compiler warning + +#if 0 + if (index==NULL) { + ndm_box=0; + nstar_box=0; + count_only=true; + nselect=0; + } + else { + //assert(nsel==nselect); + } +#endif + nbody=0; + + for (int i=0; i0) { // there are stars + part.skipBlock(); // skip identity + part.skipBlock(); // skip level + age = new double[npart]; + part.readDataBlock((char *) age); + for (int k=0; k=xmin && tmp[0][k]<=xmax) && + (tmp[1][k]>=ymin && tmp[1][k]<=ymax) && + (tmp[2][k]>=zmin && tmp[2][k]<=zmax)) { + + if (count_only) { + if (age[k]==0) { // it's DM + ndm_box++; + } else { // it's a star + nstar_box++; + } + nselect++; + } + else { + int idx=666;//index[nbody]; + if (idx!=-1) { // it's a valid particle + if (take_halo && age[k]==0) { // DM selected and it's a DM + int cpt = namr_box+cpt_dm; + assert(cpt<(nselect+namr_box)); + for (int l=0;l<3;l++) { + pos[cpt*3+l]=tmp[l][k]; + if (load_vel) { + vel[cpt*3+l]=tmp[3+l][k]; + } + } + cpt_dm++; + } + if (take_stars && age[k]!=0) { // STARS selected and it's a star + int cpt = namr_box+(take_halo?ndm_box:0)+cpt_star; + assert(cpt<(nselect+namr_box)); + for (int l=0;l<3;l++) { + pos[cpt*3+l]=tmp[l][k]; + if (load_vel) { + vel[cpt*3+l]=tmp[3+l][k]; + } + } + cpt_star++; + } + + } + nbody++; + } + } + } + } + // garbage + delete [] age; + } + else { // there are no stars + if (select==0 || select==2) { // DM sel|| DM + stars sel + for (int k=0; k=xmin && tmp[0][k]<=xmax) && + (tmp[1][k]>=ymin && tmp[1][k]<=ymax) && + (tmp[2][k]>=zmin && tmp[2][k]<=zmax)) { + + if (count_only) { + if (1 /*age[k]==0*/) { // it's DM + ndm_box++; + } else { // it's a star + nstar_box++; + } + nselect++; + } + else { + int idx=666;//index[nbody]; + if (idx!=-1) { // it's a valide particle + if (take_halo/* && age[k]==0*/) { // DM selected and it's a DM + int cpt = namr_box+cpt_dm; + assert(cpt<(nselect+namr_box)); + for (int l=0;l<3;l++) { + pos[cpt*3+l]=tmp[l][k]; + if (load_vel) { + vel[cpt*3+l]=tmp[3+l][k]; + } + } + cpt_dm++; + } + if (take_stars /*&& age[k]!=0*/) { // STARS selected and it's a star + int cpt = namr_box+(take_halo?ndm_box:0)+cpt_star; + assert(cpt<(nselect+namr_box)); + for (int l=0;l<3;l++) { + pos[cpt*3+l]=tmp[l][k]; + if (load_vel) { + vel[cpt*3+l]=tmp[3+l][k]; + } + } + cpt_star++; + } + + } + nbody++; + } + } + } + } + // garbage + //delete [] age; + } + // garbage collecting + for (int i=0; i<6; i++) + delete [] tmp[i]; + + part.close(); // close current file + } // for ... + return nselect; +#endif +} +} // namespace ramses diff --git a/core/src/cpart.h b/core/src/cpart.h new file mode 100644 index 0000000..7b5504c --- /dev/null +++ b/core/src/cpart.h @@ -0,0 +1,69 @@ +// ============================================================================ +// Copyright Jean-Charles LAMBERT - 2007-2012 +// e-mail: Jean-Charles.Lambert@oamp.fr +// address: Dynamique des galaxies +// 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 +// ============================================================================ + +/* + @author Jean-Charles Lambert + */ + +#ifndef CPART_H +#define CPART_H + +#include +#include +#include +#include +#include +#include "cfortio.h" +#include "snapshotramses.h" + +namespace uns { +class CParticles; +} + +namespace ramses { + +class CPart { +public: + CPart(const std::string,const bool _v=true); + ~CPart(); + void setBoundary(float x[6]) { + xmin=x[0]; + xmax=x[1]; + ymin=x[2]; + ymax=x[3]; + zmin=x[4]; + zmax=x[5]; + + } + bool isValid(); + int loadData(uns::CParticles * particles, + const unsigned int req_bits, const unsigned int comp_bits); + int getNbody(int * dm, int * stars) { + *dm = ndm_box; + *stars = nstar_box; + return nselect; + } + +private: + bool verbose,valid; + std::string infile,indir; + int nselect; + int npart,nstar,ncpu,ndim,nbody,ndm; + int ndm_box, nstar_box; + std::string s_run_index; + + float xmin,xmax,ymin,ymax,zmin,zmax; + + CFortIO part; + int readHeader(); +}; +} // namespace ramses +#endif diff --git a/core/src/snapshotramses.cc b/core/src/snapshotramses.cc index 53f8d7c..4069ff0 100644 --- a/core/src/snapshotramses.cc +++ b/core/src/snapshotramses.cc @@ -17,6 +17,7 @@ #include "camr.h" #include "cpart.h" #include +#include "uns.h" namespace uns { // ============================================================================ @@ -30,13 +31,23 @@ CSnapshotRamsesIn::CSnapshotRamsesIn(const std::string _name, first_loc=true; particles = new CParticles(); valid=false; - part = new ramses::CPart(filename,2); - amr = new ramses::CAmr(filename); + part = new ramses::CPart(filename,verbose); + amr = new ramses::CAmr(filename,verbose); if (part->isValid() && amr->isValid()) { valid=true; interface_type = "Ramses"; file_structure = "component"; interface_index= 2; + + // >> !! NEEDS TO BE FIXED + // all + uns::ComponentRange cr; + cr.setData(0,0); + cr.setType("all"); + crv.clear(); + crv.push_back(cr); + // << !! NEEDS TO BE FIXED + } } // ============================================================================ @@ -55,15 +66,6 @@ CSnapshotRamsesIn::~CSnapshotRamsesIn() // getSnapshotRange ComponentRangeVector * CSnapshotRamsesIn::getSnapshotRange() { - uns::ComponentRange cr; - - // >> !! NEEDS TO BE FIXED - // all - cr.setData(0,10); - cr.setType("all"); - crv.clear(); - crv.push_back(cr); - // << !! NEEDS TO BE FIXED if (valid && crv.size()) { //crv = getCRV(); @@ -107,6 +109,10 @@ int CSnapshotRamsesIn::nextFrame(uns::UserSelection &user_select) amr->setBoundary(x); amr->loadData(particles,req_bits); } + std::cerr << "ngas = "<< particles->ngas <<"\n"; + std::cerr << "ndm = "<< particles->ndm <<"\n"; + std::cerr << "nstars = "<< particles->nstars <<"\n"; + reorderParticles(user_select); status = 1; } } @@ -116,42 +122,274 @@ int CSnapshotRamsesIn::nextFrame(uns::UserSelection &user_select) // close operation int CSnapshotRamsesIn::close() { +} +// ============================================================================ +// reorderParticles +// here we re order particles according to user's component selection +// select_order is a vector containing indexes of components sorted +// according to user request +int CSnapshotRamsesIn::reorderParticles(uns::UserSelection &user_select) +{ + std::cerr <<"Nbody particles loaded="<ntot<<"\n"; + std::vector offset_comp(6,-1); // init 6 offsets with value =-1 + std::vector npart_comp(6,0); // initialise #part per component to ZERO + char * comp[] = { "gas","halo","disk","bulge","stars","bndry","all" }; + // get ordering + std::vector select_order = user_select.selectOrder(); + + // component range + uns::ComponentRange cr; + crv.clear(); + + // set #prticles per component + npart_comp[0] = particles->ngas; + npart_comp[1] = particles->ndm; + npart_comp[4] = particles->nstars; + + assert(select_order.size()<7); + bool first=true; + // according to user selection + // we reformat offset of each components + for (int i=0;i 0 ) { // part exist for the component + offset_comp[select_order[i]]=0; // offset 0 + first=false; + + } + } else { // remaining sorted component + // current offset of the component + assert(offset_comp[select_order[i-1]]!=-1); + offset_comp[select_order[i]]=offset_comp[select_order[i-1]]+ // previous offset + npart_comp[select_order[i-1]]; // size of previous component + } + if (!first && npart_comp[select_order[i]]>0) { // if first && #npart > 0 + cr.setData(offset_comp[select_order[i]], // first part + offset_comp[select_order[i]]+ // last part + npart_comp[select_order[i]]-1, + comp[select_order[i]]); // component name + crv.push_back(cr); + } + } + // set the new real user select + user_select.setCrv(crv); + if (verbose) + uns::ComponentRange::list(&crv); + + // all + cr.setData(0,particles->ntot-1); + cr.setType("all"); + uns::ComponentRangeVector::iterator it; + it = crv.begin(); + // insert "all" at the beginning of componentRangeVector + crv.insert(it,cr); + + for (int i=0;intot) { // exist particles to reorde + std::vector pos,vel,mass; + if (particles->pos.size()>0) + pos.resize(particles->pos.size()); // resize new pos vector + if (particles->vel.size()>0) + vel.resize(particles->vel.size()); // resize new pos vector + if (particles->mass.size()>0) + mass.resize(particles->mass.size()); // resize new mass vector + + for (int i=0; intot; i++) { + + bool found=false; + + int icomp=particles->indexes[i]; // integer component + assert(icomp==0 ||icomp==1 || icomp==4); // gas || halo || stars only + int istart=offset_comp[icomp]; // index start in the new pos array + + // positions + if (particles->pos.size()>0) { + assert((istart*3)+2pos.size()); + found=true; + pos[istart*3+0] = particles->pos[i*3+0]; // x + pos[istart*3+1] = particles->pos[i*3+1]; // y + pos[istart*3+2] = particles->pos[i*3+2]; // z + } + + // velocities + if (particles->vel.size()>0) { + assert((istart*3)+2vel.size()); + found=true; + vel[istart*3+0] = particles->vel[i*3+0]; // x + vel[istart*3+1] = particles->vel[i*3+1]; // y + vel[istart*3+2] = particles->vel[i*3+2]; // z + } + + // masses + if (particles->mass.size()>0) { + assert(istartmass.size()); + found=true; + mass[istart] = particles->mass[i]; + } + + if (found) { // found particles + offset_comp[icomp]++; // update offset + } + } + // copy back arrays + particles->pos=pos; + particles->vel=vel; + particles->mass=mass; + } + } // ============================================================================ // getData // return requested array according 'name' selection bool CSnapshotRamsesIn::getData(const std::string comp, std::string name, int *n,float **data) { + bool ok=true; + *data=NULL; + *n = 0; + + int nbody,first,last; + bool status=getRangeSelect(comp.c_str(),&nbody,&first,&last,false); // find components ranges + if (!status && comp=="all") { // retreive all particles selected by the user + status=1; + first=0; + nbody=particles->ntot; + } + switch(CunsOut::s_mapStringValues[name]) { + case uns::Nbody : + if (status) { + *data = NULL; + *n = nbody; + } else { + ok = false; + } + break; + case uns::Nsel : + if (status) { + *n = nbody; + } else { + ok=false; + } + case uns::Pos : + if (status && particles->pos.size()>0) { + *data = &particles->pos[first*3]; + *n = nbody;//getNSel(); + } else { + ok=false; + } + break; + case uns::Vel : + if (status && particles->vel.size()>0) { + *data = &particles->vel[first*3]; + *n = nbody;//getNSel(); + } else { + ok=false; + } + break; + case uns::Mass : + if (status && particles->mass.size()) { + *data = &particles->mass[first]; + *n = nbody;//getNSel(); + } else { + ok=false; + } + break; + + case uns::Rho : + if (status && comp=="gas" && particles->rho.size()>0) { + *data = &particles->rho[0]; + *n=particles->rho.size(); + } else { + ok=false; + } + break; + case uns::U : + ok=false; + break; + case uns::Hsml : + if (status && comp=="gas" && particles->hsml.size()>0) { + *data = &particles->hsml[0]; + *n=particles->hsml.size(); + } else { + ok=false; + } + break; + case uns::Temp : + if (status && comp=="gas" && particles->temp.size()>0) { + *data = &particles->temp[0]; + *n=particles->temp.size(); + } else { + ok=false; + } + break; + case uns::Age : + if (status && comp=="stars" && particles->age.size()>0) { + *data = &particles->age[0]; + *n=particles->age.size(); + } else { + ok=false; + } + break; + + default: ok=false; + } + if (ok && !*data && + (CunsOut::s_mapStringValues[name]!=uns::Nbody && + CunsOut::s_mapStringValues[name]!=uns::Nsel)) ok = false; // not ok because array is NULL + if (verbose) { + if (ok) { + std::cerr << "CSnapshotGadgetIn::getData name["< does not exist...\n"; + } + } + return ok; } // ============================================================================ // getData // return requested array according 'name' selection bool CSnapshotRamsesIn::getData(const std::string name,int *n,float **data) { + bool ok=false; + return ok; } // ============================================================================ // getData // return requested float according 'name' selection bool CSnapshotRamsesIn::getData(const std::string name,float *data) { + bool ok=false; + return ok; } // ============================================================================ // getData // return requested array according 'name' selection bool CSnapshotRamsesIn::getData(const std::string comp,const std::string name,int *n, int **data) { + bool ok=false; + return ok; } // ============================================================================ // getData // return requested array according 'name' selection bool CSnapshotRamsesIn::getData(const std::string name,int *n, int **data) { + bool ok=false; + return ok; } // ============================================================================ // getData // return requested int according 'name' selection bool CSnapshotRamsesIn::getData(const std::string name,int *data) { + bool ok=false; + return ok; } // ============================================================================ // Normal function diff --git a/core/src/snapshotramses.h b/core/src/snapshotramses.h index 42ff32f..8ff3946 100644 --- a/core/src/snapshotramses.h +++ b/core/src/snapshotramses.h @@ -29,10 +29,12 @@ class CParticles { public: CParticles() { ntot=ngas=ndm,nstars=0; + load_bits=0; } std::vector pos,vel,mass,hsml,rho,temp,age; std::vector indexes; int ntot, ngas, ndm, nstars; + unsigned int load_bits; }; class CSnapshotRamsesIn: public CSnapshotInterfaceIn { @@ -57,6 +59,8 @@ private: ramses::CPart * part; CParticles * particles; bool first_loc; + + int reorderParticles(uns::UserSelection & ); }; } #endif // SNAPSHOTRAMSES_H diff --git a/core/src/uns.cc b/core/src/uns.cc index e2e7634..d8eec91 100644 --- a/core/src/uns.cc +++ b/core/src/uns.cc @@ -1,5 +1,5 @@ // ============================================================================ -// Copyright Jean-Charles LAMBERT - 2008-2010 +// Copyright Jean-Charles LAMBERT - 2008-2012 // e-mail: Jean-Charles.Lambert@oamp.fr // address: Dynamique des galaxies // Laboratoire d'Astrophysique de Marseille @@ -29,7 +29,7 @@ namespace uns { // static variable to store DATA string std::map CunsOut::s_mapStringValues; - + std::map CunsIn::s_mapCompInt; // ---------------------------------------------------------------------------- // READING OPERATIONS CunsIn::CunsIn(const std::string _name ,const std::string _comp ,const std::string _time, const bool verb) @@ -42,6 +42,15 @@ namespace uns { CunsIn::CunsIn(const char * _name ,const char * _comp, const char * _time, const bool verb) { + CunsIn::s_mapCompInt["gas" ] = 0; + CunsIn::s_mapCompInt["halo" ] = 1; + CunsIn::s_mapCompInt["dm" ] = 1; + CunsIn::s_mapCompInt["disk" ] = 2; + CunsIn::s_mapCompInt["bulge" ] = 3; + CunsIn::s_mapCompInt["stars" ] = 4; + CunsIn::s_mapCompInt["bndry" ] = 5; + CunsIn::s_mapCompInt["all" ] =-1; + init(_name,_comp,_time,verb); } // ---------------------------------------------------------------------------- @@ -211,6 +220,7 @@ namespace uns { CunsOut::s_mapStringValues["gas" ] = uns::Gas; CunsOut::s_mapStringValues["halo" ] = uns::Halo; CunsOut::s_mapStringValues["dm" ] = uns::Halo; + CunsOut::s_mapStringValues["ndm" ] = uns::Halo; CunsOut::s_mapStringValues["bulge" ] = uns::Bulge; CunsOut::s_mapStringValues["disk" ] = uns::Disk; CunsOut::s_mapStringValues["stars" ] = uns::Stars; diff --git a/core/src/uns.h b/core/src/uns.h index 1d41f2e..12ebc03 100644 --- a/core/src/uns.h +++ b/core/src/uns.h @@ -84,6 +84,9 @@ namespace uns { bool isValid() { return valid;} CSnapshotInterfaceIn * snapshot; // object to store data + // Map to associate component with a type + static std::map s_mapCompInt; + private: void init(const std::string ,const std::string,const std::string, const bool verb=false ); std::string simname, sel_comp, sel_time; // IN @@ -113,6 +116,8 @@ namespace uns { // Map to associate the strings with the enum values static std::map s_mapStringValues; + + static void initializeStringMap(const bool); private: std::string simname, simtype; // OUT diff --git a/core/src/userselection.cc b/core/src/userselection.cc index ecd4330..6565596 100644 --- a/core/src/userselection.cc +++ b/core/src/userselection.cc @@ -17,6 +17,7 @@ #include #include "assert.h" #include "ctools.h" +#include "uns.h" namespace uns { // ============================================================================ @@ -96,7 +97,16 @@ bool UserSelection::setSelection(const std::string _sel, crvResize(crvsel); } } else { // parse comp_bits with no_data + select_order.clear(); status=parse(); + if (select_order.size()==1 && select_order[0]==-1) { // "all" has been selected + // set to default + select_order.clear(); + for (int i=0;i<6;i++) { + select_order.push_back(i); + } + + } } return status; } @@ -196,7 +206,12 @@ int UserSelection::isComponent(const std::string comp) while (rx[i] && match==-1) { if (rx[i]) { std::string tmp=rx[i]; - if (tmp == comp) match=i; + if (tmp == comp) { + match=i; + if (comp=="dm") { + match=i-1; + } + } } i++; } @@ -209,7 +224,7 @@ int UserSelection::isComponent(const std::string comp) std::string type=rx[match]; int offset; int icrv=ComponentRange::getIndexMatchType(crv,type,offset); - if (icrv != -1 ) { + if (icrv != -1 && !nodata) { assert(icrv<(int)crv->size()); comp_bits |= tools::Ctools::compBits(type); first=(*crv)[icrv].first; @@ -222,8 +237,9 @@ int UserSelection::isComponent(const std::string comp) pos++; } else { - if (nodata) { // no data know yet (like ramses) - comp_bits |= tools::Ctools::compBits(type); + if (nodata) { // no data known yet (like ramses) + comp_bits |= tools::Ctools::compBits(type); // one more bits component + select_order.push_back(CunsIn::s_mapCompInt[comp]); // save order } else { status=4; // type does not exist } diff --git a/core/src/userselection.h b/core/src/userselection.h index 0d2c680..dff54f7 100644 --- a/core/src/userselection.h +++ b/core/src/userselection.h @@ -42,6 +42,13 @@ public: static std::string parseString(std::string&); ComponentRangeVector * getCrvFromSelection() { return &crvsel;} int compBits() { return comp_bits; } + std::vector selectOrder() { + return select_order; + } + void setCrv(ComponentRangeVector _crv) { + crvsel = _crv; + } + private: ParticlesObjectVector pov; static int comparePos(const void * a, const void * b) { @@ -49,6 +56,7 @@ private: t_indexes_tab * bb = (t_indexes_tab *) b; return (aa->p - bb->p); } + std::vector select_order; std::string select; // input range (console | GUI) bool parse(); // parse selection int parseComponent(const std::string); -- GitLab