Smith  0.1
Smith is an implicit thermal structural mechanics simulation code.
solid_mechanics_state_advancer.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 
15 #pragma once
16 
17 #include "gretl/data_store.hpp"
18 #include "smith/smith_config.hpp"
19 #include "smith/physics/mesh.hpp"
25 
26 namespace smith {
27 
28 class DifferentiableSolver;
29 class DirichletBoundaryConditions;
30 class SecondOrderTimeDiscretizedWeakForms;
31 
34  public:
40  SolidMechanicsStateAdvancer(std::shared_ptr<DifferentiableSolver> solid_solver,
41  std::shared_ptr<DirichletBoundaryConditions> vector_bcs,
42  std::shared_ptr<SecondOrderTimeDiscretizedWeakForms> solid_dynamic_weak_forms,
44 
46  enum STATE
47  {
48  DISPLACEMENT,
49  VELOCITY,
50  ACCELERATION
51  };
52 
55  template <typename FirstParamSpace, typename... ParamSpaces>
56  static std::vector<FieldState> createParams(gretl::DataStore& graph, const std::string& name,
57  const std::vector<std::string>& param_names, const std::string& tag,
58  size_t index = 0)
59  {
60  FieldState newParam = createFieldState(graph, FirstParamSpace{}, name + "_" + param_names[index], tag);
61  std::vector<FieldState> end_spaces{};
62  if constexpr (sizeof...(ParamSpaces) > 0) {
63  end_spaces = createParams<ParamSpaces...>(graph, name, param_names, tag, ++index);
64  }
65  end_spaces.insert(end_spaces.begin(), newParam);
66  return end_spaces;
67  }
68 
71  template <int spatial_dim, typename ShapeDispSpace, typename VectorSpace, typename... ParamSpaces>
72  static auto buildWeakFormAndStates(const std::shared_ptr<Mesh>& mesh, const std::shared_ptr<gretl::DataStore>& graph,
73  ImplicitNewmarkSecondOrderTimeIntegrationRule time_rule, std::string physics_name,
74  const std::vector<std::string>& param_names, double initial_time = 0.0)
75  {
76  auto shape_disp = createFieldState(*graph, ShapeDispSpace{}, physics_name + "_shape_displacement", mesh->tag());
77  auto disp = createFieldState(*graph, VectorSpace{}, physics_name + "_displacement", mesh->tag());
78  auto velo = createFieldState(*graph, VectorSpace{}, physics_name + "_velocity", mesh->tag());
79  auto acceleration = createFieldState(*graph, VectorSpace{}, physics_name + "_acceleration", mesh->tag());
80  auto time = graph->create_state<double, double>(initial_time);
81  std::vector<FieldState> params =
82  createParams<ParamSpaces...>(*graph, physics_name + "_param", param_names, mesh->tag());
83  std::vector<FieldState> states{disp, velo, acceleration};
84 
85  // weak form unknowns are disp, disp_old, velo_old, accel_old
86  using SolidWeakFormT = SecondOrderTimeDiscretizedWeakForm<
87  spatial_dim, VectorSpace, Parameters<VectorSpace, VectorSpace, VectorSpace, VectorSpace, ParamSpaces...>>;
88  auto input_spaces = spaces({states[DISPLACEMENT], states[DISPLACEMENT], states[VELOCITY], states[ACCELERATION]});
89  auto param_spaces = spaces(params);
90  input_spaces.insert(input_spaces.end(), param_spaces.begin(), param_spaces.end());
91 
92  auto solid_mechanics_weak_form =
93  std::make_shared<SolidWeakFormT>(physics_name, mesh, time_rule, space(states[DISPLACEMENT]), input_spaces);
94 
95  return std::make_tuple(shape_disp, states, params, time, solid_mechanics_weak_form);
96  }
97 
99  std::vector<FieldState> advanceState(const TimeInfo& time_info, const FieldState& shape_disp,
100  const std::vector<FieldState>& states_old,
101  const std::vector<FieldState>& params) const override;
102 
104  std::vector<ReactionState> computeReactions(const TimeInfo& time_info, const FieldState& shape_disp,
105  const std::vector<FieldState>& states,
106  const std::vector<FieldState>& params) const override;
107 
108  private:
109  std::shared_ptr<DifferentiableSolver> solver_;
110  std::shared_ptr<DirichletBoundaryConditions> vector_bcs_;
111  std::shared_ptr<SecondOrderTimeDiscretizedWeakForms>
112  solid_dynamic_weak_forms_;
115  time_rule_;
117 };
118 
119 } // namespace smith
Implementation of the StateAdvancer interface for advancing the solution of solid mechanics problems.
STATE
State enum for indexing convenience.
SolidMechanicsStateAdvancer(std::shared_ptr< DifferentiableSolver > solid_solver, std::shared_ptr< DirichletBoundaryConditions > vector_bcs, std::shared_ptr< SecondOrderTimeDiscretizedWeakForms > solid_dynamic_weak_forms, ImplicitNewmarkSecondOrderTimeIntegrationRule time_rule)
Constructor.
static auto buildWeakFormAndStates(const std::shared_ptr< Mesh > &mesh, const std::shared_ptr< gretl::DataStore > &graph, ImplicitNewmarkSecondOrderTimeIntegrationRule time_rule, std::string physics_name, const std::vector< std::string > &param_names, double initial_time=0.0)
Utility function to consistently construct all the weak forms and FieldStates for a solid mechanics a...
static std::vector< FieldState > createParams(gretl::DataStore &graph, const std::string &name, const std::vector< std::string > &param_names, const std::string &tag, size_t index=0)
Recursive function for constructing parameter FieldStates of the appropriate space and name,...
std::vector< FieldState > advanceState(const TimeInfo &time_info, const FieldState &shape_disp, const std::vector< FieldState > &states_old, const std::vector< FieldState > &params) const override
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::vector< ReactionState > computeReactions(const TimeInfo &time_info, const FieldState &shape_disp, const std::vector< FieldState > &states, const std::vector< FieldState > &params) const override
This is an overloaded member function, provided for convenience. It differs from the above function o...
Base state advancer class, allows specification for quasi-static solve strategies,...
Smith mesh class which assists in constructing the appropriate parallel mfem meshes and registering a...
Accelerator functionality.
Definition: smith.cpp:36
std::vector< const mfem::ParFiniteElementSpace * > spaces(const std::vector< FieldState > &states, const std::vector< FieldState > &params={})
Get the spaces from the primal fields of a vector of field states.
gretl::State< FEFieldPtr, FEDualPtr > FieldState
typedef
Definition: field_state.hpp:22
FieldState createFieldState(gretl::DataStore &dataStore, const smith::FEFieldPtr &s)
initialize on the gretl::DataStore a FieldState with values from s
Definition: field_state.hpp:48
SMITH_HOST_DEVICE tuple< T... > make_tuple(const T &... args)
helper function for combining a list of values into a tuple
Definition: tuple.hpp:266
mfem::ParFiniteElementSpace & space(FieldState field)
Get the space from the primal field of a field states.
Methods for solving systems of equations as given by WeakForms. Tracks these operations on the gretl ...
Interface and implementations for advancing from one step to the next. Typically these are time integ...
encodes rules for time discretizing second order odes (involving first and second time derivatives)....
a struct that is used in the physics modules to clarify which template arguments are user-controlled ...
Definition: common.hpp:45
struct storing time and timestep information
Definition: common.hpp:18
Specifies parametrized residuals and various linearized evaluations for arbitrary nonlinear systems o...
Provides templated implementations for discretizing values, velocities and accelerations from current...