31 virtual void add(std::size_t obj_id, std::vector<std::unique_ptr<Attribute>> attribs) = 0;
32 virtual std::vector<std::size_t>
query(
const std::vector<std::unique_ptr<Attribute>> & conds) = 0;
33 virtual void set(std::size_t obj_id, std::vector<std::unique_ptr<Attribute>> attribs) = 0;
37operator==(
const std::unique_ptr<Attribute> & lhs,
const std::unique_ptr<Attribute> & rhs)
39 return (*lhs) == (*rhs);
65 virtual void add(std::size_t obj_id, std::vector<std::unique_ptr<Attribute>> attribs)
override
67 std::lock_guard<std::mutex> l(
_mutex);
68 if (obj_id !=
_data.size())
69 throw std::runtime_error(
"object with id " + std::to_string(obj_id) +
" already added");
70 _data.push_back(std::move(attribs));
73 virtual std::vector<std::size_t>
74 query(
const std::vector<std::unique_ptr<Attribute>> & conds)
override
76 std::vector<std::size_t> ids;
77 std::lock_guard<std::mutex> l(
_mutex);
78 for (std::size_t i = 0; i <
_data.size(); i++)
80 auto & data =
_data[i];
82 for (
auto & cond : conds)
84 if (!data[cond->id()]->isMatch(*cond))
92 mooseAssert(std::find(ids.begin(), ids.end(), i) == ids.end(),
"Duplicate object");
99 virtual void set(std::size_t obj_id, std::vector<std::unique_ptr<Attribute>> attribs)
override
101 if (obj_id >
_data.size())
102 throw std::runtime_error(
"unknown object id " + std::to_string(obj_id));
104 std::lock_guard<std::mutex> l(
_mutex);
106 auto & dst =
_data[obj_id];
107 for (
auto & attrib : attribs)
108 dst[attrib->id()] = std::move(attrib);
113 std::vector<std::vector<std::unique_ptr<Attribute>>>
_data;
126 std::size_t obj_id = 0;
130 mooseAssert(!
_obj_ids.count(obj.get()), obj->typeAndName() +
" has already been added");
142 std::vector<std::unique_ptr<Attribute>> attribs;
144 _store->add(obj_id, std::move(attribs));
150 std::vector<std::unique_ptr<Attribute>> attribs;
151 attribs.push_back(extra.
clone());
162 std::vector<std::unique_ptr<Attribute>> attribs;
175 std::unique_ptr<Attribute> sorted_attrib;
176 if (!conds.empty() &&
dynamic_cast<AttribSorted *
>(conds.back().get()))
178 sorted_attrib = std::move(conds.back());
179 static const AttribSorted sorted_attrib_true(*
this,
true);
180 sort = sorted_attrib->isMatch(sorted_attrib_true);
186 for (
auto & cond : conds)
188 "There should be no sorted attributes in this container.");
191 auto obj_ids =
_store->query(conds);
193 conds.push_back(std::move(sorted_attrib));
196 auto & vec =
_obj_cache.emplace_back(obj_ids.size());
203 std::lock_guard<std::mutex> o_lock(
_obj_mutex);
204 for (
const auto i : index_range(obj_ids))
206 auto obj =
_objects[obj_ids[i]].get();
207 mooseAssert(std::find(vec.begin(), vec.end(), obj) == vec.end(),
"Duplicate object");
213 std::vector<DependencyResolverInterface *> dependers;
222 dependers.push_back(d);
231 DependencyResolverInterface::cyclicDependencyError<MooseObject *>(
233 "Cyclic dependency detected in object ordering",
236 auto * moose_obj =
dynamic_cast<MooseObject *
>(obj);
237 mooseAssert(moose_obj,
"Failed to cast dependency object to MooseObject");
238 return moose_obj->name();
242 mooseAssert(dependers.size() == vec.size(),
"Dependency resolution size mismatch");
243 for (
unsigned int i = 0; i < dependers.size(); i++)
244 vec[i] =
dynamic_cast<MooseObject *
>(dependers[i]);
250const std::vector<MooseObject *> &
253 if (
static_cast<std::size_t
>(query_id) >=
_obj_cache.size())
254 throw std::runtime_error(
"unknown query id");
268 std::vector<std::unique_ptr<Attribute>> conds_clone;
269 conds_clone.resize(conds.size());
270 for (std::size_t i = 0; i < conds.size(); i++)
271 conds_clone[i] = conds[i]->clone();
272 return prepare(std::move(conds_clone));
278 auto query_id =
queryID(conds);
280 auto & objs =
query(query_id);
281 std::size_t
count = 0;
282 for (
auto obj : objs)
290 std::vector<std::unique_ptr<Attribute>> & attribs)
294 attribs.emplace_back(ref->clone());
295 attribs.back()->initFrom(obj);
309 const auto & var = scalar_kernel.
variable();
313 if (subdomains.empty())
318 const auto & coupled_subdomains = coupled_var->activeSubdomains();
319 if (coupled_subdomains.empty())
322 std::set<SubdomainID> shared_subdomains;
323 std::set_intersection(subdomains.begin(),
325 coupled_subdomains.begin(),
326 coupled_subdomains.end(),
327 std::inserter(shared_subdomains, shared_subdomains.begin()));
329 if (shared_subdomains.empty())
330 mooseError(
"The 'block' parameter of the scalar variable '",
332 "' coupled into the object '",
333 scalar_kernel.
name(),
334 "' must overlap the 'block' parameter of the variable '",
336 "' that the object acts on:\n Variable '",
364 blk->checkVariable(*var);
370 blk->checkVariable(*var);
381 std::string variable_name = parameters.
getMooseType(
"variable");
382 if (variable_name ==
"")
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
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)
void checkCoupledScalarVariableBlocks(ScalarKernelBase &scalar_kernel)
Check the scalar variables coupled into a scalar kernel.
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.
const std::string & name() const
Get the name of the class.
Every object that can be built by the factory should be derived from this class.
const std::set< SubdomainID > & activeSubdomains() const
The subdomains the variable is active on.
This class provides an interface for common operations on field variables of both FE and FV types wit...
Class for scalar variables (they are different).
Interface for objects that needs scalar coupling capabilities.
const std::vector< MooseVariableScalar * > & getCoupledMooseScalarVars()
Get the list of coupled scalar variables.
Base class shared by AD and non-AD scalar kernels.
virtual const MooseVariableScalar & variable() const override
The variable that this kernel operates on.
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
std::string stringify(const T &t)
conversion to string