db::ComputeTag Struct Reference

Mark a struct as a compute tag by inheriting from this. More...

#include <Tag.hpp>

Detailed Description

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:

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,
const double value) {
if (t->number_of_grid_points() != 10) {
*t = Variables<
tmpl::list<test_databox_tags::ScalarTag, test_databox_tags::VectorTag>>(
10, 0.0);
}
for (auto& p : get<test_databox_tags::ScalarTag>(*t)) {
p = 2.0 * value;
}
for (auto& p : get<test_databox_tags::VectorTag>(*t)) {
p = 3.0 * value;
}
}

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

The documentation for this struct was generated from the following file:
db::ComputeTag
Mark a struct as a compute tag by inheriting from this.
Definition: Tag.hpp:157
db::SimpleTag
Mark a struct as a simple tag by inheriting from this.
Definition: Tag.hpp:36
gsl::not_null
Require a pointer to not be a nullptr
Definition: Gsl.hpp:183