Moved subsampling to the loaders to be able to do online subsampling (only implemented for gadget and multidark so far, the other coming in...)

This commit is contained in:
Guilhem Lavaux 2013-02-25 12:29:09 -05:00
parent ecb4479178
commit 5cf7a94538
9 changed files with 330 additions and 34 deletions

View file

@ -2,8 +2,17 @@
#define _MOCK_SIMULATION_LOADER_HPP
#include <string>
#include <algorithm>
#include <CosmoTool/loadSimu.hpp>
struct SingleParticle
{
float Pos[3];
float Vel[3];
long Index;
long ID;
};
class SimulationLoader
{
protected:
@ -15,9 +24,37 @@ protected:
do_redshift = false;
redshift_axis = 2;
}
template<typename T> void reallocArray(T *& a, long newSize, long toCopy)
{
T *b = new T[newSize];
if (a != 0)
{
std::copy(a, a+toCopy, b);
delete[] a;
}
a = b;
}
void reallocSimu(CosmoTool::SimuData *s, long newNumPart);
void applyTransformations(CosmoTool::SimuData *s);
void copyParticleToSimu(const SingleParticle& p, CosmoTool::SimuData *s, long index)
{
s->Pos[0][index] = p.Pos[0];
s->Pos[1][index] = p.Pos[1];
s->Pos[2][index] = p.Pos[2];
if (s->Vel[0])
s->Vel[0][index] = p.Vel[0];
if (s->Vel[1])
s->Vel[1][index] = p.Vel[1];
if (s->Vel[2])
s->Vel[2][index] = p.Vel[2];
s->Id[index] = p.ID;
}
public:
virtual ~SimulationLoader() {}
@ -28,6 +65,38 @@ public:
virtual int num_files() = 0;
virtual CosmoTool::SimuData* loadFile(int id) = 0;
template<typename T>
void filteredCopy(T *a, bool *accepted, long N)
{
long i = 0, j = 0;
if (a == 0)
return;
while (i < N)
{
if (!accepted[i])
{
i++;
continue;
}
a[j] = a[i];
j++;
i++;
}
}
};
class SimulationPreprocessor
{
public:
SimulationPreprocessor() {}
virtual ~SimulationPreprocessor() {}
virtual long getEstimatedPostprocessed(long numParticles) { return numParticles; };
virtual bool accept(const SingleParticle& p) { return true; }
};
template<typename T>
@ -40,10 +109,10 @@ void delete_adaptor(void *ptr)
// 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);
SimulationLoader *gadgetLoader(const std::string& snapshot, double Mpc_unitLength, int flags, SimulationPreprocessor *p);
SimulationLoader *flashLoader(const std::string& snapshot, int flags, SimulationPreprocessor *p);
SimulationLoader *multidarkLoader(const std::string& snapshot, SimulationPreprocessor *p);
SimulationLoader *ramsesLoader(const std::string& snapshot, int baseid, bool double_precision, int flags, SimulationPreprocessor *p);
#endif