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) 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 <utility>
20 #include <cstddef>
21 
25 
26 namespace serac {
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 
118  void setDofs(mfem::Vector& state, const double time = 0.0) const;
119 
144  void apply(mfem::HypreParMatrix& k_mat, mfem::Vector& rhs, mfem::Vector& state) const;
145 
146  private:
153  void setDofListsFromAttributeMarkers();
154 
162  void setTrueDofList(const mfem::Array<int>& true_dofs);
163 
167  GeneralCoefficient coef_;
171  std::optional<int> component_;
175  mfem::Array<int> attr_markers_;
180  mfem::Array<int> true_dofs_;
185  mfem::Array<int> local_dofs_;
190  const mfem::ParFiniteElementSpace& space_;
191 
197  std::optional<std::pair<int, std::size_t>> tag_;
198 };
199 
200 } // 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...
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 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: serac.cpp:36