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;}
......
......@@ -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,6 +91,7 @@ namespace uns {
void tryNemo();
void trySimDB();
void trySnapList();
void tryRamses();
//bool findSim();
bool valid;
......
......@@ -46,8 +46,11 @@ 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)
{
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
......@@ -67,7 +70,7 @@ bool UserSelection::setSelection(const std::string _sel,
min = max = -1;
crvsel.clear(); // crv to stro selected component
pov.clear();
bool status=parse();
status=parse();
if (status || 1 ) { // we force here
t_indexes_tab * indx2 = new t_indexes_tab[nbody];
for (int i=0;i<nbody;i++) {
......@@ -92,6 +95,9 @@ bool UserSelection::setSelection(const std::string _sel,
// resise crvsel
crvResize(crvsel);
}
} else { // parse comp_bits with no_data
status=parse();
}
return status;
}
// ============================================================================
......@@ -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,9 +222,13 @@ int UserSelection::isComponent(const std::string comp)
pos++;
}
else {
if (nodata) { // no data know yet (like ramses)
comp_bits |= tools::Ctools::compBits(type);
} else {
status=4; // type does not exist
}
}
}
return status;
}
// ============================================================================
......@@ -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);
......
......@@ -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