https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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.
 
 DependencyResolverInterface (const DependencyResolverInterface &, const Moose::Kokkos::FunctorCopy &)
 Special constructor used for Kokkos functor copy during parallel dispatch.
 
virtual const std::set< std::string > & getRequestedItems ()=0
 Return a set containing the names of items requested by the object.
 
virtual const std::set< std::string > & getSuppliedItems ()=0
 Return a set containing the names of items owned by the object.
 

Static Public Member Functions

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

Detailed Description

Interface for sorting dependent vectors of objects.

Definition at line 25 of file DependencyResolverInterface.h.

Constructor & Destructor Documentation

◆ DependencyResolverInterface() [1/2]

DependencyResolverInterface::DependencyResolverInterface ( )
inline

Constructor.

Definition at line 31 of file DependencyResolverInterface.h.

31{}

◆ DependencyResolverInterface() [2/2]

DependencyResolverInterface::DependencyResolverInterface ( const DependencyResolverInterface ,
const Moose::Kokkos::FunctorCopy  
)
inline

Special constructor used for Kokkos functor copy during parallel dispatch.

Definition at line 37 of file DependencyResolverInterface.h.

39 {
40 }

Member Function Documentation

◆ cyclicDependencyError() [1/2]

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

Definition at line 151 of file DependencyResolverInterface.h.

153{
154 cyclicDependencyError<T>(e, header, [](const auto & obj) { return static_cast<T>(obj)->name(); });
155}
std::string name(const ElemQuality q)

◆ cyclicDependencyError() [2/2]

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

A helper method for cyclic errors.

Definition at line 134 of file DependencyResolverInterface.h.

137{
138 std::ostringstream oss;
139
140 oss << header << ":\n";
141 const auto cycle = e.getCyclicDependencies();
142 std::vector<std::string> names(cycle.size());
143 for (const auto i : index_range(cycle))
144 names[i] = name_func(cycle[i]);
145 oss << MooseUtils::join(names, " <- ");
146 mooseError(oss.str());
147}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
const std::vector< T > & getCyclicDependencies() const
auto index_range(const T &sizable)

◆ 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 ScalarInitialCondition, AuxKernelBase, AuxScalarKernel, FVInitialConditionBase, InitialConditionBase, Marker, MaterialBase, MFEMExecutedObject, and UserObjectBase.

◆ 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 ScalarInitialCondition, AuxKernelBase, AuxScalarKernel, FVInitialConditionBase, InitialConditionBase, Marker, MaterialBase, MFEMExecutedObject, and UserObjectBase.

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

80{
81 sortDFS(vector);
82}
static void sortDFS(typename std::vector< T > &vector)
Given a vector, sort using the depth-first search.

Referenced by TheWarehouse::prepare().

◆ sortDFS()

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

Given a vector, sort using the depth-first search.

Class that represents the dependency as a graph

Definition at line 86 of file DependencyResolverInterface.h.

87{
88 if (vector.size() <= 1)
89 return;
90
95
96 // Map of suppliers: what is supplied -> by what object
97 std::multimap<std::string, T> suppliers_map;
98 for (auto & v : vector)
99 {
100 // Whether or not this object supplies something, we will always
101 // add it as a node because we want to make sure that it gets returned
102 graph.addNode(v);
103
104 for (const auto & supplied_item : v->getSuppliedItems())
105 suppliers_map.emplace(supplied_item, v);
106 }
107
108 // build the dependency graph
109 for (auto & v : vector)
110 for (const auto & requested_item : v->getRequestedItems())
111 {
112 const auto & [begin_it, end_it] = suppliers_map.equal_range(requested_item);
113 for (const auto & [supplier_name, supplier_object] : as_range(begin_it, end_it))
114 {
115 libmesh_ignore(supplier_name);
116
117 // We allow an object to have a circular dependency within itself; e.g. we choose to
118 // trust a developer knows what they are doing within a single object
119 if (supplier_object != v)
120 graph.addEdge(supplier_object, v);
121 }
122 }
123
124 const auto & sorted = graph.dfs();
125
126 // The set here gets unique objects, as it's valid to pass in duplicates
127 mooseAssert(sorted.size() == std::set<T>(vector.begin(), vector.end()).size(), "Size mismatch");
128
129 vector = sorted;
130}
for(PetscInt i=0;i< nvars;++i)
virtual const std::set< std::string > & getRequestedItems()=0
Return a set containing the names of items requested by the object.
virtual const std::set< std::string > & getSuppliedItems()=0
Return a set containing the names of items owned by the object.
Class that represents the dependecy as a graph.
void addNode(const T &a)
Add a node 'a' to the graph.
const std::vector< T > & dfs()
Do depth-first search from root nodes to obtain order in which graph nodes should be "executed".
void addEdge(const T &a, const T &b)
Add an edge between nodes 'a' and 'b'.
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
void libmesh_ignore(const Args &...)

Referenced by sort().


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