Added phase loading support in Ramses

This commit is contained in:
Guilhem Lavaux 2009-09-29 16:32:59 -05:00
parent c09f426b7b
commit afd706c1dc
3 changed files with 174 additions and 14 deletions

View File

@ -416,18 +416,171 @@ CosmoTool::PurePositionData *CosmoTool::loadRamsesPosition(const char *basename,
return gd;
}
#if 0
int main(int argc, char **argv)
CosmoTool::PhaseSpaceData *CosmoTool::loadRamsesPhase(const char *basename, int outputId, bool quiet)
{
GadgetData *gd = loadRamses(argv[1]);
PhaseSpaceData *gd = (PhaseSpaceData *)malloc(sizeof(PhaseSpaceData));
int id = 1;
uint32_t totPart = 0;
int nCpu = 0;
InfoData info;
static const double CM_IN_MPC = 3.08e24;
if (!readInfoFile(basename, outputId, info))
return 0;
double L0 = info.boxSize*info.unitLength/CM_IN_MPC/info.aexp;
if (!quiet)
cout << "L0=" << L0 << " Mpc" << endl;
if (!quiet)
cout << "Detecting number of files and particles..." << endl;
while (1)
{
ostringstream ss_fname;
ss_fname << basename << "/part_" << setfill('0') << setw(5) << outputId << ".out" << setfill('0') << setw(5) << id;
string fname = ss_fname.str();
if (!quiet)
cout << " ... " << fname << endl;
try
{
UnformattedRead infile(fname);
int ndim, nPar;
infile.beginCheckpoint();
nCpu = max(1,infile.readInt32());
infile.endCheckpoint();
infile.beginCheckpoint();
ndim = infile.readInt32();
infile.endCheckpoint();
infile.beginCheckpoint();
nPar = infile.readInt32();
infile.endCheckpoint();
if (!quiet)
cout << " NUMCPU=" << nCpu << " NUMDIM=" << ndim << " NumPart=" << nPar << endl;
totPart += nPar;
id++;
}
catch (const NoSuchFileException& e)
{
break;
}
}
assert (totPart <= ((~(size_t)0)/sizeof(FCoordinates)));
size_t memSize = sizeof(FCoordinates)*(size_t)(totPart+totPart/nCpu);
if (!quiet)
cout << " Needing " << memSize / 1024 << " kBytes" << endl;
gd->pos = (FCoordinates *)malloc(sizeof(FCoordinates)*totPart);
assert(gd->pos != 0);
gd->vel = (FCoordinates *)malloc(sizeof(FCoordinates)*totPart);
assert(gd->vel != 0);
gd->NumPart = totPart;
gd->BoxSize = L0*1000;
if (!quiet)
cout << " Total number part=" << totPart << endl
<< "Loading particles ..." << endl;
uint32_t curPos = 0;
id = 1;
while (1)
{
ostringstream ss_fname;
ss_fname << basename << "/part_" << setfill('0') << setw(5) << outputId << ".out" << setfill('0') << setw(5) << id;
string fname = ss_fname.str();
int *idP;
if (!quiet)
(cout << " ... " << id).flush();
try
{
UnformattedRead infile(fname);
int nCpu, ndim, nPar;
infile.beginCheckpoint();
nCpu = infile.readInt32();
infile.endCheckpoint();
infile.beginCheckpoint();
ndim = infile.readInt32();
infile.endCheckpoint();
infile.beginCheckpoint();
nPar = infile.readInt32();
infile.endCheckpoint();
FCoordinates *s = new FCoordinates[nPar];
FCoordinates *vel = new FCoordinates[nPar];
for (int k = 0; k < 3; k++)
{
infile.beginCheckpoint();
for (uint32_t i = 0; i < nPar; i++)
{
s[i][k] = infile.readReal32();
s[i][k] *= gd->BoxSize;
}
infile.endCheckpoint();
}
// SKIP VELOCITIES
for (int k = 0; k < 3; k++) {
infile.beginCheckpoint();
for (uint32_t i = 0; i < nPar; i++)
{
vel[i][k] = infile.readReal32()*gd->BoxSize/1000*100;
}
infile.endCheckpoint();
}
float minMass = INFINITY;
infile.beginCheckpoint();
for (uint32_t i = nPar; i > 0; i--)
{
float dummyF = infile.readReal32();
if (dummyF < minMass) minMass = dummyF;
}
infile.endCheckpoint();
infile.beginCheckpoint();
for (uint32_t i = 0; i < nPar; i++)
{
int id = infile.readInt32();
id--;
assert(id >= 0);
assert(id < totPart);
memcpy(&gd->pos[id], &s[i], sizeof(FCoordinates));
memcpy(&gd->vel[id], &vel[i], sizeof(FCoordinates));
}
infile.endCheckpoint();
delete[] vel;
delete[] s;
curPos += nPar;
} catch (const NoSuchFileException& e)
{
break;
}
id++;
}
if (!quiet)
cout << endl;
return gd;
}
#endif
#if 0
int main(int argc, char **argv)
{
GadgetData *gd = loadRamses(argv[1]);
}
#endif

View File

@ -7,7 +7,7 @@ namespace CosmoTool {
GadgetData *loadRamses(const char *name, bool quiet = false);
PurePositionData *loadRamsesPosition(const char *fname, int id, bool quiet = false);
PhaseSpaceData *loadRamsesPhase(const char *fname, int id, bool quiet = false);
};
#endif

View File

@ -63,6 +63,13 @@ namespace CosmoTool {
FCoordinates *pos;
};
struct PhaseSpaceData {
unsigned int NumPart;
double BoxSize;
FCoordinates *pos;
FCoordinates *vel;
};
void writeGadget(GadgetData *data, const char *fname);
GadgetData *loadGadget(const char *fname);
void freeGadget(GadgetData *data);