Line data Source code
1 0 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : #pragma once
5 :
6 : #include <cstddef>
7 : #include <utility>
8 :
9 : #include "DataStructures/DataVector.hpp"
10 : #include "DataStructures/Tensor/TypeAliases.hpp"
11 : #include "DataStructures/Variables.hpp"
12 : #include "Domain/Structure/DirectionMap.hpp"
13 : #include "Domain/Structure/DirectionalIdMap.hpp"
14 : #include "Evolution/DgSubcell/GhostData.hpp"
15 : #include "NumericalAlgorithms/FiniteDifference/PartialDerivatives.hpp"
16 : #include "Utilities/ErrorHandling/Assert.hpp"
17 : #include "Utilities/Gsl.hpp"
18 :
19 : namespace grmhd::GhValenciaDivClean::fd {
20 : /*!
21 : * \brief Helper function that takes spacetime variable data from a
22 : * `DirectionalIdMap` containing all neighbor data and copies them to
23 : * `ghost_cell_spacetime_vars`, a separate `DirectionMap`.
24 : *
25 : * \tparam NeighborVariables a `Variables` type containing all tags stored in
26 : * the neighbor data
27 : * \tparam FirstGhTag the first spacetime variables tag in
28 : * `NeighborVariables`. Note: it is assumed that the spacetime variables are
29 : * consecutively stored in the `Variables`
30 : * \param ghost_cell_spacetime_vars a `DirectionMap` to be filled with spans
31 : * storing the spacetime data
32 : * \param all_ghost_data a `DirectionalIdMap` containing all neighbor data
33 : * \param number_of_gh_components the number of independent components for all
34 : * spacetime variables in `NeighborVariables`
35 : */
36 : template <typename NeighborVariables, typename FirstGhTag>
37 1 : void fill_neighbor_spacetime_variables(
38 : const gsl::not_null<DirectionMap<3, gsl::span<const double>>*>
39 : ghost_cell_spacetime_vars,
40 : const DirectionalIdMap<3, evolution::dg::subcell::GhostData>&
41 : all_ghost_data,
42 : const size_t number_of_gh_components) {
43 : for (const auto& [directional_element_id, ghost_data] : all_ghost_data) {
44 : const DataVector& neighbor_data =
45 : ghost_data.neighbor_ghost_data_for_reconstruction();
46 : const size_t neighbor_number_of_points =
47 : neighbor_data.size() /
48 : NeighborVariables::number_of_independent_components;
49 : ASSERT(
50 : neighbor_data.size() %
51 : NeighborVariables::number_of_independent_components ==
52 : 0,
53 : "Amount of reconstruction data sent ("
54 : << neighbor_data.size() << ") from " << directional_element_id
55 : << " is not a multiple of the number of reconstruction variables "
56 : << NeighborVariables::number_of_independent_components);
57 : // Use a Variables view to get offset into spacetime variables
58 : // without having to do pointer math.
59 : const NeighborVariables
60 : // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
61 : view{const_cast<double*>(neighbor_data.data()),
62 : neighbor_number_of_points *
63 : NeighborVariables::number_of_independent_components};
64 : // Note: assumes that the spacetime tags are consecutive in
65 : // `NeighborVariables`
66 : ghost_cell_spacetime_vars->insert(std::pair{
67 : directional_element_id.direction(),
68 : gsl::make_span(get<FirstGhTag>(view)[0].data(),
69 : number_of_gh_components * neighbor_number_of_points)});
70 : }
71 : }
72 :
73 : } // namespace grmhd::GhValenciaDivClean::fd
|