25 virtual void add(std::size_t obj_id, std::vector<std::unique_ptr<Attribute>> attribs) = 0;
26 virtual std::vector<std::size_t>
query(
const std::vector<std::unique_ptr<Attribute>> & conds) = 0;
27 virtual void set(std::size_t obj_id, std::vector<std::unique_ptr<Attribute>> attribs) = 0;
31 operator==(
const std::unique_ptr<Attribute> & lhs,
const std::unique_ptr<Attribute> & rhs)
33 return (*lhs) == (*rhs);
47 return _initd && a && a->_initd && (a->_val ==
_val);
59 virtual void add(std::size_t obj_id, std::vector<std::unique_ptr<Attribute>> attribs)
override 61 std::lock_guard<std::mutex> l(
_mutex);
62 if (obj_id !=
_data.size())
63 throw std::runtime_error(
"object with id " + std::to_string(obj_id) +
" already added");
64 _data.push_back(std::move(attribs));
67 virtual std::vector<std::size_t>
68 query(
const std::vector<std::unique_ptr<Attribute>> & conds)
override 70 std::vector<std::size_t> ids;
71 std::lock_guard<std::mutex> l(
_mutex);
72 for (std::size_t i = 0; i <
_data.size(); i++)
74 auto & data =
_data[i];
76 for (
auto & cond : conds)
78 if (!data[cond->id()]->isMatch(*cond))
86 mooseAssert(std::find(ids.begin(), ids.end(), i) == ids.end(),
"Duplicate object");
93 virtual void set(std::size_t obj_id, std::vector<std::unique_ptr<Attribute>> attribs)
override 95 if (obj_id >
_data.size())
96 throw std::runtime_error(
"unknown object id " + std::to_string(obj_id));
98 std::lock_guard<std::mutex> l(
_mutex);
100 auto & dst =
_data[obj_id];
101 for (
auto & attrib : attribs)
102 dst[attrib->id()] = std::move(attrib);
107 std::vector<std::vector<std::unique_ptr<Attribute>>>
_data;
120 std::size_t obj_id = 0;
124 mooseAssert(!
_obj_ids.count(obj.get()), obj->typeAndName() +
" has already been added");
136 std::vector<std::unique_ptr<Attribute>> attribs;
138 _store->add(obj_id, std::move(attribs));
144 std::vector<std::unique_ptr<Attribute>> attribs;
145 attribs.push_back(extra.
clone());
156 std::vector<std::unique_ptr<Attribute>> attribs;
169 std::unique_ptr<Attribute> sorted_attrib;
170 if (!conds.empty() &&
dynamic_cast<AttribSorted *
>(conds.back().get()))
172 sorted_attrib = std::move(conds.back());
173 static const AttribSorted sorted_attrib_true(*
this,
true);
174 sort = sorted_attrib->isMatch(sorted_attrib_true);
180 for (
auto & cond : conds)
181 mooseAssert(!dynamic_cast<AttribSorted *>(cond.get()),
182 "There should be no sorted attributes in this container.");
185 auto obj_ids =
_store->query(conds);
187 conds.push_back(std::move(sorted_attrib));
190 auto & vec =
_obj_cache.emplace_back(obj_ids.size());
197 std::lock_guard<std::mutex> o_lock(
_obj_mutex);
200 auto obj =
_objects[obj_ids[i]].get();
201 mooseAssert(std::find(vec.begin(), vec.end(), obj) == vec.end(),
"Duplicate object");
207 std::vector<DependencyResolverInterface *> dependers;
216 dependers.push_back(d);
225 DependencyResolverInterface::cyclicDependencyError<UserObject *>(
226 e,
"Cyclic dependency detected in object ordering");
229 mooseAssert(dependers.size() == vec.size(),
"Dependency resolution size mismatch");
230 for (
unsigned int i = 0; i < dependers.size(); i++)
231 vec[i] = dynamic_cast<MooseObject *>(dependers[i]);
237 const std::vector<MooseObject *> &
240 if (static_cast<std::size_t>(query_id) >=
_obj_cache.size())
241 throw std::runtime_error(
"unknown query id");
255 std::vector<std::unique_ptr<Attribute>> conds_clone;
256 conds_clone.resize(conds.size());
257 for (std::size_t i = 0; i < conds.size(); i++)
258 conds_clone[i] = conds[i]->clone();
259 return prepare(std::move(conds_clone));
265 auto query_id =
queryID(conds);
267 auto & objs =
query(query_id);
268 std::size_t
count = 0;
269 for (
auto obj : objs)
277 std::vector<std::unique_ptr<Attribute>> & attribs)
281 attribs.emplace_back(ref->clone());
282 attribs.back()->initFrom(obj);
297 blk->checkVariable(*var);
308 std::string variable_name = parameters.
getMooseType(
"variable");
309 if (variable_name ==
"")
std::string name(const ElemQuality q)
std::mutex _obj_cache_mutex
virtual void add(std::size_t obj_id, std::vector< std::unique_ptr< Attribute >> attribs)=0
std::size_t count(const std::vector< std::unique_ptr< Attribute >> &conds)
count returns the number of objects that match the provided query conditions.
void isValid(MooseObject *obj)
Attribute is an abstract class that can be implemented in order to track custom metadata about MooseO...
void add(std::shared_ptr< MooseObject > obj)
add adds a new object to the warehouse and stores attributes/metadata about it for running queries/fi...
This attribute describes sorting state.
This class provides an interface for common operations on field variables of both FE and FV types wit...
virtual void add(std::size_t obj_id, std::vector< std::unique_ptr< Attribute >> attribs) override
Attribute(TheWarehouse &w, const std::string name)
Constructs/initializes a new attribute with the specified name for use in warehouse w...
virtual bool isEqual(const Attribute &other) const override
isEqual returns true if the meta-data stored in this attribute is identical to that stored in other...
std::vector< std::vector< std::unique_ptr< Attribute > > > _data
std::mutex _query_cache_mutex
std::vector< std::shared_ptr< MooseObject > > _objects
Every object that can be built by the factory should be derived from this class.
std::unique_ptr< Storage > _store
virtual ~Storage()=default
void readAttribs(const MooseObject *obj, std::vector< std::unique_ptr< Attribute >> &attribs)
std::size_t queryID(const std::vector< std::unique_ptr< Attribute >> &conds)
TheWarehouse is a container for MooseObjects that allows querying/filtering over various customizeabl...
virtual bool isMatch(const Attribute &other) const override
isMatch returns true if the meta-data stored in this attribute is equivalent to that stored in other...
virtual std::vector< std::size_t > query(const std::vector< std::unique_ptr< Attribute >> &conds)=0
int prepare(std::vector< std::unique_ptr< Attribute >> conds)
prepares a query and returns an associated query_id (i.e. for use with the query function).
std::unordered_map< std::vector< std::unique_ptr< Attribute > >, int > _query_cache
virtual const MooseVariableFieldBase & getVariable(const THREAD_ID tid, const std::string &var_name, Moose::VarKindType expected_var_type=Moose::VarKindType::VAR_ANY, Moose::VarFieldType expected_var_field_type=Moose::VarFieldType::VAR_FIELD_ANY) const =0
Returns the variable reference for requested variable which must be of the expected_var_type (Nonline...
virtual std::vector< std::size_t > query(const std::vector< std::unique_ptr< Attribute >> &conds) override
std::unordered_map< MooseObject *, std::size_t > _obj_ids
void update(MooseObject *obj)
update updates the metadata/attribute-info stored for the given object obj that must already exists i...
Interface for objects that needs coupling capabilities.
static void sort(typename std::vector< T > &vector)
Given a vector, sort using the getRequested/SuppliedItems sets.
Generic class for solving transient nonlinear problems.
Query query()
query creates and returns an initialized a query object for querying objects from the warehouse...
bool operator==(const std::unique_ptr< Attribute > &lhs, const std::unique_ptr< Attribute > &rhs)
TheWarehouse uses this operator function for indexing and caching queries.
An interface that restricts an object to subdomains via the 'blocks' input parameter.
Interface for sorting dependent vectors of objects.
const InputParameters & parameters() const
Get the parameters of the object.
virtual void initFrom(const MooseObject *obj) override
initFrom reads and stores the desired meta-data from obj for later matching comparisons.
auto index_range(const T &sizable)
std::vector< std::unique_ptr< Attribute > > _attrib_list
std::vector< std::vector< MooseObject * > > _obj_cache
virtual std::unique_ptr< Attribute > clone() const =0
clone creates and returns and identical (deep) copy of this attribute - i.e.