Skip to content
Snippets Groups Projects
Commit c0690f45 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Updated the testSymmetry to run multiple random realisations. Also tests the...

Updated the testSymmetry to run multiple random realisations. Also tests the chemistry part of the particles.
parent a919026a
No related branches found
No related tags found
No related merge requests found
...@@ -26,12 +26,13 @@ ...@@ -26,12 +26,13 @@
#include "swift.h" #include "swift.h"
int main(int argc, char *argv[]) { void print_bytes(void *p, size_t len) {
printf("(");
for (size_t i = 0; i < len; ++i) printf("%02x", ((unsigned char *)p)[i]);
printf(")\n");
}
/* Choke on FPEs */ void test() {
#ifdef HAVE_FE_ENABLE_EXCEPT
feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
#endif
#if defined(SHADOWFAX_SPH) #if defined(SHADOWFAX_SPH)
/* Initialize the Voronoi simulation box */ /* Initialize the Voronoi simulation box */
...@@ -52,8 +53,8 @@ int main(int argc, char *argv[]) { ...@@ -52,8 +53,8 @@ int main(int argc, char *argv[]) {
for (size_t i = 0; i < 3; ++i) pj.x[0] = random_uniform(-1., 1.); for (size_t i = 0; i < 3; ++i) pj.x[0] = random_uniform(-1., 1.);
pi.h = 2.f; pi.h = 2.f;
pj.h = 2.f; pj.h = 2.f;
pi.id = 1; pi.id = 1ll;
pj.id = 2; pj.id = 2ll;
#if defined(GIZMO_SPH) || defined(SHADOWFAX_SPH) #if defined(GIZMO_SPH) || defined(SHADOWFAX_SPH)
/* Give the primitive variables sensible values, since the Riemann solver does /* Give the primitive variables sensible values, since the Riemann solver does
...@@ -120,11 +121,11 @@ int main(int argc, char *argv[]) { ...@@ -120,11 +121,11 @@ int main(int argc, char *argv[]) {
memcpy(&pi2, &pi, sizeof(struct part)); memcpy(&pi2, &pi, sizeof(struct part));
memcpy(&pj2, &pj, sizeof(struct part)); memcpy(&pj2, &pj, sizeof(struct part));
int i_ok = memcmp(&pi, &pi2, sizeof(struct part)); int i_not_ok = memcmp(&pi, &pi2, sizeof(struct part));
int j_ok = memcmp(&pj, &pj2, sizeof(struct part)); int j_not_ok = memcmp(&pj, &pj2, sizeof(struct part));
if (i_ok != 0) error("Particles 'pi' do not match after copy"); if (i_not_ok) error("Particles 'pi' do not match after copy");
if (j_ok != 0) error("Particles 'pj' do not match after copy"); if (j_not_ok) error("Particles 'pj' do not match after copy");
/* Compute distance vector */ /* Compute distance vector */
float dx[3]; float dx[3];
...@@ -152,11 +153,11 @@ int main(int argc, char *argv[]) { ...@@ -152,11 +153,11 @@ int main(int argc, char *argv[]) {
runner_iact_nonsym_chemistry(r2, dx, pj2.h, pi2.h, &pj2, &pi2); runner_iact_nonsym_chemistry(r2, dx, pj2.h, pi2.h, &pj2, &pi2);
/* Check that the particles are the same */ /* Check that the particles are the same */
i_ok = memcmp(&pi, &pi2, sizeof(struct part)); i_not_ok = memcmp(&pi, &pi2, sizeof(struct part));
j_ok = memcmp(&pj, &pj2, sizeof(struct part)); j_not_ok = memcmp(&pj, &pj2, sizeof(struct part));
if (i_ok) error("Particles 'pi' do not match after density"); if (i_not_ok) error("Particles 'pi' do not match after density");
if (j_ok) error("Particles 'pj' do not match after density"); if (j_not_ok) error("Particles 'pj' do not match after density");
/* --- Test the force loop --- */ /* --- Test the force loop --- */
...@@ -172,8 +173,8 @@ int main(int argc, char *argv[]) { ...@@ -172,8 +173,8 @@ int main(int argc, char *argv[]) {
/* Check that the particles are the same */ /* Check that the particles are the same */
#if defined(GIZMO_SPH) #if defined(GIZMO_SPH)
i_ok = 0; i_not_ok = 0;
j_ok = 0; j_not_ok = 0;
for (size_t i = 0; i < sizeof(struct part) / sizeof(float); ++i) { for (size_t i = 0; i < sizeof(struct part) / sizeof(float); ++i) {
float a = *(((float *)&pi) + i); float a = *(((float *)&pi) + i);
float b = *(((float *)&pi2) + i); float b = *(((float *)&pi2) + i);
...@@ -200,24 +201,53 @@ int main(int argc, char *argv[]) { ...@@ -200,24 +201,53 @@ int main(int argc, char *argv[]) {
message("%.8e, %.8e, %lu", c, d, i); message("%.8e, %.8e, %lu", c, d, i);
} }
i_ok |= a_is_b; i_not_ok |= a_is_b;
j_ok |= c_is_d; j_not_ok |= c_is_d;
} }
#else #else
i_ok = memcmp(&pi, &pi2, sizeof(struct part)); i_not_ok =
j_ok = memcmp(&pj, &pj2, sizeof(struct part)); strncmp((const char *)&pi, (const char *)&pi2, sizeof(struct part));
j_not_ok =
strncmp((const char *)&pj, (const char *)&pj2, sizeof(struct part));
#endif #endif
if (i_ok) { if (i_not_ok) {
printParticle_single(&pi, &xpi); printParticle_single(&pi, &xpi);
printParticle_single(&pi2, &xpi); printParticle_single(&pi2, &xpi);
error("Particles 'pi' do not match after force"); print_bytes(&pj, sizeof(struct part));
print_bytes(&pj2, sizeof(struct part));
error("Particles 'pi' do not match after force (byte = %d)", i_not_ok);
} }
if (j_ok) { if (j_not_ok) {
printParticle_single(&pj, &xpj); printParticle_single(&pj, &xpj);
printParticle_single(&pj2, &xpj); printParticle_single(&pj2, &xpj);
error("Particles 'pj' do not match after force"); print_bytes(&pj, sizeof(struct part));
print_bytes(&pj2, sizeof(struct part));
error("Particles 'pj' do not match after force (byte = %d)", j_not_ok);
}
}
int main(int argc, char *argv[]) {
/* Initialize CPU frequency, this also starts time. */
unsigned long long cpufreq = 0;
clocks_set_cpufreq(cpufreq);
/* Choke on FPEs */
#ifdef HAVE_FE_ENABLE_EXCEPT
feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
#endif
/* Get some randomness going */
const int seed = time(NULL);
message("Seed = %d", seed);
srand(seed);
for (int i = 0; i < 100; ++i) {
message("Random test %d/100", i);
test();
} }
message("All good");
return 0; return 0;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment