mirror of
https://bitbucket.org/cosmicvoids/vide_public.git
synced 2025-07-04 23:31:12 +00:00
Moved simulation loaders into their own subdirectory.
This commit is contained in:
parent
28edc7ce3d
commit
d29f92529b
6 changed files with 0 additions and 0 deletions
111
c_tools/mock/loaders/flash_loader.cpp
Normal file
111
c_tools/mock/loaders/flash_loader.cpp
Normal file
|
@ -0,0 +1,111 @@
|
|||
#include <cassert>
|
||||
#include <string>
|
||||
#include <CosmoTool/loadFlash.hpp>
|
||||
#include <CosmoTool/fortran.hpp>
|
||||
#include "simulation_loader.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace CosmoTool;
|
||||
|
||||
class FlashLoader: public SimulationLoader
|
||||
{
|
||||
private:
|
||||
int load_flags;
|
||||
bool onefile;
|
||||
int _num_files;
|
||||
SimuData *gadget_header;
|
||||
string snapshot_name;
|
||||
public:
|
||||
FlashLoader(const string& basename, SimuData *header, int flags, bool singleFile, int _num)
|
||||
: snapshot_name(basename), load_flags(flags), onefile(singleFile), _num_files(_num), gadget_header(header)
|
||||
{
|
||||
}
|
||||
|
||||
~FlashLoader()
|
||||
{
|
||||
delete gadget_header;
|
||||
}
|
||||
|
||||
SimuData *getHeader() {
|
||||
return gadget_header;
|
||||
}
|
||||
|
||||
int num_files() {
|
||||
return _num_files;
|
||||
}
|
||||
|
||||
SimuData *loadFile(int id) {
|
||||
SimuData *d;
|
||||
|
||||
if (onefile && id > 0)
|
||||
return 0;
|
||||
if (id >= _num_files)
|
||||
return 0;
|
||||
|
||||
if (onefile)
|
||||
d = loadFlashMulti(snapshot_name.c_str(), -1, load_flags);
|
||||
else
|
||||
d = loadFlashMulti(snapshot_name.c_str(), id, load_flags);
|
||||
|
||||
if (d->Id != 0)
|
||||
{
|
||||
long *uniqueID = new long[d->NumPart];
|
||||
for (long i = 0; i < d->NumPart; i++)
|
||||
{
|
||||
uniqueID[i] = d->Id[i];
|
||||
}
|
||||
d->new_attribute("uniqueID", uniqueID, delete_adaptor<long>);
|
||||
}
|
||||
|
||||
applyTransformations(d);
|
||||
|
||||
return d;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
SimulationLoader *flashLoader(const std::string& snapshot, int flags)
|
||||
{
|
||||
bool singleFile;
|
||||
int num_files;
|
||||
SimuData *d;
|
||||
|
||||
try
|
||||
{
|
||||
d = loadFlashMulti(snapshot.c_str(), -1, 0);
|
||||
singleFile = true;
|
||||
num_files = 1;
|
||||
}
|
||||
catch (const NoSuchFileException& e)
|
||||
{
|
||||
try
|
||||
{
|
||||
d = loadFlashMulti(snapshot.c_str(), 0, 0);
|
||||
num_files = 0;
|
||||
}
|
||||
catch(const NoSuchFileException& e)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
assert(d != 0);
|
||||
SimuData *header = d;
|
||||
|
||||
if (!singleFile)
|
||||
{
|
||||
try
|
||||
{
|
||||
while ((d = loadFlashMulti(snapshot.c_str(), num_files, 0)) != 0)
|
||||
{
|
||||
num_files++;
|
||||
delete d;
|
||||
}
|
||||
}
|
||||
catch(const NoSuchFileException& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
return new FlashLoader(snapshot, header, flags, singleFile, num_files);
|
||||
}
|
124
c_tools/mock/loaders/gadget_loader.cpp
Normal file
124
c_tools/mock/loaders/gadget_loader.cpp
Normal file
|
@ -0,0 +1,124 @@
|
|||
#include <cassert>
|
||||
#include <string>
|
||||
#include <CosmoTool/loadGadget.hpp>
|
||||
#include <CosmoTool/fortran.hpp>
|
||||
#include "simulation_loader.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace CosmoTool;
|
||||
|
||||
class GadgetLoader: public SimulationLoader
|
||||
{
|
||||
private:
|
||||
int load_flags;
|
||||
bool onefile;
|
||||
int _num_files;
|
||||
double unitMpc;
|
||||
SimuData *gadget_header;
|
||||
string snapshot_name;
|
||||
public:
|
||||
GadgetLoader(const string& basename, SimuData *header, int flags, bool singleFile, int _num, double unit)
|
||||
: snapshot_name(basename), load_flags(flags), onefile(singleFile), _num_files(_num), unitMpc(1/unit), gadget_header(header)
|
||||
{
|
||||
}
|
||||
|
||||
~GadgetLoader()
|
||||
{
|
||||
delete gadget_header;
|
||||
}
|
||||
|
||||
SimuData *getHeader() {
|
||||
return gadget_header;
|
||||
}
|
||||
|
||||
int num_files() {
|
||||
return _num_files;
|
||||
}
|
||||
|
||||
SimuData *loadFile(int id) {
|
||||
SimuData *d;
|
||||
|
||||
if (onefile && id > 0)
|
||||
return 0;
|
||||
if (id >= _num_files)
|
||||
return 0;
|
||||
|
||||
if (onefile)
|
||||
d = loadGadgetMulti(snapshot_name.c_str(), -1, load_flags);
|
||||
else
|
||||
d = loadGadgetMulti(snapshot_name.c_str(), id, load_flags);
|
||||
|
||||
if (d->Id != 0)
|
||||
{
|
||||
long *uniqueID = new long[d->NumPart];
|
||||
for (long i = 0; i < d->NumPart; i++)
|
||||
{
|
||||
uniqueID[i] = d->Id[i];
|
||||
}
|
||||
d->new_attribute("uniqueID", uniqueID, delete_adaptor<long>);
|
||||
}
|
||||
|
||||
for (int k = 0; k < 3; k++)
|
||||
{
|
||||
if (d->Pos[k] != 0)
|
||||
{
|
||||
for (long i = 0; i < d->NumPart; i++)
|
||||
d->Pos[k][i] *= unitMpc;
|
||||
}
|
||||
}
|
||||
d->BoxSize *= unitMpc;
|
||||
|
||||
applyTransformations(d);
|
||||
|
||||
return d;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
SimulationLoader *gadgetLoader(const std::string& snapshot, double Mpc_unitLength, int flags)
|
||||
{
|
||||
bool singleFile;
|
||||
int num_files;
|
||||
SimuData *d;
|
||||
|
||||
try
|
||||
{
|
||||
d = loadGadgetMulti(snapshot.c_str(), -1, 0);
|
||||
singleFile = true;
|
||||
num_files = 1;
|
||||
}
|
||||
catch (const NoSuchFileException& e)
|
||||
{
|
||||
try
|
||||
{
|
||||
d = loadGadgetMulti(snapshot.c_str(), 0, 0);
|
||||
num_files = 0;
|
||||
}
|
||||
catch(const NoSuchFileException& e)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
assert(d != 0);
|
||||
SimuData *header = d;
|
||||
|
||||
header->BoxSize /= Mpc_unitLength;
|
||||
|
||||
if (!singleFile)
|
||||
{
|
||||
try
|
||||
{
|
||||
while ((d = loadGadgetMulti(snapshot.c_str(), num_files, 0)) != 0)
|
||||
{
|
||||
num_files++;
|
||||
delete d;
|
||||
}
|
||||
}
|
||||
catch(const NoSuchFileException& e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
return new GadgetLoader(snapshot, header, flags, singleFile, num_files, Mpc_unitLength);
|
||||
}
|
108
c_tools/mock/loaders/multidark_loader.cpp
Normal file
108
c_tools/mock/loaders/multidark_loader.cpp
Normal file
|
@ -0,0 +1,108 @@
|
|||
#include <cassert>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <CosmoTool/loadRamses.hpp>
|
||||
#include <CosmoTool/fortran.hpp>
|
||||
#include "simulation_loader.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace CosmoTool;
|
||||
|
||||
class MultiDarkLoader: public SimulationLoader
|
||||
{
|
||||
protected:
|
||||
SimuData *header;
|
||||
string darkname;
|
||||
public:
|
||||
MultiDarkLoader(const std::string& name, SimuData *h)
|
||||
: darkname(name), header(h)
|
||||
{
|
||||
}
|
||||
|
||||
~MultiDarkLoader()
|
||||
{
|
||||
delete header;
|
||||
}
|
||||
|
||||
int num_files()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
SimuData *getHeader()
|
||||
{
|
||||
return header;
|
||||
}
|
||||
|
||||
SimuData *loadFile(int id)
|
||||
{
|
||||
if (id != 0)
|
||||
return 0;
|
||||
|
||||
ifstream fp(darkname.c_str());
|
||||
SimuData *simu;
|
||||
|
||||
fp >> simu->BoxSize >> simu->Omega_M >> simu->Hubble >> simu->time >> simu->NumPart;
|
||||
simu->time = 1./(1.+simu->time); // convert to scale factor
|
||||
simu->TotalNumPart = simu->NumPart;
|
||||
simu->Omega_Lambda = 1.0 - simu->Omega_M;
|
||||
|
||||
for (int k = 0; k < 3; k++)
|
||||
simu->Pos[k] = new float[simu->NumPart];
|
||||
simu->Vel[2] = new float[simu->NumPart];
|
||||
simu->Id = new int[simu->NumPart];
|
||||
long *uniqueID = new long[simu->NumPart];
|
||||
|
||||
simu->new_attribute("uniqueID", uniqueID, delete_adaptor<long>);
|
||||
|
||||
cout << "loading multidark particles" << endl;
|
||||
long actualNumPart = 0;
|
||||
for (int i = 0; i < simu->NumPart; i++) {
|
||||
|
||||
fp >> simu->Id[i] >> simu->Pos[0][i] >> simu->Pos[1][i]
|
||||
>> simu->Pos[2][i] >> simu->Vel[2][i];
|
||||
|
||||
uniqueID[i] = 1;
|
||||
//uniqueID[i] = 1 * simu->Id[i];
|
||||
|
||||
if (simu->Id[i] == -99 &&
|
||||
simu->Pos[0][i] == -99 && simu->Pos[1][i] == -99 &&
|
||||
simu->Pos[2][i] == -99 && simu->Vel[2][i] == -99) {
|
||||
break;
|
||||
} else {
|
||||
actualNumPart++;
|
||||
}
|
||||
}
|
||||
|
||||
simu->NumPart = actualNumPart;
|
||||
simu->TotalNumPart = actualNumPart;
|
||||
return simu;
|
||||
}
|
||||
};
|
||||
|
||||
SimulationLoader *multidarkLoader(const string& multidarkname)
|
||||
{
|
||||
SimuData *header;
|
||||
int actualNumPart;
|
||||
ifstream fp(multidarkname.c_str());
|
||||
|
||||
cout << "opening multidark file " << multidarkname << endl;
|
||||
if (!fp)
|
||||
{
|
||||
cout << "could not open file!" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
header = new SimuData();
|
||||
fp >> header->BoxSize >> header->Omega_M >> header->Hubble >> header->time >> header->NumPart;
|
||||
|
||||
header->time = 1./(1.+header->time); // convert to scale factor
|
||||
header->TotalNumPart = header->NumPart;
|
||||
header->Omega_Lambda = 1.0 - header->Omega_M;
|
||||
|
||||
return new MultiDarkLoader(multidarkname, header);
|
||||
}
|
||||
|
||||
|
||||
|
81
c_tools/mock/loaders/ramses_loader.cpp
Normal file
81
c_tools/mock/loaders/ramses_loader.cpp
Normal file
|
@ -0,0 +1,81 @@
|
|||
#include <cassert>
|
||||
#include <string>
|
||||
#include <CosmoTool/loadRamses.hpp>
|
||||
#include <CosmoTool/fortran.hpp>
|
||||
#include "simulation_loader.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace CosmoTool;
|
||||
|
||||
class RamsesLoader: public SimulationLoader
|
||||
{
|
||||
private:
|
||||
int load_flags;
|
||||
int _num_files;
|
||||
int baseid;
|
||||
bool double_precision;
|
||||
SimuData *ramses_header;
|
||||
string snapshot_name;
|
||||
public:
|
||||
RamsesLoader(const string& basename, int baseid, bool dp, SimuData *header, int flags, int _num)
|
||||
: snapshot_name(basename), load_flags(flags), _num_files(_num), double_precision(dp),
|
||||
ramses_header(header)
|
||||
{
|
||||
}
|
||||
|
||||
~RamsesLoader()
|
||||
{
|
||||
delete ramses_header;
|
||||
}
|
||||
|
||||
SimuData *getHeader() {
|
||||
return ramses_header;
|
||||
}
|
||||
|
||||
int num_files() {
|
||||
return _num_files;
|
||||
}
|
||||
|
||||
SimuData *loadFile(int id) {
|
||||
SimuData *d;
|
||||
|
||||
if (id >= _num_files)
|
||||
return 0;
|
||||
|
||||
d = loadRamsesSimu(snapshot_name.c_str(), baseid, id, double_precision, load_flags);
|
||||
assert(d != 0);
|
||||
|
||||
if (d->Id != 0)
|
||||
{
|
||||
long *uniqueID = new long[d->NumPart];
|
||||
for (long i = 0; i < d->NumPart; i++)
|
||||
{
|
||||
uniqueID[i] = d->Id[i];
|
||||
}
|
||||
d->new_attribute("uniqueID", uniqueID, delete_adaptor<long>);
|
||||
}
|
||||
|
||||
applyTransformations(d);
|
||||
|
||||
return d;
|
||||
}
|
||||
};
|
||||
|
||||
SimulationLoader *ramsesLoader(const std::string& snapshot, int baseid, bool double_precision, int flags)
|
||||
{
|
||||
SimuData *d, *header;
|
||||
int num_files = 0;
|
||||
|
||||
header = loadRamsesSimu(snapshot.c_str(), baseid, 0, double_precision, 0);
|
||||
if (header == 0)
|
||||
return 0;
|
||||
|
||||
while ((d = loadRamsesSimu(snapshot.c_str(), baseid, num_files, double_precision, 0)) != 0)
|
||||
{
|
||||
num_files++;
|
||||
delete d;
|
||||
}
|
||||
|
||||
return new RamsesLoader(snapshot, baseid, double_precision, header, flags, num_files);
|
||||
}
|
||||
|
15
c_tools/mock/loaders/simulation_loader.cpp
Normal file
15
c_tools/mock/loaders/simulation_loader.cpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
#include <CosmoTool/loadSimu.hpp>
|
||||
#include "simulation_loader.hpp"
|
||||
|
||||
using namespace CosmoTool;
|
||||
|
||||
void SimulationLoader::applyTransformations(SimuData *s)
|
||||
{
|
||||
float redshift_gravity = do_redshift ? 1.0 : 0.0;
|
||||
|
||||
for (int i = 0; i < s->NumPart; i++)
|
||||
{
|
||||
s->Pos[redshift_axis][i] +=
|
||||
redshift_gravity*s->Vel[redshift_axis][i]/100.;
|
||||
}
|
||||
}
|
49
c_tools/mock/loaders/simulation_loader.hpp
Normal file
49
c_tools/mock/loaders/simulation_loader.hpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
#ifndef _MOCK_SIMULATION_LOADER_HPP
|
||||
#define _MOCK_SIMULATION_LOADER_HPP
|
||||
|
||||
#include <string>
|
||||
#include <CosmoTool/loadSimu.hpp>
|
||||
|
||||
class SimulationLoader
|
||||
{
|
||||
protected:
|
||||
bool do_redshift;
|
||||
int redshift_axis;
|
||||
|
||||
SimulationLoader()
|
||||
{
|
||||
do_redshift = false;
|
||||
redshift_axis = 2;
|
||||
}
|
||||
|
||||
void applyTransformations(CosmoTool::SimuData *s);
|
||||
|
||||
public:
|
||||
virtual ~SimulationLoader() {}
|
||||
|
||||
void doRedshift(bool set = true) { do_redshift = set; }
|
||||
void setVelAxis(int axis) { redshift_axis = axis; }
|
||||
|
||||
virtual CosmoTool::SimuData *getHeader() = 0;
|
||||
virtual int num_files() = 0;
|
||||
virtual CosmoTool::SimuData* loadFile(int id) = 0;
|
||||
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
void delete_adaptor(void *ptr)
|
||||
{
|
||||
T *ptr_T = reinterpret_cast<T *>(ptr);
|
||||
|
||||
delete[] ptr_T;
|
||||
}
|
||||
|
||||
|
||||
// Unit length is the size of one Mpc in the simulation units
|
||||
SimulationLoader *gadgetLoader(const std::string& snapshot, double Mpc_unitLength, int flags);
|
||||
SimulationLoader *flashLoader(const std::string& snapshot, int flags);
|
||||
SimulationLoader *multidarkLoader(const std::string& snapshot);
|
||||
SimulationLoader *ramsesLoader(const std::string& snapshot, int baseid, bool double_precision, int flags);
|
||||
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue