Serac  0.1
Serac is an implicit thermal strucural mechanics simulation code.
boundary_condition.hpp
Go to the documentation of this file.
1 // Copyright (c) 2019-2024, Lawrence Livermore National Security, LLC and
2 // other Serac 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 <typeinfo>
20 #include <utility>
21 
24 
25 namespace serac {
26 
31 public:
41  BoundaryCondition(GeneralCoefficient coef, const std::optional<int> component,
42  const mfem::ParFiniteElementSpace& space, const std::set<int>& attrs);
43 
52  BoundaryCondition(GeneralCoefficient coef, const std::optional<int> component,
53  const mfem::ParFiniteElementSpace& space, const mfem::Array<int>& true_dofs);
54 
61  template <typename Tag>
62  bool tagEquals(const Tag tag) const
63  {
64  static_assert(std::is_enum_v<Tag>, "Only enumerations can be used to tag a boundary condition.");
65  SLIC_ERROR_ROOT_IF(!tag_, "No tag has been configured for this boundary condition");
66  bool tags_same_type = typeid(tag).hash_code() == tag_->second;
67  SLIC_WARNING_ROOT_IF(!tags_same_type, "Attempting to compare tags of two different enum types (always false)");
68  return (static_cast<int>(tag) == tag_->first) && tags_same_type;
69  }
70 
77  template <typename Tag>
78  void setTag(const Tag tag)
79  {
80  static_assert(std::is_enum_v<Tag>, "Only enumerations can be used to tag a boundary condition.");
81  tag_ = {static_cast<int>(tag), typeid(tag).hash_code()};
82  }
83 
88  const mfem::Array<int>& markers() const { return attr_markers_; }
89 
94  mfem::Array<int>& markers() { return attr_markers_; }
95 
104  const mfem::VectorCoefficient& vectorCoefficient() const;
105 
114  mfem::VectorCoefficient& vectorCoefficient();
115 
124  const mfem::Coefficient& scalarCoefficient() const;
125 
134  mfem::Coefficient& scalarCoefficient();
135 
142  const mfem::Array<int>& getTrueDofList() const { return true_dofs_; }
143 
150  const mfem::Array<int>& getLocalDofList() const { return local_dofs_; }
151 
157  void setDofs(mfem::Vector& state, const double time = 0.0) const;
158 
183  void apply(mfem::HypreParMatrix& k_mat, mfem::Vector& rhs, mfem::Vector& state) const;
184 
185 private:
192  void setDofListsFromAttributeMarkers();
193 
201  void setTrueDofList(const mfem::Array<int>& true_dofs);
202 
211  void setLocalDofList(const mfem::Array<int>& local_dofs);
212 
216  GeneralCoefficient coef_;
220  std::optional<int> component_;
224  mfem::Array<int> attr_markers_;
229  mfem::Array<int> true_dofs_;
234  mfem::Array<int> local_dofs_;
239  const mfem::ParFiniteElementSpace& space_;
240 
246  std::optional<std::pair<int, std::size_t>> tag_;
247 };
248 
249 } // namespace serac
Boundary condition information bundle.
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...
const mfem::VectorCoefficient & vectorCoefficient() const
Accessor for the underlying vector coefficient.
const mfem::Coefficient & scalarCoefficient() const
Accessor for the underlying scalar coefficient.
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.
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.
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.
const mfem::Array< int > & getTrueDofList() const
Returns the DOF indices for an essential boundary condition.
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...
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 all the necessary functions and macros required for logging as well as a helpe...
Accelerator functionality.
Definition: serac.cpp:38