Smith  0.1
Smith is an implicit thermal structural mechanics simulation code.
time_discretized_weak_form.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 
17 #include "smith/physics/mesh.hpp"
20 
21 namespace smith {
22 
23 template <int spatial_dim, typename OutputSpace, typename inputs = Parameters<>>
25 
32 template <int spatial_dim, typename OutputSpace, typename... InputSpaces>
33 class TimeDiscretizedWeakForm<spatial_dim, OutputSpace, Parameters<InputSpaces...>>
34  : public FunctionalWeakForm<spatial_dim, OutputSpace, Parameters<InputSpaces...>> {
35  public:
36  using WeakFormT = FunctionalWeakForm<spatial_dim, OutputSpace, Parameters<InputSpaces...>>;
37 
39  TimeDiscretizedWeakForm(std::string physics_name, std::shared_ptr<Mesh> mesh,
40  const mfem::ParFiniteElementSpace& output_mfem_space,
41  const typename WeakFormT::SpacesT& input_mfem_spaces)
42  : WeakFormT(physics_name, mesh, output_mfem_space, input_mfem_spaces)
43  {
44  }
45 
47  template <int... active_parameters, typename BodyIntegralType>
48  void addBodyIntegral(DependsOn<active_parameters...> depends_on, std::string body_name, BodyIntegralType integrand)
49  {
50  const double* dt = &this->dt_;
51  const size_t* cycle = &this->cycle_;
52  WeakFormT::addBodyIntegral(depends_on, body_name, [dt, cycle, integrand](double t, auto X, auto... inputs) {
53  TimeInfo time_info(t, *dt, *cycle);
54  return integrand(time_info, X, inputs...);
55  });
56  }
57 
59  template <typename BodyForceType, int... all_active_parameters>
60  void addBodyIntegralImpl(std::string body_name, BodyForceType body_integral,
61  std::integer_sequence<int, all_active_parameters...>)
62  {
63  addBodyIntegral(DependsOn<all_active_parameters...>{}, body_name, body_integral);
64  }
65 
67  template <typename BodyForceType>
68  void addBodyIntegral(std::string body_name, BodyForceType body_integral)
69  {
70  addBodyIntegralImpl(body_name, body_integral, std::make_integer_sequence<int, sizeof...(InputSpaces)>{});
71  }
72 };
73 
77  public:
78  std::shared_ptr<WeakForm> time_discretized_weak_form;
80  std::shared_ptr<WeakForm>
84 };
85 
86 template <int spatial_dim, typename OutputSpace, typename inputs = Parameters<>>
88 
99 template <int spatial_dim, typename OutputSpace, typename TrialInputSpace, typename... InputSpaces>
100 class SecondOrderTimeDiscretizedWeakForm<spatial_dim, OutputSpace, Parameters<TrialInputSpace, InputSpaces...>>
102  public:
103  static constexpr int NUM_STATE_VARS = 4;
104 
106  TimeDiscretizedWeakForm<spatial_dim, OutputSpace, Parameters<TrialInputSpace, InputSpaces...>>;
107  using FinalReactionFormT = TimeDiscretizedWeakForm<spatial_dim, OutputSpace, Parameters<InputSpaces...>>;
108 
110  SecondOrderTimeDiscretizedWeakForm(std::string physics_name, std::shared_ptr<Mesh> mesh,
112  const mfem::ParFiniteElementSpace& output_mfem_space,
113  const typename TimeDiscretizedWeakFormT::SpacesT& input_mfem_spaces)
114  : time_rule_(time_rule)
115  {
116  time_discretized_weak_form_ =
117  std::make_shared<TimeDiscretizedWeakFormT>(physics_name, mesh, output_mfem_space, input_mfem_spaces);
118  time_discretized_weak_form = time_discretized_weak_form_;
119 
120  typename TimeDiscretizedWeakFormT::SpacesT input_mfem_spaces_trial_removed(std::next(input_mfem_spaces.begin()),
121  input_mfem_spaces.end());
122  final_reaction_weak_form_ =
123  std::make_shared<FinalReactionFormT>(physics_name, mesh, output_mfem_space, input_mfem_spaces_trial_removed);
124  final_reaction_weak_form = final_reaction_weak_form_;
125  }
126 
128  template <int... active_parameters, typename BodyIntegralType>
129  void addBodyIntegral(DependsOn<active_parameters...> /*depends_on*/, std::string body_name,
130  BodyIntegralType integrand)
131  {
132  auto time_rule = time_rule_;
133  time_discretized_weak_form_->addBodyIntegral(
135  [integrand, time_rule](const TimeInfo& t, auto X, auto U, auto U_old, auto U_dot_old, auto U_dot_dot_old,
136  auto... inputs) {
137  return integrand(t, X, time_rule.value(t, U, U_old, U_dot_old, U_dot_dot_old),
138  time_rule.dot(t, U, U_old, U_dot_old, U_dot_dot_old),
139  time_rule.ddot(t, U, U_old, U_dot_old, U_dot_dot_old), inputs...);
140  });
141  final_reaction_weak_form_->addBodyIntegral(DependsOn<0, 1, 2, NUM_STATE_VARS - 1 + active_parameters...>{},
142  body_name, integrand);
143  }
144 
146  template <typename BodyForceType>
147  void addBodyIntegral(std::string body_name, BodyForceType body_integral)
148  {
149  addBodyIntegral(DependsOn<>{}, body_name, body_integral);
150  }
151 
152  private:
153  std::shared_ptr<TimeDiscretizedWeakFormT>
154  time_discretized_weak_form_;
156  std::shared_ptr<FinalReactionFormT>
157  final_reaction_weak_form_;
159 
161 };
162 
163 } // namespace smith
SecondOrderTimeDiscretizedWeakForm(std::string physics_name, std::shared_ptr< Mesh > mesh, ImplicitNewmarkSecondOrderTimeIntegrationRule time_rule, const mfem::ParFiniteElementSpace &output_mfem_space, const typename TimeDiscretizedWeakFormT::SpacesT &input_mfem_spaces)
Constructor.
void addBodyIntegral(DependsOn< active_parameters... >, std::string body_name, BodyIntegralType integrand)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void addBodyIntegral(std::string body_name, BodyForceType body_integral)
This is an overloaded member function, provided for convenience. It differs from the above function o...
A container holding the two types of weak forms useful for solving time discretized second order (in ...
A time discretized weakform gets a TimeInfo object passed as arguments to q-function (lambdas which a...
void addBodyIntegralImpl(std::string body_name, BodyForceType body_integral, std::integer_sequence< int, all_active_parameters... >)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void addBodyIntegral(std::string body_name, BodyForceType body_integral)
This is an overloaded member function, provided for convenience. It differs from the above function o...
TimeDiscretizedWeakForm(std::string physics_name, std::shared_ptr< Mesh > mesh, const mfem::ParFiniteElementSpace &output_mfem_space, const typename WeakFormT::SpacesT &input_mfem_spaces)
Constructor.
void addBodyIntegral(DependsOn< active_parameters... > depends_on, std::string body_name, BodyIntegralType integrand)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Implements the WeakForm interface using smith::ShapeAwareFunctional. Allows for generic specification...
Smith mesh class which assists in constructing the appropriate parallel mfem meshes and registering a...
Accelerator functionality.
Definition: smith.cpp:36
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
Provides templated implementations for discretizing values, velocities and accelerations from current...