NEML2 2.0.0
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
TransientDriver.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 <filesystem>
28
29#include "neml2/drivers/ModelDriver.h"
30
31namespace torch::nn
32{
33class ModuleDict;
34}
35
36namespace neml2
37{
43{
44public:
46
47 TransientDriver(const OptionSet & options);
48
49 void setup() override;
50
51 void diagnose() const override;
52
53 bool run() override;
54
55protected:
57 virtual bool solve();
58
59 // @{ Routines that are called every step
61 virtual void advance_step();
63 virtual void update_forces();
65 virtual void apply_ic();
67 virtual void apply_predictor();
69 virtual void solve_step();
71 virtual void store_input();
72 // @}
73
84
87
89 std::vector<ValueMap> _result_in;
91 std::vector<ValueMap> _result_out;
92
94 std::vector<VariableName> _driving_force_names;
95 std::vector<Tensor> _driving_forces;
96
99public:
109 virtual torch::nn::ModuleDict result() const;
111 virtual std::string save_as_path() const;
112
113protected:
115 virtual void output() const;
116
118 std::string _save_as;
119
120private:
122 void output_pt(const std::filesystem::path & out) const;
124};
125} // namespace neml2
Selection of an enum value from a list of candidates.
Definition EnumSelection.h:41
ModelDriver(const OptionSet &options)
Definition ModelDriver.cxx:68
A custom map-like data structure. The keys are strings, and the values can be nonhomogeneously typed.
Definition OptionSet.h:52
Scalar.
Definition Scalar.h:38
const VariableName _time_name
VariableName for the time.
Definition TransientDriver.h:75
std::vector< ValueMap > _result_in
Inputs from all time steps.
Definition TransientDriver.h:89
virtual bool solve()
Solve the initial value problem.
Definition TransientDriver.cxx:220
std::vector< Tensor > _driving_forces
Definition TransientDriver.h:95
virtual void advance_step()
Advance in time: the state becomes old state, and forces become old forces.
Definition TransientDriver.cxx:254
TransientDriver(const OptionSet &options)
Definition TransientDriver.cxx:143
virtual void update_forces()
Update the driving forces for the current time step.
Definition TransientDriver.cxx:274
bool run() override
Let the driver run, return true upon successful completion, and return false otherwise.
Definition TransientDriver.cxx:209
Scalar _time
The current time.
Definition TransientDriver.h:77
virtual std::string save_as_path() const
The destination file/path to save the results.
Definition TransientDriver.cxx:373
virtual void apply_predictor()
Apply the predictor to calculate the initial guess for the current time step.
Definition TransientDriver.cxx:316
virtual void store_input()
Save the input of the current time step.
Definition TransientDriver.cxx:367
const EnumSelection _predictor
The predictor used to set the initial guess.
Definition TransientDriver.h:86
const Size _nsteps
Total number of steps.
Definition TransientDriver.h:81
std::vector< ValueMap > _result_out
Outputs from all time steps.
Definition TransientDriver.h:91
virtual torch::nn::ModuleDict result() const
The results (input and output) from all time steps.
Definition TransientDriver.cxx:379
ValueMap _in
The input to the constitutive model.
Definition TransientDriver.h:83
Size _step_count
The current step count.
Definition TransientDriver.h:79
std::string _save_as
The destination file name or file path.
Definition TransientDriver.h:118
void setup() override
Setup this object.
Definition TransientDriver.cxx:157
virtual void output() const
Save the results into the destination file/path.
Definition TransientDriver.cxx:410
void diagnose() const override
Check for common problems.
Definition TransientDriver.cxx:172
static OptionSet expected_options()
Definition TransientDriver.cxx:104
std::vector< VariableName > _driving_force_names
Driving forces (other than time)
Definition TransientDriver.h:94
virtual void apply_ic()
Apply the initial conditions.
Definition TransientDriver.cxx:284
virtual void solve_step()
Perform the constitutive update for the current time step.
Definition TransientDriver.cxx:352
Definition DiagnosticsInterface.cxx:30
std::map< LabeledAxisAccessor, Tensor > ValueMap
Definition map_types_fwd.h:33
int64_t Size
Definition types.h:69
LabeledAxisAccessor VariableName
Definition LabeledAxisAccessor.h:185
Definition TransientDriver.h:32