LCOV - code coverage report
Current view: top level - src/base - Attributes.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 226 281 80.4 %
Date: 2026-05-29 20:35:17 Functions: 47 50 94.0 %
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             : #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"
      24             : #include "ThreadedGeneralUserObject.h"
      25             : #include "ShapeUserObject.h"
      26             : #include "ShapeSideUserObject.h"
      27             : #include "ShapeElementUserObject.h"
      28             : #include "Reporter.h"
      29             : #include "SystemBase.h"
      30             : #include "DomainUserObject.h"
      31             : #include "MortarUserObject.h"
      32             : #include "FVInterpolationMethod.h"
      33             : #include "ExecFlagRegistry.h"
      34             : 
      35             : #include <algorithm>
      36             : 
      37             : const ExecFlagType AttribExecOns::EXEC_ALL = registerExecFlag("ALL");
      38             : 
      39             : std::ostream &
      40           0 : operator<<(std::ostream & os, Interfaces & iface)
      41             : {
      42           0 :   os << "Interfaces(";
      43           0 :   if (static_cast<bool>(iface & Interfaces::UserObject))
      44           0 :     os << "|UserObject";
      45           0 :   if (static_cast<bool>(iface & Interfaces::ElementUserObject))
      46           0 :     os << "|ElementUserObject";
      47           0 :   if (static_cast<bool>(iface & Interfaces::SideUserObject))
      48           0 :     os << "|SideUserObject";
      49           0 :   if (static_cast<bool>(iface & Interfaces::InternalSideUserObject))
      50           0 :     os << "|InternalSideUserObject";
      51           0 :   if (static_cast<bool>(iface & Interfaces::NodalUserObject))
      52           0 :     os << "|NodalUserObject";
      53           0 :   if (static_cast<bool>(iface & Interfaces::GeneralUserObject))
      54           0 :     os << "|GeneralUserObject";
      55           0 :   if (static_cast<bool>(iface & Interfaces::ThreadedGeneralUserObject))
      56           0 :     os << "|ThreadedGeneralUserObject";
      57           0 :   if (static_cast<bool>(iface & Interfaces::ShapeElementUserObject))
      58           0 :     os << "|ShapeElementUserObject";
      59           0 :   if (static_cast<bool>(iface & Interfaces::ShapeSideUserObject))
      60           0 :     os << "|ShapeSideUserObject";
      61           0 :   if (static_cast<bool>(iface & Interfaces::Postprocessor))
      62           0 :     os << "|Postprocessor";
      63           0 :   if (static_cast<bool>(iface & Interfaces::VectorPostprocessor))
      64           0 :     os << "|VectorPostprocessor";
      65           0 :   if (static_cast<bool>(iface & Interfaces::InterfaceUserObject))
      66           0 :     os << "|InterfaceUserObject";
      67           0 :   if (static_cast<bool>(iface & Interfaces::Reporter))
      68           0 :     os << "|Reporter";
      69           0 :   if (static_cast<bool>(iface & Interfaces::DomainUserObject))
      70           0 :     os << "|DomainUserObject";
      71           0 :   if (static_cast<bool>(iface & Interfaces::MortarUserObject))
      72           0 :     os << "|MortarUserObject";
      73           0 :   if (static_cast<bool>(iface & Interfaces::FVInterpolationMethod))
      74           0 :     os << "|FVInterpolationMethod";
      75           0 :   os << ")";
      76           0 :   return os;
      77             : }
      78             : 
      79             : bool
      80       41447 : AttribTagBase::isMatch(const Attribute & other) const
      81             : {
      82       41447 :   auto a = dynamic_cast<const AttribTagBase *>(&other);
      83       41447 :   if (!a)
      84           0 :     return false;
      85       41447 :   if (a->_vals.size() == 0)
      86           0 :     return true; // the condition is empty tags - which we take to mean any tag should match
      87             : 
      88             :   // return true if any single tag matches between the two attribute objects
      89       42477 :   for (auto val : _vals)
      90       41422 :     if (std::find(a->_vals.begin(), a->_vals.end(), val) != a->_vals.end())
      91       40392 :       return true;
      92        1055 :   return false;
      93             : }
      94             : 
      95             : bool
      96     7264745 : AttribTagBase::isEqual(const Attribute & other) const
      97             : {
      98     7264745 :   auto a = dynamic_cast<const AttribTagBase *>(&other);
      99     7264745 :   if (!a || a->_vals.size() != _vals.size())
     100           0 :     return false;
     101             : 
     102    24448130 :   for (size_t i = 0; i < a->_vals.size(); i++)
     103    17183385 :     if (a->_vals[i] != _vals[i])
     104           0 :       return false;
     105     7264745 :   return true;
     106             : }
     107             : 
     108             : void
     109      301823 : AttribMatrixTags::initFrom(const MooseObject * obj)
     110             : {
     111      301823 :   _vals.clear();
     112      301823 :   auto t = dynamic_cast<const TaggingInterface *>(obj);
     113      301823 :   if (t)
     114             :   {
     115      450588 :     for (auto & tag : t->getMatrixTags({}))
     116      269257 :       _vals.push_back(static_cast<int>(tag));
     117             :   }
     118      301823 : }
     119             : 
     120             : void
     121      301823 : AttribVectorTags::initFrom(const MooseObject * obj)
     122             : {
     123      301823 :   _vals.clear();
     124      301823 :   auto t = dynamic_cast<const TaggingInterface *>(obj);
     125      301823 :   if (t)
     126             :   {
     127      366281 :     for (auto & tag : t->getVectorTags({}))
     128      184950 :       _vals.push_back(static_cast<int>(tag));
     129             :   }
     130      301823 : }
     131             : 
     132             : void
     133      301823 : AttribExecOns::initFrom(const MooseObject * obj)
     134             : {
     135      301823 :   _vals.clear();
     136      301823 :   if (const auto sup = dynamic_cast<const SetupInterface *>(obj))
     137             :   {
     138      257381 :     const auto & current_items = sup->getExecuteOnEnum();
     139      257381 :     _vals.reserve(current_items.size());
     140      347555 :     for (auto & on : current_items)
     141       90174 :       _vals.push_back(on);
     142             :   }
     143      301823 : }
     144             : 
     145             : bool
     146     3088633 : AttribExecOns::isMatch(const Attribute & other) const
     147             : {
     148     3088633 :   auto a = dynamic_cast<const AttribExecOns *>(&other);
     149     3088633 :   if (!a || a->_vals.empty())
     150           0 :     return false;
     151     3088633 :   auto cond = a->_vals[0];
     152     3088633 :   if (cond == EXEC_ALL)
     153        1128 :     return true;
     154             : 
     155     5105644 :   for (const auto val : _vals)
     156     3678582 :     if (val == EXEC_ALL || val == cond)
     157     1660443 :       return true;
     158     1427062 :   return false;
     159             : }
     160             : 
     161             : bool
     162    32193790 : AttribExecOns::isEqual(const Attribute & other) const
     163             : {
     164    32193790 :   auto a = dynamic_cast<const AttribExecOns *>(&other);
     165    32193790 :   if (!a || a->_vals.size() != _vals.size())
     166           0 :     return false;
     167             : 
     168    64387580 :   for (size_t i = 0; i < a->_vals.size(); i++)
     169    32193790 :     if (a->_vals[i] != _vals[i])
     170           0 :       return false;
     171    32193790 :   return true;
     172             : }
     173             : 
     174             : void
     175      301823 : AttribSubdomains::initFrom(const MooseObject * obj)
     176             : {
     177      301823 :   _vals.clear();
     178      301823 :   auto blk = dynamic_cast<const BlockRestrictable *>(obj);
     179      301823 :   if (blk && blk->blockRestricted())
     180             :   {
     181       34140 :     for (auto id : blk->blockIDs())
     182       18801 :       _vals.push_back(id);
     183             :   }
     184             :   else
     185      286484 :     _vals.push_back(Moose::ANY_BLOCK_ID);
     186      301823 : }
     187             : 
     188             : bool
     189     1040462 : AttribSubdomains::isMatch(const Attribute & other) const
     190             : {
     191     1040462 :   auto a = dynamic_cast<const AttribSubdomains *>(&other);
     192     1040462 :   if (!a || a->_vals.size() < 1)
     193           0 :     return false;
     194             : 
     195     1040462 :   auto cond = a->_vals[0];
     196     1040462 :   if (cond == Moose::ANY_BLOCK_ID)
     197           0 :     return true;
     198     1040462 :   else if (cond == Moose::INVALID_BLOCK_ID)
     199        7014 :     return false;
     200             : 
     201     1171046 :   for (auto id : _vals)
     202             :   {
     203     1076688 :     if (id == cond || id == Moose::ANY_BLOCK_ID)
     204      939090 :       return true;
     205             :   }
     206       94358 :   return false;
     207             : }
     208             : 
     209             : bool
     210     6079923 : AttribSubdomains::isEqual(const Attribute & other) const
     211             : {
     212     6079923 :   auto a = dynamic_cast<const AttribSubdomains *>(&other);
     213     6079923 :   if (!a || a->_vals.size() != _vals.size())
     214           0 :     return false;
     215             : 
     216    12159846 :   for (size_t i = 0; i < a->_vals.size(); i++)
     217     6079923 :     if (a->_vals[i] != _vals[i])
     218           0 :       return false;
     219     6079923 :   return true;
     220             : }
     221             : 
     222             : void
     223      301823 : AttribBoundaries::initFrom(const MooseObject * obj)
     224             : {
     225      301823 :   _vals.clear();
     226      301823 :   auto bnd = dynamic_cast<const BoundaryRestrictable *>(obj);
     227      301823 :   if (bnd && bnd->boundaryRestricted())
     228             :   {
     229      206618 :     for (auto & bound : bnd->boundaryIDs())
     230      116221 :       _vals.push_back(bound);
     231             :   }
     232             :   else
     233      211426 :     _vals.push_back(Moose::ANY_BOUNDARY_ID);
     234      301823 : }
     235             : 
     236             : bool
     237      714627 : AttribBoundaries::isMatch(const Attribute & other) const
     238             : {
     239      714627 :   auto a = dynamic_cast<const AttribBoundaries *>(&other);
     240      714627 :   if (!a || a->_vals.size() < 1)
     241           0 :     return false;
     242             : 
     243             :   // return true if a single tag matches between the two attribute objects
     244      977563 :   for (auto val : _vals)
     245             :   {
     246      793141 :     if (!a->_must_be_restricted && (val == Moose::ANY_BOUNDARY_ID))
     247      530205 :       return true;
     248      347535 :     if (std::find(a->_vals.begin(), a->_vals.end(), val) != a->_vals.end())
     249       79721 :       return true;
     250      267814 :     else if (std::find(a->_vals.begin(), a->_vals.end(), Moose::ANY_BOUNDARY_ID) != a->_vals.end())
     251        4878 :       return true;
     252             :   }
     253      184422 :   return false;
     254             : }
     255             : 
     256             : bool
     257     9554831 : AttribBoundaries::isEqual(const Attribute & other) const
     258             : {
     259     9554831 :   auto a = dynamic_cast<const AttribBoundaries *>(&other);
     260     9554831 :   if (!a || a->_vals.size() != _vals.size())
     261           0 :     return false;
     262             : 
     263    19109662 :   for (size_t i = 0; i < a->_vals.size(); i++)
     264     9554831 :     if (a->_vals[i] != _vals[i])
     265           0 :       return false;
     266     9554831 :   return true;
     267             : }
     268             : 
     269             : void
     270      301823 : AttribThread::initFrom(const MooseObject * obj)
     271             : {
     272      603646 :   _val = obj->getParam<THREAD_ID>("_tid");
     273      301823 : }
     274             : bool
     275    24527572 : AttribThread::isMatch(const Attribute & other) const
     276             : {
     277    24527572 :   auto a = dynamic_cast<const AttribThread *>(&other);
     278    24527572 :   return a && (a->_val == _val);
     279             : }
     280             : bool
     281    21257511 : AttribThread::isEqual(const Attribute & other) const
     282             : {
     283    21257511 :   return isMatch(other);
     284             : }
     285             : 
     286             : void
     287      301823 : AttribExecutionOrderGroup::initFrom(const MooseObject * obj)
     288             : {
     289      301823 :   const auto * uo = dynamic_cast<const UserObjectBase *>(obj);
     290      374962 :   _val = uo ? uo->getParam<int>("execution_order_group") : 0;
     291      301823 : }
     292             : bool
     293    10271345 : AttribExecutionOrderGroup::isMatch(const Attribute & other) const
     294             : {
     295    10271345 :   auto a = dynamic_cast<const AttribExecutionOrderGroup *>(&other);
     296    10271345 :   return a && (a->_val == _val);
     297             : }
     298             : bool
     299     8856836 : AttribExecutionOrderGroup::isEqual(const Attribute & other) const
     300             : {
     301     8856836 :   return isMatch(other);
     302             : }
     303             : 
     304             : void
     305      301823 : AttribSysNum::initFrom(const MooseObject * obj)
     306             : {
     307      603646 :   auto * sys = obj->getParam<SystemBase *>("_sys");
     308             : 
     309      301823 :   if (sys)
     310      301394 :     _val = sys->number();
     311      301823 : }
     312             : 
     313             : bool
     314     8306803 : AttribSysNum::isMatch(const Attribute & other) const
     315             : {
     316     8306803 :   auto a = dynamic_cast<const AttribSysNum *>(&other);
     317     8306803 :   return a && (a->_val == _val);
     318             : }
     319             : 
     320             : bool
     321     7639750 : AttribSysNum::isEqual(const Attribute & other) const
     322             : {
     323     7639750 :   return isMatch(other);
     324             : }
     325             : 
     326             : void
     327      301823 : AttribPreIC::initFrom(const MooseObject * /*obj*/)
     328             : {
     329      301823 : }
     330             : bool
     331       15293 : AttribPreIC::isMatch(const Attribute & other) const
     332             : {
     333       15293 :   auto a = dynamic_cast<const AttribPreIC *>(&other);
     334       15293 :   return a && (a->_val == _val);
     335             : }
     336             : 
     337             : bool
     338          61 : AttribPreIC::isEqual(const Attribute & other) const
     339             : {
     340          61 :   return isMatch(other);
     341             : }
     342             : 
     343             : bool
     344      176503 : AttribPreAux::isMatch(const Attribute & other) const
     345             : {
     346      176503 :   const auto a = dynamic_cast<const AttribPreAux *>(&other);
     347             : 
     348      176503 :   bool is_match = false;
     349             : 
     350      176503 :   if (a && !_vals.empty() && !a->_vals.empty())
     351             :   {
     352       56252 :     is_match = std::includes(_vals.begin(), _vals.end(), a->_vals.begin(), a->_vals.end()) ||
     353        4016 :                std::includes(a->_vals.begin(), a->_vals.end(), _vals.begin(), _vals.end());
     354             :   }
     355             : 
     356      176503 :   return is_match;
     357             : }
     358             : 
     359             : bool
     360     9149880 : AttribPreAux::isEqual(const Attribute & other) const
     361             : {
     362     9149880 :   const auto a = dynamic_cast<const AttribPreAux *>(&other);
     363     9149880 :   return a && a->_vals == _vals;
     364             : }
     365             : 
     366             : void
     367      301823 : AttribPreAux::initFrom(const MooseObject * /*obj*/)
     368             : {
     369      301823 : }
     370             : 
     371             : bool
     372     1466862 : AttribPostAux::isMatch(const Attribute & other) const
     373             : {
     374     1466862 :   const auto a = dynamic_cast<const AttribPostAux *>(&other);
     375             : 
     376     1466862 :   bool is_match = false;
     377             : 
     378     1466862 :   if (a && !_vals.empty() && !a->_vals.empty())
     379             :   {
     380     1473803 :     is_match = std::includes(_vals.begin(), _vals.end(), a->_vals.begin(), a->_vals.end()) ||
     381       11935 :                std::includes(a->_vals.begin(), a->_vals.end(), _vals.begin(), _vals.end());
     382             :   }
     383             : 
     384     1466862 :   return is_match;
     385             : }
     386             : 
     387             : bool
     388    17663879 : AttribPostAux::isEqual(const Attribute & other) const
     389             : {
     390    17663879 :   const auto a = dynamic_cast<const AttribPostAux *>(&other);
     391    17663879 :   return a && a->_vals == _vals;
     392             : }
     393             : 
     394             : void
     395      301823 : AttribPostAux::initFrom(const MooseObject * /*obj*/)
     396             : {
     397      301823 : }
     398             : 
     399             : void
     400      301823 : AttribName::initFrom(const MooseObject * obj)
     401             : {
     402      301823 :   _val = obj->name();
     403      301823 : }
     404             : bool
     405     1504176 : AttribName::isMatch(const Attribute & other) const
     406             : {
     407     1504176 :   auto a = dynamic_cast<const AttribName *>(&other);
     408     1504176 :   return a && (a->_val == _val);
     409             : }
     410             : 
     411             : bool
     412     1281476 : AttribName::isEqual(const Attribute & other) const
     413             : {
     414     1281476 :   return isMatch(other);
     415             : }
     416             : 
     417             : void
     418      301823 : AttribSystem::initFrom(const MooseObject * obj)
     419             : {
     420      301823 :   _val = obj->parameters().getSystemAttributeName();
     421      301823 : }
     422             : 
     423             : bool
     424    70284862 : AttribSystem::isMatch(const Attribute & other) const
     425             : {
     426    70284862 :   auto a = dynamic_cast<const AttribSystem *>(&other);
     427    70284862 :   return a && (a->_val == _val);
     428             : }
     429             : 
     430             : bool
     431    48570686 : AttribSystem::isEqual(const Attribute & other) const
     432             : {
     433    48570686 :   return isMatch(other);
     434             : }
     435             : 
     436             : void
     437      301823 : AttribResidualObject::initFrom(const MooseObject * obj)
     438             : {
     439      603646 :   _val = obj->getParam<bool>("_residual_object");
     440      301823 :   _initd = true;
     441      301823 : }
     442             : 
     443             : bool
     444           0 : AttribResidualObject::isMatch(const Attribute & other) const
     445             : {
     446           0 :   auto a = dynamic_cast<const AttribResidualObject *>(&other);
     447           0 :   return _initd && a && a->_initd && (a->_val == _val);
     448             : }
     449             : 
     450             : bool
     451           0 : AttribResidualObject::isEqual(const Attribute & other) const
     452             : {
     453           0 :   return isMatch(other);
     454             : }
     455             : 
     456             : void
     457      301823 : AttribVar::initFrom(const MooseObject * obj)
     458             : {
     459      301823 :   auto vi = dynamic_cast<const MooseVariableInterface<Real> *>(obj);
     460      301823 :   if (vi)
     461      204756 :     _val = static_cast<int>(vi->mooseVariableBase()->number());
     462      301823 : }
     463             : bool
     464      186587 : AttribVar::isMatch(const Attribute & other) const
     465             : {
     466      186587 :   auto a = dynamic_cast<const AttribVar *>(&other);
     467      186587 :   return a && (_val != -1) && (a->_val == _val);
     468             : }
     469             : 
     470             : bool
     471      127596 : AttribVar::isEqual(const Attribute & other) const
     472             : {
     473      127596 :   return isMatch(other);
     474             : }
     475             : 
     476             : void
     477      301823 : AttribInterfaces::initFrom(const MooseObject * obj)
     478             : {
     479      301823 :   _val = 0;
     480             :   // clang-format off
     481      301823 :   _val |= (unsigned int)Interfaces::UserObject                * (dynamic_cast<const UserObjectBase *>(obj) != nullptr);
     482      301823 :   _val |= (unsigned int)Interfaces::ElementUserObject         * (dynamic_cast<const ElementUserObject *>(obj) != nullptr);
     483      301823 :   _val |= (unsigned int)Interfaces::SideUserObject            * (dynamic_cast<const SideUserObject *>(obj) != nullptr);
     484      301823 :   _val |= (unsigned int)Interfaces::InternalSideUserObject    * (dynamic_cast<const InternalSideUserObject *>(obj) != nullptr);
     485      301823 :   _val |= (unsigned int)Interfaces::InterfaceUserObject       * (dynamic_cast<const InterfaceUserObject *>(obj) != nullptr);
     486      301823 :   _val |= (unsigned int)Interfaces::NodalUserObject           * (dynamic_cast<const NodalUserObject *>(obj) != nullptr);
     487      301823 :   _val |= (unsigned int)Interfaces::GeneralUserObject         * (dynamic_cast<const GeneralUserObject *>(obj) != nullptr);
     488      301823 :   _val |= (unsigned int)Interfaces::ThreadedGeneralUserObject * (dynamic_cast<const ThreadedGeneralUserObject *>(obj) != nullptr);
     489      301823 :   _val |= (unsigned int)Interfaces::ShapeElementUserObject    * (dynamic_cast<const ShapeElementUserObject *>(obj) != nullptr);
     490      301823 :   _val |= (unsigned int)Interfaces::ShapeSideUserObject       * (dynamic_cast<const ShapeSideUserObject *>(obj) != nullptr);
     491      301823 :   _val |= (unsigned int)Interfaces::Postprocessor             * (dynamic_cast<const Postprocessor *>(obj) != nullptr);
     492      301823 :   _val |= (unsigned int)Interfaces::VectorPostprocessor       * (dynamic_cast<const VectorPostprocessor *>(obj) != nullptr);
     493      301823 :   _val |= (unsigned int)Interfaces::BlockRestrictable         * (dynamic_cast<const BlockRestrictable *>(obj) != nullptr);
     494      301823 :   _val |= (unsigned int)Interfaces::BoundaryRestrictable      * (dynamic_cast<const BoundaryRestrictable *>(obj) != nullptr);
     495      301823 :   _val |= (unsigned int)Interfaces::Reporter                  * (dynamic_cast<const Reporter *>(obj) != nullptr);
     496      301823 :   _val |= (unsigned int)Interfaces::DomainUserObject          * (dynamic_cast<const DomainUserObject *>(obj) != nullptr);
     497      301823 :   _val |= (unsigned int)Interfaces::MortarUserObject          * (dynamic_cast<const MortarUserObject *>(obj) != nullptr);
     498      301823 :   _val |= (unsigned int)Interfaces::FVInterpolationMethod     * (dynamic_cast<const FVInterpolationMethod *>(obj) != nullptr);
     499             :   // clang-format on
     500      301823 : }
     501             : 
     502             : bool
     503     5214945 : AttribInterfaces::isMatch(const Attribute & other) const
     504             : {
     505     5214945 :   auto a = dynamic_cast<const AttribInterfaces *>(&other);
     506     5214945 :   return a && (a->_val & _val);
     507             : }
     508             : 
     509             : bool
     510    14158432 : AttribInterfaces::isEqual(const Attribute & other) const
     511             : {
     512    14158432 :   auto a = dynamic_cast<const AttribInterfaces *>(&other);
     513    14158432 :   return a && (a->_val == _val);
     514             : }
     515             : 
     516             : void
     517      301823 : AttribDisplaced::initFrom(const MooseObject * obj)
     518             : {
     519      554229 :   _val = obj->parameters().have_parameter<bool>("use_displaced_mesh") &&
     520      806635 :          obj->getParam<bool>("use_displaced_mesh");
     521      301823 : }
     522             : 
     523             : bool
     524     7036120 : AttribDisplaced::isMatch(const Attribute & other) const
     525             : {
     526     7036120 :   auto a = dynamic_cast<const AttribDisplaced *>(&other);
     527     7036120 :   return a && (a->_val == _val);
     528             : }
     529             : 
     530             : bool
     531     6991726 : AttribDisplaced::isEqual(const Attribute & other) const
     532             : {
     533     6991726 :   return isMatch(other);
     534             : }

Generated by: LCOV version 1.14