https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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 MOOSE_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(boundariesToAttributes())
32{
33 if (!_boundary_attributes.IsEmpty())
34 mfem::common::AttrToMarker(
36}
37
38mfem::Array<int>
40{
41 mfem::Array<int> attributes(_boundary_names.size());
42 auto & mesh = getMesh();
43 std::transform(
44 _boundary_names.begin(),
45 _boundary_names.end(),
46 attributes.begin(),
47 [&mesh](const BoundaryName & boundary) -> int
48 {
49 try
50 {
51 // Is this a sideset ID?
52 return std::stoi(boundary);
53 }
54 catch (...)
55 {
56 // It was not
57 auto & boundary_ids = mesh.bdr_attribute_sets.GetAttributeSet(boundary);
58 if (boundary_ids.Size() != 1)
60 "There should be a 1-to-1 correspondence between boundary name and boundary ID");
61 return boundary_ids[0];
62 }
63 });
64 return attributes;
65}
66
67std::vector<std::string>
69{
70 const auto & attrs = _boundary_attributes;
71 std::vector<std::string> strs(attrs.Size());
72 std::transform(attrs.begin(), attrs.end(), strs.begin(), [](int n) { return std::to_string(n); });
73 return strs;
74}
75
76#endif
InputParameters emptyInputParameters()
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
mfem::Array< int > _boundary_attributes
Array storing boundary attribute IDs for this object.
mfem::Array< int > boundariesToAttributes()
std::vector< BoundaryName > _boundary_names
Stores the names of the boundaries.
mfem::Array< int > _boundary_markers
Boolean array indicating which boundaries are active in this object.
std::vector< std::string > boundariesToStrings()
const mfem::ParMesh & getMesh()
MFEMBoundaryRestrictable(const InputParameters &parameters, const mfem::ParMesh &mfem_mesh)
const mfem::ParMesh & _mfem_mesh
Stores the names of the boundaries.
static InputParameters validParams()
MeshBase & mesh