Skip to content

Commit

Permalink
Fix the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sbird committed Dec 26, 2024
1 parent 590350a commit 23b5947
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 60 deletions.
6 changes: 3 additions & 3 deletions libgadget/tests/test_density.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static struct density_testdata setup_density(void)
static void check_densities(double MinGasHsml)
{
int i;
double maxHsml=P[0].Hsml, minHsml= P[0].Hsml;
double maxHsml=PartManager->Base[0].Hsml, minHsml= PartManager->Base[0].Hsml;
for(i=0; i<PartManager->NumPart; i++) {
BOOST_TEST(std::isfinite(PartManager->Base[i].Hsml));
BOOST_TEST(std::isfinite(SPHP(i).Density));
Expand Down Expand Up @@ -264,8 +264,8 @@ BOOST_AUTO_TEST_CASE(test_density_close)
PartManager->Base[i].Pos[1] = 4.1 + ((i/ncbrt) % ncbrt) /close;
PartManager->Base[i].Pos[2] = 4.1 + (i % ncbrt)/close;
}
P[numpart-1].Type = 5;
P[numpart-1].PI = 0;
PartManager->Base[numpart-1].Type = 5;
PartManager->Base[numpart-1].PI = 0;

do_density_test(&data, numpart, 0.131726, 1e-4);
free_domain(&data.ddecomp);
Expand Down
16 changes: 8 additions & 8 deletions libgadget/tests/test_fof.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ setup_particles(int NumPart, double BoxSize)
int i;
#pragma omp parallel for
for(i = 0; i < PartManager->NumPart; i ++) {
P[i].ID = i + PartManager->NumPart * ThisTask;
PartManager->Base[i].ID = i + PartManager->NumPart * ThisTask;
/* DM only*/
P[i].Type = 1;
P[i].Mass = 1;
P[i].IsGarbage = 0;
PartManager->Base[i].Type = 1;
PartManager->Base[i].Mass = 1;
PartManager->Base[i].IsGarbage = 0;
int j;
for(j=0; j<3; j++) {
P[i].Pos[j] = BoxSize * (j+1) * P[i].ID / (PartManager->NumPart * NTask);
while(P[i].Pos[j] > BoxSize)
P[i].Pos[j] -= BoxSize;
PartManager->Base[i].Pos[j] = BoxSize * (j+1) * PartManager->Base[i].ID / (PartManager->NumPart * NTask);
while(PartManager->Base[i].Pos[j] > BoxSize)
PartManager->Base[i].Pos[j] -= BoxSize;
}
}
fof_init(BoxSize/cbrt(PartManager->NumPart));
Expand Down Expand Up @@ -94,6 +94,6 @@ BOOST_AUTO_TEST_CASE(test_fof)
fof_finish(&fof);
domain_free(&ddecomp);
slots_free(SlotsManager);
myfree(P);
myfree(PartManager->Base);
return;
}
56 changes: 28 additions & 28 deletions libgadget/tests/test_forcetree.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static int check_moments(const ForceTree * tb, const int numpart, const int nrea
BOOST_TEST(fnode >= tb->firstnode);
BOOST_TEST(fnode < tb->lastnode);
while(fnode > 0) {
tb->Nodes[fnode].mom.mass -= P[i].Mass;
tb->Nodes[fnode].mom.mass -= PartManager->Base[i].Mass;
fnode = tb->Nodes[fnode].father;
/*Validate father*/
if(fnode != -1) {
Expand Down Expand Up @@ -85,7 +85,7 @@ static int check_moments(const ForceTree * tb, const int numpart, const int nrea
if(tb->Nodes[node].f.ChildType == PARTICLE_NODE_TYPE)
for(i = 0; i < nop->s.noccupied; i++) {
int nn = nop->s.suns[i];
printf("particles P[%d], Mass=%g\n", nn, P[nn].Mass);
printf("particles PartManager->Base[%d], Mass=%g\n", nn, PartManager->Base[nn].Mass);
}
}
BOOST_TEST(tb->Nodes[node].mom.mass < 0.5);
Expand Down Expand Up @@ -135,7 +135,7 @@ static int check_tree(const ForceTree * tb, const int nnodes, const int numpart)
int child = pNode->s.suns[j];
BOOST_TEST(child >= 0);
BOOST_TEST(child < firstnode);
P[child].PI += 1;
PartManager->Base[child].PI += 1;
BOOST_TEST(force_get_father(child, tb) == i);
}
}
Expand All @@ -161,7 +161,7 @@ static int check_tree(const ForceTree * tb, const int nnodes, const int numpart)

for(i=0; i<numpart; i++)
{
BOOST_TEST(P[i].PI == 1);
BOOST_TEST(PartManager->Base[i].PI == 1);
}
printf("Tree filling factor: %g on %d nodes (wasted: %d empty: %d)\n", tot_empty/(8.*nrealnode), nrealnode, nnodes - nrealnode, sevens);
return nrealnode - sevens;
Expand All @@ -173,9 +173,9 @@ static void do_tree_test(const int numpart, ForceTree tb, DomainDecomp * ddecomp
int i;
#pragma omp parallel for
for(i=0; i<numpart; i++) {
P[i].Mass = 1;
P[i].PI = 0;
P[i].IsGarbage = 0;
PartManager->Base[i].Mass = 1;
PartManager->Base[i].PI = 0;
PartManager->Base[i].IsGarbage = 0;
}
int maxnode = tb.lastnode - tb.firstnode;
PartManager->MaxPart = numpart;
Expand Down Expand Up @@ -215,7 +215,7 @@ static double compute_distance(int i, struct NODE * node)
/* Compute each direction independently and take the maximum.
* This is the largest possible distance away from node center within a cube bounding hsml.
* Note that because Pos - Center < len/2, the maximum value this can have is Hsml.*/
hmax = DMAX(hmax, fabs(P[i].Pos[j] - node->center[j]) + P[i].Hsml - node->len/2.);
hmax = DMAX(hmax, fabs(PartManager->Base[i].Pos[j] - node->center[j]) + PartManager->Base[i].Hsml - node->len/2.);
}
return hmax;
}
Expand All @@ -226,7 +226,7 @@ static double check_inside(int i, struct NODE * node)
{
int j;
for(j = 0; j < 3; j++)
if (fabs(P[i].Pos[j] - node->center[j]) > node->len/2)
if (fabs(PartManager->Base[i].Pos[j] - node->center[j]) > node->len/2)
return 0;
return 1;
}
Expand Down Expand Up @@ -259,11 +259,11 @@ static void do_tree_mask_hmax_update_test(const int numpart, ForceTree * tb, Dom
int i;
#pragma omp parallel for
for(i=0; i<numpart; i++) {
P[i].Mass = 1;
P[i].PI = 0;
P[i].IsGarbage = 0;
P[i].Type = 0;
P[i].Hsml = PartManager->BoxSize/cbrt(numpart) * get_random_number(i, &rnd);
PartManager->Base[i].Mass = 1;
PartManager->Base[i].PI = 0;
PartManager->Base[i].IsGarbage = 0;
PartManager->Base[i].Type = 0;
PartManager->Base[i].Hsml = PartManager->BoxSize/cbrt(numpart) * get_random_number(i, &rnd);
}
free_random_numbers(&rnd);
PartManager->MaxPart = numpart;
Expand Down Expand Up @@ -347,10 +347,10 @@ BOOST_AUTO_TEST_CASE(test_rebuild_flat)
int i;
#pragma omp parallel for
for(i=0; i<numpart; i++) {
P[i].Type = 1;
P[i].Pos[0] = (PartManager->BoxSize/ncbrt) * (i/ncbrt/ncbrt);
P[i].Pos[1] = (PartManager->BoxSize/ncbrt) * ((i/ncbrt) % ncbrt);
P[i].Pos[2] = (PartManager->BoxSize/ncbrt) * (i % ncbrt);
PartManager->Base[i].Type = 1;
PartManager->Base[i].Pos[0] = (PartManager->BoxSize/ncbrt) * (i/ncbrt/ncbrt);
PartManager->Base[i].Pos[1] = (PartManager->BoxSize/ncbrt) * ((i/ncbrt) % ncbrt);
PartManager->Base[i].Pos[2] = (PartManager->BoxSize/ncbrt) * (i % ncbrt);
}
PartManager->NumPart = numpart;
/*Allocate tree*/
Expand Down Expand Up @@ -383,10 +383,10 @@ BOOST_AUTO_TEST_CASE(test_rebuild_close)
int i;
#pragma omp parallel for
for(i=0; i<numpart; i++) {
P[i].Type = 1;
P[i].Pos[0] = 4. + (i/ncbrt/ncbrt)/close;
P[i].Pos[1] = 4. + ((i/ncbrt) % ncbrt) /close;
P[i].Pos[2] = 4. + (i % ncbrt)/close;
PartManager->Base[i].Type = 1;
PartManager->Base[i].Pos[0] = 4. + (i/ncbrt/ncbrt)/close;
PartManager->Base[i].Pos[1] = 4. + ((i/ncbrt) % ncbrt) /close;
PartManager->Base[i].Pos[2] = 4. + (i % ncbrt)/close;
}
PartManager->NumPart = numpart;
ForceTree tb = force_treeallocate(0.7*numpart, numpart, &ddecomp, 1, 0);
Expand All @@ -407,22 +407,22 @@ void do_random_test(boost::random::mt19937 & r, const int numpart, const ForceTr
* in a box 8 kpc across.*/
int i;
for(i=0; i<numpart/4; i++) {
P[i].Type = 1;
PartManager->Base[i].Type = 1;
int j;
for(j=0; j<3; j++)
P[i].Pos[j] = PartManager->BoxSize * dist(r);
PartManager->Base[i].Pos[j] = PartManager->BoxSize * dist(r);
}
for(i=numpart/4; i<3*numpart/4; i++) {
P[i].Type = 1;
PartManager->Base[i].Type = 1;
int j;
for(j=0; j<3; j++)
P[i].Pos[j] = PartManager->BoxSize/2 + PartManager->BoxSize/8 * exp(pow(dist(r)-0.5,2));
PartManager->Base[i].Pos[j] = PartManager->BoxSize/2 + PartManager->BoxSize/8 * exp(pow(dist(r)-0.5,2));
}
for(i=3*numpart/4; i<numpart; i++) {
P[i].Type = 1;
PartManager->Base[i].Type = 1;
int j;
for(j=0; j<3; j++)
P[i].Pos[j] = PartManager->BoxSize*0.1 + PartManager->BoxSize/32 * exp(pow(dist(r)-0.5,2));
PartManager->Base[i].Pos[j] = PartManager->BoxSize*0.1 + PartManager->BoxSize/32 * exp(pow(dist(r)-0.5,2));
}
PartManager->NumPart = numpart;
do_tree_test(numpart, tb, ddecomp);
Expand Down
42 changes: 21 additions & 21 deletions libgadget/tests/test_gravity.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ grav_force(const int p_i, const int other, const double * offset, double * accns
double dist[3];
for(d = 0; d < 3; d ++) {
/* the distance vector points to 'other' */
dist[d] = offset[d] + P[p_i].Pos[d] - P[other].Pos[d];
dist[d] = offset[d] + PartManager->Base[p_i].Pos[d] - PartManager->Base[other].Pos[d];
r2 += dist[d] * dist[d];
}

Expand All @@ -69,8 +69,8 @@ grav_force(const int p_i, const int other, const double * offset, double * accns
}

for(d = 0; d < 3; d ++) {
accns[3*p_i + d] += - dist[d] * fac * G * P[other].Mass;
accns[3*other + d] += dist[d] * fac * G * P[p_i].Mass;
accns[3*p_i + d] += - dist[d] * fac * G * PartManager->Base[other].Mass;
accns[3*other + d] += dist[d] * fac * G * PartManager->Base[p_i].Mass;
}
}

Expand All @@ -84,7 +84,7 @@ void check_accns(double * meanerr_tot, double * maxerr_tot, double *PairAccn, do
{
int k;
for(k=0; k<3; k++) {
double err = fabs((PairAccn[3*i+k] - (P[i].GravPM[k] + P[i].FullTreeGravAccel[k]))/meanacc);
double err = fabs((PairAccn[3*i+k] - (PartManager->Base[i].GravPM[k] + PartManager->Base[i].FullTreeGravAccel[k]))/meanacc);
meanerr += err;
if(maxerr < err)
maxerr = err;
Expand All @@ -109,7 +109,7 @@ static void find_means(double * meangrav, double * suppmean, double * suppaccns)
for(k=0; k<3; k++) {
if(suppaccns)
meanacc += fabs(suppaccns[3*i+k]);
meanforce += fabs(P[i].GravPM[k] + P[i].FullTreeGravAccel[k]);
meanforce += fabs(PartManager->Base[i].GravPM[k] + PartManager->Base[i].FullTreeGravAccel[k]);
}
}
int64_t tot_npart;
Expand Down Expand Up @@ -169,12 +169,12 @@ static void do_force_test(int Nmesh, double Asmth, double ErrTolForceAcc, int di
int i;
#pragma omp parallel for
for(i=0; i<PartManager->NumPart; i++) {
P[i].Type = 1;
P[i].Mass = 1;
P[i].ID = i;
P[i].TimeBinHydro = 0;
P[i].TimeBinGravity = 0;
P[i].IsGarbage = 0;
PartManager->Base[i].Type = 1;
PartManager->Base[i].Mass = 1;
PartManager->Base[i].ID = i;
PartManager->Base[i].TimeBinHydro = 0;
PartManager->Base[i].TimeBinGravity = 0;
PartManager->Base[i].IsGarbage = 0;
}

DomainDecomp ddecomp = {0};
Expand Down Expand Up @@ -235,9 +235,9 @@ BOOST_AUTO_TEST_CASE(test_force_flat)
int i;
#pragma omp parallel for
for(i=0; i<numpart; i++) {
P[i].Pos[0] = (PartManager->BoxSize/ncbrt) * (i/ncbrt/ncbrt);
P[i].Pos[1] = (PartManager->BoxSize/ncbrt) * ((i/ncbrt) % ncbrt);
P[i].Pos[2] = (PartManager->BoxSize/ncbrt) * (i % ncbrt);
PartManager->Base[i].Pos[0] = (PartManager->BoxSize/ncbrt) * (i/ncbrt/ncbrt);
PartManager->Base[i].Pos[1] = (PartManager->BoxSize/ncbrt) * ((i/ncbrt) % ncbrt);
PartManager->Base[i].Pos[2] = (PartManager->BoxSize/ncbrt) * (i % ncbrt);
}
PartManager->NumPart = numpart;
do_force_test(48, 1.5, 0.002, 0);
Expand All @@ -248,7 +248,7 @@ BOOST_AUTO_TEST_CASE(test_force_flat)
{
int k;
for(k=0; k<3; k++) {
double err = fabs((P[i].GravPM[k] + P[i].FullTreeGravAccel[k]));
double err = fabs((PartManager->Base[i].GravPM[k] + PartManager->Base[i].FullTreeGravAccel[k]));
meanerr += err;
if(maxerr < err)
maxerr = err;
Expand Down Expand Up @@ -279,9 +279,9 @@ BOOST_AUTO_TEST_CASE(test_force_close)
int i;
#pragma omp parallel for
for(i=0; i<numpart; i++) {
P[i].Pos[0] = 4. + (i/ncbrt/ncbrt)/close;
P[i].Pos[1] = 4. + ((i/ncbrt) % ncbrt) /close;
P[i].Pos[2] = 4. + (i % ncbrt)/close;
PartManager->Base[i].Pos[0] = 4. + (i/ncbrt/ncbrt)/close;
PartManager->Base[i].Pos[1] = 4. + ((i/ncbrt) % ncbrt) /close;
PartManager->Base[i].Pos[2] = 4. + (i % ncbrt)/close;
}
PartManager->NumPart = numpart;
do_force_test(48, 1.5, 0.002, 1);
Expand All @@ -297,17 +297,17 @@ void do_random_test(boost::random::mt19937 & r, const int numpart)
for(i=0; i<numpart/4; i++) {
int j;
for(j=0; j<3; j++)
P[i].Pos[j] = PartManager->BoxSize * dist(r);
PartManager->Base[i].Pos[j] = PartManager->BoxSize * dist(r);
}
for(i=numpart/4; i<3*numpart/4; i++) {
int j;
for(j=0; j<3; j++)
P[i].Pos[j] = PartManager->BoxSize/2 + PartManager->BoxSize/8 * exp(pow(dist(r)-0.5,2));
PartManager->Base[i].Pos[j] = PartManager->BoxSize/2 + PartManager->BoxSize/8 * exp(pow(dist(r)-0.5,2));
}
for(i=3*numpart/4; i<numpart; i++) {
int j;
for(j=0; j<3; j++)
P[i].Pos[j] = PartManager->BoxSize*0.1 + PartManager->BoxSize/32 * exp(pow(dist(r)-0.5,2));
PartManager->Base[i].Pos[j] = PartManager->BoxSize*0.1 + PartManager->BoxSize/32 * exp(pow(dist(r)-0.5,2));
}
PartManager->NumPart = numpart;
do_force_test(48, 1.5, 0.002, 1);
Expand Down

0 comments on commit 23b5947

Please sign in to comment.