Mark a struct as a compute tag by inheriting from this.
Details
A compute tag is used to identify an item in a DataBox that will be computed on-demand from other items in the DataBox. A compute tag must be derived from a simple tag corresponding to the type of object that is computed. This simple tag can be used to fetch the item corresponding to the compute tag from a DataBox.
A compute tag contains a member named function that is either a static constexpr function pointer, or a static function. The compute tag must also have a a type alias argument_tags that is a typelist of the tags that will be retrieved from the DataBox and whose data will be passed to the function (pointer). Compute tags must also contain a type alias named return_type that is the type the function is mutating. The type must be default constructible.
By convention, the name of a compute tag should be the name of the simple tag that it derives from, appended by Compute.
Derived Class Requires:
- type alias return_type of the type of the item computed
- type alias base that is the simple tag from which it is derived
- member functionthat is either a function pointer, or a static constexpr function that is used to compute the item from the argument_tags fetched from the DataBox
- type alias argument_tags that is a tmpl::list of the tags of the items that will be passed (in order) to the function specified by function
A compute tag may optionally specify a static std::string name() method to override the default name produced by db::tag_name.
- Warning
- A compute tag should only be derived from a simple tag and db::ComputeTag.
Example
Compute tags are of the form:
struct MutateVariablesCompute : MutateVariables, db::ComputeTag {
using base = MutateVariables;
static constexpr auto function = mutate_variables;
using return_type = Variables<
tmpl::list<test_databox_tags::ScalarTag, test_databox_tags::VectorTag>>;
using argument_tags = tmpl::list<Tag0>;
};
where the function is:
void mutate_variables(
const gsl::not_null<Variables<tmpl::list<test_databox_tags::ScalarTag,
test_databox_tags::VectorTag>>*>
t,
if (t->number_of_grid_points() != 10) {
*t = Variables<
tmpl::list<test_databox_tags::ScalarTag, test_databox_tags::VectorTag>>(
10, 0.0);
}
}
}
}
You can also have function be a function instead of a function pointer, which offers a lot of simplicity for very simple compute items.
struct Lambda0 : db::SimpleTag {
using type = double;
};
struct Lambda0Compute : Lambda0, db::ComputeTag {
using base = Lambda0;
using return_type = double;
static constexpr void function(const gsl::not_null<double*> result,
const double a) {
*result = 3.0 * a;
}
using argument_tags = tmpl::list<Tag0>;
};
Note that the arguments can be empty:
struct Lambda1Compute : Lambda1, db::ComputeTag {
using base = Lambda1;
using return_type = double;
static constexpr void function(const gsl::not_null<double*> result) {
*result = 7.0;
}
using argument_tags = tmpl::list<>;
};
- See also
- DataBox SimpleTag