www.mooseframework.org
Public Member Functions | Static Public Member Functions | List of all members
DependencyResolverInterface Class Referenceabstract

Interface for sorting dependent vectors of objects. More...

#include <DependencyResolverInterface.h>

Inheritance diagram for DependencyResolverInterface:
[legend]

Public Member Functions

 DependencyResolverInterface ()
 Constructor. More...
 
virtual const std::set< std::string > & getRequestedItems ()=0
 Return a set containing the names of items requested by the object. More...
 
virtual const std::set< std::string > & getSuppliedItems ()=0
 Return a set containing the names of items owned by the object. More...
 

Static Public Member Functions

template<typename T >
static void sort (typename std::vector< T > &vector)
 Given a vector, sort using the getRequested/SuppliedItems sets. More...
 
template<typename T >
static void cyclicDependencyError (CyclicDependencyException< T > &e, const std::string &header)
 A helper method for cyclic errors. More...
 

Detailed Description

Interface for sorting dependent vectors of objects.

Definition at line 25 of file DependencyResolverInterface.h.

Constructor & Destructor Documentation

◆ DependencyResolverInterface()

DependencyResolverInterface::DependencyResolverInterface ( )
inline

Constructor.

Definition at line 31 of file DependencyResolverInterface.h.

31 {}

Member Function Documentation

◆ cyclicDependencyError()

template<typename T >
void DependencyResolverInterface::cyclicDependencyError ( CyclicDependencyException< T > &  e,
const std::string &  header 
)
static

A helper method for cyclic errors.

Definition at line 95 of file DependencyResolverInterface.h.

97 {
98  std::ostringstream oss;
99 
100  oss << header << ":\n";
101  const typename std::multimap<T, T> & depends = e.getCyclicDependencies();
102  for (typename std::multimap<T, T>::const_iterator it = depends.begin(); it != depends.end(); ++it)
103  oss << (static_cast<T>(it->first))->name() << " -> " << (static_cast<T>(it->second))->name()
104  << "\n";
105  mooseError(oss.str());
106 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
const std::multimap< T, T > & getCyclicDependencies() const

◆ getRequestedItems()

virtual const std::set<std::string>& DependencyResolverInterface::getRequestedItems ( )
pure virtual

Return a set containing the names of items requested by the object.

Implemented in Material, AuxKernel, InitialConditionBase, Marker, ScalarInitialCondition, AuxScalarKernel, and GeneralUserObject.

◆ getSuppliedItems()

virtual const std::set<std::string>& DependencyResolverInterface::getSuppliedItems ( )
pure virtual

Return a set containing the names of items owned by the object.

Implemented in Material, AuxKernel, InitialConditionBase, Marker, ScalarInitialCondition, AuxScalarKernel, and GeneralUserObject.

◆ sort()

template<typename T >
void DependencyResolverInterface::sort ( typename std::vector< T > &  vector)
static

Given a vector, sort using the getRequested/SuppliedItems sets.

Definition at line 58 of file DependencyResolverInterface.h.

Referenced by TheWarehouse::prepare().

59 {
60  DependencyResolver<T> resolver;
61 
62  typename std::vector<T>::iterator start = vector.begin();
63  typename std::vector<T>::iterator end = vector.end();
64 
65  for (typename std::vector<T>::iterator iter = start; iter != end; ++iter)
66  {
67  const std::set<std::string> & requested_items = (*iter)->getRequestedItems();
68 
69  for (typename std::vector<T>::iterator iter2 = start; iter2 != end; ++iter2)
70  {
71  if (iter == iter2)
72  continue;
73 
74  const std::set<std::string> & supplied_items = (*iter2)->getSuppliedItems();
75 
76  std::set<std::string> intersect;
77  std::set_intersection(requested_items.begin(),
78  requested_items.end(),
79  supplied_items.begin(),
80  supplied_items.end(),
81  std::inserter(intersect, intersect.end()));
82 
83  // If the intersection isn't empty then there is a dependency here
84  if (!intersect.empty())
85  resolver.insertDependency(*iter, *iter2);
86  }
87  }
88 
89  // Sort based on dependencies
90  std::stable_sort(start, end, resolver);
91 }
void insertDependency(const T &key, const T &value)
Insert a dependency pair - the first value or the "key" depends on the second value or the "value"...

The documentation for this class was generated from the following file: