Loading [MathJax]/extensions/tex2jax.js
https://mooseframework.inl.gov
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
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. More...
 
template<typename T >
 QueryCache (const T &q)
 
QueryCacheoperator= (const QueryCache &other)
 
template<typename T >
QueryCacheoperator= (const T &q)
 Copy constructor from another Query. More...
 
 QueryCache (const QueryCache &other)
 
template<typename T , typename... Args>
QueryCachecondition (Args &&... args)
 Adds a new condition to the query. More...
 
QueryCache clone () const
 clone creates and returns an independent copy of the query in its current state. More...
 
std::size_t count ()
 count returns the number of results that match the query (this requires actually running the query). More...
 
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. More...
 
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. More...
 
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. More...
 
std::size_t numAttribs () const
 Gets the number of attributes associated with the cached query. More...
 

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. More...
 
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 208 of file TheWarehouse.h.

Member Typedef Documentation

◆ AttribTuple

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

Definition at line 212 of file TheWarehouse.h.

◆ KeyTuple

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

Definition at line 211 of file TheWarehouse.h.

Constructor & Destructor Documentation

◆ QueryCache() [1/4]

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

Definition at line 214 of file TheWarehouse.h.

214 {}

◆ 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 218 of file TheWarehouse.h.

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

◆ QueryCache() [3/4]

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

Definition at line 225 of file TheWarehouse.h.

225  : _w(&q.warehouse())
226  {
227  addAttribs<0, Attribs...>();
228  _attribs.reserve(5);
229 
230  for (auto & attrib : q.attributes())
231  _attribs.push_back(attrib->clone());
232  }
std::vector< std::unique_ptr< Attribute > > _attribs
Definition: TheWarehouse.h:401

◆ QueryCache() [4/4]

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

Definition at line 269 of file TheWarehouse.h.

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

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 374 of file TheWarehouse.h.

375  {
376  }

◆ 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 300 of file TheWarehouse.h.

300 { return clone()._attribs; }
std::vector< std::unique_ptr< Attribute > > _attribs
Definition: TheWarehouse.h:401
QueryCache clone() const
clone creates and returns an independent copy of the query in its current state.
Definition: TheWarehouse.h:292

◆ 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 284 of file TheWarehouse.h.

Referenced by FEProblemBase::checkUserObjectJacobianRequirement(), FEProblemBase::checkUserObjects(), NonlinearSystemBase::computeJacobianInternal(), NonlinearSystemBase::computeResidualAndJacobianInternal(), NonlinearSystemBase::computeResidualInternal(), FEProblemBase::computeUserObjectByName(), FEProblemBase::computeUserObjects(), FEProblemBase::computeUserObjectsInternal(), FEProblemBase::customSetup(), FEProblemBase::executeSamplers(), FEProblemBase::getDistribution(), FEProblemBase::getMortarUserObjects(), FEProblemBase::getPositionsObject(), FEProblemBase::getSampler(), CompositionDT::getTimeSteppers(), FEProblemBase::getUserObject(), FEProblemBase::getUserObjectBase(), FEProblemBase::hasUserObject(), SideFVFluxBCIntegral::initialSetup(), FEProblemBase::initialSetup(), AdvancedOutput::initPostprocessorOrVectorPostprocessorLists(), FEProblemBase::needBoundaryMaterialOnSide(), FEProblemBase::needInterfaceMaterialOnSide(), FEProblemBase::needSubdomainMaterialOnSide(), ComputeNodalUserObjectsThread::onNode(), BoundaryNodeIntegrityCheckThread::onNode(), BoundaryElemIntegrityCheckThread::operator()(), JSONOutput::outputReporters(), BlockRestrictionDebugOutput::printBlockRestrictionMap(), ComputeNodalUserObjectsThread::printGeneralExecutionInformation(), ComputeNodalUserObjectsThread::subdomainChanged(), ComputeUserObjectsThread::subdomainChanged(), and FEProblemBase::timestepSetup().

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

◆ 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 295 of file TheWarehouse.h.

295 { 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.
Definition: TheWarehouse.C:263
std::vector< std::unique_ptr< Attribute > > _attribs
Definition: TheWarehouse.h:401

◆ 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 330 of file TheWarehouse.h.

330 { return _attribs.size(); }
std::vector< std::unique_ptr< Attribute > > _attribs
Definition: TheWarehouse.h:401

◆ operator=() [1/2]

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

Definition at line 234 of file TheWarehouse.h.

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

◆ 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 255 of file TheWarehouse.h.

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

◆ 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 311 of file TheWarehouse.h.

Referenced by LinearSystem::containsTimeKernel(), NonlinearSystemBase::customSetup(), ComputeResidualAndJacobianThread::determineObjectWarehouses(), NonlinearSystemBase::initialSetup(), FEProblemBase::initialSetup(), ComputeUserObjectsThread::queryBoundary(), ComputeUserObjectsThread::querySubdomain(), NonlinearThread::subdomainChanged(), and NonlinearSystemBase::timestepSetup().

312  {
313  return queryIntoHelper(results, true, args...);
314  }
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.
Definition: TheWarehouse.h:342

◆ 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 342 of file TheWarehouse.h.

Referenced by TheWarehouse::QueryCache< AttribThread, AttribBoundaries, AttribInterfaces >::queryInto(), and TheWarehouse::QueryCache< AttribThread, AttribBoundaries, AttribInterfaces >::queryIntoUnsorted().

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

◆ 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 324 of file TheWarehouse.h.

Referenced by FEProblemBase::computeUserObjectsInternal().

325  {
326  return queryIntoHelper(results, false, args...);
327  }
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.
Definition: TheWarehouse.h:342

◆ setAttribsInner() [1/2]

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

Definition at line 390 of file TheWarehouse.h.

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

◆ setAttribsInner() [2/2]

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

◆ setKeysInner() [1/2]

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

Definition at line 379 of file TheWarehouse.h.

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

◆ setKeysInner() [2/2]

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

◆ warehouse()

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

Definition at line 297 of file TheWarehouse.h.

297 { 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: