Skip to content

Commit

Permalink
Remove template parameter ArrayIndex when it must be an ElementId
Browse files Browse the repository at this point in the history
  • Loading branch information
kidder committed Feb 8, 2023
1 parent 9d92ffd commit 39ae07b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,11 @@ namespace amr::Actions {
/// - Sends the (possibly updated) decision to all of the neighboring Elements
struct EvaluateRefinementCriteria {
template <typename ParallelComponent, typename DbTagList,
typename Metavariables, typename ArrayIndex>
typename Metavariables>
static void apply(db::DataBox<DbTagList>& box,
Parallel::GlobalCache<Metavariables>& cache,
const ArrayIndex& array_index) {
const ElementId<Metavariables::volume_dim>& element_id) {
constexpr size_t volume_dim = Metavariables::volume_dim;
ElementId<volume_dim> element_id{array_index};
auto overall_decision =
make_array<volume_dim>(amr::domain::Flag::Undefined);

Expand All @@ -95,7 +94,7 @@ struct EvaluateRefinementCriteria {
const auto& refinement_criteria =
db::get<amr::Criteria::Tags::Criteria>(box);
for (const auto& criterion : refinement_criteria) {
auto decision = criterion->evaluate(observation_box, cache, array_index);
auto decision = criterion->evaluate(observation_box, cache, element_id);
for (size_t d = 0; d < volume_dim; ++d) {
overall_decision[d] = std::max(overall_decision[d], decision[d]);
}
Expand Down
4 changes: 2 additions & 2 deletions src/ParallelAlgorithms/Amr/Actions/UpdateAmrDecision.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ namespace amr::Actions {
///
struct UpdateAmrDecision {
template <typename ParallelComponent, typename DbTagList,
typename Metavariables, typename ArrayIndex>
typename Metavariables>
static void apply(
db::DataBox<DbTagList>& box, Parallel::GlobalCache<Metavariables>& cache,
const ArrayIndex& /*array_index*/,
const ElementId<Metavariables::volume_dim>& /*element_id*/,
const ElementId<Metavariables::volume_dim>& neighbor_id,
const std::array<amr::domain::Flag, Metavariables::volume_dim>&
neighbor_amr_flags) {
Expand Down
15 changes: 8 additions & 7 deletions src/ParallelAlgorithms/Amr/Criteria/Criterion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "DataStructures/DataBox/ObservationBox.hpp"
#include "Domain/Amr/Flag.hpp"
#include "Domain/Structure/ElementId.hpp"
#include "Parallel/CharmPupable.hpp"
#include "Parallel/GlobalCache.hpp"
#include "Parallel/Tags/Metavariables.hpp"
Expand All @@ -31,9 +32,9 @@ namespace amr {
/// call operator.
/// The call operator should take as arguments the values corresponding to each
/// tag in `argument_tags` (in order), followed by the Parallel::GlobalCache,
/// and the ArrayIndex (which is typically an ElementId). The tags listed in
/// `argument_tags` should either be tags in the DataBox of the array component,
/// or listed in `compute_tags_for_observation_box`.
/// and the ElementId. The tags listed in `argument_tags` should either be tags
/// in the DataBox of the array component, or listed in
/// `compute_tags_for_observation_box`.
///
/// \example
/// \snippet Test_Criterion.cpp criterion_examples
Expand Down Expand Up @@ -65,17 +66,17 @@ class Criterion : public PUP::able {
/// of the tags listed in `compute_tags_for_observation_box` for each derived
/// Criterion listed in the `factory_classes`.
template <typename ComputeTagsList, typename DataBoxType,
typename Metavariables, typename ArrayIndex>
typename Metavariables>
auto evaluate(const ObservationBox<ComputeTagsList, DataBoxType>& box,
Parallel::GlobalCache<Metavariables>& cache,
const ArrayIndex& array_index) const {
const ElementId<Metavariables::volume_dim>& element_id) const {
using factory_classes =
typename std::decay_t<Metavariables>::factory_creation::factory_classes;
return call_with_dynamic_type<
std::array<amr::domain::Flag, Metavariables::volume_dim>,
tmpl::at<factory_classes, Criterion>>(
this, [&box, &cache, &array_index](auto* const criterion) {
return apply(*criterion, box, cache, array_index);
this, [&box, &cache, &element_id](auto* const criterion) {
return apply(*criterion, box, cache, element_id);
});
}
};
Expand Down
12 changes: 6 additions & 6 deletions src/ParallelAlgorithms/Amr/Criteria/Random.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ class Random : public Criterion {

using argument_tags = tmpl::list<>;

template <typename ArrayIndex, typename Metavariables>
template <typename Metavariables>
auto operator()(Parallel::GlobalCache<Metavariables>& /*cache*/,
const ArrayIndex& array_index) const;
const ElementId<Metavariables::volume_dim>& element_id) const;

void pup(PUP::er& p) override;

Expand All @@ -83,12 +83,12 @@ class Random : public Criterion {
size_t maximum_refinement_level_{0};
};

template <typename ArrayIndex, typename Metavariables>
auto Random::operator()(Parallel::GlobalCache<Metavariables>& /*cache*/,
const ArrayIndex& array_index) const {
template <typename Metavariables>
auto Random::operator()(
Parallel::GlobalCache<Metavariables>& /*cache*/,
const ElementId<Metavariables::volume_dim>& element_id) const {
constexpr size_t volume_dim = Metavariables::volume_dim;
auto result = make_array<volume_dim>(amr::domain::Flag::Undefined);
const ElementId<volume_dim> element_id{array_index};
for (size_t d = 0; d < volume_dim; ++d) {
result[d] = random_flag(element_id.segment_ids()[d].refinement_level());
}
Expand Down
21 changes: 11 additions & 10 deletions tests/Unit/ParallelAlgorithms/Amr/Criteria/Test_Criterion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "DataStructures/DataBox/DataBox.hpp"
#include "DataStructures/DataBox/ObservationBox.hpp"
#include "Domain/Amr/Flag.hpp"
#include "Domain/Structure/ElementId.hpp"
#include "Framework/TestCreation.hpp"
#include "Framework/TestHelpers.hpp"
#include "Options/Protocols/FactoryCreation.hpp"
Expand Down Expand Up @@ -67,10 +68,10 @@ class CriterionOne : public amr::Criterion {
using compute_tags_for_observartion_box = tmpl::list<>;
using argument_tags = tmpl::list<FieldOne>;

template <typename ArrayIndex, typename Metavariables>
auto operator()(const double field_one,
Parallel::GlobalCache<Metavariables>& /*cache*/,
const ArrayIndex& /*array_index*/) const {
template <typename Metavariables>
auto operator()(
const double field_one, Parallel::GlobalCache<Metavariables>& /*cache*/,
const ElementId<Metavariables::volume_dim>& /*element_id*/) const {
return field_one > critical_value_
? std::array{amr::domain::Flag::Split}
: std::array{amr::domain::Flag::DoNothing};
Expand Down Expand Up @@ -110,10 +111,10 @@ class CriterionTwo : public amr::Criterion {
using compute_tags_for_observartion_box = tmpl::list<ConstraintCompute>;
using argument_tags = tmpl::list<Constraint>;

template <typename ArrayIndex, typename Metavariables>
auto operator()(const double constraint,
Parallel::GlobalCache<Metavariables>& /*cache*/,
const ArrayIndex& /*array_index*/) const {
template <typename Metavariables>
auto operator()(
const double constraint, Parallel::GlobalCache<Metavariables>& /*cache*/,
const ElementId<Metavariables::volume_dim>& /*element_id*/) const {
return std::abs(constraint) > target_value_
? std::array{amr::domain::Flag::Split}
: (std::abs(constraint) < 0.1 * target_value_
Expand Down Expand Up @@ -157,8 +158,8 @@ void test_criterion(const amr::Criterion& criterion, const double field_one,
// we just explicitly list them
using compute_tags = tmpl::list<ConstraintCompute>;
ObservationBox<compute_tags, db::DataBox<simple_tags>> box{databox};
size_t fake_id{0_st};
auto flags = criterion.evaluate(box, empty_cache, fake_id);
ElementId<1> element_id{0};
auto flags = criterion.evaluate(box, empty_cache, element_id);
CHECK(flags == std::array{expected_flag});
}

Expand Down

0 comments on commit 39ae07b

Please sign in to comment.