Line data Source code
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 : #pragma once
11 :
12 : #include "MooseHashing.h"
13 : #include "TheWarehouse.h"
14 : #include "Moose.h"
15 :
16 : #include <ostream>
17 : #include <tuple>
18 : #include <type_traits>
19 :
20 : enum class Interfaces
21 : {
22 : UserObject = 1 << 1,
23 : ElementUserObject = 1 << 2,
24 : SideUserObject = 1 << 3,
25 : InternalSideUserObject = 1 << 4,
26 : NodalUserObject = 1 << 5,
27 : GeneralUserObject = 1 << 6,
28 : ThreadedGeneralUserObject = 1 << 7,
29 : ShapeElementUserObject = 1 << 8,
30 : ShapeSideUserObject = 1 << 9,
31 : Postprocessor = 1 << 10,
32 : VectorPostprocessor = 1 << 11,
33 : InterfaceUserObject = 1 << 12,
34 : BlockRestrictable = 1 << 13,
35 : BoundaryRestrictable = 1 << 14,
36 : Reporter = 1 << 15,
37 : DomainUserObject = 1 << 16,
38 : MortarUserObject = 1 << 17
39 : };
40 :
41 : template <>
42 : struct enable_bitmask_operators<Interfaces>
43 : {
44 : static const bool enable = true;
45 : };
46 :
47 : std::ostream & operator<<(std::ostream & os, Interfaces & iface);
48 :
49 : #define clonefunc(T) \
50 : virtual std::unique_ptr<Attribute> clone() const override \
51 : { \
52 : return std::unique_ptr<Attribute>(new T(*this)); \
53 : }
54 :
55 : #define hashfunc(...) \
56 : virtual size_t hash() const override \
57 : { \
58 : size_t h = 0; \
59 : Moose::hash_combine(h, __VA_ARGS__); \
60 : return h; \
61 : }
62 :
63 : /// AttribTagBase tracks all (vector or matrix) tags associated with an object.
64 : /// When running queries, an object matches true if it has at least one tag in
65 : /// common with the tags in the query attribute.
66 : class AttribTagBase : public Attribute
67 : {
68 : public:
69 : AttribTagBase(TheWarehouse & w, const std::string & attrib_name) : Attribute(w, attrib_name) {}
70 125630 : AttribTagBase(TheWarehouse & w, TagID tag, const std::string & attrib_name)
71 125630 : : Attribute(w, attrib_name)
72 : {
73 125630 : _vals.push_back(tag);
74 125630 : }
75 8407372 : AttribTagBase(TheWarehouse & w, const std::set<TagID> & tags, const std::string & attrib_name)
76 8407372 : : Attribute(w, attrib_name)
77 : {
78 28838572 : for (auto tag : tags)
79 20431200 : _vals.push_back(tag);
80 8407372 : }
81 :
82 : virtual bool isMatch(const Attribute & other) const override;
83 : virtual bool isEqual(const Attribute & other) const override;
84 8497347 : hashfunc(_vals);
85 :
86 : protected:
87 : std::vector<TagID> _vals;
88 : };
89 :
90 : class AttribMatrixTags : public AttribTagBase
91 : {
92 : public:
93 : typedef unsigned int Key;
94 : void setFrom(Key k)
95 : {
96 : _vals.clear();
97 : _vals.push_back(k);
98 : }
99 :
100 : AttribMatrixTags(TheWarehouse & w) : AttribTagBase(w, "matrix_tags") {}
101 62754 : AttribMatrixTags(TheWarehouse & w, TagID tag) : AttribTagBase(w, tag, "matrix_tags") {}
102 2167619 : AttribMatrixTags(TheWarehouse & w, const std::set<TagID> & tags)
103 2167619 : : AttribTagBase(w, tags, "matrix_tags")
104 : {
105 2167619 : }
106 : virtual void initFrom(const MooseObject * obj) override;
107 330354 : clonefunc(AttribMatrixTags);
108 : };
109 :
110 : class AttribVectorTags : public AttribTagBase
111 : {
112 : public:
113 337035 : clonefunc(AttribVectorTags);
114 :
115 : typedef unsigned int Key;
116 : void setFrom(Key k)
117 : {
118 : _vals.clear();
119 : _vals.push_back(k);
120 : }
121 :
122 : AttribVectorTags(TheWarehouse & w) : AttribTagBase(w, "vector_tags") {}
123 62876 : AttribVectorTags(TheWarehouse & w, TagID tag) : AttribTagBase(w, tag, "vector_tags") {}
124 6239753 : AttribVectorTags(TheWarehouse & w, const std::set<TagID> & tags)
125 6239753 : : AttribTagBase(w, tags, "vector_tags")
126 : {
127 6239753 : }
128 : virtual void initFrom(const MooseObject * obj) override;
129 : };
130 :
131 : class AttribExecOns : public Attribute
132 : {
133 : public:
134 : /// Execute flag that is used to represent all flags when querying AttribExecOns
135 : static const ExecFlagType EXEC_ALL;
136 :
137 : typedef int Key;
138 : void setFrom(Key k)
139 : {
140 : _vals.clear();
141 : _vals.push_back(k);
142 : }
143 :
144 : AttribExecOns(TheWarehouse & w) : Attribute(w, "exec_ons") {}
145 62754 : AttribExecOns(TheWarehouse & w, const int id) : Attribute(w, "exec_ons"), _vals({id}) {}
146 17096249 : AttribExecOns(TheWarehouse & w, const ExecFlagType & exec_flag)
147 17096249 : : Attribute(w, "exec_ons"), _vals({exec_flag.id()})
148 : {
149 17096249 : }
150 : virtual void initFrom(const MooseObject * obj) override;
151 : virtual bool isMatch(const Attribute & other) const override;
152 : virtual bool isEqual(const Attribute & other) const override;
153 27596881 : hashfunc(_vals);
154 33161883 : clonefunc(AttribExecOns);
155 :
156 : private:
157 : std::vector<Key> _vals;
158 : };
159 :
160 : class AttribSubdomains : public Attribute
161 : {
162 : public:
163 : typedef SubdomainID Key;
164 1045555 : void setFrom(Key k)
165 : {
166 1045555 : _vals.clear();
167 1045555 : _vals.push_back(k);
168 1045555 : }
169 :
170 194729 : AttribSubdomains(TheWarehouse & w) : Attribute(w, "subdomains") {}
171 5408372 : AttribSubdomains(TheWarehouse & w, SubdomainID id) : Attribute(w, "subdomains")
172 : {
173 5408372 : _vals.push_back(id);
174 5408372 : }
175 : virtual void initFrom(const MooseObject * obj) override;
176 : virtual bool isMatch(const Attribute & other) const override;
177 : virtual bool isEqual(const Attribute & other) const override;
178 6571599 : hashfunc(_vals);
179 468846 : clonefunc(AttribSubdomains);
180 :
181 : private:
182 : std::vector<SubdomainID> _vals;
183 : };
184 :
185 : /// AttribBoundaries tracks all boundary IDs associated with an object.
186 : /// When running queries, an object matches true if it has at least one
187 : /// boundary id in common with the boundary IDs in the query attribute.
188 : class AttribBoundaries : public Attribute
189 : {
190 : public:
191 : typedef std::tuple<BoundaryID, bool> Key;
192 688107 : void setFrom(Key k)
193 : {
194 688107 : _vals.clear();
195 688107 : _vals.push_back(std::get<0>(k));
196 688107 : _must_be_restricted = std::get<1>(k);
197 688107 : }
198 :
199 194729 : AttribBoundaries(TheWarehouse & w) : Attribute(w, "boundaries") {}
200 9363853 : AttribBoundaries(TheWarehouse & w, BoundaryID id, bool must_be_restricted = false)
201 9363853 : : Attribute(w, "boundaries"), _must_be_restricted(must_be_restricted)
202 : {
203 9363853 : _vals.push_back(id);
204 9363853 : }
205 190216 : AttribBoundaries(TheWarehouse & w,
206 : const std::set<BoundaryID> & ids,
207 : bool must_be_restricted = false)
208 190216 : : Attribute(w, "boundaries"), _must_be_restricted(must_be_restricted)
209 : {
210 380432 : for (auto id : ids)
211 190216 : _vals.push_back(id);
212 190216 : }
213 : AttribBoundaries(TheWarehouse & w,
214 : const std::vector<BoundaryID> & ids,
215 : bool must_be_restricted = false)
216 : : Attribute(w, "boundaries"), _must_be_restricted(must_be_restricted)
217 : {
218 : _vals.reserve(ids.size());
219 : for (auto id : ids)
220 : _vals.push_back(id);
221 : }
222 : virtual void initFrom(const MooseObject * obj) override;
223 : virtual bool isMatch(const Attribute & other) const override;
224 : virtual bool isEqual(const Attribute & other) const override;
225 10715820 : hashfunc(_vals, _must_be_restricted);
226 824806 : clonefunc(AttribBoundaries);
227 :
228 : private:
229 : std::vector<BoundaryID> _vals;
230 : bool _must_be_restricted = false;
231 : };
232 :
233 : class AttribThread : public Attribute
234 : {
235 : public:
236 : typedef THREAD_ID Key;
237 1733662 : void setFrom(Key k) { _val = k; }
238 :
239 389458 : AttribThread(TheWarehouse & w) : Attribute(w, "thread") {}
240 21236563 : AttribThread(TheWarehouse & w, THREAD_ID t) : Attribute(w, "thread"), _val(t) {}
241 : virtual void initFrom(const MooseObject * obj) override;
242 : virtual bool isMatch(const Attribute & other) const override;
243 : virtual bool isEqual(const Attribute & other) const override;
244 24600570 : hashfunc(_val);
245 2171221 : clonefunc(AttribThread);
246 :
247 : private:
248 : THREAD_ID _val = 0;
249 : };
250 :
251 : class AttribExecutionOrderGroup : public Attribute
252 : {
253 : public:
254 : typedef int Key;
255 : void setFrom(Key k) { _val = k; }
256 :
257 : AttribExecutionOrderGroup(TheWarehouse & w) : Attribute(w, "execution_order_group") {}
258 317798 : AttribExecutionOrderGroup(TheWarehouse & w, Key p)
259 317798 : : Attribute(w, "execution_order_group"), _val(p)
260 : {
261 317798 : }
262 : virtual void initFrom(const MooseObject * obj) override;
263 : virtual bool isMatch(const Attribute & other) const override;
264 : virtual bool isEqual(const Attribute & other) const override;
265 9079684 : hashfunc(_val);
266 8847995 : clonefunc(AttribExecutionOrderGroup);
267 :
268 : private:
269 : int _val = 0;
270 : };
271 :
272 : /**
273 : * Tracks the libmesh system number that a \p MooseObject is associated with
274 : */
275 : class AttribSysNum : public Attribute
276 : {
277 : public:
278 : typedef unsigned int Key;
279 : void setFrom(Key k) { _val = k; }
280 :
281 : AttribSysNum(TheWarehouse & w) : Attribute(w, "sys_num") {}
282 8962665 : AttribSysNum(TheWarehouse & w, unsigned int t) : Attribute(w, "sys_num"), _val(t) {}
283 : virtual void initFrom(const MooseObject * obj) override;
284 : virtual bool isMatch(const Attribute & other) const override;
285 : virtual bool isEqual(const Attribute & other) const override;
286 9187364 : hashfunc(_val);
287 690344 : clonefunc(AttribSysNum);
288 :
289 : private:
290 : unsigned int _val = libMesh::invalid_uint;
291 : };
292 :
293 : /// TODO: delete this later - it is a temporary hack for dealing with inter-system dependencies
294 : class AttribPreIC : public Attribute
295 : {
296 : public:
297 : typedef bool Key;
298 : void setFrom(Key k) { _val = k; }
299 :
300 : AttribPreIC(TheWarehouse & w) : Attribute(w, "pre_ic") {}
301 114477 : AttribPreIC(TheWarehouse & w, bool pre_ic) : Attribute(w, "pre_ic"), _val(pre_ic) {}
302 : virtual void initFrom(const MooseObject * obj) override;
303 : virtual bool isMatch(const Attribute & other) const override;
304 : virtual bool isEqual(const Attribute & other) const override;
305 105478 : hashfunc(_val);
306 394131 : clonefunc(AttribPreIC);
307 :
308 : private:
309 : bool _val = false;
310 : };
311 :
312 : /// TODO: delete this later - it is a temporary hack for dealing with inter-system dependencies
313 : class AttribPreAux : public Attribute
314 : {
315 : public:
316 : typedef int Key;
317 : void setFrom(Key k)
318 : {
319 : _vals.clear();
320 : _vals.insert(k);
321 : }
322 :
323 62754 : AttribPreAux(TheWarehouse & w) : Attribute(w, "pre_aux") {}
324 5633543 : AttribPreAux(TheWarehouse & w, Key val) : Attribute(w, "pre_aux") { _vals.insert(val); }
325 2908 : AttribPreAux(TheWarehouse & w, const std::set<Key> & vals) : Attribute(w, "pre_aux"), _vals(vals)
326 : {
327 2908 : }
328 : virtual void initFrom(const MooseObject * obj) override;
329 : virtual bool isMatch(const Attribute & other) const override;
330 : virtual bool isEqual(const Attribute & other) const override;
331 6352456 : hashfunc(_vals);
332 6627867 : clonefunc(AttribPreAux);
333 :
334 : private:
335 : std::set<Key> _vals;
336 : };
337 :
338 : /// TODO: delete this later - it is a temporary hack for dealing with inter-system dependencies
339 : ///
340 : /// this attribute was added to ensure that UOs are uniquely assigned a single group to
341 : /// prevent multiple executions when it is queried in FEProblemBase::computeUserObjectsInternal()
342 : /// for a given exec flag time.
343 : ///
344 : class AttribPostAux : public Attribute
345 : {
346 : public:
347 : typedef int Key;
348 : void setFrom(Key k)
349 : {
350 : _vals.clear();
351 : _vals.insert(k);
352 : }
353 :
354 62754 : AttribPostAux(TheWarehouse & w) : Attribute(w, "post_aux") {}
355 5633933 : AttribPostAux(TheWarehouse & w, Key val) : Attribute(w, "post_aux") { _vals.insert(val); }
356 70966 : AttribPostAux(TheWarehouse & w, const std::set<Key> & vals)
357 70966 : : Attribute(w, "post_aux"), _vals(vals)
358 : {
359 70966 : }
360 : virtual void initFrom(const MooseObject * obj) override;
361 : virtual bool isMatch(const Attribute & other) const override;
362 : virtual bool isEqual(const Attribute & other) const override;
363 14939655 : hashfunc(_vals);
364 15049847 : clonefunc(AttribPostAux);
365 :
366 : private:
367 : std::set<Key> _vals;
368 : };
369 :
370 : class AttribName : public Attribute
371 : {
372 : public:
373 : typedef std::string Key;
374 : void setFrom(const Key & k) { _val = k; }
375 :
376 : AttribName(TheWarehouse & w) : Attribute(w, "name") {}
377 524839 : AttribName(TheWarehouse & w, const std::string & name) : Attribute(w, "name"), _val(name) {}
378 : virtual void initFrom(const MooseObject * obj) override;
379 : virtual bool isMatch(const Attribute & other) const override;
380 : virtual bool isEqual(const Attribute & other) const override;
381 524664 : hashfunc(_val);
382 500630 : clonefunc(AttribName);
383 :
384 : private:
385 : std::string _val;
386 : };
387 :
388 : class AttribSystem : public Attribute
389 : {
390 : public:
391 : typedef std::string Key;
392 : void setFrom(const Key & k) { _val = k; }
393 :
394 : AttribSystem(TheWarehouse & w) : Attribute(w, "system") {}
395 29670986 : AttribSystem(TheWarehouse & w, const std::string & system) : Attribute(w, "system"), _val(system)
396 : {
397 29670986 : }
398 : virtual void initFrom(const MooseObject * obj) override;
399 : virtual bool isMatch(const Attribute & other) const override;
400 : virtual bool isEqual(const Attribute & other) const override;
401 45705361 : hashfunc(_val);
402 39070121 : clonefunc(AttribSystem);
403 :
404 : private:
405 : std::string _val;
406 : };
407 :
408 : /**
409 : * Residual objects have this attribute
410 : */
411 : class AttribResidualObject : public Attribute
412 : {
413 : public:
414 : typedef bool Key;
415 : void setFrom(const Key & k) { _val = k; }
416 :
417 62754 : AttribResidualObject(TheWarehouse & w)
418 62754 : : Attribute(w, "residual_object"), _val(false), _initd(false)
419 : {
420 62754 : }
421 :
422 : AttribResidualObject(TheWarehouse & w, bool is_residual_object)
423 : : Attribute(w, "residual_object"), _val(is_residual_object), _initd(true)
424 : {
425 : }
426 :
427 : virtual void initFrom(const MooseObject * obj) override;
428 : virtual bool isMatch(const Attribute & other) const override;
429 : virtual bool isEqual(const Attribute & other) const override;
430 0 : hashfunc(_val);
431 288408 : clonefunc(AttribResidualObject);
432 :
433 : private:
434 : bool _val;
435 : bool _initd;
436 : };
437 :
438 : class AttribVar : public Attribute
439 : {
440 : public:
441 : typedef int Key;
442 : void setFrom(const Key & k) { _val = k; }
443 :
444 : AttribVar(TheWarehouse & w) : Attribute(w, "variable") {}
445 126321 : AttribVar(TheWarehouse & w, int var) : Attribute(w, "variable"), _val(var) {}
446 : virtual void initFrom(const MooseObject * obj) override;
447 : virtual bool isMatch(const Attribute & other) const override;
448 : virtual bool isEqual(const Attribute & other) const override;
449 251599 : hashfunc(_val);
450 590313 : clonefunc(AttribVar);
451 :
452 : private:
453 : int _val = -1;
454 : };
455 :
456 : class AttribInterfaces : public Attribute
457 : {
458 : public:
459 : typedef Interfaces Key;
460 1733662 : void setFrom(Key k) { _val = static_cast<uint64_t>(k); }
461 :
462 389458 : AttribInterfaces(TheWarehouse & w) : Attribute(w, "interfaces") {}
463 10617679 : AttribInterfaces(TheWarehouse & w, Interfaces mask)
464 10617679 : : Attribute(w, "interfaces"), _val(static_cast<uint64_t>(mask))
465 : {
466 10617679 : }
467 62754 : AttribInterfaces(TheWarehouse & w, unsigned int mask) : Attribute(w, "interfaces"), _val(mask) {}
468 : virtual void initFrom(const MooseObject * obj) override;
469 : virtual bool isMatch(const Attribute & other) const override;
470 : virtual bool isEqual(const Attribute & other) const override;
471 14730145 : hashfunc(_val);
472 2747161 : clonefunc(AttribInterfaces);
473 :
474 : private:
475 : uint64_t _val = 0;
476 : };
477 :
478 : /**
479 : * Tracks whether the object is on the displaced mesh
480 : */
481 : class AttribDisplaced : public Attribute
482 : {
483 : public:
484 : typedef signed char Key;
485 : void setFrom(Key k) { _val = k; }
486 :
487 : AttribDisplaced(TheWarehouse & w) : Attribute(w, "displaced") {}
488 8391805 : AttribDisplaced(TheWarehouse & w, Key t) : Attribute(w, "displaced"), _val(t) {}
489 : virtual void initFrom(const MooseObject * obj) override;
490 : virtual bool isMatch(const Attribute & other) const override;
491 : virtual bool isEqual(const Attribute & other) const override;
492 8408285 : hashfunc(_val);
493 367642 : clonefunc(AttribDisplaced);
494 :
495 : private:
496 : Key _val = -1;
497 : };
498 :
499 : #undef clonefunc
500 : #undef hashfunc
|