LCOV - code coverage report
Current view: top level - include/base - Attributes.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #33416 (b10b36) with base 9fbd27 Lines: 110 111 99.1 %
Date: 2026-07-23 16:15:30 Functions: 71 72 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      136322 :   AttribTagBase(TheWarehouse & w, TagID tag, const std::string & attrib_name)
      72      136322 :     : Attribute(w, attrib_name)
      73             :   {
      74      136322 :     _vals.push_back(tag);
      75      136322 :   }
      76     7285075 :   AttribTagBase(TheWarehouse & w, const std::set<TagID> & tags, const std::string & attrib_name)
      77     7282177 :     : Attribute(w, attrib_name)
      78             :   {
      79    24497879 :     for (auto tag : tags)
      80    17212804 :       _vals.push_back(tag);
      81     7285075 :   }
      82             : 
      83             :   virtual bool isMatch(const Attribute & other) const override;
      84             :   virtual bool isEqual(const Attribute & other) const override;
      85     7355678 :   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      204303 :   AttribMatrixTags(TheWarehouse & w, TagID tag) : AttribTagBase(w, tag, "matrix_tags") {}
     103     2003403 :   AttribMatrixTags(TheWarehouse & w, const std::set<TagID> & tags)
     104     4001502 :     : AttribTagBase(w, tags, "matrix_tags")
     105             :   {
     106     2002077 :   }
     107             :   virtual void initFrom(const MooseObject * obj) override;
     108      343084 :   clonefunc(AttribMatrixTags);
     109             : };
     110             : 
     111             : class AttribVectorTags : public AttribTagBase
     112             : {
     113             : public:
     114      348279 :   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      204663 :   AttribVectorTags(TheWarehouse & w, TagID tag) : AttribTagBase(w, tag, "vector_tags") {}
     125     5284570 :   AttribVectorTags(TheWarehouse & w, const std::set<TagID> & tags)
     126    10562852 :     : AttribTagBase(w, tags, "vector_tags")
     127             :   {
     128     5282998 :   }
     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      272404 :   AttribExecOns(TheWarehouse & w, const int id) : Attribute(w, "exec_ons"), _vals({id}) {}
     147    25981628 :   AttribExecOns(TheWarehouse & w, const ExecFlagType & exec_flag)
     148   103926512 :     : Attribute(w, "exec_ons"), _vals({exec_flag.id()})
     149             :   {
     150    25981628 :   }
     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    77602302 :   hashfunc(_vals);
     155    32922271 :   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     1114430 :   void setFrom(Key k)
     166             :   {
     167     1114430 :     _vals.clear();
     168     1114430 :     _vals.push_back(k);
     169     1114430 :   }
     170             : 
     171      622587 :   AttribSubdomains(TheWarehouse & w) : Attribute(w, "subdomains") {}
     172    15301989 :   AttribSubdomains(TheWarehouse & w, SubdomainID id) : Attribute(w, "subdomains")
     173             :   {
     174     5100663 :     _vals.push_back(id);
     175     5100663 :   }
     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    12651340 :   hashfunc(_vals);
     180      488750 :   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      772119 :   void setFrom(Key k)
     194             :   {
     195      772119 :     _vals.clear();
     196      772119 :     _vals.push_back(std::get<0>(k));
     197      772119 :     _must_be_restricted = std::get<1>(k);
     198      772119 :   }
     199             : 
     200      622587 :   AttribBoundaries(TheWarehouse & w) : Attribute(w, "boundaries") {}
     201     9816880 :   AttribBoundaries(TheWarehouse & w, BoundaryID id, bool must_be_restricted = false)
     202    29450640 :     : Attribute(w, "boundaries"), _must_be_restricted(must_be_restricted)
     203             :   {
     204     9816880 :     _vals.push_back(id);
     205     9816880 :   }
     206      171731 :   AttribBoundaries(TheWarehouse & w,
     207             :                    const std::set<BoundaryID> & ids,
     208             :                    bool must_be_restricted = false)
     209      515193 :     : Attribute(w, "boundaries"), _must_be_restricted(must_be_restricted)
     210             :   {
     211      343462 :     for (auto id : ids)
     212      171731 :       _vals.push_back(id);
     213      171731 :   }
     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    22480624 :   hashfunc(_vals, _must_be_restricted);
     227      857743 :   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     1886549 :   void setFrom(Key k) { _val = k; }
     239             : 
     240     1245174 :   AttribThread(TheWarehouse & w) : Attribute(w, "thread") {}
     241    65046615 :   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    25437390 :   hashfunc(_val);
     246     2407273 :   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      576222 :   AttribExecutionOrderGroup(TheWarehouse & w, Key p)
     260     1152444 :     : Attribute(w, "execution_order_group"), _val(p)
     261             :   {
     262      576222 :   }
     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    10402784 :   hashfunc(_val);
     267     9880199 :   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    22964286 :   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     7843781 :   hashfunc(_val);
     288      663510 :   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      499464 :   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      198805 :   hashfunc(_val);
     307      410984 :   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      204303 :   AttribPreAux(TheWarehouse & w) : Attribute(w, "pre_aux") {}
     325    29880561 :   AttribPreAux(TheWarehouse & w, Key val) : Attribute(w, "pre_aux") { _vals.insert(val); }
     326        9084 :   AttribPreAux(TheWarehouse & w, const std::set<Key> & vals) : Attribute(w, "pre_aux"), _vals(vals)
     327             :   {
     328        3028 :   }
     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    11111854 :   hashfunc(_vals);
     333     1497680 :   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      204303 :   AttribPostAux(TheWarehouse & w) : Attribute(w, "post_aux") {}
     356    29882631 :   AttribPostAux(TheWarehouse & w, Key val) : Attribute(w, "post_aux") { _vals.insert(val); }
     357       74304 :   AttribPostAux(TheWarehouse & w, const std::set<Key> & vals)
     358      222912 :     : Attribute(w, "post_aux"), _vals(vals)
     359             :   {
     360       74304 :   }
     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    20999139 :   hashfunc(_vals);
     365    11163078 :   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     2080593 :   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     1546500 :   hashfunc(_val);
     383     1322299 :   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   114816453 :   AttribSystem(TheWarehouse & w, const std::string & system) : Attribute(w, "system"), _val(system)
     397             :   {
     398    38272151 :   }
     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    57632489 :   hashfunc(_val);
     403    39905640 :   clonefunc(AttribSystem);
     404             : 
     405             : private:
     406             :   std::string _val;
     407             : };
     408             : 
     409             : class AttribKokkos : public Attribute
     410             : {
     411             : public:
     412             :   typedef bool Key;
     413             :   void setFrom(const Key & k) { _val = k; }
     414             : 
     415             :   AttribKokkos(TheWarehouse & w) : Attribute(w, "kokkos"), _val(false) {}
     416     1025817 :   AttribKokkos(TheWarehouse & w, bool is_kokkos) : Attribute(w, "kokkos"), _val(is_kokkos) {}
     417             :   virtual void initFrom(const MooseObject * obj) override;
     418             :   virtual bool isMatch(const Attribute & other) const override;
     419             :   virtual bool isEqual(const Attribute & other) const override;
     420      290738 :   hashfunc(_val);
     421      326960 :   clonefunc(AttribKokkos);
     422             : 
     423             : private:
     424             :   bool _val;
     425             : };
     426             : 
     427             : /**
     428             :  * Residual objects have this attribute
     429             :  */
     430             : class AttribResidualObject : public Attribute
     431             : {
     432             : public:
     433             :   typedef bool Key;
     434             :   void setFrom(const Key & k) { _val = k; }
     435             : 
     436       68101 :   AttribResidualObject(TheWarehouse & w)
     437      136202 :     : Attribute(w, "residual_object"), _val(false), _initd(false)
     438             :   {
     439       68101 :   }
     440             : 
     441             :   AttribResidualObject(TheWarehouse & w, bool is_residual_object)
     442             :     : Attribute(w, "residual_object"), _val(is_residual_object), _initd(true)
     443             :   {
     444             :   }
     445             : 
     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           0 :   hashfunc(_val);
     450      310060 :   clonefunc(AttribResidualObject);
     451             : 
     452             : private:
     453             :   bool _val;
     454             :   bool _initd;
     455             : };
     456             : 
     457             : class AttribVar : public Attribute
     458             : {
     459             : public:
     460             :   typedef int Key;
     461             :   void setFrom(const Key & k) { _val = k; }
     462             : 
     463             :   AttribVar(TheWarehouse & w) : Attribute(w, "variable") {}
     464      363939 :   AttribVar(TheWarehouse & w, int var) : Attribute(w, "variable"), _val(var) {}
     465             :   virtual void initFrom(const MooseObject * obj) override;
     466             :   virtual bool isMatch(const Attribute & other) const override;
     467             :   virtual bool isEqual(const Attribute & other) const override;
     468      225842 :   hashfunc(_val);
     469      578368 :   clonefunc(AttribVar);
     470             : 
     471             : private:
     472             :   int _val = -1;
     473             : };
     474             : 
     475             : class AttribInterfaces : public Attribute
     476             : {
     477             : public:
     478             :   typedef Interfaces Key;
     479     1886549 :   void setFrom(Key k) { _val = static_cast<uint64_t>(k); }
     480             : 
     481     1245174 :   AttribInterfaces(TheWarehouse & w) : Attribute(w, "interfaces") {}
     482    13245438 :   AttribInterfaces(TheWarehouse & w, Interfaces mask)
     483    26490876 :     : Attribute(w, "interfaces"), _val(static_cast<uint64_t>(mask))
     484             :   {
     485    13245438 :   }
     486      204303 :   AttribInterfaces(TheWarehouse & w, unsigned int mask) : Attribute(w, "interfaces"), _val(mask) {}
     487             :   virtual void initFrom(const MooseObject * obj) override;
     488             :   virtual bool isMatch(const Attribute & other) const override;
     489             :   virtual bool isEqual(const Attribute & other) const override;
     490    17969512 :   hashfunc(_val);
     491     3211972 :   clonefunc(AttribInterfaces);
     492             : 
     493             : private:
     494             :   uint64_t _val = 0;
     495             : };
     496             : 
     497             : /**
     498             :  * Tracks whether the object is on the displaced mesh
     499             :  */
     500             : class AttribDisplaced : public Attribute
     501             : {
     502             : public:
     503             :   typedef signed char Key;
     504             :   void setFrom(Key k) { _val = k; }
     505             : 
     506             :   AttribDisplaced(TheWarehouse & w) : Attribute(w, "displaced") {}
     507    21221943 :   AttribDisplaced(TheWarehouse & w, Key t) : Attribute(w, "displaced"), _val(t) {}
     508             :   virtual void initFrom(const MooseObject * obj) override;
     509             :   virtual bool isMatch(const Attribute & other) const override;
     510             :   virtual bool isEqual(const Attribute & other) const override;
     511     7065062 :   hashfunc(_val);
     512      369242 :   clonefunc(AttribDisplaced);
     513             : 
     514             : private:
     515             :   Key _val = -1;
     516             : };
     517             : 
     518             : #undef clonefunc
     519             : #undef hashfunc

Generated by: LCOV version 1.14