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(BoundaryID id, THREAD_ID tid = 0) const;
101 
108  bool hasObjectsForVariableAndBlocks(const VariableName & var_name,
109  const std::set<SubdomainID> & blocks,
110  std::set<SubdomainID> & blocks_covered,
111  THREAD_ID tid) const;
112 
116  std::set<SubdomainID> getActiveBlocks(THREAD_ID tid = 0) const;
117 
119 
122  bool hasActiveObject(const std::string & name, THREAD_ID tid = 0) const;
123  std::shared_ptr<T> getObject(const std::string & name, THREAD_ID tid = 0) const;
124  std::shared_ptr<T> getActiveObject(const std::string & name, THREAD_ID tid = 0) const;
126 
130  const std::vector<std::shared_ptr<T>> & getObjectsForVariable(const VariableName & var_name,
131  THREAD_ID tid) const;
132 
136  virtual void updateActive(THREAD_ID tid = 0);
137 
141  void sort(THREAD_ID tid = 0);
142 
144 
147  void updateVariableDependency(std::set<MooseVariableFieldBase *> & needed_moose_vars,
148  THREAD_ID tid = 0) const;
150  std::set<MooseVariableFieldBase *> & needed_moose_vars,
151  THREAD_ID tid = 0) const;
152  void updateBoundaryVariableDependency(std::set<MooseVariableFieldBase *> & needed_moose_vars,
153  THREAD_ID tid = 0) const;
155  std::set<MooseVariableFieldBase *> & needed_moose_vars,
156  THREAD_ID tid = 0) const;
158 
160 
164  void updateFEVariableCoupledVectorTagDependency(std::set<TagID> & needed_fe_var_vector_tags,
165  THREAD_ID tid = 0) const;
167  std::set<TagID> & needed_fe_var_vector_tags,
168  THREAD_ID tid = 0) const;
170  BoundaryID id, std::set<TagID> & needed_fe_var_vector_tags, THREAD_ID tid = 0) const;
172 
174 
178  void updateMatPropDependency(std::unordered_set<unsigned int> & needed_mat_props,
179  THREAD_ID tid = 0,
180  const bool producer_only = false) const;
182  std::unordered_set<unsigned int> & needed_mat_props,
183  THREAD_ID tid = 0,
184  const bool producer_only = false) const;
185  void updateBoundaryMatPropDependency(std::unordered_set<unsigned int> & needed_mat_props,
186  THREAD_ID tid = 0,
187  const bool producer_only = false) const;
189  std::unordered_set<unsigned int> & needed_mat_props,
190  THREAD_ID tid = 0,
191  const bool producer_only = false) const;
193 
197  void subdomainsCovered(std::set<SubdomainID> & subdomains_covered,
198  std::set<std::string> & unique_variables,
199  THREAD_ID tid = 0) const;
200 
204  THREAD_ID numThreads() const { return _num_threads; }
205 
211  std::string activeObjectsToFormattedString(THREAD_ID tid = 0,
212  const std::string & prefix = "[DBG]") const;
213 
214 protected:
217 
219  std::vector<std::vector<std::shared_ptr<T>>> _all_objects;
220 
222  std::vector<std::vector<std::shared_ptr<T>>> _active_objects;
223 
224  // All block restricted objects (THREAD_ID on outer vector)
225  std::vector<std::map<SubdomainID, std::vector<std::shared_ptr<T>>>> _all_block_objects;
226 
228  std::vector<std::map<SubdomainID, std::vector<std::shared_ptr<T>>>> _active_block_objects;
229 
230  // All boundary restricted objects (THREAD_ID on outer vector)
231  std::vector<std::map<BoundaryID, std::vector<std::shared_ptr<T>>>> _all_boundary_objects;
232 
234  std::vector<std::map<BoundaryID, std::vector<std::shared_ptr<T>>>> _active_boundary_objects;
235 
237  std::vector<std::map<VariableName, std::vector<std::shared_ptr<T>>>> _all_variable_objects;
238 
242  static void updateActiveHelper(std::vector<std::shared_ptr<T>> & active,
243  const std::vector<std::shared_ptr<T>> & all);
244 
248  static void sortHelper(std::vector<std::shared_ptr<T>> & objects);
249 
253  static void updateVariableDependencyHelper(std::set<MooseVariableFieldBase *> & needed_moose_vars,
254  const std::vector<std::shared_ptr<T>> & objects);
255 
259  static void
260  updateFEVariableCoupledVectorTagDependencyHelper(std::set<TagID> & needed_fe_var_vector_tags,
261  const std::vector<std::shared_ptr<T>> & objects);
262 
266  virtual void updateMatPropDependencyHelper(std::unordered_set<unsigned int> & needed_mat_props,
267  const std::vector<std::shared_ptr<T>> & objects,
268  const bool producer_only) const;
269 
273  void checkThreadID(THREAD_ID tid) const;
274 
275  friend class MaterialWarehouse;
276 };
277 
278 template <typename T>
280  : _num_threads(threaded ? libMesh::n_threads() : 1),
288 {
289 }
290 
291 template <typename T>
293 {
294 }
295 
296 template <typename T>
297 unsigned int
299 {
300  checkThreadID(tid);
301  return _all_objects[tid].size();
302 }
303 
304 template <typename T>
305 void
306 MooseObjectWarehouseBase<T>::addObject(std::shared_ptr<T> object,
307  THREAD_ID tid /*= 0*/,
308  bool /* recurse = true */)
309 {
310  checkThreadID(tid);
311 
312  // Stores object in list of all objects
313  _all_objects[tid].push_back(object);
314 
315  // If enabled, store object in a list of all active
316  bool enabled = object->enabled();
317  if (enabled)
318  _active_objects[tid].push_back(object);
319 
320  // Perform casts to the Block/BoundaryRestrictable
321  std::shared_ptr<BoundaryRestrictable> bnd =
323  std::shared_ptr<BlockRestrictable> blk = std::dynamic_pointer_cast<BlockRestrictable>(object);
324 
325  // Boundary Restricted
326  if (bnd && bnd->boundaryRestricted())
327  {
328  const std::set<BoundaryID> & ids = bnd->boundaryIDs();
329  for (std::set<BoundaryID>::const_iterator it = ids.begin(); it != ids.end(); ++it)
330  {
331  _all_boundary_objects[tid][*it].push_back(object);
332  if (enabled)
333  _active_boundary_objects[tid][*it].push_back(object);
334  }
335  }
336 
337  // Block Restricted
338  else if (blk)
339  {
340  const std::set<SubdomainID> & ids =
341  blk->blockRestricted() ? blk->blockIDs() : blk->meshBlockIDs();
342  for (std::set<SubdomainID>::const_iterator it = ids.begin(); it != ids.end(); ++it)
343  {
344  _all_block_objects[tid][*it].push_back(object);
345  if (enabled)
346  _active_block_objects[tid][*it].push_back(object);
347  }
348 
349  // Check variables
350  std::shared_ptr<Coupleable> c_ptr = std::dynamic_pointer_cast<Coupleable>(object);
351  if (c_ptr)
352  for (MooseVariableFieldBase * var : c_ptr->getCoupledMooseVars())
353  blk->checkVariable(*var);
354 
355  const InputParameters & parameters = object->parameters();
356 
357  SubProblem & problem = *parameters.get<SubProblem *>("_subproblem");
358 
359  THREAD_ID tid = parameters.get<THREAD_ID>("_tid");
360 
361  if (parameters.isParamValid("variable"))
362  {
363  // Try the scalar version first
364  std::string variable_name = parameters.getMooseType("variable");
365  if (variable_name == "")
366  // When using vector variables, we are only going to use the first one in the list at the
367  // interface level...
368  variable_name = parameters.getVecMooseType("variable")[0];
369 
370  blk->checkVariable(problem.getVariable(
372 
373  _all_variable_objects[tid][variable_name].push_back(object);
374  }
375  }
376 }
377 
378 template <typename T>
379 inline const std::vector<std::shared_ptr<T>> &
381 {
382  checkThreadID(tid);
383  return _all_objects[tid];
384 }
385 
386 template <typename T>
387 inline const std::map<BoundaryID, std::vector<std::shared_ptr<T>>> &
389 {
390  checkThreadID(tid);
391  return _all_boundary_objects[tid];
392 }
393 
394 template <typename T>
395 bool
397 {
398  checkThreadID(tid);
399  return _all_boundary_objects[tid].find(id) != _all_boundary_objects[tid].end();
400 }
401 
402 template <typename T>
403 const std::vector<std::shared_ptr<T>> &
405 {
406  checkThreadID(tid);
407  const auto iter = _all_boundary_objects[tid].find(id);
408  mooseAssert(iter != _all_boundary_objects[tid].end(),
409  "Unable to located active boundary objects for the given id: " << id << ".");
410  return iter->second;
411 }
412 
413 template <typename T>
414 inline const std::map<SubdomainID, std::vector<std::shared_ptr<T>>> &
416 {
417  checkThreadID(tid);
418  return _all_block_objects[tid];
419 }
420 
421 template <typename T>
422 const std::vector<std::shared_ptr<T>> &
424 {
425  checkThreadID(tid);
426  const auto iter = _all_block_objects[tid].find(id);
427  mooseAssert(iter != _all_block_objects[tid].end(),
428  "Unable to located active block objects for the given id: " << id << ".");
429  return iter->second;
430 }
431 
432 template <typename T>
433 inline const std::vector<std::shared_ptr<T>> &
435 {
436  checkThreadID(tid);
437  return _active_objects[tid];
438 }
439 
440 template <typename T>
441 inline const std::map<BoundaryID, std::vector<std::shared_ptr<T>>> &
443 {
444  checkThreadID(tid);
445  return _active_boundary_objects[tid];
446 }
447 
448 template <typename T>
449 const std::vector<std::shared_ptr<T>> &
451 {
452  checkThreadID(tid);
453  const auto iter = _active_boundary_objects[tid].find(id);
454  mooseAssert(iter != _active_boundary_objects[tid].end(),
455  "Unable to located active boundary objects for the given id: " << id << ".");
456  return iter->second;
457 }
458 
459 template <typename T>
460 inline const std::map<SubdomainID, std::vector<std::shared_ptr<T>>> &
462 {
463  checkThreadID(tid);
464  return _active_block_objects[tid];
465 }
466 
467 template <typename T>
468 const std::vector<std::shared_ptr<T>> &
470 {
471  checkThreadID(tid);
472  const auto iter = _active_block_objects[tid].find(id);
473  mooseAssert(iter != _active_block_objects[tid].end(),
474  "Unable to located active block objects for the given id: " << id << ".");
475  return iter->second;
476 }
477 
478 template <typename T>
479 bool
481 {
482  checkThreadID(tid);
483  return !_all_objects[tid].empty();
484 }
485 
486 template <typename T>
487 bool
489 {
490  checkThreadID(tid);
491  return !_active_objects[tid].empty();
492 }
493 
494 template <typename T>
495 bool
497  THREAD_ID tid) const
498 {
499  checkThreadID(tid);
500  return _all_variable_objects[tid].count(var_name);
501 }
502 
503 template <typename T>
504 bool
506  const std::set<SubdomainID> & blocks,
507  std::set<SubdomainID> & blocks_covered,
508  THREAD_ID tid /* = 0*/) const
509 {
510  checkThreadID(tid);
511  blocks_covered.clear();
512  if (!hasObjectsForVariable(var_name, tid))
513  return false;
514 
515  // Check block restriction as a whole
516  for (const auto & object : libmesh_map_find(_all_variable_objects[tid], var_name))
517  {
518  std::shared_ptr<BlockRestrictable> blk = std::dynamic_pointer_cast<BlockRestrictable>(object);
519  if (blk && blk->hasBlocks(blocks))
520  {
521  blocks_covered = blocks;
522  return true;
523  }
524  }
525  // No object has all the blocks, but one might overlap, which could be troublesome.
526  // We'll keep track of which blocks are covered in case several overlap
527  for (const auto & object : libmesh_map_find(_all_variable_objects[tid], var_name))
528  {
529  std::shared_ptr<BlockRestrictable> blk = std::dynamic_pointer_cast<BlockRestrictable>(object);
530  if (blk)
531  for (const auto & block : blocks)
532  if (blk->hasBlocks(block))
533  blocks_covered.insert(block);
534  }
535  // No overlap at all
536  if (blocks_covered.empty())
537  return false;
538 
539  return (blocks == blocks_covered);
540 }
541 
542 template <typename T>
543 bool
545 {
546  checkThreadID(tid);
547  bool has_active_block_objects = false;
548  for (const auto & object_pair : _active_block_objects[tid])
549  has_active_block_objects |= !(object_pair.second.empty());
550  return has_active_block_objects;
551 }
552 
553 template <typename T>
554 bool
556 {
557  checkThreadID(tid);
558  const auto iter = _active_block_objects[tid].find(id);
559  return iter != _active_block_objects[tid].end();
560 }
561 
562 template <typename T>
563 bool
565 {
566  checkThreadID(tid);
567  bool has_active_boundary_objects = false;
568  for (const auto & object_pair : _active_boundary_objects[tid])
569  has_active_boundary_objects |= !(object_pair.second.empty());
570  return has_active_boundary_objects;
571 }
572 
573 template <typename T>
574 bool
576 {
577  checkThreadID(tid);
578  const auto iter = _active_boundary_objects[tid].find(id);
579  return iter != _active_boundary_objects[tid].end();
580 }
581 
582 template <typename T>
583 bool
584 MooseObjectWarehouseBase<T>::hasActiveObject(const std::string & name, THREAD_ID tid /* = 0*/) const
585 {
586  checkThreadID(tid);
587  for (const auto & object : _active_objects[tid])
588  if (object->name() == name)
589  return true;
590  return false;
591 }
592 
593 template <typename T>
594 std::shared_ptr<T>
595 MooseObjectWarehouseBase<T>::getObject(const std::string & name, THREAD_ID tid /* = 0*/) const
596 {
597  checkThreadID(tid);
598  for (const auto & object : _all_objects[tid])
599  if (object->name() == name)
600  return object;
601  mooseError("Unable to locate object: ", name, ".");
602 }
603 
604 template <typename T>
605 std::shared_ptr<T>
606 MooseObjectWarehouseBase<T>::getActiveObject(const std::string & name, THREAD_ID tid /* = 0*/) const
607 {
608  checkThreadID(tid);
609  for (const auto & object : _active_objects[tid])
610  if (object->name() == name)
611  return object;
612  mooseError("Unable to locate active object: ", name, ".");
613 }
614 
615 template <typename T>
616 const std::vector<std::shared_ptr<T>> &
618  THREAD_ID tid /* = 0*/) const
619 {
620  return libmesh_map_find(_all_variable_objects[tid], var_name);
621 }
622 
623 template <typename T>
624 std::set<SubdomainID>
626 {
627  checkThreadID(tid);
628  std::set<SubdomainID> ids;
629  for (const auto & object_pair : _active_block_objects[tid])
630  ids.insert(object_pair.first);
631  return ids;
632 }
633 
634 template <typename T>
635 void
637 {
638  checkThreadID(tid);
639 
641 
642  for (const auto & object_pair : _all_block_objects[tid])
643  updateActiveHelper(_active_block_objects[tid][object_pair.first], object_pair.second);
644 
645  for (const auto & object_pair : _all_boundary_objects[tid])
646  updateActiveHelper(_active_boundary_objects[tid][object_pair.first], object_pair.second);
647 }
648 
649 template <typename T>
650 void
651 MooseObjectWarehouseBase<T>::updateActiveHelper(std::vector<std::shared_ptr<T>> & active,
652  const std::vector<std::shared_ptr<T>> & all)
653 {
654  // Clear the active list
655  active.clear();
656 
657  std::copy_if(all.begin(),
658  all.end(),
659  std::back_inserter(active),
660  [](const std::shared_ptr<T> & object) { return object->enabled(); });
661 }
662 
663 template <typename T>
664 void
666 {
667  checkThreadID(tid);
668 
669  for (auto & object_pair : _all_block_objects[tid])
670  sortHelper(object_pair.second);
671 
672  for (auto & object_pair : _all_boundary_objects[tid])
673  sortHelper(object_pair.second);
674 
675  sortHelper(_all_objects[tid]);
676 
677  // The active lists now must be update to reflect the order changes
678  updateActive(tid);
679 }
680 
681 template <typename T>
682 void
684  std::set<MooseVariableFieldBase *> & needed_moose_vars, THREAD_ID tid /* = 0*/) const
685 {
686  if (hasActiveObjects(tid))
687  updateVariableDependencyHelper(needed_moose_vars, _active_objects[tid]);
688 }
689 
690 template <typename T>
691 void
693  SubdomainID id,
694  std::set<MooseVariableFieldBase *> & needed_moose_vars,
695  THREAD_ID tid /* = 0*/) const
696 {
697  if (hasActiveBlockObjects(id, tid))
698  updateVariableDependencyHelper(needed_moose_vars, getActiveBlockObjects(id, tid));
699 }
700 
701 template <typename T>
702 void
704  std::set<MooseVariableFieldBase *> & needed_moose_vars, THREAD_ID tid /* = 0*/) const
705 {
706  if (hasActiveBoundaryObjects(tid))
707  {
708  typename std::map<BoundaryID, std::vector<std::shared_ptr<T>>>::const_iterator it;
709  for (const auto & object_pair : _active_boundary_objects[tid])
710  updateVariableDependencyHelper(needed_moose_vars, object_pair.second);
711  }
712 }
713 
714 template <typename T>
715 void
717  BoundaryID id,
718  std::set<MooseVariableFieldBase *> & needed_moose_vars,
719  THREAD_ID tid /* = 0*/) const
720 {
721  if (hasActiveBoundaryObjects(id, tid))
722  updateVariableDependencyHelper(needed_moose_vars, getActiveBoundaryObjects(id, tid));
723 }
724 
725 template <typename T>
726 void
728  std::set<MooseVariableFieldBase *> & needed_moose_vars,
729  const std::vector<std::shared_ptr<T>> & objects)
730 {
731  for (const auto & object : objects)
732  {
733  auto c = dynamic_cast<const MooseVariableDependencyInterface *>(object.get());
734  if (c)
735  {
736  const auto & mv_deps = c->getMooseVariableDependencies();
737  needed_moose_vars.insert(mv_deps.begin(), mv_deps.end());
738  }
739  }
740 }
741 
742 template <typename T>
743 void
745  std::set<TagID> & needed_fe_var_vector_tags, THREAD_ID tid /* = 0*/) const
746 {
747  if (hasActiveObjects(tid))
748  updateFEVariableCoupledVectorTagDependencyHelper(needed_fe_var_vector_tags,
749  _active_objects[tid]);
750 }
751 
752 template <typename T>
753 void
755  SubdomainID id, std::set<TagID> & needed_fe_var_vector_tags, THREAD_ID tid /* = 0*/) const
756 {
757  if (hasActiveBlockObjects(id, tid))
758  updateFEVariableCoupledVectorTagDependencyHelper(needed_fe_var_vector_tags,
759  getActiveBlockObjects(id, tid));
760 }
761 
762 template <typename T>
763 void
765  BoundaryID id, std::set<TagID> & needed_fe_var_vector_tags, THREAD_ID tid /* = 0*/) const
766 {
767  if (hasActiveBoundaryObjects(id, tid))
768  updateFEVariableCoupledVectorTagDependencyHelper(needed_fe_var_vector_tags,
769  getActiveBoundaryObjects(id, tid));
770 }
771 
772 template <typename T>
773 void
775  std::set<TagID> & needed_fe_var_vector_tags, const std::vector<std::shared_ptr<T>> & objects)
776 {
777  for (const auto & object : objects)
778  {
779  auto c = dynamic_cast<const Coupleable *>(object.get());
780  if (c)
781  {
782  const auto & tag_deps = c->getFEVariableCoupleableVectorTags();
783  needed_fe_var_vector_tags.insert(tag_deps.begin(), tag_deps.end());
784  }
785  }
786 }
787 
788 template <typename T>
789 void
791  std::unordered_set<unsigned int> & needed_mat_props,
792  THREAD_ID tid /* = 0*/,
793  const bool producer_only /* = false*/) const
794 {
795  if (hasActiveObjects(tid))
796  updateMatPropDependencyHelper(needed_mat_props, _active_objects[tid], producer_only);
797 }
798 
799 template <typename T>
800 void
802  SubdomainID id,
803  std::unordered_set<unsigned int> & needed_mat_props,
804  THREAD_ID tid /* = 0*/,
805  const bool producer_only /* = false*/) const
806 {
807  if (hasActiveBlockObjects(id, tid))
808  updateMatPropDependencyHelper(needed_mat_props, getActiveBlockObjects(id, tid), producer_only);
809 }
810 
811 template <typename T>
812 void
814  std::unordered_set<unsigned int> & needed_mat_props,
815  THREAD_ID tid /* = 0*/,
816  const bool producer_only /* = false*/) const
817 {
818  if (hasActiveBoundaryObjects(tid))
819  for (auto & active_bnd_object : _active_boundary_objects[tid])
820  updateMatPropDependencyHelper(needed_mat_props, active_bnd_object.second, producer_only);
821 }
822 
823 template <typename T>
824 void
826  BoundaryID 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 (hasActiveBoundaryObjects(id, tid))
833  needed_mat_props, getActiveBoundaryObjects(id, tid), producer_only);
834 }
835 
836 template <typename T>
837 void
839  std::unordered_set<unsigned int> & needed_mat_props,
840  const std::vector<std::shared_ptr<T>> & objects,
841  const bool /* producer_only */) const
842 {
843  for (auto & object : objects)
844  {
845  auto c = dynamic_cast<const MaterialPropertyInterface *>(object.get());
846  if (c)
847  {
848  auto & mp_deps = c->getMatPropDependencies();
849  needed_mat_props.insert(mp_deps.begin(), mp_deps.end());
850  }
851  }
852 }
853 
854 template <typename T>
855 void
856 MooseObjectWarehouseBase<T>::subdomainsCovered(std::set<SubdomainID> & subdomains_covered,
857  std::set<std::string> & unique_variables,
858  THREAD_ID tid /*=0*/) const
859 {
860  for (const auto & object : _active_objects[tid])
861  {
862  unique_variables.insert(object->variable().name());
863  const auto additional_variables_covered = object->additionalROVariables();
864  unique_variables.insert(additional_variables_covered.begin(),
865  additional_variables_covered.end());
866  }
867 
868  for (const auto & object_pair : _active_block_objects[tid])
869  subdomains_covered.insert(object_pair.first);
870 }
871 
872 template <typename T>
873 std::string
875  const THREAD_ID tid /*=0*/, const std::string & prefix /*="[DBG]"*/) const
876 {
877  std::vector<std::string> output;
878  for (const auto & object : _active_objects[tid])
879  output.push_back(object->name());
880  return ConsoleUtils::formatString(MooseUtils::join(output, " "), prefix);
881 }
882 
883 template <typename T>
884 void
885 MooseObjectWarehouseBase<T>::sortHelper(std::vector<std::shared_ptr<T>> & objects)
886 {
887  // Do nothing if the vector is empty
888  if (objects.empty())
889  return;
890 
891  try
892  {
893  // Sort based on dependencies
894  DependencyResolverInterface::sort<std::shared_ptr<T>>(objects);
895  }
896  catch (CyclicDependencyException<std::shared_ptr<T>> & e)
897  {
898  DependencyResolverInterface::cyclicDependencyError<std::shared_ptr<T>>(
899  e, "Cyclic dependency detected in object ordering");
900  }
901 }
902 
903 template <typename T>
904 inline void
906 {
907  mooseAssert(tid < _num_threads,
908  "Attempting to access a thread id ("
909  << tid << ") greater than the number allowed by the storage item ("
910  << _num_threads << ")");
911 }
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.
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.
bool hasBoundaryObjects(BoundaryID id, THREAD_ID tid=0) const
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.
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.