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;
31operator==(
const std::unique_ptr<Attribute> & lhs,
const std::unique_ptr<Attribute> & rhs)
33 return (*lhs) == (*rhs);
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)
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);
198 for (
const auto i : index_range(obj_ids))
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<MooseObject *>(
227 "Cyclic dependency detected in object ordering",
230 auto * moose_obj =
dynamic_cast<MooseObject *
>(obj);
231 mooseAssert(moose_obj,
"Failed to cast dependency object to MooseObject");
232 return moose_obj->name();
236 mooseAssert(dependers.size() == vec.size(),
"Dependency resolution size mismatch");
237 for (
unsigned int i = 0; i < dependers.size(); i++)
238 vec[i] =
dynamic_cast<MooseObject *
>(dependers[i]);
244const std::vector<MooseObject *> &
247 if (
static_cast<std::size_t
>(query_id) >=
_obj_cache.size())
248 throw std::runtime_error(
"unknown query id");
262 std::vector<std::unique_ptr<Attribute>> conds_clone;
263 conds_clone.resize(conds.size());
264 for (std::size_t i = 0; i < conds.size(); i++)
265 conds_clone[i] = conds[i]->clone();
266 return prepare(std::move(conds_clone));
272 auto query_id =
queryID(conds);
274 auto & objs =
query(query_id);
275 std::size_t
count = 0;
276 for (
auto obj : objs)
284 std::vector<std::unique_ptr<Attribute>> & attribs)
288 attribs.emplace_back(ref->clone());
289 attribs.back()->initFrom(obj);
304 blk->checkVariable(*var);
315 std::string variable_name = parameters.
getMooseType(
"variable");
316 if (variable_name ==
"")
bool operator==(const std::unique_ptr< Attribute > &lhs, const std::unique_ptr< Attribute > &rhs)
TheWarehouse uses this operator function for indexing and caching queries.
void isValid(MooseObject *obj)
This attribute describes sorting state.
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 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.
virtual void initFrom(const MooseObject *obj) override
initFrom reads and stores the desired meta-data from obj for later matching comparisons.
Attribute is an abstract class that can be implemented in order to track custom metadata about MooseO...
Attribute(TheWarehouse &w, const std::string name)
Constructs/initializes a new attribute with the specified name for use in warehouse w.
virtual std::unique_ptr< Attribute > clone() const =0
clone creates and returns and identical (deep) copy of this attribute - i.e.
An interface that restricts an object to subdomains via the 'blocks' input parameter.
Interface for objects that needs coupling capabilities.
Interface for sorting dependent vectors of objects.
static void sort(typename std::vector< T > &vector)
Given a vector, sort using the getRequested/SuppliedItems sets.
const InputParameters & parameters() const
Get the parameters of the object.
Every object that can be built by the factory should be derived from this class.
This class provides an interface for common operations on field variables of both FE and FV types wit...
Generic class for solving transient nonlinear problems.
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...
TheWarehouse is a container for MooseObjects that allows querying/filtering over various customizeabl...
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::mutex _query_cache_mutex
Query query()
query creates and returns an initialized a query object for querying objects from the warehouse.
std::vector< std::shared_ptr< MooseObject > > _objects
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...
std::size_t count(const std::vector< std::unique_ptr< Attribute > > &conds)
count returns the number of objects that match the provided query conditions.
std::unordered_map< MooseObject *, std::size_t > _obj_ids
void readAttribs(const MooseObject *obj, std::vector< std::unique_ptr< Attribute > > &attribs)
void update(MooseObject *obj)
update updates the metadata/attribute-info stored for the given object obj that must already exists i...
std::vector< std::vector< MooseObject * > > _obj_cache
std::unique_ptr< WarehouseStorage > _store
std::mutex _obj_cache_mutex
std::unordered_map< std::vector< std::unique_ptr< Attribute > >, int > _query_cache
std::size_t queryID(const std::vector< std::unique_ptr< Attribute > > &conds)
std::vector< std::unique_ptr< Attribute > > _attrib_list
virtual void set(std::size_t obj_id, std::vector< std::unique_ptr< Attribute > > attribs) override
virtual void add(std::size_t obj_id, std::vector< std::unique_ptr< Attribute > > attribs) override
virtual std::vector< std::size_t > query(const std::vector< std::unique_ptr< Attribute > > &conds) override
std::vector< std::vector< std::unique_ptr< Attribute > > > _data
virtual void set(std::size_t obj_id, std::vector< std::unique_ptr< Attribute > > attribs)=0
virtual std::vector< std::size_t > query(const std::vector< std::unique_ptr< Attribute > > &conds)=0
virtual ~WarehouseStorage()=default
virtual void add(std::size_t obj_id, std::vector< std::unique_ptr< Attribute > > attribs)=0