diff --git a/src/ParallelAlgorithms/Events/ObserveFields.hpp b/src/ParallelAlgorithms/Events/ObserveFields.hpp index dc9f3769e818..9e6e25eb3030 100644 --- a/src/ParallelAlgorithms/Events/ObserveFields.hpp +++ b/src/ParallelAlgorithms/Events/ObserveFields.hpp @@ -20,6 +20,7 @@ #include "DataStructures/DataBox/ValidateSelection.hpp" #include "DataStructures/DataVector.hpp" #include "DataStructures/FloatingPointType.hpp" +#include "Domain/Structure/BlockGroups.hpp" #include "Domain/Structure/ElementId.hpp" #include "Domain/Tags.hpp" #include "IO/H5/TensorData.hpp" @@ -157,9 +158,19 @@ class ObserveFields, using type = FloatingPointType; }; + /// \brief A list of block or group names on which to observe. + /// + /// Set to `All` to observe everywhere. + struct BlocksToObserve { + using type = + Options::Auto, Options::AutoLabel::All>; + static constexpr Options::String help = { + "A list of block and group names on which to observe."}; + }; + using options = tmpl::list; + VariablesToObserve, BlocksToObserve, InterpolateToMesh>; static constexpr Options::String help = "Observe volume tensor fields.\n" @@ -170,12 +181,14 @@ class ObserveFields, ObserveFields() = default; - ObserveFields(const std::string& subfile_name, - FloatingPointType coordinates_floating_point_type, - const std::vector& floating_point_types, - const std::vector& variables_to_observe, - std::optional> interpolation_mesh = {}, - const Options::Context& context = {}); + ObserveFields( + const std::string& subfile_name, + FloatingPointType coordinates_floating_point_type, + const std::vector& floating_point_types, + const std::vector& variables_to_observe, + std::optional> active_block_or_block_groups = {}, + std::optional> interpolation_mesh = {}, + const Options::Context& context = {}); using compute_tags_for_observation_box = tmpl::list; @@ -192,6 +205,10 @@ class ObserveFields, const ElementId& array_index, const ParallelComponent* const component, const ObservationValue& observation_value) const { + if (not active_block(get>(box), + array_index)) { + return; + } // Skip observation on elements that are not part of a section const std::optional section_observation_key = observers::get_section_observation_key(box); @@ -333,6 +350,10 @@ class ObserveFields, std::pair> get_observation_type_and_key_for_registration( const db::DataBox& box) const { + if (not active_block(db::get>(box), + db::get>(box).id())) { + return std::nullopt; + } const std::optional section_observation_key = observers::get_section_observation_key(box); if (not section_observation_key.has_value()) { @@ -359,6 +380,7 @@ class ObserveFields, Event::pup(p); p | subfile_path_; p | variables_to_observe_; + p | active_block_or_block_groups_; p | interpolation_mesh_; } @@ -375,8 +397,22 @@ class ObserveFields, return false; } + bool active_block(const Domain& domain, + const ElementId& element_id) const { + if (not active_block_or_block_groups_.has_value()) { + return true; + } + const std::unordered_set 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 variables_to_observe_{}; + std::optional> active_block_or_block_groups_{}; std::optional> interpolation_mesh_{}; }; @@ -384,12 +420,14 @@ template ObserveFields, tmpl::list, ArraySectionIdTag>:: - ObserveFields(const std::string& subfile_name, - const FloatingPointType coordinates_floating_point_type, - const std::vector& floating_point_types, - const std::vector& variables_to_observe, - std::optional> interpolation_mesh, - const Options::Context& context) + ObserveFields( + const std::string& subfile_name, + const FloatingPointType coordinates_floating_point_type, + const std::vector& floating_point_types, + const std::vector& variables_to_observe, + std::optional> active_block_or_block_groups, + std::optional> interpolation_mesh, + const Options::Context& context) : subfile_path_("/" + subfile_name), variables_to_observe_([&context, &floating_point_types, &variables_to_observe]() { @@ -416,6 +454,7 @@ ObserveFields, } return result; }()), + active_block_or_block_groups_(std::move(active_block_or_block_groups)), interpolation_mesh_(interpolation_mesh) { ASSERT( (... or (db::tag_name() == "InertialCoordinates")), diff --git a/support/Pipelines/Bbh/InitialData.yaml b/support/Pipelines/Bbh/InitialData.yaml index 5d47556efa1a..45e7091d040b 100644 --- a/support/Pipelines/Bbh/InitialData.yaml +++ b/support/Pipelines/Bbh/InitialData.yaml @@ -247,6 +247,7 @@ EventsAndTriggers: InterpolateToMesh: None CoordinatesFloatingPointType: Double FloatingPointTypes: [Double] + BlocksToObserve: All - ObserveAdmIntegrals RandomizeInitialGuess: None diff --git a/support/Pipelines/Bbh/Inspiral.yaml b/support/Pipelines/Bbh/Inspiral.yaml index 8d0bccadb8d5..d647caf799bf 100644 --- a/support/Pipelines/Bbh/Inspiral.yaml +++ b/support/Pipelines/Bbh/Inspiral.yaml @@ -328,6 +328,7 @@ EventsAndTriggers: # for visualization. CoordinatesFloatingPointType: Float FloatingPointTypes: [Float] + BlocksToObserve: All # Try to find common horizon at small separation - Trigger: SeparationLessThan: diff --git a/support/Pipelines/Bbh/Ringdown.yaml b/support/Pipelines/Bbh/Ringdown.yaml index a85a20313d33..ecb356243076 100644 --- a/support/Pipelines/Bbh/Ringdown.yaml +++ b/support/Pipelines/Bbh/Ringdown.yaml @@ -191,6 +191,7 @@ EventsAndTriggers: InterpolateToMesh: None CoordinatesFloatingPointType: Double FloatingPointTypes: [Double] + BlocksToObserve: All - ApparentHorizon - ExcisionBoundary # Never terminate... run until something fails! diff --git a/tests/InputFiles/CurvedScalarWave/PlaneWaveMinkowski3D.yaml b/tests/InputFiles/CurvedScalarWave/PlaneWaveMinkowski3D.yaml index 6cc3165dc7b2..35b674c1b56e 100644 --- a/tests/InputFiles/CurvedScalarWave/PlaneWaveMinkowski3D.yaml +++ b/tests/InputFiles/CurvedScalarWave/PlaneWaveMinkowski3D.yaml @@ -100,6 +100,7 @@ EventsAndTriggers: InterpolateToMesh: None CoordinatesFloatingPointType: Double FloatingPointTypes: [Double] + BlocksToObserve: All - Trigger: Slabs: EvenlySpaced: @@ -116,6 +117,7 @@ EventsAndTriggers: InterpolateToMesh: None CoordinatesFloatingPointType: Double FloatingPointTypes: [Double] + BlocksToObserve: All - Trigger: Slabs: EvenlySpaced: diff --git a/tests/InputFiles/CurvedScalarWave/WorldtubeKerrSchild.yaml b/tests/InputFiles/CurvedScalarWave/WorldtubeKerrSchild.yaml index eea71d0dd931..45a08de81396 100644 --- a/tests/InputFiles/CurvedScalarWave/WorldtubeKerrSchild.yaml +++ b/tests/InputFiles/CurvedScalarWave/WorldtubeKerrSchild.yaml @@ -112,6 +112,7 @@ EventsAndTriggers: InterpolateToMesh: None CoordinatesFloatingPointType: Double FloatingPointTypes: [Double] + BlocksToObserve: All - Trigger: Slabs: EvenlySpaced: diff --git a/tests/InputFiles/Elasticity/BentBeam.yaml b/tests/InputFiles/Elasticity/BentBeam.yaml index d261e4577d37..dec336b7daab 100644 --- a/tests/InputFiles/Elasticity/BentBeam.yaml +++ b/tests/InputFiles/Elasticity/BentBeam.yaml @@ -108,6 +108,7 @@ EventsAndTriggers: InterpolateToMesh: None CoordinatesFloatingPointType: Double FloatingPointTypes: [Double] + BlocksToObserve: All Amr: Verbosity: Quiet diff --git a/tests/InputFiles/Elasticity/HalfSpaceMirror.yaml b/tests/InputFiles/Elasticity/HalfSpaceMirror.yaml index 2899b7c456c8..854e6e215e6c 100644 --- a/tests/InputFiles/Elasticity/HalfSpaceMirror.yaml +++ b/tests/InputFiles/Elasticity/HalfSpaceMirror.yaml @@ -142,6 +142,7 @@ EventsAndTriggers: InterpolateToMesh: None CoordinatesFloatingPointType: Double FloatingPointTypes: [Double] + BlocksToObserve: All Amr: Verbosity: Quiet diff --git a/tests/InputFiles/Elasticity/SingleCoatingMirror.yaml b/tests/InputFiles/Elasticity/SingleCoatingMirror.yaml index 656437543aff..a7d1eedfeacf 100644 --- a/tests/InputFiles/Elasticity/SingleCoatingMirror.yaml +++ b/tests/InputFiles/Elasticity/SingleCoatingMirror.yaml @@ -159,6 +159,7 @@ EventsAndTriggers: InterpolateToMesh: None CoordinatesFloatingPointType: Float FloatingPointTypes: [Float] + BlocksToObserve: All Amr: Verbosity: Quiet diff --git a/tests/InputFiles/GeneralizedHarmonic/CylindricalBinaryBlackHole.yaml b/tests/InputFiles/GeneralizedHarmonic/CylindricalBinaryBlackHole.yaml index a5d72abcd0d6..e7372a1aad80 100644 --- a/tests/InputFiles/GeneralizedHarmonic/CylindricalBinaryBlackHole.yaml +++ b/tests/InputFiles/GeneralizedHarmonic/CylindricalBinaryBlackHole.yaml @@ -205,6 +205,7 @@ EventsAndTriggers: InterpolateToMesh: None CoordinatesFloatingPointType: Double FloatingPointTypes: [Double] + BlocksToObserve: All - Trigger: Slabs: EvenlySpaced: diff --git a/tests/InputFiles/GeneralizedHarmonic/GaugeWave1D.yaml b/tests/InputFiles/GeneralizedHarmonic/GaugeWave1D.yaml index 612f0700b752..fad804c5e7b3 100644 --- a/tests/InputFiles/GeneralizedHarmonic/GaugeWave1D.yaml +++ b/tests/InputFiles/GeneralizedHarmonic/GaugeWave1D.yaml @@ -145,6 +145,7 @@ EventsAndTriggers: InterpolateToMesh: None CoordinatesFloatingPointType: Double FloatingPointTypes: [Double] + BlocksToObserve: All - Trigger: Slabs: Specified: diff --git a/tests/InputFiles/GeneralizedHarmonic/GaugeWave3D.yaml b/tests/InputFiles/GeneralizedHarmonic/GaugeWave3D.yaml index c7f39f3e0639..5c826c76cfc3 100644 --- a/tests/InputFiles/GeneralizedHarmonic/GaugeWave3D.yaml +++ b/tests/InputFiles/GeneralizedHarmonic/GaugeWave3D.yaml @@ -138,6 +138,7 @@ EventsAndTriggers: InterpolateToMesh: None CoordinatesFloatingPointType: Double FloatingPointTypes: [Double] + BlocksToObserve: All - Trigger: Slabs: Specified: diff --git a/tests/InputFiles/GeneralizedHarmonic/KerrSchild.yaml b/tests/InputFiles/GeneralizedHarmonic/KerrSchild.yaml index 1e1847b92503..260a759ef6fc 100644 --- a/tests/InputFiles/GeneralizedHarmonic/KerrSchild.yaml +++ b/tests/InputFiles/GeneralizedHarmonic/KerrSchild.yaml @@ -195,6 +195,7 @@ EventsAndTriggers: InterpolateToMesh: None CoordinatesFloatingPointType: Double FloatingPointTypes: [Double] + BlocksToObserve: All - Trigger: Slabs: EvenlySpaced: diff --git a/tests/InputFiles/GrMhd/GhValenciaDivClean/BinaryNeutronStar.yaml b/tests/InputFiles/GrMhd/GhValenciaDivClean/BinaryNeutronStar.yaml index 8dc7add31bbe..d8335d57c918 100644 --- a/tests/InputFiles/GrMhd/GhValenciaDivClean/BinaryNeutronStar.yaml +++ b/tests/InputFiles/GrMhd/GhValenciaDivClean/BinaryNeutronStar.yaml @@ -311,6 +311,7 @@ EventsAndTriggers: InterpolateToMesh: None CoordinatesFloatingPointType: Float FloatingPointTypes: [Float] + BlocksToObserve: All - Trigger: TimeCompares: Comparison: GreaterThan @@ -362,6 +363,7 @@ EventsRunAtCleanup: InterpolateToMesh: None CoordinatesFloatingPointType: Double FloatingPointTypes: [Double] + BlocksToObserve: All # Control systems are disabled by default ControlSystems: diff --git a/tests/InputFiles/GrMhd/GhValenciaDivClean/GhMhdBondiMichel.yaml b/tests/InputFiles/GrMhd/GhValenciaDivClean/GhMhdBondiMichel.yaml index e3c1b4196a4e..0f0e787aadb5 100644 --- a/tests/InputFiles/GrMhd/GhValenciaDivClean/GhMhdBondiMichel.yaml +++ b/tests/InputFiles/GrMhd/GhValenciaDivClean/GhMhdBondiMichel.yaml @@ -206,6 +206,7 @@ EventsAndTriggers: InterpolateToMesh: None CoordinatesFloatingPointType: Double FloatingPointTypes: [Double, Double, Double, Double, Double] + BlocksToObserve: All - Trigger: Slabs: EvenlySpaced: diff --git a/tests/InputFiles/GrMhd/GhValenciaDivClean/GhMhdTovStar.yaml b/tests/InputFiles/GrMhd/GhValenciaDivClean/GhMhdTovStar.yaml index fb5ddbddc589..1c74ae44596e 100644 --- a/tests/InputFiles/GrMhd/GhValenciaDivClean/GhMhdTovStar.yaml +++ b/tests/InputFiles/GrMhd/GhValenciaDivClean/GhMhdTovStar.yaml @@ -239,6 +239,7 @@ EventsAndTriggers: InterpolateToMesh: None CoordinatesFloatingPointType: Double FloatingPointTypes: [Double, Double, Double, Double, Double] + BlocksToObserve: All - Trigger: Slabs: Specified: diff --git a/tests/InputFiles/Poisson/Lorentzian.yaml b/tests/InputFiles/Poisson/Lorentzian.yaml index b918d7ed8cf0..0df596acb8de 100644 --- a/tests/InputFiles/Poisson/Lorentzian.yaml +++ b/tests/InputFiles/Poisson/Lorentzian.yaml @@ -132,6 +132,7 @@ EventsAndTriggers: InterpolateToMesh: None CoordinatesFloatingPointType: Double FloatingPointTypes: [Double] + BlocksToObserve: All BuildMatrix: MatrixSubfileName: Matrix diff --git a/tests/InputFiles/Poisson/ProductOfSinusoids1D.yaml b/tests/InputFiles/Poisson/ProductOfSinusoids1D.yaml index e31ea749a9e3..9f9bda1566c4 100644 --- a/tests/InputFiles/Poisson/ProductOfSinusoids1D.yaml +++ b/tests/InputFiles/Poisson/ProductOfSinusoids1D.yaml @@ -169,6 +169,7 @@ EventsAndTriggers: InterpolateToMesh: None CoordinatesFloatingPointType: Double FloatingPointTypes: [Double] + BlocksToObserve: All BuildMatrix: MatrixSubfileName: Matrix diff --git a/tests/InputFiles/Poisson/ProductOfSinusoids2D.yaml b/tests/InputFiles/Poisson/ProductOfSinusoids2D.yaml index 403a0a1ef857..9f9d55f682ba 100644 --- a/tests/InputFiles/Poisson/ProductOfSinusoids2D.yaml +++ b/tests/InputFiles/Poisson/ProductOfSinusoids2D.yaml @@ -111,6 +111,7 @@ EventsAndTriggers: InterpolateToMesh: None CoordinatesFloatingPointType: Double FloatingPointTypes: [Double] + BlocksToObserve: All Amr: Verbosity: Quiet diff --git a/tests/InputFiles/Poisson/ProductOfSinusoids3D.yaml b/tests/InputFiles/Poisson/ProductOfSinusoids3D.yaml index bd6df0fbd632..b553f1560a26 100644 --- a/tests/InputFiles/Poisson/ProductOfSinusoids3D.yaml +++ b/tests/InputFiles/Poisson/ProductOfSinusoids3D.yaml @@ -115,6 +115,7 @@ EventsAndTriggers: InterpolateToMesh: None CoordinatesFloatingPointType: Double FloatingPointTypes: [Double] + BlocksToObserve: All Amr: Verbosity: Quiet diff --git a/tests/InputFiles/Punctures/MultiplePunctures.yaml b/tests/InputFiles/Punctures/MultiplePunctures.yaml index 98ecb1422589..1e777810bab4 100644 --- a/tests/InputFiles/Punctures/MultiplePunctures.yaml +++ b/tests/InputFiles/Punctures/MultiplePunctures.yaml @@ -169,6 +169,7 @@ EventsAndTriggers: InterpolateToMesh: None CoordinatesFloatingPointType: Double FloatingPointTypes: [Double] + BlocksToObserve: All - ObserveNorms: SubfileName: VolumeIntegrals TensorsToObserve: diff --git a/tests/InputFiles/ScalarAdvection/Krivodonova1D.yaml b/tests/InputFiles/ScalarAdvection/Krivodonova1D.yaml index 350d5134a4b5..92d76ad0a2ed 100644 --- a/tests/InputFiles/ScalarAdvection/Krivodonova1D.yaml +++ b/tests/InputFiles/ScalarAdvection/Krivodonova1D.yaml @@ -84,6 +84,7 @@ EventsAndTriggers: InterpolateToMesh: None CoordinatesFloatingPointType: Double FloatingPointTypes: [Float, Float] + BlocksToObserve: All EventsAndDenseTriggers: diff --git a/tests/InputFiles/ScalarAdvection/Kuzmin2D.yaml b/tests/InputFiles/ScalarAdvection/Kuzmin2D.yaml index b8f45ed29304..d801cddfb2da 100644 --- a/tests/InputFiles/ScalarAdvection/Kuzmin2D.yaml +++ b/tests/InputFiles/ScalarAdvection/Kuzmin2D.yaml @@ -85,6 +85,7 @@ EventsAndTriggers: InterpolateToMesh: None CoordinatesFloatingPointType: Double FloatingPointTypes: [Float, Float] + BlocksToObserve: All EventsAndDenseTriggers: diff --git a/tests/InputFiles/ScalarAdvection/Sinusoid1D.yaml b/tests/InputFiles/ScalarAdvection/Sinusoid1D.yaml index 705e1c73ae00..f26bd8d0d958 100644 --- a/tests/InputFiles/ScalarAdvection/Sinusoid1D.yaml +++ b/tests/InputFiles/ScalarAdvection/Sinusoid1D.yaml @@ -84,6 +84,7 @@ EventsAndTriggers: InterpolateToMesh: None CoordinatesFloatingPointType: Double FloatingPointTypes: [Float, Float] + BlocksToObserve: All EventsAndDenseTriggers: diff --git a/tests/InputFiles/ScalarTensor/KerrSchildSphericalHarmonic.yaml b/tests/InputFiles/ScalarTensor/KerrSchildSphericalHarmonic.yaml index 30696a450c21..5d931e2c1bbe 100644 --- a/tests/InputFiles/ScalarTensor/KerrSchildSphericalHarmonic.yaml +++ b/tests/InputFiles/ScalarTensor/KerrSchildSphericalHarmonic.yaml @@ -173,6 +173,7 @@ EventsAndTriggers: InterpolateToMesh: None CoordinatesFloatingPointType: Float FloatingPointTypes: [Float] + BlocksToObserve: All - Trigger: Slabs: EvenlySpaced: diff --git a/tests/InputFiles/ScalarWave/PlaneWave1DEventsAndTriggersExample.yaml b/tests/InputFiles/ScalarWave/PlaneWave1DEventsAndTriggersExample.yaml index a3755a8ba27b..01a1474389df 100644 --- a/tests/InputFiles/ScalarWave/PlaneWave1DEventsAndTriggersExample.yaml +++ b/tests/InputFiles/ScalarWave/PlaneWave1DEventsAndTriggersExample.yaml @@ -93,6 +93,7 @@ EventsAndTriggers: InterpolateToMesh: None CoordinatesFloatingPointType: Double FloatingPointTypes: [Double] + BlocksToObserve: All - ObserveNorms: SubfileName: Errors TensorsToObserve: diff --git a/tests/InputFiles/ScalarWave/PlaneWave1DObserveExample.yaml b/tests/InputFiles/ScalarWave/PlaneWave1DObserveExample.yaml index 2faa71d57d63..d8cb919c52ba 100644 --- a/tests/InputFiles/ScalarWave/PlaneWave1DObserveExample.yaml +++ b/tests/InputFiles/ScalarWave/PlaneWave1DObserveExample.yaml @@ -129,6 +129,7 @@ EventsAndTriggers: InterpolateToMesh: None CoordinatesFloatingPointType: Double FloatingPointTypes: [Double, Float, Float] + BlocksToObserve: All # [observe_event_trigger] Observers: diff --git a/tests/InputFiles/Xcts/BinaryBlackHole.yaml b/tests/InputFiles/Xcts/BinaryBlackHole.yaml index d3c4a81911cb..ffa1230ffbf2 100644 --- a/tests/InputFiles/Xcts/BinaryBlackHole.yaml +++ b/tests/InputFiles/Xcts/BinaryBlackHole.yaml @@ -269,3 +269,4 @@ EventsAndTriggers: InterpolateToMesh: None CoordinatesFloatingPointType: Double FloatingPointTypes: [Double] + BlocksToObserve: All diff --git a/tests/InputFiles/Xcts/HeadOnBns.yaml b/tests/InputFiles/Xcts/HeadOnBns.yaml index 8505acaa123b..60922f21a190 100644 --- a/tests/InputFiles/Xcts/HeadOnBns.yaml +++ b/tests/InputFiles/Xcts/HeadOnBns.yaml @@ -222,6 +222,7 @@ EventsAndTriggers: InterpolateToMesh: None CoordinatesFloatingPointType: Double FloatingPointTypes: [Double] + BlocksToObserve: All Amr: Verbosity: Quiet diff --git a/tests/InputFiles/Xcts/KerrSchild.yaml b/tests/InputFiles/Xcts/KerrSchild.yaml index b6a3a60395a8..0c581bc0bece 100644 --- a/tests/InputFiles/Xcts/KerrSchild.yaml +++ b/tests/InputFiles/Xcts/KerrSchild.yaml @@ -242,3 +242,4 @@ EventsAndTriggers: InterpolateToMesh: None CoordinatesFloatingPointType: Double FloatingPointTypes: [Double] + BlocksToObserve: All diff --git a/tests/InputFiles/Xcts/TovStar.yaml b/tests/InputFiles/Xcts/TovStar.yaml index f7c041755e16..882d1bd52a36 100644 --- a/tests/InputFiles/Xcts/TovStar.yaml +++ b/tests/InputFiles/Xcts/TovStar.yaml @@ -157,6 +157,7 @@ EventsAndTriggers: InterpolateToMesh: None CoordinatesFloatingPointType: Float FloatingPointTypes: [Float] + BlocksToObserve: All Amr: Verbosity: Quiet diff --git a/tests/Unit/Helpers/ParallelAlgorithms/Events/ObserveFields.hpp b/tests/Unit/Helpers/ParallelAlgorithms/Events/ObserveFields.hpp index 0a64cb747c56..6049dae15570 100644 --- a/tests/Unit/Helpers/ParallelAlgorithms/Events/ObserveFields.hpp +++ b/tests/Unit/Helpers/ParallelAlgorithms/Events/ObserveFields.hpp @@ -224,14 +224,18 @@ struct ScalarSystem { " CoordinatesFloatingPointType: Double\n" " VariablesToObserve: [Scalar, ScalarVarTimesTwo, ScalarVarTimesThree, " "Error(Scalar)]\n" - " FloatingPointTypes: [Double]\n"; + " FloatingPointTypes: [Double]\n" + " BlocksToObserve: All\n"; static ObserveEvent make_test_object( - const std::optional>& interpolating_mesh) { + const std::optional>& interpolating_mesh, + std::optional> active_block_or_block_groups = + std::nullopt) { return ObserveEvent{ "element_data", FloatingPointType::Double, {FloatingPointType::Double}, {"Scalar", "ScalarVarTimesTwo", "ScalarVarTimesThree", "Error(Scalar)"}, + std::move(active_block_or_block_groups), interpolating_mesh}; } }; @@ -346,10 +350,13 @@ struct ComplicatedSystem { " Vector, Tensor, Tensor2," " Error(Vector), Error(Tensor2)]\n" " FloatingPointTypes: [Double, Double, Double, Double, Float, Float," - " Double, Float]\n"; + " Double, Float]\n" + " BlocksToObserve: All\n"; static ObserveEvent make_test_object( - const std::optional>& interpolating_mesh) { + const std::optional>& interpolating_mesh, + std::optional> active_block_or_block_groups = + std::nullopt) { return ObserveEvent( "element_data", FloatingPointType::Double, {FloatingPointType::Double, FloatingPointType::Double, @@ -358,7 +365,7 @@ struct ComplicatedSystem { FloatingPointType::Double, FloatingPointType::Float}, {"Scalar", "ScalarVarTimesTwo", "ScalarVarTimesThree", "Vector", "Tensor", "Tensor2", "Error(Vector)", "Error(Tensor2)"}, - interpolating_mesh); + std::move(active_block_or_block_groups), interpolating_mesh); } }; } // namespace TestHelpers::dg::Events::ObserveFields diff --git a/tests/Unit/ParallelAlgorithms/Events/Test_ObserveFields.cpp b/tests/Unit/ParallelAlgorithms/Events/Test_ObserveFields.cpp index c897e4c02d12..919228c0a5b6 100644 --- a/tests/Unit/ParallelAlgorithms/Events/Test_ObserveFields.cpp +++ b/tests/Unit/ParallelAlgorithms/Events/Test_ObserveFields.cpp @@ -1,6 +1,7 @@ // Distributed under the MIT License. // See LICENSE.txt for details. +#include "Domain/Creators/Rectilinear.hpp" #include "Framework/TestingFramework.hpp" #include @@ -21,6 +22,7 @@ #include "DataStructures/FloatingPointType.hpp" #include "DataStructures/Tensor/Tensor.hpp" #include "DataStructures/Variables.hpp" +#include "Domain/Structure/Element.hpp" #include "Domain/Structure/ElementId.hpp" #include "Domain/Tags.hpp" #include "Framework/ActionTesting.hpp" @@ -95,8 +97,9 @@ template observe, const std::optional>& interpolating_mesh, - const bool has_analytic_solutions, + const bool has_analytic_solutions, const bool test_specific_blocks, const std::optional& section = std::nullopt) { + INFO(test_specific_blocks); using metavariables = Metavariables; constexpr size_t volume_dim = System::volume_dim; using DataType = typename System::data_type; @@ -105,7 +108,14 @@ void test_observe( using coordinates_tag = domain::Tags::Coordinates; - const ElementId element_id(2); + const ElementId element_id(0); + const Element element(element_id, {}); + // NOTE: The coordinate map is not actually what is used to compute the + // coordinates. + const domain::creators::Rectilinear rectilinear{ + make_array(-2.0), make_array(2.0), + make_array(0_st), make_array(5_st), + make_array(true)}; const typename element_component::array_index array_index(element_id); const Mesh mesh(5, Spectral::Basis::Legendre, Spectral::Quadrature::GaussLobatto); @@ -160,13 +170,14 @@ void test_observe( auto box = db::create, + domain::Tags::Domain, domain::Tags::Element, domain::Tags::Mesh, ::Tags::Variables, ::Tags::Variables, coordinates_tag, ::Tags::AnalyticSolutions, observers::Tags::ObservationKey>>( - metavariables{}, mesh, vars, prim_vars, - get(coordinate_vars), + metavariables{}, rectilinear.create_domain(), element, mesh, vars, + prim_vars, get(coordinate_vars), [&solutions, &has_analytic_solutions]() { return has_analytic_solutions ? std::make_optional(solutions) : std::nullopt; @@ -322,22 +333,25 @@ void test_system( INFO(pretty_type::get_name()); CAPTURE(section); using metavariables = Metavariables; - test_observe( - std::make_unique( - System::make_test_object(interpolating_mesh)), - interpolating_mesh, has_analytic_solutions, section); - INFO("create/serialize"); - register_factory_classes_with_charm(); - { - const std::string creation_string = System::creation_string_for_test + - mesh_creation_string; - const auto factory_event = - TestHelpers::test_creation, metavariables>( - creation_string); - auto serialized_event = serialize_and_deserialize(factory_event); + for (const bool test_specific_blocks : {false, true}) { test_observe( - std::move(serialized_event), interpolating_mesh, has_analytic_solutions, + std::make_unique( + System::make_test_object(interpolating_mesh)), + interpolating_mesh, has_analytic_solutions, test_specific_blocks, section); + INFO("create/serialize"); + register_factory_classes_with_charm(); + { + const std::string creation_string = + System::creation_string_for_test + mesh_creation_string; + const auto factory_event = + TestHelpers::test_creation, metavariables>( + creation_string); + auto serialized_event = serialize_and_deserialize(factory_event); + test_observe( + std::move(serialized_event), interpolating_mesh, + has_analytic_solutions, test_specific_blocks, section); + } } } } // namespace @@ -466,7 +480,7 @@ SPECTRE_TEST_CASE("Unit.Evolution.dG.ObserveFields", "[Unit][Evolution]") { dg::Events::ObserveFields>::ObserveEvent>( ComplicatedSystem::make_test_object( interpolating_mesh)), - interpolating_mesh, true); + interpolating_mesh, true, false); } CHECK_THROWS_WITH( TestHelpers::test_creation< @@ -475,7 +489,8 @@ SPECTRE_TEST_CASE("Unit.Evolution.dG.ObserveFields", "[Unit][Evolution]") { "CoordinatesFloatingPointType: Double\n" "VariablesToObserve: [NotAVar]\n" "FloatingPointTypes: [Double]\n" - "InterpolateToMesh: None\n"), + "InterpolateToMesh: None\n" + "BlocksToObserve: All\n"), Catch::Matchers::ContainsSubstring("Invalid selection: NotAVar")); CHECK_THROWS_WITH( @@ -485,6 +500,7 @@ SPECTRE_TEST_CASE("Unit.Evolution.dG.ObserveFields", "[Unit][Evolution]") { "CoordinatesFloatingPointType: Double\n" "VariablesToObserve: [Scalar, Scalar]\n" "FloatingPointTypes: [Double]\n" - "InterpolateToMesh: None\n"), + "InterpolateToMesh: None\n" + "BlocksToObserve: All\n"), Catch::Matchers::ContainsSubstring("Scalar specified multiple times")); }