Commit 8ad92d2b authored by LAMBERT Jean-charles's avatar LAMBERT Jean-charles

add checkGravity()

parent adcf15b4
Pipeline #296 skipped
...@@ -274,6 +274,7 @@ template <class T> int CAmr::loadData(uns::CParticles<T> * particles, ...@@ -274,6 +274,7 @@ template <class T> int CAmr::loadData(uns::CParticles<T> * particles,
if (!count_only) { if (!count_only) {
var= new double[ngrida*twotondim*nvarh]; var= new double[ngrida*twotondim*nvarh];
if (is_gravity && (req_bits&POT_BIT || req_bits&ACC_BIT)) { if (is_gravity && (req_bits&POT_BIT || req_bits&ACC_BIT)) {
checkGravity(ngrida,ilevel,icpu,&ngridfile[0][0]);
varg= new double[ngrida*twotondim*nvarg]; varg= new double[ngrida*twotondim*nvarg];
} }
} }
...@@ -337,7 +338,10 @@ template <class T> int CAmr::loadData(uns::CParticles<T> * particles, ...@@ -337,7 +338,10 @@ template <class T> int CAmr::loadData(uns::CParticles<T> * particles,
assert(n==ngrida*8); assert(n==ngrida*8);
} }
else grav.skipBlock(); else {
int n=grav.skipBlock();
std::cerr << "n="<<n<<"\n";
}
} }
} }
} }
...@@ -493,4 +497,59 @@ template <class T> int CAmr::loadData(uns::CParticles<T> * particles, ...@@ -493,4 +497,59 @@ template <class T> int CAmr::loadData(uns::CParticles<T> * particles,
} //for (int icpu=0 .... } //for (int icpu=0 ....
return nbody; return nbody;
} }
//
// checkGravity
//
bool CAmr::checkGravity(const int ngrida, const int ilevel, const int icpu, int *gridfile)
{
bool status=true;
// MUST verify this
assert(nvarg==ndim);
assert(ngrida>0);
// pointer to gridfile
int (*pgf)[nlevelmax][ncpu+nboundary] = (int (*)[nlevelmax][ncpu+nboundary]) gridfile;
//double * varg = new double[ngrida*twotondim]; // allocate temporary variable
int sdouble = sizeof(double); // sizeof double
// save grav file position
std::streampos position = grav.getPos();
try {
for (int j=0; j<(nboundary+ncpu); j++) {
grav.skipBlock(2);
if ((*pgf)[ilevel][j]>0) {
// Read grav variables
for (int ind=0;ind<twotondim;ind++) {
for (int ivar=0; ivar<nvarg; ivar++) {
if (j==icpu&& ngrida>0) {
//int n=grav.readDataBlock((char *) &varg[0]);
int n=grav.skipBlock();
//std::cerr << "n="<<n<<"\n";
if (n!=ngrida*sdouble) {
// old RAMSES code detected, nvarg=ndim and should be ndim+1
throw -1;
}
assert(n==ngrida*8);
}
else {
grav.skipBlock();
}
}
}
}
}
} catch (const int e) {
std::cerr << "CAmr::checkGravity, old RAMSES code detected, fixing [nvarg=ndim+1]...\n";
nvarg++;
status=false;
assert(nvarg==ndim+1);
}
//delete [] varg;
// get back to file position
grav.setPos(position);
return status;
}
} // end of namespace ramses } // end of namespace ramses
...@@ -80,6 +80,7 @@ private: ...@@ -80,6 +80,7 @@ private:
int lmin,lmax; int lmin,lmax;
CFortIO amr, hydro, grav; CFortIO amr, hydro, grav;
int readHeader(); int readHeader();
bool checkGravity(const int ngrida,const int ilevel,const int icpu, int * gridfile);
// amr header variables // amr header variables
static const double XH, mH, kB; static const double XH, mH, kB;
int ncpu, ndim, nx, ny ,nz, nlevelmax, ngridmax, nboundary, ngrid_current; int ncpu, ndim, nx, ny ,nz, nlevelmax, ngridmax, nboundary, ngrid_current;
......
...@@ -43,6 +43,12 @@ public: ...@@ -43,6 +43,12 @@ public:
return len1; return len1;
} else return 1; } else return 1;
} }
inline std::streampos getPos() {
return in.tellg();
}
inline void setPos(const std::streampos position) {
in.seekg(position);
}
inline int readData(char * ptr,const size_t size_bytes,const int items) { inline int readData(char * ptr,const size_t size_bytes,const int items) {
if (!fake_reading) { if (!fake_reading) {
// get data from file // get data from file
...@@ -79,16 +85,19 @@ public: ...@@ -79,16 +85,19 @@ public:
else return 1; else return 1;
} }
// skip Block // skip Block
inline void skipBlock(int n=1) { inline int skipBlock(int n=1) {
int cpt=0;
if (!fake_reading) { if (!fake_reading) {
for (int i=0;i<n;i++) { for (int i=0;i<n;i++) {
int len1 = readFRecord(); int len1 = readFRecord();
cpt+=len1;
in.seekg(len1,std::ios::cur); in.seekg(len1,std::ios::cur);
int len2 = readFRecord(); int len2 = readFRecord();
if (len2==len1) ; // remove warning.... if (len2==len1) ; // remove warning....
assert(in.good() && len1==len2); assert(in.good() && len1==len2);
} }
} }
return cpt;
} }
private: private:
std::ifstream in; std::ifstream in;
......
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