testVoronoi1D.c 2.46 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*******************************************************************************
 * This file is part of SWIFT.
 * Copyright (C) 2016 Bert Vandenbroucke (bert.vandenbroucke@gmail.com).
 *
 * 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/>.
 *
 ******************************************************************************/
#include "hydro/Shadowswift/voronoi1d_algorithm.h"

21
int main(int argc, char *argv[]) {
22

23 24 25
  double box_anchor[1] = {-0.5};
  double box_side[1] = {2.};

26 27 28
  /* Create a Voronoi cell */
  double x[1] = {0.5f};
  struct voronoi_cell cell;
29
  voronoi_cell_init(&cell, x, box_anchor, box_side);
30 31

  /* Interact with a left and right neighbour */
32 33
  float xL[1] = {0.5f};
  float xR[1] = {-0.5f};
34 35 36
  voronoi_cell_interact(&cell, xL, 1);
  voronoi_cell_interact(&cell, xR, 2);

37 38 39 40 41 42
  /* Interact with some more neighbours to check if they are properly ignored */
  float x0[1] = {0.6f};
  float x1[1] = {-0.7f};
  voronoi_cell_interact(&cell, x0, 3);
  voronoi_cell_interact(&cell, x1, 4);

43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
  /* Finalize cell and check results */
  voronoi_cell_finalize(&cell);

  if (cell.volume != 0.5f) {
    error("Wrong volume: %g!", cell.volume);
  }
  if (cell.centroid != 0.5f) {
    error("Wrong centroid: %g!", cell.centroid);
  }
  if (cell.idL != 1) {
    error("Wrong left neighbour: %llu!", cell.idL);
  }
  if (cell.idR != 2) {
    error("Wrong right neighbour: %llu!", cell.idR);
  }

59
  /* Check face method */
60
  float A;
61
  float midpoint[3];
62 63 64
  A = voronoi_get_face(&cell, 1, midpoint);
  if (A != 1.0f) {
    error("Wrong surface area returned for left neighbour!");
65 66 67 68
  }
  if (midpoint[0] != -0.25f) {
    error("Wrong midpoint returned for left neighbour!");
  }
69 70 71
  A = voronoi_get_face(&cell, 2, midpoint);
  if (A != 1.0f) {
    error("Wrong surface area returned for right neighbour!");
72 73 74 75 76
  }
  if (midpoint[0] != 0.25f) {
    error("Wrong midpoint returned for right neighbour!");
  }

77 78
  return 0;
}