NEML2 1.4.0
Loading...
Searching...
No Matches
NonlinearSystem.h
1// Copyright 2023, UChicago Argonne, LLC
2// All Rights Reserved
3// Software Name: NEML2 -- the New Engineering material Model Library, version 2
4// By: Argonne National Laboratory
5// OPEN SOURCE LICENSE (MIT)
6//
7// Permission is hereby granted, free of charge, to any person obtaining a copy
8// of this software and associated documentation files (the "Software"), to deal
9// in the Software without restriction, including without limitation the rights
10// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11// copies of the Software, and to permit persons to whom the Software is
12// furnished to do so, subject to the following conditions:
13//
14// The above copyright notice and this permission notice shall be included in
15// all copies or substantial portions of the Software.
16//
17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23// THE SOFTWARE.
24
25#pragma once
26
27#include "neml2/tensors/BatchTensor.h"
28#include "neml2/base/OptionSet.h"
29
30namespace neml2
31{
37{
38public:
40
41 static void disable_automatic_scaling(OptionSet & options);
42
43 static void enable_automatic_scaling(OptionSet & options);
44
45 NonlinearSystem(const OptionSet & options);
46
53 virtual void init_scaling(const bool verbose = false);
54
61
63 virtual void set_solution(const BatchTensor & x);
64
66 virtual BatchTensor solution() const { return _solution; }
67
71 void residual();
72
76 void Jacobian();
77
79 std::tuple<BatchTensor, BatchTensor> residual_and_Jacobian(const BatchTensor & x);
82
85
88
89protected:
96 virtual void assemble(bool residual, bool Jacobian) = 0;
97
100
103
106
109
111
113
115 const bool _autoscale;
116
119
121 const unsigned int _autoscale_miter;
122
125
128
131};
132} // namespace neml2
Definition BatchTensor.h:32
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:52
Definition of a nonlinear system of equations.
Definition NonlinearSystem.h:37
static void disable_automatic_scaling(OptionSet &options)
Definition NonlinearSystem.cxx:54
BatchTensor _scaled_residual
Definition NonlinearSystem.h:110
BatchTensor _Jacobian
View for the Jacobian of this nonlinear system.
Definition NonlinearSystem.h:108
static void enable_automatic_scaling(OptionSet &options)
Definition NonlinearSystem.cxx:62
NonlinearSystem(const OptionSet &options)
Definition NonlinearSystem.cxx:69
virtual void set_solution(const BatchTensor &x)
Set the solution vector.
Definition NonlinearSystem.cxx:161
BatchTensor _col_scaling
Column scaling "matrix" – since it's a batched diagonal matrix, we are only storing its diagonals.
Definition NonlinearSystem.h:130
virtual void init_scaling(const bool verbose=false)
Compute algebraic Jacobian-based automatic scaling following https://cs.stanford.edu/people/paulliu/f...
Definition NonlinearSystem.cxx:78
void residual_and_Jacobian()
Convenient shortcut to assemble and return the system residual and Jacobian.
Definition NonlinearSystem.cxx:209
void residual()
Convenient shortcut to assemble and return the system residual.
Definition NonlinearSystem.cxx:175
const BatchTensor & Jacobian_view() const
Definition NonlinearSystem.h:84
BatchTensor _solution
View for the solution of this nonlinear system.
Definition NonlinearSystem.h:102
BatchTensor scale_direction(const BatchTensor &p) const
Remove scaling from the search direction, i.e. .
Definition NonlinearSystem.cxx:151
TorchSize _ndof
Number of degrees of freedom.
Definition NonlinearSystem.h:99
BatchTensor _residual
View for the residual of this nonlinear system.
Definition NonlinearSystem.h:105
const bool _autoscale
If true, do automatic scaling.
Definition NonlinearSystem.h:115
BatchTensor scale_residual(const BatchTensor &r) const
Apply scaling to the residual.
Definition NonlinearSystem.cxx:130
const BatchTensor & residual_view() const
Definition NonlinearSystem.h:83
BatchTensor _row_scaling
Row scaling "matrix" – since it's a batched diagonal matrix, we are only storing its diagonals.
Definition NonlinearSystem.h:127
const unsigned int _autoscale_miter
Maximum number of iterations allowed for the iterative automatic scaling algorithm.
Definition NonlinearSystem.h:121
BatchTensor _scaled_Jacobian
Definition NonlinearSystem.h:112
BatchTensor residual_norm() const
The residual norm.
Definition NonlinearSystem.cxx:221
void Jacobian()
Convenient shortcut to assemble and return the system Jacobian.
Definition NonlinearSystem.cxx:192
static OptionSet expected_options()
Definition NonlinearSystem.cxx:31
const Real _autoscale_tol
Tolerance for convergence check of the iterative automatic scaling algorithm.
Definition NonlinearSystem.h:118
BatchTensor scale_Jacobian(const BatchTensor &J) const
Apply scaling to the Jacobian.
Definition NonlinearSystem.cxx:140
virtual BatchTensor solution() const
Get the solution vector.
Definition NonlinearSystem.h:66
bool _scaling_matrices_initialized
Flag to indicate whether scaling matrices have been computed.
Definition NonlinearSystem.h:124
virtual void assemble(bool residual, bool Jacobian)=0
Compute the residual and Jacobian.
A custom map-like data structure. The keys are strings, and the values can be nonhomogeneously typed.
Definition OptionSet.h:59
Definition CrossRef.cxx:32
double Real
Definition types.h:31