Commit 678963fa authored by jclamber's avatar jclamber

ramses in progress...

git-svn-id: http://svn.oamp.fr/repos/unsio/trunk@104 ce2cc22f-6084-46ce-a062-084b172ee5dc
parent f27c077d
This diff is collapsed.
// ============================================================================
// Copyright Jean-Charles LAMBERT - 2007-2012
// e-mail: Jean-Charles.Lambert@oamp.fr
// address: Dynamique des galaxies
// Laboratoire d'Astrophysique de Marseille
// Pole de l'Etoile, site de Chateau-Gombert
// 38, rue Frederic Joliot-Curie
// 13388 Marseille cedex 13 France
// CNRS U.M.R 7326
// ============================================================================
/*
@author Jean-Charles Lambert <Jean-Charles.Lambert@oamp.fr>
*/
#ifndef CAMR_H
#define CAMR_H
#include <string>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <vector>
#include "cfortio.h"
#include "snapshotramses.h"
namespace uns {
class CParticles;
}
namespace ramses {
class CAmr {
public:
CAmr(const std::string,const bool _v=true);
~CAmr();
void setBoundary(float x[8]) {
xmin=x[0];
xmax=x[1];
ymin=x[2];
ymax=x[3];
zmin=x[4];
zmax=x[5];
if (x[7]==0.) {
lmax= nlevelmax;
} else {
lmax = (int) x[7];
}
lmin = std::min((int) x[6],lmax-1);
}
bool isValid();
int loadData(uns::CParticles * particles,
const unsigned int req_bits);
int getNbody() { return nbody;}
private:
// some variables
bool verbose,valid;
std::string infile,indir;
int select,nselect;
int nbody;
std::string s_run_index,ordering;
float xmin,xmax,ymin,ymax,zmin,zmax;
int lmin,lmax;
CFortIO amr, hydro;
int readHeader();
// amr header variables
static const double XH, mH, kB;
int ncpu, ndim, nx, ny ,nz, nlevelmax, ngridmax, nboundary, ngrid_current;
int twotondim;
double xbound[3];
// hydro
int nvarh;
double scale_nH;
};
} // end of namespace
#endif // CAMR_H
// ============================================================================
// Copyright Jean-Charles LAMBERT - 2007-2012
// e-mail: Jean-Charles.Lambert@oamp.fr
// address: Dynamique des galaxies
// Laboratoire d'Astrophysique de Marseille
// Pole de l'Etoile, site de Chateau-Gombert
// 38, rue Frederic Joliot-Curie
// 13388 Marseille cedex 13 France
// CNRS U.M.R 7326
// ============================================================================
/*
@author Jean-Charles Lambert <Jean-Charles.Lambert@oamp.fr>
*/
#include <cstdlib>
#include <sstream>
#include <iomanip>
#include "cfortio.h"
// ============================================================================
//
CFortIO::CFortIO()
{
}
// ============================================================================
//
CFortIO::~CFortIO()
{
close();
}
// ============================================================================
//
void CFortIO::close()
{
if (!fake_reading && in.is_open()) {
in.close();
}
}
// ============================================================================
// open() :
// open file and return :
int CFortIO::open(const std::string myfile, bool fake,bool _swap)
{
int ret=1;
fake_reading = fake;
infile = myfile;
swap = _swap;
if (!fake_reading) {
in.clear();
in.open(myfile.c_str(),std::ios::in | std::ios::binary);
if ( ! in.is_open()) {
std::cerr << "Unable to open file ["<<myfile<<"], aborting...\n";
ret=0;
}
}
return ret;
}
// ============================================================================
// Copyright Jean-Charles LAMBERT - 2007-2012
// e-mail: Jean-Charles.Lambert@oamp.fr
// address: Dynamique des galaxies
// Laboratoire d'Astrophysique de Marseille
// Pole de l'Etoile, site de Chateau-Gombert
// 38, rue Frederic Joliot-Curie
// 13388 Marseille cedex 13 France
// CNRS U.M.R 7326
// ============================================================================
/*
@author Jean-Charles Lambert <Jean-Charles.Lambert@oamp.fr>
*/
#ifndef CFORTIO_H
#define CFORTIO_H
#include <string>
#include <assert.h>
#include <fstream>
#include <iostream>
#define CHAR 1
class CFortIO
{
public:
CFortIO();
~CFortIO();
int open(const std::string myfile, bool _fake=false,bool _swap=false);
void close();
bool good() {
if (!fake_reading) return in.good();
else return true;}
inline int readDataBlock(char * ptr) {
if (!fake_reading) {
int len1=readFRecord();
readData(ptr,1,len1);
int len2=readFRecord();
assert(good() && len1==len2);
return len1;
} else return 1;
}
inline int readData(char * ptr,const size_t size_bytes,const int items) {
if (!fake_reading) {
// get data from file
in.read(ptr,size_bytes*items);
//assert(in.good());
if (! in.good()) return 0;
// We SWAP data
if (swap && (size_bytes != CHAR)) { // swapping requested
for (int i=0; i<items; i++) {
swapBytes(ptr,size_bytes);
ptr += size_bytes;
}
}
}
return 1;
}
// read fortran record
inline int readFRecord() {
if (!fake_reading) {
int len; in.read((char *) &len,sizeof(int));
// We SWAP data
if (swap) { // swapping requested
swapBytes(&len,sizeof(int));
}
assert(in.good());
return len;
}
else return 1;
}
// skip Block
inline void skipBlock(int n=1) {
if (!fake_reading) {
for (int i=0;i<n;i++) {
int len1 = readFRecord();
in.seekg(len1,std::ios::cur);
int len2 = readFRecord();
assert(in.good() && len1==len2);
}
}
}
private:
std::ifstream in;
bool swap;
std::string infile;
bool fake_reading;
// swap bytes
inline void swapBytes(void * x,const int size) {
char * p=(char *) x;
for (int i=0;i<size/2;i++) {
int t=*(p+i); *(p+i)=*(p+size-i-1); *(p+size-i-1)=t;
}
}
};
#endif // CFORTIO_H
This diff is collapsed.
// ============================================================================
// Copyright Jean-Charles LAMBERT - 2007-2012
// e-mail: Jean-Charles.Lambert@oamp.fr
// address: Dynamique des galaxies
// Laboratoire d'Astrophysique de Marseille
// Pole de l'Etoile, site de Chateau-Gombert
// 38, rue Frederic Joliot-Curie
// 13388 Marseille cedex 13 France
// CNRS U.M.R 7326
// ============================================================================
/*
@author Jean-Charles Lambert <Jean-Charles.Lambert@oamp.fr>
*/
#ifndef CPART_H
#define CPART_H
#include <string>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <vector>
#include "cfortio.h"
#include "snapshotramses.h"
namespace uns {
class CParticles;
}
namespace ramses {
class CPart {
public:
CPart(const std::string,const bool _v=true);
~CPart();
void setBoundary(float x[6]) {
xmin=x[0];
xmax=x[1];
ymin=x[2];
ymax=x[3];
zmin=x[4];
zmax=x[5];
}
bool isValid();
int loadData(uns::CParticles * particles,
const unsigned int req_bits, const unsigned int comp_bits);
int getNbody(int * dm, int * stars) {
*dm = ndm_box;
*stars = nstar_box;
return nselect;
}
private:
bool verbose,valid;
std::string infile,indir;
int nselect;
int npart,nstar,ncpu,ndim,nbody,ndm;
int ndm_box, nstar_box;
std::string s_run_index;
float xmin,xmax,ymin,ymax,zmin,zmax;
CFortIO part;
int readHeader();
};
} // namespace ramses
#endif
This diff is collapsed.
......@@ -29,10 +29,12 @@ class CParticles {
public:
CParticles() {
ntot=ngas=ndm,nstars=0;
load_bits=0;
}
std::vector <float> pos,vel,mass,hsml,rho,temp,age;
std::vector <int> indexes;
int ntot, ngas, ndm, nstars;
unsigned int load_bits;
};
class CSnapshotRamsesIn: public CSnapshotInterfaceIn {
......@@ -57,6 +59,8 @@ private:
ramses::CPart * part;
CParticles * particles;
bool first_loc;
int reorderParticles(uns::UserSelection & );
};
}
#endif // SNAPSHOTRAMSES_H
......
// ============================================================================
// Copyright Jean-Charles LAMBERT - 2008-2010
// Copyright Jean-Charles LAMBERT - 2008-2012
// e-mail: Jean-Charles.Lambert@oamp.fr
// address: Dynamique des galaxies
// Laboratoire d'Astrophysique de Marseille
......@@ -29,7 +29,7 @@
namespace uns {
// static variable to store DATA string
std::map<std::string, StringData> CunsOut::s_mapStringValues;
std::map<std::string, int> CunsIn::s_mapCompInt;
// ----------------------------------------------------------------------------
// READING OPERATIONS
CunsIn::CunsIn(const std::string _name ,const std::string _comp ,const std::string _time, const bool verb)
......@@ -42,6 +42,15 @@ namespace uns {
CunsIn::CunsIn(const char * _name ,const char * _comp, const char * _time,
const bool verb)
{
CunsIn::s_mapCompInt["gas" ] = 0;
CunsIn::s_mapCompInt["halo" ] = 1;
CunsIn::s_mapCompInt["dm" ] = 1;
CunsIn::s_mapCompInt["disk" ] = 2;
CunsIn::s_mapCompInt["bulge" ] = 3;
CunsIn::s_mapCompInt["stars" ] = 4;
CunsIn::s_mapCompInt["bndry" ] = 5;
CunsIn::s_mapCompInt["all" ] =-1;
init(_name,_comp,_time,verb);
}
// ----------------------------------------------------------------------------
......@@ -211,6 +220,7 @@ namespace uns {
CunsOut::s_mapStringValues["gas" ] = uns::Gas;
CunsOut::s_mapStringValues["halo" ] = uns::Halo;
CunsOut::s_mapStringValues["dm" ] = uns::Halo;
CunsOut::s_mapStringValues["ndm" ] = uns::Halo;
CunsOut::s_mapStringValues["bulge" ] = uns::Bulge;
CunsOut::s_mapStringValues["disk" ] = uns::Disk;
CunsOut::s_mapStringValues["stars" ] = uns::Stars;
......
......@@ -84,6 +84,9 @@ namespace uns {
bool isValid() { return valid;}
CSnapshotInterfaceIn * snapshot; // object to store data
// Map to associate component with a type
static std::map<std::string, int> s_mapCompInt;
private:
void init(const std::string ,const std::string,const std::string, const bool verb=false );
std::string simname, sel_comp, sel_time; // IN
......@@ -113,6 +116,8 @@ namespace uns {
// Map to associate the strings with the enum values
static std::map<std::string, StringData> s_mapStringValues;
static void initializeStringMap(const bool);
private:
std::string simname, simtype; // OUT
......
......@@ -17,6 +17,7 @@
#include <algorithm>
#include "assert.h"
#include "ctools.h"
#include "uns.h"
namespace uns {
// ============================================================================
......@@ -96,7 +97,16 @@ bool UserSelection::setSelection(const std::string _sel,
crvResize(crvsel);
}
} else { // parse comp_bits with no_data
select_order.clear();
status=parse();
if (select_order.size()==1 && select_order[0]==-1) { // "all" has been selected
// set to default
select_order.clear();
for (int i=0;i<6;i++) {
select_order.push_back(i);
}
}
}
return status;
}
......@@ -196,7 +206,12 @@ int UserSelection::isComponent(const std::string comp)
while (rx[i] && match==-1) {
if (rx[i]) {
std::string tmp=rx[i];
if (tmp == comp) match=i;
if (tmp == comp) {
match=i;
if (comp=="dm") {
match=i-1;
}
}
}
i++;
}
......@@ -209,7 +224,7 @@ int UserSelection::isComponent(const std::string comp)
std::string type=rx[match];
int offset;
int icrv=ComponentRange::getIndexMatchType(crv,type,offset);
if (icrv != -1 ) {
if (icrv != -1 && !nodata) {
assert(icrv<(int)crv->size());
comp_bits |= tools::Ctools::compBits(type);
first=(*crv)[icrv].first;
......@@ -222,8 +237,9 @@ int UserSelection::isComponent(const std::string comp)
pos++;
}
else {
if (nodata) { // no data know yet (like ramses)
comp_bits |= tools::Ctools::compBits(type);
if (nodata) { // no data known yet (like ramses)
comp_bits |= tools::Ctools::compBits(type); // one more bits component
select_order.push_back(CunsIn::s_mapCompInt[comp]); // save order
} else {
status=4; // type does not exist
}
......
......@@ -42,6 +42,13 @@ public:
static std::string parseString(std::string&);
ComponentRangeVector * getCrvFromSelection() { return &crvsel;}
int compBits() { return comp_bits; }
std::vector <int> selectOrder() {
return select_order;
}
void setCrv(ComponentRangeVector _crv) {
crvsel = _crv;
}
private:
ParticlesObjectVector pov;
static int comparePos(const void * a, const void * b) {
......@@ -49,6 +56,7 @@ private:
t_indexes_tab * bb = (t_indexes_tab *) b;
return (aa->p - bb->p);
}
std::vector <int> select_order;
std::string select; // input range (console | GUI)
bool parse(); // parse selection
int parseComponent(const std::string);
......
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