Commit 0cd8bad1 authored by jclamber's avatar jclamber

fix bug for ramses2d, add direct access to a snapshot gadget

git-svn-id: http://svn.oamp.fr/repos/unsio/trunk@217 ce2cc22f-6084-46ce-a062-084b172ee5dc
parent 51c546b9
......@@ -288,7 +288,10 @@ int CAmr::loadData(uns::CParticles * particles,
// compute cell center
double px=xg[0*ngrida+i]+xc[0][ind]-xbound[0]; // x
double py=xg[1*ngrida+i]+xc[1][ind]-xbound[1]; // y
double pz=xg[2*ngrida+i]+xc[2][ind]-xbound[2]; // z
double pz=0.0;
if (ndim > 2) {
pz=xg[2*ngrida+i]+xc[2][ind]-xbound[2]; // z
}
bool ok_cell = (
!(son[ind*ngrida+i]>0 && ilevel<lmax) && // cells is NOT refined
(ilevel>=lmin) &&
......@@ -341,7 +344,10 @@ int CAmr::loadData(uns::CParticles * particles,
if (ndim>2) offset_2d=0;
if (req_bits&TEMP_BIT && nvarh>(4+offset_2d)) {
float temp= std::max(0.0,var[(4+offset_2d)*ngrida*twotondim+ind*ngrida+i]/rho);
float temp=0.0;
if (rho!=0.0) {
std::max(0.0,var[(4+offset_2d)*ngrida*twotondim+ind*ngrida+i]/rho);
}
particles->temp.push_back(temp);
particles->load_bits |= TEMP_BIT;
}
......
......@@ -50,6 +50,10 @@ CSnapshotSimIn::CSnapshotSimIn(const std::string _name,
nframe = 0; // # frames read
nemosim = "";
verbose = verb;
sim_filename = filename;
sel_from_index = false;
force_stop = false;
checkSimIndex(); // check if index has been specified with simname
if (0) {
valid=openDbFile();
} else { // SQLite3
......@@ -95,6 +99,25 @@ int CSnapshotSimIn::nextFrameSelect(ComponentRangeVector * crvs)
snapshot->setNsel(snapshot->user_select.getNSel());
return(snapshot->nextFrame(snapshot->user_select));
}
// ============================================================================
// checkSimIndex
bool CSnapshotSimIn::checkSimIndex()
{
std::size_t found = sim_filename.find("%");
if (found!= std::string::npos) { // % found
std::string name=sim_filename.substr(0,found);
std::string index=sim_filename.substr(found+1,sim_filename.length()-1);
std::istringstream s_nframe(index);
s_nframe >> nframe; // convert string to int
if (verbose) {
std::cerr << "checkSimIndex name =" << name << " index=" << index << " nframe="<< nframe <<"\n";
}
sim_filename=name; // set a correct name for the simulation
sel_from_index = true;
}
return sel_from_index;
}
// - - - - - - - - - - - - - -
// SQlite database
// - - - - - - - - - - - - - -
......@@ -131,12 +154,12 @@ bool CSnapshotSimIn::openSqlDb(std::string db)
// findSqlSim
bool CSnapshotSimIn::findSqlSim()
{
std::string select="select * from info where name='"+filename+"'";
std::string select="select * from info where name='"+sim_filename+"'";
if (verbose) std::cerr << "select = "<<select <<"\n";
int status = sql->exe(select);
if (status) {
if (verbose) sql->display();
assert(sql->vdata[0]==filename);
assert(sql->vdata[0]==sim_filename);
simname = sql->vdata[0];
simtype = sql->vdata[1];
dirname = sql->vdata[2];
......@@ -158,12 +181,12 @@ bool CSnapshotSimIn::findSqlSim()
// readSqlEps
bool CSnapshotSimIn::readSqlEps()
{
std::string select="select * from eps where name='"+filename+"'";
std::string select="select * from eps where name='"+sim_filename+"'";
if (verbose) std::cerr << "select = "<<select <<"\n";
int status = sql->exe(select);
if (status) {
if (verbose) sql->display();
assert(sql->vdata[0]==filename);
assert(sql->vdata[0]==sim_filename);
std::stringstream str;
for (unsigned int i=1; i< sql->vdata.size(); i++) {
str << sql->vdata[i]; // convert string to stream string
......@@ -177,13 +200,13 @@ bool CSnapshotSimIn::readSqlEps()
// look for simulation in Sql Database file
bool CSnapshotSimIn::fillSqlNemoRange()
{
std::string select="select * from nemorange where name='"+filename+"'";
std::string select="select * from nemorange where name='"+sim_filename+"'";
if (verbose) std::cerr << "select = "<<select <<"\n";
int status = sql->exe(select);
if (status) {
if (verbose) sql->display();
int offset=0;
assert(sql->vdata[0]==filename);
assert(sql->vdata[0]==sim_filename);
addNemoComponent(offset,sql->vdata[1],"all" );
addNemoComponent(offset,sql->vdata[2],"disk" );
addNemoComponent(offset,sql->vdata[3],"bulge");
......@@ -206,7 +229,7 @@ bool CSnapshotSimIn::openDbFile()
bool status=true;
fi.open(sim_db_file.c_str(),std::ios::in);
if (! fi.is_open()) {
std::cerr << "Unable to open file ["<<filename<<"] for reading, aborting...\n";
std::cerr << "Unable to open file ["<<sim_filename<<"] for reading, aborting...\n";
status = false;
}
if (status) {
......@@ -262,7 +285,7 @@ bool CSnapshotSimIn::findSim()
basename=parse;
}
}
if (simname == filename) { // we found simulation
if (simname == sim_filename) { // we found simulation
stop = true; // we have a snapshot
status = true; // so we can stop reading
std::cerr << "SIM DB:Found simulation ["<<simname<<"] in database !\n";
......@@ -291,7 +314,7 @@ bool CSnapshotSimIn::readEpsFile()
std::string simname;
fi.open(eps_db_file.c_str(),std::ios::in);
if (! fi.is_open()) {
std::cerr << "Warning !!! Unable to open file ["<<filename<<"] for reading...\n";
std::cerr << "Warning !!! Unable to open file ["<<sim_filename<<"] for reading...\n";
status = false;
}
if (status) {
......@@ -311,13 +334,13 @@ bool CSnapshotSimIn::readEpsFile()
cpt++;
if (cpt==1) { // simname
simname=parse;
if (simname == filename) { // we found simulation
if (simname == sim_filename) { // we found simulation
//stop = true; // we have a snapshot
status = true; // we have all components
std::cerr << "EPS:Found simulation ["<<simname<<"] in database !\n";
}
}
if (simname == filename) { // we found simulation
if (simname == sim_filename) { // we found simulation
std::istringstream ss(parse);
if (cpt < MAX_EPS+2) { //
ss >> eps[cpt-2]; // file EPS array
......@@ -325,7 +348,7 @@ bool CSnapshotSimIn::readEpsFile()
}
} // while ( str ....
//
if (simname == filename) {
if (simname == sim_filename) {
stop=true; // simulation has been found
assert(cpt>1); // we must have read at least one eps
......@@ -345,7 +368,7 @@ bool CSnapshotSimIn::readEpsFile()
} // while (!stop ...
} // if (status....
if (! status) {
std::cerr<<"\n\nWARNING, simulation ["<<filename<<"] has no entry in the"
std::cerr<<"\n\nWARNING, simulation ["<<sim_filename<<"] has no entry in the"
<<"EPS datafile ["<<uns::CSnapshotInterfaceIn::eps_db_file<<"]\n\n";
}
return status;
......@@ -380,7 +403,7 @@ bool CSnapshotSimIn::fillNemoRange()
int offset;
fi.open(nemo_range_file.c_str(),std::ios::in);
if (! fi.is_open()) {
std::cerr << "Unable to open file ["<<filename<<"] for reading, aborting...\n";
std::cerr << "Unable to open file ["<<sim_filename<<"] for reading, aborting...\n";
status = false;
}
if (status) {
......@@ -400,7 +423,7 @@ bool CSnapshotSimIn::fillNemoRange()
cpt++;
if (cpt==1) { // simname
simname=parse;
if (simname == filename) { // we found simulation
if (simname == sim_filename) { // we found simulation
stop = true; // we have a snapshot
status = true; // we have all components
std::cerr << "Found simulation ["<<simname<<"] in database !\n";
......@@ -408,7 +431,7 @@ bool CSnapshotSimIn::fillNemoRange()
offset=0;
}
}
if (simname == filename) { // we found simulation
if (simname == sim_filename) { // we found simulation
if (cpt==2) { // #total
addNemoComponent(offset,parse,"all");
}
......@@ -545,7 +568,7 @@ bool CSnapshotSimIn::buildGadgetFile()
// loop on all the possibility of file
// dirname+basename+nframe
// ex : gas001_0 gas001_00 gas001_000
while (!stop && cpt<5) {
while (!force_stop && !stop && cpt<5) {
std::ostringstream ss;
ss << std::setw(cpt) << std::setfill('0') << nframe;
std::string myfile = dirname+'/'+basename+'_'+ss.str();
......@@ -576,6 +599,9 @@ bool CSnapshotSimIn::buildGadgetFile()
if (status) {
nframe++; // next frame index
}
if (sel_from_index) { // occurs only one time
force_stop = true;
}
return status;
}
// ============================================================================
......
......@@ -77,9 +77,12 @@ namespace uns {
bool readSqlEps();
bool findSqlSim();
bool fillSqlNemoRange();
bool checkSimIndex();
bool sel_from_index;
bool force_stop;
std::string sqlite_db;
std::string simname;
std::string simname, sim_filename;
CSnapshotInterfaceIn * snapshot;
std::ifstream fi;
std::string simtype; // gadget, nemo, ftm
......
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