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 {
if (s=="all" ) ret=ALL_BIT|GAS_BIT|HALO_BIT|DISK_BIT|STARS_BIT|BNDRY_BIT;
if (s=="gas" ) ret=GAS_BIT;
if (s=="halo" ) ret=HALO_BIT;
if (s=="dm" ) ret=HALO_BIT;
if (s=="disk" ) ret=DISK_BIT;
if (s=="stars" ) ret=STARS_BIT;
if (s=="bndry" ) ret=BNDRY_BIT;
......
......@@ -138,7 +138,7 @@ typedef struct particle_data_lite
int multiplefiles;
bool lonely_file;
unsigned int load_bits, comp_bits;
//data
float * mass, * pos, * vel, * acc, *pot, * rho, * hsml, * age, * metal, * intenerg, * temp;
int * id;
......@@ -172,13 +172,7 @@ typedef struct particle_data_lite
bool swap;
uns::ComponentRangeVector crv;
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
float * getMass() { return mass; }
float getTime() { return tframe;}
......
......@@ -51,7 +51,7 @@ namespace uns {
// ============================================================================
// nextFrame
int CSnapshotInterfaceIn::nextFrameSelect(ComponentRangeVector * crvs)
{
{
user_select.setSelection(getSelectPart(),crvs);
setNsel(user_select.getNSel());
return(nextFrame(user_select));
......
......@@ -80,7 +80,9 @@ namespace uns {
verbose = verb;
first=true;
valid=false;
req_bits=0; // requested bits
req_bits=0; // data requested
load_bits=0; // data loaded
comp_bits=0; // component requested
crvs=NULL;
crv.clear();
stv.clear();
......@@ -164,7 +166,14 @@ namespace uns {
static std::string eps_db_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;
void computeBits(std::string _s="");
CSelectTimeVector stv;
......
......@@ -14,10 +14,38 @@
*/
#include "snapshotramses.h"
#include "camr.h"
#include "cpart.h"
#include <limits>
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
......@@ -27,11 +55,62 @@ 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();
//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
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
......
......@@ -16,14 +16,31 @@
#define SNAPSHOTRAMSES_H
#include "snapshotinterface.h"
//#include "camr.h"
//#include "cpart.h"
namespace ramses {
class CAmr;
class CPart;
}
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 {
public:
CSnapshotRamsesIn();
CSnapshotRamsesIn(const std::string, const std::string, const std::string, const bool verb=false);
~CSnapshotRamsesIn();
// pure virtual function implemented
ComponentRangeVector * getSnapshotRange();
int nextFrame(uns::UserSelection &);
......@@ -35,6 +52,11 @@ public:
bool getData(const std::string, const std::string ,int *,int **);
int close();
private:
ramses::CAmr * amr;
ramses::CPart * part;
CParticles * particles;
bool first_loc;
};
}
#endif // SNAPSHOTRAMSES_H
......
......@@ -16,6 +16,7 @@
#include <assert.h>
#include "snapshotinterface.h"
#include "snapshotgadget.h"
#include "snapshotramses.h"
#include "snapshotnemo.h"
#include "snapshotsim.h"
#include "snapshotlist.h"
......@@ -68,6 +69,9 @@ namespace uns {
} else {
if (tools::Ctools::isFileExist(simname)) { // file exist
tryGadget(); // try gadget
if (!valid) { // gadget failed
tryRamses(); // try ramses
}
if (!valid) { // gadget failed
tryNemo(); // try nemo
}
......@@ -106,6 +110,14 @@ namespace uns {
valid = snapshot->isValidData();
}
// ----------------------------------------------------------------------------
// tryRamses
void CunsIn::tryRamses()
{
PRINT("tryRamses("<<simname<<")\n");
snapshot = new CSnapshotRamsesIn(simname, sel_comp, sel_time, verbose);
valid = snapshot->isValidData();
}
// ----------------------------------------------------------------------------
// tryNemo
void CunsIn::tryNemo()
{
......@@ -198,6 +210,7 @@ namespace uns {
CunsOut::s_mapStringValues["nbndry" ] = uns::Nbndry;
CunsOut::s_mapStringValues["gas" ] = uns::Gas;
CunsOut::s_mapStringValues["halo" ] = uns::Halo;
CunsOut::s_mapStringValues["dm" ] = uns::Halo;
CunsOut::s_mapStringValues["bulge" ] = uns::Bulge;
CunsOut::s_mapStringValues["disk" ] = uns::Disk;
CunsOut::s_mapStringValues["stars" ] = uns::Stars;
......
......@@ -91,7 +91,8 @@ namespace uns {
void tryNemo();
void trySimDB();
void trySnapList();
void tryRamses();
//bool findSim();
bool valid;
bool verbose;
......
......@@ -32,7 +32,7 @@ UserSelection::UserSelection()
// destructor
UserSelection::~UserSelection()
{
if (indx) {
if (indx) {
delete [] indx;
}
}
......@@ -46,51 +46,57 @@ UserSelection::~UserSelection()
// This function takes care in which order the user has selected the particles and build
// the array of selected indexes accordingly.
bool UserSelection::setSelection(const std::string _sel,
const ComponentRangeVector * _crv)
const ComponentRangeVector * _crv,bool _nodata)
{
pos = 0; // current component selection
select =_sel; // cop selection
crv = _crv; // link component range vector
comp_bits = 0; // no bits yet
assert(crv); // must not be NULL
assert((*crv)[0].type=="all"); // first entry must be "all"
nbody = (*crv)[0].n; // #bodies max in the snapshot
if (indx) {
delete [] indx;
}
indx = new t_indexes_tab[nbody];
for (int i=0;i<nbody;i++) {
indx[i].i=-1; // reset indexes
indx[i].p=10000; // set position to high number
}
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];
nodata = _nodata; // are there data selected ?
bool status;
if (!nodata) {
pos = 0; // current component selection
select =_sel; // cop selection
crv = _crv; // link component range vector
comp_bits = 0; // no bits yet
assert(crv); // must not be NULL
assert((*crv)[0].type=="all"); // first entry must be "all"
nbody = (*crv)[0].n; // #bodies max in the snapshot
if (indx) {
delete [] indx;
}
indx = new t_indexes_tab[nbody];
for (int i=0;i<nbody;i++) {
indx2[i].i=-1; // reset indexes
indx2[i].p=10000; // set position to high number
indx[i].i=-1; // reset indexes
indx[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++;
nsel = 0;
min = max = -1;
crvsel.clear(); // crv to stro selected component
pov.clear();
status=parse();
if (status || 1 ) { // we force here
t_indexes_tab * indx2 = new t_indexes_tab[nbody];
for (int i=0;i<nbody;i++) {
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);
delete [] indx;
indx=indx2;
// resise crvsel
crvResize(crvsel);
} else { // parse comp_bits with no_data
status=parse();
}
return status;
}
......@@ -132,21 +138,21 @@ int UserSelection::isRange(const std::string comp)
size_t found = comp.find(':',ppos);
if (found!=std::string::npos) {
if (found > (size_t) (ppos)) {
cpt++;
std::string str=comp.substr(ppos,found-ppos);
std::istringstream ss(str);
int val;
ss>>val;
store.push_back(val);
cpt++;
std::string str=comp.substr(ppos,found-ppos);
std::istringstream ss(str);
int val;
ss>>val;
store.push_back(val);
}
ppos=found+1; //
} else { // no more ":"
if (cpt>0) {
std::string str=comp.substr(ppos);
std::istringstream ss(str);
int val;
ss>>val;
store.push_back(val);
std::string str=comp.substr(ppos);
std::istringstream ss(str);
int val;
ss>>val;
store.push_back(val);
}
stop=true;
}
......@@ -184,7 +190,7 @@ int UserSelection::isComponent(const std::string comp)
{
int status;
// 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 match=-1;
while (rx[i] && match==-1) {
......@@ -216,7 +222,11 @@ int UserSelection::isComponent(const std::string comp)
pos++;
}
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;
......@@ -230,7 +240,7 @@ void UserSelection::fillIndexes(const std::string comp,const int first, const in
assert(npart<=nbody);
for (int i=first; i<=last; i+=step) {
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;
assert(nsel<=nbody);
}
......@@ -253,8 +263,8 @@ void UserSelection::fillIndexes(const std::string comp,const int first, const in
int nlast=first+npart-1;
// step =1 by default now
findMinMax(first,nlast); // find min and max for later processing
// like resizing cvrsel according user selected
// data
// like resizing cvrsel according user selected
// data
}
// ============================================================================
// parseString
......@@ -289,8 +299,8 @@ void UserSelection::findMinMax(const int first, const int last)
//
void UserSelection::crvResize(ComponentRangeVector & mycrv)
{
// std::cerr << "BEFORE Listing of the Users' selectef CRV\n";
// ComponentRange::list(&mycrv);
// std::cerr << "BEFORE Listing of the Users' selectef CRV\n";
// ComponentRange::list(&mycrv);
// sort mycrv according to its smaller "first" field
std::sort(mycrv.begin(),mycrv.end(),ComponentRange::compareFirst);
......@@ -328,7 +338,7 @@ int UserSelection::crvPermut(ComponentRange& cr,int min, int max, int &next_firs
}
next_first=cr.last+1;
cr.setData(cr.first,cr.last,cr.type);
return ret;
return ret;
}
} //namespace uns
......@@ -36,7 +36,7 @@ public:
UserSelection();
//const UserSelection& operator=(const UserSelection& m);
~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; }
int getNSel() const { return nsel ; }
static std::string parseString(std::string&);
......@@ -55,6 +55,7 @@ private:
bool checkComponent(const std::string);
int isComponent(const std::string);
int isRange(const std::string);
bool nodata; // no data before setSelection
std::string out_range; // range selected
int nbody; // #bodies max
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