Smith  0.1
Smith is an implicit thermal structural mechanics simulation code.
odes.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 
13 #pragma once
14 
15 #include <functional>
16 #include <memory>
17 
18 #include "mfem.hpp"
19 
23 
24 namespace smith::mfem_ext {
25 
36 class SecondOrderODE : public mfem::SecondOrderTimeDependentOperator {
37  public:
47  static constexpr double epsilon = 0.0001;
48 
53  struct State {
57  double& time;
58 
62  double& c0;
63 
67  double& c1;
68 
72  mfem::Vector& u;
73 
77  mfem::Vector& du_dt;
78 
82  mfem::Vector& d2u_dt2;
83  };
84 
104  SecondOrderODE(int n, State&& state, const EquationSolver& solver, const BoundaryConditionManager& bcs);
105 
113  void Mult(const mfem::Vector& u, const mfem::Vector& du_dt, mfem::Vector& d2u_dt2) const override
114  {
115  Solve(t, 0.0, 0.0, u, du_dt, d2u_dt2);
116  }
117 
127  void ImplicitSolve(const double c0, const double c1, const mfem::Vector& u, const mfem::Vector& du_dt,
128  mfem::Vector& d2u_dt2) override
129  {
130  Solve(t, c0, c1, u, du_dt, d2u_dt2);
131  }
132 
136  void ImplicitSolve(const double dt, const mfem::Vector& u, mfem::Vector& du_dt) override;
137 
142  void SetEnforcementMethod(const DirichletEnforcementMethod method) { enforcement_method_ = method; }
143 
149  void SetTimestepper(const smith::TimestepMethod timestepper);
150 
161  void Step(mfem::Vector& x, mfem::Vector& dxdt, double& time, double& dt);
162 
166  const State& GetState() { return state_; }
167 
173  TimestepMethod GetTimestepper() { return timestepper_; }
174 
175  private:
187  void Solve(const double time, const double c0, const double c1, const mfem::Vector& u, const mfem::Vector& du_dt,
188  mfem::Vector& d2u_dt2) const;
189 
193  State state_;
201  const EquationSolver& solver_;
205  std::unique_ptr<mfem::SecondOrderODESolver> second_order_ode_solver_;
206 
210  std::unique_ptr<mfem::ODESolver> first_order_system_ode_solver_;
211 
215  const BoundaryConditionManager& bcs_;
216  mfem::Vector zero_;
217 
221  mutable mfem::Vector U_minus_;
222  mutable mfem::Vector U_;
223  mutable mfem::Vector U_plus_;
224  mutable mfem::Vector dU_dt_;
225  mutable mfem::Vector d2U_dt2_;
226 
227  smith::TimestepMethod timestepper_;
228 };
229 
240 class FirstOrderODE : public mfem::TimeDependentOperator {
241  public:
251  static constexpr double epsilon = 0.000001;
252 
257  struct State {
261  double& time;
262 
266  mfem::Vector& u;
267 
271  double& dt;
272 
276  mfem::Vector& du_dt;
277 
281  double& previous_dt;
282  };
283 
302  FirstOrderODE(int n, FirstOrderODE::State&& state, const EquationSolver& solver, const BoundaryConditionManager& bcs);
303 
310  void Mult(const mfem::Vector& u, mfem::Vector& du_dt) const { Solve(t, 0.0, u, du_dt); }
311 
319  void ImplicitSolve(const double dt, const mfem::Vector& u, mfem::Vector& du_dt) { Solve(t, dt, u, du_dt); }
320 
325  void SetEnforcementMethod(const DirichletEnforcementMethod method) { enforcement_method_ = method; }
326 
332  void SetTimestepper(const smith::TimestepMethod timestepper);
333 
343  void Step(mfem::Vector& x, double& time, double& dt)
344  {
345  if (ode_solver_) {
346  ode_solver_->Step(x, time, dt);
347  } else {
348  SLIC_ERROR("ode_solver_ unspecified");
349  }
350  }
351 
357  TimestepMethod GetTimestepper() { return timestepper_; }
358 
359  private:
367  virtual void Solve(const double time, const double dt, const mfem::Vector& u, mfem::Vector& du_dt) const;
368 
372  FirstOrderODE::State state_;
373 
381  const EquationSolver& solver_;
385  std::unique_ptr<mfem::ODESolver> ode_solver_;
389  const BoundaryConditionManager& bcs_;
390  mfem::Vector zero_;
391 
395  mutable mfem::Vector U_minus_;
396  mutable mfem::Vector U_;
397  mutable mfem::Vector U_plus_;
398  mutable mfem::Vector dU_dt_;
399 
400  TimestepMethod timestepper_;
401 };
402 
403 } // namespace smith::mfem_ext
This file contains the declaration of the boundary condition manager class.
A container for the boundary condition information relating to a specific physics module.
This class manages the objects typically required to solve a nonlinear set of equations arising from ...
FirstOrderODE is a class wrapping mfem::TimeDependentOperator so that the user can use std::function ...
Definition: odes.hpp:240
FirstOrderODE(int n, FirstOrderODE::State &&state, const EquationSolver &solver, const BoundaryConditionManager &bcs)
Constructor defining the size and specific system of ordinary differential equations to be solved.
Definition: odes.cpp:253
static constexpr double epsilon
a small number used to compute finite difference approximations to time derivatives of boundary condi...
Definition: odes.hpp:251
void ImplicitSolve(const double dt, const mfem::Vector &u, mfem::Vector &du_dt)
Solves the equation du_dt = f(u + dt * du_dt, t)
Definition: odes.hpp:319
void SetEnforcementMethod(const DirichletEnforcementMethod method)
Configures the Dirichlet enforcement method to use.
Definition: odes.hpp:325
void Mult(const mfem::Vector &u, mfem::Vector &du_dt) const
Solves the equation du_dt = f(u, t)
Definition: odes.hpp:310
void Step(mfem::Vector &x, double &time, double &dt)
Performs a time step.
Definition: odes.hpp:343
TimestepMethod GetTimestepper()
Query the timestep method for the ode solver.
Definition: odes.hpp:357
void SetTimestepper(const smith::TimestepMethod timestepper)
Set the time integration method.
Definition: odes.cpp:264
SecondOrderODE is a class wrapping mfem::SecondOrderTimeDependentOperator so that the user can use st...
Definition: odes.hpp:36
void ImplicitSolve(const double c0, const double c1, const mfem::Vector &u, const mfem::Vector &du_dt, mfem::Vector &d2u_dt2) override
Solves the equation d2u_dt2 = f(u + c0 * d2u_dt2, du_dt + c1 * d2u_dt2, t)
Definition: odes.hpp:127
SecondOrderODE(int n, State &&state, const EquationSolver &solver, const BoundaryConditionManager &bcs)
Constructor defining the size and specific system of ordinary differential equations to be solved.
Definition: odes.cpp:14
void SetTimestepper(const smith::TimestepMethod timestepper)
Set the time integration method.
Definition: odes.cpp:25
TimestepMethod GetTimestepper()
Query the timestep method for the ode solver.
Definition: odes.hpp:173
void Step(mfem::Vector &x, mfem::Vector &dxdt, double &time, double &dt)
Performs a time step.
Definition: odes.cpp:80
static constexpr double epsilon
a small number used to compute finite difference approximations to time derivatives of boundary condi...
Definition: odes.hpp:47
void SetEnforcementMethod(const DirichletEnforcementMethod method)
Configures the Dirichlet enforcement method to use.
Definition: odes.hpp:142
const State & GetState()
Get a reference to the current state.
Definition: odes.hpp:166
void Mult(const mfem::Vector &u, const mfem::Vector &du_dt, mfem::Vector &d2u_dt2) const override
Solves the equation d2u_dt2 = f(u, du_dt, t)
Definition: odes.hpp:113
This file contains the declaration of an equation solver wrapper.
TimestepMethod
Timestep method of a solver.
DirichletEnforcementMethod
this enum describes which way to enforce the time-varying constraint u(t) == U(t)
This file contains enumerations and record types for physics solver configuration.
A set of references to physics-module-owned variables used by the residual operator.
Definition: odes.hpp:257
double & previous_dt
Previous value of dt.
Definition: odes.hpp:281
mfem::Vector & u
Predicted true DOFs.
Definition: odes.hpp:266
double & time
Time value at which the ODE solver wants to compute a residual.
Definition: odes.hpp:261
mfem::Vector & du_dt
Previous value of du_dt.
Definition: odes.hpp:276
double & dt
Current time step.
Definition: odes.hpp:271
A set of references to physics-module-owned variables used by the residual operator.
Definition: odes.hpp:53
double & c0
coefficient used to calculate updated displacement: u_{n + 1} := u + c0 * d2u_dt2
Definition: odes.hpp:62
mfem::Vector & du_dt
Predicted du_dt.
Definition: odes.hpp:77
mfem::Vector & u
Predicted true DOFs.
Definition: odes.hpp:72
mfem::Vector & d2u_dt2
Previous value of d^2u_dt^2.
Definition: odes.hpp:82
double & c1
coefficient used to calculate updated velocity: du_dt_{n+1} := du_dt + c1 * d2u_dt2
Definition: odes.hpp:67
double & time
Time value at which the ODE solver wants to compute a residual.
Definition: odes.hpp:57