https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MFEMBlockRestrictable.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<SubdomainName>>(
20 "block",
21 {},
22 "The list of subdomains (names or ids) that this object will be restricted to. "
23 "Leave empty to apply to all subdomains.");
24 return params;
25}
26
28 const mfem::ParMesh & mfem_mesh)
29 : _mfem_mesh(mfem_mesh),
30 _subdomain_names(parameters.get<std::vector<SubdomainName>>("block")),
31 _subdomain_attributes(subdomainsToAttributes(parameters)),
32 _subdomain_markers(_mfem_mesh.attributes.IsEmpty()
33 ? mfem::Array<int>()
34 : mfem::AttributeSets::AttrToMarker(_mfem_mesh.attributes.Max(),
35 _subdomain_attributes.IsEmpty()
36 ? _mfem_mesh.attributes
37 : _subdomain_attributes))
38{
39}
40
41mfem::Array<int>
43{
44 mfem::Array<int> attributes;
45 auto & mesh = getMesh();
46
47 for (const SubdomainName & subdomain_name : _subdomain_names)
48 {
49 try
50 {
51 // Is this a block ID?
52 const int attribute_id = std::stoi(subdomain_name);
53 attributes.Append(attribute_id);
54 }
55 catch (...)
56 {
57 // It was not
58 if (!mesh.attribute_sets.AttributeSetExists(subdomain_name))
59 parameters.paramError("block", "the mesh has no block named '", subdomain_name, "'.");
60 auto & subdomain_ids = mesh.attribute_sets.GetAttributeSet(subdomain_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.attributes.Find(attribute) == -1)
68 parameters.paramError("block", "the mesh has no block with ID ", attribute, ".");
69 return attributes;
70}
71
72std::vector<std::string>
74{
75 const auto & attrs = _subdomain_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.
std::vector< std::string > subdomainsToStrings()
std::vector< SubdomainName > _subdomain_names
Stores the names of the subdomains.
mfem::Array< int > subdomainsToAttributes(const InputParameters &parameters)
Converts the block names and IDs to mesh attributes, checking that the mesh has them.
static InputParameters validParams()
const mfem::ParMesh & getMesh() const
MFEMBlockRestrictable(const InputParameters &parameters, const mfem::ParMesh &mfem_mesh)
mfem::Array< int > _subdomain_attributes
Array storing subdomain attribute IDs for this object.
MeshBase & mesh