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 58753 : AttribTagBase::isMatch(const Attribute & other) const 78 : { 79 58753 : auto a = dynamic_cast<const AttribTagBase *>(&other); 80 58753 : if (!a) 81 0 : return false; 82 58753 : 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 59877 : for (auto val : _vals) 87 58726 : if (std::find(a->_vals.begin(), a->_vals.end(), val) != a->_vals.end()) 88 57602 : return true; 89 1151 : return false; 90 : } 91 : 92 : bool 93 9183521 : AttribTagBase::isEqual(const Attribute & other) const 94 : { 95 9183521 : auto a = dynamic_cast<const AttribTagBase *>(&other); 96 9183521 : if (!a || a->_vals.size() != _vals.size()) 97 0 : return false; 98 : 99 31568299 : for (size_t i = 0; i < a->_vals.size(); i++) 100 22384778 : if (a->_vals[i] != _vals[i]) 101 0 : return false; 102 9183521 : return true; 103 : } 104 : 105 : void 106 310938 : AttribMatrixTags::initFrom(const MooseObject * obj) 107 : { 108 310938 : _vals.clear(); 109 310938 : auto t = dynamic_cast<const TaggingInterface *>(obj); 110 310938 : if (t) 111 : { 112 495964 : for (auto & tag : t->getMatrixTags({})) 113 295732 : _vals.push_back(static_cast<int>(tag)); 114 : } 115 310938 : } 116 : 117 : void 118 310938 : AttribVectorTags::initFrom(const MooseObject * obj) 119 : { 120 310938 : _vals.clear(); 121 310938 : auto t = dynamic_cast<const TaggingInterface *>(obj); 122 310938 : if (t) 123 : { 124 404381 : for (auto & tag : t->getVectorTags({})) 125 204149 : _vals.push_back(static_cast<int>(tag)); 126 : } 127 310938 : } 128 : 129 : void 130 310938 : AttribExecOns::initFrom(const MooseObject * obj) 131 : { 132 310938 : _vals.clear(); 133 310938 : if (const auto sup = dynamic_cast<const SetupInterface *>(obj)) 134 : { 135 279687 : const auto & current_items = sup->getExecuteOnEnum(); 136 279687 : _vals.reserve(current_items.size()); 137 373220 : for (auto & on : current_items) 138 93533 : _vals.push_back(on); 139 : } 140 310938 : } 141 : 142 : bool 143 3273828 : AttribExecOns::isMatch(const Attribute & other) const 144 : { 145 3273828 : auto a = dynamic_cast<const AttribExecOns *>(&other); 146 3273828 : if (!a || a->_vals.empty()) 147 0 : return false; 148 3273828 : auto cond = a->_vals[0]; 149 3273828 : if (cond == EXEC_ALL) 150 1464 : return true; 151 : 152 5373193 : for (const auto val : _vals) 153 3866004 : if (val == EXEC_ALL || val == cond) 154 1765175 : return true; 155 1507189 : return false; 156 : } 157 : 158 : bool 159 26048459 : AttribExecOns::isEqual(const Attribute & other) const 160 : { 161 26048459 : auto a = dynamic_cast<const AttribExecOns *>(&other); 162 26048459 : if (!a || a->_vals.size() != _vals.size()) 163 0 : return false; 164 : 165 52096918 : for (size_t i = 0; i < a->_vals.size(); i++) 166 26048459 : if (a->_vals[i] != _vals[i]) 167 0 : return false; 168 26048459 : return true; 169 : } 170 : 171 : void 172 310938 : AttribSubdomains::initFrom(const MooseObject * obj) 173 : { 174 310938 : _vals.clear(); 175 310938 : auto blk = dynamic_cast<const BlockRestrictable *>(obj); 176 310938 : if (blk && blk->blockRestricted()) 177 : { 178 35031 : for (auto id : blk->blockIDs()) 179 19215 : _vals.push_back(id); 180 : } 181 : else 182 295122 : _vals.push_back(Moose::ANY_BLOCK_ID); 183 310938 : } 184 : 185 : bool 186 1098986 : AttribSubdomains::isMatch(const Attribute & other) const 187 : { 188 1098986 : auto a = dynamic_cast<const AttribSubdomains *>(&other); 189 1098986 : if (!a || a->_vals.size() < 1) 190 0 : return false; 191 : 192 1098986 : auto cond = a->_vals[0]; 193 1098986 : if (cond == Moose::ANY_BLOCK_ID) 194 0 : return true; 195 1098986 : else if (cond == Moose::INVALID_BLOCK_ID) 196 9423 : return false; 197 : 198 1210622 : for (auto id : _vals) 199 : { 200 1124415 : if (id == cond || id == Moose::ANY_BLOCK_ID) 201 1003356 : return true; 202 : } 203 86207 : return false; 204 : } 205 : 206 : bool 207 6992524 : AttribSubdomains::isEqual(const Attribute & other) const 208 : { 209 6992524 : auto a = dynamic_cast<const AttribSubdomains *>(&other); 210 6992524 : if (!a || a->_vals.size() != _vals.size()) 211 0 : return false; 212 : 213 13985048 : for (size_t i = 0; i < a->_vals.size(); i++) 214 6992524 : if (a->_vals[i] != _vals[i]) 215 0 : return false; 216 6992524 : return true; 217 : } 218 : 219 : void 220 310938 : AttribBoundaries::initFrom(const MooseObject * obj) 221 : { 222 310938 : _vals.clear(); 223 310938 : auto bnd = dynamic_cast<const BoundaryRestrictable *>(obj); 224 310938 : if (bnd && bnd->boundaryRestricted()) 225 : { 226 228109 : for (auto & bound : bnd->boundaryIDs()) 227 128594 : _vals.push_back(bound); 228 : } 229 : else 230 211423 : _vals.push_back(Moose::ANY_BOUNDARY_ID); 231 310938 : } 232 : 233 : bool 234 784245 : AttribBoundaries::isMatch(const Attribute & other) const 235 : { 236 784245 : auto a = dynamic_cast<const AttribBoundaries *>(&other); 237 784245 : 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 1082866 : for (auto val : _vals) 242 : { 243 880743 : if (!a->_must_be_restricted && (val == Moose::ANY_BOUNDARY_ID)) 244 582122 : return true; 245 398532 : if (std::find(a->_vals.begin(), a->_vals.end(), val) != a->_vals.end()) 246 94391 : return true; 247 304141 : else if (std::find(a->_vals.begin(), a->_vals.end(), Moose::ANY_BOUNDARY_ID) != a->_vals.end()) 248 5520 : return true; 249 : } 250 202123 : return false; 251 : } 252 : 253 : bool 254 10835863 : AttribBoundaries::isEqual(const Attribute & other) const 255 : { 256 10835863 : auto a = dynamic_cast<const AttribBoundaries *>(&other); 257 10835863 : if (!a || a->_vals.size() != _vals.size()) 258 0 : return false; 259 : 260 21671726 : for (size_t i = 0; i < a->_vals.size(); i++) 261 10835863 : if (a->_vals[i] != _vals[i]) 262 0 : return false; 263 10835863 : return true; 264 : } 265 : 266 : void 267 310938 : AttribThread::initFrom(const MooseObject * obj) 268 : { 269 310938 : _val = obj->getParam<THREAD_ID>("_tid"); 270 310938 : } 271 : bool 272 27524917 : AttribThread::isMatch(const Attribute & other) const 273 : { 274 27524917 : auto a = dynamic_cast<const AttribThread *>(&other); 275 27524917 : return a && (a->_val == _val); 276 : } 277 : bool 278 24073867 : AttribThread::isEqual(const Attribute & other) const 279 : { 280 24073867 : return isMatch(other); 281 : } 282 : 283 : void 284 310938 : AttribExecutionOrderGroup::initFrom(const MooseObject * obj) 285 : { 286 310938 : const auto * uo = dynamic_cast<const UserObject *>(obj); 287 310938 : _val = uo ? uo->getParam<int>("execution_order_group") : 0; 288 310938 : } 289 : bool 290 10586699 : AttribExecutionOrderGroup::isMatch(const Attribute & other) const 291 : { 292 10586699 : auto a = dynamic_cast<const AttribExecutionOrderGroup *>(&other); 293 10586699 : return a && (a->_val == _val); 294 : } 295 : bool 296 9081061 : AttribExecutionOrderGroup::isEqual(const Attribute & other) const 297 : { 298 9081061 : return isMatch(other); 299 : } 300 : 301 : void 302 310938 : AttribSysNum::initFrom(const MooseObject * obj) 303 : { 304 310938 : auto * sys = obj->getParam<SystemBase *>("_sys"); 305 : 306 310938 : if (sys) 307 310531 : _val = sys->number(); 308 310938 : } 309 : 310 : bool 311 10622805 : AttribSysNum::isMatch(const Attribute & other) const 312 : { 313 10622805 : auto a = dynamic_cast<const AttribSysNum *>(&other); 314 10622805 : return a && (a->_val == _val); 315 : } 316 : 317 : bool 318 9773596 : AttribSysNum::isEqual(const Attribute & other) const 319 : { 320 9773596 : return isMatch(other); 321 : } 322 : 323 : void 324 310938 : AttribPreIC::initFrom(const MooseObject * /*obj*/) 325 : { 326 310938 : } 327 : bool 328 15161 : AttribPreIC::isMatch(const Attribute & other) const 329 : { 330 15161 : auto a = dynamic_cast<const AttribPreIC *>(&other); 331 15161 : return a && (a->_val == _val); 332 : } 333 : 334 : bool 335 67 : AttribPreIC::isEqual(const Attribute & other) const 336 : { 337 67 : return isMatch(other); 338 : } 339 : 340 : bool 341 192322 : AttribPreAux::isMatch(const Attribute & other) const 342 : { 343 192322 : const auto a = dynamic_cast<const AttribPreAux *>(&other); 344 : 345 192322 : bool is_match = false; 346 : 347 192322 : if (a && !_vals.empty() && !a->_vals.empty()) 348 : { 349 62325 : 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 192322 : return is_match; 354 : } 355 : 356 : bool 357 5772246 : AttribPreAux::isEqual(const Attribute & other) const 358 : { 359 5772246 : const auto a = dynamic_cast<const AttribPreAux *>(&other); 360 5772246 : return a && a->_vals == _vals; 361 : } 362 : 363 : void 364 310938 : AttribPreAux::initFrom(const MooseObject * /*obj*/) 365 : { 366 310938 : } 367 : 368 : bool 369 1552750 : AttribPostAux::isMatch(const Attribute & other) const 370 : { 371 1552750 : const auto a = dynamic_cast<const AttribPostAux *>(&other); 372 : 373 1552750 : bool is_match = false; 374 : 375 1552750 : if (a && !_vals.empty() && !a->_vals.empty()) 376 : { 377 1560612 : is_match = std::includes(_vals.begin(), _vals.end(), a->_vals.begin(), a->_vals.end()) || 378 13357 : std::includes(a->_vals.begin(), a->_vals.end(), _vals.begin(), _vals.end()); 379 : } 380 : 381 1552750 : return is_match; 382 : } 383 : 384 : bool 385 14487578 : AttribPostAux::isEqual(const Attribute & other) const 386 : { 387 14487578 : const auto a = dynamic_cast<const AttribPostAux *>(&other); 388 14487578 : return a && a->_vals == _vals; 389 : } 390 : 391 : void 392 310938 : AttribPostAux::initFrom(const MooseObject * /*obj*/) 393 : { 394 310938 : } 395 : 396 : void 397 310938 : AttribName::initFrom(const MooseObject * obj) 398 : { 399 310938 : _val = obj->name(); 400 310938 : } 401 : bool 402 1497455 : AttribName::isMatch(const Attribute & other) const 403 : { 404 1497455 : auto a = dynamic_cast<const AttribName *>(&other); 405 1497455 : return a && (a->_val == _val); 406 : } 407 : 408 : bool 409 1273154 : AttribName::isEqual(const Attribute & other) const 410 : { 411 1273154 : return isMatch(other); 412 : } 413 : 414 : void 415 310938 : AttribSystem::initFrom(const MooseObject * obj) 416 : { 417 310938 : _val = obj->parameters().getSystemAttributeName(); 418 310938 : } 419 : 420 : bool 421 61889252 : AttribSystem::isMatch(const Attribute & other) const 422 : { 423 61889252 : auto a = dynamic_cast<const AttribSystem *>(&other); 424 61889252 : return a && (a->_val == _val); 425 : } 426 : 427 : bool 428 44216432 : AttribSystem::isEqual(const Attribute & other) const 429 : { 430 44216432 : return isMatch(other); 431 : } 432 : 433 : void 434 310938 : AttribResidualObject::initFrom(const MooseObject * obj) 435 : { 436 310938 : _val = obj->getParam<bool>("_residual_object"); 437 310938 : _initd = true; 438 310938 : } 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 310938 : AttribVar::initFrom(const MooseObject * obj) 455 : { 456 310938 : auto vi = dynamic_cast<const MooseVariableInterface<Real> *>(obj); 457 310938 : if (vi) 458 224083 : _val = static_cast<int>(vi->mooseVariableBase()->number()); 459 310938 : } 460 : bool 461 223582 : AttribVar::isMatch(const Attribute & other) const 462 : { 463 223582 : auto a = dynamic_cast<const AttribVar *>(&other); 464 223582 : return a && (_val != -1) && (a->_val == _val); 465 : } 466 : 467 : bool 468 152234 : AttribVar::isEqual(const Attribute & other) const 469 : { 470 152234 : return isMatch(other); 471 : } 472 : 473 : void 474 310938 : AttribInterfaces::initFrom(const MooseObject * obj) 475 : { 476 310938 : _val = 0; 477 : // clang-format off 478 310938 : _val |= (unsigned int)Interfaces::UserObject * (dynamic_cast<const UserObject *>(obj) != nullptr); 479 310938 : _val |= (unsigned int)Interfaces::ElementUserObject * (dynamic_cast<const ElementUserObject *>(obj) != nullptr); 480 310938 : _val |= (unsigned int)Interfaces::SideUserObject * (dynamic_cast<const SideUserObject *>(obj) != nullptr); 481 310938 : _val |= (unsigned int)Interfaces::InternalSideUserObject * (dynamic_cast<const InternalSideUserObject *>(obj) != nullptr); 482 310938 : _val |= (unsigned int)Interfaces::InterfaceUserObject * (dynamic_cast<const InterfaceUserObject *>(obj) != nullptr); 483 310938 : _val |= (unsigned int)Interfaces::NodalUserObject * (dynamic_cast<const NodalUserObject *>(obj) != nullptr); 484 310938 : _val |= (unsigned int)Interfaces::GeneralUserObject * (dynamic_cast<const GeneralUserObject *>(obj) != nullptr); 485 310938 : _val |= (unsigned int)Interfaces::ThreadedGeneralUserObject * (dynamic_cast<const ThreadedGeneralUserObject *>(obj) != nullptr); 486 310938 : _val |= (unsigned int)Interfaces::ShapeElementUserObject * (dynamic_cast<const ShapeElementUserObject *>(obj) != nullptr); 487 310938 : _val |= (unsigned int)Interfaces::ShapeSideUserObject * (dynamic_cast<const ShapeSideUserObject *>(obj) != nullptr); 488 310938 : _val |= (unsigned int)Interfaces::Postprocessor * (dynamic_cast<const Postprocessor *>(obj) != nullptr); 489 310938 : _val |= (unsigned int)Interfaces::VectorPostprocessor * (dynamic_cast<const VectorPostprocessor *>(obj) != nullptr); 490 310938 : _val |= (unsigned int)Interfaces::BlockRestrictable * (dynamic_cast<const BlockRestrictable *>(obj) != nullptr); 491 310938 : _val |= (unsigned int)Interfaces::BoundaryRestrictable * (dynamic_cast<const BoundaryRestrictable *>(obj) != nullptr); 492 310938 : _val |= (unsigned int)Interfaces::Reporter * (dynamic_cast<const Reporter *>(obj) != nullptr); 493 310938 : _val |= (unsigned int)Interfaces::DomainUserObject * (dynamic_cast<const DomainUserObject *>(obj) != nullptr); 494 310938 : _val |= (unsigned int)Interfaces::MortarUserObject * (dynamic_cast<const MortarUserObject *>(obj) != nullptr); 495 : // clang-format on 496 310938 : } 497 : 498 : bool 499 4532241 : AttribInterfaces::isMatch(const Attribute & other) const 500 : { 501 4532241 : auto a = dynamic_cast<const AttribInterfaces *>(&other); 502 4532241 : return a && (a->_val & _val); 503 : } 504 : 505 : bool 506 14229987 : AttribInterfaces::isEqual(const Attribute & other) const 507 : { 508 14229987 : auto a = dynamic_cast<const AttribInterfaces *>(&other); 509 14229987 : return a && (a->_val == _val); 510 : } 511 : 512 : void 513 310938 : AttribDisplaced::initFrom(const MooseObject * obj) 514 : { 515 587889 : _val = obj->parameters().have_parameter<bool>("use_displaced_mesh") && 516 587889 : obj->getParam<bool>("use_displaced_mesh"); 517 310938 : } 518 : 519 : bool 520 9172281 : AttribDisplaced::isMatch(const Attribute & other) const 521 : { 522 9172281 : auto a = dynamic_cast<const AttribDisplaced *>(&other); 523 9172281 : return a && (a->_val == _val); 524 : } 525 : 526 : bool 527 9112674 : AttribDisplaced::isEqual(const Attribute & other) const 528 : { 529 9112674 : return isMatch(other); 530 : }