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/Variables.hpp" 11 : #include "Domain/Structure/Direction.hpp" 12 : #include "Domain/Structure/DirectionalId.hpp" 13 : #include "Domain/Structure/DirectionalIdMap.hpp" 14 : #include "Domain/Structure/ElementId.hpp" 15 : #include "Evolution/DgSubcell/GhostData.hpp" 16 : #include "NumericalAlgorithms/Spectral/Mesh.hpp" 17 : #include "Utilities/ErrorHandling/Assert.hpp" 18 : #include "Utilities/Gsl.hpp" 19 : 20 : namespace fd { 21 : /*! 22 : * \brief Given the type-erased neighbor data for reconstruction stored in a 23 : * `DataVector`, have `Variables` point into them. 24 : * 25 : * This function is helpful for reconstruction, especially when wanting to apply 26 : * different reconstruction methods to different tags. This can happen, for 27 : * example, when doing positivity-preserving reconstruction. The density should 28 : * remain positive, but negative velocities are fine. 29 : */ 30 : template <size_t Dim, typename ReconstructionTags> 31 1 : void neighbor_data_as_variables( 32 : const gsl::not_null<DirectionalIdMap<Dim, Variables<ReconstructionTags>>*> 33 : vars_neighbor_data, 34 : const DirectionalIdMap<Dim, evolution::dg::subcell::GhostData>& 35 : all_ghost_data, 36 : const size_t ghost_zone_size, const Mesh<Dim>& subcell_mesh) { 37 : const size_t neighbor_num_pts = 38 : ghost_zone_size * subcell_mesh.extents().slice_away(0).product(); 39 : ASSERT( 40 : subcell_mesh == Mesh<Dim>(subcell_mesh.extents(0), subcell_mesh.basis(0), 41 : subcell_mesh.quadrature(0)), 42 : "subcell_mesh must be isotropic but got " << subcell_mesh); 43 : vars_neighbor_data->clear(); 44 : for (const auto& [neighbor_id, ghost_data] : all_ghost_data) { 45 : const DataVector& data = 46 : ghost_data.neighbor_ghost_data_for_reconstruction(); 47 : (*vars_neighbor_data)[neighbor_id] = {}; 48 : (*vars_neighbor_data)[neighbor_id].set_data_ref( 49 : const_cast<double*>(data.data()), 50 : Variables<ReconstructionTags>::number_of_independent_components * 51 : neighbor_num_pts); 52 : } 53 : } 54 : } // namespace fd