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 "Utilities/TMPL.hpp"
16 
18 
19 template <class... PackageDataTags, class FluxType,
20  class... NormalDotNumericalFluxTypes>
21 void apply_numerical_flux(
22  const FluxType& flux,
23  const Variables<tmpl::list<PackageDataTags...>>& packaged_data_int,
24  const Variables<tmpl::list<PackageDataTags...>>& packaged_data_ext,
25  NormalDotNumericalFluxTypes&&... normal_dot_numerical_flux) noexcept {
26  flux(std::forward<NormalDotNumericalFluxTypes>(normal_dot_numerical_flux)...,
27  get<PackageDataTags>(packaged_data_int)...,
28  get<PackageDataTags>(packaged_data_ext)...);
29 }
30 
31 namespace detail {
32 
33 /// Test that the flux is single-valued on the interface, i.e. that the elements
34 /// on either side of the interface are working with the same numerical flux
35 /// data
36 template <size_t Dim, typename FluxType, typename... VariablesTags>
37 void test_conservation_impl(const FluxType& flux_computer,
38  const DataVector& used_for_size,
39  const tmpl::list<VariablesTags...> /*meta*/) {
40  MAKE_GENERATOR(gen);
41  std::uniform_real_distribution<> dist(0.0, 1.0);
42 
43  using PackagedData = Variables<typename FluxType::package_tags>;
44  const auto packaged_data_interior = make_with_random_values<PackagedData>(
45  make_not_null(&gen), make_not_null(&dist), used_for_size);
46  const auto packaged_data_exterior = make_with_random_values<PackagedData>(
47  make_not_null(&gen), make_not_null(&dist), used_for_size);
48 
49  Variables<tmpl::list<VariablesTags...>> n_dot_num_flux_interior(
50  used_for_size.size(), std::numeric_limits<double>::signaling_NaN());
51  apply_numerical_flux(flux_computer, packaged_data_interior,
52  packaged_data_exterior,
53  &get<VariablesTags>(n_dot_num_flux_interior)...);
54 
55  Variables<tmpl::list<VariablesTags...>> n_dot_num_flux_exterior(
56  used_for_size.size(), std::numeric_limits<double>::signaling_NaN());
57  apply_numerical_flux(flux_computer, packaged_data_exterior,
58  packaged_data_interior,
59  &get<VariablesTags>(n_dot_num_flux_exterior)...);
60 
61  const auto check = [](const auto& int_flux, const auto& ext_flux) noexcept {
62  for (size_t i = 0; i < int_flux.size(); ++i) {
63  CHECK_ITERABLE_APPROX(int_flux[i], -ext_flux[i]);
64  }
65  return nullptr;
66  };
67 
68  EXPAND_PACK_LEFT_TO_RIGHT(check(get<VariablesTags>(n_dot_num_flux_interior),
69  get<VariablesTags>(n_dot_num_flux_exterior)));
70 }
71 
72 } // namespace detail
73 
74 template <size_t Dim, typename VariablesTags, typename FluxType>
75 void test_conservation(const FluxType& flux_computer,
76  const DataVector& used_for_size) {
77  detail::test_conservation_impl<Dim>(flux_computer, used_for_size,
78  VariablesTags{});
79 }
80 
81 } // namespace EllipticNumericalFluxesTestHelpers
#define EXPAND_PACK_LEFT_TO_RIGHT(...)
Expand a parameter pack evaluating the terms from left to right.
Definition: TMPL.hpp:562
T signaling_NaN(T... args)
Commonly used routines, functions and definitions shared amongst unit tests.
Helper functions for data structures used in unit tests.
#define MAKE_GENERATOR(...)
MAKE_GENERATOR(NAME [, SEED]) declares a variable of name NAME containing a generator of type std::mt...
Definition: TestHelpers.hpp:417
Definition: Determinant.hpp:11
Defines class Variables.
void check(EosType in_eos, const std::string &python_function_prefix, const T &used_for_size, const MemberArgs &... member_args) noexcept
Test an equation of state by comparing to python functions.
Definition: TestHelpers.hpp:210
Defines classes for Tensor.
#define CHECK_ITERABLE_APPROX(a, b)
A wrapper around Catch&#39;s CHECK macro that checks approximate equality of entries in iterable containe...
Definition: TestingFramework.hpp:139
Stores a collection of function values.
Definition: DataVector.hpp:42
Wraps the template metaprogramming library used (brigand)
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, but it may be necessary to perform the conversion explicitly when type deduction is desired.
Definition: Gsl.hpp:879
Code to wrap or improve the Catch testing framework used for unit tests.
Definition: TestHelpers.hpp:17