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"
14 #include "NumericalAlgorithms/DiscontinuousGalerkin/NumericalFluxes/NumericalFluxHelpers.hpp"
15 #include "NumericalAlgorithms/DiscontinuousGalerkin/SimpleBoundaryData.hpp"
16 #include "Utilities/TMPL.hpp"
17 
18 namespace EllipticNumericalFluxesTestHelpers {
19 
20 /// Test that the flux is single-valued on the interface, i.e. that the elements
21 /// on either side of the interface are working with the same numerical flux
22 /// data
23 template <size_t Dim, typename NumericalFluxComputer, typename MakeRandomArgs>
24 void test_conservation(const NumericalFluxComputer& numerical_flux_computer,
25  MakeRandomArgs&& make_random_args,
26  const DataVector& used_for_size) {
27  const size_t num_points = used_for_size.size();
28  using PackagedData = dg::SimpleBoundaryData<
29  typename NumericalFluxComputer::package_field_tags,
30  typename NumericalFluxComputer::package_extra_tags>;
31  const auto make_random_packaged_data = [&numerical_flux_computer,
32  &make_random_args, &num_points]() {
33  return std::apply(
34  [&numerical_flux_computer, &num_points](const auto... args) noexcept {
35  PackagedData packaged_data{num_points};
36  dg::NumericalFluxes::package_data(make_not_null(&packaged_data),
37  numerical_flux_computer, args...);
38  return packaged_data;
39  },
40  make_random_args());
41  };
42  const auto packaged_data_interior = make_random_packaged_data();
43  const auto packaged_data_exterior = make_random_packaged_data();
44 
45  using Vars = Variables<typename NumericalFluxComputer::variables_tags>;
46  Vars n_dot_num_flux_interior(num_points,
48  dg::NumericalFluxes::normal_dot_numerical_fluxes(
49  make_not_null(&n_dot_num_flux_interior), numerical_flux_computer,
50  packaged_data_interior, packaged_data_exterior);
51  Vars n_dot_num_flux_exterior(num_points,
53  dg::NumericalFluxes::normal_dot_numerical_fluxes(
54  make_not_null(&n_dot_num_flux_exterior), numerical_flux_computer,
55  packaged_data_exterior, packaged_data_interior);
56 
57  CHECK_VARIABLES_APPROX(n_dot_num_flux_interior, -n_dot_num_flux_exterior);
58 }
59 
60 } // namespace EllipticNumericalFluxesTestHelpers
TestingFramework.hpp
TestHelpers.hpp
db::apply
constexpr auto apply(F &&f, const DataBox< BoxTags > &box, Args &&... args) noexcept
Apply the invokable f with argument Tags TagsList from DataBox box
Definition: DataBox.hpp:1443
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
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:880
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