NEML2 1.4.0
Loading...
Searching...
No Matches
LabeledAxis Class Reference

A labeled axis used to associate layout of a tensor with human-interpretable names. More...

Detailed Description

A labeled axis used to associate layout of a tensor with human-interpretable names.

A logically one-dimensional tensor requires one LabeledAxis, two-dimensional tensor requires two LabeledAxis, and so on. See Tensor labeling for a detailed explanation of tensor labeling.

All the LabeledAxis modifiers can only be used during the setup stage. Calling any modifiers after the setup stage is forbidden and will result in a runtime error in Debug mode.

All the modifiers return the modified LabeledAxis by reference, so modifiers can be chained. For example

LabeledAxis labels = input().clone();
labels.add<SR2>("stress").rename("stress", "stress1").remove("stress1");
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:56
A labeled axis used to associate layout of a tensor with human-interpretable names.
Definition LabeledAxis.h:55
The (logical) symmetric second order tensor.
Definition SR2.h:46

#include <LabeledAxis.h>

Classes

struct  AssemblySliceCmp
 

Public Types

typedef std::unordered_map< std::string, std::pair< Size, Size > > AxisLayout
 

Public Member Functions

 LabeledAxis ()
 Empty constructor.
 
 LabeledAxis (const LabeledAxis &other)
 (Shallow) copy constructor
 
template<typename T >
LabeledAxisadd (const LabeledAxisAccessor &accessor)
 Add a variable or subaxis.
 
LabeledAxisadd (const LabeledAxisAccessor &accessor, Size sz)
 Add an arbitrary variable using a LabeledAxisAccessor
 
void clear ()
 Clear all internal data.
 
void setup_layout ()
 
size_t nvariable (bool recursive=true) const
 Number of variables.
 
size_t nsubaxis (bool recursive=false) const
 Number of subaxes.
 
bool has_item (const LabeledAxisAccessor &name) const
 Does the item exist?
 
template<typename T >
bool has_variable (const LabeledAxisAccessor &var) const
 Does the variable of a given primitive type exist?
 
bool has_variable (const LabeledAxisAccessor &var) const
 Check the existence of a variable by its LabeledAxisAccessor.
 
bool has_subaxis (const LabeledAxisAccessor &s) const
 Check the existence of a subaxis by its LabeledAxisAccessor.
 
Size storage_size (const LabeledAxisAccessor &name={}) const
 Get the total storage size of this axis or the storage size of an item.
 
const AxisLayoutlayout () const
 Get the layout.
 
indexing::TensorIndex indices (const LabeledAxisAccessor &accessor) const
 Get the indices of a specific item by a LabeledAxisAccessor
 
std::vector< std::pair< indexing::TensorIndex, indexing::TensorIndex > > common_indices (const LabeledAxis &other, bool recursive=true) const
 Get the common indices of two LabeledAxiss.
 
std::vector< LabeledAxisAccessorsort_by_assembly_order (const std::set< LabeledAxisAccessor > &) const
 Sort a set of LabeledAxisAccessors by their indices.
 
const std::map< std::string, Size > & variables () const
 Get the variables.
 
std::set< LabeledAxisAccessorvariable_names (bool recursive=true) const
 Get the variable names.
 
const std::map< std::string, std::shared_ptr< LabeledAxis > > & subaxes () const
 Get the subaxes.
 
std::set< LabeledAxisAccessorsubaxis_names (bool recursive=false) const
 Get subaxes' names.
 
const LabeledAxissubaxis (const LabeledAxisAccessor &name) const
 Get a sub-axis.
 
LabeledAxissubaxis (const LabeledAxisAccessor &name)
 Get a sub-axis.
 
bool equals (const LabeledAxis &other) const
 Check to see if two LabeledAxis objects are equivalent.
 
bool has_state () const
 
bool has_old_state () const
 
bool has_forces () const
 
bool has_old_forces () const
 
bool has_residual () const
 
bool has_parameters () const
 

Friends

std::ostream & operator<< (std::ostream &os, const LabeledAxis &axis)
 

Member Typedef Documentation

◆ AxisLayout

typedef std::unordered_map<std::string, std::pair<Size, Size> > AxisLayout

Constructor & Destructor Documentation

◆ LabeledAxis() [1/2]

Empty constructor.

◆ LabeledAxis() [2/2]

(Shallow) copy constructor

Member Function Documentation

◆ add() [1/2]

template<typename T >
LabeledAxis & add ( const LabeledAxisAccessor & accessor)
inline

Add a variable or subaxis.

◆ add() [2/2]

LabeledAxis & add ( const LabeledAxisAccessor & accessor,
Size sz )

Add an arbitrary variable using a LabeledAxisAccessor

◆ clear()

void clear ( )

Clear all internal data.

◆ common_indices()

std::vector< std::pair< indexing::TensorIndex, indexing::TensorIndex > > common_indices ( const LabeledAxis & other,
bool recursive = true ) const

Get the common indices of two LabeledAxiss.

◆ equals()

bool equals ( const LabeledAxis & other) const

Check to see if two LabeledAxis objects are equivalent.

◆ has_forces()

bool has_forces ( ) const
inline

◆ has_item()

bool has_item ( const LabeledAxisAccessor & name) const
inline

Does the item exist?

◆ has_old_forces()

bool has_old_forces ( ) const
inline

◆ has_old_state()

bool has_old_state ( ) const
inline

◆ has_parameters()

bool has_parameters ( ) const
inline

◆ has_residual()

bool has_residual ( ) const
inline

◆ has_state()

bool has_state ( ) const
inline

Check the existence of reserved subaxes

◆ has_subaxis()

bool has_subaxis ( const LabeledAxisAccessor & s) const

Check the existence of a subaxis by its LabeledAxisAccessor.

◆ has_variable() [1/2]

template<typename T >
bool has_variable ( const LabeledAxisAccessor & var) const
inline

Does the variable of a given primitive type exist?

◆ has_variable() [2/2]

bool has_variable ( const LabeledAxisAccessor & var) const

Check the existence of a variable by its LabeledAxisAccessor.

◆ indices()

indexing::TensorIndex indices ( const LabeledAxisAccessor & accessor) const

Get the indices of a specific item by a LabeledAxisAccessor

◆ layout()

const AxisLayout & layout ( ) const
inline

Get the layout.

◆ nsubaxis()

size_t nsubaxis ( bool recursive = false) const

Number of subaxes.

◆ nvariable()

size_t nvariable ( bool recursive = true) const

Number of variables.

◆ setup_layout()

void setup_layout ( )

Setup the layout of all items recursively. The layout of each item is contiguous in memory.

◆ sort_by_assembly_order()

std::vector< LabeledAxisAccessor > sort_by_assembly_order ( const std::set< LabeledAxisAccessor > & names) const

Sort a set of LabeledAxisAccessors by their indices.

◆ storage_size()

Size storage_size ( const LabeledAxisAccessor & name = {}) const

Get the total storage size of this axis or the storage size of an item.

◆ subaxes()

const std::map< std::string, std::shared_ptr< LabeledAxis > > & subaxes ( ) const
inline

Get the subaxes.

◆ subaxis() [1/2]

LabeledAxis & subaxis ( const LabeledAxisAccessor & name)

Get a sub-axis.

◆ subaxis() [2/2]

const LabeledAxis & subaxis ( const LabeledAxisAccessor & name) const

Get a sub-axis.

◆ subaxis_names()

std::set< LabeledAxisAccessor > subaxis_names ( bool recursive = false) const

Get subaxes' names.

◆ variable_names()

std::set< LabeledAxisAccessor > variable_names ( bool recursive = true) const

Get the variable names.

◆ variables()

const std::map< std::string, Size > & variables ( ) const
inline

Get the variables.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
const LabeledAxis & axis )
friend