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

get hydro array from RAMSES

parent 3c5bca3a
...@@ -28,6 +28,13 @@ include(SetupFlags) ...@@ -28,6 +28,13 @@ include(SetupFlags)
# Check fortran compiler # Check fortran compiler
include(CheckFortranCompiler) include(CheckFortranCompiler)
# use ccache if any
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif(CCACHE_FOUND)
# contains the full path to the top level directory of your build tree # contains the full path to the top level directory of your build tree
MESSAGE( STATUS "PROJECT_BINARY_DIR: " ${PROJECT_BINARY_DIR} ) MESSAGE( STATUS "PROJECT_BINARY_DIR: " ${PROJECT_BINARY_DIR} )
......
...@@ -25,6 +25,13 @@ SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/../cmake ) ...@@ -25,6 +25,13 @@ SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/../cmake )
# load setup flags # load setup flags
include(SetupFlags) include(SetupFlags)
# use ccache if any
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif(CCACHE_FOUND)
# required package # required package
FIND_PACKAGE(SWIG REQUIRED) FIND_PACKAGE(SWIG REQUIRED)
FIND_PACKAGE(NumPy REQUIRED) FIND_PACKAGE(NumPy REQUIRED)
......
...@@ -234,6 +234,7 @@ template <class T> int CAmr::loadData(uns::CParticles<T> * particles, ...@@ -234,6 +234,7 @@ template <class T> int CAmr::loadData(uns::CParticles<T> * particles,
hydro.open(hydrofile,count_only); hydro.open(hydrofile,count_only);
hydro.skipBlock(); // ncpu hydro.skipBlock(); // ncpu
hydro.readDataBlock((char *) &nvarh); hydro.readDataBlock((char *) &nvarh);
particles->nvarh = nvarh;
//std::cerr << "nvarh = " << nvarh << "\n" ; //std::cerr << "nvarh = " << nvarh << "\n" ;
hydro.skipBlock(4); // ndim,levelmax,nboundary,gamma hydro.skipBlock(4); // ndim,levelmax,nboundary,gamma
...@@ -445,7 +446,15 @@ template <class T> int CAmr::loadData(uns::CParticles<T> * particles, ...@@ -445,7 +446,15 @@ template <class T> int CAmr::loadData(uns::CParticles<T> * particles,
particles->load_bits |= ACC_BIT; particles->load_bits |= ACC_BIT;
} }
// //
// Get hydrodinamic data // Get EXTRA hydrodynamic data stored in var[nvarh] array
//
// 0 : rho
// 1 : vx
// 2 : vy
// 3 : vz
// 4 : pressure
// 5 : metalicity
// 6-? : extra
// //
// with 2D simulations, hydro variables from var[] array are shifted to the left // with 2D simulations, hydro variables from var[] array are shifted to the left
int offset_2d=-1; int offset_2d=-1;
...@@ -469,11 +478,21 @@ template <class T> int CAmr::loadData(uns::CParticles<T> * particles, ...@@ -469,11 +478,21 @@ template <class T> int CAmr::loadData(uns::CParticles<T> * particles,
particles->metal.push_back(metal); particles->metal.push_back(metal);
particles->load_bits |= METAL_BIT; particles->load_bits |= METAL_BIT;
} }
// extra hydro data (> 4 )
int extra_start=4+offset_2d;
if (req_bits&HYDRO_BIT && nvarh>(extra_start)) {
for (unsigned int extra=(extra_start); extra<(unsigned int) nvarh;extra++) {
assert(extra<particles->MAX_HYDRO);
particles->hydro[extra].push_back(var[(extra)*ngrida*twotondim+ind*ngrida+i]);
particles->load_bits |= HYDRO_BIT;
}
}
// particles ID
if (req_bits&ID_BIT) { if (req_bits&ID_BIT) {
particles->id.push_back(-1.); // no id for gas, use "-1" particles->id.push_back(-1.); // no id for gas, use "-1"
particles->load_bits |= ID_BIT; particles->load_bits |= ID_BIT;
} }
if (take|| !req_bits) { // !req_bits for uns_info and siplay=f if (take|| !req_bits) { // !req_bits for uns_info and display=f
particles->indexes.push_back(0); // GAS particles particles->indexes.push_back(0); // GAS particles
particles->ngas++; // One more gas particles particles->ngas++; // One more gas particles
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <dirent.h> #include <dirent.h>
#include <sys/types.h> #include <sys/types.h>
#include <dirent.h> #include <dirent.h>
#include <sstream>
namespace tools { namespace tools {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
...@@ -123,4 +124,21 @@ std::string Ctools::toupper(std::string s) ...@@ -123,4 +124,21 @@ std::string Ctools::toupper(std::string s)
std::transform(s.begin(),s.end(),s.begin(),(int(*)(int)) std::toupper); std::transform(s.begin(),s.end(),s.begin(),(int(*)(int)) std::toupper);
return s; return s;
} }
//
// isStringANumber
// return true if string is a number of type T. Set data to this number
template <class T> bool Ctools::isStringANumber(const std::string mystring, T &data)
{
bool status=true;
std::stringstream stream;
stream << mystring;
stream >> data;
if (! stream.eof()) {
status=false;
}
return status;
}
template bool Ctools::isStringANumber<double>(const std::string mystring, double &data);
template bool Ctools::isStringANumber<float> (const std::string mystring, float &data);
template bool Ctools::isStringANumber<int> (const std::string mystring, int &data);
} }
...@@ -43,6 +43,7 @@ namespace tools { ...@@ -43,6 +43,7 @@ namespace tools {
#define IM_BIT (1 << 20) #define IM_BIT (1 << 20)
#define CM_BIT (1 << 21) #define CM_BIT (1 << 21)
#define SSL_BIT (1 << 22) #define SSL_BIT (1 << 22)
#define HYDRO_BIT (1 << 23)
// Component BITS // Component BITS
#define ALL_BIT (1 << 1) #define ALL_BIT (1 << 1)
...@@ -64,6 +65,7 @@ namespace tools { ...@@ -64,6 +65,7 @@ namespace tools {
static bool isDirectory(std::string); static bool isDirectory(std::string);
static std::string toupper(std::string); static std::string toupper(std::string);
static std::string tolower(std::string); static std::string tolower(std::string);
template <class T> static bool isStringANumber(const std::string mystring, T &data);
static int compBits(std::string s) { static int compBits(std::string s) {
int ret=0; int ret=0;
if (s=="all" ) ret=ALL_BIT|GAS_BIT|HALO_BIT|DISK_BIT|STARS_BIT|BNDRY_BIT; if (s=="all" ) ret=ALL_BIT|GAS_BIT|HALO_BIT|DISK_BIT|STARS_BIT|BNDRY_BIT;
......
...@@ -146,6 +146,7 @@ template <class T> void CSnapshotInterfaceIn<T>::computeBits(std::string bits) ...@@ -146,6 +146,7 @@ template <class T> void CSnapshotInterfaceIn<T>::computeBits(std::string bits)
case 'M': req_bits |= METAL_BIT ; break; // metallicity case 'M': req_bits |= METAL_BIT ; break; // metallicity
case 'A': req_bits |= AGE_BIT ; break; // stars's age case 'A': req_bits |= AGE_BIT ; break; // stars's age
case 'H': req_bits |= HSML_BIT ; break; // hsml case 'H': req_bits |= HSML_BIT ; break; // hsml
case 'h': req_bits |= HYDRO_BIT ; break; // hydro extra
case 'T': req_bits |= TEMP_BIT ; break; // temperature case 'T': req_bits |= TEMP_BIT ; break; // temperature
case 'z': req_bits |= ZS_BIT ; break; // case 'z': req_bits |= ZS_BIT ; break; //
case 'Z': req_bits |= ZSMT_BIT ; break; // case 'Z': req_bits |= ZSMT_BIT ; break; //
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "cpart.h" #include "cpart.h"
#include <limits> #include <limits>
#include "uns.h" #include "uns.h"
#include "ctools.h"
namespace uns { namespace uns {
...@@ -304,7 +305,7 @@ template <class T> int CSnapshotRamsesIn<T>::reorderParticles(uns::UserSelection ...@@ -304,7 +305,7 @@ template <class T> int CSnapshotRamsesIn<T>::reorderParticles(uns::UserSelection
// ============================================================================ // ============================================================================
// getData // getData
// return requested array according 'name' selection // return requested array according 'name' selection
template <class T> bool CSnapshotRamsesIn<T>::getData(const std::string comp, std::string name, int *n,T **data) template <class T> bool CSnapshotRamsesIn<T>::getData(const std::string comp, const std::string name, int *n,T **data)
{ {
bool ok=true; bool ok=true;
*data=NULL; *data=NULL;
...@@ -317,107 +318,135 @@ template <class T> bool CSnapshotRamsesIn<T>::getData(const std::string comp, st ...@@ -317,107 +318,135 @@ template <class T> bool CSnapshotRamsesIn<T>::getData(const std::string comp, st
first=0; first=0;
nbody=particles->ntot; nbody=particles->ntot;
} }
switch(CunsOut2<T>::s_mapStringValues[name]) { if (!status) { // "comp" is not a known conponent, might be an array
case uns::Nbody :
if (status) { int a_index=-1;
*data = NULL; bool res;
*n = nbody; switch(CunsOut2<T>::s_mapStringValues[comp]) {
} else { case uns::Hydro : // hydro array requested
ok = false; res=tools::Ctools::isStringANumber(name,a_index);
} if (res) { // string is a number
break; if (a_index >= 0 && a_index < particles->nvarh) {
case uns::Nsel : *data=&particles->hydro[a_index][0];
if (status) { *n=particles->hydro[a_index].size();
*n = nbody; if (*n == 0) { // array not processed
} else { ok = false;
ok=false; }
} } else {
case uns::Pos : std::cerr << "CSnapshotGadgetIn::getData uns::Hydro index out of range ["
if (status && particles->pos.size()>0) { <<a_index<<"]\n";
*data = &particles->pos[first*3]; ok=false;
*n = nbody;//getNSel(); }
} else { } else {
ok=false; ok=false;
} }
break; break;
case uns::Vel : default: ok=false;
if (status && particles->vel.size()>0) { }
*data = &particles->vel[first*3];
*n = nbody;//getNSel(); } else {
} else { switch(CunsOut2<T>::s_mapStringValues[name]) {
ok=false; case uns::Nbody :
} if (status) {
break; *data = NULL;
case uns::Mass : *n = nbody;
if (status && particles->mass.size()) { } else {
*data = &particles->mass[first]; ok = false;
*n = nbody;//getNSel(); }
} else { break;
case uns::Nsel :
if (status) {
*n = nbody;
} else {
ok=false;
}
case uns::Pos :
if (status && particles->pos.size()>0) {
*data = &particles->pos[first*3];
*n = nbody;//getNSel();
} else {
ok=false;
}
break;
case uns::Vel :
if (status && particles->vel.size()>0) {
*data = &particles->vel[first*3];
*n = nbody;//getNSel();
} else {
ok=false;
}
break;
case uns::Mass :
if (status && particles->mass.size()) {
*data = &particles->mass[first];
*n = nbody;//getNSel();
} else {
ok=false;
}
break;
case uns::Rho :
if (status && comp=="gas" && particles->rho.size()>0) {
*data = &particles->rho[0];
*n=particles->rho.size();
} else {
ok=false;
}
break;
case uns::Pot :
if (status && comp=="gas" && particles->phi.size()>0) {
*data = &particles->phi[0];
*n=particles->phi.size();
} else {
ok=false;
}
break;
case uns::Acc :
if (status && comp=="gas" && particles->acc.size()>0) {
*data = &particles->acc[0];
*n=particles->acc.size()/3;
} else {
ok=false;
}
break;
case uns::U :
ok=false; ok=false;
} break;
break; case uns::Hsml :
if (status && comp=="gas" && particles->hsml.size()>0) {
*data = &particles->hsml[0];
*n=particles->hsml.size();
} else {
ok=false;
}
break;
case uns::Temp :
if (status && comp=="gas" && particles->temp.size()>0) {
*data = &particles->temp[0];
*n=particles->temp.size();
} else {
ok=false;
}
break;
case uns::Age :
if (status && comp=="stars" && particles->age.size()>0) {
*data = &particles->age[0];
*n=particles->age.size();
} else {
ok=false;
}
break;
case uns::Metal :
if (status && particles->metal.size()>0) {
*data = &particles->metal[first];
*n = nbody;
} else {
ok=false;
}
break;
case uns::Rho : default: ok=false;
if (status && comp=="gas" && particles->rho.size()>0) {
*data = &particles->rho[0];
*n=particles->rho.size();
} else {
ok=false;
}
break;
case uns::Pot :
if (status && comp=="gas" && particles->phi.size()>0) {
*data = &particles->phi[0];
*n=particles->phi.size();
} else {
ok=false;
}
break;
case uns::Acc :
if (status && comp=="gas" && particles->acc.size()>0) {
*data = &particles->acc[0];
*n=particles->acc.size()/3;
} else {
ok=false;
}
break;
case uns::U :
ok=false;
break;
case uns::Hsml :
if (status && comp=="gas" && particles->hsml.size()>0) {
*data = &particles->hsml[0];
*n=particles->hsml.size();
} else {
ok=false;
}
break;
case uns::Temp :
if (status && comp=="gas" && particles->temp.size()>0) {
*data = &particles->temp[0];
*n=particles->temp.size();
} else {
ok=false;
}
break;
case uns::Age :
if (status && comp=="stars" && particles->age.size()>0) {
*data = &particles->age[0];
*n=particles->age.size();
} else {
ok=false;
}
break;
case uns::Metal :
if (status && particles->metal.size()>0) {
*data = &particles->metal[first];
*n = nbody;
} else {
ok=false;
} }
break;
default: ok=false;
} }
if (ok && !*data && if (ok && !*data &&
(CunsOut2<T>::s_mapStringValues[name]!=uns::Nbody && (CunsOut2<T>::s_mapStringValues[name]!=uns::Nbody &&
...@@ -632,9 +661,12 @@ template <class T> bool CSnapshotRamsesIn<T>::getData(const std::string name,int ...@@ -632,9 +661,12 @@ template <class T> bool CSnapshotRamsesIn<T>::getData(const std::string name,int
case uns::Nhalo : case uns::Nhalo :
*data = particles->ndm; *data = particles->ndm;
break; break;
case uns::Nstars : case uns::Nstars :
*data = particles->nstars; *data = particles->nstars;
break; break;
case uns::Nvarh :
*data = particles->nvarh;
break;
default: ok=false; default: ok=false;
} }
if (ok && !*data) ok = false; // not ok because array is NULL if (ok && !*data) ok = false; // not ok because array is NULL
......
...@@ -34,12 +34,15 @@ public: ...@@ -34,12 +34,15 @@ public:
ngas =0; // like ntot=ngas=ndm=0 !!!!!!!!! ngas =0; // like ntot=ngas=ndm=0 !!!!!!!!!
ndm =0; // it was a bug in py_unsio wrapper for ramses files, ndm =0; // it was a bug in py_unsio wrapper for ramses files,
nstars=0; // really really damn crazy !!!!! nstars=0; // really really damn crazy !!!!!
nvarh =0; // #hydro variables
load_bits=0; load_bits=0;
} }
static const unsigned int MAX_HYDRO=20;
std::vector <T> pos,vel,mass,hsml,rho,acc,phi,temp,age,metal; std::vector <T> pos,vel,mass,hsml,rho,acc,phi,temp,age,metal;
std::vector <T> hydro[MAX_HYDRO]; // extra hydro from var[nvarh] array
std::vector <int> indexes,id; std::vector <int> indexes,id;
int ntot, ngas, ndm, nstars; int ntot, ngas, ndm, nstars, nvarh;
unsigned int load_bits; unsigned int load_bits;
}; };
......
...@@ -403,6 +403,10 @@ template <class T> void CunsOut2<T>::initializeStringMap(const bool verbose) ...@@ -403,6 +403,10 @@ template <class T> void CunsOut2<T>::initializeStringMap(const bool verbose)
CunsOut2<T>::s_mapStringValues["cm" ] = uns::Cm; CunsOut2<T>::s_mapStringValues["cm" ] = uns::Cm;
CunsOut2<T>::s_mapStringValues["czs" ] = uns::Czs; CunsOut2<T>::s_mapStringValues["czs" ] = uns::Czs;
CunsOut2<T>::s_mapStringValues["czsmt" ] = uns::Czsmt; CunsOut2<T>::s_mapStringValues["czsmt" ] = uns::Czsmt;
// HYDRO
CunsOut2<T>::s_mapStringValues["hydro" ] = uns::Hydro;
CunsOut2<T>::s_mapStringValues["nvarh" ] = uns::Nvarh;
if (verbose) { if (verbose) {
std::cout << "CunsOut2<T>::initializeStringMap s_mapStringValues contains " std::cout << "CunsOut2<T>::initializeStringMap s_mapStringValues contains "
<< CunsOut2<T>::s_mapStringValues.size() << " entries." << std::endl; << CunsOut2<T>::s_mapStringValues.size() << " entries." << std::endl;
......
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
namespace uns { namespace uns {
const std::string VERSION="1.2.0.pre-January-04th-2018"; // UNSIO version const std::string VERSION="1.2.1.January-18th-2018"; // UNSIO version
inline std::string getVersion() { return uns::VERSION; } inline std::string getVersion() { return uns::VERSION; }
...@@ -90,7 +90,11 @@ enum StringData { ...@@ -90,7 +90,11 @@ enum StringData {
Czs , Czs ,
Czsmt , Czsmt ,
Ssl , Ssl ,
// hydro data
Hydro , // hydro arrays (mainly for RAMSES)
Nvarh , // #hydros arrays
// Nbodies per component // Nbodies per component
Nsel , Nsel ,
Nbody , Nbody ,
......
...@@ -111,6 +111,21 @@ template <class T> void displayInfo(bool display,int maxlines, std::string comp, ...@@ -111,6 +111,21 @@ template <class T> void displayInfo(bool display,int maxlines, std::string comp,
if (ok && display) { if (ok && display) {
displayFormat(maxlines,"metal[1] = ",metal,1,nbody, 3); displayFormat(maxlines,"metal[1] = ",metal,1,nbody, 3);
} }
// RAMSES hydro
if (comp=="gas") {
int nvarh=0;
ok = uns->getData("nvarh",&nvarh);
std::cerr << "nvarh=" << nvarh << "\n";
for (int i=0; i<std::min(nvarh,20); i++) {
T * hydro;
stringstream s_int;
s_int << i;
ok = uns->snapshot->getData("hydro",s_int.str(),&nbody,&hydro);
if (ok && display) {
displayFormat(maxlines,"hydro["+s_int.str()+"] = ",hydro,1,nbody, 3);
}
}
}
//} //}
//if (comp == "stars") { //if (comp == "stars") {
T * age;//, * metal; T * age;//, * metal;
......
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