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 55284 : AttribTagBase::isMatch(const Attribute & other) const 78 : { 79 55284 : auto a = dynamic_cast<const AttribTagBase *>(&other); 80 55284 : if (!a) 81 0 : return false; 82 55284 : 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 56334 : for (auto val : _vals) 87 55259 : if (std::find(a->_vals.begin(), a->_vals.end(), val) != a->_vals.end()) 88 54209 : return true; 89 1075 : return false; 90 : } 91 : 92 : bool 93 8316921 : AttribTagBase::isEqual(const Attribute & other) const 94 : { 95 8316921 : auto a = dynamic_cast<const AttribTagBase *>(&other); 96 8316921 : if (!a || a->_vals.size() != _vals.size()) 97 0 : return false; 98 : 99 28569078 : for (size_t i = 0; i < a->_vals.size(); i++) 100 20252157 : if (a->_vals[i] != _vals[i]) 101 0 : return false; 102 8316921 : return true; 103 : } 104 : 105 : void 106 288408 : AttribMatrixTags::initFrom(const MooseObject * obj) 107 : { 108 288408 : _vals.clear(); 109 288408 : auto t = dynamic_cast<const TaggingInterface *>(obj); 110 288408 : if (t) 111 : { 112 462362 : for (auto & tag : t->getMatrixTags({})) 113 275654 : _vals.push_back(static_cast<int>(tag)); 114 : } 115 288408 : } 116 : 117 : void 118 288408 : AttribVectorTags::initFrom(const MooseObject * obj) 119 : { 120 288408 : _vals.clear(); 121 288408 : auto t = dynamic_cast<const TaggingInterface *>(obj); 122 288408 : if (t) 123 : { 124 377151 : for (auto & tag : t->getVectorTags({})) 125 190443 : _vals.push_back(static_cast<int>(tag)); 126 : } 127 288408 : } 128 : 129 : void 130 288408 : AttribExecOns::initFrom(const MooseObject * obj) 131 : { 132 288408 : _vals.clear(); 133 288408 : if (const auto sup = dynamic_cast<const SetupInterface *>(obj)) 134 : { 135 259427 : const auto & current_items = sup->getExecuteOnEnum(); 136 259427 : _vals.reserve(current_items.size()); 137 344920 : for (auto & on : current_items) 138 85493 : _vals.push_back(on); 139 : } 140 288408 : } 141 : 142 : bool 143 2973546 : AttribExecOns::isMatch(const Attribute & other) const 144 : { 145 2973546 : auto a = dynamic_cast<const AttribExecOns *>(&other); 146 2973546 : if (!a || a->_vals.empty()) 147 0 : return false; 148 2973546 : auto cond = a->_vals[0]; 149 2973546 : if (cond == EXEC_ALL) 150 1320 : return true; 151 : 152 4852214 : for (const auto val : _vals) 153 3498606 : if (val == EXEC_ALL || val == cond) 154 1618618 : return true; 155 1353608 : return false; 156 : } 157 : 158 : bool 159 23271179 : AttribExecOns::isEqual(const Attribute & other) const 160 : { 161 23271179 : auto a = dynamic_cast<const AttribExecOns *>(&other); 162 23271179 : if (!a || a->_vals.size() != _vals.size()) 163 0 : return false; 164 : 165 46542358 : for (size_t i = 0; i < a->_vals.size(); i++) 166 23271179 : if (a->_vals[i] != _vals[i]) 167 0 : return false; 168 23271179 : return true; 169 : } 170 : 171 : void 172 288408 : AttribSubdomains::initFrom(const MooseObject * obj) 173 : { 174 288408 : _vals.clear(); 175 288408 : auto blk = dynamic_cast<const BlockRestrictable *>(obj); 176 288408 : if (blk && blk->blockRestricted()) 177 : { 178 32580 : for (auto id : blk->blockIDs()) 179 17871 : _vals.push_back(id); 180 : } 181 : else 182 273699 : _vals.push_back(Moose::ANY_BLOCK_ID); 183 288408 : } 184 : 185 : bool 186 1001793 : AttribSubdomains::isMatch(const Attribute & other) const 187 : { 188 1001793 : auto a = dynamic_cast<const AttribSubdomains *>(&other); 189 1001793 : if (!a || a->_vals.size() < 1) 190 0 : return false; 191 : 192 1001793 : auto cond = a->_vals[0]; 193 1001793 : if (cond == Moose::ANY_BLOCK_ID) 194 0 : return true; 195 1001793 : else if (cond == Moose::INVALID_BLOCK_ID) 196 8968 : return false; 197 : 198 1105111 : for (auto id : _vals) 199 : { 200 1025236 : if (id == cond || id == Moose::ANY_BLOCK_ID) 201 912950 : return true; 202 : } 203 79875 : return false; 204 : } 205 : 206 : bool 207 6210735 : AttribSubdomains::isEqual(const Attribute & other) const 208 : { 209 6210735 : auto a = dynamic_cast<const AttribSubdomains *>(&other); 210 6210735 : if (!a || a->_vals.size() != _vals.size()) 211 0 : return false; 212 : 213 12421470 : for (size_t i = 0; i < a->_vals.size(); i++) 214 6210735 : if (a->_vals[i] != _vals[i]) 215 0 : return false; 216 6210735 : return true; 217 : } 218 : 219 : void 220 288408 : AttribBoundaries::initFrom(const MooseObject * obj) 221 : { 222 288408 : _vals.clear(); 223 288408 : auto bnd = dynamic_cast<const BoundaryRestrictable *>(obj); 224 288408 : if (bnd && bnd->boundaryRestricted()) 225 : { 226 212358 : for (auto & bound : bnd->boundaryIDs()) 227 119896 : _vals.push_back(bound); 228 : } 229 : else 230 195946 : _vals.push_back(Moose::ANY_BOUNDARY_ID); 231 288408 : } 232 : 233 : bool 234 705019 : AttribBoundaries::isMatch(const Attribute & other) const 235 : { 236 705019 : auto a = dynamic_cast<const AttribBoundaries *>(&other); 237 705019 : 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 975786 : for (auto val : _vals) 242 : { 243 795120 : if (!a->_must_be_restricted && (val == Moose::ANY_BOUNDARY_ID)) 244 524353 : return true; 245 362257 : if (std::find(a->_vals.begin(), a->_vals.end(), val) != a->_vals.end()) 246 85970 : return true; 247 276287 : else if (std::find(a->_vals.begin(), a->_vals.end(), Moose::ANY_BOUNDARY_ID) != a->_vals.end()) 248 5520 : return true; 249 : } 250 180666 : return false; 251 : } 252 : 253 : bool 254 9643024 : AttribBoundaries::isEqual(const Attribute & other) const 255 : { 256 9643024 : auto a = dynamic_cast<const AttribBoundaries *>(&other); 257 9643024 : if (!a || a->_vals.size() != _vals.size()) 258 0 : return false; 259 : 260 19286048 : for (size_t i = 0; i < a->_vals.size(); i++) 261 9643024 : if (a->_vals[i] != _vals[i]) 262 0 : return false; 263 9643024 : return true; 264 : } 265 : 266 : void 267 288408 : AttribThread::initFrom(const MooseObject * obj) 268 : { 269 288408 : _val = obj->getParam<THREAD_ID>("_tid"); 270 288408 : } 271 : bool 272 24558484 : AttribThread::isMatch(const Attribute & other) const 273 : { 274 24558484 : auto a = dynamic_cast<const AttribThread *>(&other); 275 24558484 : return a && (a->_val == _val); 276 : } 277 : bool 278 21405107 : AttribThread::isEqual(const Attribute & other) const 279 : { 280 21405107 : return isMatch(other); 281 : } 282 : 283 : void 284 288408 : AttribExecutionOrderGroup::initFrom(const MooseObject * obj) 285 : { 286 288408 : const auto * uo = dynamic_cast<const UserObject *>(obj); 287 288408 : _val = uo ? uo->getParam<int>("execution_order_group") : 0; 288 288408 : } 289 : bool 290 8976866 : AttribExecutionOrderGroup::isMatch(const Attribute & other) const 291 : { 292 8976866 : auto a = dynamic_cast<const AttribExecutionOrderGroup *>(&other); 293 8976866 : return a && (a->_val == _val); 294 : } 295 : bool 296 7595878 : AttribExecutionOrderGroup::isEqual(const Attribute & other) const 297 : { 298 7595878 : return isMatch(other); 299 : } 300 : 301 : void 302 288408 : AttribSysNum::initFrom(const MooseObject * obj) 303 : { 304 288408 : auto * sys = obj->getParam<SystemBase *>("_sys"); 305 : 306 288408 : if (sys) 307 288032 : _val = sys->number(); 308 288408 : } 309 : 310 : bool 311 9670443 : AttribSysNum::isMatch(const Attribute & other) const 312 : { 313 9670443 : auto a = dynamic_cast<const AttribSysNum *>(&other); 314 9670443 : return a && (a->_val == _val); 315 : } 316 : 317 : bool 318 8878585 : AttribSysNum::isEqual(const Attribute & other) const 319 : { 320 8878585 : return isMatch(other); 321 : } 322 : 323 : void 324 288408 : AttribPreIC::initFrom(const MooseObject * /*obj*/) 325 : { 326 288408 : } 327 : bool 328 14060 : AttribPreIC::isMatch(const Attribute & other) const 329 : { 330 14060 : auto a = dynamic_cast<const AttribPreIC *>(&other); 331 14060 : return a && (a->_val == _val); 332 : } 333 : 334 : bool 335 62 : AttribPreIC::isEqual(const Attribute & other) const 336 : { 337 62 : return isMatch(other); 338 : } 339 : 340 : bool 341 178516 : AttribPreAux::isMatch(const Attribute & other) const 342 : { 343 178516 : const auto a = dynamic_cast<const AttribPreAux *>(&other); 344 : 345 178516 : bool is_match = false; 346 : 347 178516 : if (a && !_vals.empty() && !a->_vals.empty()) 348 : { 349 56733 : is_match = std::includes(_vals.begin(), _vals.end(), a->_vals.begin(), a->_vals.end()) || 350 4122 : std::includes(a->_vals.begin(), a->_vals.end(), _vals.begin(), _vals.end()); 351 : } 352 : 353 178516 : return is_match; 354 : } 355 : 356 : bool 357 5328752 : AttribPreAux::isEqual(const Attribute & other) const 358 : { 359 5328752 : const auto a = dynamic_cast<const AttribPreAux *>(&other); 360 5328752 : return a && a->_vals == _vals; 361 : } 362 : 363 : void 364 288408 : AttribPreAux::initFrom(const MooseObject * /*obj*/) 365 : { 366 288408 : } 367 : 368 : bool 369 1424150 : AttribPostAux::isMatch(const Attribute & other) const 370 : { 371 1424150 : const auto a = dynamic_cast<const AttribPostAux *>(&other); 372 : 373 1424150 : bool is_match = false; 374 : 375 1424150 : if (a && !_vals.empty() && !a->_vals.empty()) 376 : { 377 1431089 : is_match = std::includes(_vals.begin(), _vals.end(), a->_vals.begin(), a->_vals.end()) || 378 12289 : std::includes(a->_vals.begin(), a->_vals.end(), _vals.begin(), _vals.end()); 379 : } 380 : 381 1424150 : return is_match; 382 : } 383 : 384 : bool 385 12586255 : AttribPostAux::isEqual(const Attribute & other) const 386 : { 387 12586255 : const auto a = dynamic_cast<const AttribPostAux *>(&other); 388 12586255 : return a && a->_vals == _vals; 389 : } 390 : 391 : void 392 288408 : AttribPostAux::initFrom(const MooseObject * /*obj*/) 393 : { 394 288408 : } 395 : 396 : void 397 288408 : AttribName::initFrom(const MooseObject * obj) 398 : { 399 288408 : _val = obj->name(); 400 288408 : } 401 : bool 402 588628 : AttribName::isMatch(const Attribute & other) const 403 : { 404 588628 : auto a = dynamic_cast<const AttribName *>(&other); 405 588628 : return a && (a->_val == _val); 406 : } 407 : 408 : bool 409 401707 : AttribName::isEqual(const Attribute & other) const 410 : { 411 401707 : return isMatch(other); 412 : } 413 : 414 : void 415 288408 : AttribSystem::initFrom(const MooseObject * obj) 416 : { 417 288408 : _val = obj->parameters().getSystemAttributeName(); 418 288408 : } 419 : 420 : bool 421 56001553 : AttribSystem::isMatch(const Attribute & other) const 422 : { 423 56001553 : auto a = dynamic_cast<const AttribSystem *>(&other); 424 56001553 : return a && (a->_val == _val); 425 : } 426 : 427 : bool 428 39733215 : AttribSystem::isEqual(const Attribute & other) const 429 : { 430 39733215 : return isMatch(other); 431 : } 432 : 433 : void 434 288408 : AttribResidualObject::initFrom(const MooseObject * obj) 435 : { 436 288408 : _val = obj->getParam<bool>("_residual_object"); 437 288408 : _initd = true; 438 288408 : } 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 288408 : AttribVar::initFrom(const MooseObject * obj) 455 : { 456 288408 : auto vi = dynamic_cast<const MooseVariableInterface<Real> *>(obj); 457 288408 : if (vi) 458 209051 : _val = static_cast<int>(vi->mooseVariableBase()->number()); 459 288408 : } 460 : bool 461 208027 : AttribVar::isMatch(const Attribute & other) const 462 : { 463 208027 : auto a = dynamic_cast<const AttribVar *>(&other); 464 208027 : return a && (_val != -1) && (a->_val == _val); 465 : } 466 : 467 : bool 468 142094 : AttribVar::isEqual(const Attribute & other) const 469 : { 470 142094 : return isMatch(other); 471 : } 472 : 473 : void 474 288408 : AttribInterfaces::initFrom(const MooseObject * obj) 475 : { 476 288408 : _val = 0; 477 : // clang-format off 478 288408 : _val |= (unsigned int)Interfaces::UserObject * (dynamic_cast<const UserObject *>(obj) != nullptr); 479 288408 : _val |= (unsigned int)Interfaces::ElementUserObject * (dynamic_cast<const ElementUserObject *>(obj) != nullptr); 480 288408 : _val |= (unsigned int)Interfaces::SideUserObject * (dynamic_cast<const SideUserObject *>(obj) != nullptr); 481 288408 : _val |= (unsigned int)Interfaces::InternalSideUserObject * (dynamic_cast<const InternalSideUserObject *>(obj) != nullptr); 482 288408 : _val |= (unsigned int)Interfaces::InterfaceUserObject * (dynamic_cast<const InterfaceUserObject *>(obj) != nullptr); 483 288408 : _val |= (unsigned int)Interfaces::NodalUserObject * (dynamic_cast<const NodalUserObject *>(obj) != nullptr); 484 288408 : _val |= (unsigned int)Interfaces::GeneralUserObject * (dynamic_cast<const GeneralUserObject *>(obj) != nullptr); 485 288408 : _val |= (unsigned int)Interfaces::ThreadedGeneralUserObject * (dynamic_cast<const ThreadedGeneralUserObject *>(obj) != nullptr); 486 288408 : _val |= (unsigned int)Interfaces::ShapeElementUserObject * (dynamic_cast<const ShapeElementUserObject *>(obj) != nullptr); 487 288408 : _val |= (unsigned int)Interfaces::ShapeSideUserObject * (dynamic_cast<const ShapeSideUserObject *>(obj) != nullptr); 488 288408 : _val |= (unsigned int)Interfaces::Postprocessor * (dynamic_cast<const Postprocessor *>(obj) != nullptr); 489 288408 : _val |= (unsigned int)Interfaces::VectorPostprocessor * (dynamic_cast<const VectorPostprocessor *>(obj) != nullptr); 490 288408 : _val |= (unsigned int)Interfaces::BlockRestrictable * (dynamic_cast<const BlockRestrictable *>(obj) != nullptr); 491 288408 : _val |= (unsigned int)Interfaces::BoundaryRestrictable * (dynamic_cast<const BoundaryRestrictable *>(obj) != nullptr); 492 288408 : _val |= (unsigned int)Interfaces::Reporter * (dynamic_cast<const Reporter *>(obj) != nullptr); 493 288408 : _val |= (unsigned int)Interfaces::DomainUserObject * (dynamic_cast<const DomainUserObject *>(obj) != nullptr); 494 288408 : _val |= (unsigned int)Interfaces::MortarUserObject * (dynamic_cast<const MortarUserObject *>(obj) != nullptr); 495 : // clang-format on 496 288408 : } 497 : 498 : bool 499 4147582 : AttribInterfaces::isMatch(const Attribute & other) const 500 : { 501 4147582 : auto a = dynamic_cast<const AttribInterfaces *>(&other); 502 4147582 : return a && (a->_val & _val); 503 : } 504 : 505 : bool 506 12224640 : AttribInterfaces::isEqual(const Attribute & other) const 507 : { 508 12224640 : auto a = dynamic_cast<const AttribInterfaces *>(&other); 509 12224640 : return a && (a->_val == _val); 510 : } 511 : 512 : void 513 288408 : AttribDisplaced::initFrom(const MooseObject * obj) 514 : { 515 545724 : _val = obj->parameters().have_parameter<bool>("use_displaced_mesh") && 516 545724 : obj->getParam<bool>("use_displaced_mesh"); 517 288408 : } 518 : 519 : bool 520 8307078 : AttribDisplaced::isMatch(const Attribute & other) const 521 : { 522 8307078 : auto a = dynamic_cast<const AttribDisplaced *>(&other); 523 8307078 : return a && (a->_val == _val); 524 : } 525 : 526 : bool 527 8249995 : AttribDisplaced::isEqual(const Attribute & other) const 528 : { 529 8249995 : return isMatch(other); 530 : }