www.mooseframework.org
BoundaryRestrictable.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 // MOOSE includes
16 #include "BoundaryRestrictable.h"
17 #include "Material.h"
18 #include "MooseMesh.h"
19 #include "MooseObject.h"
20 
21 template <>
24 {
25  // Create instance of InputParameters
27 
28  // Create user-facing 'boundary' input for restricting inheriting object to boundaries
29  params.addParam<std::vector<BoundaryName>>(
30  "boundary", "The list of boundary IDs from the mesh where this boundary condition applies");
31 
32  // A parameter for disabling error message for objects restrictable by boundary and block,
33  // if the parameter is valid it was already set so don't do anything
34  if (!params.isParamValid("_dual_restrictable"))
35  params.addPrivateParam<bool>("_dual_restrictable", false);
36 
37  return params;
38 }
39 
40 // Standard constructor
42  : _bnd_feproblem(moose_object->isParamValid("_fe_problem_base")
43  ? moose_object->getParam<FEProblemBase *>("_fe_problem_base")
44  : NULL),
45  _bnd_mesh(moose_object->isParamValid("_mesh") ? moose_object->getParam<MooseMesh *>("_mesh")
46  : NULL),
47  _bnd_dual_restrictable(moose_object->getParam<bool>("_dual_restrictable")),
48  _block_ids(_empty_block_ids),
49  _bnd_tid(moose_object->isParamValid("_tid") ? moose_object->getParam<THREAD_ID>("_tid") : 0),
50  _bnd_material_data(_bnd_feproblem->getMaterialData(Moose::BOUNDARY_MATERIAL_DATA, _bnd_tid)),
51  _bnd_nodal(nodal)
52 {
53  initializeBoundaryRestrictable(moose_object);
54 }
55 
56 // Dual restricted constructor
58  const std::set<SubdomainID> & block_ids,
59  bool nodal)
60  : _bnd_feproblem(moose_object->isParamValid("_fe_problem_base")
61  ? moose_object->getParam<FEProblemBase *>("_fe_problem_base")
62  : NULL),
63  _bnd_mesh(moose_object->isParamValid("_mesh") ? moose_object->getParam<MooseMesh *>("_mesh")
64  : NULL),
65  _bnd_dual_restrictable(moose_object->getParam<bool>("_dual_restrictable")),
66  _block_ids(block_ids),
67  _bnd_tid(moose_object->isParamValid("_tid") ? moose_object->getParam<THREAD_ID>("_tid") : 0),
69  _bnd_nodal(nodal)
70 {
71  initializeBoundaryRestrictable(moose_object);
72 }
73 
74 void
76 {
77  // The name and id of the object
78  const std::string & name = moose_object->getParam<std::string>("_object_name");
79 
80  // If the mesh pointer is not defined, but FEProblemBase is, get it from there
81  if (_bnd_feproblem != NULL && _bnd_mesh == NULL)
83 
84  // Check that the mesh pointer was defined, it is required for this class to operate
85  if (_bnd_mesh == NULL)
86  mooseError("The input parameters must contain a pointer to FEProblemBase via '_fe_problem' or "
87  "a pointer to the MooseMesh via '_mesh'");
88 
89  // If the user supplies boundary IDs
90  if (moose_object->isParamValid("boundary"))
91  {
92  // Extract the blocks from the input
93  _boundary_names = moose_object->getParam<std::vector<BoundaryName>>("boundary");
94 
95  // Get the IDs from the supplied names
96  std::vector<BoundaryID> vec_ids = _bnd_mesh->getBoundaryIDs(_boundary_names, true);
97 
98  // Store the IDs, handling ANY_BOUNDARY_ID if supplied
99  if (std::find(_boundary_names.begin(), _boundary_names.end(), "ANY_BOUNDARY_ID") !=
100  _boundary_names.end())
102  else
103  _bnd_ids.insert(vec_ids.begin(), vec_ids.end());
104  }
105 
106  // Produce error if the object is not allowed to be both block and boundary restricted
107  if (!_bnd_dual_restrictable && !_bnd_ids.empty() && !_block_ids.empty())
108  if (!_block_ids.empty() && _block_ids.find(Moose::ANY_BLOCK_ID) == _block_ids.end())
109  mooseError("Attempted to restrict the object '",
110  name,
111  "' to a boundary, but the object is already restricted by block(s)");
112 
113  // Store ANY_BOUNDARY_ID if empty
114  if (_bnd_ids.empty())
115  {
117  _boundary_names = {"ANY_BOUNDARY_ID"};
118  }
119 
120  // If this object is block restricted, check that defined blocks exist on the mesh
121  if (_bnd_ids.find(Moose::ANY_BOUNDARY_ID) == _bnd_ids.end())
122  {
123  const std::set<BoundaryID> * valid_ids;
124 
125  if (_bnd_nodal)
126  valid_ids = &_bnd_mesh->meshNodesetIds();
127  else
128  valid_ids = &_bnd_mesh->meshSidesetIds();
129 
130  std::vector<BoundaryID> diff;
131 
132  std::set_difference(_bnd_ids.begin(),
133  _bnd_ids.end(),
134  valid_ids->begin(),
135  valid_ids->end(),
136  std::back_inserter(diff));
137 
138  if (!diff.empty())
139  {
140  std::ostringstream msg;
141  msg << "The object '" << name
142  << "' contains the following boundary ids that do not exist on the mesh:";
143  for (const auto & id : diff)
144  msg << " " << id;
145  mooseError(msg.str());
146  }
147  }
148 }
149 
151 
152 const std::set<BoundaryID> &
154 {
155  return _bnd_ids;
156 }
157 
158 const std::vector<BoundaryName> &
160 {
161  return _boundary_names;
162 }
163 
164 unsigned int
166 {
167  return (unsigned int)_bnd_ids.size();
168 }
169 
170 bool
172 {
174 }
175 
176 bool
177 BoundaryRestrictable::restricted(const std::set<BoundaryID> & ids)
178 {
179  return ids.find(Moose::ANY_BOUNDARY_ID) == ids.end();
180 }
181 
182 bool
183 BoundaryRestrictable::hasBoundary(const BoundaryName & name) const
184 {
185  // Create a vector and utilize the getBoundaryIDs function, which
186  // handles the ANY_BOUNDARY_ID (getBoundaryID does not)
187  return hasBoundary(_bnd_mesh->getBoundaryIDs({name}));
188 }
189 
190 bool
191 BoundaryRestrictable::hasBoundary(const std::vector<BoundaryName> & names) const
192 {
193  return hasBoundary(_bnd_mesh->getBoundaryIDs(names));
194 }
195 
196 bool
198 {
199  if (_bnd_ids.empty() || _bnd_ids.find(Moose::ANY_BOUNDARY_ID) != _bnd_ids.end())
200  return true;
201  else
202  return _bnd_ids.find(id) != _bnd_ids.end();
203 }
204 
205 bool
206 BoundaryRestrictable::hasBoundary(const std::vector<BoundaryID> & ids, TEST_TYPE type) const
207 {
208  std::set<BoundaryID> ids_set(ids.begin(), ids.end());
209  return hasBoundary(ids_set, type);
210 }
211 
212 bool
213 BoundaryRestrictable::hasBoundary(const std::set<BoundaryID> & ids, TEST_TYPE type) const
214 {
215  // An empty input is assumed to be ANY_BOUNDARY_ID
216  if (ids.empty() || ids.find(Moose::ANY_BOUNDARY_ID) != ids.end())
217  return true;
218 
219  // All supplied IDs must match those of the object
220  else if (type == ALL)
221  {
222  if (_bnd_ids.find(Moose::ANY_BOUNDARY_ID) != _bnd_ids.end())
223  return true;
224  else
225  return std::includes(_bnd_ids.begin(), _bnd_ids.end(), ids.begin(), ids.end());
226  }
227  // Any of the supplied IDs must match those of the object
228  else
229  {
230  // Loop through the supplied ids
231  for (const auto & id : ids)
232  {
233  // Test the current supplied id
234  bool test = hasBoundary(id);
235 
236  // If the id exists in the stored ids, then return true, otherwise
237  if (test)
238  return true;
239  }
240  return false;
241  }
242 }
243 
244 bool
245 BoundaryRestrictable::isBoundarySubset(const std::set<BoundaryID> & ids) const
246 {
247  // An empty input is assumed to be ANY_BOUNDARY_ID
248  if (ids.empty() || ids.find(Moose::ANY_BOUNDARY_ID) != ids.end())
249  return true;
250 
251  if (_bnd_ids.find(Moose::ANY_BOUNDARY_ID) != _bnd_ids.end())
252  return std::includes(ids.begin(),
253  ids.end(),
254  _bnd_mesh->meshBoundaryIds().begin(),
255  _bnd_mesh->meshBoundaryIds().end());
256  else
257  return std::includes(ids.begin(), ids.end(), _bnd_ids.begin(), _bnd_ids.end());
258 }
259 
260 bool
261 BoundaryRestrictable::isBoundarySubset(const std::vector<BoundaryID> & ids) const
262 {
263  std::set<BoundaryID> ids_set(ids.begin(), ids.end());
264  return isBoundarySubset(ids_set);
265 }
266 
267 const std::set<BoundaryID> &
269 {
270  return _bnd_mesh->getBoundaryIDs();
271 }
272 
273 bool
275 {
276  // Reference to MaterialWarehouse for testing and retrieving boundary ids
278 
279  // Complete set of BoundaryIDs that this object is defined
280  const std::set<BoundaryID> & ids =
282 
283  // Loop over each BoundaryID for this object
284  for (const auto & id : ids)
285  {
286  // Storage of material properties that have been DECLARED on this BoundaryID
287  std::set<std::string> declared_props;
288 
289  // If boundary materials exist, populated the set of properties that were declared
290  if (warehouse.hasActiveBoundaryObjects(id))
291  {
292  const std::vector<std::shared_ptr<Material>> & mats = warehouse.getActiveBoundaryObjects(id);
293  for (const auto & mat : mats)
294  {
295  const std::set<std::string> & mat_props = mat->getSuppliedItems();
296  declared_props.insert(mat_props.begin(), mat_props.end());
297  }
298  }
299 
300  // If the supplied property is not in the list of properties on the current id, return false
301  if (declared_props.find(prop_name) == declared_props.end())
302  return false;
303  }
304 
305  // If you get here the supplied property is defined on all boundaries
306  return true;
307 }
virtual const std::set< BoundaryID > & boundaryIDs() const
Return the boundary IDs for this object.
virtual ~BoundaryRestrictable()
Empty class destructor.
unsigned int numBoundaryIDs() const
Return the number of boundaries for this object.
bool hasBoundaryMaterialPropertyHelper(const std::string &prop_name) const
A helper method to avoid circular #include problems.
void addPrivateParam(const std::string &name, const T &value)
These method add a parameter to the InputParameters object which can be retrieved like any other para...
void initializeBoundaryRestrictable(const MooseObject *moose_object)
An initialization routine needed for dual constructors.
const std::map< BoundaryID, std::vector< std::shared_ptr< T > > > & getActiveBoundaryObjects(THREAD_ID tid=0) const
std::vector< BoundaryID > getBoundaryIDs(const Elem *const elem, const unsigned short int side) const
Returns a vector of boundary IDs for the requested element on the requested side. ...
Definition: MooseMesh.C:1951
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
const std::set< BoundaryID > & meshBoundaryIds() const
Returns a read-only reference to the set of boundary IDs currently present in the Mesh...
Definition: MooseMesh.C:2110
MooseMesh * _bnd_mesh
Point to mesh.
const std::set< BoundaryID > & meshSidesetIds() const
Returns a read-only reference to the set of sidesets currently present in the Mesh.
Definition: MooseMesh.C:2116
virtual bool boundaryRestricted() const
Returns true if this object has been restricted to a boundary.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Material objects are special in that they have additional objects created automatically (see FEProble...
const bool _bnd_dual_restrictable
Flag for allowing dual restriction with BlockRestrictable.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
const std::set< BoundaryID > & meshBoundaryIDs() const
Returns the set of all boundary ids for the entire mesh.
InputParameters emptyInputParameters()
const std::vector< BoundaryName > & boundaryNames() const
Return the boundary names for this object.
THREAD_ID _bnd_tid
Thread id for this object.
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.
const std::set< BoundaryID > & meshNodesetIds() const
Returns a read-only reference to the set of nodesets currently present in the Mesh.
Definition: MooseMesh.C:2122
InputParameters validParams< BoundaryRestrictable >()
static bool restricted(const std::set< BoundaryID > &ids)
Helper for determining if the object is boundary restricted.
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:36
bool hasActiveBoundaryObjects(THREAD_ID tid=0) const
std::set< BoundaryID > _bnd_ids
Set of the boundary ids.
bool isBoundarySubset(const std::set< BoundaryID > &ids) const
Test if the class boundary ids are a subset of the supplied objects.
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:74
bool hasBoundary(const BoundaryName &name) const
Test if the supplied boundary name is valid for this object.
TEST_TYPE
A flag changing the behavior of hasBoundary.
bool _bnd_nodal
Whether or not this object is restricted to nodesets.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseObject.h:67
std::shared_ptr< MaterialData > _bnd_material_data
Pointer to MaterialData for boundary (.
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition: MooseObject.h:122
const MaterialWarehouse & getMaterialWarehouse()
MatType type
const SubdomainID ANY_BLOCK_ID
Definition: MooseTypes.h:117
std::vector< BoundaryName > _boundary_names
Vector the the boundary names.
virtual MooseMesh & mesh() override
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
const std::set< SubdomainID > & _block_ids
Reference to the block_ids, defaults to an empty set if not provided.
FEProblemBase * _bnd_feproblem
Pointer to FEProblemBase.
Definition: Moose.h:84
BoundaryRestrictable(const MooseObject *moose_object, bool nodal)
Class constructor Populates the _bnd_ids for the given boundary names supplied with the &#39;boundary&#39; in...
const BoundaryID ANY_BOUNDARY_ID
Definition: MooseTypes.h:119
boundary_id_type BoundaryID
Definition: MooseTypes.h:75
unsigned int THREAD_ID
Definition: MooseTypes.h:79