The finite element method using deal.II - 2021/2022
poisson_tester.cc File Reference
#include "poisson_tester.h"
#include <gtest/gtest.h>
#include <fstream>
#include <sstream>
Include dependency graph for poisson_tester.cc:

Go to the source code of this file.

Typedefs

using PoissonTestTypes = ::testing::Types< std::integral_constant< int, 1 >, std::integral_constant< int, 2 >, std::integral_constant< int, 3 > >
 
using Poisson2DTester = PoissonTester< std::integral_constant< int, 2 > >
 

Functions

 TYPED_TEST_CASE (PoissonTester, PoissonTestTypes)
 
 TYPED_TEST (PoissonTester, MakeGrid)
 
 TEST_F (Poisson2DTester, TestLinear)
 
 TEST_F (Poisson2DTester, TestQuadratic)
 
 TEST_F (Poisson2DTester, TestMixedBC1)
 
 TEST_F (Poisson2DTester, TestLinearWithHangingNodes)
 

Typedef Documentation

◆ PoissonTestTypes

using PoissonTestTypes = ::testing::Types<std::integral_constant<int, 1>, std::integral_constant<int, 2>, std::integral_constant<int, 3> >

Definition at line 12 of file poisson_tester.cc.

◆ Poisson2DTester

using Poisson2DTester = PoissonTester<std::integral_constant<int, 2> >

Definition at line 15 of file poisson_tester.cc.

Function Documentation

◆ TYPED_TEST_CASE()

TYPED_TEST_CASE ( PoissonTester  ,
PoissonTestTypes   
)

◆ TYPED_TEST()

TYPED_TEST ( PoissonTester  ,
MakeGrid   
)

Definition at line 19 of file poisson_tester.cc.

20 {
21  // Output dimension
22  std::cout << "Working on dim " << TypeParam::value << std::endl;
23  this->make_grid();
24 }

◆ TEST_F() [1/4]

TEST_F ( Poisson2DTester  ,
TestLinear   
)

Definition at line 29 of file poisson_tester.cc.

30 {
31  std::stringstream str;
32 
33  str << "subsection Poisson<2>" << std::endl
34  << " set Dirichlet boundary condition expression = x" << std::endl
35  << " set Dirichlet boundary ids = 0" << std::endl
36  << " set Finite element degree = 1" << std::endl
37  << " set Forcing term expression = 0" << std::endl
38  << " set Grid generator arguments = 0: 1: false"
39  << std::endl
40  << " set Grid generator function = hyper_cube"
41  << std::endl
42  << " set Neumann boundary condition expression = 0" << std::endl
43  << " set Neumann boundary ids = " << std::endl
44  << " set Number of global refinements = 4" << std::endl
45  << " set Number of refinement cycles = 1" << std::endl
46  << " set Output filename = poisson" << std::endl
47  << " set Problem constants = pi:3.14" << std::endl
48  << "end" << std::endl;
49 
50  parse_string(str.str());
51  make_grid();
52  setup_system();
53  assemble_system();
54  solve();
55 
56  auto tmp = solution;
57  VectorTools::interpolate(dof_handler, dirichlet_boundary_condition, tmp);
58 
59  tmp -= solution;
60 
61  ASSERT_NEAR(tmp.l2_norm(), 0, 1e-10);
62 }

◆ TEST_F() [2/4]

TEST_F ( Poisson2DTester  ,
TestQuadratic   
)

Definition at line 65 of file poisson_tester.cc.

66 {
67  std::stringstream str;
68 
69  str << "subsection Poisson<2>" << std::endl
70  << " set Dirichlet boundary condition expression = x^2" << std::endl
71  << " set Dirichlet boundary ids = 0" << std::endl
72  << " set Finite element degree = 2" << std::endl
73  << " set Forcing term expression = -2" << std::endl
74  << " set Grid generator arguments = 0: 1: false"
75  << std::endl
76  << " set Grid generator function = hyper_cube"
77  << std::endl
78  << " set Neumann boundary condition expression = 0" << std::endl
79  << " set Neumann boundary ids = " << std::endl
80  << " set Number of global refinements = 4" << std::endl
81  << " set Number of refinement cycles = 1" << std::endl
82  << " set Output filename = quadratic"
83  << std::endl
84  << " set Problem constants = pi:3.14" << std::endl
85  << "end" << std::endl;
86 
87  parse_string(str.str());
88  make_grid();
89  setup_system();
90  assemble_system();
91  solve();
92 
93  auto tmp = solution;
94  VectorTools::interpolate(dof_handler, dirichlet_boundary_condition, tmp);
95 
96  tmp -= solution;
97 
98  ASSERT_NEAR(tmp.l2_norm(), 0, 1e-10);
99 }

◆ TEST_F() [3/4]

TEST_F ( Poisson2DTester  ,
TestMixedBC1   
)

Definition at line 103 of file poisson_tester.cc.

104 {
105  std::stringstream str;
106 
107  str << "subsection Poisson<2>" << std::endl
108  << " set Dirichlet boundary condition expression = x^2" << std::endl
109  << " set Dirichlet boundary ids = 1,2,3" << std::endl
110  << " set Finite element degree = 2" << std::endl
111  << " set Forcing term expression = -2" << std::endl
112  << " set Grid generator arguments = 0: 1: true"
113  << std::endl
114  << " set Grid generator function = hyper_cube"
115  << std::endl
116  << " set Neumann boundary condition expression = 0" << std::endl
117  << " set Neumann boundary ids = 0" << std::endl
118  << " set Number of global refinements = 4" << std::endl
119  << " set Number of refinement cycles = 1" << std::endl
120  << " set Output filename = quadratic"
121  << std::endl
122  << " set Problem constants = pi:3.14" << std::endl
123  << "end" << std::endl;
124 
125  parse_string(str.str());
126  make_grid();
127  setup_system();
128  assemble_system();
129  solve();
130 
131  auto tmp = solution;
132  VectorTools::interpolate(dof_handler, dirichlet_boundary_condition, tmp);
133 
134  tmp -= solution;
135 
136  ASSERT_NEAR(tmp.l2_norm(), 0, 1e-10);
137 }

◆ TEST_F() [4/4]

TEST_F ( Poisson2DTester  ,
TestLinearWithHangingNodes   
)

Definition at line 142 of file poisson_tester.cc.

143 {
144  std::stringstream str;
145 
146  str << "subsection Poisson<2>" << std::endl
147  << " set Dirichlet boundary condition expression = x" << std::endl
148  << " set Dirichlet boundary ids = 0" << std::endl
149  << " set Finite element degree = 1" << std::endl
150  << " set Forcing term expression = 0" << std::endl
151  << " set Grid generator arguments = 0: 1: false"
152  << std::endl
153  << " set Grid generator function = hyper_cube"
154  << std::endl
155  << " set Neumann boundary condition expression = 0" << std::endl
156  << " set Neumann boundary ids = " << std::endl
157  << " set Number of global refinements = 4" << std::endl
158  << " set Number of refinement cycles = 1" << std::endl
159  << " set Output filename = lin_with_handing"
160  << std::endl
161  << " set Problem constants = pi:3.14" << std::endl
162  << "end" << std::endl;
163 
164  parse_string(str.str());
165  make_grid();
166 
167  for (unsigned int i = 0; i < 2; ++i)
168  {
169  for (const auto &cell : triangulation.active_cell_iterators())
170  if (cell->center().square() <= .25)
171  cell->set_refine_flag();
172  triangulation.execute_coarsening_and_refinement();
173  }
174 
175 
176  setup_system();
177  assemble_system();
178  solve();
179  output_results(0);
180 
181  auto tmp = solution;
182  VectorTools::interpolate(dof_handler, dirichlet_boundary_condition, tmp);
183 
184  tmp -= solution;
185 
186  ASSERT_NEAR(tmp.l2_norm(), 0, 1e-10);
187 }
VectorTools::interpolate
void interpolate(const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &dof, const Function< spacedim, typename VectorType::value_type > &function, VectorType &vec, const ComponentMask &component_mask=ComponentMask())
triangulation
const ::parallel::distributed::Triangulation< dim, spacedim > * triangulation
value
static constexpr bool const value
make_grid
void make_grid(Triangulation< 2 > &triangulation)
Definition: step-2.cc:41