Smith  0.1
Smith is an implicit thermal structural mechanics simulation code.
heat_transfer_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 
18 namespace smith {
19 
20 template <int order, int dim, typename InputSpaces = Parameters<>>
22 
32 template <int order, int dim, typename... InputSpaces>
33 class HeatTransferWeakForm<order, dim, Parameters<InputSpaces...>>
34  : public FunctionalWeakForm<dim, H1<order>, Parameters<H1<order>, H1<order>, InputSpaces...>> {
35  public:
38 
39  // /// @brief a container holding quadrature point data of the specified type
40  // /// @tparam T the type of data to store at each quadrature point
41  // template <typename T>
42  // using qdata_type = std::shared_ptr<QuadratureData<T>>;
43 
45  static constexpr int NUM_STATE_VARS = 2;
46 
48  enum STATE
49  {
50  TEMPERATURE,
51  TEMPERATURE_RATE,
52  NUM_STATES
53  };
54 
63  HeatTransferWeakForm(std::string physics_name, std::shared_ptr<Mesh> mesh,
64  const mfem::ParFiniteElementSpace& test_space,
65  std::vector<const mfem::ParFiniteElementSpace*> parameter_fe_spaces = {})
66  : BaseWeakFormT(physics_name, mesh, test_space, constructAllSpaces(test_space, parameter_fe_spaces))
67  {
68  }
69 
92  template <int... active_parameters, typename MaterialType>
93  void setMaterial(DependsOn<active_parameters...>, std::string body_name, const MaterialType& material)
94  {
95  ThermalMaterialFunctor<MaterialType> material_functor(material);
96  BaseWeakFormT::weak_form_->AddDomainIntegral(Dimension<dim>{},
97  DependsOn<0, 1, active_parameters + NUM_STATE_VARS...>{},
98  std::move(material_functor), BaseWeakFormT::mesh_->domain(body_name));
99  BaseWeakFormT::v_dot_weak_form_residual_->AddDomainIntegral(
100  Dimension<dim>{}, DependsOn<0, 1, 2, active_parameters + 1 + NUM_STATE_VARS...>{},
101  [material_functor](double t, auto X, auto V, auto... params) {
102  auto flux = material_functor(t, X, params...);
103  return smith::inner(get<VALUE>(V), get<VALUE>(flux)) +
104  smith::inner(get<DERIVATIVE>(V), get<DERIVATIVE>(flux));
105  },
106  BaseWeakFormT::mesh_->domain(body_name));
107  }
108 
110  template <typename MaterialType>
111  void setMaterial(std::string body_name, const MaterialType& material)
112  {
113  setMaterial(DependsOn<>{}, body_name, material);
114  }
115 
116  protected:
122  std::vector<const mfem::ParFiniteElementSpace*> constructAllSpaces(
123  const mfem::ParFiniteElementSpace& state_space, const std::vector<const mfem::ParFiniteElementSpace*>& spaces)
124  {
125  std::vector<const mfem::ParFiniteElementSpace*> all_spaces{&state_space, &state_space};
126  for (auto& s : spaces) {
127  all_spaces.push_back(s);
128  }
129  return all_spaces;
130  }
131 
135  template <typename MaterialType>
136  struct ThermalMaterialFunctor {
142  ThermalMaterialFunctor(MaterialType material) : material_(material) {}
143 
145  MaterialType material_;
146 
161  template <typename X, typename Temperature, typename dT_dt, typename... Params>
162  auto operator()(double /*time*/, X x, Temperature temperature, dT_dt dtemp_dt, Params... params) const
163  {
164  // Get the value and the gradient from the input tuple
165  auto [u, du_dX] = temperature;
166  auto du_dt = get<VALUE>(dtemp_dt);
167  auto [heat_capacity, heat_flux] = material_(x, u, du_dX, params...);
168  return smith::tuple{heat_capacity * du_dt, -heat_flux};
169  }
170  };
171 };
172 
173 } // namespace smith
HeatTransferWeakForm(std::string physics_name, std::shared_ptr< Mesh > mesh, const mfem::ParFiniteElementSpace &test_space, std::vector< const mfem::ParFiniteElementSpace * > parameter_fe_spaces={})
Construct a new HeatTransferWeakForm object.
void setMaterial(std::string body_name, const MaterialType &material)
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::vector< const mfem::ParFiniteElementSpace * > constructAllSpaces(const mfem::ParFiniteElementSpace &state_space, const std::vector< const mfem::ParFiniteElementSpace * > &spaces)
For use in the constructor, combined the correct number of state spaces (disp,velo,...
void setMaterial(DependsOn< active_parameters... >, std::string body_name, const MaterialType &material)
Set the thermal material model for the physics module.
Implements the WeakForm interface using smith::ShapeAwareFunctional. Allows for generic specification...
Accelerator functionality.
Definition: smith.cpp:36
constexpr SMITH_HOST_DEVICE auto inner(const dual< S > &A, const dual< T > &B)
Definition: dual.hpp:281
Compile-time alias for a dimension.
Definition: geometry.hpp:17
H1 elements of order p.
ThermalMaterialFunctor(MaterialType material)
Construct a ThermalMaterialIntegrand functor with material model of type MaterialType.
auto operator()(double, X x, Temperature temperature, dT_dt dtemp_dt, Params... params) const
Thermal material response call.
a struct that is used in the physics modules to clarify which template arguments are user-controlled ...
Definition: common.hpp:21
This is a class that mimics most of std::tuple's interface, except that it is usable in CUDA kernels ...
Definition: tuple.hpp:28