www.mooseframework.org
Attributes.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 #include "Attributes.h"
11 
12 #include "TaggingInterface.h"
13 #include "BoundaryRestrictable.h"
14 #include "BlockRestrictable.h"
15 #include "SetupInterface.h"
16 #include "MooseVariableInterface.h"
17 #include "MooseVariableFE.h"
18 #include "ElementUserObject.h"
19 #include "SideUserObject.h"
20 #include "InternalSideUserObject.h"
21 #include "InterfaceUserObject.h"
22 #include "NodalUserObject.h"
23 #include "GeneralUserObject.h"
25 #include "ShapeUserObject.h"
26 #include "ShapeSideUserObject.h"
27 #include "ShapeElementUserObject.h"
28 
29 bool
30 AttribTagBase::isMatch(const Attribute & other) const
31 {
32  auto a = dynamic_cast<const AttribTagBase *>(&other);
33  if (!a || a->_vals.size() < 1)
34  return false;
35 
36  auto cond = a->_vals[0];
37  for (auto val : _vals)
38  if (val == cond)
39  return true;
40  return false;
41 }
42 
43 bool
44 AttribTagBase::isEqual(const Attribute & other) const
45 {
46  auto a = dynamic_cast<const AttribTagBase *>(&other);
47  if (!a || a->_vals.size() != _vals.size())
48  return false;
49 
50  for (size_t i = 0; i < a->_vals.size(); i++)
51  if (a->_vals[i] != _vals[i])
52  return false;
53  return true;
54 }
55 
56 void
58 {
59  _vals.clear();
60  auto t = dynamic_cast<const TaggingInterface *>(obj);
61  if (t)
62  {
63  for (auto & tag : t->getMatrixTags())
64  _vals.push_back(static_cast<int>(tag));
65  }
66 }
67 
68 void
70 {
71  _vals.clear();
72  auto t = dynamic_cast<const TaggingInterface *>(obj);
73  if (t)
74  {
75  for (auto & tag : t->getVectorTags())
76  _vals.push_back(static_cast<int>(tag));
77  }
78 }
79 
80 void
82 {
83  _vals.clear();
84  auto sup = dynamic_cast<const SetupInterface *>(obj);
85  if (sup)
86  {
87  auto e = sup->getExecuteOnEnum();
88  for (auto & on : e.items())
89  if (e.contains(on))
90  _vals.push_back(on);
91  }
92 }
93 
94 bool
95 AttribExecOns::isMatch(const Attribute & other) const
96 {
97  auto a = dynamic_cast<const AttribExecOns *>(&other);
98  if (!a || a->_vals.size() < 1)
99  return false;
100  auto cond = a->_vals[0];
101  if (cond == Moose::ALL)
102  return true;
103 
104  for (auto val : _vals)
105  if (val == Moose::ALL || val == cond)
106  return true;
107  return false;
108 }
109 
110 bool
111 AttribExecOns::isEqual(const Attribute & other) const
112 {
113  auto a = dynamic_cast<const AttribExecOns *>(&other);
114  if (!a || a->_vals.size() != _vals.size())
115  return false;
116 
117  for (size_t i = 0; i < a->_vals.size(); i++)
118  if (a->_vals[i] != _vals[i])
119  return false;
120  return true;
121 }
122 
123 void
125 {
126  _vals.clear();
127  auto blk = dynamic_cast<const BlockRestrictable *>(obj);
128  if (blk && blk->blockRestricted())
129  {
130  for (auto id : blk->blockIDs())
131  _vals.push_back(id);
132  }
133  else
134  _vals.push_back(Moose::ANY_BLOCK_ID);
135 }
136 
137 bool
139 {
140  auto a = dynamic_cast<const AttribSubdomains *>(&other);
141  if (!a || a->_vals.size() < 1)
142  return false;
143 
144  auto cond = a->_vals[0];
145  if (cond == Moose::ANY_BLOCK_ID)
146  return true;
147  for (auto id : _vals)
148  {
149  if (id == cond || id == Moose::ANY_BLOCK_ID)
150  return true;
151  }
152  return false;
153 }
154 
155 bool
157 {
158  auto a = dynamic_cast<const AttribSubdomains *>(&other);
159  if (!a || a->_vals.size() != _vals.size())
160  return false;
161 
162  for (size_t i = 0; i < a->_vals.size(); i++)
163  if (a->_vals[i] != _vals[i])
164  return false;
165  return true;
166 }
167 
168 void
170 {
171  _vals.clear();
172  auto bnd = dynamic_cast<const BoundaryRestrictable *>(obj);
173  if (bnd && bnd->boundaryRestricted())
174  {
175  for (auto & bound : bnd->boundaryIDs())
176  _vals.push_back(bound);
177  }
178  else
179  _vals.push_back(Moose::ANY_BOUNDARY_ID);
180 }
181 
182 bool
184 {
185  auto a = dynamic_cast<const AttribBoundaries *>(&other);
186  if (!a || a->_vals.size() < 1)
187  return false;
188 
189  auto cond = a->_vals[0];
190  if (cond == Moose::ANY_BOUNDARY_ID)
191  return true;
192  for (auto id : _vals)
193  {
194  if (id == cond || (!a->_must_be_restricted && (id == Moose::ANY_BOUNDARY_ID)))
195  return true;
196  }
197  return false;
198 }
199 
200 bool
202 {
203  auto a = dynamic_cast<const AttribBoundaries *>(&other);
204  if (!a || a->_vals.size() != _vals.size())
205  return false;
206 
207  for (size_t i = 0; i < a->_vals.size(); i++)
208  if (a->_vals[i] != _vals[i])
209  return false;
210  return true;
211 }
212 
213 void
215 {
216  _val = obj->getParam<THREAD_ID>("_tid");
217 }
218 bool
219 AttribThread::isMatch(const Attribute & other) const
220 {
221  auto a = dynamic_cast<const AttribThread *>(&other);
222  return a && (a->_val == _val);
223 }
224 bool
225 AttribThread::isEqual(const Attribute & other) const
226 {
227  return isMatch(other);
228 }
229 
230 void
232 {
233 }
234 bool
235 AttribPreIC::isMatch(const Attribute & other) const
236 {
237  auto a = dynamic_cast<const AttribPreIC *>(&other);
238  return a && (a->_val == _val);
239 }
240 
241 bool
242 AttribPreIC::isEqual(const Attribute & other) const
243 {
244  return isMatch(other);
245 }
246 
247 void
249 {
250 }
251 bool
252 AttribPreAux::isMatch(const Attribute & other) const
253 {
254  auto a = dynamic_cast<const AttribPreAux *>(&other);
255  return a && (a->_val == _val);
256 }
257 
258 bool
259 AttribPreAux::isEqual(const Attribute & other) const
260 {
261  return isMatch(other);
262 }
263 
264 void
266 {
267  _val = obj->name();
268 }
269 bool
270 AttribName::isMatch(const Attribute & other) const
271 {
272  auto a = dynamic_cast<const AttribName *>(&other);
273  return a && (a->_val == _val);
274 }
275 
276 bool
277 AttribName::isEqual(const Attribute & other) const
278 {
279  return isMatch(other);
280 }
281 
282 void
284 {
285 }
286 bool
287 AttribSystem::isMatch(const Attribute & other) const
288 {
289  auto a = dynamic_cast<const AttribSystem *>(&other);
290  return a && (a->_val == _val);
291 }
292 
293 bool
294 AttribSystem::isEqual(const Attribute & other) const
295 {
296  return isMatch(other);
297 }
298 
299 void
301 {
302  auto vi = dynamic_cast<const MooseVariableInterface<Real> *>(obj);
303  if (vi)
304  _val = static_cast<int>(vi->mooseVariable()->number());
305 }
306 bool
307 AttribVar::isMatch(const Attribute & other) const
308 {
309  auto a = dynamic_cast<const AttribVar *>(&other);
310  return a && (a->_val == _val);
311 }
312 
313 bool
314 AttribVar::isEqual(const Attribute & other) const
315 {
316  return isMatch(other);
317 }
318 
319 void
321 {
322  _val = 0;
323  // clang-format off
324  _val |= (unsigned int)Interfaces::UserObject * (dynamic_cast<const UserObject *>(obj) != nullptr);
325  _val |= (unsigned int)Interfaces::ElementUserObject * (dynamic_cast<const ElementUserObject *>(obj) != nullptr);
326  _val |= (unsigned int)Interfaces::SideUserObject * (dynamic_cast<const SideUserObject *>(obj) != nullptr);
327  _val |= (unsigned int)Interfaces::InternalSideUserObject * (dynamic_cast<const InternalSideUserObject *>(obj) != nullptr);
328  _val |= (unsigned int)Interfaces::InterfaceUserObject * (dynamic_cast<const InterfaceUserObject *>(obj) != nullptr);
329  _val |= (unsigned int)Interfaces::NodalUserObject * (dynamic_cast<const NodalUserObject *>(obj) != nullptr);
330  _val |= (unsigned int)Interfaces::GeneralUserObject * (dynamic_cast<const GeneralUserObject *>(obj) != nullptr);
331  _val |= (unsigned int)Interfaces::ThreadedGeneralUserObject * (dynamic_cast<const ThreadedGeneralUserObject *>(obj) != nullptr);
332  _val |= (unsigned int)Interfaces::ShapeElementUserObject * (dynamic_cast<const ShapeElementUserObject *>(obj) != nullptr);
333  _val |= (unsigned int)Interfaces::ShapeSideUserObject * (dynamic_cast<const ShapeSideUserObject *>(obj) != nullptr);
334  _val |= (unsigned int)Interfaces::Postprocessor * (dynamic_cast<const Postprocessor *>(obj) != nullptr);
335  _val |= (unsigned int)Interfaces::VectorPostprocessor * (dynamic_cast<const VectorPostprocessor *>(obj) != nullptr);
336  // clang-format on
337 }
338 
339 bool
341 {
342  auto a = dynamic_cast<const AttribInterfaces *>(&other);
343  return a && (a->_val & _val);
344 }
345 
346 bool
348 {
349  auto a = dynamic_cast<const AttribInterfaces *>(&other);
350  return a && (a->_val == _val);
351 }
virtual void initFrom(const MooseObject *obj) override
initFrom reads and stores the desired meta-data from obj for later matching comparisons.
Definition: Attributes.C:69
std::vector< SubdomainID > _vals
Definition: Attributes.h:116
virtual bool isEqual(const Attribute &other) const override
isEqual returns true if the meta-data stored in this attribute is identical to that stored in other...
Definition: Attributes.C:44
virtual void initFrom(const MooseObject *obj) override
initFrom reads and stores the desired meta-data from obj for later matching comparisons.
Definition: Attributes.C:231
virtual bool isMatch(const Attribute &other) const override
isMatch returns true if the meta-data stored in this attribute is equivalent to that stored in other...
Definition: Attributes.C:30
std::string _val
Definition: Attributes.h:193
virtual bool isMatch(const Attribute &other) const override
isMatch returns true if the meta-data stored in this attribute is equivalent to that stored in other...
Definition: Attributes.C:270
Attribute is an abstract class that can be implemented in order to track custom metadata about MooseO...
Definition: TheWarehouse.h:31
virtual void initFrom(const MooseObject *obj) override
initFrom reads and stores the desired meta-data from obj for later matching comparisons.
Definition: Attributes.C:214
virtual void initFrom(const MooseObject *obj) override
initFrom reads and stores the desired meta-data from obj for later matching comparisons.
Definition: Attributes.C:300
virtual bool isEqual(const Attribute &other) const override
isEqual returns true if the meta-data stored in this attribute is identical to that stored in other...
Definition: Attributes.C:111
std::vector< BoundaryID > _vals
Definition: Attributes.h:134
TODO: delete this later - it is a temporary hack for dealing with inter-system dependencies.
Definition: Attributes.h:168
/class BoundaryRestrictable /brief Provides functionality for limiting the object to certain boundary...
virtual void initFrom(const MooseObject *obj) override
initFrom reads and stores the desired meta-data from obj for later matching comparisons.
Definition: Attributes.C:81
virtual bool isEqual(const Attribute &other) const override
isEqual returns true if the meta-data stored in this attribute is identical to that stored in other...
Definition: Attributes.C:156
virtual bool isMatch(const Attribute &other) const override
isMatch returns true if the meta-data stored in this attribute is equivalent to that stored in other...
Definition: Attributes.C:138
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition: MooseObject.h:191
virtual void initFrom(const MooseObject *obj) override
initFrom reads and stores the desired meta-data from obj for later matching comparisons.
Definition: Attributes.C:265
virtual bool isEqual(const Attribute &other) const override
isEqual returns true if the meta-data stored in this attribute is identical to that stored in other...
Definition: Attributes.C:201
virtual bool isEqual(const Attribute &other) const override
isEqual returns true if the meta-data stored in this attribute is identical to that stored in other...
Definition: Attributes.C:314
TODO: delete this later - it is a temporary hack for dealing with inter-system dependencies.
Definition: Attributes.h:153
virtual bool isMatch(const Attribute &other) const override
isMatch returns true if the meta-data stored in this attribute is equivalent to that stored in other...
Definition: Attributes.C:219
virtual void initFrom(const MooseObject *obj) override
initFrom reads and stores the desired meta-data from obj for later matching comparisons.
Definition: Attributes.C:283
virtual bool isMatch(const Attribute &other) const override
isMatch returns true if the meta-data stored in this attribute is equivalent to that stored in other...
Definition: Attributes.C:183
std::vector< unsigned int > _vals
Definition: Attributes.h:99
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:42
const ExecFlagEnum & getExecuteOnEnum() const
Return the execute on MultiMooseEnum for this object.
virtual bool isMatch(const Attribute &other) const override
isMatch returns true if the meta-data stored in this attribute is equivalent to that stored in other...
Definition: Attributes.C:252
virtual bool isMatch(const Attribute &other) const override
isMatch returns true if the meta-data stored in this attribute is equivalent to that stored in other...
Definition: Attributes.C:340
virtual bool isMatch(const Attribute &other) const override
isMatch returns true if the meta-data stored in this attribute is equivalent to that stored in other...
Definition: Attributes.C:287
virtual bool isEqual(const Attribute &other) const override
isEqual returns true if the meta-data stored in this attribute is identical to that stored in other...
Definition: Attributes.C:347
virtual void initFrom(const MooseObject *obj) override
initFrom reads and stores the desired meta-data from obj for later matching comparisons.
Definition: Attributes.C:57
virtual void initFrom(const MooseObject *obj) override
initFrom reads and stores the desired meta-data from obj for later matching comparisons.
Definition: Attributes.C:169
virtual bool isMatch(const Attribute &other) const override
isMatch returns true if the meta-data stored in this attribute is equivalent to that stored in other...
Definition: Attributes.C:95
const SubdomainID ANY_BLOCK_ID
Definition: MooseTypes.C:15
virtual bool isMatch(const Attribute &other) const override
isMatch returns true if the meta-data stored in this attribute is equivalent to that stored in other...
Definition: Attributes.C:235
std::vector< unsigned int > _vals
Definition: Attributes.h:65
virtual bool isEqual(const Attribute &other) const override
isEqual returns true if the meta-data stored in this attribute is identical to that stored in other...
Definition: Attributes.C:225
An interface that restricts an object to subdomains via the &#39;blocks&#39; input parameter.
virtual bool isEqual(const Attribute &other) const override
isEqual returns true if the meta-data stored in this attribute is identical to that stored in other...
Definition: Attributes.C:277
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:59
virtual bool isEqual(const Attribute &other) const override
isEqual returns true if the meta-data stored in this attribute is identical to that stored in other...
Definition: Attributes.C:242
virtual void initFrom(const MooseObject *obj) override
initFrom reads and stores the desired meta-data from obj for later matching comparisons.
Definition: Attributes.C:320
virtual bool isMatch(const Attribute &other) const override
isMatch returns true if the meta-data stored in this attribute is equivalent to that stored in other...
Definition: Attributes.C:307
virtual bool isEqual(const Attribute &other) const override
isEqual returns true if the meta-data stored in this attribute is identical to that stored in other...
Definition: Attributes.C:294
virtual void initFrom(const MooseObject *obj) override
initFrom reads and stores the desired meta-data from obj for later matching comparisons.
Definition: Attributes.C:248
std::string _val
Definition: Attributes.h:209
virtual bool isEqual(const Attribute &other) const override
isEqual returns true if the meta-data stored in this attribute is identical to that stored in other...
Definition: Attributes.C:259
virtual void initFrom(const MooseObject *obj) override
initFrom reads and stores the desired meta-data from obj for later matching comparisons.
Definition: Attributes.C:124
const BoundaryID ANY_BOUNDARY_ID
Definition: MooseTypes.C:17
unsigned int THREAD_ID
Definition: MooseTypes.h:161
THREAD_ID _val
Definition: Attributes.h:149