Smith  0.1
Smith is an implicit thermal structural mechanics simulation code.
boundary_condition_manager.cpp
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 
7 #include <algorithm>
8 #include <iterator>
9 
12 
13 namespace smith {
14 
15 void BoundaryConditionManager::addEssential(const std::set<int>& ess_bdr, smith::GeneralCoefficient ess_bdr_coef,
16  mfem::ParFiniteElementSpace& space, const std::optional<int> component)
17 {
18  std::set<int> filtered_attrs;
19  std::set_difference(ess_bdr.begin(), ess_bdr.end(), attrs_in_use_.begin(), attrs_in_use_.end(),
20  std::inserter(filtered_attrs, filtered_attrs.begin()));
21 
22  // Check if anything was removed
23  if (filtered_attrs.size() < ess_bdr.size()) {
24  SLIC_WARNING_ROOT("Multiple definition of essential boundary! Using first definition given.");
25  }
26 
27  ess_bdr_.emplace_back(ess_bdr_coef, component, space, filtered_attrs);
28  attrs_in_use_.insert(ess_bdr.begin(), ess_bdr.end());
29  all_dofs_valid_ = false;
30 }
31 
32 void BoundaryConditionManager::addEssential(const mfem::Array<int>& local_dofs,
33  std::shared_ptr<mfem::Coefficient> ess_bdr_coef,
34  mfem::ParFiniteElementSpace& space, std::optional<int> component)
35 {
36  // translate vector ldofs to tdofs (discarding ldofs that are not owned by this rank)
37  mfem::Array<int> true_dofs;
38  for (int j = 0; j < local_dofs.Size(); ++j) {
39  int tdof = space.GetLocalTDofNumber(local_dofs[j]);
40  if (tdof >= 0) true_dofs.Append(tdof);
41  }
42 
43  ess_bdr_.emplace_back(ess_bdr_coef, component, space, true_dofs);
44  all_dofs_valid_ = false;
45 }
46 
47 void BoundaryConditionManager::addEssentialByTrueDofs(const mfem::Array<int>& true_dofs,
48  std::shared_ptr<mfem::VectorCoefficient> ess_bdr_coef,
49  mfem::ParFiniteElementSpace& space)
50 {
51  ess_bdr_.emplace_back(ess_bdr_coef, std::nullopt, space, true_dofs);
52  all_dofs_valid_ = false;
53 }
54 
55 void BoundaryConditionManager::updateAllDofs() const
56 {
57  all_true_dofs_.DeleteAll();
58  all_local_dofs_.DeleteAll();
59  for (const auto& bc : ess_bdr_) {
60  all_true_dofs_.Append(bc.getTrueDofList());
61  all_local_dofs_.Append(bc.getLocalDofList());
62  }
63  all_true_dofs_.Sort();
64  all_local_dofs_.Sort();
65  all_true_dofs_.Unique();
66  all_local_dofs_.Unique();
67  all_dofs_valid_ = true;
68 }
69 
70 } // namespace smith
This file contains the declaration of the boundary condition manager class.
void addEssentialByTrueDofs(const mfem::Array< int > &true_dofs, std::shared_ptr< mfem::VectorCoefficient > ess_bdr_coef, mfem::ParFiniteElementSpace &space)
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.
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.