testFFT.c 18.9 KB
Newer Older
Matthieu Schaller's avatar
Matthieu Schaller committed
1 2
/*******************************************************************************
 * This file is part of SWIFT.
3
 * Copyright (C) 2017 Matthieu Schaller (matthieu.schaller@durham.ac.uk).
Matthieu Schaller's avatar
Matthieu Schaller committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 ******************************************************************************/

/* Some standard headers. */
21
#include "../config.h"
Matthieu Schaller's avatar
Matthieu Schaller committed
22

23 24
// MATTHIEU fix this test
#if 1 || !defined(HAVE_FFTW)
25

26
int main(int argc, char *argv[]) { return 0; }
27 28 29

#else

30
/* Some standard headers. */
31
#include <fenv.h>
32 33
#include <stdlib.h>
#include <string.h>
Matthieu Schaller's avatar
Matthieu Schaller committed
34 35

/* Includes. */
36
#include "runner_doiact_fft.h"
Matthieu Schaller's avatar
Matthieu Schaller committed
37 38
#include "swift.h"

39 40 41 42 43 44 45 46 47
__attribute__((always_inline)) INLINE static int row_major_id(int i, int j,
                                                              int k, int N) {
  return (((i + N) % N) * N * N + ((j + N) % N) * N + ((k + N) % N));
}

int is_close(double x, double y, double abs_err) {
  return (abs(x - y) < abs_err);
}

48
int main(int argc, char *argv[]) {
Matthieu Schaller's avatar
Matthieu Schaller committed
49 50 51 52
  /* Initialize CPU frequency, this also starts time. */
  unsigned long long cpufreq = 0;
  clocks_set_cpufreq(cpufreq);

53 54 55 56 57
/* Choke on FP-exceptions */
#ifdef HAVE_FE_ENABLE_EXCEPT
  feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
#endif

58 59 60
  /* Make one particle */
  int nr_gparts = 1;
  struct gpart *gparts = NULL;
61 62
  if (posix_memalign((void **)&gparts, gpart_align,
                     nr_gparts * sizeof(struct gpart)) != 0)
63
    error("Impossible to allocate memory for gparts.");
64 65 66 67 68 69 70 71
  bzero(gparts, nr_gparts * sizeof(struct gpart));

  gparts[0].x[0] = 0.3;
  gparts[0].x[1] = 0.8;
  gparts[0].x[2] = 0.2;
  gparts[0].mass = 1.f;

  /* Read the parameter file */
72 73
  struct swift_params *params =
      (struct swift_params *)malloc(sizeof(struct swift_params));
74 75
  parser_read_file("fft_params.yml", params);

76 77 78
  struct cosmology cosmo;
  cosmology_init_no_cosmo(&cosmo);

79 80
  /* Initialise the gravity properties */
  struct gravity_props gravity_properties;
81
  gravity_props_init(&gravity_properties, params, &cosmo);
82 83 84 85

  /* Build the infrastructure */
  struct space space;
  double dim[3] = {1., 1., 1.};
86
  space_init(&space, params, &cosmo, dim, NULL, gparts, NULL, 0, nr_gparts, 0,
87
             1, 1, 0, 1, 1, 0);
88 89 90 91 92

  struct engine engine;
  engine.s = &space;
  space.e = &engine;
  engine.time = 0.1f;
93 94
  engine.ti_current = 0;
  engine.ti_old = 0;
95 96 97
  engine.max_active_bin = num_time_bins;
  engine.gravity_properties = &gravity_properties;
  engine.nr_threads = 1;
98 99
  engine.nodeID = 0;
  engine_rank = 0;
100
  engine.verbose = 1;
101

102 103 104 105 106 107
  struct runner runner;
  runner.e = &engine;

  /* Initialize the threadpool. */
  threadpool_init(&engine.threadpool, engine.nr_threads);

108 109 110 111 112 113 114
  /* Construct the space and all the multipoles. */
  space_rebuild(&space, 1);

/* Initialise the Ewald correction table */
#ifdef SWIFT_GRAVITY_FORCE_CHECKS
  gravity_exact_force_ewald_init(dim[0]);
#endif
115 116 117 118 119 120

  /* Run the FFT task */
  runner_do_grav_fft(&runner, 1);

  /* Now check that we got the right answer */
  int nr_cells = space.nr_cells;
121 122 123 124
  double *r = (double *)malloc(nr_cells * sizeof(double));
  double *m = (double *)malloc(nr_cells * sizeof(double));
  double *pot = (double *)malloc(nr_cells * sizeof(double));
  double *pot_exact = (double *)malloc(nr_cells * sizeof(double));
125

126
  FILE *file = fopen("potential.dat", "w");
127 128
  for (int i = 0; i < nr_cells; ++i) {
    pot[i] = space.multipoles_top[i].pot.F_000;
129
    m[i] = space.multipoles_top[i].m_pole.M_000;
130 131 132 133 134 135
    double dx =
        nearest(space.multipoles_top[i].CoM[0] - gparts[0].x[0], dim[0]);
    double dy =
        nearest(space.multipoles_top[i].CoM[1] - gparts[0].x[1], dim[1]);
    double dz =
        nearest(space.multipoles_top[i].CoM[2] - gparts[0].x[2], dim[2]);
136 137

    /* Distance */
138
    r[i] = sqrt(dx * dx + dy * dy + dz * dz);
139 140 141 142 143 144 145 146 147 148 149 150

    /* Potential with correction */
    if (r[i] > 0) pot_exact[i] = 1. / r[i];

#ifdef SWIFT_GRAVITY_FORCE_CHECKS
    /* Get Ewald periodic correction */
    double f_corr[3], pot_corr;
    gravity_exact_force_ewald_evaluate(dx, dy, dz, f_corr, &pot_corr);
    pot_exact[i] -= pot_corr;
#endif

    fprintf(file, "%e %e %e %e\n", r[i], m[i], pot[i], pot_exact[i]);
Matthieu Schaller's avatar
Matthieu Schaller committed
151
  }
152
  fclose(file);
153

154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
  /* Let's now check the interpolation functions */
  int cdim[3] = {space.cdim[0], space.cdim[1], space.cdim[2]};

  /* Constant function --> Derivatives must be 0 */
  for (int i = 0; i < cdim[0]; ++i) {
    for (int j = 0; j < cdim[1]; ++j) {
      for (int k = 0; k < cdim[2]; ++k) {
        pot[row_major_id(i, j, k, cdim[0])] = 1.;
      }
    }
  }
  for (int i = 0; i < nr_cells; ++i)
    gravity_field_tensors_init(&space.multipoles_top[i].pot, engine.ti_current);
  for (int i = 0; i < nr_cells; ++i)
    mesh_to_multipole_CIC(&space.multipoles_top[i], pot, cdim[0], cdim[0], dim);
  for (int i = 0; i < cdim[0]; ++i) {
    for (int j = 0; j < cdim[1]; ++j) {
      for (int k = 0; k < cdim[2]; ++k) {
        const struct grav_tensor *f =
            &space.multipoles_top[row_major_id(i, j, k, cdim[0])].pot;

        if (!is_close(f->F_000, -1., 1e-10))
          error("Invalid value for (%d %d %d) F_000 (%e)", i, j, k, f->F_000);
        if (!is_close(f->F_100, 0., 1e-10))
          error("Invalid value for (%d %d %d) F_100 (%e)", i, j, k, f->F_100);
        if (!is_close(f->F_010, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_010 (%e)", i, j, k, f->F_010);
        if (!is_close(f->F_001, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_001 (%e)", i, j, k, f->F_001);
        if (!is_close(f->F_200, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_200 (%e)", i, j, k, f->F_200);
        if (!is_close(f->F_020, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_020 (%e)", i, j, k, f->F_020);
        if (!is_close(f->F_002, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_002 (%e)", i, j, k, f->F_002);
        if (!is_close(f->F_011, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_011 (%e)", i, j, k, f->F_011);
        if (!is_close(f->F_101, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_101 (%e)", i, j, k, f->F_101);
        if (!is_close(f->F_110, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_110 (%e)", i, j, k, f->F_110);
      }
    }
  }

  /* Linear function in x --> Derivatives must be 1 */
  for (int i = 0; i < cdim[0]; ++i) {
    for (int j = 0; j < cdim[1]; ++j) {
      for (int k = 0; k < cdim[2]; ++k) {
        pot[row_major_id(i, j, k, cdim[0])] = i / ((double)cdim[0]);
      }
    }
  }
  for (int i = 0; i < nr_cells; ++i)
    gravity_field_tensors_init(&space.multipoles_top[i].pot, engine.ti_current);
  for (int i = 0; i < nr_cells; ++i)
    mesh_to_multipole_CIC(&space.multipoles_top[i], pot, cdim[0], cdim[0], dim);
  for (int i = 2; i < cdim[0] - 3; ++i) {
    for (int j = 0; j < cdim[1]; ++j) {
      for (int k = 0; k < cdim[2]; ++k) {
        const struct grav_tensor *f =
            &space.multipoles_top[row_major_id(i, j, k, cdim[0])].pot;

        if (!is_close(f->F_000, -i / ((double)cdim[0]), 1e-10))
          error("Invalid value for (%d %d %d) F_000 (%e)", i, j, k, f->F_000);
        if (!is_close(f->F_100, -1., 1e-10))
          error("Invalid value for (%d %d %d) F_100 (%e)", i, j, k, f->F_100);
        if (!is_close(f->F_010, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_010 (%e)", i, j, k, f->F_010);
        if (!is_close(f->F_001, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_001 (%e)", i, j, k, f->F_001);
        if (!is_close(f->F_200, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_200 (%e)", i, j, k, f->F_200);
        if (!is_close(f->F_020, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_020 (%e)", i, j, k, f->F_020);
        if (!is_close(f->F_002, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_002 (%e)", i, j, k, f->F_002);
        if (!is_close(f->F_011, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_011 (%e)", i, j, k, f->F_011);
        if (!is_close(f->F_101, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_101 (%e)", i, j, k, f->F_101);
        if (!is_close(f->F_110, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_110 (%e)", i, j, k, f->F_110);
      }
    }
  }

  /* Linear function in y --> Derivatives must be 1 */
  for (int i = 0; i < cdim[0]; ++i) {
    for (int j = 0; j < cdim[1]; ++j) {
      for (int k = 0; k < cdim[2]; ++k) {
        pot[row_major_id(i, j, k, cdim[0])] = j / ((double)cdim[0]);
      }
    }
  }
  for (int i = 0; i < nr_cells; ++i)
    gravity_field_tensors_init(&space.multipoles_top[i].pot, engine.ti_current);
  for (int i = 0; i < nr_cells; ++i)
    mesh_to_multipole_CIC(&space.multipoles_top[i], pot, cdim[0], cdim[0], dim);
  for (int i = 0; i < cdim[0]; ++i) {
    for (int j = 2; j < cdim[1] - 3; ++j) {
      for (int k = 0; k < cdim[2]; ++k) {
        const struct grav_tensor *f =
            &space.multipoles_top[row_major_id(i, j, k, cdim[0])].pot;

        if (!is_close(f->F_000, -j / ((double)cdim[0]), 1e-10))
          error("Invalid value for (%d %d %d) F_000 (%e)", i, j, k, f->F_000);
        if (!is_close(f->F_100, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_100 (%e)", i, j, k, f->F_100);
        if (!is_close(f->F_010, -1., 1e-10))
          error("Invalid value for (%d %d %d) F_010 (%e)", i, j, k, f->F_010);
        if (!is_close(f->F_001, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_001 (%e)", i, j, k, f->F_001);
        if (!is_close(f->F_200, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_200 (%e)", i, j, k, f->F_200);
        if (!is_close(f->F_020, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_020 (%e)", i, j, k, f->F_020);
        if (!is_close(f->F_002, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_002 (%e)", i, j, k, f->F_002);
        if (!is_close(f->F_011, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_011 (%e)", i, j, k, f->F_011);
        if (!is_close(f->F_101, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_101 (%e)", i, j, k, f->F_101);
        if (!is_close(f->F_110, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_110 (%e)", i, j, k, f->F_110);
      }
    }
  }

  /* Linear function in z --> Derivatives must be 1 */
  for (int i = 0; i < cdim[0]; ++i) {
    for (int j = 0; j < cdim[1]; ++j) {
      for (int k = 0; k < cdim[2]; ++k) {
        pot[row_major_id(i, j, k, cdim[0])] = k / ((double)cdim[0]);
      }
    }
  }
  for (int i = 0; i < nr_cells; ++i)
    gravity_field_tensors_init(&space.multipoles_top[i].pot, engine.ti_current);
  for (int i = 0; i < nr_cells; ++i)
    mesh_to_multipole_CIC(&space.multipoles_top[i], pot, cdim[0], cdim[0], dim);
  for (int i = 0; i < cdim[0]; ++i) {
    for (int j = 0; j < cdim[1]; ++j) {
      for (int k = 2; k < cdim[2] - 3; ++k) {
        const struct grav_tensor *f =
            &space.multipoles_top[row_major_id(i, j, k, cdim[0])].pot;

        if (!is_close(f->F_000, -k / ((double)cdim[0]), 1e-10))
          error("Invalid value for (%d %d %d) F_000 (%e)", i, j, k, f->F_000);
        if (!is_close(f->F_100, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_100 (%e)", i, j, k, f->F_100);
        if (!is_close(f->F_010, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_010 (%e)", i, j, k, f->F_010);
        if (!is_close(f->F_001, -1., 1e-10))
          error("Invalid value for (%d %d %d) F_001 (%e)", i, j, k, f->F_001);
        if (!is_close(f->F_200, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_200 (%e)", i, j, k, f->F_200);
        if (!is_close(f->F_020, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_020 (%e)", i, j, k, f->F_020);
        if (!is_close(f->F_002, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_002 (%e)", i, j, k, f->F_002);
        if (!is_close(f->F_011, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_011 (%e)", i, j, k, f->F_011);
        if (!is_close(f->F_101, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_101 (%e)", i, j, k, f->F_101);
        if (!is_close(f->F_110, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_110 (%e)", i, j, k, f->F_110);
      }
    }
  }

  /* Quadratic function in x --> Derivatives must be 2 */
  for (int i = 0; i < cdim[0]; ++i) {
    for (int j = 0; j < cdim[1]; ++j) {
      for (int k = 0; k < cdim[2]; ++k) {
        pot[row_major_id(i, j, k, cdim[0])] =
            i * i / ((double)cdim[0] * cdim[0]);
      }
    }
  }
  for (int i = 0; i < nr_cells; ++i)
    gravity_field_tensors_init(&space.multipoles_top[i].pot, engine.ti_current);
  for (int i = 0; i < nr_cells; ++i)
    mesh_to_multipole_CIC(&space.multipoles_top[i], pot, cdim[0], cdim[0], dim);
  for (int i = 2; i < cdim[0] - 3; ++i) {
    for (int j = 0; j < cdim[1]; ++j) {
      for (int k = 0; k < cdim[2]; ++k) {
        const struct grav_tensor *f =
            &space.multipoles_top[row_major_id(i, j, k, cdim[0])].pot;
        const double val = i / ((double)cdim[0]);
        const double val2 = val * val;

        if (!is_close(f->F_000, -val2, 1e-10))
          error("Invalid value for (%d %d %d) F_000 (%e)", i, j, k, f->F_000);
        if (!is_close(f->F_100, -2 * val, 1e-10))
          error("Invalid value for (%d %d %d) F_100 (%e)", i, j, k, f->F_100);
        if (!is_close(f->F_010, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_010 (%e)", i, j, k, f->F_010);
        if (!is_close(f->F_001, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_001 (%e)", i, j, k, f->F_001);
        if (!is_close(f->F_200, 2.f, 1e-10))
          error("Invalid value for (%d %d %d) F_200 (%e)", i, j, k, f->F_200);
        if (!is_close(f->F_020, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_020 (%e)", i, j, k, f->F_020);
        if (!is_close(f->F_002, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_002 (%e)", i, j, k, f->F_002);
        if (!is_close(f->F_011, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_011 (%e)", i, j, k, f->F_011);
        if (!is_close(f->F_101, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_101 (%e)", i, j, k, f->F_101);
        if (!is_close(f->F_110, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_110 (%e)", i, j, k, f->F_110);
      }
    }
  }

  /* Quadratic function in y --> Derivatives must be 2 */
  for (int i = 0; i < cdim[0]; ++i) {
    for (int j = 0; j < cdim[1]; ++j) {
      for (int k = 0; k < cdim[2]; ++k) {
        pot[row_major_id(i, j, k, cdim[0])] =
            j * j / ((double)cdim[0] * cdim[0]);
      }
    }
  }
  for (int i = 0; i < nr_cells; ++i)
    gravity_field_tensors_init(&space.multipoles_top[i].pot, engine.ti_current);
  for (int i = 0; i < nr_cells; ++i)
    mesh_to_multipole_CIC(&space.multipoles_top[i], pot, cdim[0], cdim[0], dim);
  for (int i = 0; i < cdim[0]; ++i) {
    for (int j = 2; j < cdim[1] - 3; ++j) {
      for (int k = 0; k < cdim[2]; ++k) {
        const struct grav_tensor *f =
            &space.multipoles_top[row_major_id(i, j, k, cdim[0])].pot;
        const double val = j / ((double)cdim[0]);
        const double val2 = val * val;

        if (!is_close(f->F_000, -val2, 1e-10))
          error("Invalid value for (%d %d %d) F_000 (%e)", i, j, k, f->F_000);
        if (!is_close(f->F_100, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_100 (%e)", i, j, k, f->F_100);
        if (!is_close(f->F_010, -2 * val, 1e-10))
          error("Invalid value for (%d %d %d) F_010 (%e)", i, j, k, f->F_010);
        if (!is_close(f->F_001, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_001 (%e)", i, j, k, f->F_001);
        if (!is_close(f->F_200, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_200 (%e)", i, j, k, f->F_200);
        if (!is_close(f->F_020, 2.f, 1e-10))
          error("Invalid value for (%d %d %d) F_020 (%e)", i, j, k, f->F_020);
        if (!is_close(f->F_002, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_002 (%e)", i, j, k, f->F_002);
        if (!is_close(f->F_011, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_011 (%e)", i, j, k, f->F_011);
        if (!is_close(f->F_101, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_101 (%e)", i, j, k, f->F_101);
        if (!is_close(f->F_110, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_110 (%e)", i, j, k, f->F_110);
      }
    }
  }

  /* Quadratic function in z --> Derivatives must be 2 */
  for (int i = 0; i < cdim[0]; ++i) {
    for (int j = 0; j < cdim[1]; ++j) {
      for (int k = 0; k < cdim[2]; ++k) {
        pot[row_major_id(i, j, k, cdim[0])] =
            k * k / ((double)cdim[0] * cdim[0]);
      }
    }
  }
  for (int i = 0; i < nr_cells; ++i)
    gravity_field_tensors_init(&space.multipoles_top[i].pot, engine.ti_current);
  for (int i = 0; i < nr_cells; ++i)
    mesh_to_multipole_CIC(&space.multipoles_top[i], pot, cdim[0], cdim[0], dim);
  for (int i = 0; i < cdim[0]; ++i) {
    for (int j = 0; j < cdim[1]; ++j) {
      for (int k = 2; k < cdim[2] - 3; ++k) {
        const struct grav_tensor *f =
            &space.multipoles_top[row_major_id(i, j, k, cdim[0])].pot;
        const double val = k / ((double)cdim[0]);
        const double val2 = val * val;

        if (!is_close(f->F_000, -val2, 1e-10))
          error("Invalid value for (%d %d %d) F_000 (%e)", i, j, k, f->F_000);
        if (!is_close(f->F_100, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_100 (%e)", i, j, k, f->F_100);
        if (!is_close(f->F_010, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_010 (%e)", i, j, k, f->F_010);
        if (!is_close(f->F_001, -2 * val, 1e-10))
          error("Invalid value for (%d %d %d) F_001 (%e)", i, j, k, f->F_001);
        if (!is_close(f->F_200, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_200 (%e)", i, j, k, f->F_200);
        if (!is_close(f->F_020, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_020 (%e)", i, j, k, f->F_020);
        if (!is_close(f->F_002, 2.f, 1e-10))
          error("Invalid value for (%d %d %d) F_002 (%e)", i, j, k, f->F_002);
        if (!is_close(f->F_011, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_011 (%e)", i, j, k, f->F_011);
        if (!is_close(f->F_101, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_101 (%e)", i, j, k, f->F_101);
        if (!is_close(f->F_110, 0.f, 1e-10))
          error("Invalid value for (%d %d %d) F_110 (%e)", i, j, k, f->F_110);
      }
    }
Matthieu Schaller's avatar
Matthieu Schaller committed
458
  }
459

460 461
  /* Clean up */
  free(r);
462
  free(m);
463 464 465
  free(pot);
  free(pot_exact);
  free(params);
Matthieu Schaller's avatar
Matthieu Schaller committed
466 467 468
  free(gparts);
  return 0;
}
469 470

#endif