Protocols.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
7 #include "Utilities/Gsl.hpp"
8 #include "Utilities/TMPL.hpp"
9 #include "Utilities/TypeTraits.hpp"
10 #include "Utilities/TypeTraits/CreateHasTypeAlias.hpp"
11 #include "Utilities/TypeTraits/CreateIsCallable.hpp"
12 #include "Utilities/TypeTraits/IsCallable.hpp"
13 
14 namespace dg {
15 /// \ref protocols related to Discontinuous Galerkin functionality
16 namespace protocols {
17 
18 namespace detail {
19 CREATE_HAS_TYPE_ALIAS(variables_tags)
20 CREATE_HAS_TYPE_ALIAS_V(variables_tags)
21 CREATE_HAS_TYPE_ALIAS(argument_tags)
22 CREATE_HAS_TYPE_ALIAS_V(argument_tags)
23 CREATE_HAS_TYPE_ALIAS(package_field_tags)
24 CREATE_HAS_TYPE_ALIAS_V(package_field_tags)
25 CREATE_HAS_TYPE_ALIAS(package_extra_tags)
26 CREATE_HAS_TYPE_ALIAS_V(package_extra_tags)
27 
28 template <typename NumericalFluxType, typename VariablesTags,
29  typename PackageFieldTags, typename PackageExtraTags>
30 struct IsNumericalFluxCallableImpl;
31 
32 template <typename NumericalFluxType, typename... VariablesTags,
33  typename... PackageFieldTags, typename... PackageExtraTags>
34 struct IsNumericalFluxCallableImpl<
35  NumericalFluxType, tmpl::list<VariablesTags...>,
36  tmpl::list<PackageFieldTags...>, tmpl::list<PackageExtraTags...>>
37  : tt::is_callable_t<NumericalFluxType,
38  gsl::not_null<db::item_type<VariablesTags>*>...,
39  db::const_item_type<PackageFieldTags>...,
40  db::const_item_type<PackageExtraTags>...,
41  db::const_item_type<PackageFieldTags>...,
42  db::const_item_type<PackageExtraTags>...> {};
43 
44 template <typename NumericalFluxType>
45 struct IsNumericalFluxCallable
46  : IsNumericalFluxCallableImpl<
47  NumericalFluxType, typename NumericalFluxType::variables_tags,
48  typename NumericalFluxType::package_field_tags,
49  typename NumericalFluxType::package_extra_tags> {};
50 } // namespace detail
51 
52 /*!
53  * \ingroup ProtocolsGroup
54  * \brief Defines the interface for DG numerical fluxes
55  *
56  * This protocol defines the interface that a class must conform to so that it
57  * can be used as a numerical flux in DG boundary schemes. Essentially, the
58  * class must be able to compute the quantity \f$G\f$ that appears, for example,
59  * in the strong first-order DG boundary scheme
60  * \f$G_\alpha(n_i^\mathrm{int}, u_\alpha^\mathrm{int}, n_i^\mathrm{ext},
61  * u_\alpha^\mathrm{ext}) - n_i^\mathrm{int} F^{i,\mathrm{int}}_\alpha\f$
62  * where \f$u_\alpha\f$ are the system variables and \f$F^i_\alpha\f$ their
63  * corresponding fluxes. See also Eq. (2.20) in \cite Teukolsky2015ega where the
64  * quantity \f$G\f$ is denoted \f$n_i F^{i*}\f$, which is why we occasionally
65  * refer to it as the "normal-dot-numerical-fluxes".
66  *
67  * Requires the `ConformingType` has these type aliases:
68  * - `variables_tags`: A typelist of DataBox tags that the class computes
69  * numerical fluxes for.
70  * - `argument_tags`: A typelist of DataBox tags that will be retrieved on
71  * interfaces and passed to the `package_data` function (see below). The
72  * `ConformingType` may also have a `volume_tags` typelist that specifies the
73  * subset of `argument_tags` that should be retrieved from the volume instead
74  * of the interface.
75  * - `package_field_tags`: A typelist of DataBox tags with `Tensor` types that
76  * the `package_data` function will compute from the `argument_tags`. These
77  * quantities will be made available on both sides of a mortar and passed to
78  * the call operator to compute the numerical flux.
79  * - `package_extra_tags`: Additional non-tensor tags that will be made
80  * available on both sides of a mortar, e.g. geometric quantities.
81  *
82  * Requires the `ConformingType` has these member functions:
83  * - `package_data`: Takes the types of the `package_field_tags` and the
84  * `package_extra_tags` by `gsl::not_null` pointer, followed by the types of the
85  * `argument_tags`.
86  * - `operator()`: Takes the types of the `variables_tags` by `gsl::not_null`
87  * pointer, followed by the types of the `package_field_tags` and the
88  * `package_extra_tags` from the interior side of the mortar and from the
89  * exterior side. Note that the data from the exterior side was computed
90  * entirely with data from the neighboring element, including its interface
91  * normal which is (at least when it's independent of the system variables)
92  * opposite to the interior element's interface normal. Therefore, make sure to
93  * take into account the sign flip for quantities that include the interface
94  * normal.
95  *
96  * Here's an example for a simple "central" numerical flux
97  * \f$G_\alpha(n_i^\mathrm{int}, u_\alpha^\mathrm{int}, n_i^\mathrm{ext},
98  * u_\alpha^\mathrm{ext}) = \frac{1}{2}\left(n_i^\mathrm{int}
99  * F^{i,\mathrm{int}}_\alpha - n_i^\mathrm{ext} F^{i,\mathrm{ext}}_\alpha
100  * \right)\f$:
101  *
102  * \snippet DiscontinuousGalerkin/Test_Protocols.cpp numerical_flux_example
103  *
104  * Note that this numerical flux reduces to the interface average
105  * \f$G_\alpha=\frac{n^\mathrm{int}_i}{2}\left(F^{i,\mathrm{int}}_\alpha +
106  * F^{i,\mathrm{ext}}_\alpha\right)\f$ for the case where the interface normal
107  * is independent of the system variables and therefore \f$n_i^\mathrm{ext} =
108  * -n_i^\mathrm{int}\f$.
109  */
110 template <typename ConformingType>
112  tmpl2::flat_all_v<detail::has_variables_tags_v<ConformingType>,
113  detail::has_argument_tags_v<ConformingType>,
114  detail::has_package_field_tags_v<ConformingType>,
115  detail::has_package_extra_tags_v<ConformingType>>,
116  // We can't currently check that the package_data function is callable
117  // because the `argument_tags` may contain base tags and we can't resolve
118  // their types.
119  detail::IsNumericalFluxCallable<ConformingType>, std::false_type>;
120 
121 } // namespace protocols
122 } // namespace dg
tt::is_callable_t
typename is_callable< T, Args... >::type is_callable_t
Definition: IsCallable.hpp:71
std::false_type
DataBoxTag.hpp
dg
Functionality related to discontinuous Galerkin schemes.
Definition: ComputeNonconservativeBoundaryFluxes.hpp:23
CREATE_HAS_TYPE_ALIAS
#define CREATE_HAS_TYPE_ALIAS(ALIAS_NAME)
Generate a type trait to check if a class has a type alias with a particular name,...
Definition: CreateHasTypeAlias.hpp:27
Gsl.hpp
std::conditional_t
TMPL.hpp