Commit 22a7c7b7 authored by jclamber's avatar jclamber

add identity for ramses data

git-svn-id: http://svn.oamp.fr/repos/unsio/trunk@155 ce2cc22f-6084-46ce-a062-084b172ee5dc
parent 5a967574
......@@ -29,7 +29,8 @@ BEGIN
use strict; # must define everything
use Getopt::Long;
use Tools::Tools;
use Tools::Sqlite3;
use DBI;
# -------------------------------------------------------------
# Main program
# get exe basename
......@@ -40,7 +41,7 @@ my $name;
my $type;
my $dir;
my $base;
my $db = "/pil/programs/DB/simulation.dbl"; # Marseille database
my $db;
my $help = 0;
GetOptions( 'simname=s' => \$name,
......@@ -77,6 +78,9 @@ if ( @ARGV >= 4) {
die "Option --dir not specified.\n" unless defined($dir);
die "Option --base not specified.\n" unless defined($base);
}
my $db = Sqlite->getValidDb($db);
printf STDERR "simname=[$name] type=[$type] dir=[$dir] base=[$base] db=[$db]\n";
# check if file exist
......
......@@ -369,6 +369,10 @@ int CAmr::loadData(uns::CParticles * particles,
particles->metal.push_back(metal);
particles->load_bits |= METAL_BIT;
}
if (req_bits&ID_BIT) {
particles->id.push_back(-1.); // no id for gas, use "-1"
particles->load_bits |= ID_BIT;
}
if (take) {
particles->indexes.push_back(0); // GAS particles
particles->ngas++; // One more gas particles
......
......@@ -116,8 +116,13 @@ int CPart::loadData(uns::CParticles * particles,
tmp[6] = new double[npart]; // alloc
part.readDataBlock((char *) tmp[6]);
double * agetmp, * metaltmp;
int * id=NULL;
//part.skipBlock(); // skip identity
id = new int[npart];
part.readDataBlock((char *) id); // read identity
if (nstar>0) { // || 1) { // there are stars
part.skipBlock(); // skip identity
part.skipBlock(); // skip level
agetmp = new double[npart];
part.readDataBlock((char *) agetmp);
......@@ -167,9 +172,13 @@ int CPart::loadData(uns::CParticles * particles,
if (agetmp[k]==0 && req_bits&METAL_BIT && found_metal) { // stars only (metallicity)
//if ( tmp[6][k] == 0.0 )
//std::cerr << "DM => "<<metaltmp[k]<<" mass=" << tmp[6][k] << "\n";
particles->metal.push_back(tmp[6][k]); // put 0 for dark matter
particles->metal.push_back(tmp[6][k]); // put mass for dark matter
particles->load_bits |= METAL_BIT;
}
if (req_bits&ID_BIT) {
particles->id.push_back(id[k]); // save real id for dm or stars
particles->load_bits |= ID_BIT;
}
if (take && agetmp[k]!=0) {
particles->indexes.push_back(4); // save star positions
particles->nstars++;
......@@ -178,6 +187,7 @@ int CPart::loadData(uns::CParticles * particles,
particles->indexes.push_back(1); // save DM positions
particles->ndm++;
}
particles->ntot++; // one more total particles
offset++;
......@@ -187,6 +197,7 @@ int CPart::loadData(uns::CParticles * particles,
}
// garbage
delete [] agetmp;
delete [] id;
if (req_bits&METAL_BIT) {
delete [] metaltmp;
}
......
......@@ -147,7 +147,7 @@ int CSnapshotRamsesIn::reorderParticles(uns::UserSelection &user_select)
uns::ComponentRange cr;
crv.clear();
// set #prticles per component
// set #particles per component
npart_comp[0] = particles->ngas;
npart_comp[1] = particles->ndm;
npart_comp[4] = particles->nstars;
......@@ -211,6 +211,7 @@ int CSnapshotRamsesIn::reorderParticles(uns::UserSelection &user_select)
// particles reordering
if (particles->ntot) { // exist particles to reorder
std::vector <float> pos,vel,mass,metal;
std::vector <int> id;
if (particles->pos.size()>0)
pos.resize(particles->pos.size()); // resize new pos vector
if (particles->vel.size()>0)
......@@ -219,6 +220,8 @@ int CSnapshotRamsesIn::reorderParticles(uns::UserSelection &user_select)
mass.resize(particles->mass.size()); // resize new mass vector
if (particles->metal.size()>0)
metal.resize(particles->metal.size()); // resize new metal vector
if (particles->id.size()>0)
id.resize(particles->id.size()); // resize new id vector
for (int i=0; i<particles->ntot; i++) {
......@@ -252,6 +255,13 @@ int CSnapshotRamsesIn::reorderParticles(uns::UserSelection &user_select)
found=true;
mass[istart] = particles->mass[i];
}
// id
if (particles->id.size()>0) {
assert(istart<(int)particles->id.size());
found=true;
id[istart] = particles->id[i];
}
// metal
if (particles->metal.size()>0) { // && (icomp==0 || icomp==4)) { // metal for gas or stars
if (!(istart<(int)particles->metal.size())) {
......@@ -267,10 +277,11 @@ int CSnapshotRamsesIn::reorderParticles(uns::UserSelection &user_select)
}
}
// copy back arrays
particles->pos=pos;
particles->vel=vel;
particles->mass=mass;
particles->metal=metal;
particles->pos = pos;
particles->vel = vel;
particles->mass = mass;
particles->metal = metal;
particles->id = id;
//std::cerr << "metal.size() ="<<particles->metal.size() <<"\n";
}
return 1;
......@@ -522,6 +533,14 @@ bool CSnapshotRamsesIn::getData(const std::string comp,const std::string name,in
nbody=particles->ntot;
}
switch(CunsOut::s_mapStringValues[name]) {
case uns::Id :
if (status && particles->id.size()>0) {
*data = &particles->id[first];
*n = nbody;
} else {
ok = false;
}
break;
case uns::Nbody :
if (status) {
*data = NULL;
......
......@@ -32,7 +32,7 @@ public:
load_bits=0;
}
std::vector <float> pos,vel,mass,hsml,rho,temp,age,metal;
std::vector <int> indexes;
std::vector <int> indexes,id;
int ntot, ngas, ndm, nstars;
unsigned int load_bits;
};
......
......@@ -16,6 +16,7 @@
#include "snapshotsim.h"
#include "snapshotgadget.h"
#include "snapshotnemo.h"
#include "snapshotramses.h"
#include "ctools.h"
#include <sstream>
#include <iomanip>
......@@ -144,9 +145,11 @@ bool CSnapshotSimIn::findSqlSim()
if (tools::Ctools::tolower(interface_type) == "gadget") interface_index=1;
else
if (tools::Ctools::tolower(interface_type) == "nemo") interface_index=0;
else {
std::cerr <<"CSnapshotSimIn::findSqlSim => Unknown interface type....\n";
}
else
if (tools::Ctools::tolower(interface_type) == "ramses") interface_index=2;
else {
std::cerr <<"CSnapshotSimIn::findSqlSim => Unknown interface type....\n";
}
}
return status;
}
......@@ -477,15 +480,20 @@ bool CSnapshotSimIn::isNewFrame()
{
bool status=false;
if (valid) {
if (simtype=="Gadget") {
if (tools::Ctools::tolower(simtype)=="gadget") {
status=buildGadgetFile();
}
else {
if (simtype=="Nemo") {
if (tools::Ctools::tolower(simtype)=="nemo") {
status=buildNemoFile();
}
else {
std::cerr <<"\nUnknown simulation type ["<<simtype<<"]\n";
if (tools::Ctools::tolower(simtype)=="ramses") {
status=buildRamsesFile();
}
else {
std::cerr <<"\nUnknown simulation type ["<<simtype<<"]\n";
}
}
}
if (status) {
......@@ -570,6 +578,34 @@ bool CSnapshotSimIn::buildGadgetFile()
return status;
}
// ============================================================================
// buildRamsesFile
bool CSnapshotSimIn::buildRamsesFile()
{
bool status=false;
std::string myfile = dirname+'/'+basename;
if (nframe==0) {
snapshot = new CSnapshotRamsesIn(myfile, select_part, select_time, verbose);
if (snapshot->isValidData()) { // file exist
float t;
bool ok=snapshot->getData("time",&t);
if (ok && checkRangeTime(t)) { // time in range
status=true; // valid snap
nframe++;
} else { // time out of range
delete snapshot; // del object
snapshot = NULL; // NULL for the next
nframe++; // try next frame
}
}
else { // file does not exist
delete snapshot;
snapshot = NULL;
}
}
return status;
}
// ============================================================================
// getCod
// returns:
// -2 file exist but can't open
......
......@@ -87,6 +87,7 @@ namespace uns {
int nframe; // #frames read
bool buildGadgetFile();
bool buildNemoFile();
bool buildRamsesFile();
int addNemoComponent(int&,std::string,std::string );
virtual int nextFrameSelect(ComponentRangeVector * crvs);
std::string nemosim;
......
......@@ -143,7 +143,7 @@ namespace uns {
snapshot = new CSnapshotSimIn(simname, sel_comp, sel_time, verbose);
valid = snapshot->isValidData();
if (valid && verbose) {
std::cerr << "CunsIn::trySimDB() It's a simulation...\n";
std::cerr << "CunsIn::trySimDB() It's recorded to sqlite3 database...\n";
}
#else
valid = false;
......
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