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 59244 : AttribTagBase::isMatch(const Attribute & other) const 78 : { 79 59244 : auto a = dynamic_cast<const AttribTagBase *>(&other); 80 59244 : if (!a) 81 0 : return false; 82 59244 : 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 60368 : for (auto val : _vals) 87 59217 : if (std::find(a->_vals.begin(), a->_vals.end(), val) != a->_vals.end()) 88 58093 : return true; 89 1151 : return false; 90 : } 91 : 92 : bool 93 9214963 : AttribTagBase::isEqual(const Attribute & other) const 94 : { 95 9214963 : auto a = dynamic_cast<const AttribTagBase *>(&other); 96 9214963 : if (!a || a->_vals.size() != _vals.size()) 97 0 : return false; 98 : 99 31659097 : for (size_t i = 0; i < a->_vals.size(); i++) 100 22444134 : if (a->_vals[i] != _vals[i]) 101 0 : return false; 102 9214963 : return true; 103 : } 104 : 105 : void 106 316099 : AttribMatrixTags::initFrom(const MooseObject * obj) 107 : { 108 316099 : _vals.clear(); 109 316099 : auto t = dynamic_cast<const TaggingInterface *>(obj); 110 316099 : if (t) 111 : { 112 501612 : for (auto & tag : t->getMatrixTags({})) 113 299054 : _vals.push_back(static_cast<int>(tag)); 114 : } 115 316099 : } 116 : 117 : void 118 316099 : AttribVectorTags::initFrom(const MooseObject * obj) 119 : { 120 316099 : _vals.clear(); 121 316099 : auto t = dynamic_cast<const TaggingInterface *>(obj); 122 316099 : if (t) 123 : { 124 409033 : for (auto & tag : t->getVectorTags({})) 125 206475 : _vals.push_back(static_cast<int>(tag)); 126 : } 127 316099 : } 128 : 129 : void 130 316099 : AttribExecOns::initFrom(const MooseObject * obj) 131 : { 132 316099 : _vals.clear(); 133 316099 : if (const auto sup = dynamic_cast<const SetupInterface *>(obj)) 134 : { 135 284070 : const auto & current_items = sup->getExecuteOnEnum(); 136 284070 : _vals.reserve(current_items.size()); 137 380669 : for (auto & on : current_items) 138 96599 : _vals.push_back(on); 139 : } 140 316099 : } 141 : 142 : bool 143 3386815 : AttribExecOns::isMatch(const Attribute & other) const 144 : { 145 3386815 : auto a = dynamic_cast<const AttribExecOns *>(&other); 146 3386815 : if (!a || a->_vals.empty()) 147 0 : return false; 148 3386815 : auto cond = a->_vals[0]; 149 3386815 : if (cond == EXEC_ALL) 150 1464 : return true; 151 : 152 5585546 : for (const auto val : _vals) 153 4028470 : if (val == EXEC_ALL || val == cond) 154 1828275 : return true; 155 1557076 : return false; 156 : } 157 : 158 : bool 159 26186787 : AttribExecOns::isEqual(const Attribute & other) const 160 : { 161 26186787 : auto a = dynamic_cast<const AttribExecOns *>(&other); 162 26186787 : if (!a || a->_vals.size() != _vals.size()) 163 0 : return false; 164 : 165 52373574 : for (size_t i = 0; i < a->_vals.size(); i++) 166 26186787 : if (a->_vals[i] != _vals[i]) 167 0 : return false; 168 26186787 : return true; 169 : } 170 : 171 : void 172 316099 : AttribSubdomains::initFrom(const MooseObject * obj) 173 : { 174 316099 : _vals.clear(); 175 316099 : auto blk = dynamic_cast<const BlockRestrictable *>(obj); 176 316099 : if (blk && blk->blockRestricted()) 177 : { 178 38349 : for (auto id : blk->blockIDs()) 179 21107 : _vals.push_back(id); 180 : } 181 : else 182 298857 : _vals.push_back(Moose::ANY_BLOCK_ID); 183 316099 : } 184 : 185 : bool 186 1175176 : AttribSubdomains::isMatch(const Attribute & other) const 187 : { 188 1175176 : auto a = dynamic_cast<const AttribSubdomains *>(&other); 189 1175176 : if (!a || a->_vals.size() < 1) 190 0 : return false; 191 : 192 1175176 : auto cond = a->_vals[0]; 193 1175176 : if (cond == Moose::ANY_BLOCK_ID) 194 0 : return true; 195 1175176 : else if (cond == Moose::INVALID_BLOCK_ID) 196 9489 : return false; 197 : 198 1329206 : for (auto id : _vals) 199 : { 200 1217169 : if (id == cond || id == Moose::ANY_BLOCK_ID) 201 1053650 : return true; 202 : } 203 112037 : return false; 204 : } 205 : 206 : bool 207 7017329 : AttribSubdomains::isEqual(const Attribute & other) const 208 : { 209 7017329 : auto a = dynamic_cast<const AttribSubdomains *>(&other); 210 7017329 : if (!a || a->_vals.size() != _vals.size()) 211 0 : return false; 212 : 213 14034658 : for (size_t i = 0; i < a->_vals.size(); i++) 214 7017329 : if (a->_vals[i] != _vals[i]) 215 0 : return false; 216 7017329 : return true; 217 : } 218 : 219 : void 220 316099 : AttribBoundaries::initFrom(const MooseObject * obj) 221 : { 222 316099 : _vals.clear(); 223 316099 : auto bnd = dynamic_cast<const BoundaryRestrictable *>(obj); 224 316099 : if (bnd && bnd->boundaryRestricted()) 225 : { 226 230786 : for (auto & bound : bnd->boundaryIDs()) 227 130046 : _vals.push_back(bound); 228 : } 229 : else 230 215359 : _vals.push_back(Moose::ANY_BOUNDARY_ID); 231 316099 : } 232 : 233 : bool 234 809894 : AttribBoundaries::isMatch(const Attribute & other) const 235 : { 236 809894 : auto a = dynamic_cast<const AttribBoundaries *>(&other); 237 809894 : 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 1115551 : for (auto val : _vals) 242 : { 243 906735 : if (!a->_must_be_restricted && (val == Moose::ANY_BOUNDARY_ID)) 244 601078 : return true; 245 407480 : if (std::find(a->_vals.begin(), a->_vals.end(), val) != a->_vals.end()) 246 96303 : return true; 247 311177 : else if (std::find(a->_vals.begin(), a->_vals.end(), Moose::ANY_BOUNDARY_ID) != a->_vals.end()) 248 5520 : return true; 249 : } 250 208816 : return false; 251 : } 252 : 253 : bool 254 10901352 : AttribBoundaries::isEqual(const Attribute & other) const 255 : { 256 10901352 : auto a = dynamic_cast<const AttribBoundaries *>(&other); 257 10901352 : if (!a || a->_vals.size() != _vals.size()) 258 0 : return false; 259 : 260 21802704 : for (size_t i = 0; i < a->_vals.size(); i++) 261 10901352 : if (a->_vals[i] != _vals[i]) 262 0 : return false; 263 10901352 : return true; 264 : } 265 : 266 : void 267 316099 : AttribThread::initFrom(const MooseObject * obj) 268 : { 269 632198 : _val = obj->getParam<THREAD_ID>("_tid"); 270 316099 : } 271 : bool 272 27848486 : AttribThread::isMatch(const Attribute & other) const 273 : { 274 27848486 : auto a = dynamic_cast<const AttribThread *>(&other); 275 27848486 : return a && (a->_val == _val); 276 : } 277 : bool 278 24234321 : AttribThread::isEqual(const Attribute & other) const 279 : { 280 24234321 : return isMatch(other); 281 : } 282 : 283 : void 284 316099 : AttribExecutionOrderGroup::initFrom(const MooseObject * obj) 285 : { 286 316099 : const auto * uo = dynamic_cast<const UserObject *>(obj); 287 397231 : _val = uo ? uo->getParam<int>("execution_order_group") : 0; 288 316099 : } 289 : bool 290 10703226 : AttribExecutionOrderGroup::isMatch(const Attribute & other) const 291 : { 292 10703226 : auto a = dynamic_cast<const AttribExecutionOrderGroup *>(&other); 293 10703226 : return a && (a->_val == _val); 294 : } 295 : bool 296 9141023 : AttribExecutionOrderGroup::isEqual(const Attribute & other) const 297 : { 298 9141023 : return isMatch(other); 299 : } 300 : 301 : void 302 316099 : AttribSysNum::initFrom(const MooseObject * obj) 303 : { 304 632198 : auto * sys = obj->getParam<SystemBase *>("_sys"); 305 : 306 316099 : if (sys) 307 315614 : _val = sys->number(); 308 316099 : } 309 : 310 : bool 311 10666990 : AttribSysNum::isMatch(const Attribute & other) const 312 : { 313 10666990 : auto a = dynamic_cast<const AttribSysNum *>(&other); 314 10666990 : return a && (a->_val == _val); 315 : } 316 : 317 : bool 318 9807783 : AttribSysNum::isEqual(const Attribute & other) const 319 : { 320 9807783 : return isMatch(other); 321 : } 322 : 323 : void 324 316099 : AttribPreIC::initFrom(const MooseObject * /*obj*/) 325 : { 326 316099 : } 327 : bool 328 16095 : AttribPreIC::isMatch(const Attribute & other) const 329 : { 330 16095 : auto a = dynamic_cast<const AttribPreIC *>(&other); 331 16095 : 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 195307 : AttribPreAux::isMatch(const Attribute & other) const 342 : { 343 195307 : const auto a = dynamic_cast<const AttribPreAux *>(&other); 344 : 345 195307 : bool is_match = false; 346 : 347 195307 : if (a && !_vals.empty() && !a->_vals.empty()) 348 : { 349 62485 : 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 195307 : return is_match; 354 : } 355 : 356 : bool 357 5798892 : AttribPreAux::isEqual(const Attribute & other) const 358 : { 359 5798892 : const auto a = dynamic_cast<const AttribPreAux *>(&other); 360 5798892 : return a && a->_vals == _vals; 361 : } 362 : 363 : void 364 316099 : AttribPreAux::initFrom(const MooseObject * /*obj*/) 365 : { 366 316099 : } 367 : 368 : bool 369 1611932 : AttribPostAux::isMatch(const Attribute & other) const 370 : { 371 1611932 : const auto a = dynamic_cast<const AttribPostAux *>(&other); 372 : 373 1611932 : bool is_match = false; 374 : 375 1611932 : if (a && !_vals.empty() && !a->_vals.empty()) 376 : { 377 1619806 : is_match = std::includes(_vals.begin(), _vals.end(), a->_vals.begin(), a->_vals.end()) || 378 13369 : std::includes(a->_vals.begin(), a->_vals.end(), _vals.begin(), _vals.end()); 379 : } 380 : 381 1611932 : return is_match; 382 : } 383 : 384 : bool 385 14574155 : AttribPostAux::isEqual(const Attribute & other) const 386 : { 387 14574155 : const auto a = dynamic_cast<const AttribPostAux *>(&other); 388 14574155 : return a && a->_vals == _vals; 389 : } 390 : 391 : void 392 316099 : AttribPostAux::initFrom(const MooseObject * /*obj*/) 393 : { 394 316099 : } 395 : 396 : void 397 316099 : AttribName::initFrom(const MooseObject * obj) 398 : { 399 316099 : _val = obj->name(); 400 316099 : } 401 : bool 402 1517367 : AttribName::isMatch(const Attribute & other) const 403 : { 404 1517367 : auto a = dynamic_cast<const AttribName *>(&other); 405 1517367 : return a && (a->_val == _val); 406 : } 407 : 408 : bool 409 1285533 : AttribName::isEqual(const Attribute & other) const 410 : { 411 1285533 : return isMatch(other); 412 : } 413 : 414 : void 415 316099 : AttribSystem::initFrom(const MooseObject * obj) 416 : { 417 316099 : _val = obj->parameters().getSystemAttributeName(); 418 316099 : } 419 : 420 : bool 421 62535960 : AttribSystem::isMatch(const Attribute & other) const 422 : { 423 62535960 : auto a = dynamic_cast<const AttribSystem *>(&other); 424 62535960 : return a && (a->_val == _val); 425 : } 426 : 427 : bool 428 44478290 : AttribSystem::isEqual(const Attribute & other) const 429 : { 430 44478290 : return isMatch(other); 431 : } 432 : 433 : void 434 316099 : AttribResidualObject::initFrom(const MooseObject * obj) 435 : { 436 632198 : _val = obj->getParam<bool>("_residual_object"); 437 316099 : _initd = true; 438 316099 : } 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 316099 : AttribVar::initFrom(const MooseObject * obj) 455 : { 456 316099 : auto vi = dynamic_cast<const MooseVariableInterface<Real> *>(obj); 457 316099 : if (vi) 458 226601 : _val = static_cast<int>(vi->mooseVariableBase()->number()); 459 316099 : } 460 : bool 461 224083 : AttribVar::isMatch(const Attribute & other) const 462 : { 463 224083 : auto a = dynamic_cast<const AttribVar *>(&other); 464 224083 : return a && (_val != -1) && (a->_val == _val); 465 : } 466 : 467 : bool 468 152472 : AttribVar::isEqual(const Attribute & other) const 469 : { 470 152472 : return isMatch(other); 471 : } 472 : 473 : void 474 316099 : AttribInterfaces::initFrom(const MooseObject * obj) 475 : { 476 316099 : _val = 0; 477 : // clang-format off 478 316099 : _val |= (unsigned int)Interfaces::UserObject * (dynamic_cast<const UserObject *>(obj) != nullptr); 479 316099 : _val |= (unsigned int)Interfaces::ElementUserObject * (dynamic_cast<const ElementUserObject *>(obj) != nullptr); 480 316099 : _val |= (unsigned int)Interfaces::SideUserObject * (dynamic_cast<const SideUserObject *>(obj) != nullptr); 481 316099 : _val |= (unsigned int)Interfaces::InternalSideUserObject * (dynamic_cast<const InternalSideUserObject *>(obj) != nullptr); 482 316099 : _val |= (unsigned int)Interfaces::InterfaceUserObject * (dynamic_cast<const InterfaceUserObject *>(obj) != nullptr); 483 316099 : _val |= (unsigned int)Interfaces::NodalUserObject * (dynamic_cast<const NodalUserObject *>(obj) != nullptr); 484 316099 : _val |= (unsigned int)Interfaces::GeneralUserObject * (dynamic_cast<const GeneralUserObject *>(obj) != nullptr); 485 316099 : _val |= (unsigned int)Interfaces::ThreadedGeneralUserObject * (dynamic_cast<const ThreadedGeneralUserObject *>(obj) != nullptr); 486 316099 : _val |= (unsigned int)Interfaces::ShapeElementUserObject * (dynamic_cast<const ShapeElementUserObject *>(obj) != nullptr); 487 316099 : _val |= (unsigned int)Interfaces::ShapeSideUserObject * (dynamic_cast<const ShapeSideUserObject *>(obj) != nullptr); 488 316099 : _val |= (unsigned int)Interfaces::Postprocessor * (dynamic_cast<const Postprocessor *>(obj) != nullptr); 489 316099 : _val |= (unsigned int)Interfaces::VectorPostprocessor * (dynamic_cast<const VectorPostprocessor *>(obj) != nullptr); 490 316099 : _val |= (unsigned int)Interfaces::BlockRestrictable * (dynamic_cast<const BlockRestrictable *>(obj) != nullptr); 491 316099 : _val |= (unsigned int)Interfaces::BoundaryRestrictable * (dynamic_cast<const BoundaryRestrictable *>(obj) != nullptr); 492 316099 : _val |= (unsigned int)Interfaces::Reporter * (dynamic_cast<const Reporter *>(obj) != nullptr); 493 316099 : _val |= (unsigned int)Interfaces::DomainUserObject * (dynamic_cast<const DomainUserObject *>(obj) != nullptr); 494 316099 : _val |= (unsigned int)Interfaces::MortarUserObject * (dynamic_cast<const MortarUserObject *>(obj) != nullptr); 495 : // clang-format on 496 316099 : } 497 : 498 : bool 499 4688400 : AttribInterfaces::isMatch(const Attribute & other) const 500 : { 501 4688400 : auto a = dynamic_cast<const AttribInterfaces *>(&other); 502 4688400 : return a && (a->_val & _val); 503 : } 504 : 505 : bool 506 14337874 : AttribInterfaces::isEqual(const Attribute & other) const 507 : { 508 14337874 : auto a = dynamic_cast<const AttribInterfaces *>(&other); 509 14337874 : return a && (a->_val == _val); 510 : } 511 : 512 : void 513 316099 : AttribDisplaced::initFrom(const MooseObject * obj) 514 : { 515 597407 : _val = obj->parameters().have_parameter<bool>("use_displaced_mesh") && 516 878715 : obj->getParam<bool>("use_displaced_mesh"); 517 316099 : } 518 : 519 : bool 520 9200859 : AttribDisplaced::isMatch(const Attribute & other) const 521 : { 522 9200859 : auto a = dynamic_cast<const AttribDisplaced *>(&other); 523 9200859 : return a && (a->_val == _val); 524 : } 525 : 526 : bool 527 9140865 : AttribDisplaced::isEqual(const Attribute & other) const 528 : { 529 9140865 : return isMatch(other); 530 : }