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 <tuple> 8 : #include <type_traits> 9 : #include <vector> 10 : 11 : #include "DataStructures/Variables.hpp" 12 : #include "NumericalAlgorithms/Spectral/Mesh.hpp" 13 : #include "Parallel/GlobalCache.hpp" 14 : #include "Parallel/Invoke.hpp" 15 : #include "Parallel/Local.hpp" 16 : #include "ParallelAlgorithms/Interpolation/Actions/AddTemporalIdsToInterpolationTarget.hpp" 17 : #include "ParallelAlgorithms/Interpolation/Actions/InterpolatorReceiveVolumeData.hpp" 18 : #include "Utilities/TMPL.hpp" 19 : 20 : /// \cond 21 : template <size_t VolumeDim> 22 : class ElementId; 23 : namespace intrp { 24 : template <typename Metavariables, typename Tag> 25 : struct InterpolationTarget; 26 : template <typename Metavariables> 27 : struct Interpolator; 28 : } // namespace intrp 29 : /// \endcond 30 : 31 : namespace intrp { 32 : template <typename InterpolationTargetTag, size_t VolumeDim, 33 : typename Metavariables, typename... InterpolatorSourceVars> 34 0 : void interpolate( 35 : const typename InterpolationTargetTag::temporal_id::type& temporal_id, 36 : const Mesh<VolumeDim>& mesh, Parallel::GlobalCache<Metavariables>& cache, 37 : const ElementId<VolumeDim>& array_index, 38 : const InterpolatorSourceVars&... interpolator_source_vars_input) { 39 : Variables<typename Metavariables::interpolator_source_vars> 40 : interpolator_source_vars(mesh.number_of_grid_points()); 41 : const std::tuple<const InterpolatorSourceVars&...> 42 : interpolator_source_vars_tuple{interpolator_source_vars_input...}; 43 : tmpl::for_each< 44 : tmpl::make_sequence<tmpl::size_t<0>, sizeof...(InterpolatorSourceVars)>>( 45 : [&interpolator_source_vars, 46 : &interpolator_source_vars_tuple](auto index_v) { 47 : constexpr size_t index = tmpl::type_from<decltype(index_v)>::value; 48 : get<tmpl::at_c<typename Metavariables::interpolator_source_vars, 49 : index>>(interpolator_source_vars) = 50 : get<index>(interpolator_source_vars_tuple); 51 : }); 52 : 53 : // Send volume data to the Interpolator, to trigger interpolation. 54 : auto& interpolator = *Parallel::local_branch( 55 : ::Parallel::get_parallel_component<Interpolator<Metavariables>>(cache)); 56 : Parallel::simple_action<Actions::InterpolatorReceiveVolumeData< 57 : typename InterpolationTargetTag::temporal_id>>( 58 : interpolator, temporal_id, array_index, mesh, interpolator_source_vars); 59 : 60 : // Tell the interpolation target that it should interpolate. 61 : auto& target = Parallel::get_parallel_component< 62 : InterpolationTarget<Metavariables, InterpolationTargetTag>>(cache); 63 : Parallel::simple_action< 64 : Actions::AddTemporalIdsToInterpolationTarget<InterpolationTargetTag>>( 65 : target, std::vector<typename InterpolationTargetTag::temporal_id::type>{ 66 : temporal_id}); 67 : } 68 : } // namespace intrp