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

add set/get to snapshot header g2/ramses

parent 1653b5ba
......@@ -169,13 +169,12 @@ class CUNS_IN:
ret_data=np.zeros(1,dtype=data_type)
data=0
# proceed __uns.getValue()
if tab_value_F.count(comp_value) > 0:
if tab_value_I.count(comp_value) > 0:
ok,ret_data[0]=self.__uns.getValueI(comp_value)
data=int(ret_data[0])
else:
ok,ret_data[0]=self.__uns.getValueF(comp_value)
data=float(ret_data[0])
else:
if tab_value_I.count(comp_value) > 0:
ok,ret_data[0]=self.__uns.getValueI(comp_value)
data=int(ret_data[0])
#ret_data[0]=data
if self.__vdebug:
print ("ok,data",ok,data)
......
......@@ -69,16 +69,11 @@ class CUNS_OUT:
if tag is None: # only one value
tab_value_F=["time"]
tab_value_I=["nbody","nsel"]
if tab_value_F.count(select) > 0:
ok=self.__uns.setValueF(select,data_array)
if tab_value_I.count(select) > 0:
ok=self.__uns.setValueI(select,data_array)
else:
if tab_value_I.count(select) > 0:
ok=self.__uns.setValueI(select,data_array)
data=int(ret_data[0])
else:
print("Unknown select[%s] ..."%(select))
ok=self.__uns.setValueF(select,data_array)
print(ok)
else:
if tag != "id": #not id, then we save float arrays
ok = self.__uns.setArrayF(select,tag,data_array)
......
......@@ -176,6 +176,7 @@ template <class T> int CAmr::loadData(uns::CParticles<T> * particles,
int ngridlevel [nlevelmax][ncpu ];
int ngridbound [nlevelmax][ nboundary];
double xc[3][8];
double gamma;
int ngrida;
std::string infile;
......@@ -236,7 +237,8 @@ template <class T> int CAmr::loadData(uns::CParticles<T> * particles,
hydro.readDataBlock((char *) &nvarh);
particles->nvarh = nvarh;
//std::cerr << "nvarh = " << nvarh << "\n" ;
hydro.skipBlock(4); // ndim,levelmax,nboundary,gamma
hydro.skipBlock(3); // ndim,levelmax,nboundary
hydro.readDataBlock((char *) &gamma); // gamma
// --------------
// Open GRAV file and skip header
......@@ -463,7 +465,7 @@ template <class T> int CAmr::loadData(uns::CParticles<T> * particles,
if (req_bits&TEMP_BIT && nvarh>(4+offset_2d)) {
double temp=0.0;
if (rho!=0.0) {
temp=std::max(0.0,var[(4+offset_2d)*ngrida*twotondim+ind*ngrida+i]/rho);
temp=std::max(0.0,var[(4+offset_2d)*ngrida*twotondim+ind*ngrida+i]/((gamma-1)*rho));
}
particles->temp.push_back(temp);
particles->load_bits |= TEMP_BIT;
......
......@@ -36,6 +36,13 @@ typedef struct {
double aexp,hexp,aexp_old,epot_tot_int,epot_tot_old;
} Header;
template <class T> class T_Header {
public:
T time;
T boxlen, omega_m, omega_l, omega_k, omega_b, h0, aexp_ini, boxlen_ini;
T aexp,hexp,aexp_old,epot_tot_int,epot_tot_old;
};
class CAmr {
public:
CAmr(const std::string,const bool _v=true);
......@@ -66,7 +73,6 @@ public:
int getNbody() { return nbody;}
Header * getHeader() { return &header; }
private:
// some variables
......@@ -80,6 +86,7 @@ private:
int lmin,lmax;
CFortIO amr, hydro, grav;
int readHeader();
bool checkGravity(const int ngrida,const int ilevel,const int icpu, int * gridfile);
// amr header variables
static const double XH, mH, kB;
......@@ -87,6 +94,7 @@ private:
int twotondim;
double xbound[3];
Header header;
// hydro
int nvarh;
double scale_nH;
......
This diff is collapsed.
// ============================================================================
// Copyright Jean-Charles LAMBERT - 2008-2016
// Centre de donneeS Astrophysiques de Marseille (CeSAM)
// e-mail: Jean-Charles.Lambert@lam.fr
// address: Aix Marseille Universite, CNRS, LAM
// Laboratoire d'Astrophysique de Marseille
// Pole de l'Etoile, site de Chateau-Gombert
// 38, rue Frederic Joliot-Curie
// 13388 Marseille cedex 13 France
// CNRS UMR 7326
// Centre de donneeS Astrophysiques de Marseille (CeSAM)
// e-mail: Jean-Charles.Lambert@lam.fr
// address: Aix Marseille Universite, CNRS, LAM
// Laboratoire d'Astrophysique de Marseille
// Pole de l'Etoile, site de Chateau-Gombert
// 38, rue Frederic Joliot-Curie
// 13388 Marseille cedex 13 France
// CNRS UMR 7326
// ============================================================================
/**
......@@ -41,10 +41,20 @@ typedef struct io_header_1
double BoxSize;
double Omega0;
double OmegaLambda;
double HubbleParam;
double HubbleParam;
char fill[256- 6*4- 6*8- 2*8- 2*4- 6*4- 2*4 - 4*8]; /* fills to 256 Bytes */
} t_io_header_1;
template <class T> class CG2_T_Header {
public:
T time;
T redshift;
T BoxSize;
T Omega0;
T OmegaLambda;
T HubbleParam;
};
typedef struct s_data_type_header {
int size_bytes;
int items;
......@@ -71,7 +81,7 @@ const t_data_type_header dth[NB_DATA_HEADER] = {
{DOUBLE ,1}, // double BoxSize;
{DOUBLE ,1}, // double Omega0;
{DOUBLE ,1}, // double OmegaLambda;
{DOUBLE ,1}, // double HubbleParam;
{DOUBLE ,1}, // double HubbleParam;
{CHAR ,96} // char fill[256- 6*4- 6*8- 2*8- 2*4- 6*4- 2*4 - 4*8];
};
......@@ -82,7 +92,7 @@ const t_data_type_header dth[NB_DATA_HEADER] = {
// ---------------------------------------------------
template <class T> class CSnapshotGadgetIn : public CSnapshotInterfaceIn<T> {
public:
// READING constrcuctor
CSnapshotGadgetIn(const std::string, const std::string, const std::string, const bool verb=false);
......@@ -130,6 +140,7 @@ const t_data_type_header dth[NB_DATA_HEADER] = {
T tframe,redshift;
int ntotmasses;
t_io_header_1 header;
CG2_T_Header<T> t_header;
int npartTotal, npart, npart_total_local;
int array_vs_file_size; // array vs file 0:same 1:smaler(half) 2:bigger(double)
inline void checkFileVsArray(const int bytes_to_read, const int size_data, const int npart) {
......@@ -193,7 +204,7 @@ const t_data_type_header dth[NB_DATA_HEADER] = {
T * getCm(int & n) { n=1*(header.npartTotal[0]+header.npartTotal[4]); return cm;}
T * getCmGas(int & n) { n=1*(header.npartTotal[0]); return cm;}
T * getCmStars(int & n) { n=1*(header.npartTotal[4]); return ((cm==NULL)?cm:cm+header.npartTotal[0]*1);}
bool getHeader(std::string name, T * data);
//fortran offset record length
int frecord_offset;
//control
......@@ -250,7 +261,7 @@ const t_data_type_header dth[NB_DATA_HEADER] = {
return len;
}
}; // end of class CSnapshotGadgetIn
}; // end of class CSnapshotGadgetIn
//
//
......@@ -274,11 +285,11 @@ const t_data_type_header dth[NB_DATA_HEADER] = {
// array by double keys
int setData(std::string, std::string, const int , T *,const bool _addr=false);
int setData(std::string, std::string, const int , int *,const bool _addr=false);
int setData(std::string, const int , int *,const bool _addr=false);
int setData(std::string, const int ,
int setData(std::string, const int ,
T *, T *, T *, const bool _addr=false);
int save();
std::vector<double> moveToCom();
......@@ -326,8 +337,9 @@ const t_data_type_header dth[NB_DATA_HEADER] = {
int setMetalStars(const int _n, T * _ms , const bool addr);
// extra TAGS
int setExtra(std::string tag, const int _n, T * _data, const bool addr);
int setHeader(std::string tag, T _data);
}; // end of class CSnapshotGadgetOut
}; // end of class CSnapshotGadgetOut
} // namespace
#endif
......@@ -36,6 +36,23 @@ template <class T> CSnapshotRamsesIn<T>::CSnapshotRamsesIn(const std::string _na
this->valid=false;
part = new ramses::CPart(this->filename,this->verbose);
amr = new ramses::CAmr(this->filename,this->verbose);
// convert Header to template format
t_header = new ramses::T_Header<T>;
t_header->omega_m = (T) amr->getHeader()->omega_m;
t_header->omega_l = (T) amr->getHeader()->omega_l;
t_header->omega_k = (T) amr->getHeader()->omega_k;
t_header->omega_b = (T) amr->getHeader()->omega_b;
t_header->h0 = (T) amr->getHeader()->h0;
t_header->aexp_ini = (T) amr->getHeader()->aexp_ini;
t_header->boxlen_ini = (T) amr->getHeader()->boxlen_ini;
t_header->boxlen = (T) amr->getHeader()->boxlen;
t_header->aexp = (T) amr->getHeader()->aexp;
t_header->hexp = (T) amr->getHeader()->hexp;
t_header->aexp_old = (T) amr->getHeader()->aexp_old;
t_header->epot_tot_int = (T) amr->getHeader()->epot_tot_int;
t_header->epot_tot_old = (T) amr->getHeader()->epot_tot_old;
if (part->isValid() || amr->isValid()) {
this->valid=true;
this->interface_type = "Ramses";
......@@ -303,6 +320,30 @@ template <class T> int CSnapshotRamsesIn<T>::reorderParticles(uns::UserSelection
return 1;
}
// ============================================================================
// getHeader
template <class T> bool CSnapshotRamsesIn<T>::getHeader(const std::string name, T * data)
{
std::string nameupper = tools::Ctools::toupper(name);
int status = false;
if (nameupper=="BOXLEN" || nameupper=="BOXSIZE") {
*data= (T) t_header->boxlen;
status = true;
}
if (nameupper=="OMEGA_M" || nameupper=="OMEGA0") {
*data= (T) t_header->omega_m;
status = true;
}
if (nameupper=="OMEGA_L" || nameupper=="OMEGALAMBDA") {
*data= (T) t_header->omega_l;
status = true;
}
if (nameupper=="HUBBLEPARAM" || nameupper=="H0") {
*data= (T) t_header->h0;
status = true;
}
return status;
}
// ============================================================================
// getData
// return requested array according 'name' selection
template <class T> bool CSnapshotRamsesIn<T>::getData(const std::string comp, const std::string name, int *n,T **data)
......@@ -341,7 +382,7 @@ template <class T> bool CSnapshotRamsesIn<T>::getData(const std::string comp, co
ok=false;
}
break;
default: ok=false;
default: ok=false;
}
} else {
......@@ -582,6 +623,9 @@ template <class T> bool CSnapshotRamsesIn<T>::getData(const std::string name,T *
break;
default: ok=false;
if (getHeader(name,data)) {
ok = true;
}
}
if (this->verbose) {
if (ok) {
......
......@@ -24,6 +24,7 @@ namespace ramses {
class CAmr;
class CPart;
class CGrav;
template <class T> class T_Header;
}
namespace uns {
......@@ -39,7 +40,7 @@ public:
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,u,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, nvarh;
......@@ -71,8 +72,10 @@ private:
ramses::CGrav * grav;
CParticles<T> * particles;
bool first_loc;
ramses::T_Header<T> * t_header;
int reorderParticles(uns::UserSelection & );
bool getHeader(std::string name, T * data);
};
}
#endif // SNAPSHOTRAMSES_H
......
// ============================================================================
// Copyright Jean-Charles LAMBERT - 2008-2016
// Centre de donneeS Astrophysiques de Marseille (CeSAM)
// e-mail: Jean-Charles.Lambert@lam.fr
// address: Aix Marseille Universite, CNRS, LAM
// Laboratoire d'Astrophysique de Marseille
// Pole de l'Etoile, site de Chateau-Gombert
// 38, rue Frederic Joliot-Curie
// 13388 Marseille cedex 13 France
// CNRS UMR 7326
// e-mail: Jean-Charles.Lambert@lam.fr
// address: Aix Marseille Universite, CNRS, LAM
// Laboratoire d'Astrophysique de Marseille
// Pole de l'Etoile, site de Chateau-Gombert
// 38, rue Frederic Joliot-Curie
// 13388 Marseille cedex 13 France
// CNRS UMR 7326
// ============================================================================
#include "uns.h"
......@@ -94,7 +94,7 @@ template <class T> void CunsIn2<T>::init(const std::string _name ,const std::st
}
if (!valid) { // nemo
trySnapList(); // try snapshotlist
}
}
if (!valid) {
trySimDB(); // try DataBase
}
......@@ -157,7 +157,7 @@ template <class T> void CunsIn2<T>::tryNemo()
// trySim
template <class T> void CunsIn2<T>::trySimDB()
{
#ifndef NOSQLITE3
#ifndef NOSQLITE3
snapshot = new CSnapshotSimIn<T>(simname, sel_comp, sel_time, verbose);
valid = snapshot->isValidData();
if (valid && 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["czs" ] = uns::Czs;
CunsOut2<T>::s_mapStringValues["czsmt" ] = uns::Czsmt;
//
CunsOut2<T>::s_mapStringValues["header" ] = uns::Header;
// EXTRA
CunsOut2<T>::s_mapStringValues["EXTRA" ] = uns::Extra;
// HYDRO
CunsOut2<T>::s_mapStringValues["hydro" ] = uns::Hydro;
CunsOut2<T>::s_mapStringValues["nvarh" ] = uns::Nvarh;
......@@ -431,6 +435,6 @@ template class CunsOut2<float>;
template class CunsOut2<double>;
}
// ----------------------------------------------------------------------------
// End of file
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// End of file
// ----------------------------------------------------------------------------
// ============================================================================
// Copyright Jean-Charles LAMBERT - 2008-2016
// Centre de donneeS Astrophysiques de Marseille (CeSAM)
// e-mail: Jean-Charles.Lambert@lam.fr
// address: Aix Marseille Universite, CNRS, LAM
// Laboratoire d'Astrophysique de Marseille
// Pole de l'Etoile, site de Chateau-Gombert
// 38, rue Frederic Joliot-Curie
// 13388 Marseille cedex 13 France
// CNRS UMR 7326
// Centre de donneeS Astrophysiques de Marseille (CeSAM)
// e-mail: Jean-Charles.Lambert@lam.fr
// address: Aix Marseille Universite, CNRS, LAM
// Laboratoire d'Astrophysique de Marseille
// Pole de l'Etoile, site de Chateau-Gombert
// 38, rue Frederic Joliot-Curie
// 13388 Marseille cedex 13 France
// CNRS UMR 7326
// ============================================================================
//
// How to implement a plugin for UNSIO
......@@ -68,6 +68,7 @@ inline std::string getVersion() { return uns::VERSION; }
enum StringData {
// data
EMPTY ,
Time ,
Redshift ,
Pos ,
......@@ -95,6 +96,9 @@ enum StringData {
Czsmt ,
Ssl ,
// Header
Header ,
// hydro data
Hydro , // hydro arrays (mainly for RAMSES)
Nvarh , // #hydros arrays
......@@ -117,17 +121,20 @@ enum StringData {
Stars ,
Bndry ,
All ,
GasMPV ,
HaloMPV ,
DiskMPV ,
BulgeMPV ,
StarsMPV ,
BndryMPV
BndryMPV ,
// Extra data
Extra
};
// class Cuns
// manage Unified Nbody Snapshot Input operations
// class Cuns
// manage Unified Nbody Snapshot Input operations
template <class T> class CunsIn2 {
public:
......@@ -170,7 +177,7 @@ enum StringData {
unsigned int * size,int ** iarray);
bool getData(const std::string prop,int * ivalue);
// close
bool close() {
bool status=false;
......@@ -221,7 +228,7 @@ typedef CunsIn2<float> CunsInF;
typedef CunsIn2<double> CunsInD;
// class CunsOut2
// manage Unified Nbody Snapshot Output operations
// manage Unified Nbody Snapshot Output operations
template <class T> class CunsOut2 {
public:
......@@ -266,7 +273,7 @@ typedef CunsIn2<double> CunsInD;
static void initializeStringMap(const bool);
private:
std::string simname, simtype; // OUT
//bool findSim();
bool valid;
bool verbose;
......
......@@ -19,7 +19,7 @@
#define UNSIO_MAJOR "1"
#define UNSIO_MINOR "2"
#define UNSIO_PATCH "0"
#define UNSIO_EXTRA "-dev-Sep-21-2018"
#define UNSIO_EXTRA "-dev-May-09-2019"
#endif // UNS_VERSION_H
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