SpECTRE  v2024.09.29
spectre::Exporter Namespace Reference

Functions that are intended to be used by external programs, e.g. to interpolate data in volume files to target points. More...

Classes

struct  ObservationId
 Identifies an observation by its ID in the volume data file. More...
 
struct  ObservationStep
 Identifies an observation by its index in the ordered list of observations. Negative indices are counted from the end of the list. More...
 

Functions

template<size_t Dim>
std::vector< std::vector< double > > interpolate_to_points (const std::variant< std::vector< std::string >, std::string > &volume_files_or_glob, const std::string &subfile_name, const std::variant< ObservationId, ObservationStep > &observation, const std::vector< std::string > &tensor_components, const std::array< std::vector< double >, Dim > &target_points, bool extrapolate_into_excisions=false, std::optional< size_t > num_threads=std::nullopt)
 Interpolate data in volume files to target points. More...
 
template<typename Tags , typename DataType , size_t Dim>
tuples::tagged_tuple_from_typelist< Tags > interpolate_to_points (const std::variant< std::vector< std::string >, std::string > &volume_files_or_glob, const std::string &subfile_name, const std::variant< ObservationId, ObservationStep > &observation, const tnsr::I< DataType, Dim > &target_points, bool extrapolate_into_excisions=false, std::optional< size_t > num_threads=std::nullopt)
 Interpolates data in volume files to target points. More...
 

Detailed Description

Functions that are intended to be used by external programs, e.g. to interpolate data in volume files to target points.

Function Documentation

◆ interpolate_to_points() [1/2]

template<size_t Dim>
std::vector< std::vector< double > > spectre::Exporter::interpolate_to_points ( const std::variant< std::vector< std::string >, std::string > &  volume_files_or_glob,
const std::string subfile_name,
const std::variant< ObservationId, ObservationStep > &  observation,
const std::vector< std::string > &  tensor_components,
const std::array< std::vector< double >, Dim > &  target_points,
bool  extrapolate_into_excisions = false,
std::optional< size_t >  num_threads = std::nullopt 
)

Interpolate data in volume files to target points.

Template Parameters
DimDimension of the domain
Parameters
volume_files_or_globThe list of H5 files, or a glob pattern
subfile_nameThe name of the subfile in the H5 files containing the volume data
observationEither the observation ID as a size_t, or the index of the observation in the volume files to interpolate as an int (a value of 0 would be the first observation, and a value of -1 would be the last observation).
tensor_componentsThe tensor components to interpolate, e.g. "Lapse", "Shift_x", "Shift_y", "Shift_z", "SpatialMetric_xx", etc. Look into the H5 file to see what components are available.
target_pointsThe points to interpolate to, in inertial coordinates.
extrapolate_into_excisionsEnables extrapolation into excision regions of the domain (default is false). This can be useful to fill the excision region with (constraint-violating but smooth) data so it can be imported into moving puncture codes. Specifically, we implement the strategy used in [64] adjusted for distorted excisions: we choose uniformly spaced radial anchor points spaced as \(\Delta r = 0.3 r_\mathrm{AH}\) in the grid frame (where the excision is spherical), then map the anchor points to the distorted frame (where we have the target point) and do a 7th order polynomial extrapolation into the excision region.
num_threadsThe number of threads to use if OpenMP is linked in. If not specified, OpenMP will determine the number of threads automatically. It's also possible to set the number of threads using the environment variable OMP_NUM_THREADS. It's an error to specify num_threads if OpenMP is not linked in. Set num_threads to 1 to disable OpenMP.

Returns: std::vector<std::vector<double>> The interpolated data. The first dimension corresponds to the selected tensor components, and the second dimension corresponds to the target points.

◆ interpolate_to_points() [2/2]

template<typename Tags , typename DataType , size_t Dim>
tuples::tagged_tuple_from_typelist< Tags > spectre::Exporter::interpolate_to_points ( const std::variant< std::vector< std::string >, std::string > &  volume_files_or_glob,
const std::string subfile_name,
const std::variant< ObservationId, ObservationStep > &  observation,
const tnsr::I< DataType, Dim > &  target_points,
bool  extrapolate_into_excisions = false,
std::optional< size_t >  num_threads = std::nullopt 
)

Interpolates data in volume files to target points.

This is an overload of the interpolate_to_points function that works with Tensor types and tags, rather than the raw C++ types that are used in the other overload so it can be used by external programs.

The Tags template parameter is a typelist of tags that should be read from the volume files. The dataset names to read are constructed from the tag names. Here is an example of how to use this function:

const tnsr::I<DataVector, 3> target_points{
{{{0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}, {0.0, 0.0, 0.0}}}};
const auto interpolated_data = interpolate_to_points<
tmpl::list<ScalarWave::Tags::Psi, ScalarWave::Tags::Phi<3>>>(
unit_test_src_path() + "/Visualization/Python/VolTestData*.h5",
"element_data", ObservationStep{0}, target_points);
const auto& psi = get(get<ScalarWave::Tags::Psi>(interpolated_data));
Definition: ContractFirstNIndices.hpp:16
const auto & get(const DataBox< TagList > &box)
Retrieve the item with tag Tag from the DataBox.
Definition: DataBox.hpp:1259
std::string unit_test_src_path()
Returns the path to the Unit test directory.
std::vector< std::vector< double > > interpolate_to_points(const std::variant< std::vector< std::string >, std::string > &volume_files_or_glob, const std::string &subfile_name, const std::variant< ObservationId, ObservationStep > &observation, const std::vector< std::string > &tensor_components, const std::array< std::vector< double >, Dim > &target_points, bool extrapolate_into_excisions=false, std::optional< size_t > num_threads=std::nullopt)
Interpolate data in volume files to target points.