Smith  0.1
Smith is an implicit thermal structural mechanics simulation code.
time_integration_rule.hpp
Go to the documentation of this file.
1 // Copyright (c) Lawrence Livermore National Security, LLC and
2 // other Smith Project Developers. See the top-level LICENSE file for
3 // details.
4 //
5 // SPDX-License-Identifier: (BSD-3-Clause)
6 
14 #pragma once
15 
16 #include <tuple>
17 #include "smith/physics/common.hpp"
19 
20 namespace smith {
21 
24  public:
26  virtual ~TimeIntegrationRule() {}
27 
29  virtual bool requiresInitialAccelerationSolve() const { return false; }
30 
33  virtual FieldState corrected_value(const TimeInfo& t, const std::vector<FieldState>& states) const = 0;
34 
36  virtual int num_args() const = 0;
37 
40  virtual FieldState corrected_dot(const TimeInfo& t, const std::vector<FieldState>& states) const = 0;
41 
44  virtual FieldState corrected_ddot(const TimeInfo& t, const std::vector<FieldState>& states) const = 0;
45 };
46 
52  public:
53  static constexpr int num_states = 2;
54 
57 
59  int num_args() const override { return num_states; }
60 
62  template <typename T1, typename T2>
63  SMITH_HOST_DEVICE auto value(const TimeInfo& /*t*/, const T1& field_new, const T2& /*field_old*/) const
64  {
65  return field_new;
66  }
67 
69  template <typename T1, typename T2>
70  SMITH_HOST_DEVICE auto dot(const TimeInfo& t, const T1& field_new, const T2& field_old) const
71  {
72  return (1.0 / t.dt()) * (field_new - field_old);
73  }
74 
76  template <typename T1, typename T2>
77  SMITH_HOST_DEVICE auto interpolate(const TimeInfo& t, const T1& field_new, const T2& field_old) const
78  {
79  return std::make_tuple(value(t, field_new, field_old), dot(t, field_new, field_old));
80  }
81 
83  FieldState corrected_value(const TimeInfo& t, const std::vector<FieldState>& states) const override
84  {
85  return value(t, states[0], states[1]);
86  }
87 
89  FieldState corrected_dot(const TimeInfo& t, const std::vector<FieldState>& states) const override
90  {
91  return dot(t, states[0], states[1]);
92  }
93 
95  FieldState corrected_ddot(const TimeInfo& /*t*/, const std::vector<FieldState>& states) const override
96  {
97  SLIC_ERROR("BackwardEulerFirstOrderTimeIntegrationRule does not support second derivatives.");
98  return states[0];
99  }
100 };
101 
106  public:
107  static constexpr int num_states = 1;
108 
111 
113  int num_args() const override { return num_states; }
114 
116  template <typename T1>
117  SMITH_HOST_DEVICE auto value(const TimeInfo& /*t*/, const T1& field_new) const
118  {
119  return field_new;
120  }
121 
123  template <typename T1>
124  SMITH_HOST_DEVICE auto dot(const TimeInfo& /*t*/, const T1& /*field_new*/) const
125  {
126  return zero{};
127  }
128 
130  template <typename T1>
131  SMITH_HOST_DEVICE auto interpolate(const TimeInfo& t, const T1& field_new) const
132  {
133  return std::make_tuple(value(t, field_new), dot(t, field_new));
134  }
135 
137  FieldState corrected_value(const TimeInfo& t, const std::vector<FieldState>& states) const override
138  {
139  return value(t, states[0]);
140  }
141 
143  FieldState corrected_dot(const TimeInfo& /*t*/, const std::vector<FieldState>& states) const override
144  {
145  return zeroCopy(states[0]);
146  }
147 
149  FieldState corrected_ddot(const TimeInfo& /*t*/, const std::vector<FieldState>& states) const override
150  {
151  SLIC_ERROR("QuasiStaticRule does not support second derivatives.");
152  return states[0];
153  }
154 };
155 
159 
165  public:
166  static constexpr int num_states = 4;
167 
170 
172  int num_args() const override { return num_states; }
173 
175  bool requiresInitialAccelerationSolve() const override { return true; }
176 
178  template <typename T1, typename T2, typename T3, typename T4>
179  SMITH_HOST_DEVICE auto value([[maybe_unused]] const TimeInfo& t, [[maybe_unused]] const T1& field_new,
180  [[maybe_unused]] const T2& field_old, [[maybe_unused]] const T3& velo_old,
181  [[maybe_unused]] const T4& accel_old) const
182  {
183  return field_new;
184  }
185 
187  template <typename T1, typename T2, typename T3, typename T4>
188  SMITH_HOST_DEVICE auto dot([[maybe_unused]] const TimeInfo& t, [[maybe_unused]] const T1& field_new,
189  [[maybe_unused]] const T2& field_old, [[maybe_unused]] const T3& velo_old,
190  [[maybe_unused]] const T4& accel_old) const
191  {
192  return (2.0 / t.dt()) * (field_new - field_old) - velo_old;
193  }
194 
196  template <typename T1, typename T2, typename T3, typename T4>
197  SMITH_HOST_DEVICE auto ddot([[maybe_unused]] const TimeInfo& t, [[maybe_unused]] const T1& field_new,
198  [[maybe_unused]] const T2& field_old, [[maybe_unused]] const T3& velo_old,
199  [[maybe_unused]] const T4& accel_old) const
200  {
201  auto dt = t.dt();
202  return (4.0 / (dt * dt)) * (field_new - field_old) - (4.0 / dt) * velo_old - accel_old;
203  }
204 
206  template <typename T1, typename T2, typename T3, typename T4>
207  SMITH_HOST_DEVICE auto interpolate(const TimeInfo& t, const T1& field_new, const T2& field_old, const T3& velo_old,
208  const T4& accel_old) const
209  {
210  return std::make_tuple(value(t, field_new, field_old, velo_old, accel_old),
211  dot(t, field_new, field_old, velo_old, accel_old),
212  ddot(t, field_new, field_old, velo_old, accel_old));
213  }
214 
216  FieldState corrected_value(const TimeInfo& t, const std::vector<FieldState>& states) const override
217  {
218  return value(t, states[0], states[1], states[2], states[3]);
219  }
220 
222  FieldState corrected_dot(const TimeInfo& t, const std::vector<FieldState>& states) const override
223  {
224  return dot(t, states[0], states[1], states[2], states[3]);
225  }
226 
228  FieldState corrected_ddot(const TimeInfo& t, const std::vector<FieldState>& states) const override
229  {
230  return ddot(t, states[0], states[1], states[2], states[3]);
231  }
232 };
233 
239  public:
240  static constexpr int num_states = 4;
241 
244 
246  int num_args() const override { return num_states; }
247 
249  bool requiresInitialAccelerationSolve() const override { return false; }
250 
252  template <typename T1, typename T2, typename T3, typename T4>
253  SMITH_HOST_DEVICE auto value([[maybe_unused]] const TimeInfo& t, [[maybe_unused]] const T1& field_new,
254  [[maybe_unused]] const T2& field_old, [[maybe_unused]] const T3& velo_old,
255  [[maybe_unused]] const T4& accel_old) const
256  {
257  return field_new;
258  }
259 
261  template <typename T1, typename T2, typename T3, typename T4>
262  SMITH_HOST_DEVICE auto dot([[maybe_unused]] const TimeInfo& t, [[maybe_unused]] const T1& field_new,
263  [[maybe_unused]] const T2& field_old, [[maybe_unused]] const T3& velo_old,
264  [[maybe_unused]] const T4& accel_old) const
265  {
266  return (1.0 / t.dt()) * (field_new - field_old);
267  }
268 
270  template <typename T1, typename T2, typename T3, typename T4>
271  SMITH_HOST_DEVICE auto ddot([[maybe_unused]] const TimeInfo& t, [[maybe_unused]] const T1& field_new,
272  [[maybe_unused]] const T2& field_old, [[maybe_unused]] const T3& velo_old,
273  [[maybe_unused]] const T4& accel_old) const
274  {
275  return zero{};
276  }
277 
279  template <typename T1, typename T2, typename T3, typename T4>
280  SMITH_HOST_DEVICE auto interpolate(const TimeInfo& t, const T1& field_new, const T2& field_old, const T3& velo_old,
281  const T4& accel_old) const
282  {
283  return std::make_tuple(value(t, field_new, field_old, velo_old, accel_old),
284  dot(t, field_new, field_old, velo_old, accel_old),
285  ddot(t, field_new, field_old, velo_old, accel_old));
286  }
287 
289  FieldState corrected_value(const TimeInfo& t, const std::vector<FieldState>& states) const override
290  {
291  return value(t, states[0], states[1], states[2], states[3]);
292  }
293 
295  FieldState corrected_dot(const TimeInfo& t, const std::vector<FieldState>& states) const override
296  {
297  return dot(t, states[0], states[1], states[2], states[3]);
298  }
299 
301  FieldState corrected_ddot(const TimeInfo& /*t*/, const std::vector<FieldState>& states) const override
302  {
303  return zeroCopy(states[0]);
304  }
305 };
306 
307 } // namespace smith
#define SMITH_HOST_DEVICE
Macro that evaluates to __host__ __device__ when compiling with nvcc or amdclang and does nothing on ...
Definition: accelerator.hpp:37
encodes rules for time discretizing first order odes (involving first time derivatives)....
SMITH_HOST_DEVICE auto dot(const TimeInfo &t, const T1 &field_new, const T2 &field_old) const
evaluate time derivative discretization of the ode state as used by the integration rule
FieldState corrected_value(const TimeInfo &t, const std::vector< FieldState > &states) const override
This is an overloaded member function, provided for convenience. It differs from the above function o...
FieldState corrected_ddot(const TimeInfo &, const std::vector< FieldState > &states) const override
This is an overloaded member function, provided for convenience. It differs from the above function o...
static constexpr int num_states
number of states required by this rule (compile-time)
FieldState corrected_dot(const TimeInfo &t, const std::vector< FieldState > &states) const override
This is an overloaded member function, provided for convenience. It differs from the above function o...
SMITH_HOST_DEVICE auto value(const TimeInfo &, const T1 &field_new, const T2 &) const
evaluate value of the ode state as used by the integration rule
int num_args() const override
get the number of states required by the rule
SMITH_HOST_DEVICE auto interpolate(const TimeInfo &t, const T1 &field_new, const T2 &field_old) const
interpolate all derived quantities in one call
encodes rules for time discretizing first order odes where time derivatives are zero....
FieldState corrected_dot(const TimeInfo &, const std::vector< FieldState > &states) const override
This is an overloaded member function, provided for convenience. It differs from the above function o...
SMITH_HOST_DEVICE auto dot(const TimeInfo &, const T1 &) const
evaluate time derivative discretization of the ode state as used by the integration rule
int num_args() const override
get the number of states required by the rule
FieldState corrected_value(const TimeInfo &t, const std::vector< FieldState > &states) const override
This is an overloaded member function, provided for convenience. It differs from the above function o...
FieldState corrected_ddot(const TimeInfo &, const std::vector< FieldState > &states) const override
This is an overloaded member function, provided for convenience. It differs from the above function o...
SMITH_HOST_DEVICE auto interpolate(const TimeInfo &t, const T1 &field_new) const
interpolate all derived quantities in one call
SMITH_HOST_DEVICE auto value(const TimeInfo &, const T1 &field_new) const
evaluate value of the ode state as used by the integration rule
static constexpr int num_states
number of states required by this rule (compile-time)
Abstract time integration rule for discretizing odes in time.
virtual ~TimeIntegrationRule()
destructor
virtual FieldState corrected_ddot(const TimeInfo &t, const std::vector< FieldState > &states) const =0
update the current value of the independent variable's second time derivative, given the predicted va...
virtual FieldState corrected_value(const TimeInfo &t, const std::vector< FieldState > &states) const =0
update the current value of the independent variable, given the predicted value of the current indepe...
virtual bool requiresInitialAccelerationSolve() const
whether this rule needs a cycle-zero initial acceleration solve
virtual FieldState corrected_dot(const TimeInfo &t, const std::vector< FieldState > &states) const =0
update the current value of the independent variable's first time derivative, given the predicted val...
virtual int num_args() const =0
get the number of states required by the rule
A file defining some enums and structs that are used by the different physics modules.
Accelerator functionality.
Definition: smith.cpp:36
gretl::State< FEFieldPtr, FEDualPtr > FieldState
typedef
Definition: field_state.hpp:22
FieldState zeroCopy(const FieldState &x)
gretl-function to make a deep-copy of a FieldState and initialize it to 0.
Definition: field_state.cpp:76
encodes rules for time discretizing second order odes (involving first and second time derivatives)....
SMITH_HOST_DEVICE auto value([[maybe_unused]] const TimeInfo &t, [[maybe_unused]] const T1 &field_new, [[maybe_unused]] const T2 &field_old, [[maybe_unused]] const T3 &velo_old, [[maybe_unused]] const T4 &accel_old) const
evaluate value of the ode state as used by the integration rule
int num_args() const override
get the number of states required by the rule
SMITH_HOST_DEVICE auto interpolate(const TimeInfo &t, const T1 &field_new, const T2 &field_old, const T3 &velo_old, const T4 &accel_old) const
interpolate all derived quantities in one call
FieldState corrected_ddot(const TimeInfo &t, const std::vector< FieldState > &states) const override
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool requiresInitialAccelerationSolve() const override
implicit second-order dynamics needs the cycle-zero acceleration solve
FieldState corrected_dot(const TimeInfo &t, const std::vector< FieldState > &states) const override
This is an overloaded member function, provided for convenience. It differs from the above function o...
static constexpr int num_states
number of states required by this rule (compile-time)
SMITH_HOST_DEVICE auto dot([[maybe_unused]] const TimeInfo &t, [[maybe_unused]] const T1 &field_new, [[maybe_unused]] const T2 &field_old, [[maybe_unused]] const T3 &velo_old, [[maybe_unused]] const T4 &accel_old) const
evaluate time derivative discretization of the ode state as used by the integration rule
SMITH_HOST_DEVICE auto ddot([[maybe_unused]] const TimeInfo &t, [[maybe_unused]] const T1 &field_new, [[maybe_unused]] const T2 &field_old, [[maybe_unused]] const T3 &velo_old, [[maybe_unused]] const T4 &accel_old) const
evaluate time derivative discretization of the ode state as used by the integration rule
FieldState corrected_value(const TimeInfo &t, const std::vector< FieldState > &states) const override
This is an overloaded member function, provided for convenience. It differs from the above function o...
encodes rules for time discretizing second order odes (involving first and second time derivatives)....
SMITH_HOST_DEVICE auto ddot([[maybe_unused]] const TimeInfo &t, [[maybe_unused]] const T1 &field_new, [[maybe_unused]] const T2 &field_old, [[maybe_unused]] const T3 &velo_old, [[maybe_unused]] const T4 &accel_old) const
evaluate time derivative discretization of the ode state as used by the integration rule
FieldState corrected_value(const TimeInfo &t, const std::vector< FieldState > &states) const override
This is an overloaded member function, provided for convenience. It differs from the above function o...
FieldState corrected_ddot(const TimeInfo &, const std::vector< FieldState > &states) const override
This is an overloaded member function, provided for convenience. It differs from the above function o...
FieldState corrected_dot(const TimeInfo &t, const std::vector< FieldState > &states) const override
This is an overloaded member function, provided for convenience. It differs from the above function o...
int num_args() const override
get the number of states required by the rule
bool requiresInitialAccelerationSolve() const override
quasi-static second-order rules do not need the cycle-zero acceleration solve
SMITH_HOST_DEVICE auto dot([[maybe_unused]] const TimeInfo &t, [[maybe_unused]] const T1 &field_new, [[maybe_unused]] const T2 &field_old, [[maybe_unused]] const T3 &velo_old, [[maybe_unused]] const T4 &accel_old) const
evaluate time derivative discretization of the ode state as used by the integration rule
SMITH_HOST_DEVICE auto value([[maybe_unused]] const TimeInfo &t, [[maybe_unused]] const T1 &field_new, [[maybe_unused]] const T2 &field_old, [[maybe_unused]] const T3 &velo_old, [[maybe_unused]] const T4 &accel_old) const
evaluate value of the ode state as used by the integration rule
static constexpr int num_states
number of states required by this rule (compile-time)
SMITH_HOST_DEVICE auto interpolate(const TimeInfo &t, const T1 &field_new, const T2 &field_old, const T3 &velo_old, const T4 &accel_old) const
interpolate all derived quantities in one call
struct storing time and timestep information
Definition: common.hpp:18
double dt() const
accessor for dt
Definition: common.hpp:29
A sentinel struct for eliding no-op tensor operations.
Definition: tensor.hpp:122