Skip to content

Commit

Permalink
Allow observing only some blocks in ObserveFields
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsdeppe committed Sep 25, 2024
1 parent ebb074c commit 4cb9b91
Show file tree
Hide file tree
Showing 33 changed files with 133 additions and 39 deletions.
65 changes: 52 additions & 13 deletions src/ParallelAlgorithms/Events/ObserveFields.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "DataStructures/DataBox/ValidateSelection.hpp"
#include "DataStructures/DataVector.hpp"
#include "DataStructures/FloatingPointType.hpp"
#include "Domain/Creators/BlockGroups.hpp"
#include "Domain/Structure/ElementId.hpp"
#include "Domain/Tags.hpp"
#include "IO/H5/TensorData.hpp"
Expand Down Expand Up @@ -157,9 +158,19 @@ class ObserveFields<VolumeDim, tmpl::list<Tensors...>,
using type = FloatingPointType;
};

/// \brief A list of block or group names on which to observe.
///
/// Set to `All` to observer everywhere.
struct BlocksToObserve {
using type =
Options::Auto<std::vector<std::string>, Options::AutoLabel::All>;
static constexpr Options::String help = {
"A list of block and group names on which to observe."};
};

using options =
tmpl::list<SubfileName, CoordinatesFloatingPointType, FloatingPointTypes,
VariablesToObserve, InterpolateToMesh>;
VariablesToObserve, BlocksToObserve, InterpolateToMesh>;

static constexpr Options::String help =
"Observe volume tensor fields.\n"
Expand All @@ -170,12 +181,14 @@ class ObserveFields<VolumeDim, tmpl::list<Tensors...>,

ObserveFields() = default;

ObserveFields(const std::string& subfile_name,
FloatingPointType coordinates_floating_point_type,
const std::vector<FloatingPointType>& floating_point_types,
const std::vector<std::string>& variables_to_observe,
std::optional<Mesh<VolumeDim>> interpolation_mesh = {},
const Options::Context& context = {});
ObserveFields(
const std::string& subfile_name,
FloatingPointType coordinates_floating_point_type,
const std::vector<FloatingPointType>& floating_point_types,
const std::vector<std::string>& variables_to_observe,
std::optional<std::vector<std::string>> active_block_or_block_groups = {},
std::optional<Mesh<VolumeDim>> interpolation_mesh = {},
const Options::Context& context = {});

using compute_tags_for_observation_box =
tmpl::list<Tensors..., NonTensorComputeTags...>;
Expand All @@ -192,6 +205,10 @@ class ObserveFields<VolumeDim, tmpl::list<Tensors...>,
const ElementId<VolumeDim>& array_index,
const ParallelComponent* const component,
const ObservationValue& observation_value) const {
if (not active_block(get<domain::Tags::Domain<VolumeDim>>(box),
array_index)) {
return;
}
// Skip observation on elements that are not part of a section
const std::optional<std::string> section_observation_key =
observers::get_section_observation_key<ArraySectionIdTag>(box);
Expand Down Expand Up @@ -333,6 +350,10 @@ class ObserveFields<VolumeDim, tmpl::list<Tensors...>,
std::pair<observers::TypeOfObservation, observers::ObservationKey>>
get_observation_type_and_key_for_registration(
const db::DataBox<DbTagsList>& box) const {
if (not active_block(db::get<domain::Tags::Domain<VolumeDim>>(box),
db::get<domain::Tags::Element<VolumeDim>>(box).id())) {
return std::nullopt;
}
const std::optional<std::string> section_observation_key =
observers::get_section_observation_key<ArraySectionIdTag>(box);
if (not section_observation_key.has_value()) {
Expand All @@ -359,6 +380,7 @@ class ObserveFields<VolumeDim, tmpl::list<Tensors...>,
Event::pup(p);
p | subfile_path_;
p | variables_to_observe_;
p | active_block_or_block_groups_;
p | interpolation_mesh_;
}

Expand All @@ -375,21 +397,37 @@ class ObserveFields<VolumeDim, tmpl::list<Tensors...>,
return false;
}

bool active_block(const Domain<VolumeDim>& domain,
const ElementId<VolumeDim>& element_id) const {
if (not active_block_or_block_groups_.has_value()) {
return true;
}
const std::unordered_set<std::string> block_names =
domain::expand_block_groups_to_block_names(
active_block_or_block_groups_.value(), domain.block_names(),
domain.block_groups());
return alg::found(block_names,
domain.blocks().at(element_id.block_id()).name());
}

std::string subfile_path_;
std::unordered_map<std::string, FloatingPointType> variables_to_observe_{};
std::optional<std::vector<std::string>> active_block_or_block_groups_{};
std::optional<Mesh<VolumeDim>> interpolation_mesh_{};
};

template <size_t VolumeDim, typename... Tensors,
typename... NonTensorComputeTags, typename ArraySectionIdTag>
ObserveFields<VolumeDim, tmpl::list<Tensors...>,
tmpl::list<NonTensorComputeTags...>, ArraySectionIdTag>::
ObserveFields(const std::string& subfile_name,
const FloatingPointType coordinates_floating_point_type,
const std::vector<FloatingPointType>& floating_point_types,
const std::vector<std::string>& variables_to_observe,
std::optional<Mesh<VolumeDim>> interpolation_mesh,
const Options::Context& context)
ObserveFields(
const std::string& subfile_name,
const FloatingPointType coordinates_floating_point_type,
const std::vector<FloatingPointType>& floating_point_types,
const std::vector<std::string>& variables_to_observe,
std::optional<std::vector<std::string>> active_block_or_block_groups,
std::optional<Mesh<VolumeDim>> interpolation_mesh,
const Options::Context& context)
: subfile_path_("/" + subfile_name),
variables_to_observe_([&context, &floating_point_types,
&variables_to_observe]() {
Expand All @@ -416,6 +454,7 @@ ObserveFields<VolumeDim, tmpl::list<Tensors...>,
}
return result;
}()),
active_block_or_block_groups_(std::move(active_block_or_block_groups)),
interpolation_mesh_(interpolation_mesh) {
ASSERT(
(... or (db::tag_name<Tensors>() == "InertialCoordinates")),
Expand Down
1 change: 1 addition & 0 deletions support/Pipelines/Bbh/InitialData.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ EventsAndTriggers:
InterpolateToMesh: None
CoordinatesFloatingPointType: Double
FloatingPointTypes: [Double]
BlocksToObserve: All
- ObserveAdmIntegrals

RandomizeInitialGuess: None
Expand Down
1 change: 1 addition & 0 deletions support/Pipelines/Bbh/Inspiral.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ EventsAndTriggers:
# for visualization.
CoordinatesFloatingPointType: Float
FloatingPointTypes: [Float]
BlocksToObserve: All
# Try to find common horizon at small separation
- Trigger:
SeparationLessThan:
Expand Down
1 change: 1 addition & 0 deletions support/Pipelines/Bbh/Ringdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ EventsAndTriggers:
InterpolateToMesh: None
CoordinatesFloatingPointType: Double
FloatingPointTypes: [Double]
BlocksToObserve: All
- ApparentHorizon
- ExcisionBoundary
# Never terminate... run until something fails!
Expand Down
2 changes: 2 additions & 0 deletions tests/InputFiles/CurvedScalarWave/PlaneWaveMinkowski3D.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ EventsAndTriggers:
InterpolateToMesh: None
CoordinatesFloatingPointType: Double
FloatingPointTypes: [Double]
BlocksToObserve: All
- Trigger:
Slabs:
EvenlySpaced:
Expand All @@ -116,6 +117,7 @@ EventsAndTriggers:
InterpolateToMesh: None
CoordinatesFloatingPointType: Double
FloatingPointTypes: [Double]
BlocksToObserve: All
- Trigger:
Slabs:
EvenlySpaced:
Expand Down
1 change: 1 addition & 0 deletions tests/InputFiles/CurvedScalarWave/WorldtubeKerrSchild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ EventsAndTriggers:
InterpolateToMesh: None
CoordinatesFloatingPointType: Double
FloatingPointTypes: [Double]
BlocksToObserve: All
- Trigger:
Slabs:
EvenlySpaced:
Expand Down
1 change: 1 addition & 0 deletions tests/InputFiles/Elasticity/BentBeam.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ EventsAndTriggers:
InterpolateToMesh: None
CoordinatesFloatingPointType: Double
FloatingPointTypes: [Double]
BlocksToObserve: All

Amr:
Verbosity: Quiet
Expand Down
1 change: 1 addition & 0 deletions tests/InputFiles/Elasticity/HalfSpaceMirror.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ EventsAndTriggers:
InterpolateToMesh: None
CoordinatesFloatingPointType: Double
FloatingPointTypes: [Double]
BlocksToObserve: All

Amr:
Verbosity: Quiet
Expand Down
1 change: 1 addition & 0 deletions tests/InputFiles/Elasticity/SingleCoatingMirror.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ EventsAndTriggers:
InterpolateToMesh: None
CoordinatesFloatingPointType: Float
FloatingPointTypes: [Float]
BlocksToObserve: All

Amr:
Verbosity: Quiet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ EventsAndTriggers:
InterpolateToMesh: None
CoordinatesFloatingPointType: Double
FloatingPointTypes: [Double]
BlocksToObserve: All
- Trigger:
Slabs:
EvenlySpaced:
Expand Down
1 change: 1 addition & 0 deletions tests/InputFiles/GeneralizedHarmonic/GaugeWave1D.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ EventsAndTriggers:
InterpolateToMesh: None
CoordinatesFloatingPointType: Double
FloatingPointTypes: [Double]
BlocksToObserve: All
- Trigger:
Slabs:
Specified:
Expand Down
1 change: 1 addition & 0 deletions tests/InputFiles/GeneralizedHarmonic/GaugeWave3D.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ EventsAndTriggers:
InterpolateToMesh: None
CoordinatesFloatingPointType: Double
FloatingPointTypes: [Double]
BlocksToObserve: All
- Trigger:
Slabs:
Specified:
Expand Down
1 change: 1 addition & 0 deletions tests/InputFiles/GeneralizedHarmonic/KerrSchild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ EventsAndTriggers:
InterpolateToMesh: None
CoordinatesFloatingPointType: Double
FloatingPointTypes: [Double]
BlocksToObserve: All
- Trigger:
Slabs:
EvenlySpaced:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ EventsAndTriggers:
InterpolateToMesh: None
CoordinatesFloatingPointType: Float
FloatingPointTypes: [Float]
BlocksToObserve: All
- Trigger:
TimeCompares:
Comparison: GreaterThan
Expand Down Expand Up @@ -362,6 +363,7 @@ EventsRunAtCleanup:
InterpolateToMesh: None
CoordinatesFloatingPointType: Double
FloatingPointTypes: [Double]
BlocksToObserve: All

# Control systems are disabled by default
ControlSystems:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ EventsAndTriggers:
InterpolateToMesh: None
CoordinatesFloatingPointType: Double
FloatingPointTypes: [Double, Double, Double, Double, Double]
BlocksToObserve: All
- Trigger:
Slabs:
EvenlySpaced:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ EventsAndTriggers:
InterpolateToMesh: None
CoordinatesFloatingPointType: Double
FloatingPointTypes: [Double, Double, Double, Double, Double]
BlocksToObserve: All
- Trigger:
Slabs:
Specified:
Expand Down
1 change: 1 addition & 0 deletions tests/InputFiles/Poisson/Lorentzian.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ EventsAndTriggers:
InterpolateToMesh: None
CoordinatesFloatingPointType: Double
FloatingPointTypes: [Double]
BlocksToObserve: All

BuildMatrix:
MatrixSubfileName: Matrix
Expand Down
1 change: 1 addition & 0 deletions tests/InputFiles/Poisson/ProductOfSinusoids1D.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ EventsAndTriggers:
InterpolateToMesh: None
CoordinatesFloatingPointType: Double
FloatingPointTypes: [Double]
BlocksToObserve: All

BuildMatrix:
MatrixSubfileName: Matrix
Expand Down
1 change: 1 addition & 0 deletions tests/InputFiles/Poisson/ProductOfSinusoids2D.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ EventsAndTriggers:
InterpolateToMesh: None
CoordinatesFloatingPointType: Double
FloatingPointTypes: [Double]
BlocksToObserve: All

Amr:
Verbosity: Quiet
Expand Down
1 change: 1 addition & 0 deletions tests/InputFiles/Poisson/ProductOfSinusoids3D.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ EventsAndTriggers:
InterpolateToMesh: None
CoordinatesFloatingPointType: Double
FloatingPointTypes: [Double]
BlocksToObserve: All

Amr:
Verbosity: Quiet
Expand Down
1 change: 1 addition & 0 deletions tests/InputFiles/Punctures/MultiplePunctures.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ EventsAndTriggers:
InterpolateToMesh: None
CoordinatesFloatingPointType: Double
FloatingPointTypes: [Double]
BlocksToObserve: All
- ObserveNorms:
SubfileName: VolumeIntegrals
TensorsToObserve:
Expand Down
1 change: 1 addition & 0 deletions tests/InputFiles/ScalarAdvection/Krivodonova1D.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ EventsAndTriggers:
InterpolateToMesh: None
CoordinatesFloatingPointType: Double
FloatingPointTypes: [Float, Float]
BlocksToObserve: All

EventsAndDenseTriggers:

Expand Down
1 change: 1 addition & 0 deletions tests/InputFiles/ScalarAdvection/Kuzmin2D.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ EventsAndTriggers:
InterpolateToMesh: None
CoordinatesFloatingPointType: Double
FloatingPointTypes: [Float, Float]
BlocksToObserve: All

EventsAndDenseTriggers:

Expand Down
1 change: 1 addition & 0 deletions tests/InputFiles/ScalarAdvection/Sinusoid1D.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ EventsAndTriggers:
InterpolateToMesh: None
CoordinatesFloatingPointType: Double
FloatingPointTypes: [Float, Float]
BlocksToObserve: All

EventsAndDenseTriggers:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ EventsAndTriggers:
InterpolateToMesh: None
CoordinatesFloatingPointType: Float
FloatingPointTypes: [Float]
BlocksToObserve: All
- Trigger:
Slabs:
EvenlySpaced:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ EventsAndTriggers:
InterpolateToMesh: None
CoordinatesFloatingPointType: Double
FloatingPointTypes: [Double]
BlocksToObserve: All
- ObserveNorms:
SubfileName: Errors
TensorsToObserve:
Expand Down
1 change: 1 addition & 0 deletions tests/InputFiles/ScalarWave/PlaneWave1DObserveExample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ EventsAndTriggers:
InterpolateToMesh: None
CoordinatesFloatingPointType: Double
FloatingPointTypes: [Double, Float, Float]
BlocksToObserve: All
# [observe_event_trigger]

Observers:
Expand Down
1 change: 1 addition & 0 deletions tests/InputFiles/Xcts/BinaryBlackHole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,4 @@ EventsAndTriggers:
InterpolateToMesh: None
CoordinatesFloatingPointType: Double
FloatingPointTypes: [Double]
BlocksToObserve: All
1 change: 1 addition & 0 deletions tests/InputFiles/Xcts/HeadOnBns.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ EventsAndTriggers:
InterpolateToMesh: None
CoordinatesFloatingPointType: Double
FloatingPointTypes: [Double]
BlocksToObserve: All

Amr:
Verbosity: Quiet
Expand Down
1 change: 1 addition & 0 deletions tests/InputFiles/Xcts/KerrSchild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,4 @@ EventsAndTriggers:
InterpolateToMesh: None
CoordinatesFloatingPointType: Double
FloatingPointTypes: [Double]
BlocksToObserve: All
1 change: 1 addition & 0 deletions tests/InputFiles/Xcts/TovStar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ EventsAndTriggers:
InterpolateToMesh: None
CoordinatesFloatingPointType: Float
FloatingPointTypes: [Float]
BlocksToObserve: All

Amr:
Verbosity: Quiet
Expand Down
Loading

0 comments on commit 4cb9b91

Please sign in to comment.