Commit bdc88990 authored by LAMBERT Jean-charles's avatar LAMBERT Jean-charles

fix gravity bug on ramses code version < 2012

parent 8ad92d2b
Pipeline #307 skipped
......@@ -182,7 +182,14 @@ template <class T> int CAmr::loadData(uns::CParticles<T> * particles,
nbody = 0;
bool count_only=false;
//if (index==NULL) count_only=true;
int cpt=0;
bool stop=false;
int offset_nvarg=0;
int sdouble=sizeof(double);
while (!stop) {
stop=true;
try {
// loop on all cpus/files
for (int icpu=0; icpu<ncpu; icpu++) {
std::ostringstream osf;
......@@ -238,7 +245,9 @@ template <class T> int CAmr::loadData(uns::CParticles<T> * particles,
//if (verbose) std::cerr << "CAmr::loadData hydrofile-> ["<<hydrofile << "]\n";
grav.open(gravfile,count_only);
grav.skipBlock(); // ncpu
grav.readDataBlock((char *) &nvarg); // buggy in new RAMSES version
grav.readDataBlock((char *) &nvarg);
nvarg+=offset_nvarg; // buggy in old RAMSES version
// we had offset in case of old ramses code
//nvarg=ndim+1; // this is MUST be the real value
// ndim = 3; nvarg =4, phi,ax,ay,az
// ndim = 2; nvarg =3, phi,ax,ay
......@@ -274,8 +283,12 @@ template <class T> int CAmr::loadData(uns::CParticles<T> * particles,
if (!count_only) {
var= new double[ngrida*twotondim*nvarh];
if (is_gravity && (req_bits&POT_BIT || req_bits&ACC_BIT)) {
checkGravity(ngrida,ilevel,icpu,&ngridfile[0][0]);
varg= new double[ngrida*twotondim*nvarg];
//checkGravity(ngrida,ilevel,icpu,&ngridfile[0][0]);
//varg= new double[ngrida*twotondim*nvarg];
varg= new double[ngrida*twotondim*(ndim+1)]; // allocate with ndim+1
// to prevent crash in case of nvarg=3 and
// 4 variables (pot,ax,ay,az) due
// to ramses code prior 2012
}
}
}
......@@ -334,13 +347,17 @@ template <class T> int CAmr::loadData(uns::CParticles<T> * particles,
for (int ivar=0; ivar<nvarg; ivar++) {
if (j==icpu&& ngrida>0) {
int n=grav.readDataBlock((char *) &varg[ivar*ngrida*twotondim+ind*ngrida]);
//std::cerr << "n="<<n<<"\n";
assert(n==ngrida*8);
if (n!=ngrida*sdouble) { // error !!!
// garbage collecting
delete [] xg;
delete [] son;
delete [] var;
delete [] varg;
throw(-1); // throw error and try with another offset
}
}
else {
int n=grav.skipBlock();
std::cerr << "n="<<n<<"\n";
grav.skipBlock();
}
}
}
......@@ -467,11 +484,11 @@ template <class T> int CAmr::loadData(uns::CParticles<T> * particles,
nbody++;
}
else {
// if (ilevel>=lmin) {
// std::cerr << "Not ok lmin="<<lmin<<" ilevel="<<ilevel<<" xmin="<<xmin<<" xmax="<<xmax
// <<" ymin="<<ymin<<" ymax="<<ymax
// <<" zmin="<<zmin<<" zmax="<<zmax<<"\n";
// }
// if (ilevel>=lmin) {
// std::cerr << "Not ok lmin="<<lmin<<" ilevel="<<ilevel<<" xmin="<<xmin<<" xmax="<<xmax
// <<" ymin="<<ymin<<" ymax="<<ymax
// <<" zmin="<<zmin<<" zmax="<<zmax<<"\n";
// }
}
}
}
......@@ -495,6 +512,26 @@ template <class T> int CAmr::loadData(uns::CParticles<T> * particles,
grav.close();
}
} //for (int icpu=0 ....
}
catch (const int e) { // suppose to catch bug on wrong nvarg value
// from ramses code prior 2012
assert(is_gravity && (req_bits&POT_BIT || req_bits&ACC_BIT)); // we must be here if there is gravity
std::cerr << "\n\nCatch error on gravity files, try next alorithms....\n";
if (nvarg>ndim) {
std::cerr << "ALGORITHM ERROR, nvarg>ndim\n";
assert(0);
std::exit(1);
}
offset_nvarg=1;
stop=false;
cpt++;
assert(cpt<2); // we can loop only twice
// close files
amr.close();
hydro.close();
grav.close();
}
}
return nbody;
}
//
......
......@@ -58,7 +58,7 @@
namespace uns {
const std::string VERSION="1.2.0.pre-june-16th-2016"; // UNSIO version
const std::string VERSION="1.2.0.pre-june-17th-2016"; // UNSIO version
inline std::string getVersion() { return uns::VERSION; }
......
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