https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MeshTests.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#include "TriSubChannelMesh.h"
11
12#include "gtest/gtest.h"
13#include <algorithm>
14#include <sstream>
15
16const double tol = 1e-8;
17const double eps = 1e-9;
18
19void
20triRodPositionsRef(std::vector<Point> & positions, Real nrings, Real pitch, Point center)
21{
22 positions.clear();
23
24 const Real start_r = (nrings - 1) * pitch;
25 const Real theta0 = 2 * libMesh::pi / 3;
26 const Real startx = start_r * std::cos(theta0);
27 const Real starty = start_r * std::sin(theta0);
28 for (int i = 0; i < nrings; i++)
29 {
30 int n_rods_in_row = nrings + i;
31 const Real y = starty - i * pitch * std::sin(theta0);
32 const Real x_row = startx + i * pitch * std::cos(theta0);
33 for (int j = 0; j < n_rods_in_row; j++)
34 {
35 const Real x = x_row + j * pitch;
36 positions.emplace_back(center(0) + x, center(1) + y);
37 if (i < nrings - 1)
38 positions.emplace_back(center(0) + x, center(1) - y);
39 }
40 }
41}
42
43bool
44relativeEq(double x, double y)
45{
46 if (std::abs(x) < eps && std::abs(y) < eps)
47 return true;
48
49 double diff = std::abs(x - y);
50 x = std::abs(x);
51 y = std::abs(y);
52 double largest = (y > x) ? y : x;
53 return diff <= largest * tol;
54}
55
56bool
57pointLess(const Point & a, const Point & b)
58{
59 for (int i = 0; i < LIBMESH_DIM; i++)
60 {
61 if (relativeEq(a(i), b(i)))
62 continue;
63 return a(i) < b(i);
64 }
65 return false;
66}
67
68TEST(MeshTests, triRodCoordinates)
69{
70
71 int nrings = 4;
72 Real pitch = 1;
73 Point center(0, 0, 0);
74
75 std::vector<Point> positions;
76 triRodPositionsRef(positions, nrings, pitch, center);
77 std::sort(positions.begin(), positions.end(), pointLess);
78
79 std::vector<Point> positions2;
80 TriSubChannelMesh::pinPositions(positions2, nrings, pitch, center);
81 std::sort(positions2.begin(), positions2.end(), pointLess);
82
83 ASSERT_EQ(positions.size(), positions2.size());
84
85 std::stringstream msg;
86 for (size_t i = 0; i < positions.size(); i++)
87 if (!positions[i].absolute_fuzzy_equals(positions2[i]))
88 msg << "point " << i + 1 << " differs: " << positions[i] << " != " << positions2[i] << "\n";
89
90 if (msg.str().size() > 0)
91 FAIL() << msg.str();
92}
const std::vector< double > y
const std::vector< double > x
bool pointLess(const Point &a, const Point &b)
Definition MeshTests.C:57
const double eps
Definition MeshTests.C:17
const double tol
Definition MeshTests.C:16
bool relativeEq(double x, double y)
Definition MeshTests.C:44
void triRodPositionsRef(std::vector< Point > &positions, Real nrings, Real pitch, Point center)
Definition MeshTests.C:20
TEST(MeshTests, triRodCoordinates)
Definition MeshTests.C:68
Point center
static void pinPositions(std::vector< Point > &positions, unsigned int nrings, Real pitch, Point center)
Calculates and stores the pin positions/centers for a hexagonal assembly containing the given number ...
const Real pi