Line data Source code
1 0 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : #pragma once
5 :
6 : #include <type_traits>
7 :
8 : #include "DataStructures/DataBox/DataBox.hpp"
9 : #include "DataStructures/DataBox/MetavariablesTag.hpp"
10 : #include "DataStructures/Variables.hpp"
11 : #include "Utilities/CallWithDynamicType.hpp"
12 : #include "Utilities/TMPL.hpp"
13 :
14 : namespace elliptic::util {
15 : /// Get data for the tensors in `TagsList` from the `analytic_data`. The
16 : /// `analytic_data` can be any subclass of `Base` that is listed in
17 : /// `Metavariables::factory_creation`.
18 : template <typename TagsList, typename Base, typename DbTagsList,
19 : typename... Args>
20 1 : Variables<TagsList> get_analytic_data(const Base& analytic_data,
21 : const db::DataBox<DbTagsList>& box,
22 : const Args&... args) {
23 : using factory_classes =
24 : typename std::decay_t<decltype(db::get<Parallel::Tags::Metavariables>(
25 : box))>::factory_creation::factory_classes;
26 : return call_with_dynamic_type<Variables<TagsList>,
27 : tmpl::at<factory_classes, Base>>(
28 : &analytic_data, [&args...](const auto* const derived) {
29 : return variables_from_tagged_tuple(
30 : derived->variables(args..., TagsList{}));
31 : });
32 : }
33 : } // namespace elliptic::util
|