SpECTRE  v2024.04.12
Variables< tmpl::list< Tags... > > Class Template Reference

A Variables holds a contiguous memory block with Tensors pointing into it. More...

#include <Variables.hpp>

Public Types

using size_type = size_t
 
using difference_type = std::ptrdiff_t
 
using tags_list = tmpl::list< Tags... >
 A typelist of the Tags whose variables are held.
 
using vector_type = tmpl::conditional_t< is_any_spin_weighted_v< first_tensors_type >, typename first_tensors_type::value_type, first_tensors_type >
 
using value_type = typename vector_type::value_type
 
using pointer = value_type *
 
using const_pointer = const value_type *
 
using allocator_type = std::allocator< value_type >
 
using pointer_type = blaze::CustomVector< value_type, blaze::AlignmentFlag::unaligned, blaze::PaddingFlag::unpadded, transpose_flag, blaze::GroupTag< 0 >, vector_type >
 

Public Member Functions

 Variables ()
 Default construct an empty Variables class, Charm++ needs this.
 
 Variables (size_t number_of_grid_points)
 
 Variables (size_t number_of_grid_points, value_type value)
 
 Variables (pointer start, size_t size)
 Construct a non-owning Variables that points to start. size is the size of the allocation, which must be number_of_grid_points * Variables::number_of_independent_components
 
 Variables (Variables &&rhs)
 
Variables & operator= (Variables &&rhs)
 
 Variables (const Variables &rhs)
 
Variables & operator= (const Variables &rhs)
 
constexpr size_t number_of_grid_points () const
 
constexpr size_type size () const
 Number of grid points * number of independent components.
 
bool is_owning () const
 Returns true if the class owns the data.
 
void pup (PUP::er &p)
 Serialization for Charm++.
 
template<typename SubsetOfTags >
Variables< SubsetOfTags > extract_subset () const
 Create a Variables from a subset of the Tensors in this Variables.
 
template<typename SubsetOfTags >
Variables< SubsetOfTags > reference_subset () const
 Create a non-owning Variables referencing a subset of the Tensors in this Variables. The referenced tensors must be consecutive in this Variables's tags list. More...
 
template<typename WrappedVariables >
WrappedVariables reference_with_different_prefixes () const
 Create a non-owning version of this Variables with different prefixes on the tensors. Both sets of prefixes must have the same tensor types. More...
 
template<typename VT , bool VF>
 Variables (const blaze::DenseVector< VT, VF > &expression)
 Converting constructor for an expression to a Variables class.
 
template<typename VT , bool VF>
Variables & operator= (const blaze::DenseVector< VT, VF > &expression)
 
template<typename T , typename VectorType , size_t StaticSize>
 Variables (const VectorImpl< T, VectorType, StaticSize > &)=delete
 
template<typename T , typename VectorType , size_t StaticSize>
Variables & operator= (const VectorImpl< T, VectorType, StaticSize > &)=delete
 
template<typename... WrappedTags, Requires< tmpl2::flat_all< std::is_same_v< db::remove_all_prefixes< WrappedTags >, db::remove_all_prefixes< Tags > >... >::value > = nullptr>
Variables & operator+= (const Variables< tmpl::list< WrappedTags... > > &rhs)
 
template<typename VT , bool VF>
Variables & operator+= (const blaze::Vector< VT, VF > &rhs)
 
template<typename... WrappedTags, Requires< tmpl2::flat_all< std::is_same_v< db::remove_all_prefixes< WrappedTags >, db::remove_all_prefixes< Tags > >... >::value > = nullptr>
Variables & operator-= (const Variables< tmpl::list< WrappedTags... > > &rhs)
 
template<typename VT , bool VF>
Variables & operator-= (const blaze::Vector< VT, VF > &rhs)
 
Variables & operator*= (const value_type &rhs)
 
Variables & operator/= (const value_type &rhs)
 
template<typename... WrappedTags, Requires< tmpl2::flat_all< std::is_same< db::remove_all_prefixes< WrappedTags >, db::remove_all_prefixes< Tags > >::value... >::value > = nullptr>
 Variables (Variables< tmpl::list< WrappedTags... > > &&rhs)
 Copy and move semantics for wrapped variables.
 
template<typename... WrappedTags, Requires< tmpl2::flat_all< std::is_same< db::remove_all_prefixes< WrappedTags >, db::remove_all_prefixes< Tags > >::value... >::value > = nullptr>
Variables & operator= (Variables< tmpl::list< WrappedTags... > > &&rhs)
 Copy and move semantics for wrapped variables.
 
template<typename... WrappedTags, Requires< tmpl2::flat_all< std::is_same< db::remove_all_prefixes< WrappedTags >, db::remove_all_prefixes< Tags > >::value... >::value > = nullptr>
 Variables (const Variables< tmpl::list< WrappedTags... > > &rhs)
 Copy and move semantics for wrapped variables.
 
template<typename... WrappedTags, Requires< tmpl2::flat_all< std::is_same< db::remove_all_prefixes< WrappedTags >, db::remove_all_prefixes< Tags > >::value... >::value > = nullptr>
Variables & operator= (const Variables< tmpl::list< WrappedTags... > > &rhs)
 Copy and move semantics for wrapped variables.
 
void initialize (size_t number_of_grid_points)
 Initialize a Variables to the state it would have after calling the constructor with the same arguments.
 
void initialize (size_t number_of_grid_points, value_type value)
 Initialize a Variables to the state it would have after calling the constructor with the same arguments.
 
void set_data_ref (const gsl::not_null< Variables * > rhs)
 Set the VectorImpl to be a reference to another VectorImpl object.
 
void set_data_ref (pointer const start, const size_t size)
 Set the VectorImpl to be a reference to another VectorImpl object.
 
pointer data ()
 Access pointer to underlying data.
 
const_pointer data () const
 Access pointer to underlying data.
 
template<typename... SubsetOfTags>
void assign_subset (const Variables< tmpl::list< SubsetOfTags... > > &vars)
 Assign a subset of the Tensors from another Variables or a tuples::TaggedTuple. Any tags that aren't in both containers are ignored. More...
 
template<typename... SubsetOfTags>
void assign_subset (const tuples::TaggedTuple< SubsetOfTags... > &vars)
 Assign a subset of the Tensors from another Variables or a tuples::TaggedTuple. Any tags that aren't in both containers are ignored. More...
 

Static Public Attributes

static constexpr auto transpose_flag = blaze::defaultTransposeFlag
 
static constexpr auto number_of_variables = sizeof...(Tags)
 The number of variables of the Variables object is holding. E.g. \(\psi_{ab}\) would be counted as one variable.
 
static constexpr size_t number_of_independent_components
 The total number of independent components of all the variables. E.g. a rank-2 symmetric spacetime Tensor \(\psi_{ab}\) in 3 spatial dimensions would have 10 independent components. More...
 

Friends

template<typename Tag , typename TagList >
constexpr Tag::type & get (Variables< TagList > &v)
 Return Tag::type pointing into the contiguous array. More...
 
template<typename Tag , typename TagList >
constexpr const Tag::type & get (const Variables< TagList > &v)
 
template<typename... WrappedTags, Requires< tmpl2::flat_all< std::is_same_v< db::remove_all_prefixes< WrappedTags >, db::remove_all_prefixes< Tags > >... >::value > = nullptr>
decltype(auto) operator+ (const Variables< tmpl::list< WrappedTags... > > &lhs, const Variables &rhs)
 
template<typename VT , bool VF>
decltype(auto) operator+ (const blaze::DenseVector< VT, VF > &lhs, const Variables &rhs)
 
template<typename VT , bool VF>
decltype(auto) operator+ (const Variables &lhs, const blaze::DenseVector< VT, VF > &rhs)
 
template<typename... WrappedTags, Requires< tmpl2::flat_all< std::is_same_v< db::remove_all_prefixes< WrappedTags >, db::remove_all_prefixes< Tags > >... >::value > = nullptr>
decltype(auto) operator- (const Variables< tmpl::list< WrappedTags... > > &lhs, const Variables &rhs)
 
template<typename VT , bool VF>
decltype(auto) operator- (const blaze::DenseVector< VT, VF > &lhs, const Variables &rhs)
 
template<typename VT , bool VF>
decltype(auto) operator- (const Variables &lhs, const blaze::DenseVector< VT, VF > &rhs)
 
decltype(auto) operator* (const Variables &lhs, const value_type &rhs)
 
decltype(auto) operator* (const value_type &lhs, const Variables &rhs)
 
decltype(auto) operator/ (const Variables &lhs, const value_type &rhs)
 
decltype(auto) operator- (const Variables &lhs)
 
decltype(auto) operator+ (const Variables &lhs)
 
bool operator== (const Variables &lhs, const Variables &rhs)
 
template<typename VT , bool TF>
bool operator== (const Variables &lhs, const blaze::DenseVector< VT, TF > &rhs)
 
template<typename VT , bool TF>
bool operator== (const blaze::DenseVector< VT, TF > &lhs, const Variables &rhs)
 

Detailed Description

template<typename... Tags>
class Variables< tmpl::list< Tags... > >

A Variables holds a contiguous memory block with Tensors pointing into it.

The Tags are structs that must have a public type alias type whose value must be a Tensor<DataVector, ...>, a ‘static’ method name() that returns a std::string of the tag name, and must derive off of db::SimpleTag. In general, they should be DataBoxTags that are not compute items. For example,

template <typename VectorType = DataVector>
struct Vector : ::db::SimpleTag {
using type = tnsr::I<VectorType, 3>;
};
Definition: ContractFirstNIndices.hpp:16
Mark a struct as a simple tag by inheriting from this.
Definition: Tag.hpp:36

Prefix tags can also be stored and their format is:

template <class Tag>
struct Prefix0 : ::db::PrefixTag, ::db::SimpleTag {
using type = typename Tag::type;
using tag = Tag;
};
Mark a struct as a prefix tag by inheriting from this.
Definition: Tag.hpp:103

Design Decisions

The Variables class is designed to hold several different Tensors performing one memory allocation for all the Tensors. The advantage is that memory allocations are quite expensive, especially in a parallel environment.

In Debug mode, or if the macro SPECTRE_NAN_INIT is defined, the contents are initialized with NaNs.

Variables stores the data it owns in a std::unique_ptr<double[]> instead of a std::vector because std::vector value-initializes its contents, which is very slow.

Member Function Documentation

◆ assign_subset() [1/2]

template<typename... Tags>
template<typename... SubsetOfTags>
void Variables< tmpl::list< Tags... > >::assign_subset ( const tuples::TaggedTuple< SubsetOfTags... > &  vars)
inline

Assign a subset of the Tensors from another Variables or a tuples::TaggedTuple. Any tags that aren't in both containers are ignored.

Note
There is no need for an rvalue overload because we need to copy into the contiguous array anyway

◆ assign_subset() [2/2]

template<typename... Tags>
template<typename... SubsetOfTags>
void Variables< tmpl::list< Tags... > >::assign_subset ( const Variables< tmpl::list< SubsetOfTags... > > &  vars)
inline

Assign a subset of the Tensors from another Variables or a tuples::TaggedTuple. Any tags that aren't in both containers are ignored.

Note
There is no need for an rvalue overload because we need to copy into the contiguous array anyway

◆ reference_subset()

template<typename... Tags>
template<typename SubsetOfTags >
Variables< SubsetOfTags > Variables< tmpl::list< Tags... > >::reference_subset ( ) const
inline

Create a non-owning Variables referencing a subset of the Tensors in this Variables. The referenced tensors must be consecutive in this Variables's tags list.

Warning
As with other appearances of non-owning variables, this method can cast away constness.

◆ reference_with_different_prefixes()

template<typename... Tags>
template<typename WrappedVariables >
WrappedVariables Variables< tmpl::list< Tags... > >::reference_with_different_prefixes ( ) const
inline

Create a non-owning version of this Variables with different prefixes on the tensors. Both sets of prefixes must have the same tensor types.

Warning
As with other appearances of non-owning variables, this method can cast away constness.

Friends And Related Function Documentation

◆ get

template<typename... Tags>
template<typename Tag , typename TagList >
constexpr Tag::type & get ( Variables< TagList > &  v)
friend

Return Tag::type pointing into the contiguous array.

Template Parameters
Tagthe variable to return

Member Data Documentation

◆ number_of_independent_components

template<typename... Tags>
constexpr size_t Variables< tmpl::list< Tags... > >::number_of_independent_components
staticconstexpr
Initial value:
=
(... + Tags::type::size())

The total number of independent components of all the variables. E.g. a rank-2 symmetric spacetime Tensor \(\psi_{ab}\) in 3 spatial dimensions would have 10 independent components.


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