NEML2 2.1.0
Loading...
Searching...
No Matches
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 solve_step();
69 virtual void postprocess();
70 // @}
71
80
82 std::vector<ValueMap> _result_in;
84 std::vector<ValueMap> _result_out;
85
87 std::vector<VariableName> _driving_force_names;
88 std::vector<Tensor> _driving_forces;
89
92public:
102 virtual torch::nn::ModuleDict result() const;
104 virtual std::string save_as_path() const;
105
106protected:
108 virtual void output() const;
109
111 std::string _save_as;
112
113private:
115 void output_pt(const std::filesystem::path & out) const;
117};
118} // namespace neml2
ModelDriver(const OptionSet &options)
A custom map-like data structure. The keys are strings, and the values can be nonhomogeneously typed.
Definition OptionSet.h:54
Scalar.
Definition Scalar.h:38
const VariableName _time_name
VariableName for the time.
Definition TransientDriver.h:73
std::vector< ValueMap > _result_in
Inputs from all time steps.
Definition TransientDriver.h:82
virtual void postprocess()
Postprocess the output of the current time step.
std::vector< Tensor > _driving_forces
Definition TransientDriver.h:88
virtual void apply_ic()
Apply the initial conditions.
TransientDriver(const OptionSet &options)
bool run() override
Let the driver run, return true upon successful completion, and return false otherwise.
Scalar _time
The current time.
Definition TransientDriver.h:75
virtual void output() const
Save the results into the destination file/path.
virtual torch::nn::ModuleDict result() const
The results (input and output) from all time steps.
virtual void update_forces()
Update the driving forces for the current time step.
virtual void solve_step()
Perform the constitutive update for the current time step.
const Size _nsteps
Total number of steps.
Definition TransientDriver.h:79
std::vector< ValueMap > _result_out
Outputs from all time steps.
Definition TransientDriver.h:84
Size _step_count
The current step count.
Definition TransientDriver.h:77
std::string _save_as
The destination file name or file path.
Definition TransientDriver.h:111
virtual std::string save_as_path() const
The destination file/path to save the results.
void setup() override
Setup this object.
void diagnose() const override
Check for common problems.
static OptionSet expected_options()
virtual void advance_step()
Advance in time: the state becomes old state, and forces become old forces.
std::vector< VariableName > _driving_force_names
Driving forces (other than time).
Definition TransientDriver.h:87
virtual bool solve()
Solve the initial value problem.
Definition DiagnosticsInterface.h:31
int64_t Size
Definition types.h:71
std::string VariableName
Definition types.h:75
Definition TransientDriver.h:32