11 #include <gsl/gsl_rng.h>
37 #pragma omp parallel for
54 pow(3.0 / (4 * M_PI) * DesNumNgb *
P[i].Mass / (Tree->
Nodes[no].
mom.
mass),
63 double maxHsml=
P[0].Hsml, minHsml=
P[0].Hsml;
64 #pragma omp parallel for reduction(min:minHsml) reduction(max:maxHsml)
66 assert_true(isfinite(
P[i].Hsml));
67 assert_true(isfinite(
SPHP(i).Density));
68 assert_true(
SPHP(i).Density > 0);
69 if(
P[i].Hsml < minHsml)
71 if(
P[i].Hsml > maxHsml)
74 assert_true(isfinite(minHsml));
75 assert_true(minHsml >= MinGasHsml);
76 assert_true(maxHsml <= PartManager->BoxSize);
80 static void do_density_test(
void ** state,
const int numpart,
double expectedhsml,
double hsmlerr)
83 #pragma omp parallel for reduction(+: npbh)
84 for(i=0; i<numpart; i++) {
94 SPHP(i).DtEntropy = 0;
135 double ms = (end - start)*1000;
136 message(0,
"Found densities in %.3g ms\n", ms);
140 #pragma omp parallel for reduction(+:avghsml)
141 for(i=0; i<numpart; i++) {
142 avghsml +=
P[i].Hsml;
144 message(0,
"Average Hsml: %g Expected %g +- %g\n",avghsml/numpart, expectedhsml, hsmlerr);
145 assert_true(fabs(avghsml/numpart - expectedhsml) < hsmlerr);
147 double * Hsml =
mymalloc2(
"Hsml", numpart *
sizeof(
double));
148 #pragma omp parallel for
149 for(i=0; i<numpart; i++) {
159 ms = (end - start)*1000;
160 message(0,
"Found 1 dev densities in %.3g ms\n", ms);
166 #pragma omp parallel for reduction(max:diff)
167 for(i=0; i<numpart; i++) {
169 if(fabs(Hsml[i] -
P[i].Hsml) > diff)
170 diff = fabs(Hsml[i] -
P[i].Hsml);
172 message(0,
"Max diff between Hsml: %g\n",diff);
181 int numpart = ncbrt*ncbrt*ncbrt;
185 #pragma omp parallel for
186 for(i=0; i<numpart; i++) {
200 int numpart = ncbrt*ncbrt*ncbrt;
204 #pragma omp parallel for
205 for(i=0; i<numpart/4; i++) {
215 #pragma omp parallel for
216 for(i=numpart/4; i<numpart; i++) {
219 P[i].Hsml = 2*ncbrt/close;
220 P[i].Pos[0] = 4.1 + (i/ncbrt/ncbrt)/close;
221 P[i].Pos[1] = 4.1 + ((i/ncbrt) % ncbrt) /close;
222 P[i].Pos[2] = 4.1 + (i % ncbrt)/close;
224 P[numpart-1].Type = 5;
234 for(i=0; i<numpart/4; i++) {
243 for(i=numpart/4; i<3*numpart/4; i++) {
251 for(i=3*numpart/4; i<numpart; i++) {
266 gsl_rng *
r = (gsl_rng *) data->
r;
267 int numpart = ncbrt*ncbrt*ncbrt;
322 int64_t atleast[6] = {0};
323 atleast[0] = pow(32,3);
327 for(i = 0; i < 6; i++)
329 const double BoxSize = 8;
351 data->
r = gsl_rng_alloc(gsl_rng_mt19937);
352 gsl_rng_set(data->
r, 0);
353 *state = (
void *) data;
358 const struct CMUnitTest tests[] = {
void init_cosmology(Cosmology *CP, const double TimeBegin, const struct UnitSystem units)
double GetNumNgb(enum DensityKernelType KernelType)
void set_densitypar(struct density_params dp)
struct sph_pred_data slots_allocate_sph_pred_data(int nsph)
void slots_free_sph_pred_data(struct sph_pred_data *sph_scratch)
enum DensityKernelType GetDensityKernelType(void)
void density(const ActiveParticles *act, int update_hsml, int DoEgyDensity, int BlackHoleOn, double MinEgySpec, const DriftKickTimes times, Cosmology *CP, struct sph_pred_data *SPH_predicted, MyFloat *GradRho, const ForceTree *const tree)
@ DENSITY_KERNEL_CUBIC_SPLINE
void message(int where, const char *fmt,...)
void force_tree_rebuild(ForceTree *tree, DomainDecomp *ddecomp, const int HybridNuGrav, const int DoMoments, const char *EmergencyOutputDir)
void init_forcetree_params(const int FastParticleType)
void force_tree_free(ForceTree *tree)
int force_get_father(int no, const ForceTree *tree)
void gravshort_set_softenings(double MeanDMSeparation)
void set_gravshort_treepar(struct gravshort_tree_params tree_params)
#define mymalloc(name, size)
#define mymalloc2(name, size)
struct part_manager_type PartManager[1]
void particle_alloc_memory(struct part_manager_type *PartManager, double BoxSize, int64_t MaxPart)
static peano_t PEANO(double *Pos, double BoxSize)
#define BITS_PER_DIMENSION
size_t slots_reserve(int where, int64_t atleast[6], struct slots_manager_type *sman)
void slots_set_enabled(int ptype, size_t elsize, struct slots_manager_type *sman)
struct slots_manager_type SlotsManager[1]
void slots_init(double increase, struct slots_manager_type *sman)
int64_t NumActiveParticle
struct topnode_data * TopNodes
struct topleaf_data * TopLeaves
int domain_allocated_flag
double MaxNumNgbDeviation
double DensityResolutionEta
double MinGasHsmlFractional
double BlackHoleNgbFactor
enum DensityKernelType DensityKernelType
double BlackHoleMaxAccretionRadius
struct sph_pred_data sph_pred
double FractionalGravitySoftening
static void test_density_close(void **state)
static void do_density_test(void **state, const int numpart, double expectedhsml, double hsmlerr)
static void set_init_hsml(ForceTree *Tree)
static struct ClockTable CT
static int teardown_density(void **state)
static void check_densities(double MinGasHsml)
static void test_density_random(void **state)
static int setup_density(void **state)
void trivial_domain(DomainDecomp *ddecomp)
void do_random_test(void **state, gsl_rng *r, const int numpart)
static void test_density_flat(void **state)
void setup_sync_points(double TimeIC, double TimeMax, double no_snapshot_until_time, int SnapshotWithFOF)
struct UnitSystem get_unitsystem(double UnitLength_in_cm, double UnitMass_in_g, double UnitVelocity_in_cm_per_s)
void walltime_init(struct ClockTable *ct)