https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
TheWarehouse::QueryCache< Attribs > Class Template Reference

QueryCache is a convenient way to construct and pass around (possible partially constructed) warehouse queries. More...

#include <TheWarehouse.h>

Public Types

typedef std::tuple< KeyType< Attribs >... > KeyTuple
 
typedef std::tuple< AttribType< Attribs >... > AttribTuple
 

Public Member Functions

 QueryCache ()
 
 QueryCache (TheWarehouse &w)
 Creates a new query operating on the given warehouse w.
 
template<typename T >
 QueryCache (const T &q)
 
QueryCacheoperator= (const QueryCache &other)
 
template<typename T >
QueryCacheoperator= (const T &q)
 Copy constructor from another Query.
 
 QueryCache (const QueryCache &other)
 
template<typename T , typename... Args>
QueryCachecondition (Args &&... args)
 Adds a new condition to the query.
 
QueryCache clone () const
 clone creates and returns an independent copy of the query in its current state.
 
std::size_t count ()
 count returns the number of results that match the query (this requires actually running the query).
 
TheWarehousewarehouse () const
 
std::vector< std::unique_ptr< Attribute > > attributes () const
 attribs returns a copy of the constructed Attribute list for the query in its current state.
 
template<typename T , typename... Args>
std::vector< T * > & queryInto (std::vector< T * > &results, Args &&... args)
 queryInto executes the query and stores the results in the given vector.
 
template<typename T , typename... Args>
std::vector< T * > & queryIntoUnsorted (std::vector< T * > &results, Args &&... args)
 queryInto executes the query and stores the results in the given vector.
 
std::size_t numAttribs () const
 Gets the number of attributes associated with the cached query.
 

Private Member Functions

template<typename T , typename... Args>
std::vector< T * > & queryIntoHelper (std::vector< T * > &results, const bool sort, Args &&... args)
 queryInto executes the query and stores the results in the given vector.
 
template<int Index, typename A , typename... As>
void addAttribs ()
 
template<int Index>
void addAttribs ()
 
template<int Index, typename K , typename... Args>
void setKeysInner (K &k, Args &... args)
 
template<int Index>
void setKeysInner ()
 
template<int Index, typename K , typename... Args>
void setAttribsInner (K k, Args &... args)
 
template<int Index>
void setAttribsInner ()
 

Private Attributes

TheWarehouse_w = nullptr
 
std::vector< std::unique_ptr< Attribute > > _attribs
 
KeyTuple _key_tup
 
AttribTuple _attrib_tup
 
std::map< std::pair< bool, KeyTuple >, std::size_t > _cache
 
std::mutex _cache_mutex
 

Detailed Description

template<typename... Attribs>
class TheWarehouse::QueryCache< Attribs >

QueryCache is a convenient way to construct and pass around (possible partially constructed) warehouse queries.

The warehouse's "query()" or "queryCache(...)" functions should generally be used to create new Query objects rather than constructing them directly. A Query object holds a list of persistent conditions used to filter/select objects from the warehouse. When the query is executed/run, results are filtered by "and"ing each condition together - i.e. only objects that match all conditions are returned.

Template arguments (i.e. Attribs) are used to specify parametrized query conditions. The passed template parameters should be the Attribute classes you want to use for parameterization (i.e. the values that will change from query to query).

Definition at line 209 of file TheWarehouse.h.

Member Typedef Documentation

◆ AttribTuple

template<typename... Attribs>
typedef std::tuple<AttribType<Attribs>...> TheWarehouse::QueryCache< Attribs >::AttribTuple

Definition at line 213 of file TheWarehouse.h.

◆ KeyTuple

template<typename... Attribs>
typedef std::tuple<KeyType<Attribs>...> TheWarehouse::QueryCache< Attribs >::KeyTuple

Definition at line 212 of file TheWarehouse.h.

Constructor & Destructor Documentation

◆ QueryCache() [1/4]

template<typename... Attribs>
TheWarehouse::QueryCache< Attribs >::QueryCache ( )
inline

Definition at line 215 of file TheWarehouse.h.

215{}

◆ QueryCache() [2/4]

template<typename... Attribs>
TheWarehouse::QueryCache< Attribs >::QueryCache ( TheWarehouse w)
inline

Creates a new query operating on the given warehouse w.

You should generally use TheWarehouse::query() instead.

Definition at line 219 of file TheWarehouse.h.

219 : _w(&w)
220 {
221 addAttribs<0, Attribs...>();
222 _attribs.reserve(5);
223 }
std::vector< std::unique_ptr< Attribute > > _attribs

◆ QueryCache() [3/4]

template<typename... Attribs>
template<typename T >
TheWarehouse::QueryCache< Attribs >::QueryCache ( const T &  q)
inline

Definition at line 226 of file TheWarehouse.h.

226 : _w(&q.warehouse())
227 {
228 addAttribs<0, Attribs...>();
229 _attribs.reserve(5);
230
231 for (auto & attrib : q.attributes())
232 _attribs.push_back(attrib->clone());
233 }
std::vector< std::unique_ptr< Attribute > > attributes() const
attribs returns a copy of the constructed Attribute list for the query in its current state.
QueryCache clone() const
clone creates and returns an independent copy of the query in its current state.

◆ QueryCache() [4/4]

template<typename... Attribs>
TheWarehouse::QueryCache< Attribs >::QueryCache ( const QueryCache< Attribs > &  other)
inline

Definition at line 270 of file TheWarehouse.h.

270 : _w(other._w), _key_tup(other._key_tup)
271 {
272 // do NOT copy the cache.
273
274 // initialize parametrized attributes and tuple:
275 addAttribs<0, Attribs...>(); // MUST have own pointers to attribs to avoid data races.
276 for (std::size_t i = std::tuple_size<AttribTuple>::value; i < other._attribs.size(); i++)
277 _attribs.push_back(other._attribs[i]->clone());
278 }

Member Function Documentation

◆ addAttribs() [1/2]

template<typename... Attribs>
template<int Index, typename A , typename... As>
void TheWarehouse::QueryCache< Attribs >::addAttribs ( )
inlineprivate

◆ addAttribs() [2/2]

template<typename... Attribs>
template<int Index>
void TheWarehouse::QueryCache< Attribs >::addAttribs ( )
inlineprivate

Definition at line 375 of file TheWarehouse.h.

376 {
377 }

◆ attributes()

template<typename... Attribs>
std::vector< std::unique_ptr< Attribute > > TheWarehouse::QueryCache< Attribs >::attributes ( ) const
inline

attribs returns a copy of the constructed Attribute list for the query in its current state.

Definition at line 301 of file TheWarehouse.h.

301{ return clone()._attribs; }

◆ clone()

template<typename... Attribs>
QueryCache TheWarehouse::QueryCache< Attribs >::clone ( ) const
inline

◆ condition()

template<typename... Attribs>
template<typename T , typename... Args>
QueryCache & TheWarehouse::QueryCache< Attribs >::condition ( Args &&...  args)
inline

Adds a new condition to the query.

The template parameter T is the Attribute class of interest and args are forwarded to T's constructor to build+add the attribute in-situ. Conditions represent persistent query conditions that do not change from query to query for a particular QueryCache instance.

Definition at line 285 of file TheWarehouse.h.

286 {
287 _attribs.emplace_back(new T(*_w, std::forward<Args>(args)...));
288 _cache.clear(); // invalidate cache if base query changes.
289 return *this;
290 }
std::map< std::pair< bool, KeyTuple >, std::size_t > _cache

Referenced by FEProblemBase::checkUserObjectJacobianRequirement(), FEProblemBase::checkUserObjects(), NonlinearSystemBase::computeJacobianInternal(), NonlinearSystemBase::computeResidualAndJacobianInternal(), NonlinearSystemBase::computeResidualInternal(), FEProblemBase::computeUserObjectByName(), FEProblemBase::computeUserObjects(), FEProblemBase::customSetup(), MFEMProblem::executeMFEMObjects(), FEProblemBase::executeSamplers(), FEProblemBase::getDistribution(), FEProblemBase::getFVInterpolationMethod(), FEProblemBase::getKokkosUserObject(), MFEMProblem::getMFEMObject(), FEProblemBase::getMortarUserObjects(), FEProblemBase::getPositionsObject(), FEProblemBase::getPostprocessorObjectByName(), FEProblemBase::getSampler(), CompositionDT::getTimeSteppers(), FEProblemBase::getUOQuery(), FEProblemBase::getUserObject(), FEProblemBase::getUserObjectBase(), FEProblemBase::getVectorPostprocessorObjectByName(), FEProblemBase::hasDistribution(), FEProblemBase::hasFVInterpolationMethod(), MFEMProblem::hasMFEMObject(), FEProblemBase::hasUserObject(), VectorPostprocessorInterface::hasVectorPostprocessorByName(), MFEMProblem::initialSetup(), BoundaryLinearFVFluxIntegral::initialSetup(), SideFVFluxBCIntegral::initialSetup(), AdvancedOutput::initPostprocessorOrVectorPostprocessorLists(), FEProblemBase::needBoundaryMaterialOnSide(), FEProblemBase::needInterfaceMaterialOnSide(), FEProblemBase::needInternalNeighborSideMaterial(), BoundaryNodeIntegrityCheckThread::onNode(), ComputeNodalUserObjectsThread::onNode(), BoundaryElemIntegrityCheckThread::operator()(), JSONOutput::outputReporters(), BlockRestrictionDebugOutput::printBlockRestrictionGroups(), BlockRestrictionDebugOutput::printBlockRestrictionMap(), BlockRestrictionDebugOutput::printBoundaryRestrictionGroups(), ComputeNodalUserObjectsThread::printGeneralExecutionInformation(), ComputeNodalUserObjectsThread::subdomainChanged(), ComputeUserObjectsThread::subdomainChanged(), and FEProblemBase::timestepSetup().

◆ count()

template<typename... Attribs>
std::size_t TheWarehouse::QueryCache< Attribs >::count ( )
inline

count returns the number of results that match the query (this requires actually running the query).

Definition at line 296 of file TheWarehouse.h.

296{ return _w->count(_attribs); }
std::size_t count(const std::vector< std::unique_ptr< Attribute > > &conds)
count returns the number of objects that match the provided query conditions.

◆ numAttribs()

template<typename... Attribs>
std::size_t TheWarehouse::QueryCache< Attribs >::numAttribs ( ) const
inline

Gets the number of attributes associated with the cached query.

Definition at line 331 of file TheWarehouse.h.

331{ return _attribs.size(); }

◆ operator=() [1/2]

template<typename... Attribs>
QueryCache & TheWarehouse::QueryCache< Attribs >::operator= ( const QueryCache< Attribs > &  other)
inline

Definition at line 235 of file TheWarehouse.h.

236 {
237 if (this == &other)
238 return *this;
239
240 _attribs.clear();
241 _w = other._w;
242 // MUST have own pointers to attribs to avoid data races - don't copy _key_attribs.
243 // initialize parametrized attributes and tuple:
244 addAttribs<0, Attribs...>();
245 _key_tup = other._key_tup;
246 // do NOT copy the cache.
247
248 // only copy over non-parametrized attributes
249 for (std::size_t i = std::tuple_size<AttribTuple>::value; i < other._attribs.size(); i++)
250 _attribs.push_back(other._attribs[i]->clone());
251 return *this;
252 }

◆ operator=() [2/2]

template<typename... Attribs>
template<typename T >
QueryCache & TheWarehouse::QueryCache< Attribs >::operator= ( const T &  q)
inline

Copy constructor from another Query.

Definition at line 256 of file TheWarehouse.h.

257 {
258 _attribs.clear();
259 _w = &q.warehouse();
260
261 addAttribs<0, Attribs...>();
262 _attribs.reserve(5);
263
264 for (auto & attrib : q.attributes())
265 _attribs.push_back(attrib->clone());
266
267 return *this;
268 }

◆ queryInto()

template<typename... Attribs>
template<typename T , typename... Args>
std::vector< T * > & TheWarehouse::QueryCache< Attribs >::queryInto ( std::vector< T * > &  results,
Args &&...  args 
)
inline

queryInto executes the query and stores the results in the given vector.

For parametrized queries (i.e. QueryCaches created with more than zero template arguments) args must contain one value for each parametrized query attribute - the types of args should be equal to the ::Key typedef specified for each corresponding parametrized attribute. All results must be castable to the templated type T. If the objects we are querying into inherit from the dependency resolver interface, then they will be sorted

Definition at line 312 of file TheWarehouse.h.

313 {
314 return queryIntoHelper(results, true, args...);
315 }
std::vector< T * > & queryIntoHelper(std::vector< T * > &results, const bool sort, Args &&... args)
queryInto executes the query and stores the results in the given vector.

Referenced by CheckFVBCAction::act(), NonlinearSystemBase::checkKernelCoverage(), ComputeResidualAndJacobianThread::compute(), LinearSystem::containsTimeKernel(), ComputeResidualAndJacobianThread::determineObjectWarehouses(), ComputeResidualThread::determineObjectWarehouses(), ComputeLinearFVElementalThread::fetchBlockSystemContributionObjects(), ComputeLinearFVFaceThread::fetchBlockSystemContributionObjects(), LinearSystem::initialSetup(), ComputeUserObjectsThread::queryBoundary(), ComputeUserObjectsThread::querySubdomain(), ComputeLinearFVElementalThread::setupSystemContributionObjects(), and ComputeLinearFVFaceThread::setupSystemContributionObjects().

◆ queryIntoHelper()

template<typename... Attribs>
template<typename T , typename... Args>
std::vector< T * > & TheWarehouse::QueryCache< Attribs >::queryIntoHelper ( std::vector< T * > &  results,
const bool  sort,
Args &&...  args 
)
inlineprivate

queryInto executes the query and stores the results in the given vector.

For parametrized queries (i.e. QueryCaches created with more than zero template arguments) args must contain one value for each parametrized query attribute - the types of args should be equal to the ::Key typedef specified for each corresponding parametrized attribute. All results must be castable to the templated type T. If the objects we are querying into inherit from the dependency resolver interface, then they will be sorted if sort is true

Definition at line 343 of file TheWarehouse.h.

344 {
345 std::lock_guard<std::mutex> lock(_cache_mutex);
346 setKeysInner<0, KeyType<Attribs>...>(args...);
347
348 std::size_t query_id;
349 const auto entry = _cache.find(std::make_pair(sort, _key_tup));
350 if (entry == _cache.end())
351 {
352 setAttribsInner<0, KeyType<Attribs>...>(args...);
353 // add the sort attribute. No need (I think) to clear the cache because the base query is
354 // not changing
355 _attribs.emplace_back(new AttribSorted(*_w, sort));
356 query_id = _w->queryID(_attribs);
357 _cache[std::make_pair(sort, _key_tup)] = query_id;
358 // remove the sort attribute
359 _attribs.pop_back();
360 }
361 else
362 query_id = entry->second;
363
364 return _w->queryInto(query_id, results);
365 }
This attribute describes sorting state.
std::vector< T * > & queryInto(const std::vector< std::unique_ptr< Attribute > > &conds, std::vector< T * > &results)
queryInto takes the given conditions (i.e.
std::size_t queryID(const std::vector< std::unique_ptr< Attribute > > &conds)

Referenced by TheWarehouse::QueryCache< Attribs >::queryInto(), and TheWarehouse::QueryCache< Attribs >::queryIntoUnsorted().

◆ queryIntoUnsorted()

template<typename... Attribs>
template<typename T , typename... Args>
std::vector< T * > & TheWarehouse::QueryCache< Attribs >::queryIntoUnsorted ( std::vector< T * > &  results,
Args &&...  args 
)
inline

queryInto executes the query and stores the results in the given vector.

For parametrized queries (i.e. QueryCaches created with more than zero template arguments) args must contain one value for each parametrized query attribute - the types of args should be equal to the ::Key typedef specified for each corresponding parametrized attribute. All results must be castable to the templated type T. These objects will not be sorted

Definition at line 325 of file TheWarehouse.h.

326 {
327 return queryIntoHelper(results, false, args...);
328 }

◆ setAttribsInner() [1/2]

template<typename... Attribs>
template<int Index>
void TheWarehouse::QueryCache< Attribs >::setAttribsInner ( )
inlineprivate

Definition at line 397 of file TheWarehouse.h.

398 {
399 }

Referenced by TheWarehouse::QueryCache< Attribs >::setAttribsInner().

◆ setAttribsInner() [2/2]

template<typename... Attribs>
template<int Index, typename K , typename... Args>
void TheWarehouse::QueryCache< Attribs >::setAttribsInner ( k,
Args &...  args 
)
inlineprivate

Definition at line 391 of file TheWarehouse.h.

392 {
393 std::get<Index>(_attrib_tup)->setFrom(k);
394 setAttribsInner<Index + 1, Args...>(args...);
395 }

◆ setKeysInner() [1/2]

template<typename... Attribs>
template<int Index>
void TheWarehouse::QueryCache< Attribs >::setKeysInner ( )
inlineprivate

Definition at line 386 of file TheWarehouse.h.

387 {
388 }

Referenced by TheWarehouse::QueryCache< Attribs >::setKeysInner().

◆ setKeysInner() [2/2]

template<typename... Attribs>
template<int Index, typename K , typename... Args>
void TheWarehouse::QueryCache< Attribs >::setKeysInner ( K &  k,
Args &...  args 
)
inlineprivate

Definition at line 380 of file TheWarehouse.h.

381 {
382 std::get<Index>(_key_tup) = k;
383 setKeysInner<Index + 1, Args...>(args...);
384 }

◆ warehouse()

template<typename... Attribs>
TheWarehouse & TheWarehouse::QueryCache< Attribs >::warehouse ( ) const
inline

Definition at line 298 of file TheWarehouse.h.

298{ return *_w; }

Member Data Documentation

◆ _attrib_tup

template<typename... Attribs>
AttribTuple TheWarehouse::QueryCache< Attribs >::_attrib_tup
private

◆ _attribs

template<typename... Attribs>
std::vector<std::unique_ptr<Attribute> > TheWarehouse::QueryCache< Attribs >::_attribs
private

◆ _cache

template<typename... Attribs>
std::map<std::pair<bool, KeyTuple>, std::size_t> TheWarehouse::QueryCache< Attribs >::_cache
private

◆ _cache_mutex

template<typename... Attribs>
std::mutex TheWarehouse::QueryCache< Attribs >::_cache_mutex
private

◆ _key_tup

template<typename... Attribs>
KeyTuple TheWarehouse::QueryCache< Attribs >::_key_tup
private

◆ _w

template<typename... Attribs>
TheWarehouse* TheWarehouse::QueryCache< Attribs >::_w = nullptr
private

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