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 41069 : AttribTagBase::isMatch(const Attribute & other) const 81 : { 82 41069 : auto a = dynamic_cast<const AttribTagBase *>(&other); 83 41069 : if (!a) 84 0 : return false; 85 41069 : 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 42099 : for (auto val : _vals) 90 41045 : if (std::find(a->_vals.begin(), a->_vals.end(), val) != a->_vals.end()) 91 40015 : return true; 92 1054 : return false; 93 : } 94 : 95 : bool 96 7213952 : AttribTagBase::isEqual(const Attribute & other) const 97 : { 98 7213952 : auto a = dynamic_cast<const AttribTagBase *>(&other); 99 7213952 : if (!a || a->_vals.size() != _vals.size()) 100 0 : return false; 101 : 102 24288422 : for (size_t i = 0; i < a->_vals.size(); i++) 103 17074470 : if (a->_vals[i] != _vals[i]) 104 0 : return false; 105 7213952 : return true; 106 : } 107 : 108 : void 109 310060 : AttribMatrixTags::initFrom(const MooseObject * obj) 110 : { 111 310060 : _vals.clear(); 112 310060 : auto t = dynamic_cast<const TaggingInterface *>(obj); 113 310060 : if (t) 114 : { 115 457950 : for (auto & tag : t->getMatrixTags({})) 116 273578 : _vals.push_back(static_cast<int>(tag)); 117 : } 118 310060 : } 119 : 120 : void 121 310060 : AttribVectorTags::initFrom(const MooseObject * obj) 122 : { 123 310060 : _vals.clear(); 124 310060 : auto t = dynamic_cast<const TaggingInterface *>(obj); 125 310060 : if (t) 126 : { 127 372489 : for (auto & tag : t->getVectorTags({})) 128 188117 : _vals.push_back(static_cast<int>(tag)); 129 : } 130 310060 : } 131 : 132 : void 133 310060 : AttribExecOns::initFrom(const MooseObject * obj) 134 : { 135 310060 : _vals.clear(); 136 310060 : if (const auto sup = dynamic_cast<const SetupInterface *>(obj)) 137 : { 138 263488 : const auto & current_items = sup->getExecuteOnEnum(); 139 263488 : _vals.reserve(current_items.size()); 140 356535 : for (auto & on : current_items) 141 93047 : _vals.push_back(on); 142 : } 143 310060 : } 144 : 145 : bool 146 3140693 : AttribExecOns::isMatch(const Attribute & other) const 147 : { 148 3140693 : auto a = dynamic_cast<const AttribExecOns *>(&other); 149 3140693 : if (!a || a->_vals.empty()) 150 0 : return false; 151 3140693 : auto cond = a->_vals[0]; 152 3140693 : if (cond == EXEC_ALL) 153 1092 : return true; 154 : 155 5191129 : for (const auto val : _vals) 156 3730531 : if (val == EXEC_ALL || val == cond) 157 1679003 : return true; 158 1460598 : return false; 159 : } 160 : 161 : bool 162 32341293 : AttribExecOns::isEqual(const Attribute & other) const 163 : { 164 32341293 : auto a = dynamic_cast<const AttribExecOns *>(&other); 165 32341293 : if (!a || a->_vals.size() != _vals.size()) 166 0 : return false; 167 : 168 64682586 : for (size_t i = 0; i < a->_vals.size(); i++) 169 32341293 : if (a->_vals[i] != _vals[i]) 170 0 : return false; 171 32341293 : return true; 172 : } 173 : 174 : void 175 310060 : AttribSubdomains::initFrom(const MooseObject * obj) 176 : { 177 310060 : _vals.clear(); 178 310060 : auto blk = dynamic_cast<const BlockRestrictable *>(obj); 179 310060 : if (blk && blk->blockRestricted()) 180 : { 181 36033 : for (auto id : blk->blockIDs()) 182 19982 : _vals.push_back(id); 183 : } 184 : else 185 294009 : _vals.push_back(Moose::ANY_BLOCK_ID); 186 310060 : } 187 : 188 : bool 189 1027255 : AttribSubdomains::isMatch(const Attribute & other) const 190 : { 191 1027255 : auto a = dynamic_cast<const AttribSubdomains *>(&other); 192 1027255 : if (!a || a->_vals.size() < 1) 193 0 : return false; 194 : 195 1027255 : auto cond = a->_vals[0]; 196 1027255 : if (cond == Moose::ANY_BLOCK_ID) 197 0 : return true; 198 1027255 : else if (cond == Moose::INVALID_BLOCK_ID) 199 6546 : return false; 200 : 201 1163697 : for (auto id : _vals) 202 : { 203 1067731 : if (id == cond || id == Moose::ANY_BLOCK_ID) 204 924743 : return true; 205 : } 206 95966 : return false; 207 : } 208 : 209 : bool 210 5968302 : AttribSubdomains::isEqual(const Attribute & other) const 211 : { 212 5968302 : auto a = dynamic_cast<const AttribSubdomains *>(&other); 213 5968302 : if (!a || a->_vals.size() != _vals.size()) 214 0 : return false; 215 : 216 11936604 : for (size_t i = 0; i < a->_vals.size(); i++) 217 5968302 : if (a->_vals[i] != _vals[i]) 218 0 : return false; 219 5968302 : return true; 220 : } 221 : 222 : void 223 310060 : AttribBoundaries::initFrom(const MooseObject * obj) 224 : { 225 310060 : _vals.clear(); 226 310060 : auto bnd = dynamic_cast<const BoundaryRestrictable *>(obj); 227 310060 : if (bnd && bnd->boundaryRestricted()) 228 : { 229 210221 : for (auto & bound : bnd->boundaryIDs()) 230 118399 : _vals.push_back(bound); 231 : } 232 : else 233 218238 : _vals.push_back(Moose::ANY_BOUNDARY_ID); 234 310060 : } 235 : 236 : bool 237 715379 : AttribBoundaries::isMatch(const Attribute & other) const 238 : { 239 715379 : auto a = dynamic_cast<const AttribBoundaries *>(&other); 240 715379 : 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 982596 : for (auto val : _vals) 245 : { 246 796790 : if (!a->_must_be_restricted && (val == Moose::ANY_BOUNDARY_ID)) 247 529573 : return true; 248 352919 : if (std::find(a->_vals.begin(), a->_vals.end(), val) != a->_vals.end()) 249 80824 : return true; 250 272095 : else if (std::find(a->_vals.begin(), a->_vals.end(), Moose::ANY_BOUNDARY_ID) != a->_vals.end()) 251 4878 : return true; 252 : } 253 185806 : return false; 254 : } 255 : 256 : bool 257 10144946 : AttribBoundaries::isEqual(const Attribute & other) const 258 : { 259 10144946 : auto a = dynamic_cast<const AttribBoundaries *>(&other); 260 10144946 : if (!a || a->_vals.size() != _vals.size()) 261 0 : return false; 262 : 263 20289892 : for (size_t i = 0; i < a->_vals.size(); i++) 264 10144946 : if (a->_vals[i] != _vals[i]) 265 0 : return false; 266 10144946 : return true; 267 : } 268 : 269 : void 270 310060 : AttribThread::initFrom(const MooseObject * obj) 271 : { 272 620120 : _val = obj->getParam<THREAD_ID>("_tid"); 273 310060 : } 274 : bool 275 24890036 : AttribThread::isMatch(const Attribute & other) const 276 : { 277 24890036 : auto a = dynamic_cast<const AttribThread *>(&other); 278 24890036 : return a && (a->_val == _val); 279 : } 280 : bool 281 21747106 : AttribThread::isEqual(const Attribute & other) const 282 : { 283 21747106 : return isMatch(other); 284 : } 285 : 286 : void 287 310060 : AttribExecutionOrderGroup::initFrom(const MooseObject * obj) 288 : { 289 310060 : const auto * uo = dynamic_cast<const UserObjectBase *>(obj); 290 385437 : _val = uo ? uo->getParam<int>("execution_order_group") : 0; 291 310060 : } 292 : bool 293 10205710 : AttribExecutionOrderGroup::isMatch(const Attribute & other) const 294 : { 295 10205710 : auto a = dynamic_cast<const AttribExecutionOrderGroup *>(&other); 296 10205710 : return a && (a->_val == _val); 297 : } 298 : bool 299 8776450 : AttribExecutionOrderGroup::isEqual(const Attribute & other) const 300 : { 301 8776450 : return isMatch(other); 302 : } 303 : 304 : void 305 310060 : AttribSysNum::initFrom(const MooseObject * obj) 306 : { 307 620120 : auto * sys = obj->getParam<SystemBase *>("_sys"); 308 : 309 310060 : if (sys) 310 309631 : _val = sys->number(); 311 310060 : } 312 : 313 : bool 314 8272026 : AttribSysNum::isMatch(const Attribute & other) const 315 : { 316 8272026 : auto a = dynamic_cast<const AttribSysNum *>(&other); 317 8272026 : return a && (a->_val == _val); 318 : } 319 : 320 : bool 321 7576675 : AttribSysNum::isEqual(const Attribute & other) const 322 : { 323 7576675 : return isMatch(other); 324 : } 325 : 326 : void 327 310060 : AttribPreIC::initFrom(const MooseObject * /*obj*/) 328 : { 329 310060 : } 330 : bool 331 15331 : AttribPreIC::isMatch(const Attribute & other) const 332 : { 333 15331 : auto a = dynamic_cast<const AttribPreIC *>(&other); 334 15331 : 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 178997 : AttribPreAux::isMatch(const Attribute & other) const 345 : { 346 178997 : const auto a = dynamic_cast<const AttribPreAux *>(&other); 347 : 348 178997 : bool is_match = false; 349 : 350 178997 : if (a && !_vals.empty() && !a->_vals.empty()) 351 : { 352 57422 : is_match = std::includes(_vals.begin(), _vals.end(), a->_vals.begin(), a->_vals.end()) || 353 3954 : std::includes(a->_vals.begin(), a->_vals.end(), _vals.begin(), _vals.end()); 354 : } 355 : 356 178997 : return is_match; 357 : } 358 : 359 : bool 360 9240602 : AttribPreAux::isEqual(const Attribute & other) const 361 : { 362 9240602 : const auto a = dynamic_cast<const AttribPreAux *>(&other); 363 9240602 : return a && a->_vals == _vals; 364 : } 365 : 366 : void 367 310060 : AttribPreAux::initFrom(const MooseObject * /*obj*/) 368 : { 369 310060 : } 370 : 371 : bool 372 1482371 : AttribPostAux::isMatch(const Attribute & other) const 373 : { 374 1482371 : const auto a = dynamic_cast<const AttribPostAux *>(&other); 375 : 376 1482371 : bool is_match = false; 377 : 378 1482371 : if (a && !_vals.empty() && !a->_vals.empty()) 379 : { 380 1489429 : is_match = std::includes(_vals.begin(), _vals.end(), a->_vals.begin(), a->_vals.end()) || 381 11912 : std::includes(a->_vals.begin(), a->_vals.end(), _vals.begin(), _vals.end()); 382 : } 383 : 384 1482371 : return is_match; 385 : } 386 : 387 : bool 388 17666347 : AttribPostAux::isEqual(const Attribute & other) const 389 : { 390 17666347 : const auto a = dynamic_cast<const AttribPostAux *>(&other); 391 17666347 : return a && a->_vals == _vals; 392 : } 393 : 394 : void 395 310060 : AttribPostAux::initFrom(const MooseObject * /*obj*/) 396 : { 397 310060 : } 398 : 399 : void 400 310060 : AttribName::initFrom(const MooseObject * obj) 401 : { 402 310060 : _val = obj->name(); 403 310060 : } 404 : bool 405 1492485 : AttribName::isMatch(const Attribute & other) const 406 : { 407 1492485 : auto a = dynamic_cast<const AttribName *>(&other); 408 1492485 : return a && (a->_val == _val); 409 : } 410 : 411 : bool 412 1264473 : AttribName::isEqual(const Attribute & other) const 413 : { 414 1264473 : return isMatch(other); 415 : } 416 : 417 : void 418 310060 : AttribSystem::initFrom(const MooseObject * obj) 419 : { 420 310060 : _val = obj->parameters().getSystemAttributeName(); 421 310060 : } 422 : 423 : bool 424 71460082 : AttribSystem::isMatch(const Attribute & other) const 425 : { 426 71460082 : auto a = dynamic_cast<const AttribSystem *>(&other); 427 71460082 : return a && (a->_val == _val); 428 : } 429 : 430 : bool 431 49355520 : AttribSystem::isEqual(const Attribute & other) const 432 : { 433 49355520 : return isMatch(other); 434 : } 435 : 436 : void 437 310060 : AttribKokkos::initFrom(const MooseObject * obj) 438 : { 439 : #ifdef MOOSE_KOKKOS_ENABLED 440 236679 : _val = obj->isKokkosObject(); 441 : #else 442 : static_cast<void>(obj); 443 73381 : _val = false; 444 : #endif 445 310060 : } 446 : 447 : bool 448 277211 : AttribKokkos::isMatch(const Attribute & other) const 449 : { 450 277211 : auto a = dynamic_cast<const AttribKokkos *>(&other); 451 277211 : return a && (a->_val == _val); 452 : } 453 : 454 : bool 455 256938 : AttribKokkos::isEqual(const Attribute & other) const 456 : { 457 256938 : return isMatch(other); 458 : } 459 : 460 : void 461 310060 : AttribResidualObject::initFrom(const MooseObject * obj) 462 : { 463 620120 : _val = obj->getParam<bool>("_residual_object"); 464 310060 : _initd = true; 465 310060 : } 466 : 467 : bool 468 0 : AttribResidualObject::isMatch(const Attribute & other) const 469 : { 470 0 : auto a = dynamic_cast<const AttribResidualObject *>(&other); 471 0 : return _initd && a && a->_initd && (a->_val == _val); 472 : } 473 : 474 : bool 475 0 : AttribResidualObject::isEqual(const Attribute & other) const 476 : { 477 0 : return isMatch(other); 478 : } 479 : 480 : void 481 310060 : AttribVar::initFrom(const MooseObject * obj) 482 : { 483 310060 : auto vi = dynamic_cast<const MooseVariableInterface<Real> *>(obj); 484 310060 : if (vi) 485 208051 : _val = static_cast<int>(vi->mooseVariableBase()->number()); 486 310060 : } 487 : bool 488 189181 : AttribVar::isMatch(const Attribute & other) const 489 : { 490 189181 : auto a = dynamic_cast<const AttribVar *>(&other); 491 189181 : return a && (_val != -1) && (a->_val == _val); 492 : } 493 : 494 : bool 495 128366 : AttribVar::isEqual(const Attribute & other) const 496 : { 497 128366 : return isMatch(other); 498 : } 499 : 500 : void 501 310060 : AttribInterfaces::initFrom(const MooseObject * obj) 502 : { 503 310060 : _val = 0; 504 : // clang-format off 505 310060 : _val |= (unsigned int)Interfaces::UserObject * (dynamic_cast<const UserObjectBase *>(obj) != nullptr); 506 310060 : _val |= (unsigned int)Interfaces::ElementUserObject * (dynamic_cast<const ElementUserObject *>(obj) != nullptr); 507 310060 : _val |= (unsigned int)Interfaces::SideUserObject * (dynamic_cast<const SideUserObject *>(obj) != nullptr); 508 310060 : _val |= (unsigned int)Interfaces::InternalSideUserObject * (dynamic_cast<const InternalSideUserObject *>(obj) != nullptr); 509 310060 : _val |= (unsigned int)Interfaces::InterfaceUserObject * (dynamic_cast<const InterfaceUserObject *>(obj) != nullptr); 510 310060 : _val |= (unsigned int)Interfaces::NodalUserObject * (dynamic_cast<const NodalUserObject *>(obj) != nullptr); 511 310060 : _val |= (unsigned int)Interfaces::GeneralUserObject * (dynamic_cast<const GeneralUserObject *>(obj) != nullptr); 512 310060 : _val |= (unsigned int)Interfaces::ThreadedGeneralUserObject * (dynamic_cast<const ThreadedGeneralUserObject *>(obj) != nullptr); 513 310060 : _val |= (unsigned int)Interfaces::ShapeElementUserObject * (dynamic_cast<const ShapeElementUserObject *>(obj) != nullptr); 514 310060 : _val |= (unsigned int)Interfaces::ShapeSideUserObject * (dynamic_cast<const ShapeSideUserObject *>(obj) != nullptr); 515 310060 : _val |= (unsigned int)Interfaces::Postprocessor * (dynamic_cast<const Postprocessor *>(obj) != nullptr); 516 310060 : _val |= (unsigned int)Interfaces::VectorPostprocessor * (dynamic_cast<const VectorPostprocessor *>(obj) != nullptr); 517 310060 : _val |= (unsigned int)Interfaces::BlockRestrictable * (dynamic_cast<const BlockRestrictable *>(obj) != nullptr); 518 310060 : _val |= (unsigned int)Interfaces::BoundaryRestrictable * (dynamic_cast<const BoundaryRestrictable *>(obj) != nullptr); 519 310060 : _val |= (unsigned int)Interfaces::Reporter * (dynamic_cast<const Reporter *>(obj) != nullptr); 520 310060 : _val |= (unsigned int)Interfaces::DomainUserObject * (dynamic_cast<const DomainUserObject *>(obj) != nullptr); 521 310060 : _val |= (unsigned int)Interfaces::MortarUserObject * (dynamic_cast<const MortarUserObject *>(obj) != nullptr); 522 310060 : _val |= (unsigned int)Interfaces::FVInterpolationMethod * (dynamic_cast<const FVInterpolationMethod *>(obj) != nullptr); 523 : // clang-format on 524 310060 : } 525 : 526 : bool 527 5296646 : AttribInterfaces::isMatch(const Attribute & other) const 528 : { 529 5296646 : auto a = dynamic_cast<const AttribInterfaces *>(&other); 530 5296646 : return a && (a->_val & _val); 531 : } 532 : 533 : bool 534 14924384 : AttribInterfaces::isEqual(const Attribute & other) const 535 : { 536 14924384 : auto a = dynamic_cast<const AttribInterfaces *>(&other); 537 14924384 : return a && (a->_val == _val); 538 : } 539 : 540 : void 541 310060 : AttribDisplaced::initFrom(const MooseObject * obj) 542 : { 543 567330 : _val = obj->parameters().have_parameter<bool>("use_displaced_mesh") && 544 824600 : obj->getParam<bool>("use_displaced_mesh"); 545 310060 : } 546 : 547 : bool 548 6987610 : AttribDisplaced::isMatch(const Attribute & other) const 549 : { 550 6987610 : auto a = dynamic_cast<const AttribDisplaced *>(&other); 551 6987610 : return a && (a->_val == _val); 552 : } 553 : 554 : bool 555 6946700 : AttribDisplaced::isEqual(const Attribute & other) const 556 : { 557 6946700 : return isMatch(other); 558 : }