Line data Source code
1 1 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : /// \file 5 : /// Declares functions for interpolating data in volume files to target points. 6 : /// This file is intended to be included in external programs, so it 7 : /// intentionally has no dependencies on any other headers. 8 : 9 : #pragma once 10 : 11 : #include <array> 12 : #include <cstddef> 13 : #include <optional> 14 : #include <string> 15 : #include <variant> 16 : #include <vector> 17 : 18 : /// Functions that are intended to be used by external programs, e.g. to 19 : /// interpolate data in volume files to target points. 20 0 : namespace spectre::Exporter { 21 : 22 : /// Identifies an observation by its ID in the volume data file. 23 1 : struct ObservationId { 24 0 : explicit ObservationId(size_t local_value) : value(local_value) {} 25 0 : size_t value; 26 : }; 27 : 28 : /// Identifies an observation by its index in the ordered list of observations. 29 : /// Negative indices are counted from the end of the list. 30 1 : struct ObservationStep { 31 0 : explicit ObservationStep(int local_value) : value(local_value) {} 32 0 : int value; 33 : }; 34 : 35 : /*! 36 : * \brief Interpolate data in volume files to target points 37 : * 38 : * \tparam Dim Dimension of the domain 39 : * \param volume_files_or_glob The list of H5 files, or a glob pattern 40 : * \param subfile_name The name of the subfile in the H5 files containing the 41 : * volume data 42 : * \param observation Either the observation ID as a `size_t`, or the index of 43 : * the observation in the volume files to interpolate as an `int` (a value of 0 44 : * would be the first observation, and a value of -1 would be the last 45 : * observation). 46 : * \param tensor_components The tensor components to interpolate, e.g. 47 : * "Lapse", "Shift_x", "Shift_y", "Shift_z", "SpatialMetric_xx", etc. 48 : * Look into the H5 file to see what components are available. 49 : * \param target_points The points to interpolate to, in inertial coordinates. 50 : * \param extrapolate_into_excisions Enables extrapolation into excision regions 51 : * of the domain (default is `false`). This can be useful to fill the excision 52 : * region with (constraint-violating but smooth) data so it can be imported into 53 : * moving puncture codes. Specifically, we implement the strategy used in 54 : * \cite Etienne2008re adjusted for distorted excisions: we choose uniformly 55 : * spaced radial anchor points spaced as $\Delta r = 0.3 r_\mathrm{AH}$ in the 56 : * grid frame (where the excision is spherical), then map the anchor points to 57 : * the distorted frame (where we have the target point) and do a 7th order 58 : * polynomial extrapolation into the excision region. 59 : * \param num_threads The number of threads to use if OpenMP is linked in. If 60 : * not specified, OpenMP will determine the number of threads automatically. 61 : * It's also possible to set the number of threads using the environment 62 : * variable OMP_NUM_THREADS. It's an error to specify num_threads if OpenMP is 63 : * not linked in. Set num_threads to 1 to disable OpenMP. 64 : * \return std::vector<std::vector<double>> The interpolated data. The first 65 : * dimension corresponds to the selected tensor components, and the second 66 : * dimension corresponds to the target points. 67 : */ 68 : template <size_t Dim> 69 1 : std::vector<std::vector<double>> interpolate_to_points( 70 : const std::variant<std::vector<std::string>, std::string>& 71 : volume_files_or_glob, 72 : const std::string& subfile_name, 73 : const std::variant<ObservationId, ObservationStep>& observation, 74 : const std::vector<std::string>& tensor_components, 75 : const std::array<std::vector<double>, Dim>& target_points, 76 : bool extrapolate_into_excisions = false, 77 : std::optional<size_t> num_threads = std::nullopt); 78 : 79 : } // namespace spectre::Exporter