NEML2 1.4.0
Loading...
Searching...
No Matches
NonlinearSystem.h
1// Copyright 2024, 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/Tensor.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
56 Tensor scale_residual(const Tensor & r) const;
58 Tensor scale_Jacobian(const Tensor & J) const;
60 Tensor scale_direction(const Tensor & p) const;
61
63 virtual void set_solution(const Tensor & x);
64
66 virtual Tensor solution() const { return _solution; }
67
69 Tensor residual(const Tensor & x);
71 void residual();
72
74 Tensor Jacobian(const Tensor & x);
76 void Jacobian();
77
79 std::tuple<Tensor, Tensor> residual_and_Jacobian(const Tensor & x);
82
83 const Tensor & get_residual() const { return _scaled_residual; }
84 const Tensor & get_Jacobian() const { return _scaled_Jacobian; }
85
87 Tensor residual_norm() const;
88
90 virtual bool is_AD_enabled() const { return true; }
92 virtual bool is_AD_disabled() const final { return !is_AD_enabled(); }
93
94protected:
101 virtual void assemble(bool residual, bool Jacobian) = 0;
102
105
108
111
114
116
118
120 const bool _autoscale;
121
124
126 const unsigned int _autoscale_miter;
127
130
133
136};
137} // namespace neml2
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:56
Definition of a nonlinear system of equations.
Definition NonlinearSystem.h:37
Tensor _row_scaling
Row scaling "matrix" – since it's a batched diagonal matrix, we are only storing its diagonals.
Definition NonlinearSystem.h:132
static void disable_automatic_scaling(OptionSet &options)
Definition NonlinearSystem.cxx:54
virtual void set_solution(const Tensor &x)
Set the solution vector.
Definition NonlinearSystem.cxx:160
Tensor _scaled_Jacobian
Definition NonlinearSystem.h:117
Tensor _residual
View for the residual of this nonlinear system.
Definition NonlinearSystem.h:110
static void enable_automatic_scaling(OptionSet &options)
Definition NonlinearSystem.cxx:62
virtual bool is_AD_disabled() const final
Whether AD is disabled.
Definition NonlinearSystem.h:92
NonlinearSystem(const OptionSet &options)
Definition NonlinearSystem.cxx:69
virtual bool is_AD_enabled() const
Whether AD is enabled.
Definition NonlinearSystem.h:90
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:79
void residual_and_Jacobian()
Convenient shortcut to assemble and return the system residual and Jacobian.
Definition NonlinearSystem.cxx:206
Tensor _scaled_residual
Definition NonlinearSystem.h:115
const Tensor & get_residual() const
Definition NonlinearSystem.h:83
Tensor scale_Jacobian(const Tensor &J) const
Apply scaling to the Jacobian.
Definition NonlinearSystem.cxx:139
void residual()
Convenient shortcut to assemble and return the system residual.
Definition NonlinearSystem.cxx:174
Tensor scale_residual(const Tensor &r) const
Apply scaling to the residual.
Definition NonlinearSystem.cxx:129
Size _ndof
Number of degrees of freedom.
Definition NonlinearSystem.h:104
Tensor _col_scaling
Column scaling "matrix" – since it's a batched diagonal matrix, we are only storing its diagonals.
Definition NonlinearSystem.h:135
Tensor _solution
View for the solution of this nonlinear system.
Definition NonlinearSystem.h:107
const bool _autoscale
If true, do automatic scaling.
Definition NonlinearSystem.h:120
const unsigned int _autoscale_miter
Maximum number of iterations allowed for the iterative automatic scaling algorithm.
Definition NonlinearSystem.h:126
void Jacobian()
Convenient shortcut to assemble and return the system Jacobian.
Definition NonlinearSystem.cxx:190
static OptionSet expected_options()
Definition NonlinearSystem.cxx:31
Tensor scale_direction(const Tensor &p) const
Remove scaling from the search direction, i.e. .
Definition NonlinearSystem.cxx:150
const Tensor & get_Jacobian() const
Definition NonlinearSystem.h:84
Tensor _Jacobian
View for the Jacobian of this nonlinear system.
Definition NonlinearSystem.h:113
const Real _autoscale_tol
Tolerance for convergence check of the iterative automatic scaling algorithm.
Definition NonlinearSystem.h:123
Tensor residual_norm() const
The residual norm.
Definition NonlinearSystem.cxx:215
bool _scaling_matrices_initialized
Flag to indicate whether scaling matrices have been computed.
Definition NonlinearSystem.h:129
virtual void assemble(bool residual, bool Jacobian)=0
Compute the residual and Jacobian.
virtual Tensor solution() const
Get the solution vector.
Definition NonlinearSystem.h:66
A custom map-like data structure. The keys are strings, and the values can be nonhomogeneously typed.
Definition OptionSet.h:100
Definition Tensor.h:32
Definition CrossRef.cxx:30
double Real
Definition types.h:31