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 135349 : AttribTagBase(TheWarehouse & w, TagID tag, const std::string & attrib_name)
71 135349 : : Attribute(w, attrib_name)
72 : {
73 135349 : _vals.push_back(tag);
74 135349 : }
75 9280128 : AttribTagBase(TheWarehouse & w, const std::set<TagID> & tags, const std::string & attrib_name)
76 9280128 : : Attribute(w, attrib_name)
77 : {
78 31855105 : for (auto tag : tags)
79 22574977 : _vals.push_back(tag);
80 9280128 : }
81 :
82 : virtual bool isMatch(const Attribute & other) const override;
83 : virtual bool isEqual(const Attribute & other) const override;
84 9376231 : 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 67609 : AttribMatrixTags(TheWarehouse & w, TagID tag) : AttribTagBase(w, tag, "matrix_tags") {}
102 2412612 : AttribMatrixTags(TheWarehouse & w, const std::set<TagID> & tags)
103 2412612 : : AttribTagBase(w, tags, "matrix_tags")
104 : {
105 2412612 : }
106 : virtual void initFrom(const MooseObject * obj) override;
107 355785 : clonefunc(AttribMatrixTags);
108 : };
109 :
110 : class AttribVectorTags : public AttribTagBase
111 : {
112 : public:
113 362829 : 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 67740 : AttribVectorTags(TheWarehouse & w, TagID tag) : AttribTagBase(w, tag, "vector_tags") {}
124 6867516 : AttribVectorTags(TheWarehouse & w, const std::set<TagID> & tags)
125 6867516 : : AttribTagBase(w, tags, "vector_tags")
126 : {
127 6867516 : }
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 67609 : AttribExecOns(TheWarehouse & w, const int id) : Attribute(w, "exec_ons"), _vals({id}) {}
146 18506976 : AttribExecOns(TheWarehouse & w, const ExecFlagType & exec_flag)
147 18506976 : : Attribute(w, "exec_ons"), _vals({exec_flag.id()})
148 : {
149 18506976 : }
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 30771837 : hashfunc(_vals);
154 36742106 : 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 1257830 : void setFrom(Key k)
165 : {
166 1257830 : _vals.clear();
167 1257830 : _vals.push_back(k);
168 1257830 : }
169 :
170 235580 : AttribSubdomains(TheWarehouse & w) : Attribute(w, "subdomains") {}
171 5999669 : AttribSubdomains(TheWarehouse & w, SubdomainID id) : Attribute(w, "subdomains")
172 : {
173 5999669 : _vals.push_back(id);
174 5999669 : }
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 7387243 : hashfunc(_vals);
179 508304 : 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 869409 : void setFrom(Key k)
193 : {
194 869409 : _vals.clear();
195 869409 : _vals.push_back(std::get<0>(k));
196 869409 : _must_be_restricted = std::get<1>(k);
197 869409 : }
198 :
199 235580 : AttribBoundaries(TheWarehouse & w) : Attribute(w, "boundaries") {}
200 10416883 : AttribBoundaries(TheWarehouse & w, BoundaryID id, bool must_be_restricted = false)
201 10416883 : : Attribute(w, "boundaries"), _must_be_restricted(must_be_restricted)
202 : {
203 10416883 : _vals.push_back(id);
204 10416883 : }
205 203736 : AttribBoundaries(TheWarehouse & w,
206 : const std::set<BoundaryID> & ids,
207 : bool must_be_restricted = false)
208 203736 : : Attribute(w, "boundaries"), _must_be_restricted(must_be_restricted)
209 : {
210 407472 : for (auto id : ids)
211 203736 : _vals.push_back(id);
212 203736 : }
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 12008975 : hashfunc(_vals, _must_be_restricted);
226 897494 : 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 2127239 : void setFrom(Key k) { _val = k; }
238 :
239 471160 : AttribThread(TheWarehouse & w) : Attribute(w, "thread") {}
240 23655165 : 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 27558970 : hashfunc(_val);
245 2359356 : 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 370146 : AttribExecutionOrderGroup(TheWarehouse & w, Key p)
259 370146 : : Attribute(w, "execution_order_group"), _val(p)
260 : {
261 370146 : }
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 10725283 : hashfunc(_val);
266 10372087 : 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 9862985 : 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 10103318 : hashfunc(_val);
287 740367 : 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 123851 : 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 114661 : hashfunc(_val);
306 425858 : 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 67609 : AttribPreAux(TheWarehouse & w) : Attribute(w, "pre_aux") {}
324 6103767 : AttribPreAux(TheWarehouse & w, Key val) : Attribute(w, "pre_aux") { _vals.insert(val); }
325 3182 : AttribPreAux(TheWarehouse & w, const std::set<Key> & vals) : Attribute(w, "pre_aux"), _vals(vals)
326 : {
327 3182 : }
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 6885338 : hashfunc(_vals);
332 7181711 : 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 67609 : AttribPostAux(TheWarehouse & w) : Attribute(w, "post_aux") {}
355 6104202 : AttribPostAux(TheWarehouse & w, Key val) : Attribute(w, "post_aux") { _vals.insert(val); }
356 77657 : AttribPostAux(TheWarehouse & w, const std::set<Key> & vals)
357 77657 : : Attribute(w, "post_aux"), _vals(vals)
358 : {
359 77657 : }
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 17073478 : hashfunc(_vals);
364 17118179 : 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 603971 : 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 1440305 : hashfunc(_val);
382 1309960 : 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 32328292 : AttribSystem(TheWarehouse & w, const std::string & system) : Attribute(w, "system"), _val(system)
396 : {
397 32328292 : }
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 50729701 : hashfunc(_val);
402 43280723 : 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 67609 : AttribResidualObject(TheWarehouse & w)
418 67609 : : Attribute(w, "residual_object"), _val(false), _initd(false)
419 : {
420 67609 : }
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 310938 : 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 134998 : 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 269177 : hashfunc(_val);
450 633565 : clonefunc(AttribVar);
451 :
452 : private:
453 : int _val = -1;
454 : };
455 :
456 : class AttribInterfaces : public Attribute
457 : {
458 : public:
459 : typedef Interfaces Key;
460 2127239 : void setFrom(Key k) { _val = static_cast<uint64_t>(k); }
461 :
462 471160 : AttribInterfaces(TheWarehouse & w) : Attribute(w, "interfaces") {}
463 12114013 : AttribInterfaces(TheWarehouse & w, Interfaces mask)
464 12114013 : : Attribute(w, "interfaces"), _val(static_cast<uint64_t>(mask))
465 : {
466 12114013 : }
467 67609 : 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 16986284 : hashfunc(_val);
472 3142512 : 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 9263884 : 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 9280053 : hashfunc(_val);
493 394716 : clonefunc(AttribDisplaced);
494 :
495 : private:
496 : Key _val = -1;
497 : };
498 :
499 : #undef clonefunc
500 : #undef hashfunc
|