TestHelpers.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
7 
8 #include <cstddef>
9 
10 #include "DataStructures/DataVector.hpp"
15 #include "NumericalAlgorithms/DiscontinuousGalerkin/NumericalFluxes/NumericalFluxHelpers.hpp"
16 #include "NumericalAlgorithms/DiscontinuousGalerkin/SimpleBoundaryData.hpp"
17 #include "Utilities/TMPL.hpp"
18 
19 namespace EllipticNumericalFluxesTestHelpers {
20 
21 /// Test that the flux is single-valued on the interface, i.e. that the elements
22 /// on either side of the interface are working with the same numerical flux
23 /// data
24 template <size_t Dim, typename VariablesTags, typename FluxType>
25 void test_conservation(const FluxType& flux_computer,
26  const DataVector& used_for_size) {
27  MAKE_GENERATOR(gen);
28  std::uniform_real_distribution<> dist(0.0, 1.0);
29  const size_t num_points = used_for_size.size();
30 
31  using PackagedData =
32  dg::SimpleBoundaryData<typename FluxType::package_field_tags,
33  typename FluxType::package_extra_tags>;
34  PackagedData packaged_data_interior{};
35  packaged_data_interior.field_data =
36  make_with_random_values<Variables<typename FluxType::package_field_tags>>(
37  make_not_null(&gen), make_not_null(&dist), used_for_size);
38  PackagedData packaged_data_exterior{};
39  packaged_data_exterior.field_data =
40  make_with_random_values<Variables<typename FluxType::package_field_tags>>(
41  make_not_null(&gen), make_not_null(&dist), used_for_size);
42 
43  Variables<VariablesTags> n_dot_num_flux_interior(
45  dg::NumericalFluxes::normal_dot_numerical_fluxes(
46  make_not_null(&n_dot_num_flux_interior), flux_computer,
47  packaged_data_interior, packaged_data_exterior);
48 
49  Variables<VariablesTags> n_dot_num_flux_exterior(
51  dg::NumericalFluxes::normal_dot_numerical_fluxes(
52  make_not_null(&n_dot_num_flux_exterior), flux_computer,
53  packaged_data_exterior, packaged_data_interior);
54 
55  CHECK_VARIABLES_APPROX(n_dot_num_flux_interior, -n_dot_num_flux_exterior);
56 }
57 
58 } // namespace EllipticNumericalFluxesTestHelpers
dg::SimpleBoundaryData::field_data
Variables< FieldTags > field_data
Data projected to the mortar mesh.
Definition: SimpleBoundaryData.hpp:40
TestingFramework.hpp
MakeWithRandomValues.hpp
std::uniform_real_distribution
TestHelpers.hpp
dg::SimpleBoundaryData
Distinguishes between field data, which can be projected to a mortar, and extra data,...
Definition: SimpleBoundaryData.hpp:35
cstddef
DataVector
Stores a collection of function values.
Definition: DataVector.hpp:42
MAKE_GENERATOR
#define MAKE_GENERATOR(...)
MAKE_GENERATOR(NAME [, SEED]) declares a variable of name NAME containing a generator of type std::mt...
Definition: TestHelpers.hpp:417
Variables.hpp
Tensor.hpp
make_not_null
gsl::not_null< T * > make_not_null(T *ptr) noexcept
Construct a not_null from a pointer. Often this will be done as an implicit conversion,...
Definition: Gsl.hpp:879
std::numeric_limits
TMPL.hpp
CHECK_VARIABLES_APPROX
#define CHECK_VARIABLES_APPROX(a, b)
A wrapper around Catch's CHECK macro that checks approximate equality of each entry in each tag withi...
Definition: TestHelpers.hpp:434