Debian Codegraph @

packages/stk/stk_unit_tests/stk_middle_mesh/test_discretization_1d.cpp

raw
1 #include "stk_middle_mesh/discretization_1d.hpp"
2 #include "gtest/gtest.h"
3
4 namespace stk {
5 namespace middle_mesh {
6 namespace impl {
7
8 TEST(Discretization1D, MeshEntityCounts)
9 {
10 double xmin = 0;
11 double xmax = 4;
12 int numel = 10;
13 disc1d::impl::MeshSpec1D spec{numel, xmin, xmax};
14 int basisDegree = 1, quadDegree = 3;
15
16 auto disc = disc1d::impl::make_disc1_d(spec, basisDegree, quadDegree);
17
18 EXPECT_EQ(count_valid(disc->get_mesh()->get_vertices()), numel + 1);
19 EXPECT_EQ(count_valid(disc->get_mesh()->get_edges()), numel);
20
21 for (auto& edge : disc->get_mesh()->get_edges())
22 EXPECT_EQ(edge->count_down(), 2);
23 }
24
25 TEST(Discretization1D, DofNums)
26 {
27 double xmin = 0;
28 double xmax = 4;
29 int numel = 10;
30 disc1d::impl::MeshSpec1D spec{numel, xmin, xmax};
31 int basisDegree = 1, quadDegree = 3;
32
33 auto disc = disc1d::impl::make_disc1_d(spec, basisDegree, quadDegree);
34
35 EXPECT_EQ(disc->get_num_dofs(), numel + 1);
36 std::vector<int> usedDofs(disc->get_num_dofs(), 0);
37 auto& dofs = *(disc->get_dof_nums());
38 for (auto& vert : disc->get_mesh()->get_vertices())
39 {
40 int dof = dofs(vert, 0, 0);
41 EXPECT_GE(dof, 0);
42 EXPECT_LT(dof, disc->get_num_dofs());
43 usedDofs[dof] += 1;
44 }
45
46 for (auto dofCount : usedDofs)
47 EXPECT_EQ(dofCount, 1);
48 }
49
50 TEST(Discretization1D, IntegrateConstant)
51 {
52 double xmin = 0;
53 double xmax = 4;
54 disc1d::impl::MeshSpec1D spec{10, xmin, xmax};
55
56 for (int basisDegree = 1; basisDegree <= 2; ++basisDegree)
57 {
58 int quadDegree = 3;
59 auto disc = disc1d::impl::make_disc1_d(spec, basisDegree, quadDegree);
60 auto f = [](double /*x*/) { return 1; };
61 auto func = disc1d::impl::make_grid_function(disc, f);
62 auto val = disc1d::impl::integrate_function(disc, func);
63
64 EXPECT_NEAR(val, xmax - xmin, 1e-13);
65 }
66 }
67
68 TEST(Discretization1D, IntegrateLinear)
69 {
70 double xmin = 0;
71 double xmax = 4;
72 disc1d::impl::MeshSpec1D spec{10, xmin, xmax};
73
74 for (int basisDegree = 1; basisDegree <= 2; ++basisDegree)
75 {
76 int quadDegree = 3;
77 auto disc = disc1d::impl::make_disc1_d(spec, basisDegree, quadDegree);
78 auto f = [](double x) { return x; };
79 auto func = disc1d::impl::make_grid_function(disc, f);
80 auto val = disc1d::impl::integrate_function(disc, func);
81
82 EXPECT_NEAR(val, 0.5 * std::pow(xmax, 2) - 0.5 * std::pow(xmin, 2), 1e-13);
83 }
84 }
85
86 TEST(Discretization1D, SummedMassMatrix)
87 {
88 double xmin = 0;
89 double xmax = 4;
90 disc1d::impl::MeshSpec1D spec{10, xmin, xmax};
91
92 for (int basisDegree = 1; basisDegree <= 2; ++basisDegree)
93 {
94 int quadDegree = 3;
95 auto disc = disc1d::impl::make_disc1_d(spec, basisDegree, quadDegree);
96 auto f = [](double x) { return x; };
97 auto func = disc1d::impl::make_grid_function(disc, f);
98
99 auto summedMassMatrix = disc1d::impl::compute_summed_mass_matrix(disc);
100 // EXPECT_EQ(summed_mass_matrix.size(), disc->get_num_dofs());
101 EXPECT_EQ((int)func.size(), disc->get_num_dofs());
102
103 double val = 0.0;
104 for (int i = 0; i < disc->get_num_dofs(); ++i)
105 val += summedMassMatrix[i] * func[i];
106
107 EXPECT_NEAR(val, 0.5 * std::pow(xmax, 2) - 0.5 * std::pow(xmin, 2), 1e-13);
108 }
109 }
110
111 } // namespace impl
112 } // namespace middle_mesh
113 } // namespace stk