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)
# Check fortran compiler
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
MESSAGE( STATUS "PROJECT_BINARY_DIR: " ${PROJECT_BINARY_DIR} )
......
......@@ -25,6 +25,13 @@ SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/../cmake )
# load setup flags
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
FIND_PACKAGE(SWIG REQUIRED)
FIND_PACKAGE(NumPy REQUIRED)
......
......@@ -234,6 +234,7 @@ template <class T> int CAmr::loadData(uns::CParticles<T> * particles,
hydro.open(hydrofile,count_only);
hydro.skipBlock(); // ncpu
hydro.readDataBlock((char *) &nvarh);
particles->nvarh = nvarh;
//std::cerr << "nvarh = " << nvarh << "\n" ;
hydro.skipBlock(4); // ndim,levelmax,nboundary,gamma
......@@ -445,7 +446,15 @@ template <class T> int CAmr::loadData(uns::CParticles<T> * particles,
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
int offset_2d=-1;
......@@ -469,11 +478,21 @@ template <class T> int CAmr::loadData(uns::CParticles<T> * particles,
particles->metal.push_back(metal);
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) {
particles->id.push_back(-1.); // no id for gas, use "-1"
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->ngas++; // One more gas particles
......
......@@ -19,6 +19,7 @@
#include <dirent.h>
#include <sys/types.h>
#include <dirent.h>
#include <sstream>
namespace tools {
// ----------------------------------------------------------------------------
......@@ -123,4 +124,21 @@ std::string Ctools::toupper(std::string s)
std::transform(s.begin(),s.end(),s.begin(),(int(*)(int)) std::toupper);
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 {
#define IM_BIT (1 << 20)
#define CM_BIT (1 << 21)
#define SSL_BIT (1 << 22)
#define HYDRO_BIT (1 << 23)
// Component BITS
#define ALL_BIT (1 << 1)
......@@ -64,6 +65,7 @@ namespace tools {
static bool isDirectory(std::string);
static std::string toupper(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) {
int ret=0;
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)
case 'M': req_bits |= METAL_BIT ; break; // metallicity
case 'A': req_bits |= AGE_BIT ; break; // stars's age
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 'z': req_bits |= ZS_BIT ; break; //
case 'Z': req_bits |= ZSMT_BIT ; break; //
......
......@@ -19,6 +19,7 @@
#include "cpart.h"
#include <limits>
#include "uns.h"
#include "ctools.h"
namespace uns {
......@@ -304,7 +305,7 @@ template <class T> int CSnapshotRamsesIn<T>::reorderParticles(uns::UserSelection
// ============================================================================
// getData
// 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;
*data=NULL;
......@@ -317,6 +318,33 @@ template <class T> bool CSnapshotRamsesIn<T>::getData(const std::string comp, st
first=0;
nbody=particles->ntot;
}
if (!status) { // "comp" is not a known conponent, might be an array
int a_index=-1;
bool res;
switch(CunsOut2<T>::s_mapStringValues[comp]) {
case uns::Hydro : // hydro array requested
res=tools::Ctools::isStringANumber(name,a_index);
if (res) { // string is a number
if (a_index >= 0 && a_index < particles->nvarh) {
*data=&particles->hydro[a_index][0];
*n=particles->hydro[a_index].size();
if (*n == 0) { // array not processed
ok = false;
}
} else {
std::cerr << "CSnapshotGadgetIn::getData uns::Hydro index out of range ["
<<a_index<<"]\n";
ok=false;
}
} else {
ok=false;
}
break;
default: ok=false;
}
} else {
switch(CunsOut2<T>::s_mapStringValues[name]) {
case uns::Nbody :
if (status) {
......@@ -419,6 +447,7 @@ template <class T> bool CSnapshotRamsesIn<T>::getData(const std::string comp, st
default: ok=false;
}
}
if (ok && !*data &&
(CunsOut2<T>::s_mapStringValues[name]!=uns::Nbody &&
CunsOut2<T>::s_mapStringValues[name]!=uns::Nsel)) ok = false; // not ok because array is NULL
......@@ -635,6 +664,9 @@ template <class T> bool CSnapshotRamsesIn<T>::getData(const std::string name,int
case uns::Nstars :
*data = particles->nstars;
break;
case uns::Nvarh :
*data = particles->nvarh;
break;
default: ok=false;
}
if (ok && !*data) ok = false; // not ok because array is NULL
......
......@@ -34,12 +34,15 @@ public:
ngas =0; // like ntot=ngas=ndm=0 !!!!!!!!!
ndm =0; // it was a bug in py_unsio wrapper for ramses files,
nstars=0; // really really damn crazy !!!!!
nvarh =0; // #hydro variables
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> hydro[MAX_HYDRO]; // extra hydro from var[nvarh] array
std::vector <int> indexes,id;
int ntot, ngas, ndm, nstars;
int ntot, ngas, ndm, nstars, nvarh;
unsigned int load_bits;
};
......
......@@ -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["czs" ] = uns::Czs;
CunsOut2<T>::s_mapStringValues["czsmt" ] = uns::Czsmt;
// HYDRO
CunsOut2<T>::s_mapStringValues["hydro" ] = uns::Hydro;
CunsOut2<T>::s_mapStringValues["nvarh" ] = uns::Nvarh;
if (verbose) {
std::cout << "CunsOut2<T>::initializeStringMap s_mapStringValues contains "
<< CunsOut2<T>::s_mapStringValues.size() << " entries." << std::endl;
......
......@@ -58,7 +58,7 @@
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; }
......@@ -91,6 +91,10 @@ enum StringData {
Czsmt ,
Ssl ,
// hydro data
Hydro , // hydro arrays (mainly for RAMSES)
Nvarh , // #hydros arrays
// Nbodies per component
Nsel ,
Nbody ,
......
......@@ -111,6 +111,21 @@ template <class T> void displayInfo(bool display,int maxlines, std::string comp,
if (ok && display) {
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") {
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