One of the most notable differences between constitutive models and feed-forward neural networks is that updating certain stiff systems with implicit methods is often more computationally efficient compared to explicit algorithms.
A generally nonlinear, recursive, implicit system of equations take the following form
Here represents the residual (for root-fiding) of the system of equations, and , , , are defined by four reserved sub-axes in NEML2:
The state sub-axis hosts input variables in set . The variables on this sub-axis are the primary unknowns to be solved for.
The forces sub-axis hosts prescribed input variables in set . These variables are prescribed and, by definition, do not change while the system is being solved.
The old_state and old_forces sub-axes respectively correspond to and . These variables correspond to the previous solution to the system to facilitate the recursive definition of internal variables in history-dependent models. The equivalent plastic strain in plasticity models is a well-known example.
The Perzyna viscoplasticity model mentioned in a previous tutorial takes this form:
Its residual can be defined using backward-Euler time integration as
the solution procedure of which is often referred to as the return-mapping algorithm in the solid mechanics community.
This tutorial illustrates the use of ImplicitUpdate in conjunction with a Newton-Raphson solver to perform the implicit update.
Defining the system of equations
After searching among existing models provided by NEML2, we are able to translate each of these equations into a NEML2 model. The input file looks like
Once the system of equations are properly defined, we can use the ImplicitUpdate to solve the system of equations. The ImplicitUpdate is responsible for the following:
(Re)declare the solution to the system of equations as output variables.
Validate the shape of input variables and residual variables to make sure the system is square.
Assemble the residual vector and Jacobian matrix of the underlying linear system.
Invoke a solver to solve the system of equations.
Apply the implicit function theorem to calculate exact derivatives (up to machine precision).
NEML2 offers three fully vectorized Newton solvers to be used in conjunction with ImplicitUpdate:
Newton, the (vectorized) vanilla version of the Newton-Raphson algorithm which always takes the "full" step.
NewtonWithLineSearch, similar to Newton but offers several commonly used (again fully vectorized) line search strategies.
NewtonWithTrustRegion, the trust-region variant of the Newton-Raphson algorithm, where a scalar-valued, fully vectorized quadratic sub-problem is solved to identify the search direction in each update.
In addition, the assembly routines as well as the application of the implicit function theorem are also implemented in a vectorized fashion.
The resulting input file looks like
[Models]
# ...
# Other models defining the system of equations
# ...
[system]
type = ComposedModel
models = 'eq1 eq2 surface eq5 eq6 eq7 eq8'
[]
[model]
type = ImplicitUpdate
implicit_model = 'system'
solver = 'newton'
[]
[]
[Solvers]
[newton]
type = Newton
rel_tol = 1e-08
abs_tol = 1e-10
max_its = 50
verbose = true
[]
[]
The ImplicitUpdate model can then be invoked in the same way as regular models.
Unlike other regular models, declaring variables on the correct sub-axes is important because NEML2 relies on the reserved sub-axes (state, forces, etc.)
To determine whether the variable value and derivatives should be calculated during the assembly of residual and Jacobian. For example, the derivatives with respect to all variables on the forces sub-axis are skipped because they are not required in the assembly of the linear system.
To efficiently reuse the factorization of the system Jacobian when applying the implicit function theorem.
As long as models are defined using the correct sub-axis definitions and satisfy some mild continuity requirements, NEML2 guarantees the correctness of the variable derivatives after one or more implicit updates, up to machine precision. The same guarantee also applies to user-defined custom models.
This is a significant advantage compared to some of the alternative constitutive model libraries, especially in the context of coupling with external PDE solvers. For example, in the context of finite element method, thermodynamic forces (e.g. strain) are calculated at each quadrature point, and the constitutive library (e.g. NEML2) is responsible for updating the thermodynamic state variables (e.g. stress, plastic strain, etc.), which are then used in the residual definition of the discretized PDE. Therefore, the exact derivatives of the state variables with respect to the forces are the key to the assembly of the exact Jacobian of the descretized PDE, which is in turn the fundamental requirement for optimal convergence for many nonlinear solvers.