LCOV - code coverage report
Current view: top level - include/base - Attributes.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 107 108 99.1 %
Date: 2026-05-29 20:35:17 Functions: 68 69 98.6 %
Legend: Lines: hit not hit

          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             :   FVInterpolationMethod = 1 << 18
      40             : };
      41             : 
      42             : template <>
      43             : struct enable_bitmask_operators<Interfaces>
      44             : {
      45             :   static const bool enable = true;
      46             : };
      47             : 
      48             : std::ostream & operator<<(std::ostream & os, Interfaces & iface);
      49             : 
      50             : #define clonefunc(T)                                                                               \
      51             :   virtual std::unique_ptr<Attribute> clone() const override                                        \
      52             :   {                                                                                                \
      53             :     return std::unique_ptr<Attribute>(new T(*this));                                               \
      54             :   }
      55             : 
      56             : #define hashfunc(...)                                                                              \
      57             :   virtual size_t hash() const override                                                             \
      58             :   {                                                                                                \
      59             :     size_t h = 0;                                                                                  \
      60             :     Moose::hash_combine(h, __VA_ARGS__);                                                           \
      61             :     return h;                                                                                      \
      62             :   }
      63             : 
      64             : /// AttribTagBase tracks all (vector or matrix) tags associated with an object.
      65             : /// When running queries, an object matches true if it has at least one tag in
      66             : /// common with the tags in the query attribute.
      67             : class AttribTagBase : public Attribute
      68             : {
      69             : public:
      70             :   AttribTagBase(TheWarehouse & w, const std::string & attrib_name) : Attribute(w, attrib_name) {}
      71      134106 :   AttribTagBase(TheWarehouse & w, TagID tag, const std::string & attrib_name)
      72      134106 :     : Attribute(w, attrib_name)
      73             :   {
      74      134106 :     _vals.push_back(tag);
      75      134106 :   }
      76     7336066 :   AttribTagBase(TheWarehouse & w, const std::set<TagID> & tags, const std::string & attrib_name)
      77     7336066 :     : Attribute(w, attrib_name)
      78             :   {
      79    24660760 :     for (auto tag : tags)
      80    17324694 :       _vals.push_back(tag);
      81     7336066 :   }
      82             : 
      83             :   virtual bool isMatch(const Attribute & other) const override;
      84             :   virtual bool isEqual(const Attribute & other) const override;
      85     7406867 :   hashfunc(_vals);
      86             : 
      87             : protected:
      88             :   std::vector<TagID> _vals;
      89             : };
      90             : 
      91             : class AttribMatrixTags : public AttribTagBase
      92             : {
      93             : public:
      94             :   typedef unsigned int Key;
      95             :   void setFrom(Key k)
      96             :   {
      97             :     _vals.clear();
      98             :     _vals.push_back(k);
      99             :   }
     100             : 
     101             :   AttribMatrixTags(TheWarehouse & w) : AttribTagBase(w, "matrix_tags") {}
     102      200979 :   AttribMatrixTags(TheWarehouse & w, TagID tag) : AttribTagBase(w, tag, "matrix_tags") {}
     103     2015672 :   AttribMatrixTags(TheWarehouse & w, const std::set<TagID> & tags)
     104     4031344 :     : AttribTagBase(w, tags, "matrix_tags")
     105             :   {
     106     2015672 :   }
     107             :   virtual void initFrom(const MooseObject * obj) override;
     108      334818 :   clonefunc(AttribMatrixTags);
     109             : };
     110             : 
     111             : class AttribVectorTags : public AttribTagBase
     112             : {
     113             : public:
     114      340269 :   clonefunc(AttribVectorTags);
     115             : 
     116             :   typedef unsigned int Key;
     117             :   void setFrom(Key k)
     118             :   {
     119             :     _vals.clear();
     120             :     _vals.push_back(k);
     121             :   }
     122             : 
     123             :   AttribVectorTags(TheWarehouse & w) : AttribTagBase(w, "vector_tags") {}
     124      201339 :   AttribVectorTags(TheWarehouse & w, TagID tag) : AttribTagBase(w, tag, "vector_tags") {}
     125     5320394 :   AttribVectorTags(TheWarehouse & w, const std::set<TagID> & tags)
     126    10640788 :     : AttribTagBase(w, tags, "vector_tags")
     127             :   {
     128     5320394 :   }
     129             :   virtual void initFrom(const MooseObject * obj) override;
     130             : };
     131             : 
     132             : class AttribExecOns : public Attribute
     133             : {
     134             : public:
     135             :   /// Execute flag that is used to represent all flags when querying AttribExecOns
     136             :   static const ExecFlagType EXEC_ALL;
     137             : 
     138             :   typedef int Key;
     139             :   void setFrom(Key k)
     140             :   {
     141             :     _vals.clear();
     142             :     _vals.push_back(k);
     143             :   }
     144             : 
     145             :   AttribExecOns(TheWarehouse & w) : Attribute(w, "exec_ons") {}
     146      267972 :   AttribExecOns(TheWarehouse & w, const int id) : Attribute(w, "exec_ons"), _vals({id}) {}
     147    25719936 :   AttribExecOns(TheWarehouse & w, const ExecFlagType & exec_flag)
     148   102879744 :     : Attribute(w, "exec_ons"), _vals({exec_flag.id()})
     149             :   {
     150    25719936 :   }
     151             :   virtual void initFrom(const MooseObject * obj) override;
     152             :   virtual bool isMatch(const Attribute & other) const override;
     153             :   virtual bool isEqual(const Attribute & other) const override;
     154    77151408 :   hashfunc(_vals);
     155    32660650 :   clonefunc(AttribExecOns);
     156             : 
     157             : private:
     158             :   std::vector<Key> _vals;
     159             : };
     160             : 
     161             : class AttribSubdomains : public Attribute
     162             : {
     163             : public:
     164             :   typedef SubdomainID Key;
     165     1200270 :   void setFrom(Key k)
     166             :   {
     167     1200270 :     _vals.clear();
     168     1200270 :     _vals.push_back(k);
     169     1200270 :   }
     170             : 
     171      673263 :   AttribSubdomains(TheWarehouse & w) : Attribute(w, "subdomains") {}
     172    15394509 :   AttribSubdomains(TheWarehouse & w, SubdomainID id) : Attribute(w, "subdomains")
     173             :   {
     174     5131503 :     _vals.push_back(id);
     175     5131503 :   }
     176             :   virtual void initFrom(const MooseObject * obj) override;
     177             :   virtual bool isMatch(const Attribute & other) const override;
     178             :   virtual bool isEqual(const Attribute & other) const override;
     179    12899250 :   hashfunc(_vals);
     180      486680 :   clonefunc(AttribSubdomains);
     181             : 
     182             : private:
     183             :   std::vector<SubdomainID> _vals;
     184             : };
     185             : 
     186             : /// AttribBoundaries tracks all boundary IDs associated with an object.
     187             : /// When running queries, an object matches true if it has at least one
     188             : /// boundary id in common with the boundary IDs in the query attribute.
     189             : class AttribBoundaries : public Attribute
     190             : {
     191             : public:
     192             :   typedef std::tuple<BoundaryID, bool> Key;
     193      809728 :   void setFrom(Key k)
     194             :   {
     195      809728 :     _vals.clear();
     196      809728 :     _vals.push_back(std::get<0>(k));
     197      809728 :     _must_be_restricted = std::get<1>(k);
     198      809728 :   }
     199             : 
     200      673263 :   AttribBoundaries(TheWarehouse & w) : Attribute(w, "boundaries") {}
     201     9187978 :   AttribBoundaries(TheWarehouse & w, BoundaryID id, bool must_be_restricted = false)
     202    27563934 :     : Attribute(w, "boundaries"), _must_be_restricted(must_be_restricted)
     203             :   {
     204     9187978 :     _vals.push_back(id);
     205     9187978 :   }
     206      170155 :   AttribBoundaries(TheWarehouse & w,
     207             :                    const std::set<BoundaryID> & ids,
     208             :                    bool must_be_restricted = false)
     209      510465 :     : Attribute(w, "boundaries"), _must_be_restricted(must_be_restricted)
     210             :   {
     211      340310 :     for (auto id : ids)
     212      170155 :       _vals.push_back(id);
     213      170155 :   }
     214             :   AttribBoundaries(TheWarehouse & w,
     215             :                    const std::vector<BoundaryID> & ids,
     216             :                    bool must_be_restricted = false)
     217             :     : Attribute(w, "boundaries"), _must_be_restricted(must_be_restricted)
     218             :   {
     219             :     _vals.reserve(ids.size());
     220             :     for (auto id : ids)
     221             :       _vals.push_back(id);
     222             :   }
     223             :   virtual void initFrom(const MooseObject * obj) override;
     224             :   virtual bool isMatch(const Attribute & other) const override;
     225             :   virtual bool isEqual(const Attribute & other) const override;
     226    21293810 :   hashfunc(_vals, _must_be_restricted);
     227      847860 :   clonefunc(AttribBoundaries);
     228             : 
     229             : private:
     230             :   std::vector<BoundaryID> _vals;
     231             :   bool _must_be_restricted = false;
     232             : };
     233             : 
     234             : class AttribThread : public Attribute
     235             : {
     236             : public:
     237             :   typedef THREAD_ID Key;
     238     2009998 :   void setFrom(Key k) { _val = k; }
     239             : 
     240     1346526 :   AttribThread(TheWarehouse & w) : Attribute(w, "thread") {}
     241    63155682 :   AttribThread(TheWarehouse & w, THREAD_ID t) : Attribute(w, "thread"), _val(t) {}
     242             :   virtual void initFrom(const MooseObject * obj) override;
     243             :   virtual bool isMatch(const Attribute & other) const override;
     244             :   virtual bool isEqual(const Attribute & other) const override;
     245    24915505 :   hashfunc(_val);
     246     2379725 :   clonefunc(AttribThread);
     247             : 
     248             : private:
     249             :   THREAD_ID _val = 0;
     250             : };
     251             : 
     252             : class AttribExecutionOrderGroup : public Attribute
     253             : {
     254             : public:
     255             :   typedef int Key;
     256             :   void setFrom(Key k) { _val = k; }
     257             : 
     258             :   AttribExecutionOrderGroup(TheWarehouse & w) : Attribute(w, "execution_order_group") {}
     259      563700 :   AttribExecutionOrderGroup(TheWarehouse & w, Key p)
     260     1127400 :     : Attribute(w, "execution_order_group"), _val(p)
     261             :   {
     262      563700 :   }
     263             :   virtual void initFrom(const MooseObject * obj) override;
     264             :   virtual bool isMatch(const Attribute & other) const override;
     265             :   virtual bool isEqual(const Attribute & other) const override;
     266    10473708 :   hashfunc(_val);
     267     9868546 :   clonefunc(AttribExecutionOrderGroup);
     268             : 
     269             : private:
     270             :   int _val = 0;
     271             : };
     272             : 
     273             : /**
     274             :  * Tracks the libmesh system number that a \p MooseObject is associated with
     275             :  */
     276             : class AttribSysNum : public Attribute
     277             : {
     278             : public:
     279             :   typedef unsigned int Key;
     280             :   void setFrom(Key k) { _val = k; }
     281             : 
     282             :   AttribSysNum(TheWarehouse & w) : Attribute(w, "sys_num") {}
     283    23132358 :   AttribSysNum(TheWarehouse & w, unsigned int t) : Attribute(w, "sys_num"), _val(t) {}
     284             :   virtual void initFrom(const MooseObject * obj) override;
     285             :   virtual bool isMatch(const Attribute & other) const override;
     286             :   virtual bool isEqual(const Attribute & other) const override;
     287     7893017 :   hashfunc(_val);
     288      646357 :   clonefunc(AttribSysNum);
     289             : 
     290             : private:
     291             :   unsigned int _val = libMesh::invalid_uint;
     292             : };
     293             : 
     294             : /// TODO: delete this later - it is a temporary hack for dealing with inter-system dependencies
     295             : class AttribPreIC : public Attribute
     296             : {
     297             : public:
     298             :   typedef bool Key;
     299             :   void setFrom(Key k) { _val = k; }
     300             : 
     301             :   AttribPreIC(TheWarehouse & w) : Attribute(w, "pre_ic") {}
     302      488439 :   AttribPreIC(TheWarehouse & w, bool pre_ic) : Attribute(w, "pre_ic"), _val(pre_ic) {}
     303             :   virtual void initFrom(const MooseObject * obj) override;
     304             :   virtual bool isMatch(const Attribute & other) const override;
     305             :   virtual bool isEqual(const Attribute & other) const override;
     306      193747 :   hashfunc(_val);
     307      400238 :   clonefunc(AttribPreIC);
     308             : 
     309             : private:
     310             :   bool _val = false;
     311             : };
     312             : 
     313             : /// TODO: delete this later - it is a temporary hack for dealing with inter-system dependencies
     314             : class AttribPreAux : public Attribute
     315             : {
     316             : public:
     317             :   typedef int Key;
     318             :   void setFrom(Key k)
     319             :   {
     320             :     _vals.clear();
     321             :     _vals.insert(k);
     322             :   }
     323             : 
     324      200979 :   AttribPreAux(TheWarehouse & w) : Attribute(w, "pre_aux") {}
     325    29582016 :   AttribPreAux(TheWarehouse & w, Key val) : Attribute(w, "pre_aux") { _vals.insert(val); }
     326        8844 :   AttribPreAux(TheWarehouse & w, const std::set<Key> & vals) : Attribute(w, "pre_aux"), _vals(vals)
     327             :   {
     328        2948 :   }
     329             :   virtual void initFrom(const MooseObject * obj) override;
     330             :   virtual bool isMatch(const Attribute & other) const override;
     331             :   virtual bool isEqual(const Attribute & other) const override;
     332    10993156 :   hashfunc(_vals);
     333     1466847 :   clonefunc(AttribPreAux);
     334             : 
     335             : private:
     336             :   std::set<Key> _vals;
     337             : };
     338             : 
     339             : /// TODO: delete this later - it is a temporary hack for dealing with inter-system dependencies
     340             : ///
     341             : /// this attribute was added to ensure that UOs are uniquely assigned a single group to
     342             : /// prevent multiple executions when it is queried in FEProblemBase::computeUserObjectsInternal()
     343             : /// for a given exec flag time.
     344             : ///
     345             : class AttribPostAux : public Attribute
     346             : {
     347             : public:
     348             :   typedef int Key;
     349             :   void setFrom(Key k)
     350             :   {
     351             :     _vals.clear();
     352             :     _vals.insert(k);
     353             :   }
     354             : 
     355      200979 :   AttribPostAux(TheWarehouse & w) : Attribute(w, "post_aux") {}
     356    29584086 :   AttribPostAux(TheWarehouse & w, Key val) : Attribute(w, "post_aux") { _vals.insert(val); }
     357       72096 :   AttribPostAux(TheWarehouse & w, const std::set<Key> & vals)
     358      216288 :     : Attribute(w, "post_aux"), _vals(vals)
     359             :   {
     360       72096 :   }
     361             :   virtual void initFrom(const MooseObject * obj) override;
     362             :   virtual bool isMatch(const Attribute & other) const override;
     363             :   virtual bool isEqual(const Attribute & other) const override;
     364    20964201 :   hashfunc(_vals);
     365    11131653 :   clonefunc(AttribPostAux);
     366             : 
     367             : private:
     368             :   std::set<Key> _vals;
     369             : };
     370             : 
     371             : class AttribName : public Attribute
     372             : {
     373             : public:
     374             :   typedef std::string Key;
     375             :   void setFrom(const Key & k) { _val = k; }
     376             : 
     377             :   AttribName(TheWarehouse & w) : Attribute(w, "name") {}
     378     2039868 :   AttribName(TheWarehouse & w, const std::string & name) : Attribute(w, "name"), _val(name) {}
     379             :   virtual void initFrom(const MooseObject * obj) override;
     380             :   virtual bool isMatch(const Attribute & other) const override;
     381             :   virtual bool isEqual(const Attribute & other) const override;
     382     1555696 :   hashfunc(_val);
     383     1317601 :   clonefunc(AttribName);
     384             : 
     385             : private:
     386             :   std::string _val;
     387             : };
     388             : 
     389             : class AttribSystem : public Attribute
     390             : {
     391             : public:
     392             :   typedef std::string Key;
     393             :   void setFrom(const Key & k) { _val = k; }
     394             : 
     395             :   AttribSystem(TheWarehouse & w) : Attribute(w, "system") {}
     396   113938992 :   AttribSystem(TheWarehouse & w, const std::string & system) : Attribute(w, "system"), _val(system)
     397             :   {
     398    37979664 :   }
     399             :   virtual void initFrom(const MooseObject * obj) override;
     400             :   virtual bool isMatch(const Attribute & other) const override;
     401             :   virtual bool isEqual(const Attribute & other) const override;
     402    56732109 :   hashfunc(_val);
     403    38990217 :   clonefunc(AttribSystem);
     404             : 
     405             : private:
     406             :   std::string _val;
     407             : };
     408             : 
     409             : /**
     410             :  * Residual objects have this attribute
     411             :  */
     412             : class AttribResidualObject : public Attribute
     413             : {
     414             : public:
     415             :   typedef bool Key;
     416             :   void setFrom(const Key & k) { _val = k; }
     417             : 
     418       66993 :   AttribResidualObject(TheWarehouse & w)
     419      133986 :     : Attribute(w, "residual_object"), _val(false), _initd(false)
     420             :   {
     421       66993 :   }
     422             : 
     423             :   AttribResidualObject(TheWarehouse & w, bool is_residual_object)
     424             :     : Attribute(w, "residual_object"), _val(is_residual_object), _initd(true)
     425             :   {
     426             :   }
     427             : 
     428             :   virtual void initFrom(const MooseObject * obj) override;
     429             :   virtual bool isMatch(const Attribute & other) const override;
     430             :   virtual bool isEqual(const Attribute & other) const override;
     431           0 :   hashfunc(_val);
     432      301823 :   clonefunc(AttribResidualObject);
     433             : 
     434             : private:
     435             :   bool _val;
     436             :   bool _initd;
     437             : };
     438             : 
     439             : class AttribVar : public Attribute
     440             : {
     441             : public:
     442             :   typedef int Key;
     443             :   void setFrom(const Key & k) { _val = k; }
     444             : 
     445             :   AttribVar(TheWarehouse & w) : Attribute(w, "variable") {}
     446      359085 :   AttribVar(TheWarehouse & w, int var) : Attribute(w, "variable"), _val(var) {}
     447             :   virtual void initFrom(const MooseObject * obj) override;
     448             :   virtual bool isMatch(const Attribute & other) const override;
     449             :   virtual bool isEqual(const Attribute & other) const override;
     450      223460 :   hashfunc(_val);
     451      567239 :   clonefunc(AttribVar);
     452             : 
     453             : private:
     454             :   int _val = -1;
     455             : };
     456             : 
     457             : class AttribInterfaces : public Attribute
     458             : {
     459             : public:
     460             :   typedef Interfaces Key;
     461     2009998 :   void setFrom(Key k) { _val = static_cast<uint64_t>(k); }
     462             : 
     463     1346526 :   AttribInterfaces(TheWarehouse & w) : Attribute(w, "interfaces") {}
     464    12355855 :   AttribInterfaces(TheWarehouse & w, Interfaces mask)
     465    24711710 :     : Attribute(w, "interfaces"), _val(static_cast<uint64_t>(mask))
     466             :   {
     467    12355855 :   }
     468      200979 :   AttribInterfaces(TheWarehouse & w, unsigned int mask) : Attribute(w, "interfaces"), _val(mask) {}
     469             :   virtual void initFrom(const MooseObject * obj) override;
     470             :   virtual bool isMatch(const Attribute & other) const override;
     471             :   virtual bool isEqual(const Attribute & other) const override;
     472    17175774 :   hashfunc(_val);
     473     3174781 :   clonefunc(AttribInterfaces);
     474             : 
     475             : private:
     476             :   uint64_t _val = 0;
     477             : };
     478             : 
     479             : /**
     480             :  * Tracks whether the object is on the displaced mesh
     481             :  */
     482             : class AttribDisplaced : public Attribute
     483             : {
     484             : public:
     485             :   typedef signed char Key;
     486             :   void setFrom(Key k) { _val = k; }
     487             : 
     488             :   AttribDisplaced(TheWarehouse & w) : Attribute(w, "displaced") {}
     489    21360675 :   AttribDisplaced(TheWarehouse & w, Key t) : Attribute(w, "displaced"), _val(t) {}
     490             :   virtual void initFrom(const MooseObject * obj) override;
     491             :   virtual bool isMatch(const Attribute & other) const override;
     492             :   virtual bool isEqual(const Attribute & other) const override;
     493     7114919 :   hashfunc(_val);
     494      363510 :   clonefunc(AttribDisplaced);
     495             : 
     496             : private:
     497             :   Key _val = -1;
     498             : };
     499             : 
     500             : #undef clonefunc
     501             : #undef hashfunc

Generated by: LCOV version 1.14