22std::map<std::string, std::string>
25 std::map<std::string, std::string>
values;
26 for (
const auto & [name, value] : params)
27 if (name !=
"block" && !params.isPrivate(name) && params.isParamValid(name))
31 values.emplace(name, ss.str());
37std::vector<std::string>
40 const auto a_values = comparableValues(a);
41 const auto b_values = comparableValues(b);
42 std::set<std::string> names;
43 for (
const auto & [name, _] : a_values)
45 for (
const auto & [name, _] : b_values)
48 std::vector<std::string> differing;
49 for (
const auto & name : names)
51 const auto a_it = a_values.find(name);
52 const auto b_it = b_values.find(name);
53 if (a_it == a_values.end() || b_it == b_values.end() || a_it->second != b_it->second)
54 differing.push_back(name);
65 "Merges the requests of multiple Physics for the same shared variable into a single "
66 "variable spanning the union of their blocks. Created on demand; not meant to be declared "
78 const std::string & var_type,
79 const VariableName & var_name,
81 const std::vector<SubdomainName> &
blocks,
82 const std::string & requester)
91 auto & merged = it->second;
92 const auto & first_requester = merged._requester_blocks.front().first;
96 "' requests the shared variable '",
99 nl ?
"a solver" :
"an auxiliary",
100 " variable, but Physics '",
102 "' requested it as ",
103 merged._nl ?
"a solver" :
"an auxiliary",
105 if (merged._type != var_type)
108 "' requests the shared variable '",
114 "' requested it with type '",
117 const auto differing = differingParameters(params, merged.
_params);
118 if (!differing.empty())
121 "' requests the shared variable '",
123 "' with different values for parameter(s) ",
129 merged._requester_blocks.emplace_back(requester,
blocks);
135 for (
const auto & [var_name, req] :
_requests)
138 std::vector<SubdomainName>
blocks;
139 bool any_block =
false;
140 for (
const auto & [_, requested_blocks] : req._requester_blocks)
141 for (
const auto & block : requested_blocks)
142 if (block ==
"ANY_BLOCK_ID")
149 params.
set<std::vector<SubdomainName>>(
"block") =
blocks;
151 if (params.
get<
bool>(
"fv"))
154 _problem->addVariable(req._type, var_name, params);
156 _problem->addAuxVariable(req._type, var_name, params);
171 std::map<SubdomainID, std::set<std::size_t>> sub_to_requesters;
175 const std::set<SubdomainID> ids =
177 ?
_mesh->meshSubdomains()
179 for (
const auto id : ids)
180 sub_to_requesters[
id].insert(i);
185 const auto &
name =
_mesh->getSubdomainName(
id);
186 return name.empty() ? std::to_string(
id) :
name;
191 for (
const auto & [sub_a, requesters_a] : sub_to_requesters)
192 for (
const auto sub_b :
_mesh->getBlockConnectedBlocks(sub_a))
194 const auto it_b = sub_to_requesters.find(sub_b);
196 if (sub_b < sub_a || it_b == sub_to_requesters.end())
198 const auto & requesters_b = it_b->second;
200 const bool some_requester_covers_both =
201 std::any_of(requesters_a.begin(),
203 [&requesters_b](
const auto i) { return requesters_b.count(i); });
204 if (!some_requester_covers_both)
209 "' share the finite volume variable '",
211 "' on the adjacent subdomains '",
215 "', but neither is defined on both. Their flux kernels would treat the faces "
216 "between these subdomains as boundaries, so no flux would cross them. Define a "
217 "single Physics on both subdomains instead.");
225 if (!existing.empty())
228 const std::string class_name =
"PhysicsVariableCoordinator";
230 params.
set<
bool>(
"_built_by_moose") =
true;
231 params.
set<std::string>(
"registered_identifier") =
"(AutoBuilt)";
233 auto action = action_factory.
create(class_name,
"physics_variable_coordinator", params);
236 ::mooseError(
"Internal error: failed to create the PhysicsVariableCoordinator");
subdomain_id_type SubdomainID
std::array< Real, 2 > values
if(!dmm->_nl) SETERRQ(PETSC_COMM_WORLD
registerMooseAction("MooseApp", PhysicsVariableCoordinator, "flush_shared_physics_variables")
Specialized factory for generic Action System objects.
std::shared_ptr< Action > create(const std::string &action, const std::string &action_name, InputParameters ¶meters)
InputParameters getValidParams(const std::string &name)
Storage for action instances.
std::vector< const T * > getActions()
Retrieve all actions in a specific type ordered by their names.
void addActionBlock(std::shared_ptr< Action > blk)
This method add an Action instance to the warehouse.
std::shared_ptr< MooseMesh > & _mesh
static InputParameters validParams()
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
const std::string & name() const
Get the name of the class.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Lets multiple Physics instances (for example one per component) share a single variable across all of...
static PhysicsVariableCoordinator & findOrCreate(ActionWarehouse &awh, ActionFactory &action_factory)
Finds this simulation's coordinator, creating it and adding it to awh (using action_factory) if it do...
void checkFVAdjacency(const VariableName &var_name, const MergedRequest &req) const
Errors if req is a finite volume variable on two adjacent subdomains that no single requester is defi...
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
PhysicsVariableCoordinator(const InputParameters ¶ms)
std::map< VariableName, MergedRequest > _requests
Pending variable requests, keyed by variable name.
void requestVariable(bool nl, const std::string &var_type, const VariableName &var_name, const InputParameters ¶ms, const std::vector< SubdomainName > &blocks, const std::string &requester)
Requests that a shared variable be created on blocks, in addition to any blocks already requested for...
static InputParameters validParams()
std::string stringify(const T &t)
conversion to string
std::string name(const ElemQuality q)
The merged requests for one shared variable.
std::vector< std::pair< std::string, std::vector< SubdomainName > > > _requester_blocks
Name of each requesting Physics, in request order, with the blocks it requested.
InputParameters _params
Parameters of the variable, from the first request.