|
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 <Variable.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 list_shape) | |
| 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) | |
| virtual bool | owning () const =0 |
| Check if this is an owning variable. | |
| virtual void | zero (const TensorOptions &options)=0 |
| Set the variable value to zero. | |
| virtual void | set (const Tensor &val)=0 |
| Set the variable value. | |
| virtual void | set (const ATensor &val, bool force=false)=0 |
| virtual Tensor | get () const =0 |
| Get the variable value (with flattened base dimensions, i.e., for assembly purposes) | |
| virtual Tensor | tensor () const =0 |
| Get the variable value. | |
| 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. | |
| Derivative | d (const VariableBase &var) |
| Wrapper for assigning partial derivative. | |
| Derivative | d (const VariableBase &var1, const VariableBase &var2) |
| Wrapper for assigning second partial derivative. | |
| const ValueMap & | derivatives () const |
| Partial derivatives. | |
| ValueMap & | derivatives () |
| const DerivMap & | second_derivatives () const |
| Partial second derivatives. | |
| DerivMap & | 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 | |
| TensorOptions | options () const |
| Dtype | scalar_type () const |
| Scalar type. | |
| Device | device () const |
| Device. | |
| Size | dim () const |
| Number of tensor dimensions. | |
| TensorShapeRef | sizes () const |
| Tensor shape. | |
| Size | size (Size dim) const |
| Size of a dimension. | |
| bool | batched () const |
| Whether the tensor is batched. | |
| Size | batch_dim () const |
| Return the number of batch dimensions. | |
| Size | list_dim () const |
| Return the number of list dimensions. | |
| Size | base_dim () const |
| Return the number of base dimensions. | |
| TraceableTensorShape | batch_sizes () const |
| Return the batch shape. | |
| TensorShapeRef | list_sizes () const |
| Return the list shape. | |
| virtual TensorShapeRef | base_sizes () const =0 |
| Return the base shape. | |
| TraceableSize | batch_size (Size dim) const |
| Return the size of a batch axis. | |
| Size | base_size (Size dim) const |
| Return the size of a base axis. | |
| Size | list_size (Size dim) const |
| Return the size of a list axis. | |
| Size | base_storage () const |
| Base storage of the variable. | |
| Size | assembly_storage () const |
| Assembly storage of the variable. | |
| 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. | |
|
default |
|
delete |
|
delete |
|
virtualdefault |
| VariableBase | ( | VariableName | name_in, |
| Model * | owner, | ||
| TensorShapeRef | list_shape ) |
| 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 assembly_storage | ( | ) | const |
Assembly storage of the variable.
| Size base_dim | ( | ) | const |
Return the number of base dimensions.
|
pure virtual |
Return the base shape.
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 >.
| Size base_storage | ( | ) | const |
Base storage of the variable.
| Size batch_dim | ( | ) | const |
Return the number of batch dimensions.
| TraceableSize batch_size | ( | Size | dim | ) | const |
Return the size of a batch axis.
| TraceableTensorShape batch_sizes | ( | ) | const |
Return the batch shape.
| bool batched | ( | ) | const |
Whether the tensor is batched.
|
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 >.
| Derivative d | ( | const VariableBase & | var | ) |
Wrapper for assigning partial derivative.
| Derivative d | ( | const VariableBase & | var1, |
| const VariableBase & | var2 ) |
Wrapper for assigning second partial derivative.
|
inline |
|
inline |
Partial derivatives.
| Device device | ( | ) | const |
Device.
| Size dim | ( | ) | const |
Number of tensor dimensions.
|
pure virtual |
Get the variable value (with flattened base dimensions, i.e., for assembly purposes)
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 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 |
| Size list_dim | ( | ) | const |
Return the number of list dimensions.
| TensorShapeRef list_sizes | ( | ) | const |
Return the list shape.
|
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 |
| TensorOptions options | ( | ) | const |
Tensor options
| 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 >.
|
inline |
|
inline |
Partial second derivatives.
|
pure virtual |
Set the variable value from a ATensor (with inferred batch shape) If force is true, the value is set even if the variable is a reference
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.
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 >.
| TensorShapeRef sizes | ( | ) | const |
Tensor shape.
|
pure virtual |
Get the variable value.
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 >.
| const VariableName _name = {} |
Name of the variable.
| Model* const _owner = nullptr |
The model which declared this variable.