NEML2 2.1.0
Loading...
Searching...
No Matches
LinearSystem.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/base/LabeledAxisAccessor.h"
28#include "neml2/misc/types.h"
29
30namespace neml2
31{
32struct SparseTensorList;
33
39{
40public:
41 LinearSystem() = default;
42 LinearSystem(const LinearSystem &) = default;
43 LinearSystem(LinearSystem &&) noexcept = default;
44 LinearSystem & operator=(const LinearSystem &) = default;
45 LinearSystem & operator=(LinearSystem &&) noexcept = default;
46 virtual ~LinearSystem() = default;
47
48 virtual void init();
49
51 std::size_t m() const;
53 std::size_t n() const;
55 std::size_t p() const;
56
58 virtual void set_u(const SparseTensorList &) = 0;
60 virtual void set_g(const SparseTensorList &) = 0;
62 virtual SparseTensorList u() const = 0;
64 virtual SparseTensorList g() const = 0;
65
67 virtual void u_changed();
69 virtual void g_changed();
70
81
83 const std::vector<LabeledAxisAccessor> & umap() const;
85 const std::vector<TensorShape> & intmd_ulayout() const;
87 const std::vector<TensorShape> & ulayout() const;
88
90 const std::vector<LabeledAxisAccessor> & gmap() const;
92 const std::vector<TensorShape> & intmd_glayout() const;
94 const std::vector<TensorShape> & glayout() const;
95
97 const std::vector<LabeledAxisAccessor> & bmap() const;
99 const std::vector<TensorShape> & intmd_blayout() const;
101 const std::vector<TensorShape> & blayout() const;
102
103protected:
105 virtual std::vector<LabeledAxisAccessor> setup_umap() = 0;
107 virtual std::vector<TensorShape> setup_intmd_ulayout() = 0;
109 virtual std::vector<TensorShape> setup_ulayout() = 0;
110
112 virtual std::vector<LabeledAxisAccessor> setup_gmap() = 0;
114 virtual std::vector<TensorShape> setup_intmd_glayout() = 0;
116 virtual std::vector<TensorShape> setup_glayout() = 0;
117
119 virtual std::vector<LabeledAxisAccessor> setup_bmap() = 0;
121 virtual std::vector<TensorShape> setup_intmd_blayout() = 0;
123 virtual std::vector<TensorShape> setup_blayout() = 0;
124
133
143 virtual void pre_assemble(bool A, bool B, bool b);
144
155 virtual void post_assemble(bool A, bool B, bool b);
156
158 bool _A_up_to_date = false;
160 bool _B_up_to_date = false;
162 bool _b_up_to_date = false;
163
172 std::optional<std::vector<TensorShape>> _intmd_ulayout;
174 std::vector<TensorShape> _ulayout;
175
183 std::optional<std::vector<TensorShape>> _intmd_glayout;
185 std::vector<TensorShape> _glayout;
186
195 std::optional<std::vector<TensorShape>> _intmd_blayout;
197 std::vector<TensorShape> _blayout;
198
199private:
200};
201
202} // namespace neml2
The accessor containing all the information needed to access an item in a LabeledAxis.
Definition LabeledAxisAccessor.h:56
LinearSystem(const LinearSystem &)=default
SparseTensorList A()
Assemble and return the operator, A.
const std::vector< TensorShape > & blayout() const
Get the ID-to-RHS-base-shape mapping for assembly.
const std::vector< LabeledAxisAccessor > & umap() const
Get the ID-to-unknown mapping for assembly.
std::size_t m() const
Number of rows in the matrix.
std::size_t n() const
Number of columns in the matrix.
std::tuple< SparseTensorList, SparseTensorList, SparseTensorList > A_and_B_and_b()
Assemble the auxiliary matrix B = dr/dg along with A and b.
virtual void post_assemble(bool A, bool B, bool b)
Callback after assembly to perform.
virtual void assemble(SparseTensorList *A, SparseTensorList *B, SparseTensorList *b)=0
Compute the operator and right-hand side.
std::vector< TensorShape > _blayout
ID-to-RHS shape mapping.
Definition LinearSystem.h:197
bool _A_up_to_date
Flag indicating if the system matrix is up to date. Setters invalidate this.
Definition LinearSystem.h:158
const std::vector< TensorShape > & intmd_blayout() const
Get the ID-to-RHS-intermediate-shape mapping for assembly.
std::tuple< SparseTensorList, SparseTensorList > A_and_B()
Assemble the auxiliary matrix B = dr/dg along with A.
virtual std::vector< TensorShape > setup_intmd_blayout()=0
Setup the RHS intermediate layout.
const std::vector< TensorShape > & ulayout() const
Get the ID-to-unknown-base-shape mapping for assembly.
std::vector< LabeledAxisAccessor > _gmap
The ID-to-given-variable mapping.
Definition LinearSystem.h:181
bool _B_up_to_date
Flag indicating if the auxiliary matrix is up to date. Setters invalidate this.
Definition LinearSystem.h:160
std::vector< TensorShape > _ulayout
ID-to-unknown base shape mapping.
Definition LinearSystem.h:174
const std::vector< LabeledAxisAccessor > & bmap() const
Get the ID-to-RHS mapping for assembly.
std::tuple< SparseTensorList, SparseTensorList > A_and_b()
Assemble and return the right-hand side and operator.
virtual std::vector< TensorShape > setup_intmd_ulayout()=0
Setup the unknown intermediate layout.
const std::vector< TensorShape > & intmd_glayout() const
Get the ID-to-prescribed-variable-intermediate-shape mapping for assembly.
virtual SparseTensorList g() const =0
Get the given variables g from the current step.
std::vector< TensorShape > _glayout
ID-to-given base shape mapping.
Definition LinearSystem.h:185
virtual std::vector< TensorShape > setup_blayout()=0
Setup the RHS layout.
virtual void set_g(const SparseTensorList &)=0
Set the given variables g from the current step.
std::vector< LabeledAxisAccessor > _umap
The ID-to-unknown mapping.
Definition LinearSystem.h:170
std::size_t p() const
Number of columns in the auxiliary matrix.
virtual std::vector< LabeledAxisAccessor > setup_gmap()=0
Setup the given variable map.
virtual void init()
SparseTensorList b()
Assemble and return the right-hand side, b.
virtual std::vector< LabeledAxisAccessor > setup_bmap()=0
Setup the RHS map.
virtual std::vector< TensorShape > setup_intmd_glayout()=0
Setup the given variable intermediate layout.
virtual void u_changed()
Trigger when unknown variables changed.
virtual std::vector< LabeledAxisAccessor > setup_umap()=0
Setup the unknown map.
virtual SparseTensorList u() const =0
Get the unknown u.
virtual std::vector< TensorShape > setup_glayout()=0
Setup the given variable base layout.
LinearSystem(LinearSystem &&) noexcept=default
LinearSystem()=default
std::optional< std::vector< TensorShape > > _intmd_ulayout
ID-to-unknown intermediate shape mapping.
Definition LinearSystem.h:172
bool _b_up_to_date
Flag indicating if the system RHS is up to date. Setters invalidate this.
Definition LinearSystem.h:162
const std::vector< TensorShape > & glayout() const
Get the ID-to-prescribed-variable-base-shape mapping for assembly.
virtual void pre_assemble(bool A, bool B, bool b)
Callback before assembly to perform.
virtual void g_changed()
Trigger when given variables changed.
std::optional< std::vector< TensorShape > > _intmd_blayout
ID-to-RHS intermediate shape mapping.
Definition LinearSystem.h:195
virtual void set_u(const SparseTensorList &)=0
Set the unknown u.
const std::vector< LabeledAxisAccessor > & gmap() const
Get the ID-to-prescribed-variable mapping for assembly.
const std::vector< TensorShape > & intmd_ulayout() const
Get the ID-to-unknown-intermediate-shape mapping for assembly.
virtual std::vector< TensorShape > setup_ulayout()=0
Setup the unknown layout.
std::vector< LabeledAxisAccessor > _bmap
The ID-to-RHS mapping.
Definition LinearSystem.h:193
std::optional< std::vector< TensorShape > > _intmd_glayout
ID-to-given intermediate shape mapping.
Definition LinearSystem.h:183
Definition DiagnosticsInterface.h:31
c10::SmallVector< Size, 8 > TensorShape
Definition types.h:72
Alias for a list of Tensors.
Definition SparseTensorList.h:42