Debian Codegraph @

packages/stk/stk_unit_tests/stk_middle_mesh/test_search_1d.cpp

raw
1 #include "stk_middle_mesh/search_1d.hpp"
2 #include "gtest/gtest.h"
3
4 namespace stk {
5 namespace middle_mesh {
6 namespace impl {
7
8 namespace {
9
10 struct TestData
11 {
12 double xCoord;
13 int elnum;
14 };
15 } // namespace
16
17 TEST(Search1D, Element)
18 {
19 double xmin = 0;
20 double xmax = 6;
21 int numel = 3;
22 disc1d::impl::MeshSpec1D spec{numel, xmin, xmax};
23 int basisDegree = 1, quadDegree = 3;
24
25 auto disc = disc1d::impl::make_disc1_d(spec, basisDegree, quadDegree);
26
27 disc1d::impl::Search1D search(disc);
28
29 std::vector<TestData> testData = {{xmin, 0}, {1, 0}, {1.5, 0}, {2.4, 1}, {3.6, 1},
30 {4.4, 2}, {5.6, 2}, {7.0, 2}, {-1, 0}};
31
32 for (auto& data : testData)
33 {
34 std::cout << "\ntesting x coordinate " << data.xCoord << ", which should be in element " << data.elnum << std::endl;
35 auto el = search.find_containing_element(data.xCoord);
36 EXPECT_EQ(get_type_dimension(el->get_type()), 1);
37 EXPECT_EQ(el->get_id(), data.elnum);
38
39 double xiCoord = search.get_xi_coordinate(el, data.xCoord);
40
41 double xiCoordZeroToOne = (xiCoord + 1) / 2;
42 double xL = el->get_down(0)->get_point_orig(0).get_x();
43 double xR = el->get_down(1)->get_point_orig(0).get_x();
44 double xFromXi = xL + (xR - xL) * xiCoordZeroToOne;
45 EXPECT_NEAR(data.xCoord, xFromXi, 1e-13);
46 }
47 }
48 } // namespace impl
49 } // namespace middle_mesh
50 } // namespace stk