https://mooseframework.inl.gov
MFEMBoundaryRestrictable.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #ifdef MFEM_ENABLED
11 
13 
16 {
17  // Create InputParameters object that will be appended to the parameters for the inheriting object
19  params.addParam<std::vector<BoundaryName>>(
20  "boundary",
21  {"-1"},
22  "The list of boundaries (ids or names) from the mesh where this object applies. "
23  "Defaults to all boundaries.");
24  return params;
25 }
26 
28  const mfem::ParMesh & mfem_mesh)
29  : _mfem_mesh(mfem_mesh),
30  _boundary_names(parameters.get<std::vector<BoundaryName>>("boundary")),
31  _boundary_attributes(_boundary_names.size())
32 {
34  if (!_boundary_attributes.IsEmpty())
35  mfem::common::AttrToMarker(
36  _mfem_mesh.bdr_attributes.Max(), _boundary_attributes, _boundary_markers);
37 }
38 
39 mfem::Array<int>
40 MFEMBoundaryRestrictable::boundariesToAttributes(const std::vector<BoundaryName> & boundary_names)
41 {
42  mfem::Array<int> attributes(boundary_names.size());
43  auto & mesh = getMesh();
44  std::transform(
45  boundary_names.begin(),
46  boundary_names.end(),
47  attributes.begin(),
48  [&mesh](const BoundaryName & boundary) -> int
49  {
50  try
51  {
52  // Is this a sideset ID?
53  return std::stoi(boundary);
54  }
55  catch (...)
56  {
57  // It was not
58  auto & boundary_ids = mesh.bdr_attribute_sets.GetAttributeSet(boundary);
59  if (boundary_ids.Size() != 1)
60  mooseError(
61  "There should be a 1-to-1 correspondence between boundary name and boundary ID");
62  return boundary_ids[0];
63  }
64  });
65  return attributes;
66 }
67 
68 #endif
const mfem::ParMesh & getMesh()
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
Definition: MooseUtils.h:1155
static InputParameters validParams()
MeshBase & mesh
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
InputParameters emptyInputParameters()
mfem::Array< int > _boundary_markers
Boolean array indicating which boundaries are active in this object.
std::vector< BoundaryName > _boundary_names
Stores the names of the boundaries.
const mfem::ParMesh & _mfem_mesh
Stores the names of the boundaries.
mfem::Array< int > boundariesToAttributes(const std::vector< BoundaryName > &boundary_names)
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
MFEMBoundaryRestrictable(const InputParameters &parameters, const mfem::ParMesh &mfem_mesh)
mfem::Array< int > _boundary_attributes
Array storing boundary attribute IDs for this object.