Merge branch 'master' of bitbucket.org:glavaux/cosmotool
This commit is contained in:
commit
59b1b12be8
14 changed files with 84 additions and 19 deletions
|
@ -3,7 +3,6 @@ SET(CosmoTool_SRCS
|
|||
fortran.cpp
|
||||
interpolate.cpp
|
||||
load_data.cpp
|
||||
loadGadget.cpp
|
||||
loadRamses.cpp
|
||||
powerSpectrum.cpp
|
||||
miniargs.cpp
|
||||
|
@ -12,6 +11,14 @@ SET(CosmoTool_SRCS
|
|||
cic.cpp
|
||||
)
|
||||
|
||||
IF (Boost_FOUND)
|
||||
include_directories(${Boost_INCLUDE_DIRS})
|
||||
SET(CosmoTool_SRCS
|
||||
${CosmoTool_SRCS}
|
||||
loadGadget.cpp
|
||||
)
|
||||
ENDIF (Boost_FOUND)
|
||||
|
||||
IF (ENABLE_OPENMP)
|
||||
ENDIF (ENABLE_OPENMP)
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ static double powC(double q, double alpha_c)
|
|||
|
||||
static double T_tilde_0(double q, double alpha_c, double beta_c)
|
||||
{
|
||||
static const double c_E = 2.718282; //M_E;
|
||||
static const double c_E = M_E;
|
||||
double a = log(c_E + 1.8 * beta_c * q);
|
||||
return a / ( a + powC(q, alpha_c) * q * q);
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ void UnformattedRead::beginCheckpoint()
|
|||
checkPointRef = (cSize == Check_32bits) ? 4 : 8;
|
||||
checkPointAccum = 0;
|
||||
|
||||
checkPointRef = (cSize == Check_32bits) ? readInt32() : readInt64();
|
||||
checkPointRef = (cSize == Check_32bits) ? readUint32() : readInt64();
|
||||
checkPointAccum = 0;
|
||||
|
||||
if (f->eof())
|
||||
|
@ -144,7 +144,7 @@ void UnformattedRead::endCheckpoint(bool autodrop)
|
|||
void UnformattedRead::readOrderedBuffer(void *buffer, int size)
|
||||
throw (InvalidUnformattedAccess)
|
||||
{
|
||||
if ((checkPointAccum+size) > checkPointRef)
|
||||
if ((checkPointAccum+(uint64_t)size) > checkPointRef)
|
||||
throw InvalidUnformattedAccess();
|
||||
|
||||
f->read((char *)buffer, size);
|
||||
|
@ -186,6 +186,20 @@ float UnformattedRead::readReal32()
|
|||
return a.f;
|
||||
}
|
||||
|
||||
uint32_t UnformattedRead::readUint32()
|
||||
throw (InvalidUnformattedAccess)
|
||||
{
|
||||
union
|
||||
{
|
||||
char b[4];
|
||||
uint32_t i;
|
||||
} a;
|
||||
|
||||
readOrderedBuffer(&a, 4);
|
||||
|
||||
return a.i;
|
||||
}
|
||||
|
||||
int32_t UnformattedRead::readInt32()
|
||||
throw (InvalidUnformattedAccess)
|
||||
{
|
||||
|
|
|
@ -73,6 +73,8 @@ namespace CosmoTool
|
|||
// Todo implement primitive description
|
||||
void setOrdering(Ordering o);
|
||||
void setCheckpointSize(CheckpointSize cs);
|
||||
|
||||
uint64_t getBlockSize() const { return checkPointRef; }
|
||||
|
||||
void beginCheckpoint()
|
||||
throw (InvalidUnformattedAccess,EndOfFileException);
|
||||
|
@ -83,6 +85,8 @@ namespace CosmoTool
|
|||
throw (InvalidUnformattedAccess);
|
||||
float readReal32()
|
||||
throw (InvalidUnformattedAccess);
|
||||
uint32_t readUint32()
|
||||
throw (InvalidUnformattedAccess);
|
||||
int32_t readInt32()
|
||||
throw (InvalidUnformattedAccess);
|
||||
int64_t readInt64()
|
||||
|
|
|
@ -146,10 +146,12 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id,
|
|||
}
|
||||
|
||||
if (h.flag_doubleprecision) {
|
||||
cout << "Gadget format with double precision" << endl;
|
||||
readToDouble = boost::bind(myRead64<double>, f);
|
||||
readToSingle = boost::bind(myRead64<float>, f);
|
||||
float_size = sizeof(double);
|
||||
} else {
|
||||
cout << "Gadget format with single precision" << endl;
|
||||
readToDouble = boost::bind(myRead32<double>, f);
|
||||
readToSingle = boost::bind(myRead32<float>, f);
|
||||
float_size = sizeof(float);
|
||||
|
@ -188,8 +190,19 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id,
|
|||
try
|
||||
{
|
||||
f->beginCheckpoint();
|
||||
if (f->getBlockSize() != NumPart*float_size*3) {
|
||||
// Check that single would work
|
||||
if (f->getBlockSize() == NumPart*sizeof(float)*3) {
|
||||
// Change to single
|
||||
cout << "Change back to single. Buggy header." << endl;
|
||||
readToDouble = boost::bind(myRead32<double>, f);
|
||||
readToSingle = boost::bind(myRead32<float>, f);
|
||||
float_size = sizeof(float);
|
||||
}
|
||||
}
|
||||
for(int k = 0, p = 0; k < 6; k++) {
|
||||
for(int n = 0; n < h.npart[k]; n++) {
|
||||
// if ((n%1000000)==0) cout << n << endl;
|
||||
data->Pos[0][p] = readToSingle();
|
||||
data->Pos[1][p] = readToSingle();
|
||||
data->Pos[2][p] = readToSingle();
|
||||
|
@ -230,6 +243,7 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id,
|
|||
for(int k = 0, p = 0; k < 6; k++) {
|
||||
for(int n = 0; n < h.npart[k]; n++) {
|
||||
// THIS IS GADGET 1
|
||||
// if ((n%1000000)==0) cout << n << endl;
|
||||
data->Vel[0][p] = readToSingle()*velmul;
|
||||
data->Vel[1][p] = readToSingle()*velmul;
|
||||
data->Vel[2][p] = readToSingle()*velmul;
|
||||
|
@ -292,6 +306,7 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id,
|
|||
if (loadflags & NEED_MASS) {
|
||||
bool do_load = false;
|
||||
|
||||
cout << "=> Mass" << endl;
|
||||
for (int k = 0; k < 6; k++)
|
||||
{
|
||||
do_load = do_load || ((h.mass[k] == 0)&&(h.npart[k]>0));
|
||||
|
@ -308,11 +323,13 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id,
|
|||
if (h.mass[k] == 0) {
|
||||
for(int n = 0; n < h.npart[k]; n++)
|
||||
{
|
||||
// if ((n%1000000)==0) cout << n << endl;
|
||||
data->Mass[l++] = readToSingle();
|
||||
}
|
||||
} else {
|
||||
for(int n = 0; n < h.npart[k]; n++)
|
||||
{
|
||||
if ((n%1000000)==0) cout << n << endl;
|
||||
data->Mass[l++] = h.mass[k];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ knowledge of the CeCILL license and that you accept its terms.
|
|||
using namespace CosmoTool;
|
||||
|
||||
//#define LARGE_CONTROL
|
||||
#define LITTLE_ENDIAN
|
||||
//#define LITTLE_ENDIAN
|
||||
|
||||
#define NEW(t,n) ((t *)malloc(sizeof(t)*n))
|
||||
#define SKIP(f) fread(&dummy,sizeof(dummy),1,f);
|
||||
|
|
|
@ -60,9 +60,10 @@ namespace CosmoTool
|
|||
typedef void (*runParticleValue)(ValType& t);
|
||||
|
||||
public:
|
||||
typedef SPHCell *P_SPHCell;
|
||||
struct SPHState
|
||||
{
|
||||
boost::shared_ptr<SPHCell *[]> ngb;
|
||||
boost::shared_ptr<P_SPHCell[]> ngb;
|
||||
boost::shared_ptr<CoordType[]> distances;
|
||||
typename SPHTree::coords currentCenter;
|
||||
int currentNgb;
|
||||
|
|
|
@ -48,15 +48,15 @@ SPHSmooth<ValType,Ndims>::fetchNeighbours(const typename SPHTree::coords& c, uin
|
|||
if (requested > maxNgb)
|
||||
{
|
||||
maxNgb = requested;
|
||||
internal.ngb = boost::shared_ptr<SPHCell*[]>(new SPHCell *[maxNgb]);
|
||||
internal.ngb = boost::shared_ptr<P_SPHCell[]>(new P_SPHCell[maxNgb]);
|
||||
internal.distances = boost::shared_ptr<CoordType[]>(new CoordType[maxNgb]);
|
||||
}
|
||||
|
||||
memcpy(internal.currentCenter, c, sizeof(c));
|
||||
tree->getNearestNeighbours(c, requested, internal.ngb.get(), internal.distances.get());
|
||||
tree->getNearestNeighbours(c, requested, (SPHCell **)internal.ngb.get(), (CoordType*)internal.distances.get());
|
||||
|
||||
internal.currentNgb = 0;
|
||||
for (uint32_t i = 0; i < requested && internal.ngb[i] != 0; i++,internal.currentNgb++)
|
||||
for (uint32_t i = 0; i < requested && (internal.ngb)[i] != 0; i++,internal.currentNgb++)
|
||||
{
|
||||
internal.distances[i] = sqrt(internal.distances[i]);
|
||||
d2 = internal.distances[i];
|
||||
|
@ -191,9 +191,8 @@ void SPHSmooth<ValType,Ndims>::addGridSite(const typename SPHTree::coords& c)
|
|||
for (uint32_t i = 0; i < internal.currentNgb; i++)
|
||||
{
|
||||
ComputePrecision d = internal.distances[i];
|
||||
SPHCell& cell = *internal.ngb[i];
|
||||
SPHCell& cell = *(internal.ngb[i]);
|
||||
cell.val.weight += getKernel(d/internal.smoothRadius) / r3;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue