Skip to content

Commit

Permalink
Merge pull request #6286 from iago-mendes/fix-adm-observer
Browse files Browse the repository at this point in the history
Limit ADM integrals observer to the finest grid.
  • Loading branch information
nilsvu authored Sep 12, 2024
2 parents e5c08ea + 8f30b9e commit 7749b4e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/Elliptic/Executables/Xcts/SolveXcts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ struct Metavariables {
volume_dim, typename system::primal_fields>>,
tmpl::pair<Event,
tmpl::flatten<tmpl::list<
Events::Completion, Events::ObserveAdmIntegrals,
Events::Completion,
Events::ObserveAdmIntegrals<
LinearSolver::multigrid::Tags::IsFinestGrid>,
dg::Events::field_observations<
volume_dim, observe_fields, observer_compute_tags,
LinearSolver::multigrid::Tags::IsFinestGrid>>>>,
Expand Down
2 changes: 0 additions & 2 deletions src/Elliptic/Systems/Xcts/Events/ObserveAdmIntegrals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,4 @@ void local_adm_integrals(
}
}

PUP::able::PUP_ID ObserveAdmIntegrals::my_PUP_ID = 0; // NOLINT

} // namespace Events
46 changes: 37 additions & 9 deletions src/Elliptic/Systems/Xcts/Events/ObserveAdmIntegrals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ void local_adm_integrals(
* the domain boundary in the upper logical zeta direction.
*
* Writes reduction quantities:
* - `Linear momentum`
* - ADM mass
* - Linear momentum
* - Center of mass
*/
template <typename ArraySectionIdTag = void>
class ObserveAdmIntegrals : public Event {
private:
using ReductionData = Parallel::ReductionData<
Expand Down Expand Up @@ -135,9 +138,11 @@ class ObserveAdmIntegrals : public Event {
domain::Tags::InverseJacobian<3, Frame::ElementLogical, Frame::Inertial>,
domain::Tags::Mesh<3>, domain::Tags::Element<3>,
domain::Tags::Faces<3, domain::Tags::FaceNormal<3>>,
domain::Tags::Faces<3, domain::Tags::FaceNormalVector<3>>>;
domain::Tags::Faces<3, domain::Tags::FaceNormalVector<3>>,
::Tags::ObservationBox>;

template <typename Metavariables, typename ArrayIndex,
template <typename DataBoxType, typename ComputeTagsList,
typename Metavariables, typename ArrayIndex,
typename ParallelComponent>
void operator()(
const Scalar<DataVector>& conformal_factor,
Expand All @@ -156,9 +161,18 @@ class ObserveAdmIntegrals : public Event {
const DirectionMap<3, tnsr::i<DataVector, 3>>& conformal_face_normals,
const DirectionMap<3, tnsr::I<DataVector, 3>>&
conformal_face_normal_vectors,
const ObservationBox<DataBoxType, ComputeTagsList>& box,
Parallel::GlobalCache<Metavariables>& cache,
const ArrayIndex& array_index, const ParallelComponent* const /*meta*/,
const ObservationValue& observation_value) const {
// 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);
if (not section_observation_key.has_value()) {
return;
}
const std::string subfile_path = subfile_path_ + *section_observation_key;

Scalar<double> adm_mass;
tnsr::I<double, 3> adm_linear_momentum;
tnsr::I<double, 3> center_of_mass;
Expand Down Expand Up @@ -194,7 +208,7 @@ class ObserveAdmIntegrals : public Event {
observers::ObserverWriter<Metavariables>,
observers::Observer<Metavariables>>>(cache));
observers::ObservationId observation_id{observation_value.value,
subfile_path_ + ".dat"};
subfile_path + ".dat"};
Parallel::ArrayComponentId array_component_id{
std::add_pointer_t<ParallelComponent>{nullptr},
Parallel::ArrayIndex<ElementId<3>>(array_index)};
Expand All @@ -204,23 +218,31 @@ class ObserveAdmIntegrals : public Event {
Parallel::threaded_action<
observers::ThreadedActions::CollectReductionDataOnNode>(
local_observer, std::move(observation_id),
std::move(array_component_id), subfile_path_, std::move(legend),
std::move(array_component_id), subfile_path, std::move(legend),
std::move(reduction_data));
} else {
Parallel::simple_action<observers::Actions::ContributeReductionData>(
local_observer, std::move(observation_id),
std::move(array_component_id), subfile_path_, std::move(legend),
std::move(array_component_id), subfile_path, std::move(legend),
std::move(reduction_data));
}
}

using observation_registration_tags = tmpl::list<>;
using observation_registration_tags = tmpl::list<::Tags::DataBox>;

template <typename DbTagsList>
std::optional<
std::pair<observers::TypeOfObservation, observers::ObservationKey>>
get_observation_type_and_key_for_registration() const {
get_observation_type_and_key_for_registration(
const db::DataBox<DbTagsList>& box) const {
const std::optional<std::string> section_observation_key =
observers::get_section_observation_key<ArraySectionIdTag>(box);
if (not section_observation_key.has_value()) {
return std::nullopt;
}
return {{observers::TypeOfObservation::Reduction,
observers::ObservationKey(subfile_path_ + ".dat")}};
observers::ObservationKey(
subfile_path_ + section_observation_key.value() + ".dat")}};
}

using is_ready_argument_tags = tmpl::list<>;
Expand All @@ -245,4 +267,10 @@ class ObserveAdmIntegrals : public Event {
};
/// @}

/// \cond
template <typename ArraySectionIdTag>
PUP::able::PUP_ID ObserveAdmIntegrals<ArraySectionIdTag>::my_PUP_ID =
0; // NOLINT
/// \endcond

} // namespace Events

0 comments on commit 7749b4e

Please sign in to comment.