SpECTRE  v2024.09.29
amr::Criterion Class Reference

Base class for something that determines how an adaptive mesh should be changed. More...

#include <Criterion.hpp>

Public Member Functions

 Criterion (CkMigrateMessage *msg)
 
 WRAPPED_PUPable_abstract (Criterion)
 
template<typename ComputeTagsList , typename DataBoxType , typename Metavariables >
auto evaluate (const ObservationBox< ComputeTagsList, DataBoxType > &box, Parallel::GlobalCache< Metavariables > &cache, const ElementId< Metavariables::volume_dim > &element_id) const
 Evaluates the AMR criteria by selecting the appropriate derived class and forwarding its argument_tags from the ObservationBox (along with the GlobalCache and ArrayIndex) to the call operator of the derived class. More...
 

Detailed Description

Base class for something that determines how an adaptive mesh should be changed.

Details

Each class derived from this class should (see the examples below):

  • Be option-creatable
  • Be serializable
  • Define a call operator that returns a std::array<amr::Flag, Dim> containing the recommended refinement choice in each logical dimension of the Element.
  • Define the type aliases argument_tags and compute_tags_for_observation_box that are type lists of tags used in the 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 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

struct FieldOne : db::SimpleTag {
using type = double;
};
struct FieldTwo : db::SimpleTag {
using type = double;
};
struct Constraint : db::SimpleTag {
using type = double;
};
struct ConstraintCompute : db::ComputeTag, Constraint {
using base = Constraint;
using return_type = double;
using argument_tags = tmpl::list<FieldOne, FieldTwo>;
static void function(const gsl::not_null<double*> result,
const double field_one, const double field_two) {
*result = field_one - field_two;
}
};
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
class CriterionOne : public amr::Criterion {
public:
struct CriticalValue {
using type = double;
static constexpr Options::String help = {
"The critical value of field one ."};
};
using options = tmpl::list<CriticalValue>;
static constexpr Options::String help = {
"h-refine the grid if field one is above a critical value"};
CriterionOne() = default;
explicit CriterionOne(const double critical_value)
: critical_value_(critical_value) {}
explicit CriterionOne(CkMigrateMessage* msg) : Criterion(msg) {}
using PUP::able::register_constructor;
WRAPPED_PUPable_decl_template(CriterionOne); // NOLINT
using compute_tags_for_observartion_box = tmpl::list<>;
using argument_tags = tmpl::list<FieldOne>;
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::Flag::Split}
}
void pup(PUP::er& p) override {
Criterion::pup(p);
p | critical_value_;
}
private:
double critical_value_{0.0};
};
PUP::able::PUP_ID CriterionOne::my_PUP_ID = 0; // NOLINT
class CriterionTwo : public amr::Criterion {
public:
struct TargetValue {
using type = double;
static constexpr Options::String help = {"The target value."};
};
using options = tmpl::list<TargetValue>;
static constexpr Options::String help = {
"h-refine if the absolute value of the constraint is above the target "
"value. h-coarsen if the constraint is an order of magnitude below the "
"target value"};
CriterionTwo() = default;
explicit CriterionTwo(const double target_value)
: target_value_(target_value) {}
explicit CriterionTwo(CkMigrateMessage* /*msg*/) {}
using PUP::able::register_constructor;
WRAPPED_PUPable_decl_template(CriterionTwo); // NOLINT
using compute_tags_for_observartion_box = tmpl::list<ConstraintCompute>;
using argument_tags = tmpl::list<Constraint>;
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::abs(constraint) < 0.1 * target_value_
}
void pup(PUP::er& p) override {
Criterion::pup(p);
p | target_value_;
}
private:
double target_value_{0.0};
};
PUP::able::PUP_ID CriterionTwo::my_PUP_ID = 0; // NOLINT
#pragma GCC diagnostic pop
struct Metavariables {
static constexpr size_t volume_dim = 1;
using component_list = tmpl::list<>;
using const_global_cache_tags = tmpl::list<>;
struct factory_creation
: tt::ConformsTo<Options::protocols::FactoryCreation> {
using factory_classes = tmpl::map<
tmpl::pair<amr::Criterion, tmpl::list<CriterionOne, CriterionTwo>>>;
};
};
An ElementId uniquely labels an Element.
Definition: ElementId.hpp:53
A Charm++ chare that caches global data once per Charm++ node.
Definition: GlobalCache.hpp:222
Base class for something that determines how an adaptive mesh should be changed.
Definition: Criterion.hpp:41
Require a pointer to not be a nullptr
Definition: Gsl.hpp:198
@ DoNothing
stay the same
@ Split
split the Element into two smaller elements
@ Join
join the sibling of an Element
#define WRAPPED_PUPable_decl_template(className)
Mark derived classes as serializable.
Definition: CharmPupable.hpp:22
const char *const String
The string used in option structs.
Definition: String.hpp:8
Mark a struct as a compute tag by inheriting from this.
Definition: Tag.hpp:157
Mark a struct as a simple tag by inheriting from this.
Definition: Tag.hpp:36
Indicate a class conforms to the Protocol.
Definition: ProtocolHelpers.hpp:22

Member Function Documentation

◆ evaluate()

template<typename ComputeTagsList , typename DataBoxType , typename Metavariables >
auto amr::Criterion::evaluate ( const ObservationBox< ComputeTagsList, DataBoxType > &  box,
Parallel::GlobalCache< Metavariables > &  cache,
const ElementId< Metavariables::volume_dim > &  element_id 
) const
inline

Evaluates the AMR criteria by selecting the appropriate derived class and forwarding its argument_tags from the ObservationBox (along with the GlobalCache and ArrayIndex) to the call operator of the derived class.

Note
In order to be available, a derived Criterion must be listed in the entry for Criterion in Metavarialbes::factory_creation::factory_classes
The ComputeTagsList of the ObservationBox should contain the union of the tags listed in compute_tags_for_observation_box for each derived Criterion listed in the factory_classes.

The documentation for this class was generated from the following file: