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 torch::TensorOptions &options)=0 |
Set the variable value to zero. | |
virtual void | set (const Tensor &val)=0 |
Set the variable value. | |
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 | 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 | |
torch::TensorOptions | options () const |
torch::Dtype | scalar_type () const |
Scalar type. | |
torch::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.
|
inline |
Assembly storage of the variable.
|
inline |
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::WR2 >, Variable< Scalar >, and Variable< SSR4 >.
|
inline |
Base storage of the variable.
|
inline |
Return the number of batch dimensions.
|
inline |
Return the size of a batch axis.
|
inline |
Return the batch shape.
|
inline |
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::WR2 >, Variable< Scalar >, and Variable< SSR4 >.
|
pure virtual |
Clone this variable.
Implemented in Variable< T >, Variable< neml2::R2 >, Variable< neml2::Rot >, Variable< neml2::Scalar >, Variable< neml2::SR2 >, Variable< neml2::WR2 >, Variable< Scalar >, and Variable< SSR4 >.
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 |
Device.
|
inline |
Number of tensor dimensions.
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::WR2 >, Variable< Scalar >, and Variable< SSR4 >.
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 |
Return the number of list dimensions.
|
inline |
Return the list shape.
|
inline |
Name of this variable.
Assignment operator.
Implemented in Variable< T >, Variable< neml2::R2 >, Variable< neml2::Rot >, Variable< neml2::Scalar >, Variable< neml2::SR2 >, Variable< neml2::WR2 >, Variable< Scalar >, and Variable< SSR4 >.
|
delete |
|
delete |
|
inline |
Tensor options
Model & owner | ( | ) |
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::WR2 >, Variable< Scalar >, and Variable< SSR4 >.
|
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::WR2 >, Variable< Scalar >, and Variable< SSR4 >.
Reference another variable.
Implemented in Variable< T >, Variable< neml2::R2 >, Variable< neml2::Rot >, Variable< neml2::Scalar >, Variable< neml2::SR2 >, Variable< neml2::WR2 >, Variable< Scalar >, and Variable< SSR4 >.
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
|
inline |
Check if this variable is part of the AD function graph.
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::WR2 >, Variable< Scalar >, and Variable< SSR4 >.
|
inline |
Scalar type.
|
inline |
Set the variable value.
Implemented in Variable< T >, Variable< neml2::R2 >, Variable< neml2::Rot >, Variable< neml2::Scalar >, Variable< neml2::SR2 >, Variable< neml2::WR2 >, Variable< Scalar >, and Variable< SSR4 >.
|
inline |
Tensor shape.
Get the variable value.
Implemented in Variable< T >, Variable< neml2::R2 >, Variable< neml2::Rot >, Variable< neml2::Scalar >, Variable< neml2::SR2 >, Variable< neml2::WR2 >, Variable< Scalar >, and Variable< SSR4 >.
|
pure virtual |
Variable tensor type.
Implemented in Variable< T >, Variable< neml2::R2 >, Variable< neml2::Rot >, Variable< neml2::Scalar >, Variable< neml2::SR2 >, Variable< neml2::WR2 >, Variable< Scalar >, and Variable< SSR4 >.
Set the variable value to zero.
Implemented in Variable< T >, Variable< neml2::R2 >, Variable< neml2::Rot >, Variable< neml2::Scalar >, Variable< neml2::SR2 >, Variable< neml2::WR2 >, Variable< Scalar >, and Variable< SSR4 >.
const VariableName _name = {} |
Name of the variable.