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 
16 
17 namespace smith {
18 
19 class Mesh;
20 
23  public:
25  DirichletBoundaryConditions(const mfem::ParMesh& mfem_mesh, mfem::ParFiniteElementSpace& space);
26 
28  DirichletBoundaryConditions(const Mesh& mesh, mfem::ParFiniteElementSpace& space);
29 
39  template <int spatial_dim, typename AppliedDisplacementFunction>
40  void setVectorBCs(const Domain& domain, std::vector<int> components, AppliedDisplacementFunction applied_displacement)
41  {
42  int field_dim = space_.GetVDim();
43  for (auto component : components) {
44  SLIC_ERROR_IF(component >= field_dim || component < 0,
45  std::format("Trying to set boundary conditions on a field with dim {}, using component {}",
46  field_dim, component));
47  auto mfem_coefficient_function = [applied_displacement, component](const mfem::Vector& X_mfem, double t) {
48  auto X = make_tensor<spatial_dim>([&X_mfem](int k) { return X_mfem[k]; });
49  return applied_displacement(t, X)[component];
50  };
51 
52  auto dof_list = domain.dof_list(&space_);
53  // scalar ldofs -> vector ldofs
54  space_.DofsToVDofs(static_cast<int>(component), dof_list);
55 
56  auto component_disp_bdr_coef_ = std::make_shared<mfem::FunctionCoefficient>(mfem_coefficient_function);
57  bcs_.addEssential(dof_list, component_disp_bdr_coef_, space_, static_cast<int>(component));
58  }
59  }
60 
62  template <int spatial_dim, typename AppliedDisplacementFunction>
63  void setVectorBCs(const Domain& domain, AppliedDisplacementFunction applied_displacement)
64  {
65  const int field_dim = space_.GetVDim();
66  std::vector<int> components(static_cast<size_t>(field_dim));
67  for (int component = 0; component < field_dim; ++component) {
68  components[static_cast<size_t>(component)] = component;
69  }
70  setVectorBCs<spatial_dim>(domain, components, applied_displacement);
71  }
72 
78  template <int spatial_dim, typename AppliedDisplacementFunction>
79  void setScalarBCs(const Domain& domain, AppliedDisplacementFunction applied_displacement)
80  {
81  auto mfem_coefficient_function = [applied_displacement](const mfem::Vector& X_mfem, double t) {
82  auto X = make_tensor<spatial_dim>([&X_mfem](int k) { return X_mfem[k]; });
83  return applied_displacement(t, X);
84  };
85 
86  auto dof_list = domain.dof_list(&space_);
87  space_.DofsToVDofs(static_cast<int>(0), dof_list);
88 
89  auto component_disp_bdr_coef_ = std::make_shared<mfem::FunctionCoefficient>(mfem_coefficient_function);
90  bcs_.addEssential(dof_list, component_disp_bdr_coef_, space_, 0);
91  }
92 
94  template <int spatial_dim>
95  void setFixedScalarBCs(const Domain& domain)
96  {
97  setScalarBCs<spatial_dim>(domain, [](auto, auto) { return 0.0; });
98  }
99 
101  template <int spatial_dim, int field_dim>
102  void setFixedVectorBCs(const Domain& domain, std::vector<int> components)
103  {
104  setVectorBCs<spatial_dim>(domain, components, [](auto, auto) { return smith::tensor<double, field_dim>{}; });
105  }
106 
108  template <int spatial_dim, int field_dim>
109  void setFixedVectorBCs(const Domain& domain, int component)
110  {
111  std::vector<int> components{component};
112  setVectorBCs<spatial_dim, field_dim>(domain, components);
113  }
114 
116  template <int spatial_dim, int field_dim = spatial_dim>
117  void setFixedVectorBCs(const Domain& domain)
118  {
119  SLIC_ERROR_IF(field_dim != space_.GetVDim(), "Vector boundary condition field_dim does not match the fields vdim");
120  std::vector<int> components(static_cast<size_t>(field_dim));
121  for (int component = 0; component < field_dim; ++component) {
122  components[static_cast<size_t>(component)] = component;
123  }
124  setFixedVectorBCs<spatial_dim, field_dim>(domain, components);
125  }
126 
129 
130  private:
132  mfem::ParFiniteElementSpace& space_;
133 };
134 
135 } // 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 setFixedScalarBCs(const Domain &domain)
Constrain the dofs of a scalar field over a domain.
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 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 the dofs of a scalar field over a domain.
const smith::BoundaryConditionManager & getBoundaryConditionManager() const
Return the smith BoundaryConditionManager.
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