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 {},
22 "The list of boundaries (names or ids) that this object will be restricted to. "
23 "Leave empty to apply 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(parameters)),
32 _boundary_markers(_mfem_mesh.bdr_attributes.IsEmpty()
33 ? mfem::Array<int>()
34 : mfem::AttributeSets::AttrToMarker(_mfem_mesh.bdr_attributes.Max(),
35 _boundary_attributes.IsEmpty()
36 ? _mfem_mesh.bdr_attributes
37 : _boundary_attributes))
38{
39}
40
41mfem::Array<int>
43{
44 mfem::Array<int> attributes;
45 auto & mesh = getMesh();
46
47 for (const BoundaryName & boundary_name : _boundary_names)
48 {
49 try
50 {
51 // Is this a boundary ID?
52 const int attribute_id = std::stoi(boundary_name);
53 attributes.Append(attribute_id);
54 }
55 catch (...)
56 {
57 // It was not
58 if (!mesh.bdr_attribute_sets.AttributeSetExists(boundary_name))
59 parameters.paramError("boundary", "the mesh has no boundary named '", boundary_name, "'.");
60 auto & subdomain_ids = mesh.bdr_attribute_sets.GetAttributeSet(boundary_name);
61 for (const auto & subdomain_id : subdomain_ids)
62 attributes.Append(subdomain_id);
63 }
64 }
65
66 for (const auto attribute : attributes)
67 if (mesh.bdr_attributes.Find(attribute) == -1)
68 parameters.paramError("boundary", "the mesh has no boundary with ID ", attribute, ".");
69 return attributes;
70}
71
72std::vector<std::string>
74{
75 const auto & attrs = _boundary_attributes;
76 std::vector<std::string> strs(attrs.Size());
77 std::transform(attrs.begin(), attrs.end(), strs.begin(), [](int n) { return std::to_string(n); });
78 return strs;
79}
80
81#endif
InputParameters emptyInputParameters()
void ErrorVector unsigned int
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.
void paramError(const std::string &param, Args... args) const
Emits a parameter error prefixed with the parameter location and object information if available.
mfem::Array< int > _boundary_attributes
Array storing boundary attribute IDs for this object.
std::vector< BoundaryName > _boundary_names
Stores the names of the boundaries.
std::vector< std::string > boundariesToStrings()
const mfem::ParMesh & getMesh()
mfem::Array< int > boundariesToAttributes(const InputParameters &parameters)
Converts the boundary names and IDs to mesh attributes, checking that the mesh has them.
MFEMBoundaryRestrictable(const InputParameters &parameters, const mfem::ParMesh &mfem_mesh)
static InputParameters validParams()
MeshBase & mesh