|
NEML2 2.0.0
|
Base class of variable. More...
Base class of variable.
Specific implementations are defined by the derived class Variable<T> where we rely on polymorphism so that we can store different types of variables in the same container.
#include <VariableBase.h>

Public Member Functions | |
| VariableBase ()=default | |
| VariableBase (const VariableBase &)=delete | |
| VariableBase (VariableBase &&)=delete | |
| VariableBase & | operator= (const VariableBase &)=delete |
| VariableBase & | operator= (VariableBase &&)=delete |
| virtual | ~VariableBase ()=default |
| VariableBase (VariableName name_in, Model *owner, TensorShapeRef base_shape, TensorShapeRef dep_intmd_dims) | |
| const VariableName & | name () const |
| Name of this variable. | |
| virtual TensorType | type () const =0 |
| Variable tensor type. | |
| virtual std::unique_ptr< VariableBase > | clone (const VariableName &name={}, Model *owner=nullptr) const =0 |
| Clone this variable. | |
| virtual void | ref (const VariableBase &other, bool ref_is_mutable=false)=0 |
| Reference another variable. | |
| virtual const VariableBase * | ref () const =0 |
| Get the referencing variable (returns this if this is a storing variable) | |
| void | set_intmd_sizes (TensorShapeRef shape) |
| Set the intermediate shape. | |
| ArrayRef< Size > | dep_intmd_dims () const |
| Get dependent intermediate dimensions for derivative calculation. | |
| virtual bool | owning () const =0 |
| Check if this is an owning variable. | |
| Tensor | zeros (const TensorOptions &options) const |
| Make zeros tensor with the shape of this variable. | |
| virtual void | zero (const TensorOptions &options)=0 |
| Set the variable value to zero. | |
| virtual void | set (const Tensor &val, std::optional< TracerPrivilege > key=std::nullopt)=0 |
| Set the variable value from a Tensor in assembly format. | |
| virtual Tensor | get () const =0 |
| Get the variable value in assembly format. | |
| virtual Tensor | tensor () const =0 |
| Get the variable value cast to Tensor. | |
| bool | requires_grad () const |
| Check if this variable is part of the AD function graph. | |
| virtual void | requires_grad_ (bool req=true)=0 |
| Mark this variable as a leaf variable in tracing function graph for AD. | |
| virtual void | operator= (const Tensor &val)=0 |
| Assignment operator. | |
| bool | has_derivative (const VariableName &vname) const |
| Whether the variable has non-zero derivative with respect to another variable. | |
| bool | has_derivative (const VariableName &v1name, const VariableName &v2name) const |
| Whether the variable has non-zero second derivative with respect to another variable. | |
| Derivative< 1 > & | d (const VariableBase &var, ArrayRef< Size > dep_dims={}) |
| Wrapper for assigning partial derivative. | |
| const Derivative< 1 > & | d (const VariableBase &var) const |
| Derivative< 2 > & | d2 (const VariableBase &var1, const VariableBase &var2, ArrayRef< Size > dep_dims={}) |
| Wrapper for assigning second partial derivative. | |
| const Derivative< 2 > & | d2 (const VariableBase &var1, const VariableBase &var2) const |
| const std::vector< Derivative< 1 > > & | derivatives () const |
| Partial derivatives. | |
| std::vector< Derivative< 1 > > & | derivatives () |
| const std::vector< Derivative< 2 > > & | second_derivatives () const |
| Partial second derivatives. | |
| std::vector< Derivative< 2 > > & | second_derivatives () |
| virtual void | clear () |
| Clear the variable value and derivatives. | |
| void | clear_derivatives () |
| Clear only the derivatives. | |
| void | apply_chain_rule (const DependencyResolver< Model, VariableName > &) |
| Apply first order chain rule. | |
| void | apply_second_order_chain_rule (const DependencyResolver< Model, VariableName > &) |
| Apply second order chain rule. | |
| const Model & | owner () const |
| Model & | owner () |
Subaxis | |
| bool | is_state () const |
| bool | is_old_state () const |
| bool | is_force () const |
| bool | is_old_force () const |
| bool | is_residual () const |
| bool | is_parameter () const |
| bool | is_solve_dependent () const |
| bool | is_dependent () const |
| Check if the derivative with respect to this variable should be evaluated. | |
Tensor information | |
| virtual bool | defined () const =0 |
| virtual TensorOptions | options () const =0 |
| Tensor options. | |
| virtual Dtype | scalar_type () const =0 |
| Scalar type. | |
| virtual Device | device () const =0 |
| Device. | |
| Size | dim () const |
| Size | batch_dim () const |
| Size | base_dim () const |
| Size | dynamic_dim () const |
| Size | static_dim () const |
| Size | intmd_dim () const |
| TensorShapeRef | sizes () const |
| TraceableTensorShape | batch_sizes () const |
| TensorShapeRef | base_sizes () const |
| virtual const TraceableTensorShape & | dynamic_sizes () const =0 |
| TensorShapeRef | static_sizes () const |
| TensorShapeRef | intmd_sizes () const |
| Size | size (Size i) const |
| TraceableSize | batch_size (Size i) const |
| Size | base_size (Size i) const |
| const TraceableSize & | dynamic_size (Size i) const |
| Size | static_size (Size i) const |
| Size | intmd_size (Size i) const |
| void | request_AD (const VariableBase &u) |
| void | request_AD (const std::vector< const VariableBase * > &us) |
| void | request_AD (const VariableBase &u1, const VariableBase &u2) |
| void | request_AD (const std::vector< const VariableBase * > &u1s, const std::vector< const VariableBase * > &u2s) |
Public Attributes | |
| const VariableName | _name = {} |
| Name of the variable. | |
| Model *const | _owner = nullptr |
| The model which declared this variable. | |
| TensorShape | _cached_intmd_sizes = {} |
| const TensorShape | _base_sizes = {} |
| Base shape of the variable. | |
| const TensorShape | _dep_intmd_dims = {} |
| Dependent intermediate dimensions for derivative calculation. | |
|
default |
|
delete |
|
delete |
|
virtualdefault |
| VariableBase | ( | VariableName | name_in, |
| Model * | owner, | ||
| TensorShapeRef | base_shape, | ||
| TensorShapeRef | dep_intmd_dims ) |
| void apply_chain_rule | ( | const DependencyResolver< Model, VariableName > & | dep | ) |
Apply first order chain rule.
| void apply_second_order_chain_rule | ( | const DependencyResolver< Model, VariableName > & | dep | ) |
Apply second order chain rule.
| Size base_dim | ( | ) | const |
| TensorShapeRef base_sizes | ( | ) | const |
| Size batch_dim | ( | ) | const |
| TraceableSize batch_size | ( | Size | i | ) | const |
| TraceableTensorShape batch_sizes | ( | ) | const |
|
virtual |
Clear the variable value and derivatives.
Reimplemented in Variable< T >, Variable< neml2::R2 >, Variable< neml2::Rot >, Variable< neml2::Scalar >, Variable< neml2::SR2 >, Variable< neml2::SSR4 >, Variable< neml2::Vec >, and Variable< neml2::WR2 >.
| void clear_derivatives | ( | ) |
Clear only the derivatives.
|
pure virtual |
Clone this variable.
Implemented in Variable< T >, Variable< neml2::R2 >, Variable< neml2::Rot >, Variable< neml2::Scalar >, Variable< neml2::SR2 >, Variable< neml2::SSR4 >, Variable< neml2::Vec >, and Variable< neml2::WR2 >.
| const Derivative< 1 > & d | ( | const VariableBase & | var | ) | const |
| Derivative< 1 > & d | ( | const VariableBase & | var, |
| ArrayRef< Size > | dep_dims = {} ) |
Wrapper for assigning partial derivative.
| const Derivative< 2 > & d2 | ( | const VariableBase & | var1, |
| const VariableBase & | var2 ) const |
| Derivative< 2 > & d2 | ( | const VariableBase & | var1, |
| const VariableBase & | var2, | ||
| ArrayRef< Size > | dep_dims = {} ) |
Wrapper for assigning second partial derivative.
|
pure virtual |
| TensorShapeRef dep_intmd_dims | ( | ) | const |
Get dependent intermediate dimensions for derivative calculation.
|
inline |
|
inline |
Partial derivatives.
|
pure virtual |
| Size dim | ( | ) | const |
| Size dynamic_dim | ( | ) | const |
| const TraceableSize & dynamic_size | ( | Size | i | ) | const |
|
pure virtual |
|
pure virtual |
Get the variable value in assembly format.
Implemented in Variable< T >, Variable< neml2::R2 >, Variable< neml2::Rot >, Variable< neml2::Scalar >, Variable< neml2::SR2 >, Variable< neml2::SSR4 >, Variable< neml2::Vec >, and Variable< neml2::WR2 >.
| bool has_derivative | ( | const VariableName & | v1name, |
| const VariableName & | v2name ) const |
Whether the variable has non-zero second derivative with respect to another variable.
| bool has_derivative | ( | const VariableName & | vname | ) | const |
Whether the variable has non-zero derivative with respect to another variable.
| Size intmd_dim | ( | ) | const |
| TensorShapeRef intmd_sizes | ( | ) | const |
| bool is_dependent | ( | ) | const |
Check if the derivative with respect to this variable should be evaluated.
| bool is_force | ( | ) | const |
| bool is_old_force | ( | ) | const |
| bool is_old_state | ( | ) | const |
| bool is_parameter | ( | ) | const |
| bool is_residual | ( | ) | const |
| bool is_solve_dependent | ( | ) | const |
| bool is_state | ( | ) | const |
|
inline |
Name of this variable.
|
pure virtual |
Assignment operator.
Implemented in Variable< T >, Variable< neml2::R2 >, Variable< neml2::Rot >, Variable< neml2::Scalar >, Variable< neml2::SR2 >, Variable< neml2::SSR4 >, Variable< neml2::Vec >, and Variable< neml2::WR2 >.
|
delete |
|
delete |
|
pure virtual |
Tensor options.
Implemented in Variable< T >, Variable< neml2::R2 >, Variable< neml2::Rot >, Variable< neml2::Scalar >, Variable< neml2::SR2 >, Variable< neml2::SSR4 >, Variable< neml2::Vec >, and Variable< neml2::WR2 >.
| Model & owner | ( | ) |
|
pure virtual |
Check if this is an owning variable.
Implemented in Variable< T >, Variable< neml2::R2 >, Variable< neml2::Rot >, Variable< neml2::Scalar >, Variable< neml2::SR2 >, Variable< neml2::SSR4 >, Variable< neml2::Vec >, and Variable< neml2::WR2 >.
|
pure virtual |
Get the referencing variable (returns this if this is a storing variable)
Implemented in Variable< T >, Variable< neml2::R2 >, Variable< neml2::Rot >, Variable< neml2::Scalar >, Variable< neml2::SR2 >, Variable< neml2::SSR4 >, Variable< neml2::Vec >, and Variable< neml2::WR2 >.
|
pure virtual |
Reference another variable.
Implemented in Variable< T >, Variable< neml2::R2 >, Variable< neml2::Rot >, Variable< neml2::Scalar >, Variable< neml2::SR2 >, Variable< neml2::SSR4 >, Variable< neml2::Vec >, and Variable< neml2::WR2 >.
| void request_AD | ( | const std::vector< const VariableBase * > & | u1s, |
| const std::vector< const VariableBase * > & | u2s ) |
| void request_AD | ( | const std::vector< const VariableBase * > & | us | ) |
| void request_AD | ( | const VariableBase & | u | ) |
Request to use AD to calculate the derivative of this variable with respect to another variable
| void request_AD | ( | const VariableBase & | u1, |
| const VariableBase & | u2 ) |
Request to use AD to calculate the second derivative of this variable with respect to two other variables
| bool requires_grad | ( | ) | const |
Check if this variable is part of the AD function graph.
|
pure virtual |
Mark this variable as a leaf variable in tracing function graph for AD.
Implemented in Variable< T >, Variable< neml2::R2 >, Variable< neml2::Rot >, Variable< neml2::Scalar >, Variable< neml2::SR2 >, Variable< neml2::SSR4 >, Variable< neml2::Vec >, and Variable< neml2::WR2 >.
|
pure virtual |
|
inline |
|
inline |
Partial second derivatives.
|
pure virtual |
Set the variable value from a Tensor in assembly format.
Implemented in Variable< T >, Variable< neml2::R2 >, Variable< neml2::Rot >, Variable< neml2::Scalar >, Variable< neml2::SR2 >, Variable< neml2::SSR4 >, Variable< neml2::Vec >, and Variable< neml2::WR2 >.
| void set_intmd_sizes | ( | TensorShapeRef | shape | ) |
Set the intermediate shape.
| TensorShapeRef sizes | ( | ) | const |
| Size static_dim | ( | ) | const |
| TensorShapeRef static_sizes | ( | ) | const |
|
pure virtual |
Get the variable value cast to Tensor.
Implemented in Variable< T >, Variable< neml2::R2 >, Variable< neml2::Rot >, Variable< neml2::Scalar >, Variable< neml2::SR2 >, Variable< neml2::SSR4 >, Variable< neml2::Vec >, and Variable< neml2::WR2 >.
|
pure virtual |
Variable tensor type.
Implemented in Variable< T >, Variable< neml2::R2 >, Variable< neml2::Rot >, Variable< neml2::Scalar >, Variable< neml2::SR2 >, Variable< neml2::SSR4 >, Variable< neml2::Vec >, and Variable< neml2::WR2 >.
|
pure virtual |
Set the variable value to zero.
Implemented in Variable< T >, Variable< neml2::R2 >, Variable< neml2::Rot >, Variable< neml2::Scalar >, Variable< neml2::SR2 >, Variable< neml2::SSR4 >, Variable< neml2::Vec >, and Variable< neml2::WR2 >.
| Tensor zeros | ( | const TensorOptions & | options | ) | const |
Make zeros tensor with the shape of this variable.
| const TensorShape _base_sizes = {} |
Base shape of the variable.
| TensorShape _cached_intmd_sizes = {} |
Cached intermediate shape that this variable last saw
| const TensorShape _dep_intmd_dims = {} |
Dependent intermediate dimensions for derivative calculation.
| const VariableName _name = {} |
Name of the variable.
| Model* const _owner = nullptr |
The model which declared this variable.