SpECTRE  v2024.03.19
Importing data

Table of Contents

The importers namespace holds functionality for importing data into SpECTRE. We currently support loading volume data files in the same format that is written by the observers.

Importing volume data

The importers::ElementDataReader parallel component is responsible for loading volume data, interpolating it, and distributing it to elements of one or multiple array parallel components. As a first step, make sure you have added the importers::ElementDataReader to your Metavariables::component_list. Also make sure you have a Parallel::Phase in which you will perform registration with the importer, and another in which you want to load the data. Here's an example for such Metavariables:

template <size_t Dim>
struct Metavariables {
static constexpr size_t volume_dim = Dim;
struct system {};
using component_list =
tmpl::list<ElementArray<Dim, Metavariables>,
TestDataWriter<Dim, Metavariables>,
static constexpr const char* const help{"Test the volume data reader"};
static constexpr bool ignore_unrecognized_command_line_options = false;
static constexpr std::array<Parallel::Phase, 5> default_phase_order{
struct factory_creation
: tt::ConformsTo<Options::protocols::FactoryCreation> {
using factory_classes =
tmpl::map<tmpl::pair<DomainCreator<Dim>, domain_creators<Dim>>>;
};
// NOLINTNEXTLINE(google-runtime-references)
void pup(PUP::er& /*p*/) {}
};
@ Register
phase in which components register with other components
@ ImportInitialData
phase in which initial data is imported from volume files
@ Initialization
initial phase of an executable
@ Testing
phase in which something is tested
@ Exit
final phase of an executable
A nodegroup parallel component that reads in a volume data file and distributes its data to elements ...
Definition: ElementDataReader.hpp:41
Indicate a class conforms to the Protocol.
Definition: ProtocolHelpers.hpp:22
T system(T... args)

To load volume data from a file, write an action in which you invoke importers::Actions::ReadAllVolumeDataAndDistribute on the importers::ElementDataReader. For simple use cases we provide importers::Actions::ReadVolumeData, which can be added to the phase_dependent_action_list of your element array and which will generate input-file options for you. Here's an example that will be explained in more detail below:

tmpl::list<
Terminate the algorithm to proceed to the next phase.
Definition: TerminatePhase.hpp:28
List of all the actions to be executed in the specified phase.
Definition: PhaseDependentActionList.hpp:17
Read a volume data file and distribute the data to all registered elements, interpolating to the targ...
Definition: ReadVolumeData.hpp:276
Wait for data from a volume data file to arrive and directly move it into the DataBox.
Definition: ReceiveVolumeData.hpp:31
Register an element with the volume data reader component.
Definition: RegisterWithElementDataReader.hpp:61

The parameters passed to importers::Actions::ReadAllVolumeDataAndDistribute specify the volume data to load. See the documentation of importers::Actions::ReadAllVolumeDataAndDistribute for details. In the example above, we use importers::Actions::ReadVolumeData to generate the input-file options for us and place them in an option group:

struct OptionsGroup {
static std::string name() { return "Importers"; }
static constexpr Options::String help = "Numeric volume data";
};
std::string name()
Return the result of the name() member of a class. If a class doesn't have a name() member,...
Definition: PrettyType.hpp:733
const char *const String
The string used in option structs.
Definition: String.hpp:8

This results in a section in the input file that may look like this:

Importers:
VolumeData:
FileGlob: "Test_DataImporterAlgorithm2D.h5"
Subgroup: "TestData"
ObservationValue: 2.
Interpolate: False