Serac  0.1
Serac is an implicit thermal strucural mechanics simulation code.
boundary_condition_helper.cpp
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 
8 
9 namespace serac::mfem_ext {
10 
11 void GetEssentialTrueDofsFromElementAttribute(const mfem::ParFiniteElementSpace& fespace,
12  const mfem::Array<int>& elem_attr_is_ess, mfem::Array<int>& ess_tdof_list,
13  int component)
14 {
15  mfem::Array<int> ess_dofs, true_ess_dofs;
16 
17  GetEssentialVDofsFromElementAttribute(fespace, elem_attr_is_ess, ess_dofs, component);
18  fespace.GetRestrictionMatrix()->BooleanMult(ess_dofs, true_ess_dofs);
19  fespace.MarkerToList(true_ess_dofs, ess_tdof_list);
20 }
21 
22 static void mark_dofs(const mfem::Array<int>& dofs, mfem::Array<int>& mark_array)
23 {
24  for (int i = 0; i < dofs.Size(); i++) {
25  int k = dofs[i];
26  if (k < 0) {
27  k = -1 - k;
28  }
29  mark_array[k] = -1;
30  }
31 }
32 
33 void GetEssentialVDofsFromElementAttribute(const mfem::ParFiniteElementSpace& fespace,
34  const mfem::Array<int>& elem_attr_is_ess, mfem::Array<int>& ess_vdofs,
35  int component)
36 {
37  MFEM_ASSERT(
38  fespace.GetParMesh()->attributes.Max() == elem_attr_is_ess.Size(),
39  "Length of elem_attr_is_ess must match the number of element attributes on the mesh associated with fespace");
40 
41  mfem::Array<int> vdofs, dofs;
42  ess_vdofs.SetSize(fespace.GetVSize());
43  ess_vdofs = 0;
44  for (int elem = 0; elem < fespace.GetNE(); elem++) {
45  if (elem_attr_is_ess[fespace.GetAttribute(elem) - 1]) {
46  if (component < 0) // mark all components
47  {
48  fespace.GetElementVDofs(elem, vdofs);
49  } else // mark only desired component
50  {
51  fespace.GetElementDofs(elem, dofs);
52  vdofs.SetSize(dofs.Size());
53  for (int d = 0; d < dofs.Size(); d++) {
54  vdofs[d] = fespace.DofToVDof(dofs[d], component);
55  }
56  }
57  mark_dofs(vdofs, ess_vdofs);
58  }
59  }
60  fespace.Synchronize(ess_vdofs);
61 }
62 
63 } // namespace serac::mfem_ext
This file contains the declarations of helper methods for boundary conditions.