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 30 of file DependencyResolverInterface.h.

Constructor & Destructor Documentation

DependencyResolverInterface::DependencyResolverInterface ( )
inline

Constructor.

Definition at line 36 of file DependencyResolverInterface.h.

36 {}

Member Function Documentation

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

A helper method for cyclic errors.

Definition at line 100 of file DependencyResolverInterface.h.

Referenced by DependencyResolverInterface().

102 {
103  std::ostringstream oss;
104 
105  oss << header << ":\n";
106  const typename std::multimap<T, T> & depends = e.getCyclicDependencies();
107  for (typename std::multimap<T, T>::const_iterator it = depends.begin(); it != depends.end(); ++it)
108  oss << (static_cast<T>(it->first))->name() << " -> " << (static_cast<T>(it->second))->name()
109  << "\n";
110  mooseError(oss.str());
111 }
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
const std::multimap< T, T > & getCyclicDependencies() const
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, InitialCondition, AuxKernel, Marker, ScalarInitialCondition, AuxScalarKernel, and GeneralUserObject.

Referenced by DependencyResolverInterface().

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, InitialCondition, AuxKernel, Marker, ScalarInitialCondition, AuxScalarKernel, and GeneralUserObject.

Referenced by DependencyResolverInterface().

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

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

Definition at line 63 of file DependencyResolverInterface.h.

Referenced by DependencyResolverInterface().

64 {
65  DependencyResolver<T> resolver;
66 
67  typename std::vector<T>::iterator start = vector.begin();
68  typename std::vector<T>::iterator end = vector.end();
69 
70  for (typename std::vector<T>::iterator iter = start; iter != end; ++iter)
71  {
72  const std::set<std::string> & requested_items = (*iter)->getRequestedItems();
73 
74  for (typename std::vector<T>::iterator iter2 = start; iter2 != end; ++iter2)
75  {
76  if (iter == iter2)
77  continue;
78 
79  const std::set<std::string> & supplied_items = (*iter2)->getSuppliedItems();
80 
81  std::set<std::string> intersect;
82  std::set_intersection(requested_items.begin(),
83  requested_items.end(),
84  supplied_items.begin(),
85  supplied_items.end(),
86  std::inserter(intersect, intersect.end()));
87 
88  // If the intersection isn't empty then there is a dependency here
89  if (!intersect.empty())
90  resolver.insertDependency(*iter, *iter2);
91  }
92  }
93 
94  // Sort based on dependencies
95  std::stable_sort(start, end, resolver);
96 }
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: