https://mooseframework.inl.gov
MooseObjectWarehouseBase.h
Go to the documentation of this file.
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 #pragma once
11 
12 // MOOSE includes
14 #include "BoundaryRestrictable.h"
15 #include "BlockRestrictable.h"
16 #include "TransientInterface.h"
17 #include "Coupleable.h"
20 #include "SubProblem.h"
21 #include "MooseApp.h"
22 
23 // Forward declarations
25 
29 template <typename T>
31 {
32 public:
37  MooseObjectWarehouseBase(bool threaded = true);
38 
42  virtual ~MooseObjectWarehouseBase();
43 
49  virtual void addObject(std::shared_ptr<T> object, THREAD_ID tid = 0, bool recurse = true);
50 
54  unsigned int size(THREAD_ID tid = 0) const;
55 
57 
61  const std::vector<std::shared_ptr<T>> & getObjects(THREAD_ID tid = 0) const;
62  const std::map<SubdomainID, std::vector<std::shared_ptr<T>>> &
63  getBlockObjects(THREAD_ID tid = 0) const;
64  const std::vector<std::shared_ptr<T>> & getBlockObjects(SubdomainID id, THREAD_ID tid = 0) const;
65  const std::map<BoundaryID, std::vector<std::shared_ptr<T>>> &
66  getBoundaryObjects(THREAD_ID tid = 0) const;
67  const std::vector<std::shared_ptr<T>> & getBoundaryObjects(BoundaryID id,
68  THREAD_ID tid = 0) const;
70 
72 
77  const std::vector<std::shared_ptr<T>> & getActiveObjects(THREAD_ID tid = 0) const;
78  const std::map<SubdomainID, std::vector<std::shared_ptr<T>>> &
79  getActiveBlockObjects(THREAD_ID tid = 0) const;
80  const std::vector<std::shared_ptr<T>> & getActiveBlockObjects(SubdomainID id,
81  THREAD_ID tid = 0) const;
82  const std::map<BoundaryID, std::vector<std::shared_ptr<T>>> &
83  getActiveBoundaryObjects(THREAD_ID tid = 0) const;
84  const std::vector<std::shared_ptr<T>> & getActiveBoundaryObjects(BoundaryID id,
85  THREAD_ID tid = 0) const;
87 
89 
92  bool hasObjects(THREAD_ID tid = 0) const;
93  bool hasActiveObjects(THREAD_ID tid = 0) const;
94  bool hasObjectsForVariable(const VariableName & var_name, THREAD_ID tid) const;
95  bool hasActiveBlockObjects(THREAD_ID tid = 0) const;
96  bool hasActiveBlockObjects(SubdomainID id, THREAD_ID tid = 0) const;
97  bool hasActiveBoundaryObjects(THREAD_ID tid = 0) const;
98  bool hasActiveBoundaryObjects(BoundaryID id, THREAD_ID tid = 0) const;
99  bool hasBoundaryObjects(THREAD_ID tid = 0) const;
100  bool hasBoundaryObjects(BoundaryID id, THREAD_ID tid = 0) const;
102 
109  bool hasObjectsForVariableAndBlocks(const VariableName & var_name,
110  const std::set<SubdomainID> & blocks,
111  std::set<SubdomainID> & blocks_covered,
112  THREAD_ID tid) const;
113 
117  std::set<SubdomainID> getActiveBlocks(THREAD_ID tid = 0) const;
118 
120 
123  bool hasActiveObject(const std::string & name, THREAD_ID tid = 0) const;
124  std::shared_ptr<T> getObject(const std::string & name, THREAD_ID tid = 0) const;
125  std::shared_ptr<T> getActiveObject(const std::string & name, THREAD_ID tid = 0) const;
127 
131  const std::vector<std::shared_ptr<T>> & getObjectsForVariable(const VariableName & var_name,
132  THREAD_ID tid) const;
133 
137  virtual void updateActive(THREAD_ID tid = 0);
138 
142  void sort(THREAD_ID tid = 0);
143 
145 
148  void updateVariableDependency(std::set<MooseVariableFieldBase *> & needed_moose_vars,
149  THREAD_ID tid = 0) const;
151  std::set<MooseVariableFieldBase *> & needed_moose_vars,
152  THREAD_ID tid = 0) const;
153  void updateBoundaryVariableDependency(std::set<MooseVariableFieldBase *> & needed_moose_vars,
154  THREAD_ID tid = 0) const;
156  std::set<MooseVariableFieldBase *> & needed_moose_vars,
157  THREAD_ID tid = 0) const;
159 
161 
165  void updateFEVariableCoupledVectorTagDependency(std::set<TagID> & needed_fe_var_vector_tags,
166  THREAD_ID tid = 0) const;
168  std::set<TagID> & needed_fe_var_vector_tags,
169  THREAD_ID tid = 0) const;
171  BoundaryID id, std::set<TagID> & needed_fe_var_vector_tags, THREAD_ID tid = 0) const;
173 
175 
179  void updateMatPropDependency(std::unordered_set<unsigned int> & needed_mat_props,
180  THREAD_ID tid = 0,
181  const bool producer_only = false) const;
183  std::unordered_set<unsigned int> & needed_mat_props,
184  THREAD_ID tid = 0,
185  const bool producer_only = false) const;
186  void updateBoundaryMatPropDependency(std::unordered_set<unsigned int> & needed_mat_props,
187  THREAD_ID tid = 0,
188  const bool producer_only = false) const;
190  std::unordered_set<unsigned int> & needed_mat_props,
191  THREAD_ID tid = 0,
192  const bool producer_only = false) const;
194 
198  void subdomainsCovered(std::set<SubdomainID> & subdomains_covered,
199  std::set<std::string> & unique_variables,
200  THREAD_ID tid = 0) const;
201 
205  THREAD_ID numThreads() const { return _num_threads; }
206 
212  std::string activeObjectsToFormattedString(THREAD_ID tid = 0,
213  const std::string & prefix = "[DBG]") const;
214 
215 protected:
218 
220  std::vector<std::vector<std::shared_ptr<T>>> _all_objects;
221 
223  std::vector<std::vector<std::shared_ptr<T>>> _active_objects;
224 
225  // All block restricted objects (THREAD_ID on outer vector)
226  std::vector<std::map<SubdomainID, std::vector<std::shared_ptr<T>>>> _all_block_objects;
227 
229  std::vector<std::map<SubdomainID, std::vector<std::shared_ptr<T>>>> _active_block_objects;
230 
231  // All boundary restricted objects (THREAD_ID on outer vector)
232  std::vector<std::map<BoundaryID, std::vector<std::shared_ptr<T>>>> _all_boundary_objects;
233 
235  std::vector<std::map<BoundaryID, std::vector<std::shared_ptr<T>>>> _active_boundary_objects;
236 
238  std::vector<std::map<VariableName, std::vector<std::shared_ptr<T>>>> _all_variable_objects;
239 
243  static void updateActiveHelper(std::vector<std::shared_ptr<T>> & active,
244  const std::vector<std::shared_ptr<T>> & all);
245 
249  static void sortHelper(std::vector<std::shared_ptr<T>> & objects);
250 
254  static void updateVariableDependencyHelper(std::set<MooseVariableFieldBase *> & needed_moose_vars,
255  const std::vector<std::shared_ptr<T>> & objects);
256 
260  static void
261  updateFEVariableCoupledVectorTagDependencyHelper(std::set<TagID> & needed_fe_var_vector_tags,
262  const std::vector<std::shared_ptr<T>> & objects);
263 
267  virtual void updateMatPropDependencyHelper(std::unordered_set<unsigned int> & needed_mat_props,
268  const std::vector<std::shared_ptr<T>> & objects,
269  const bool producer_only) const;
270 
274  void checkThreadID(THREAD_ID tid) const;
275 
280  const std::vector<std::map<BoundaryID, std::vector<std::shared_ptr<T>>>> & boundary_objects,
281  const THREAD_ID tid = 0) const;
282 
283  friend class MaterialWarehouse;
284 };
285 
286 template <typename T>
288  : _num_threads(threaded ? libMesh::n_threads() : 1),
296 {
297 }
298 
299 template <typename T>
301 {
302 }
303 
304 template <typename T>
305 unsigned int
307 {
308  checkThreadID(tid);
309  return _all_objects[tid].size();
310 }
311 
312 template <typename T>
313 void
314 MooseObjectWarehouseBase<T>::addObject(std::shared_ptr<T> object,
315  THREAD_ID tid /*= 0*/,
316  bool /* recurse = true */)
317 {
318  checkThreadID(tid);
319 
320  // Stores object in list of all objects
321  _all_objects[tid].push_back(object);
322 
323  // If enabled, store object in a list of all active
324  bool enabled = object->enabled();
325  if (enabled)
326  _active_objects[tid].push_back(object);
327 
328  // Perform casts to the Block/BoundaryRestrictable
329  std::shared_ptr<BoundaryRestrictable> bnd =
331  std::shared_ptr<BlockRestrictable> blk = std::dynamic_pointer_cast<BlockRestrictable>(object);
332 
333  // Boundary Restricted
334  if (bnd && bnd->boundaryRestricted())
335  {
336  const std::set<BoundaryID> & ids = bnd->boundaryIDs();
337  for (std::set<BoundaryID>::const_iterator it = ids.begin(); it != ids.end(); ++it)
338  {
339  _all_boundary_objects[tid][*it].push_back(object);
340  if (enabled)
341  _active_boundary_objects[tid][*it].push_back(object);
342  }
343  }
344 
345  // Block Restricted
346  else if (blk)
347  {
348  const std::set<SubdomainID> & ids =
349  blk->blockRestricted() ? blk->blockIDs() : blk->meshBlockIDs();
350  for (std::set<SubdomainID>::const_iterator it = ids.begin(); it != ids.end(); ++it)
351  {
352  _all_block_objects[tid][*it].push_back(object);
353  if (enabled)
354  _active_block_objects[tid][*it].push_back(object);
355  }
356 
357  // Check variables
358  std::shared_ptr<Coupleable> c_ptr = std::dynamic_pointer_cast<Coupleable>(object);
359  if (c_ptr)
360  for (MooseVariableFieldBase * var : c_ptr->getCoupledMooseVars())
361  blk->checkVariable(*var);
362 
363  const InputParameters & parameters = object->parameters();
364 
365  SubProblem & problem = *parameters.get<SubProblem *>("_subproblem");
366 
367  THREAD_ID tid = parameters.get<THREAD_ID>("_tid");
368 
369  if (parameters.isParamValid("variable"))
370  {
371  // Try the scalar version first
372  std::string variable_name = parameters.getMooseType("variable");
373  if (variable_name == "")
374  // When using vector variables, we are only going to use the first one in the list at the
375  // interface level...
376  variable_name = parameters.getVecMooseType("variable")[0];
377 
378  blk->checkVariable(problem.getVariable(
380 
381  _all_variable_objects[tid][variable_name].push_back(object);
382  }
383  }
384 }
385 
386 template <typename T>
387 inline const std::vector<std::shared_ptr<T>> &
389 {
390  checkThreadID(tid);
391  return _all_objects[tid];
392 }
393 
394 template <typename T>
395 inline const std::map<BoundaryID, std::vector<std::shared_ptr<T>>> &
397 {
398  checkThreadID(tid);
399  return _all_boundary_objects[tid];
400 }
401 
402 template <typename T>
403 bool
405 {
406  checkThreadID(tid);
407  return _all_boundary_objects[tid].find(id) != _all_boundary_objects[tid].end();
408 }
409 
410 template <typename T>
411 const std::vector<std::shared_ptr<T>> &
413 {
414  checkThreadID(tid);
415  const auto iter = _all_boundary_objects[tid].find(id);
416  mooseAssert(iter != _all_boundary_objects[tid].end(),
417  "Unable to located active boundary objects for the given id: " << id << ".");
418  return iter->second;
419 }
420 
421 template <typename T>
422 inline const std::map<SubdomainID, std::vector<std::shared_ptr<T>>> &
424 {
425  checkThreadID(tid);
426  return _all_block_objects[tid];
427 }
428 
429 template <typename T>
430 const std::vector<std::shared_ptr<T>> &
432 {
433  checkThreadID(tid);
434  const auto iter = _all_block_objects[tid].find(id);
435  mooseAssert(iter != _all_block_objects[tid].end(),
436  "Unable to located active block objects for the given id: " << id << ".");
437  return iter->second;
438 }
439 
440 template <typename T>
441 inline const std::vector<std::shared_ptr<T>> &
443 {
444  checkThreadID(tid);
445  return _active_objects[tid];
446 }
447 
448 template <typename T>
449 inline const std::map<BoundaryID, std::vector<std::shared_ptr<T>>> &
451 {
452  checkThreadID(tid);
453  return _active_boundary_objects[tid];
454 }
455 
456 template <typename T>
457 const std::vector<std::shared_ptr<T>> &
459 {
460  checkThreadID(tid);
461  const auto iter = _active_boundary_objects[tid].find(id);
462  mooseAssert(iter != _active_boundary_objects[tid].end(),
463  "Unable to located active boundary objects for the given id: " << id << ".");
464  return iter->second;
465 }
466 
467 template <typename T>
468 inline const std::map<SubdomainID, std::vector<std::shared_ptr<T>>> &
470 {
471  checkThreadID(tid);
472  return _active_block_objects[tid];
473 }
474 
475 template <typename T>
476 const std::vector<std::shared_ptr<T>> &
478 {
479  checkThreadID(tid);
480  const auto iter = _active_block_objects[tid].find(id);
481  mooseAssert(iter != _active_block_objects[tid].end(),
482  "Unable to located active block objects for the given id: " << id << ".");
483  return iter->second;
484 }
485 
486 template <typename T>
487 bool
489 {
490  checkThreadID(tid);
491  return !_all_objects[tid].empty();
492 }
493 
494 template <typename T>
495 bool
497 {
498  checkThreadID(tid);
499  return !_active_objects[tid].empty();
500 }
501 
502 template <typename T>
503 bool
505  THREAD_ID tid) const
506 {
507  checkThreadID(tid);
508  return _all_variable_objects[tid].count(var_name);
509 }
510 
511 template <typename T>
512 bool
514  const std::set<SubdomainID> & blocks,
515  std::set<SubdomainID> & blocks_covered,
516  THREAD_ID tid /* = 0*/) const
517 {
518  checkThreadID(tid);
519  blocks_covered.clear();
520  if (!hasObjectsForVariable(var_name, tid))
521  return false;
522 
523  // Check block restriction as a whole
524  for (const auto & object : libmesh_map_find(_all_variable_objects[tid], var_name))
525  {
526  std::shared_ptr<BlockRestrictable> blk = std::dynamic_pointer_cast<BlockRestrictable>(object);
527  if (blk && blk->hasBlocks(blocks))
528  {
529  blocks_covered = blocks;
530  return true;
531  }
532  }
533  // No object has all the blocks, but one might overlap, which could be troublesome.
534  // We'll keep track of which blocks are covered in case several overlap
535  for (const auto & object : libmesh_map_find(_all_variable_objects[tid], var_name))
536  {
537  std::shared_ptr<BlockRestrictable> blk = std::dynamic_pointer_cast<BlockRestrictable>(object);
538  if (blk)
539  for (const auto & block : blocks)
540  if (blk->hasBlocks(block))
541  blocks_covered.insert(block);
542  }
543  // No overlap at all
544  if (blocks_covered.empty())
545  return false;
546 
547  return (blocks == blocks_covered);
548 }
549 
550 template <typename T>
551 bool
553 {
554  checkThreadID(tid);
555  bool has_active_block_objects = false;
556  for (const auto & object_pair : _active_block_objects[tid])
557  has_active_block_objects |= !(object_pair.second.empty());
558  return has_active_block_objects;
559 }
560 
561 template <typename T>
562 bool
564 {
565  checkThreadID(tid);
566  const auto iter = _active_block_objects[tid].find(id);
567  return iter != _active_block_objects[tid].end();
568 }
569 
570 template <typename T>
571 bool
573  const std::vector<std::map<BoundaryID, std::vector<std::shared_ptr<T>>>> & boundary_objects,
574  THREAD_ID tid /* = 0*/) const
575 {
576  checkThreadID(tid);
577  bool has_boundary_objects = false;
578  for (const auto & object_pair : boundary_objects[tid])
579  has_boundary_objects |= !(object_pair.second.empty());
580  return has_boundary_objects;
581 }
582 
583 template <typename T>
584 bool
586 {
588 }
589 
590 template <typename T>
591 bool
593 {
595 }
596 
597 template <typename T>
598 bool
600 {
601  checkThreadID(tid);
602  const auto iter = _active_boundary_objects[tid].find(id);
603  return iter != _active_boundary_objects[tid].end();
604 }
605 
606 template <typename T>
607 bool
608 MooseObjectWarehouseBase<T>::hasActiveObject(const std::string & name, THREAD_ID tid /* = 0*/) const
609 {
610  checkThreadID(tid);
611  for (const auto & object : _active_objects[tid])
612  if (object->name() == name)
613  return true;
614  return false;
615 }
616 
617 template <typename T>
618 std::shared_ptr<T>
619 MooseObjectWarehouseBase<T>::getObject(const std::string & name, THREAD_ID tid /* = 0*/) const
620 {
621  checkThreadID(tid);
622  for (const auto & object : _all_objects[tid])
623  if (object->name() == name)
624  return object;
625  mooseError("Unable to locate object: ", name, ".");
626 }
627 
628 template <typename T>
629 std::shared_ptr<T>
630 MooseObjectWarehouseBase<T>::getActiveObject(const std::string & name, THREAD_ID tid /* = 0*/) const
631 {
632  checkThreadID(tid);
633  for (const auto & object : _active_objects[tid])
634  if (object->name() == name)
635  return object;
636  mooseError("Unable to locate active object: ", name, ".");
637 }
638 
639 template <typename T>
640 const std::vector<std::shared_ptr<T>> &
642  THREAD_ID tid /* = 0*/) const
643 {
644  return libmesh_map_find(_all_variable_objects[tid], var_name);
645 }
646 
647 template <typename T>
648 std::set<SubdomainID>
650 {
651  checkThreadID(tid);
652  std::set<SubdomainID> ids;
653  for (const auto & object_pair : _active_block_objects[tid])
654  ids.insert(object_pair.first);
655  return ids;
656 }
657 
658 template <typename T>
659 void
661 {
662  checkThreadID(tid);
663 
665 
666  for (const auto & object_pair : _all_block_objects[tid])
667  updateActiveHelper(_active_block_objects[tid][object_pair.first], object_pair.second);
668 
669  for (const auto & object_pair : _all_boundary_objects[tid])
670  updateActiveHelper(_active_boundary_objects[tid][object_pair.first], object_pair.second);
671 }
672 
673 template <typename T>
674 void
675 MooseObjectWarehouseBase<T>::updateActiveHelper(std::vector<std::shared_ptr<T>> & active,
676  const std::vector<std::shared_ptr<T>> & all)
677 {
678  // Clear the active list
679  active.clear();
680 
681  std::copy_if(all.begin(),
682  all.end(),
683  std::back_inserter(active),
684  [](const std::shared_ptr<T> & object) { return object->enabled(); });
685 }
686 
687 template <typename T>
688 void
690 {
691  checkThreadID(tid);
692 
693  for (auto & object_pair : _all_block_objects[tid])
694  sortHelper(object_pair.second);
695 
696  for (auto & object_pair : _all_boundary_objects[tid])
697  sortHelper(object_pair.second);
698 
699  sortHelper(_all_objects[tid]);
700 
701  // The active lists now must be update to reflect the order changes
702  updateActive(tid);
703 }
704 
705 template <typename T>
706 void
708  std::set<MooseVariableFieldBase *> & needed_moose_vars, THREAD_ID tid /* = 0*/) const
709 {
710  if (hasActiveObjects(tid))
711  updateVariableDependencyHelper(needed_moose_vars, _active_objects[tid]);
712 }
713 
714 template <typename T>
715 void
717  SubdomainID id,
718  std::set<MooseVariableFieldBase *> & needed_moose_vars,
719  THREAD_ID tid /* = 0*/) const
720 {
721  if (hasActiveBlockObjects(id, tid))
722  updateVariableDependencyHelper(needed_moose_vars, getActiveBlockObjects(id, tid));
723 }
724 
725 template <typename T>
726 void
728  std::set<MooseVariableFieldBase *> & needed_moose_vars, THREAD_ID tid /* = 0*/) const
729 {
730  if (hasActiveBoundaryObjects(tid))
731  {
732  typename std::map<BoundaryID, std::vector<std::shared_ptr<T>>>::const_iterator it;
733  for (const auto & object_pair : _active_boundary_objects[tid])
734  updateVariableDependencyHelper(needed_moose_vars, object_pair.second);
735  }
736 }
737 
738 template <typename T>
739 void
741  BoundaryID id,
742  std::set<MooseVariableFieldBase *> & needed_moose_vars,
743  THREAD_ID tid /* = 0*/) const
744 {
745  if (hasActiveBoundaryObjects(id, tid))
746  updateVariableDependencyHelper(needed_moose_vars, getActiveBoundaryObjects(id, tid));
747 }
748 
749 template <typename T>
750 void
752  std::set<MooseVariableFieldBase *> & needed_moose_vars,
753  const std::vector<std::shared_ptr<T>> & objects)
754 {
755  for (const auto & object : objects)
756  {
757  auto c = dynamic_cast<const MooseVariableDependencyInterface *>(object.get());
758  if (c)
759  {
760  const auto & mv_deps = c->getMooseVariableDependencies();
761  needed_moose_vars.insert(mv_deps.begin(), mv_deps.end());
762  }
763  }
764 }
765 
766 template <typename T>
767 void
769  std::set<TagID> & needed_fe_var_vector_tags, THREAD_ID tid /* = 0*/) const
770 {
771  if (hasActiveObjects(tid))
772  updateFEVariableCoupledVectorTagDependencyHelper(needed_fe_var_vector_tags,
773  _active_objects[tid]);
774 }
775 
776 template <typename T>
777 void
779  SubdomainID id, std::set<TagID> & needed_fe_var_vector_tags, THREAD_ID tid /* = 0*/) const
780 {
781  if (hasActiveBlockObjects(id, tid))
782  updateFEVariableCoupledVectorTagDependencyHelper(needed_fe_var_vector_tags,
783  getActiveBlockObjects(id, tid));
784 }
785 
786 template <typename T>
787 void
789  BoundaryID id, std::set<TagID> & needed_fe_var_vector_tags, THREAD_ID tid /* = 0*/) const
790 {
791  if (hasActiveBoundaryObjects(id, tid))
792  updateFEVariableCoupledVectorTagDependencyHelper(needed_fe_var_vector_tags,
793  getActiveBoundaryObjects(id, tid));
794 }
795 
796 template <typename T>
797 void
799  std::set<TagID> & needed_fe_var_vector_tags, const std::vector<std::shared_ptr<T>> & objects)
800 {
801  for (const auto & object : objects)
802  {
803  auto c = dynamic_cast<const Coupleable *>(object.get());
804  if (c)
805  {
806  const auto & tag_deps = c->getFEVariableCoupleableVectorTags();
807  needed_fe_var_vector_tags.insert(tag_deps.begin(), tag_deps.end());
808  }
809  }
810 }
811 
812 template <typename T>
813 void
815  std::unordered_set<unsigned int> & needed_mat_props,
816  THREAD_ID tid /* = 0*/,
817  const bool producer_only /* = false*/) const
818 {
819  if (hasActiveObjects(tid))
820  updateMatPropDependencyHelper(needed_mat_props, _active_objects[tid], producer_only);
821 }
822 
823 template <typename T>
824 void
826  SubdomainID id,
827  std::unordered_set<unsigned int> & needed_mat_props,
828  THREAD_ID tid /* = 0*/,
829  const bool producer_only /* = false*/) const
830 {
831  if (hasActiveBlockObjects(id, tid))
832  updateMatPropDependencyHelper(needed_mat_props, getActiveBlockObjects(id, tid), producer_only);
833 }
834 
835 template <typename T>
836 void
838  std::unordered_set<unsigned int> & needed_mat_props,
839  THREAD_ID tid /* = 0*/,
840  const bool producer_only /* = false*/) const
841 {
842  if (hasActiveBoundaryObjects(tid))
843  for (auto & active_bnd_object : _active_boundary_objects[tid])
844  updateMatPropDependencyHelper(needed_mat_props, active_bnd_object.second, producer_only);
845 }
846 
847 template <typename T>
848 void
850  BoundaryID id,
851  std::unordered_set<unsigned int> & needed_mat_props,
852  THREAD_ID tid /* = 0*/,
853  const bool producer_only /* = false*/) const
854 {
855  if (hasActiveBoundaryObjects(id, tid))
857  needed_mat_props, getActiveBoundaryObjects(id, tid), producer_only);
858 }
859 
860 template <typename T>
861 void
863  std::unordered_set<unsigned int> & needed_mat_props,
864  const std::vector<std::shared_ptr<T>> & objects,
865  const bool /* producer_only */) const
866 {
867  for (auto & object : objects)
868  {
869  auto c = dynamic_cast<const MaterialPropertyInterface *>(object.get());
870  if (c)
871  {
872  auto & mp_deps = c->getMatPropDependencies();
873  needed_mat_props.insert(mp_deps.begin(), mp_deps.end());
874  }
875  }
876 }
877 
878 template <typename T>
879 void
880 MooseObjectWarehouseBase<T>::subdomainsCovered(std::set<SubdomainID> & subdomains_covered,
881  std::set<std::string> & unique_variables,
882  THREAD_ID tid /*=0*/) const
883 {
884  for (const auto & object : _active_objects[tid])
885  {
886  unique_variables.insert(object->variable().name());
887  const auto additional_variables_covered = object->additionalROVariables();
888  unique_variables.insert(additional_variables_covered.begin(),
889  additional_variables_covered.end());
890  }
891 
892  for (const auto & object_pair : _active_block_objects[tid])
893  subdomains_covered.insert(object_pair.first);
894 }
895 
896 template <typename T>
897 std::string
899  const THREAD_ID tid /*=0*/, const std::string & prefix /*="[DBG]"*/) const
900 {
901  std::vector<std::string> output;
902  for (const auto & object : _active_objects[tid])
903  output.push_back(object->name());
904  return ConsoleUtils::formatString(MooseUtils::join(output, " "), prefix);
905 }
906 
907 template <typename T>
908 void
909 MooseObjectWarehouseBase<T>::sortHelper(std::vector<std::shared_ptr<T>> & objects)
910 {
911  // Do nothing if the vector is empty
912  if (objects.empty())
913  return;
914 
915  try
916  {
917  // Sort based on dependencies
918  DependencyResolverInterface::sort<std::shared_ptr<T>>(objects);
919  }
920  catch (CyclicDependencyException<std::shared_ptr<T>> & e)
921  {
922  DependencyResolverInterface::cyclicDependencyError<std::shared_ptr<T>>(
923  e, "Cyclic dependency detected in object ordering");
924  }
925 }
926 
927 template <typename T>
928 inline void
930 {
931  mooseAssert(tid < _num_threads,
932  "Attempting to access a thread id ("
933  << tid << ") greater than the number allowed by the storage item ("
934  << _num_threads << ")");
935 }
virtual const std::unordered_set< unsigned int > & getMatPropDependencies() const
Retrieve the set of material properties that this object depends on.
std::string name(const ElemQuality q)
void updateVariableDependency(std::set< MooseVariableFieldBase *> &needed_moose_vars, THREAD_ID tid=0) const
Update variable dependency vector.
bool hasBoundaryObjects(THREAD_ID tid=0) const
std::string activeObjectsToFormattedString(THREAD_ID tid=0, const std::string &prefix="[DBG]") const
Output the active content of the warehouse to a string, meant to be output to the console...
void sort(THREAD_ID tid=0)
Sort the objects using the DependencyResolver.
std::string getMooseType(const std::string &name) const
Utility functions for retrieving one of the MooseTypes variables into the common "string" base class...
const std::set< MooseVariableFieldBase * > & getMooseVariableDependencies() const
Retrieve the set of MooseVariableFieldBase that this object depends on.
unsigned int size(THREAD_ID tid=0) const
Return how many kernels we store in the current warehouse.
bool hasObjectsForVariableAndBlocks(const VariableName &var_name, const std::set< SubdomainID > &blocks, std::set< SubdomainID > &blocks_covered, THREAD_ID tid) const
Whether there are objects for this variable and the set of blocks passed.
unsigned int n_threads()
bool hasActiveBlockObjects(THREAD_ID tid=0) const
const std::map< SubdomainID, std::vector< std::shared_ptr< T > > > & getActiveBlockObjects(THREAD_ID tid=0) const
bool hasObjects(THREAD_ID tid=0) const
Convenience functions for determining if objects exist.
char ** blocks
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
std::vector< std::map< SubdomainID, std::vector< std::shared_ptr< T > > > > _all_block_objects
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
std::vector< std::vector< std::shared_ptr< T > > > _all_objects
Storage container for the ALL pointers (THREAD_ID on outer vector)
std::vector< std::map< VariableName, std::vector< std::shared_ptr< T > > > > _all_variable_objects
All objects with a certain variable selected, as the &#39;variable&#39; parameter.
std::vector< std::map< SubdomainID, std::vector< std::shared_ptr< T > > > > _active_block_objects
Active block restricted objects (THREAD_ID on outer vector)
void checkThreadID(THREAD_ID tid) const
Calls assert on thread id.
virtual ~MooseObjectWarehouseBase()
Destructor.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
/class BoundaryRestrictable /brief Provides functionality for limiting the object to certain boundary...
MooseObjectWarehouseBase(bool threaded=true)
Constructor.
std::unique_ptr< T_DEST, T_DELETER > dynamic_pointer_cast(std::unique_ptr< T_SRC, T_DELETER > &src)
These are reworked from https://stackoverflow.com/a/11003103.
This class provides an interface for common operations on field variables of both FE and FV types wit...
MaterialBase objects are special in that they have additional objects created automatically (see FEPr...
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
void updateBlockVariableDependency(SubdomainID id, std::set< MooseVariableFieldBase *> &needed_moose_vars, THREAD_ID tid=0) const
void updateBoundaryFEVariableCoupledVectorTagDependency(BoundaryID id, std::set< TagID > &needed_fe_var_vector_tags, THREAD_ID tid=0) const
static void updateFEVariableCoupledVectorTagDependencyHelper(std::set< TagID > &needed_fe_var_vector_tags, const std::vector< std::shared_ptr< T >> &objects)
Helper method for updating FE variable coupleable vector tag vector.
const std::vector< std::shared_ptr< T > > & getObjectsForVariable(const VariableName &var_name, THREAD_ID tid) const
Getter for objects that have the &#39;variable&#39; set to a particular variable Note that users should check...
bool hasObjectsForVariable(const VariableName &var_name, THREAD_ID tid) const
bool hasActiveBoundaryObjects(THREAD_ID tid=0) const
std::vector< std::map< BoundaryID, std::vector< std::shared_ptr< T > > > > _active_boundary_objects
Active boundary restricted objects (THREAD_ID on outer vector)
const std::vector< std::shared_ptr< T > > & getActiveObjects(THREAD_ID tid=0) const
Retrieve complete vector to the active all/block/boundary restricted objects for a given thread...
virtual void updateMatPropDependencyHelper(std::unordered_set< unsigned int > &needed_mat_props, const std::vector< std::shared_ptr< MaterialBase >> &objects, const bool producer_only) const override
Helper method for updating material property dependency vector.
std::set< SubdomainID > getActiveBlocks(THREAD_ID tid=0) const
Return a set of active SubdomainsIDs.
std::shared_ptr< T > getActiveObject(const std::string &name, THREAD_ID tid=0) const
const std::vector< std::shared_ptr< T > > & getObjects(THREAD_ID tid=0) const
Retrieve complete vector to the all/block/boundary restricted objects for a given thread...
std::shared_ptr< T > getObject(const std::string &name, THREAD_ID tid=0) const
static void sortHelper(std::vector< std::shared_ptr< T >> &objects)
Helper method for sorting vectors of objects.
std::string formatString(std::string message, const std::string &prefix)
Add new lines and prefixes to a string for pretty display in output NOTE: This makes a copy of the st...
Definition: ConsoleUtils.C:583
boundary_id_type BoundaryID
static void updateVariableDependencyHelper(std::set< MooseVariableFieldBase *> &needed_moose_vars, const std::vector< std::shared_ptr< T >> &objects)
Helper method for updating variable dependency vector.
void subdomainsCovered(std::set< SubdomainID > &subdomains_covered, std::set< std::string > &unique_variables, THREAD_ID tid=0) const
Populates a set of covered subdomains and the associated variable names.
const std::map< SubdomainID, std::vector< std::shared_ptr< T > > > & getBlockObjects(THREAD_ID tid=0) const
const std::map< BoundaryID, std::vector< std::shared_ptr< T > > > & getBoundaryObjects(THREAD_ID tid=0) const
virtual const MooseVariableFieldBase & getVariable(const THREAD_ID tid, const std::string &var_name, Moose::VarKindType expected_var_type=Moose::VarKindType::VAR_ANY, Moose::VarFieldType expected_var_field_type=Moose::VarFieldType::VAR_FIELD_ANY) const =0
Returns the variable reference for requested variable which must be of the expected_var_type (Nonline...
std::vector< std::map< BoundaryID, std::vector< std::shared_ptr< T > > > > _all_boundary_objects
void updateBlockMatPropDependency(SubdomainID id, std::unordered_set< unsigned int > &needed_mat_props, THREAD_ID tid=0, const bool producer_only=false) const
const std::map< BoundaryID, std::vector< std::shared_ptr< T > > > & getActiveBoundaryObjects(THREAD_ID tid=0) const
void updateBoundaryMatPropDependency(std::unordered_set< unsigned int > &needed_mat_props, THREAD_ID tid=0, const bool producer_only=false) const
const THREAD_ID _num_threads
Convenience member storing the number of threads used for storage (1 or libMesh::n_threads) ...
Interface for objects that needs coupling capabilities.
Definition: Coupleable.h:52
void updateBlockFEVariableCoupledVectorTagDependency(SubdomainID id, std::set< TagID > &needed_fe_var_vector_tags, THREAD_ID tid=0) const
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:78
bool hasActiveObject(const std::string &name, THREAD_ID tid=0) const
Convenience functions for checking/getting specific objects.
bool hasActiveObjects(THREAD_ID tid=0) const
An interface for accessing Materials.
void updateMatPropDependency(std::unordered_set< unsigned int > &needed_mat_props, THREAD_ID tid=0, const bool producer_only=false) const
Update material property dependency vector.
bool hasBoundaryObjectsHelper(const std::vector< std::map< BoundaryID, std::vector< std::shared_ptr< T >>>> &boundary_objects, const THREAD_ID tid=0) const
Helper for determining whether we have boundary objects.
An interface that restricts an object to subdomains via the &#39;blocks&#39; input parameter.
virtual void addObject(std::shared_ptr< T > object, THREAD_ID tid=0, bool recurse=true)
Adds an object to the storage structure.
void updateFEVariableCoupledVectorTagDependency(std::set< TagID > &needed_fe_var_vector_tags, THREAD_ID tid=0) const
Update FE variable coupleable vector tag vector for all objects, block-restricted objects...
std::vector< std::vector< std::shared_ptr< T > > > _active_objects
All active objects (THREAD_ID on outer vector)
void updateBoundaryVariableDependency(std::set< MooseVariableFieldBase *> &needed_moose_vars, THREAD_ID tid=0) const
std::vector< std::string > getVecMooseType(const std::string &name) const
THREAD_ID numThreads() const
Return the number of threads.
A base storage container for MooseObjects.
std::set< TagID > & getFEVariableCoupleableVectorTags()
Definition: Coupleable.h:120
virtual void updateMatPropDependencyHelper(std::unordered_set< unsigned int > &needed_mat_props, const std::vector< std::shared_ptr< T >> &objects, const bool producer_only) const
Helper method for updating material property dependency vector.
static void updateActiveHelper(std::vector< std::shared_ptr< T >> &active, const std::vector< std::shared_ptr< T >> &all)
Helper method for updating active vectors.
virtual void updateActive(THREAD_ID tid=0)
Updates the active objects storage.
virtual void updateActive(THREAD_ID tid=0) override
Update the active status of Kernels.
unsigned int THREAD_ID
Definition: MooseTypes.h:237
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.