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 "ExecFlagRegistry.h" 33 : 34 : #include <algorithm> 35 : 36 : const ExecFlagType AttribExecOns::EXEC_ALL = registerExecFlag("ALL"); 37 : 38 : std::ostream & 39 0 : operator<<(std::ostream & os, Interfaces & iface) 40 : { 41 0 : os << "Interfaces("; 42 0 : if (static_cast<bool>(iface & Interfaces::UserObject)) 43 0 : os << "|UserObject"; 44 0 : if (static_cast<bool>(iface & Interfaces::ElementUserObject)) 45 0 : os << "|ElementUserObject"; 46 0 : if (static_cast<bool>(iface & Interfaces::SideUserObject)) 47 0 : os << "|SideUserObject"; 48 0 : if (static_cast<bool>(iface & Interfaces::InternalSideUserObject)) 49 0 : os << "|InternalSideUserObject"; 50 0 : if (static_cast<bool>(iface & Interfaces::NodalUserObject)) 51 0 : os << "|NodalUserObject"; 52 0 : if (static_cast<bool>(iface & Interfaces::GeneralUserObject)) 53 0 : os << "|GeneralUserObject"; 54 0 : if (static_cast<bool>(iface & Interfaces::ThreadedGeneralUserObject)) 55 0 : os << "|ThreadedGeneralUserObject"; 56 0 : if (static_cast<bool>(iface & Interfaces::ShapeElementUserObject)) 57 0 : os << "|ShapeElementUserObject"; 58 0 : if (static_cast<bool>(iface & Interfaces::ShapeSideUserObject)) 59 0 : os << "|ShapeSideUserObject"; 60 0 : if (static_cast<bool>(iface & Interfaces::Postprocessor)) 61 0 : os << "|Postprocessor"; 62 0 : if (static_cast<bool>(iface & Interfaces::VectorPostprocessor)) 63 0 : os << "|VectorPostprocessor"; 64 0 : if (static_cast<bool>(iface & Interfaces::InterfaceUserObject)) 65 0 : os << "|InterfaceUserObject"; 66 0 : if (static_cast<bool>(iface & Interfaces::Reporter)) 67 0 : os << "|Reporter"; 68 0 : if (static_cast<bool>(iface & Interfaces::DomainUserObject)) 69 0 : os << "|DomainUserObject"; 70 0 : if (static_cast<bool>(iface & Interfaces::MortarUserObject)) 71 0 : os << "|MortarUserObject"; 72 0 : os << ")"; 73 0 : return os; 74 : } 75 : 76 : bool 77 59473 : AttribTagBase::isMatch(const Attribute & other) const 78 : { 79 59473 : auto a = dynamic_cast<const AttribTagBase *>(&other); 80 59473 : if (!a) 81 0 : return false; 82 59473 : if (a->_vals.size() == 0) 83 0 : return true; // the condition is empty tags - which we take to mean any tag should match 84 : 85 : // return true if any single tag matches between the two attribute objects 86 60597 : for (auto val : _vals) 87 59446 : if (std::find(a->_vals.begin(), a->_vals.end(), val) != a->_vals.end()) 88 58322 : return true; 89 1151 : return false; 90 : } 91 : 92 : bool 93 9228257 : AttribTagBase::isEqual(const Attribute & other) const 94 : { 95 9228257 : auto a = dynamic_cast<const AttribTagBase *>(&other); 96 9228257 : if (!a || a->_vals.size() != _vals.size()) 97 0 : return false; 98 : 99 31699331 : for (size_t i = 0; i < a->_vals.size(); i++) 100 22471074 : if (a->_vals[i] != _vals[i]) 101 0 : return false; 102 9228257 : return true; 103 : } 104 : 105 : void 106 321099 : AttribMatrixTags::initFrom(const MooseObject * obj) 107 : { 108 321099 : _vals.clear(); 109 321099 : auto t = dynamic_cast<const TaggingInterface *>(obj); 110 321099 : if (t) 111 : { 112 505595 : for (auto & tag : t->getMatrixTags({})) 113 301376 : _vals.push_back(static_cast<int>(tag)); 114 : } 115 321099 : } 116 : 117 : void 118 321099 : AttribVectorTags::initFrom(const MooseObject * obj) 119 : { 120 321099 : _vals.clear(); 121 321099 : auto t = dynamic_cast<const TaggingInterface *>(obj); 122 321099 : if (t) 123 : { 124 412313 : for (auto & tag : t->getVectorTags({})) 125 208094 : _vals.push_back(static_cast<int>(tag)); 126 : } 127 321099 : } 128 : 129 : void 130 321099 : AttribExecOns::initFrom(const MooseObject * obj) 131 : { 132 321099 : _vals.clear(); 133 321099 : if (const auto sup = dynamic_cast<const SetupInterface *>(obj)) 134 : { 135 288217 : const auto & current_items = sup->getExecuteOnEnum(); 136 288217 : _vals.reserve(current_items.size()); 137 387615 : for (auto & on : current_items) 138 99398 : _vals.push_back(on); 139 : } 140 321099 : } 141 : 142 : bool 143 3475629 : AttribExecOns::isMatch(const Attribute & other) const 144 : { 145 3475629 : auto a = dynamic_cast<const AttribExecOns *>(&other); 146 3475629 : if (!a || a->_vals.empty()) 147 0 : return false; 148 3475629 : auto cond = a->_vals[0]; 149 3475629 : if (cond == EXEC_ALL) 150 1464 : return true; 151 : 152 5724396 : for (const auto val : _vals) 153 4126293 : if (val == EXEC_ALL || val == cond) 154 1876062 : return true; 155 1598103 : return false; 156 : } 157 : 158 : bool 159 26690103 : AttribExecOns::isEqual(const Attribute & other) const 160 : { 161 26690103 : auto a = dynamic_cast<const AttribExecOns *>(&other); 162 26690103 : if (!a || a->_vals.size() != _vals.size()) 163 0 : return false; 164 : 165 53380206 : for (size_t i = 0; i < a->_vals.size(); i++) 166 26690103 : if (a->_vals[i] != _vals[i]) 167 0 : return false; 168 26690103 : return true; 169 : } 170 : 171 : void 172 321099 : AttribSubdomains::initFrom(const MooseObject * obj) 173 : { 174 321099 : _vals.clear(); 175 321099 : auto blk = dynamic_cast<const BlockRestrictable *>(obj); 176 321099 : if (blk && blk->blockRestricted()) 177 : { 178 38349 : for (auto id : blk->blockIDs()) 179 21107 : _vals.push_back(id); 180 : } 181 : else 182 303857 : _vals.push_back(Moose::ANY_BLOCK_ID); 183 321099 : } 184 : 185 : bool 186 1181079 : AttribSubdomains::isMatch(const Attribute & other) const 187 : { 188 1181079 : auto a = dynamic_cast<const AttribSubdomains *>(&other); 189 1181079 : if (!a || a->_vals.size() < 1) 190 0 : return false; 191 : 192 1181079 : auto cond = a->_vals[0]; 193 1181079 : if (cond == Moose::ANY_BLOCK_ID) 194 0 : return true; 195 1181079 : else if (cond == Moose::INVALID_BLOCK_ID) 196 9519 : return false; 197 : 198 1335079 : for (auto id : _vals) 199 : { 200 1223042 : if (id == cond || id == Moose::ANY_BLOCK_ID) 201 1059523 : return true; 202 : } 203 112037 : return false; 204 : } 205 : 206 : bool 207 7200337 : AttribSubdomains::isEqual(const Attribute & other) const 208 : { 209 7200337 : auto a = dynamic_cast<const AttribSubdomains *>(&other); 210 7200337 : if (!a || a->_vals.size() != _vals.size()) 211 0 : return false; 212 : 213 14400674 : for (size_t i = 0; i < a->_vals.size(); i++) 214 7200337 : if (a->_vals[i] != _vals[i]) 215 0 : return false; 216 7200337 : return true; 217 : } 218 : 219 : void 220 321099 : AttribBoundaries::initFrom(const MooseObject * obj) 221 : { 222 321099 : _vals.clear(); 223 321099 : auto bnd = dynamic_cast<const BoundaryRestrictable *>(obj); 224 321099 : if (bnd && bnd->boundaryRestricted()) 225 : { 226 232366 : for (auto & bound : bnd->boundaryIDs()) 227 130919 : _vals.push_back(bound); 228 : } 229 : else 230 219652 : _vals.push_back(Moose::ANY_BOUNDARY_ID); 231 321099 : } 232 : 233 : bool 234 817671 : AttribBoundaries::isMatch(const Attribute & other) const 235 : { 236 817671 : auto a = dynamic_cast<const AttribBoundaries *>(&other); 237 817671 : if (!a || a->_vals.size() < 1) 238 0 : return false; 239 : 240 : // return true if a single tag matches between the two attribute objects 241 1127884 : for (auto val : _vals) 242 : { 243 914502 : if (!a->_must_be_restricted && (val == Moose::ANY_BOUNDARY_ID)) 244 604289 : return true; 245 412822 : if (std::find(a->_vals.begin(), a->_vals.end(), val) != a->_vals.end()) 246 97089 : return true; 247 315733 : else if (std::find(a->_vals.begin(), a->_vals.end(), Moose::ANY_BOUNDARY_ID) != a->_vals.end()) 248 5520 : return true; 249 : } 250 213382 : return false; 251 : } 252 : 253 : bool 254 11081035 : AttribBoundaries::isEqual(const Attribute & other) const 255 : { 256 11081035 : auto a = dynamic_cast<const AttribBoundaries *>(&other); 257 11081035 : if (!a || a->_vals.size() != _vals.size()) 258 0 : return false; 259 : 260 22162070 : for (size_t i = 0; i < a->_vals.size(); i++) 261 11081035 : if (a->_vals[i] != _vals[i]) 262 0 : return false; 263 11081035 : return true; 264 : } 265 : 266 : void 267 321099 : AttribThread::initFrom(const MooseObject * obj) 268 : { 269 642198 : _val = obj->getParam<THREAD_ID>("_tid"); 270 321099 : } 271 : bool 272 28365613 : AttribThread::isMatch(const Attribute & other) const 273 : { 274 28365613 : auto a = dynamic_cast<const AttribThread *>(&other); 275 28365613 : return a && (a->_val == _val); 276 : } 277 : bool 278 24665694 : AttribThread::isEqual(const Attribute & other) const 279 : { 280 24665694 : return isMatch(other); 281 : } 282 : 283 : void 284 321099 : AttribExecutionOrderGroup::initFrom(const MooseObject * obj) 285 : { 286 321099 : const auto * uo = dynamic_cast<const UserObject *>(obj); 287 404715 : _val = uo ? uo->getParam<int>("execution_order_group") : 0; 288 321099 : } 289 : bool 290 10977590 : AttribExecutionOrderGroup::isMatch(const Attribute & other) const 291 : { 292 10977590 : auto a = dynamic_cast<const AttribExecutionOrderGroup *>(&other); 293 10977590 : return a && (a->_val == _val); 294 : } 295 : bool 296 9372912 : AttribExecutionOrderGroup::isEqual(const Attribute & other) const 297 : { 298 9372912 : return isMatch(other); 299 : } 300 : 301 : void 302 321099 : AttribSysNum::initFrom(const MooseObject * obj) 303 : { 304 642198 : auto * sys = obj->getParam<SystemBase *>("_sys"); 305 : 306 321099 : if (sys) 307 320614 : _val = sys->number(); 308 321099 : } 309 : 310 : bool 311 10686810 : AttribSysNum::isMatch(const Attribute & other) const 312 : { 313 10686810 : auto a = dynamic_cast<const AttribSysNum *>(&other); 314 10686810 : return a && (a->_val == _val); 315 : } 316 : 317 : bool 318 9822994 : AttribSysNum::isEqual(const Attribute & other) const 319 : { 320 9822994 : return isMatch(other); 321 : } 322 : 323 : void 324 321099 : AttribPreIC::initFrom(const MooseObject * /*obj*/) 325 : { 326 321099 : } 327 : bool 328 16347 : AttribPreIC::isMatch(const Attribute & other) const 329 : { 330 16347 : auto a = dynamic_cast<const AttribPreIC *>(&other); 331 16347 : return a && (a->_val == _val); 332 : } 333 : 334 : bool 335 68 : AttribPreIC::isEqual(const Attribute & other) const 336 : { 337 68 : return isMatch(other); 338 : } 339 : 340 : bool 341 197932 : AttribPreAux::isMatch(const Attribute & other) const 342 : { 343 197932 : const auto a = dynamic_cast<const AttribPreAux *>(&other); 344 : 345 197932 : bool is_match = false; 346 : 347 197932 : if (a && !_vals.empty() && !a->_vals.empty()) 348 : { 349 62593 : is_match = std::includes(_vals.begin(), _vals.end(), a->_vals.begin(), a->_vals.end()) || 350 4417 : std::includes(a->_vals.begin(), a->_vals.end(), _vals.begin(), _vals.end()); 351 : } 352 : 353 197932 : return is_match; 354 : } 355 : 356 : bool 357 5888600 : AttribPreAux::isEqual(const Attribute & other) const 358 : { 359 5888600 : const auto a = dynamic_cast<const AttribPreAux *>(&other); 360 5888600 : return a && a->_vals == _vals; 361 : } 362 : 363 : void 364 321099 : AttribPreAux::initFrom(const MooseObject * /*obj*/) 365 : { 366 321099 : } 367 : 368 : bool 369 1656840 : AttribPostAux::isMatch(const Attribute & other) const 370 : { 371 1656840 : const auto a = dynamic_cast<const AttribPostAux *>(&other); 372 : 373 1656840 : bool is_match = false; 374 : 375 1656840 : if (a && !_vals.empty() && !a->_vals.empty()) 376 : { 377 1664726 : is_match = std::includes(_vals.begin(), _vals.end(), a->_vals.begin(), a->_vals.end()) || 378 13381 : std::includes(a->_vals.begin(), a->_vals.end(), _vals.begin(), _vals.end()); 379 : } 380 : 381 1656840 : return is_match; 382 : } 383 : 384 : bool 385 14895044 : AttribPostAux::isEqual(const Attribute & other) const 386 : { 387 14895044 : const auto a = dynamic_cast<const AttribPostAux *>(&other); 388 14895044 : return a && a->_vals == _vals; 389 : } 390 : 391 : void 392 321099 : AttribPostAux::initFrom(const MooseObject * /*obj*/) 393 : { 394 321099 : } 395 : 396 : void 397 321099 : AttribName::initFrom(const MooseObject * obj) 398 : { 399 321099 : _val = obj->name(); 400 321099 : } 401 : bool 402 1538236 : AttribName::isMatch(const Attribute & other) const 403 : { 404 1538236 : auto a = dynamic_cast<const AttribName *>(&other); 405 1538236 : return a && (a->_val == _val); 406 : } 407 : 408 : bool 409 1287755 : AttribName::isEqual(const Attribute & other) const 410 : { 411 1287755 : return isMatch(other); 412 : } 413 : 414 : void 415 321099 : AttribSystem::initFrom(const MooseObject * obj) 416 : { 417 321099 : _val = obj->parameters().getSystemAttributeName(); 418 321099 : } 419 : 420 : bool 421 63542718 : AttribSystem::isMatch(const Attribute & other) const 422 : { 423 63542718 : auto a = dynamic_cast<const AttribSystem *>(&other); 424 63542718 : return a && (a->_val == _val); 425 : } 426 : 427 : bool 428 45218213 : AttribSystem::isEqual(const Attribute & other) const 429 : { 430 45218213 : return isMatch(other); 431 : } 432 : 433 : void 434 321099 : AttribResidualObject::initFrom(const MooseObject * obj) 435 : { 436 642198 : _val = obj->getParam<bool>("_residual_object"); 437 321099 : _initd = true; 438 321099 : } 439 : 440 : bool 441 0 : AttribResidualObject::isMatch(const Attribute & other) const 442 : { 443 0 : auto a = dynamic_cast<const AttribResidualObject *>(&other); 444 0 : return _initd && a && a->_initd && (a->_val == _val); 445 : } 446 : 447 : bool 448 0 : AttribResidualObject::isEqual(const Attribute & other) const 449 : { 450 0 : return isMatch(other); 451 : } 452 : 453 : void 454 321099 : AttribVar::initFrom(const MooseObject * obj) 455 : { 456 321099 : auto vi = dynamic_cast<const MooseVariableInterface<Real> *>(obj); 457 321099 : if (vi) 458 228510 : _val = static_cast<int>(vi->mooseVariableBase()->number()); 459 321099 : } 460 : bool 461 224619 : AttribVar::isMatch(const Attribute & other) const 462 : { 463 224619 : auto a = dynamic_cast<const AttribVar *>(&other); 464 224619 : return a && (_val != -1) && (a->_val == _val); 465 : } 466 : 467 : bool 468 152868 : AttribVar::isEqual(const Attribute & other) const 469 : { 470 152868 : return isMatch(other); 471 : } 472 : 473 : void 474 321099 : AttribInterfaces::initFrom(const MooseObject * obj) 475 : { 476 321099 : _val = 0; 477 : // clang-format off 478 321099 : _val |= (unsigned int)Interfaces::UserObject * (dynamic_cast<const UserObject *>(obj) != nullptr); 479 321099 : _val |= (unsigned int)Interfaces::ElementUserObject * (dynamic_cast<const ElementUserObject *>(obj) != nullptr); 480 321099 : _val |= (unsigned int)Interfaces::SideUserObject * (dynamic_cast<const SideUserObject *>(obj) != nullptr); 481 321099 : _val |= (unsigned int)Interfaces::InternalSideUserObject * (dynamic_cast<const InternalSideUserObject *>(obj) != nullptr); 482 321099 : _val |= (unsigned int)Interfaces::InterfaceUserObject * (dynamic_cast<const InterfaceUserObject *>(obj) != nullptr); 483 321099 : _val |= (unsigned int)Interfaces::NodalUserObject * (dynamic_cast<const NodalUserObject *>(obj) != nullptr); 484 321099 : _val |= (unsigned int)Interfaces::GeneralUserObject * (dynamic_cast<const GeneralUserObject *>(obj) != nullptr); 485 321099 : _val |= (unsigned int)Interfaces::ThreadedGeneralUserObject * (dynamic_cast<const ThreadedGeneralUserObject *>(obj) != nullptr); 486 321099 : _val |= (unsigned int)Interfaces::ShapeElementUserObject * (dynamic_cast<const ShapeElementUserObject *>(obj) != nullptr); 487 321099 : _val |= (unsigned int)Interfaces::ShapeSideUserObject * (dynamic_cast<const ShapeSideUserObject *>(obj) != nullptr); 488 321099 : _val |= (unsigned int)Interfaces::Postprocessor * (dynamic_cast<const Postprocessor *>(obj) != nullptr); 489 321099 : _val |= (unsigned int)Interfaces::VectorPostprocessor * (dynamic_cast<const VectorPostprocessor *>(obj) != nullptr); 490 321099 : _val |= (unsigned int)Interfaces::BlockRestrictable * (dynamic_cast<const BlockRestrictable *>(obj) != nullptr); 491 321099 : _val |= (unsigned int)Interfaces::BoundaryRestrictable * (dynamic_cast<const BoundaryRestrictable *>(obj) != nullptr); 492 321099 : _val |= (unsigned int)Interfaces::Reporter * (dynamic_cast<const Reporter *>(obj) != nullptr); 493 321099 : _val |= (unsigned int)Interfaces::DomainUserObject * (dynamic_cast<const DomainUserObject *>(obj) != nullptr); 494 321099 : _val |= (unsigned int)Interfaces::MortarUserObject * (dynamic_cast<const MortarUserObject *>(obj) != nullptr); 495 : // clang-format on 496 321099 : } 497 : 498 : bool 499 4776215 : AttribInterfaces::isMatch(const Attribute & other) const 500 : { 501 4776215 : auto a = dynamic_cast<const AttribInterfaces *>(&other); 502 4776215 : return a && (a->_val & _val); 503 : } 504 : 505 : bool 506 14732851 : AttribInterfaces::isEqual(const Attribute & other) const 507 : { 508 14732851 : auto a = dynamic_cast<const AttribInterfaces *>(&other); 509 14732851 : return a && (a->_val == _val); 510 : } 511 : 512 : void 513 321099 : AttribDisplaced::initFrom(const MooseObject * obj) 514 : { 515 606552 : _val = obj->parameters().have_parameter<bool>("use_displaced_mesh") && 516 892005 : obj->getParam<bool>("use_displaced_mesh"); 517 321099 : } 518 : 519 : bool 520 9214498 : AttribDisplaced::isMatch(const Attribute & other) const 521 : { 522 9214498 : auto a = dynamic_cast<const AttribDisplaced *>(&other); 523 9214498 : return a && (a->_val == _val); 524 : } 525 : 526 : bool 527 9154261 : AttribDisplaced::isEqual(const Attribute & other) const 528 : { 529 9154261 : return isMatch(other); 530 : }