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  std::set<TagID> & needed_fe_var_vector_tags,
165  THREAD_ID tid = 0) const;
167  BoundaryID id, std::set<TagID> & needed_fe_var_vector_tags, THREAD_ID tid = 0) const;
169 
171 
174  void updateMatPropDependency(std::unordered_set<unsigned int> & needed_mat_props,
175  THREAD_ID tid = 0) const;
177  std::unordered_set<unsigned int> & needed_mat_props,
178  THREAD_ID tid = 0) const;
179  void updateBoundaryMatPropDependency(std::unordered_set<unsigned int> & needed_mat_props,
180  THREAD_ID tid = 0) const;
182  std::unordered_set<unsigned int> & needed_mat_props,
183  THREAD_ID tid = 0) const;
185 
189  void subdomainsCovered(std::set<SubdomainID> & subdomains_covered,
190  std::set<std::string> & unique_variables,
191  THREAD_ID tid = 0) const;
192 
196  THREAD_ID numThreads() const { return _num_threads; }
197 
203  std::string activeObjectsToFormattedString(THREAD_ID tid = 0,
204  const std::string & prefix = "[DBG]") const;
205 
206 protected:
209 
211  std::vector<std::vector<std::shared_ptr<T>>> _all_objects;
212 
214  std::vector<std::vector<std::shared_ptr<T>>> _active_objects;
215 
216  // All block restricted objects (THREAD_ID on outer vector)
217  std::vector<std::map<SubdomainID, std::vector<std::shared_ptr<T>>>> _all_block_objects;
218 
220  std::vector<std::map<SubdomainID, std::vector<std::shared_ptr<T>>>> _active_block_objects;
221 
222  // All boundary restricted objects (THREAD_ID on outer vector)
223  std::vector<std::map<BoundaryID, std::vector<std::shared_ptr<T>>>> _all_boundary_objects;
224 
226  std::vector<std::map<BoundaryID, std::vector<std::shared_ptr<T>>>> _active_boundary_objects;
227 
229  std::vector<std::map<VariableName, std::vector<std::shared_ptr<T>>>> _all_variable_objects;
230 
234  static void updateActiveHelper(std::vector<std::shared_ptr<T>> & active,
235  const std::vector<std::shared_ptr<T>> & all);
236 
240  static void sortHelper(std::vector<std::shared_ptr<T>> & objects);
241 
245  static void updateVariableDependencyHelper(std::set<MooseVariableFieldBase *> & needed_moose_vars,
246  const std::vector<std::shared_ptr<T>> & objects);
247 
251  static void
252  updateFEVariableCoupledVectorTagDependencyHelper(std::set<TagID> & needed_fe_var_vector_tags,
253  const std::vector<std::shared_ptr<T>> & objects);
254 
258  static void updateMatPropDependencyHelper(std::unordered_set<unsigned int> & needed_mat_props,
259  const std::vector<std::shared_ptr<T>> & objects);
260 
264  void checkThreadID(THREAD_ID tid) const;
265 
266  friend class MaterialWarehouse;
267 };
268 
269 template <typename T>
271  : _num_threads(threaded ? libMesh::n_threads() : 1),
279 {
280 }
281 
282 template <typename T>
284 {
285 }
286 
287 template <typename T>
288 unsigned int
290 {
291  checkThreadID(tid);
292  return _all_objects[tid].size();
293 }
294 
295 template <typename T>
296 void
297 MooseObjectWarehouseBase<T>::addObject(std::shared_ptr<T> object,
298  THREAD_ID tid /*= 0*/,
299  bool /* recurse = true */)
300 {
301  checkThreadID(tid);
302 
303  // Stores object in list of all objects
304  _all_objects[tid].push_back(object);
305 
306  // If enabled, store object in a list of all active
307  bool enabled = object->enabled();
308  if (enabled)
309  _active_objects[tid].push_back(object);
310 
311  // Perform casts to the Block/BoundaryRestrictable
312  std::shared_ptr<BoundaryRestrictable> bnd =
314  std::shared_ptr<BlockRestrictable> blk = std::dynamic_pointer_cast<BlockRestrictable>(object);
315 
316  // Boundary Restricted
317  if (bnd && bnd->boundaryRestricted())
318  {
319  const std::set<BoundaryID> & ids = bnd->boundaryIDs();
320  for (std::set<BoundaryID>::const_iterator it = ids.begin(); it != ids.end(); ++it)
321  {
322  _all_boundary_objects[tid][*it].push_back(object);
323  if (enabled)
324  _active_boundary_objects[tid][*it].push_back(object);
325  }
326  }
327 
328  // Block Restricted
329  else if (blk)
330  {
331  const std::set<SubdomainID> & ids =
332  blk->blockRestricted() ? blk->blockIDs() : blk->meshBlockIDs();
333  for (std::set<SubdomainID>::const_iterator it = ids.begin(); it != ids.end(); ++it)
334  {
335  _all_block_objects[tid][*it].push_back(object);
336  if (enabled)
337  _active_block_objects[tid][*it].push_back(object);
338  }
339 
340  // Check variables
341  std::shared_ptr<Coupleable> c_ptr = std::dynamic_pointer_cast<Coupleable>(object);
342  if (c_ptr)
343  for (MooseVariableFieldBase * var : c_ptr->getCoupledMooseVars())
344  blk->checkVariable(*var);
345 
346  const InputParameters & parameters = object->parameters();
347 
348  SubProblem & problem = *parameters.get<SubProblem *>("_subproblem");
349 
350  THREAD_ID tid = parameters.get<THREAD_ID>("_tid");
351 
352  if (parameters.isParamValid("variable"))
353  {
354  // Try the scalar version first
355  std::string variable_name = parameters.getMooseType("variable");
356  if (variable_name == "")
357  // When using vector variables, we are only going to use the first one in the list at the
358  // interface level...
359  variable_name = parameters.getVecMooseType("variable")[0];
360 
361  blk->checkVariable(problem.getVariable(
363 
364  _all_variable_objects[tid][variable_name].push_back(object);
365  }
366  }
367 }
368 
369 template <typename T>
370 inline const std::vector<std::shared_ptr<T>> &
372 {
373  checkThreadID(tid);
374  return _all_objects[tid];
375 }
376 
377 template <typename T>
378 inline const std::map<BoundaryID, std::vector<std::shared_ptr<T>>> &
380 {
381  checkThreadID(tid);
382  return _all_boundary_objects[tid];
383 }
384 
385 template <typename T>
386 bool
388 {
389  checkThreadID(tid);
390  return _all_boundary_objects[tid].find(id) != _all_boundary_objects[tid].end();
391 }
392 
393 template <typename T>
394 const std::vector<std::shared_ptr<T>> &
396 {
397  checkThreadID(tid);
398  const auto iter = _all_boundary_objects[tid].find(id);
399  mooseAssert(iter != _all_boundary_objects[tid].end(),
400  "Unable to located active boundary objects for the given id: " << id << ".");
401  return iter->second;
402 }
403 
404 template <typename T>
405 inline const std::map<SubdomainID, std::vector<std::shared_ptr<T>>> &
407 {
408  checkThreadID(tid);
409  return _all_block_objects[tid];
410 }
411 
412 template <typename T>
413 const std::vector<std::shared_ptr<T>> &
415 {
416  checkThreadID(tid);
417  const auto iter = _all_block_objects[tid].find(id);
418  mooseAssert(iter != _all_block_objects[tid].end(),
419  "Unable to located active block objects for the given id: " << id << ".");
420  return iter->second;
421 }
422 
423 template <typename T>
424 inline const std::vector<std::shared_ptr<T>> &
426 {
427  checkThreadID(tid);
428  return _active_objects[tid];
429 }
430 
431 template <typename T>
432 inline const std::map<BoundaryID, std::vector<std::shared_ptr<T>>> &
434 {
435  checkThreadID(tid);
436  return _active_boundary_objects[tid];
437 }
438 
439 template <typename T>
440 const std::vector<std::shared_ptr<T>> &
442 {
443  checkThreadID(tid);
444  const auto iter = _active_boundary_objects[tid].find(id);
445  mooseAssert(iter != _active_boundary_objects[tid].end(),
446  "Unable to located active boundary objects for the given id: " << id << ".");
447  return iter->second;
448 }
449 
450 template <typename T>
451 inline const std::map<SubdomainID, std::vector<std::shared_ptr<T>>> &
453 {
454  checkThreadID(tid);
455  return _active_block_objects[tid];
456 }
457 
458 template <typename T>
459 const std::vector<std::shared_ptr<T>> &
461 {
462  checkThreadID(tid);
463  const auto iter = _active_block_objects[tid].find(id);
464  mooseAssert(iter != _active_block_objects[tid].end(),
465  "Unable to located active block objects for the given id: " << id << ".");
466  return iter->second;
467 }
468 
469 template <typename T>
470 bool
472 {
473  checkThreadID(tid);
474  return !_all_objects[tid].empty();
475 }
476 
477 template <typename T>
478 bool
480 {
481  checkThreadID(tid);
482  return !_active_objects[tid].empty();
483 }
484 
485 template <typename T>
486 bool
488  THREAD_ID tid) const
489 {
490  checkThreadID(tid);
491  return _all_variable_objects[tid].count(var_name);
492 }
493 
494 template <typename T>
495 bool
497  const std::set<SubdomainID> & blocks,
498  std::set<SubdomainID> & blocks_covered,
499  THREAD_ID tid /* = 0*/) const
500 {
501  checkThreadID(tid);
502  blocks_covered.clear();
503  if (!hasObjectsForVariable(var_name, tid))
504  return false;
505 
506  // Check block restriction as a whole
507  for (const auto & object : libmesh_map_find(_all_variable_objects[tid], var_name))
508  {
509  std::shared_ptr<BlockRestrictable> blk = std::dynamic_pointer_cast<BlockRestrictable>(object);
510  if (blk && blk->hasBlocks(blocks))
511  {
512  blocks_covered = blocks;
513  return true;
514  }
515  }
516  // No object has all the blocks, but one might overlap, which could be troublesome.
517  // We'll keep track of which blocks are covered in case several overlap
518  for (const auto & object : libmesh_map_find(_all_variable_objects[tid], var_name))
519  {
520  std::shared_ptr<BlockRestrictable> blk = std::dynamic_pointer_cast<BlockRestrictable>(object);
521  if (blk)
522  for (const auto & block : blocks)
523  if (blk->hasBlocks(block))
524  blocks_covered.insert(block);
525  }
526  // No overlap at all
527  if (blocks_covered.empty())
528  return false;
529 
530  return (blocks == blocks_covered);
531 }
532 
533 template <typename T>
534 bool
536 {
537  checkThreadID(tid);
538  bool has_active_block_objects = false;
539  for (const auto & object_pair : _active_block_objects[tid])
540  has_active_block_objects |= !(object_pair.second.empty());
541  return has_active_block_objects;
542 }
543 
544 template <typename T>
545 bool
547 {
548  checkThreadID(tid);
549  const auto iter = _active_block_objects[tid].find(id);
550  return iter != _active_block_objects[tid].end();
551 }
552 
553 template <typename T>
554 bool
556 {
557  checkThreadID(tid);
558  bool has_active_boundary_objects = false;
559  for (const auto & object_pair : _active_boundary_objects[tid])
560  has_active_boundary_objects |= !(object_pair.second.empty());
561  return has_active_boundary_objects;
562 }
563 
564 template <typename T>
565 bool
567 {
568  checkThreadID(tid);
569  const auto iter = _active_boundary_objects[tid].find(id);
570  return iter != _active_boundary_objects[tid].end();
571 }
572 
573 template <typename T>
574 bool
575 MooseObjectWarehouseBase<T>::hasActiveObject(const std::string & name, THREAD_ID tid /* = 0*/) const
576 {
577  checkThreadID(tid);
578  for (const auto & object : _active_objects[tid])
579  if (object->name() == name)
580  return true;
581  return false;
582 }
583 
584 template <typename T>
585 std::shared_ptr<T>
586 MooseObjectWarehouseBase<T>::getObject(const std::string & name, THREAD_ID tid /* = 0*/) const
587 {
588  checkThreadID(tid);
589  for (const auto & object : _all_objects[tid])
590  if (object->name() == name)
591  return object;
592  mooseError("Unable to locate object: ", name, ".");
593 }
594 
595 template <typename T>
596 std::shared_ptr<T>
597 MooseObjectWarehouseBase<T>::getActiveObject(const std::string & name, THREAD_ID tid /* = 0*/) const
598 {
599  checkThreadID(tid);
600  for (const auto & object : _active_objects[tid])
601  if (object->name() == name)
602  return object;
603  mooseError("Unable to locate active object: ", name, ".");
604 }
605 
606 template <typename T>
607 const std::vector<std::shared_ptr<T>> &
609  THREAD_ID tid /* = 0*/) const
610 {
611  return libmesh_map_find(_all_variable_objects[tid], var_name);
612 }
613 
614 template <typename T>
615 std::set<SubdomainID>
617 {
618  checkThreadID(tid);
619  std::set<SubdomainID> ids;
620  for (const auto & object_pair : _active_block_objects[tid])
621  ids.insert(object_pair.first);
622  return ids;
623 }
624 
625 template <typename T>
626 void
628 {
629  checkThreadID(tid);
630 
632 
633  for (const auto & object_pair : _all_block_objects[tid])
634  updateActiveHelper(_active_block_objects[tid][object_pair.first], object_pair.second);
635 
636  for (const auto & object_pair : _all_boundary_objects[tid])
637  updateActiveHelper(_active_boundary_objects[tid][object_pair.first], object_pair.second);
638 }
639 
640 template <typename T>
641 void
642 MooseObjectWarehouseBase<T>::updateActiveHelper(std::vector<std::shared_ptr<T>> & active,
643  const std::vector<std::shared_ptr<T>> & all)
644 {
645  // Clear the active list
646  active.clear();
647 
648  std::copy_if(all.begin(),
649  all.end(),
650  std::back_inserter(active),
651  [](const std::shared_ptr<T> & object) { return object->enabled(); });
652 }
653 
654 template <typename T>
655 void
657 {
658  checkThreadID(tid);
659 
660  for (auto & object_pair : _all_block_objects[tid])
661  sortHelper(object_pair.second);
662 
663  for (auto & object_pair : _all_boundary_objects[tid])
664  sortHelper(object_pair.second);
665 
666  sortHelper(_all_objects[tid]);
667 
668  // The active lists now must be update to reflect the order changes
669  updateActive(tid);
670 }
671 
672 template <typename T>
673 void
675  std::set<MooseVariableFieldBase *> & needed_moose_vars, THREAD_ID tid /* = 0*/) const
676 {
677  if (hasActiveObjects(tid))
678  updateVariableDependencyHelper(needed_moose_vars, _all_objects[tid]);
679 }
680 
681 template <typename T>
682 void
684  SubdomainID id,
685  std::set<MooseVariableFieldBase *> & needed_moose_vars,
686  THREAD_ID tid /* = 0*/) const
687 {
688  if (hasActiveBlockObjects(id, tid))
689  updateVariableDependencyHelper(needed_moose_vars, getActiveBlockObjects(id, tid));
690 }
691 
692 template <typename T>
693 void
695  std::set<MooseVariableFieldBase *> & needed_moose_vars, THREAD_ID tid /* = 0*/) const
696 {
697  if (hasActiveBoundaryObjects(tid))
698  {
699  typename std::map<BoundaryID, std::vector<std::shared_ptr<T>>>::const_iterator it;
700  for (const auto & object_pair : _active_boundary_objects[tid])
701  updateVariableDependencyHelper(needed_moose_vars, object_pair.second);
702  }
703 }
704 
705 template <typename T>
706 void
708  BoundaryID id,
709  std::set<MooseVariableFieldBase *> & needed_moose_vars,
710  THREAD_ID tid /* = 0*/) const
711 {
712  if (hasActiveBoundaryObjects(id, tid))
713  updateVariableDependencyHelper(needed_moose_vars, getActiveBoundaryObjects(id, tid));
714 }
715 
716 template <typename T>
717 void
719  std::set<MooseVariableFieldBase *> & needed_moose_vars,
720  const std::vector<std::shared_ptr<T>> & objects)
721 {
722  for (const auto & object : objects)
723  {
724  auto c = dynamic_cast<const MooseVariableDependencyInterface *>(object.get());
725  if (c)
726  {
727  const auto & mv_deps = c->getMooseVariableDependencies();
728  needed_moose_vars.insert(mv_deps.begin(), mv_deps.end());
729  }
730  }
731 }
732 
733 template <typename T>
734 void
736  SubdomainID id, std::set<TagID> & needed_fe_var_vector_tags, THREAD_ID tid /* = 0*/) const
737 {
738  if (hasActiveBlockObjects(id, tid))
739  updateFEVariableCoupledVectorTagDependencyHelper(needed_fe_var_vector_tags,
740  getActiveBlockObjects(id, tid));
741 }
742 
743 template <typename T>
744 void
746  BoundaryID id, std::set<TagID> & needed_fe_var_vector_tags, THREAD_ID tid /* = 0*/) const
747 {
748  if (hasActiveBoundaryObjects(id, tid))
749  updateFEVariableCoupledVectorTagDependencyHelper(needed_fe_var_vector_tags,
750  getActiveBoundaryObjects(id, tid));
751 }
752 
753 template <typename T>
754 void
756  std::set<TagID> & needed_fe_var_vector_tags, const std::vector<std::shared_ptr<T>> & objects)
757 {
758  for (const auto & object : objects)
759  {
760  auto c = dynamic_cast<const Coupleable *>(object.get());
761  if (c)
762  {
763  const auto & tag_deps = c->getFEVariableCoupleableVectorTags();
764  needed_fe_var_vector_tags.insert(tag_deps.begin(), tag_deps.end());
765  }
766  }
767 }
768 
769 template <typename T>
770 void
772  std::unordered_set<unsigned int> & needed_mat_props, THREAD_ID tid /* = 0*/) const
773 {
774  if (hasActiveObjects(tid))
775  updateMatPropDependencyHelper(needed_mat_props, _all_objects[tid]);
776 }
777 
778 template <typename T>
779 void
781  SubdomainID id,
782  std::unordered_set<unsigned int> & needed_mat_props,
783  THREAD_ID tid /* = 0*/) const
784 {
785  if (hasActiveBlockObjects(id, tid))
786  updateMatPropDependencyHelper(needed_mat_props, getActiveBlockObjects(id, tid));
787 }
788 
789 template <typename T>
790 void
792  std::unordered_set<unsigned int> & needed_mat_props, THREAD_ID tid /* = 0*/) const
793 {
794  if (hasActiveBoundaryObjects(tid))
795  for (auto & active_bnd_object : _active_boundary_objects[tid])
796  updateMatPropDependencyHelper(needed_mat_props, active_bnd_object.second);
797 }
798 
799 template <typename T>
800 void
802  BoundaryID id,
803  std::unordered_set<unsigned int> & needed_mat_props,
804  THREAD_ID tid /* = 0*/) const
805 {
806  if (hasActiveBoundaryObjects(id, tid))
807  updateMatPropDependencyHelper(needed_mat_props, getActiveBoundaryObjects(id, tid));
808 }
809 
810 template <typename T>
811 void
813  std::unordered_set<unsigned int> & needed_mat_props,
814  const std::vector<std::shared_ptr<T>> & objects)
815 {
816  for (auto & object : objects)
817  {
818  auto c = dynamic_cast<const MaterialPropertyInterface *>(object.get());
819  if (c)
820  {
821  auto & mp_deps = c->getMatPropDependencies();
822  needed_mat_props.insert(mp_deps.begin(), mp_deps.end());
823  }
824  }
825 }
826 
827 template <typename T>
828 void
829 MooseObjectWarehouseBase<T>::subdomainsCovered(std::set<SubdomainID> & subdomains_covered,
830  std::set<std::string> & unique_variables,
831  THREAD_ID tid /*=0*/) const
832 {
833  for (const auto & object : _active_objects[tid])
834  {
835  unique_variables.insert(object->variable().name());
836  const auto additional_variables_covered = object->additionalROVariables();
837  unique_variables.insert(additional_variables_covered.begin(),
838  additional_variables_covered.end());
839  }
840 
841  for (const auto & object_pair : _active_block_objects[tid])
842  subdomains_covered.insert(object_pair.first);
843 }
844 
845 template <typename T>
846 std::string
848  const THREAD_ID tid /*=0*/, const std::string & prefix /*="[DBG]"*/) const
849 {
850  std::vector<std::string> output;
851  for (const auto & object : _active_objects[tid])
852  output.push_back(object->name());
853  return ConsoleUtils::formatString(MooseUtils::join(output, " "), prefix);
854 }
855 
856 template <typename T>
857 void
858 MooseObjectWarehouseBase<T>::sortHelper(std::vector<std::shared_ptr<T>> & objects)
859 {
860  // Do nothing if the vector is empty
861  if (objects.empty())
862  return;
863 
864  try
865  {
866  // Sort based on dependencies
867  DependencyResolverInterface::sort<std::shared_ptr<T>>(objects);
868  }
869  catch (CyclicDependencyException<std::shared_ptr<T>> & e)
870  {
871  DependencyResolverInterface::cyclicDependencyError<std::shared_ptr<T>>(
872  e, "Cyclic dependency detected in object ordering");
873  }
874 }
875 
876 template <typename T>
877 inline void
879 {
880  mooseAssert(tid < _num_threads,
881  "Attempting to access a thread id ("
882  << tid << ") greater than the number allowed by the storage item ("
883  << _num_threads << ")");
884 }
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.
std::string join(Iterator begin, Iterator end, const std::string &delimiter)
Python-like join function for strings over an iterator range.
Definition: MooseUtils.h:142
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:302
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...
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 updateMatPropDependencyHelper(std::unordered_set< unsigned int > &needed_mat_props, const std::vector< std::shared_ptr< T >> &objects)
Helper method for updating material property dependency vector.
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:582
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.
virtual void updateActive(THREAD_ID tid=0)
Update the active status of Kernels.
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 updateBoundaryMatPropDependency(std::unordered_set< unsigned int > &needed_mat_props, THREAD_ID tid=0) const
void updateMatPropDependency(std::unordered_set< unsigned int > &needed_mat_props, THREAD_ID tid=0) const
Update material property dependency vector.
const std::map< BoundaryID, std::vector< std::shared_ptr< T > > > & getActiveBoundaryObjects(THREAD_ID tid=0) 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:45
void updateBlockMatPropDependency(SubdomainID id, std::unordered_set< unsigned int > &needed_mat_props, THREAD_ID tid=0) const
void updateBlockFEVariableCoupledVectorTagDependency(SubdomainID id, std::set< TagID > &needed_fe_var_vector_tags, THREAD_ID tid=0) const
Update FE variable coupleable vector tag vector.
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.
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.
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:106
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.
unsigned int THREAD_ID
Definition: MooseTypes.h:209
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.