SpECTRE  v2022.01.03
Importing data

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 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 Metavariables::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 {
using component_list =
tmpl::list<ElementArray<Dim, Grid::Fine, Metavariables>,
ElementArray<Dim, Grid::Coarse, Metavariables>,
TestDataWriter<Dim, Metavariables>,
static constexpr const char* const help{"Test the volume data reader"};
static constexpr bool ignore_unrecognized_command_line_options = false;
enum class Phase { Initialization, Register, ImportData, TestResult, Exit };
template <typename... Tags>
static Phase determine_next_phase(
tuples::TaggedTuple<Tags...>*> /*phase_change_decision_data*/,
const Phase& current_phase,
const Parallel::CProxy_GlobalCache<Metavariables>& /*cache_proxy*/) {
switch (current_phase) {
case Phase::Initialization:
return Phase::Register;
case Phase::Register:
return Phase::ImportData;
case Phase::ImportData:
return Phase::TestResult;
default:
return Phase::Exit;
}
}
// NOLINTNEXTLINE(google-runtime-references)
void pup(PUP::er& /*p*/) {}
};
Require a pointer to not be a nullptr
Definition: Gsl.hpp:183
A nodegroup parallel component that reads in a volume data file and distributes its data to elements ...
Definition: ElementDataReader.hpp:38

To load volume data from a file, invoke the importers::Actions::ReadVolumeData iterable action in the phase_dependent_action_list of your array parallel component. Here's an example that will be explained in more detail below:

typename Metavariables::Phase, Metavariables::Phase::Register,
typename Metavariables::Phase, Metavariables::Phase::ImportData,
VolumeDataOptions<TheGrid>, import_fields>,
VolumeDataOptions<TheGrid>, import_fields>,
Terminate the algorithm to proceed to the next phase.
Definition: TerminatePhase.hpp:26
List of all the actions to be executed in the specified phase.
Definition: PhaseDependentActionList.hpp:16
Read a volume data file and distribute the data to all registered elements.
Definition: ReadVolumeData.hpp:67
Wait for data from a volume data file to arrive and directly move it into the DataBox.
Definition: ReceiveVolumeData.hpp:30
Register an element with the volume data reader component.
Definition: RegisterWithElementDataReader.hpp:42

The template parameters to the actions in the example above specify the volume data to load. The first template parameter is an option group that determines the file to read and the second parameter is a typelist of the tags to import and fill with the volume data. See the documentation of the importers::Actions::ReadAllVolumeDataAndDistribute action for details on these parameters. In the example above, the VolumeDataOptions is an option group that supplies information such as the file name. You provide an option group that represents the data you want to import. For example, we have the evolution::OptionTags::NumericInitialData that represents numeric initial data for an evolution. In our example, we created a new class like this:

template <Grid TheGrid>
struct VolumeDataOptions {
static std::string name() { return MakeString{} << TheGrid << "VolumeData"; }
static constexpr Options::String help = "Numeric volume data";
};
Make a string by streaming into object.
Definition: MakeString.hpp:18
const char *const String
The string used in option structs.
Definition: Options.hpp:32
Groups the data importer configurations in the input file.
Definition: Tags.hpp:27

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

Importers:
FineVolumeData:
FileName: "Test_DataImporterAlgorithm2D_shared.h5"
Subgroup: "fine_data"
ObservationValue: 3.
CoarseVolumeData:
FileName: "Test_DataImporterAlgorithm2D_shared.h5"
Subgroup: "coarse_data"
ObservationValue: 2.