Smith  0.1
Smith is an implicit thermal structural mechanics simulation code.
boundary_condition.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 <memory>
16 #include <optional>
17 #include <set>
18 #include <type_traits>
19 #include <utility>
20 #include <cstddef>
21 
25 
26 namespace smith {
27 
32  public:
42  BoundaryCondition(GeneralCoefficient coef, const std::optional<int> component,
43  const mfem::ParFiniteElementSpace& space, const std::set<int>& attrs);
44 
53  BoundaryCondition(GeneralCoefficient coef, const std::optional<int> component,
54  const mfem::ParFiniteElementSpace& space, const mfem::Array<int>& true_dofs);
55 
62  template <typename Tag>
63  bool tagEquals(const Tag tag) const
64  {
65  static_assert(std::is_enum_v<Tag>, "Only enumerations can be used to tag a boundary condition.");
66  SLIC_ERROR_ROOT_IF(!tag_, "No tag has been configured for this boundary condition");
67  bool tags_same_type = typeid(tag).hash_code() == tag_->second;
68  SLIC_WARNING_ROOT_IF(!tags_same_type, "Attempting to compare tags of two different enum types (always false)");
69  return (static_cast<int>(tag) == tag_->first) && tags_same_type;
70  }
71 
78  template <typename Tag>
79  void setTag(const Tag tag)
80  {
81  static_assert(std::is_enum_v<Tag>, "Only enumerations can be used to tag a boundary condition.");
82  tag_ = {static_cast<int>(tag), typeid(tag).hash_code()};
83  }
84 
89  const mfem::Array<int>& markers() const { return attr_markers_; }
90 
95  mfem::Array<int>& markers() { return attr_markers_; }
96 
103  const mfem::Array<int>& getTrueDofList() const { return true_dofs_; }
104 
111  const mfem::Array<int>& getLocalDofList() const { return local_dofs_; }
112 
114  const GeneralCoefficient& coefficient() const { return coef_; }
115 
117  const std::optional<int>& component() const { return component_; }
118 
124  void setDofs(mfem::Vector& state, const double time = 0.0) const;
125 
150  void apply(mfem::HypreParMatrix& k_mat, mfem::Vector& rhs, mfem::Vector& state) const;
151 
152  private:
159  void setDofListsFromAttributeMarkers();
160 
168  void setTrueDofList(const mfem::Array<int>& true_dofs);
169 
173  GeneralCoefficient coef_;
177  std::optional<int> component_;
181  mfem::Array<int> attr_markers_;
186  mfem::Array<int> true_dofs_;
191  mfem::Array<int> local_dofs_;
196  const mfem::ParFiniteElementSpace& space_;
197 
203  std::optional<std::pair<int, std::size_t>> tag_;
204 };
205 
206 } // namespace smith
Boundary condition information bundle.
const std::optional< int > & component() const
Returns constrained vector component, if any.
void setTag(const Tag tag)
Sets the tag for the BC.
const mfem::Array< int > & getLocalDofList() const
Returns the DOF indices for an essential boundary condition.
mfem::Array< int > & markers()
Returns a non-owning reference to the array of boundary attribute markers.
const mfem::Array< int > & markers() const
Returns a non-owning reference to the array of boundary attribute markers.
const GeneralCoefficient & coefficient() const
Returns stored coefficient.
void apply(mfem::HypreParMatrix &k_mat, mfem::Vector &rhs, mfem::Vector &state) const
Modify the system of equations by replacing equations that correspond to essential boundary conditio...
void setDofs(mfem::Vector &state, const double time=0.0) const
Projects the associated coefficient over a solution vector on the DOFs constrained by the boundary co...
BoundaryCondition(GeneralCoefficient coef, const std::optional< int > component, const mfem::ParFiniteElementSpace &space, const std::set< int > &attrs)
Constructor for setting up a boundary condition using a set of attributes.
const mfem::Array< int > & getTrueDofList() const
Returns the DOF indices for an essential boundary condition.
bool tagEquals(const Tag tag) const
Determines whether a boundary condition is associated with a tag.
This file contains the declaration of structure that manages the MFEM objects that make up the state ...
This file contains the declaration of structure that manages vectors derived from an MFEM finite elem...
This file contains the all the necessary functions and macros required for logging as well as a helpe...
Accelerator functionality.
Definition: smith.cpp:36
mfem::ParFiniteElementSpace & space(FieldState field)
Get the space from the primal field of a field states.