NEML2 2.1.0
Loading...
Searching...
No Matches
ModelNonlinearSystem.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/equation_systems/AxisLayout.h"
28#include "neml2/equation_systems/EquationSystem.h"
29#include "neml2/equation_systems/NonlinearSystem.h"
30#include "neml2/models/ParameterStore.h"
31#include "neml2/models/BufferStore.h"
32
33namespace neml2
34{
35class Model;
36
39 public NonlinearSystem,
40 public ParameterStore,
41 public BufferStore
42{
43public:
45
47
48 const std::shared_ptr<Model> & model_ptr() const { return _model; }
49 const Model & model() const { return *_model; }
50 Model & model() { return *_model; }
51
52 void setup() override;
53
54 void to(const TensorOptions &) override;
55
56 void set_u(const AssembledVector &) override;
57 void set_g(const AssembledVector &) override;
58
59 AssembledVector u() const override;
60 AssembledVector g() const override;
61
62protected:
63 std::shared_ptr<AxisLayout> setup_ulayout() override;
64 std::shared_ptr<AxisLayout> setup_glayout() override;
65 std::shared_ptr<AxisLayout> setup_blayout() override;
66
68 void pre_assemble(bool A, bool B, bool b) override;
69 void post_assemble(bool A, bool B, bool b) override;
70
71private:
73 void update_layouts();
75 bool _layouts_updated = false;
76
78 const std::vector<std::vector<VariableName>> _unknown_groups;
80 std::vector<std::vector<VariableName>> _residual_groups;
82 const std::vector<AxisLayout::IStructure> _unknown_istrs;
84 const std::vector<AxisLayout::IStructure> _residual_istrs;
85
86 std::shared_ptr<Model> _model;
87};
88
89} // namespace neml2
BufferStore(NEML2Object *object)
EquationSystem(const OptionSet &options)
AssembledMatrix A()
Assemble and return the operator, A.
AssembledVector b()
Assemble and return the right-hand side, b.
const Model & model() const
Definition ModelNonlinearSystem.h:49
void post_assemble(bool A, bool B, bool b) override
Callback after assembly to perform.
AssembledVector g() const override
Get the given variables g from the current step.
AssembledVector u() const override
Get the unknown u.
std::shared_ptr< AxisLayout > setup_ulayout() override
Setup the unknown layout, partitioned by variable group.
void set_g(const AssembledVector &) override
Set the given variables g from the current step.
void set_u(const AssembledVector &) override
Set the unknown u.
void to(const TensorOptions &) override
Change the device and dtype of the equation system's internal data.
void assemble(AssembledMatrix *A, AssembledMatrix *B, AssembledVector *b) override
Compute the operator and right-hand side.
void setup() override
Setup this object.
std::shared_ptr< AxisLayout > setup_blayout() override
Setup the RHS variable layout.
static OptionSet expected_options()
ModelNonlinearSystem(const OptionSet &options)
void pre_assemble(bool A, bool B, bool b) override
Callback before assembly to perform.
Model & model()
Definition ModelNonlinearSystem.h:50
std::shared_ptr< AxisLayout > setup_glayout() override
Setup the given variable layout.
const std::shared_ptr< Model > & model_ptr() const
Definition ModelNonlinearSystem.h:48
The base class for all constitutive models.
Definition Model.h:82
Definition of a nonlinear system of equations, r(u) = 0.
Definition NonlinearSystem.h:44
A custom map-like data structure. The keys are strings, and the values can be nonhomogeneously typed.
Definition OptionSet.h:54
ParameterStore(NEML2Object *object)
Definition DiagnosticsInterface.h:31
c10::TensorOptions TensorOptions
Definition types.h:66
Dense representation of a matrix assembled from a 2D-list of tensors and their layout.
Definition AssembledMatrix.h:37
Dense representation of a tensor assembled from a list of tensors and their layout.
Definition AssembledVector.h:36