Smith  0.1
Smith is an implicit thermal structural mechanics simulation code.
dirichlet_boundary_conditions.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 <optional>
16 
18 
19 namespace smith {
20 
21 class Mesh;
22 
25  public:
27  DirichletBoundaryConditions(const mfem::ParMesh& mfem_mesh, mfem::ParFiniteElementSpace& space);
28 
30  DirichletBoundaryConditions(const Mesh& mesh, mfem::ParFiniteElementSpace& space);
31 
41  template <int spatial_dim, typename AppliedDisplacementFunction>
42  void setVectorBCs(const Domain& domain, std::vector<int> components, AppliedDisplacementFunction applied_displacement)
43  {
44  int field_dim = space_.GetVDim();
45  for (auto component : components) {
46  SLIC_ERROR_IF(component >= field_dim || component < 0,
47  std::format("Trying to set boundary conditions on a field with dim {}, using component {}",
48  field_dim, component));
49  auto mfem_coefficient_function = [applied_displacement, component](const mfem::Vector& X_mfem, double t) {
50  auto X = make_tensor<spatial_dim>([&X_mfem](int k) { return X_mfem[k]; });
51  return applied_displacement(t, X)[component];
52  };
53 
54  auto dof_list = domain.dof_list(&space_);
55  // scalar ldofs -> vector ldofs
56  space_.DofsToVDofs(static_cast<int>(component), dof_list);
57 
58  auto component_disp_bdr_coef_ = std::make_shared<mfem::FunctionCoefficient>(mfem_coefficient_function);
59  bcs_.addEssential(dof_list, component_disp_bdr_coef_, space_, static_cast<int>(component));
60  }
61  }
62 
64  template <int spatial_dim, typename AppliedDisplacementFunction>
65  void setVectorBCs(const Domain& domain, AppliedDisplacementFunction applied_displacement)
66  {
67  const int field_dim = space_.GetVDim();
68  std::vector<int> components(static_cast<size_t>(field_dim));
69  for (int component = 0; component < field_dim; ++component) {
70  components[static_cast<size_t>(component)] = component;
71  }
72  setVectorBCs<spatial_dim>(domain, components, applied_displacement);
73  }
74 
80  template <int spatial_dim, typename AppliedDisplacementFunction>
81  void setScalarBCs(const Domain& domain, AppliedDisplacementFunction applied_displacement)
82  {
83  auto mfem_coefficient_function = [applied_displacement](const mfem::Vector& X_mfem, double t) {
84  auto X = make_tensor<spatial_dim>([&X_mfem](int k) { return X_mfem[k]; });
85  return applied_displacement(t, X);
86  };
87 
88  auto dof_list = domain.dof_list(&space_);
89  space_.DofsToVDofs(static_cast<int>(0), dof_list);
90 
91  auto component_disp_bdr_coef_ = std::make_shared<mfem::FunctionCoefficient>(mfem_coefficient_function);
92  bcs_.addEssential(dof_list, component_disp_bdr_coef_, space_, 0);
93  }
94 
96  template <int spatial_dim, typename AppliedDisplacementFunction>
97  void setScalarBCsOnLocalDofs(const mfem::Array<int>& local_dofs, AppliedDisplacementFunction applied_displacement)
98  {
99  auto mfem_coefficient_function = [applied_displacement](const mfem::Vector& X_mfem, double t) {
100  auto X = make_tensor<spatial_dim>([&X_mfem](int k) { return X_mfem[k]; });
101  return applied_displacement(t, X);
102  };
103 
104  auto component_disp_bdr_coef_ = std::make_shared<mfem::FunctionCoefficient>(mfem_coefficient_function);
105  bcs_.addEssential(local_dofs, component_disp_bdr_coef_, space_, 0);
106  }
107 
109  template <int spatial_dim>
110  void setFixedScalarBCs(const Domain& domain)
111  {
112  setScalarBCs<spatial_dim>(domain, [](auto, auto) { return 0.0; });
113  }
114 
116  template <int spatial_dim>
117  void setFixedScalarBCsOnLocalDofs(const mfem::Array<int>& local_dofs)
118  {
119  setScalarBCsOnLocalDofs<spatial_dim>(local_dofs, [](auto, auto) { return 0.0; });
120  }
121 
123  template <int spatial_dim, int field_dim>
124  void setFixedVectorBCs(const Domain& domain, std::vector<int> components)
125  {
126  setVectorBCs<spatial_dim>(domain, components, [](auto, auto) { return smith::tensor<double, field_dim>{}; });
127  }
128 
129  template <int spatial_dim>
131  void setFixedVectorBCs(const Domain& domain, std::vector<int> components)
132  {
133  setFixedVectorBCs<spatial_dim, spatial_dim>(domain, components);
134  }
135 
137  template <int spatial_dim, int field_dim>
138  void setFixedVectorBCs(const Domain& domain, int component)
139  {
140  std::vector<int> components{component};
141  setFixedVectorBCs<spatial_dim, field_dim>(domain, components);
142  }
143 
145  template <int spatial_dim>
146  void setFixedVectorBCs(const Domain& domain, int component)
147  {
148  setFixedVectorBCs<spatial_dim, spatial_dim>(domain, component);
149  }
150 
152  template <int spatial_dim, int field_dim = spatial_dim>
153  void setFixedVectorBCs(const Domain& domain)
154  {
155  SLIC_ERROR_IF(field_dim != space_.GetVDim(), "Vector boundary condition field_dim does not match the fields vdim");
156  std::vector<int> components(static_cast<size_t>(field_dim));
157  for (int component = 0; component < field_dim; ++component) {
158  components[static_cast<size_t>(component)] = component;
159  }
160  setFixedVectorBCs<spatial_dim, field_dim>(domain, components);
161  }
162 
165 
172 
173  private:
174  void rebuildSecondDerivativeManager(BoundaryConditionManager& target) const;
175 
176  const mfem::ParMesh& mfem_mesh_;
178  mfem::ParFiniteElementSpace& space_;
179 
180  mutable std::optional<BoundaryConditionManager> second_derivative_manager_;
181 };
182 
183 } // namespace smith
This file contains the declaration of the boundary condition manager class.
A container for the boundary condition information relating to a specific physics module.
void addEssential(const std::set< int > &ess_bdr, smith::GeneralCoefficient ess_bdr_coef, mfem::ParFiniteElementSpace &space, const std::optional< int > component={})
Set the essential boundary conditions from a list of boundary markers and a coefficient.
A generic class for setting Dirichlet boundary conditions on arbitrary physics.
void setFixedVectorBCs(const Domain &domain, std::vector< int > components)
Constrain the vector dofs over a domain corresponding to a subset of the vector components.
void setScalarBCsOnLocalDofs(const mfem::Array< int > &local_dofs, AppliedDisplacementFunction applied_displacement)
Specify time and space varying Dirichlet boundary conditions over an explicit list of local scalar do...
void setFixedScalarBCs(const Domain &domain)
Constrain the dofs of a scalar field over a domain.
const smith::BoundaryConditionManager & getSecondDerivativeManager() const
Return the BC manager whose prescribed values are the second time derivative of the value-level BC,...
DirichletBoundaryConditions(const mfem::ParMesh &mfem_mesh, mfem::ParFiniteElementSpace &space)
Construct from mfem::ParMesh.
void setFixedVectorBCs(const Domain &domain)
Constrain all the vector dofs over a domain.
void setScalarBCs(const Domain &domain, AppliedDisplacementFunction applied_displacement)
Specify time and space varying Dirichlet boundary conditions over a domain.
void setFixedVectorBCs(const Domain &domain, std::vector< int > components)
Constrain selected vector components over a domain to zero.
void setVectorBCs(const Domain &domain, std::vector< int > components, AppliedDisplacementFunction applied_displacement)
Specify time and space varying Dirichlet boundary conditions over a domain.
void setVectorBCs(const Domain &domain, AppliedDisplacementFunction applied_displacement)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void setFixedVectorBCs(const Domain &domain, int component)
Constrain one vector component over a domain to zero.
void setFixedScalarBCsOnLocalDofs(const mfem::Array< int > &local_dofs)
Constrain an explicit list of local scalar dofs.
const smith::BoundaryConditionManager & getBoundaryConditionManager() const
Return the value-level smith BoundaryConditionManager.
void setFixedVectorBCs(const Domain &domain, int component)
Constrain one vector component over a domain to zero.
Helper class for constructing a mesh consistent with Smith.
Definition: mesh.hpp:37
Accelerator functionality.
Definition: smith.cpp:36
mfem::ParFiniteElementSpace & space(FieldState field)
Get the space from the primal field of a field states.
a class for representing a geometric region that can be used for integration
Definition: domain.hpp:33
mfem::Array< int > dof_list(const fes_t *fes) const
get mfem degree of freedom list for a given FiniteElementSpace
Definition: domain.cpp:466
Arbitrary-rank tensor class.
Definition: tensor.hpp:28