NEML2 2.0.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 one-dimensional tensor requires one LabeledAxis, two-dimensional tensor requires two LabeledAxis, and so on. See Model assembly for a detailed explanation of tensor labeling and assembly.

Variables and axes can only be added during the setup stage. Adding items after the setup stage is forbidden and will result in a runtime error in Debug mode.

#include <LabeledAxis.h>

Public Member Functions

 LabeledAxis ()=default
 Empty constructor.
 
 LabeledAxis (LabeledAxisAccessor prefix)
 Sub-axis constructor.
 
bool is_setup () const
 Whether the axis has been set up.
 
LabeledAxisAccessor qualify (const LabeledAxisAccessor &accessor) const
 Return the fully qualified name of an item (i.e. this axis is a sub-axis)
 
LabeledAxisadd_subaxis (const std::string &name)
 Add a sub-axis.
 
void add_variable (const LabeledAxisAccessor &name, Size sz)
 Add a variable with known storage size.
 
template<typename T >
void add_variable (const LabeledAxisAccessor &name)
 Add a variable.
 
void setup_layout ()
 Setup the layout of all items recursively.
 
Size size () const
 Get the storage size of the entire axis.
 
Size size (const LabeledAxisAccessor &name) const
 Get the storage size of a variable or a local sub-axis.
 
indexing::Slice slice (const LabeledAxisAccessor &name) const
 Get the slicing indices of a variable or a local sub-axis.
 
bool equals (const LabeledAxis &other) const
 Check to see if two axes 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
 
std::size_t nvariable () const
 
bool has_variable (const LabeledAxisAccessor &name) const
 Check the existence of a variable by its name.
 
std::size_t variable_id (const LabeledAxisAccessor &name) const
 Get the assembly ID of a variable.
 
const std::vector< LabeledAxisAccessor > & variable_names () const
 Get the variable names.
 
const std::vector< indexing::Slice > & variable_slices () const
 Get the variable slicing indices (in assembly order)
 
const indexing::Slice & variable_slice (const LabeledAxisAccessor &name) const
 Get the slicing indices of a variable by name.
 
const std::vector< Size > & variable_sizes () const
 Get the variable storage sizes (in assembly order)
 
Size variable_size (const LabeledAxisAccessor &name) const
 Get the storage size of a variable by name.
 
std::size_t nsubaxis () const
 
bool has_subaxis (const LabeledAxisAccessor &name) const
 Check the existence of a subaxis by its name.
 
std::size_t subaxis_id (const std::string &name) const
 Get the assembly ID of a sub-axis.
 
const std::vector< const LabeledAxis * > & subaxes () const
 Get the sub-axes (in assembly order)
 
const LabeledAxissubaxis (const LabeledAxisAccessor &name) const
 Get a sub-axis by name.
 
LabeledAxissubaxis (const LabeledAxisAccessor &name)
 Get a sub-axis by name.
 
const std::vector< std::string > & subaxis_names () const
 Get the sub-axis names.
 
const std::vector< indexing::Slice > & subaxis_slices () const
 Get the sub-axis slicing indices (in assembly order)
 
indexing::Slice subaxis_slice (const LabeledAxisAccessor &name) const
 Get the slicing indices of a sub-axis by name.
 
const std::vector< Size > & subaxis_sizes () const
 Get the sub-axis storage sizes (in assembly order)
 
Size subaxis_size (const LabeledAxisAccessor &name) const
 Get the storage size of a sub-axis by name.
 

Friends

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

Constructor & Destructor Documentation

◆ LabeledAxis() [1/2]

LabeledAxis ( )
default

Empty constructor.

◆ LabeledAxis() [2/2]

Sub-axis constructor.

Member Function Documentation

◆ add_subaxis()

LabeledAxis & add_subaxis ( const std::string & name)

Add a sub-axis.

◆ add_variable() [1/2]

template<typename T >
void add_variable ( const LabeledAxisAccessor & name)
inline

Add a variable.

◆ add_variable() [2/2]

void add_variable ( const LabeledAxisAccessor & name,
Size sz )

Add a variable with known storage size.

◆ equals()

bool equals ( const LabeledAxis & other) const

Check to see if two axes are equivalent.

◆ has_forces()

bool has_forces ( ) const
inline

◆ 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 & name) const

Check the existence of a subaxis by its name.

◆ has_variable()

bool has_variable ( const LabeledAxisAccessor & name) const

Check the existence of a variable by its name.

◆ is_setup()

bool is_setup ( ) const
inline

Whether the axis has been set up.

◆ nsubaxis()

std::size_t nsubaxis ( ) const

Get sub-axis information

Number of subaxes

◆ nvariable()

std::size_t nvariable ( ) const

Get variable information

Number of variables

◆ qualify()

LabeledAxisAccessor qualify ( const LabeledAxisAccessor & accessor) const

Return the fully qualified name of an item (i.e. this axis is a sub-axis)

◆ setup_layout()

void setup_layout ( )

Setup the layout of all items recursively.

◆ size() [1/2]

Size size ( ) const

Get the storage size of the entire axis.

◆ size() [2/2]

Size size ( const LabeledAxisAccessor & name) const

Get the storage size of a variable or a local sub-axis.

◆ slice()

indexing::Slice slice ( const LabeledAxisAccessor & name) const

Get the slicing indices of a variable or a local sub-axis.

◆ subaxes()

const std::vector< const LabeledAxis * > & subaxes ( ) const

Get the sub-axes (in assembly order)

◆ subaxis() [1/2]

LabeledAxis & subaxis ( const LabeledAxisAccessor & name)

Get a sub-axis by name.

◆ subaxis() [2/2]

const LabeledAxis & subaxis ( const LabeledAxisAccessor & name) const

Get a sub-axis by name.

◆ subaxis_id()

std::size_t subaxis_id ( const std::string & name) const

Get the assembly ID of a sub-axis.

◆ subaxis_names()

const std::vector< std::string > & subaxis_names ( ) const

Get the sub-axis names.

◆ subaxis_size()

Size subaxis_size ( const LabeledAxisAccessor & name) const

Get the storage size of a sub-axis by name.

◆ subaxis_sizes()

const std::vector< Size > & subaxis_sizes ( ) const

Get the sub-axis storage sizes (in assembly order)

◆ subaxis_slice()

indexing::Slice subaxis_slice ( const LabeledAxisAccessor & name) const

Get the slicing indices of a sub-axis by name.

◆ subaxis_slices()

const std::vector< indexing::Slice > & subaxis_slices ( ) const

Get the sub-axis slicing indices (in assembly order)

◆ variable_id()

std::size_t variable_id ( const LabeledAxisAccessor & name) const

Get the assembly ID of a variable.

◆ variable_names()

const std::vector< LabeledAxisAccessor > & variable_names ( ) const

Get the variable names.

◆ variable_size()

Size variable_size ( const LabeledAxisAccessor & name) const

Get the storage size of a variable by name.

◆ variable_sizes()

const std::vector< Size > & variable_sizes ( ) const

Get the variable storage sizes (in assembly order)

◆ variable_slice()

const indexing::Slice & variable_slice ( const LabeledAxisAccessor & name) const

Get the slicing indices of a variable by name.

◆ variable_slices()

const std::vector< indexing::Slice > & variable_slices ( ) const

Get the variable slicing indices (in assembly order)

Friends And Related Symbol Documentation

◆ operator<<

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