Commit f27c077d authored by jclamber's avatar jclamber

ramses implementation in progress...


git-svn-id: http://svn.oamp.fr/repos/unsio/trunk@103 ce2cc22f-6084-46ce-a062-084b172ee5dc
parent 0bb7c1e9
...@@ -65,6 +65,7 @@ namespace tools { ...@@ -65,6 +65,7 @@ namespace tools {
if (s=="all" ) ret=ALL_BIT|GAS_BIT|HALO_BIT|DISK_BIT|STARS_BIT|BNDRY_BIT; if (s=="all" ) ret=ALL_BIT|GAS_BIT|HALO_BIT|DISK_BIT|STARS_BIT|BNDRY_BIT;
if (s=="gas" ) ret=GAS_BIT; if (s=="gas" ) ret=GAS_BIT;
if (s=="halo" ) ret=HALO_BIT; if (s=="halo" ) ret=HALO_BIT;
if (s=="dm" ) ret=HALO_BIT;
if (s=="disk" ) ret=DISK_BIT; if (s=="disk" ) ret=DISK_BIT;
if (s=="stars" ) ret=STARS_BIT; if (s=="stars" ) ret=STARS_BIT;
if (s=="bndry" ) ret=BNDRY_BIT; if (s=="bndry" ) ret=BNDRY_BIT;
......
...@@ -138,7 +138,7 @@ typedef struct particle_data_lite ...@@ -138,7 +138,7 @@ typedef struct particle_data_lite
int multiplefiles; int multiplefiles;
bool lonely_file; bool lonely_file;
unsigned int load_bits, comp_bits;
//data //data
float * mass, * pos, * vel, * acc, *pot, * rho, * hsml, * age, * metal, * intenerg, * temp; float * mass, * pos, * vel, * acc, *pot, * rho, * hsml, * age, * metal, * intenerg, * temp;
int * id; int * id;
...@@ -172,13 +172,7 @@ typedef struct particle_data_lite ...@@ -172,13 +172,7 @@ typedef struct particle_data_lite
bool swap; bool swap;
uns::ComponentRangeVector crv; uns::ComponentRangeVector crv;
void storeComponents(); void storeComponents();
inline bool ckloadBit(unsigned int lb) { return load_bits & lb; }
template <class T> inline void freeNotLoadedData(T ** data,unsigned int lb) {
if (!ckloadBit(lb) && *data) {
delete [] *data;
*data=NULL;
}
}
// member data // member data
float * getMass() { return mass; } float * getMass() { return mass; }
float getTime() { return tframe;} float getTime() { return tframe;}
......
...@@ -51,7 +51,7 @@ namespace uns { ...@@ -51,7 +51,7 @@ namespace uns {
// ============================================================================ // ============================================================================
// nextFrame // nextFrame
int CSnapshotInterfaceIn::nextFrameSelect(ComponentRangeVector * crvs) int CSnapshotInterfaceIn::nextFrameSelect(ComponentRangeVector * crvs)
{ {
user_select.setSelection(getSelectPart(),crvs); user_select.setSelection(getSelectPart(),crvs);
setNsel(user_select.getNSel()); setNsel(user_select.getNSel());
return(nextFrame(user_select)); return(nextFrame(user_select));
......
...@@ -80,7 +80,9 @@ namespace uns { ...@@ -80,7 +80,9 @@ namespace uns {
verbose = verb; verbose = verb;
first=true; first=true;
valid=false; valid=false;
req_bits=0; // requested bits req_bits=0; // data requested
load_bits=0; // data loaded
comp_bits=0; // component requested
crvs=NULL; crvs=NULL;
crv.clear(); crv.clear();
stv.clear(); stv.clear();
...@@ -164,7 +166,14 @@ namespace uns { ...@@ -164,7 +166,14 @@ namespace uns {
static std::string eps_db_file; static std::string eps_db_file;
static std::string nemo_range_file; static std::string nemo_range_file;
unsigned int load_bits, comp_bits;
inline bool ckloadBit(unsigned int lb) { return load_bits & lb; }
template <class T> inline void freeNotLoadedData(T ** data,unsigned int lb) {
if (!ckloadBit(lb) && *data) {
delete [] *data;
*data=NULL;
}
}
unsigned int req_bits; unsigned int req_bits;
void computeBits(std::string _s=""); void computeBits(std::string _s="");
CSelectTimeVector stv; CSelectTimeVector stv;
......
...@@ -14,10 +14,38 @@ ...@@ -14,10 +14,38 @@
*/ */
#include "snapshotramses.h" #include "snapshotramses.h"
#include "camr.h"
#include "cpart.h"
#include <limits>
namespace uns { namespace uns {
CSnapshotRamsesIn::CSnapshotRamsesIn() // ============================================================================
// constructor : CSnapshotRamsesIn
CSnapshotRamsesIn::CSnapshotRamsesIn(const std::string _name,
const std::string _comp,
const std::string _time,
const bool verb):
CSnapshotInterfaceIn(_name, _comp, _time, verb)
{ {
first_loc=true;
particles = new CParticles();
valid=false;
part = new ramses::CPart(filename,2);
amr = new ramses::CAmr(filename);
if (part->isValid() && amr->isValid()) {
valid=true;
interface_type = "Ramses";
file_structure = "component";
interface_index= 2;
}
}
// ============================================================================
// desstructor : ~CSnapshotRamsesIn
CSnapshotRamsesIn::~CSnapshotRamsesIn()
{
delete amr;
delete part;
delete particles;
} }
// ============================================================================ // ============================================================================
// PURE virtual FUNCTION delared in CSnapshotInterfaceIn // PURE virtual FUNCTION delared in CSnapshotInterfaceIn
...@@ -27,11 +55,62 @@ CSnapshotRamsesIn::CSnapshotRamsesIn() ...@@ -27,11 +55,62 @@ CSnapshotRamsesIn::CSnapshotRamsesIn()
// getSnapshotRange // getSnapshotRange
ComponentRangeVector * 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();
//ComponentRange::list(&crv);
if (first) {
first = false;
crv_first = crv;
//nbody_first = getNtotal();
//std::cerr << "CSnapshotGadgetIn::getSnapshotRange() = " << nbody_first << "\n";
//time_first = getTime();
}
}
return &crv;
} }
// ============================================================================ // ============================================================================
// nextFrame // nextFrame
int CSnapshotRamsesIn::nextFrame(uns::UserSelection &user_select) int CSnapshotRamsesIn::nextFrame(uns::UserSelection &user_select)
{ {
int status=0;
assert(valid==true);
if (first_loc) {
first_loc = false;
if (1 /*checkRangeTime(getTime())*/) {
// check component bits selected
user_select.setSelection(getSelectPart(),&crv,true);
unsigned int comp_bits=user_select.compBits();
// set boundaries
float x[8];
x[0]=x[2]=x[4]=std::numeric_limits<float>::min();
x[1]=x[3]=x[5]=std::numeric_limits<float>::max();
x[6]=std::numeric_limits<float>::max(); // level min
x[7]=0; // nlevelmax
if (comp_bits&HALO_BIT || comp_bits&STARS_BIT) {
part->setBoundary(x);
part->loadData(particles,req_bits,comp_bits);
}
if (comp_bits&GAS_BIT) {
amr->setBoundary(x);
amr->loadData(particles,req_bits);
}
status = 1;
}
}
return status;
} }
// ============================================================================ // ============================================================================
// close operation // close operation
......
...@@ -16,14 +16,31 @@ ...@@ -16,14 +16,31 @@
#define SNAPSHOTRAMSES_H #define SNAPSHOTRAMSES_H
#include "snapshotinterface.h" #include "snapshotinterface.h"
//#include "camr.h"
//#include "cpart.h"
namespace ramses {
class CAmr;
class CPart;
}
namespace uns { namespace uns {
class CParticles {
public:
CParticles() {
ntot=ngas=ndm,nstars=0;
}
std::vector <float> pos,vel,mass,hsml,rho,temp,age;
std::vector <int> indexes;
int ntot, ngas, ndm, nstars;
};
class CSnapshotRamsesIn: public CSnapshotInterfaceIn { class CSnapshotRamsesIn: public CSnapshotInterfaceIn {
public: public:
CSnapshotRamsesIn(); CSnapshotRamsesIn(const std::string, const std::string, const std::string, const bool verb=false);
~CSnapshotRamsesIn();
// pure virtual function implemented // pure virtual function implemented
ComponentRangeVector * getSnapshotRange(); ComponentRangeVector * getSnapshotRange();
int nextFrame(uns::UserSelection &); int nextFrame(uns::UserSelection &);
...@@ -35,6 +52,11 @@ public: ...@@ -35,6 +52,11 @@ public:
bool getData(const std::string, const std::string ,int *,int **); bool getData(const std::string, const std::string ,int *,int **);
int close(); int close();
private:
ramses::CAmr * amr;
ramses::CPart * part;
CParticles * particles;
bool first_loc;
}; };
} }
#endif // SNAPSHOTRAMSES_H #endif // SNAPSHOTRAMSES_H
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <assert.h> #include <assert.h>
#include "snapshotinterface.h" #include "snapshotinterface.h"
#include "snapshotgadget.h" #include "snapshotgadget.h"
#include "snapshotramses.h"
#include "snapshotnemo.h" #include "snapshotnemo.h"
#include "snapshotsim.h" #include "snapshotsim.h"
#include "snapshotlist.h" #include "snapshotlist.h"
...@@ -68,6 +69,9 @@ namespace uns { ...@@ -68,6 +69,9 @@ namespace uns {
} else { } else {
if (tools::Ctools::isFileExist(simname)) { // file exist if (tools::Ctools::isFileExist(simname)) { // file exist
tryGadget(); // try gadget tryGadget(); // try gadget
if (!valid) { // gadget failed
tryRamses(); // try ramses
}
if (!valid) { // gadget failed if (!valid) { // gadget failed
tryNemo(); // try nemo tryNemo(); // try nemo
} }
...@@ -106,6 +110,14 @@ namespace uns { ...@@ -106,6 +110,14 @@ namespace uns {
valid = snapshot->isValidData(); valid = snapshot->isValidData();
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// tryRamses
void CunsIn::tryRamses()
{
PRINT("tryRamses("<<simname<<")\n");
snapshot = new CSnapshotRamsesIn(simname, sel_comp, sel_time, verbose);
valid = snapshot->isValidData();
}
// ----------------------------------------------------------------------------
// tryNemo // tryNemo
void CunsIn::tryNemo() void CunsIn::tryNemo()
{ {
...@@ -198,6 +210,7 @@ namespace uns { ...@@ -198,6 +210,7 @@ namespace uns {
CunsOut::s_mapStringValues["nbndry" ] = uns::Nbndry; CunsOut::s_mapStringValues["nbndry" ] = uns::Nbndry;
CunsOut::s_mapStringValues["gas" ] = uns::Gas; CunsOut::s_mapStringValues["gas" ] = uns::Gas;
CunsOut::s_mapStringValues["halo" ] = uns::Halo; CunsOut::s_mapStringValues["halo" ] = uns::Halo;
CunsOut::s_mapStringValues["dm" ] = uns::Halo;
CunsOut::s_mapStringValues["bulge" ] = uns::Bulge; CunsOut::s_mapStringValues["bulge" ] = uns::Bulge;
CunsOut::s_mapStringValues["disk" ] = uns::Disk; CunsOut::s_mapStringValues["disk" ] = uns::Disk;
CunsOut::s_mapStringValues["stars" ] = uns::Stars; CunsOut::s_mapStringValues["stars" ] = uns::Stars;
......
...@@ -91,7 +91,8 @@ namespace uns { ...@@ -91,7 +91,8 @@ namespace uns {
void tryNemo(); void tryNemo();
void trySimDB(); void trySimDB();
void trySnapList(); void trySnapList();
void tryRamses();
//bool findSim(); //bool findSim();
bool valid; bool valid;
bool verbose; bool verbose;
......
...@@ -32,7 +32,7 @@ UserSelection::UserSelection() ...@@ -32,7 +32,7 @@ UserSelection::UserSelection()
// destructor // destructor
UserSelection::~UserSelection() UserSelection::~UserSelection()
{ {
if (indx) { if (indx) {
delete [] indx; delete [] indx;
} }
} }
...@@ -46,51 +46,57 @@ UserSelection::~UserSelection() ...@@ -46,51 +46,57 @@ UserSelection::~UserSelection()
// This function takes care in which order the user has selected the particles and build // This function takes care in which order the user has selected the particles and build
// the array of selected indexes accordingly. // the array of selected indexes accordingly.
bool UserSelection::setSelection(const std::string _sel, bool UserSelection::setSelection(const std::string _sel,
const ComponentRangeVector * _crv) const ComponentRangeVector * _crv,bool _nodata)
{ {
pos = 0; // current component selection nodata = _nodata; // are there data selected ?
select =_sel; // cop selection bool status;
crv = _crv; // link component range vector if (!nodata) {
comp_bits = 0; // no bits yet pos = 0; // current component selection
assert(crv); // must not be NULL select =_sel; // cop selection
assert((*crv)[0].type=="all"); // first entry must be "all" crv = _crv; // link component range vector
nbody = (*crv)[0].n; // #bodies max in the snapshot comp_bits = 0; // no bits yet
if (indx) { assert(crv); // must not be NULL
delete [] indx; assert((*crv)[0].type=="all"); // first entry must be "all"
} nbody = (*crv)[0].n; // #bodies max in the snapshot
indx = new t_indexes_tab[nbody]; if (indx) {
for (int i=0;i<nbody;i++) { delete [] indx;
indx[i].i=-1; // reset indexes }
indx[i].p=10000; // set position to high number indx = new t_indexes_tab[nbody];
}
nsel = 0;
min = max = -1;
crvsel.clear(); // crv to stro selected component
pov.clear();
bool status=parse();
if (status || 1 ) { // we force here
t_indexes_tab * indx2 = new t_indexes_tab[nbody];
for (int i=0;i<nbody;i++) { for (int i=0;i<nbody;i++) {
indx2[i].i=-1; // reset indexes indx[i].i=-1; // reset indexes
indx2[i].p=10000; // set position to high number indx[i].p=10000; // set position to high number
} }
int ptr=0; nsel = 0;
for (unsigned int i=0;i<pov.size();i++) { min = max = -1;
for (int j=pov[i].first; j<=pov[i].last; j++) { crvsel.clear(); // crv to stro selected component
indx2[ptr].i = indx[j].i; pov.clear();
indx2[ptr].p = indx[j].p; status=parse();
assert(indx2[ptr].i!=-1); if (status || 1 ) { // we force here
assert(indx[j].p == (int) i); t_indexes_tab * indx2 = new t_indexes_tab[nbody];
assert(ptr<nbody); for (int i=0;i<nbody;i++) {
ptr++; indx2[i].i=-1; // reset indexes
indx2[i].p=10000; // set position to high number
}
int ptr=0;
for (unsigned int i=0;i<pov.size();i++) {
for (int j=pov[i].first; j<=pov[i].last; j++) {
indx2[ptr].i = indx[j].i;
indx2[ptr].p = indx[j].p;
assert(indx2[ptr].i!=-1);
assert(indx[j].p == (int) i);
assert(ptr<nbody);
ptr++;
}
} }
//assert(ptr==nbody);
delete [] indx;
indx=indx2;
// resise crvsel
crvResize(crvsel);
} }
//assert(ptr==nbody); } else { // parse comp_bits with no_data
status=parse();
delete [] indx;
indx=indx2;
// resise crvsel
crvResize(crvsel);
} }
return status; return status;
} }
...@@ -132,21 +138,21 @@ int UserSelection::isRange(const std::string comp) ...@@ -132,21 +138,21 @@ int UserSelection::isRange(const std::string comp)
size_t found = comp.find(':',ppos); size_t found = comp.find(':',ppos);
if (found!=std::string::npos) { if (found!=std::string::npos) {
if (found > (size_t) (ppos)) { if (found > (size_t) (ppos)) {
cpt++; cpt++;
std::string str=comp.substr(ppos,found-ppos); std::string str=comp.substr(ppos,found-ppos);
std::istringstream ss(str); std::istringstream ss(str);
int val; int val;
ss>>val; ss>>val;
store.push_back(val); store.push_back(val);
} }
ppos=found+1; // ppos=found+1; //
} else { // no more ":" } else { // no more ":"
if (cpt>0) { if (cpt>0) {
std::string str=comp.substr(ppos); std::string str=comp.substr(ppos);
std::istringstream ss(str); std::istringstream ss(str);
int val; int val;
ss>>val; ss>>val;
store.push_back(val); store.push_back(val);
} }
stop=true; stop=true;
} }
...@@ -184,7 +190,7 @@ int UserSelection::isComponent(const std::string comp) ...@@ -184,7 +190,7 @@ int UserSelection::isComponent(const std::string comp)
{ {
int status; int status;
// Regular expression => all|halo|disk ...... // Regular expression => all|halo|disk ......
const char * rx[] = {"all","halo","disk","bulge","stars","gas","bndry","halo2",NULL}; const char * rx[] = {"all","halo","dm","disk","bulge","stars","gas","bndry","halo2",NULL};
int i=0; int i=0;
int match=-1; int match=-1;
while (rx[i] && match==-1) { while (rx[i] && match==-1) {
...@@ -216,7 +222,11 @@ int UserSelection::isComponent(const std::string comp) ...@@ -216,7 +222,11 @@ int UserSelection::isComponent(const std::string comp)
pos++; pos++;
} }
else { else {
status=4; // type does not exist if (nodata) { // no data know yet (like ramses)
comp_bits |= tools::Ctools::compBits(type);
} else {
status=4; // type does not exist
}
} }
} }
return status; return status;
...@@ -230,7 +240,7 @@ void UserSelection::fillIndexes(const std::string comp,const int first, const in ...@@ -230,7 +240,7 @@ void UserSelection::fillIndexes(const std::string comp,const int first, const in
assert(npart<=nbody); assert(npart<=nbody);
for (int i=first; i<=last; i+=step) { for (int i=first; i<=last; i+=step) {
if (indx[i].i==-1) nsel++; // one more particles if (indx[i].i==-1) nsel++; // one more particles
indx[i].i = i; // set new particles indx[i].i = i; // set new particles
indx[i].p = pos; indx[i].p = pos;
assert(nsel<=nbody); assert(nsel<=nbody);
} }
...@@ -253,8 +263,8 @@ void UserSelection::fillIndexes(const std::string comp,const int first, const in ...@@ -253,8 +263,8 @@ void UserSelection::fillIndexes(const std::string comp,const int first, const in
int nlast=first+npart-1; int nlast=first+npart-1;
// step =1 by default now // step =1 by default now
findMinMax(first,nlast); // find min and max for later processing findMinMax(first,nlast); // find min and max for later processing
// like resizing cvrsel according user selected // like resizing cvrsel according user selected
// data // data
} }
// ============================================================================ // ============================================================================
// parseString // parseString
...@@ -289,8 +299,8 @@ void UserSelection::findMinMax(const int first, const int last) ...@@ -289,8 +299,8 @@ void UserSelection::findMinMax(const int first, const int last)
// //
void UserSelection::crvResize(ComponentRangeVector & mycrv) void UserSelection::crvResize(ComponentRangeVector & mycrv)
{ {
// std::cerr << "BEFORE Listing of the Users' selectef CRV\n"; // std::cerr << "BEFORE Listing of the Users' selectef CRV\n";
// ComponentRange::list(&mycrv); // ComponentRange::list(&mycrv);
// sort mycrv according to its smaller "first" field // sort mycrv according to its smaller "first" field
std::sort(mycrv.begin(),mycrv.end(),ComponentRange::compareFirst); std::sort(mycrv.begin(),mycrv.end(),ComponentRange::compareFirst);
...@@ -328,7 +338,7 @@ int UserSelection::crvPermut(ComponentRange& cr,int min, int max, int &next_firs ...@@ -328,7 +338,7 @@ int UserSelection::crvPermut(ComponentRange& cr,int min, int max, int &next_firs
} }
next_first=cr.last+1; next_first=cr.last+1;
cr.setData(cr.first,cr.last,cr.type); cr.setData(cr.first,cr.last,cr.type);
return ret; return ret;
} }
} //namespace uns } //namespace uns
...@@ -36,7 +36,7 @@ public: ...@@ -36,7 +36,7 @@ public:
UserSelection(); UserSelection();
//const UserSelection& operator=(const UserSelection& m); //const UserSelection& operator=(const UserSelection& m);
~UserSelection(); ~UserSelection();
bool setSelection(const std::string,const ComponentRangeVector *); bool setSelection(const std::string,const ComponentRangeVector *, bool nodata=false);
const t_indexes_tab * getIndexesTab() const { return indx; } const t_indexes_tab * getIndexesTab() const { return indx; }
int getNSel() const { return nsel ; } int getNSel() const { return nsel ; }
static std::string parseString(std::string&); static std::string parseString(std::string&);
...@@ -55,6 +55,7 @@ private: ...@@ -55,6 +55,7 @@ private:
bool checkComponent(const std::string); bool checkComponent(const std::string);
int isComponent(const std::string); int isComponent(const std::string);
int isRange(const std::string); int isRange(const std::string);
bool nodata; // no data before setSelection
std::string out_range; // range selected std::string out_range; // range selected
int nbody; // #bodies max int nbody; // #bodies max
int nsel; // #bodies selected int nsel; // #bodies selected
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment