33 const MeshBase::const_element_iterator &,
39 std::unique_ptr<libMesh::GhostingFunctor>
48 return "RedistributeProperties";
83 std::set<const Elem *> elems_being_migrated;
85 if (mat_prop_store->hasStatefulProperties())
89 "This routine has not been implemented for threads. Please query this routine before " 90 "a threaded region or contact a MOOSE developer to discuss.");
92 for (
const auto state : mat_prop_store->stateIndexRange())
95 typedef std::unordered_map<unsigned int, std::string> stored_props_type;
96 typedef std::tuple<stored_props_type, dof_id_type, int> stored_elem_type;
97 std::map<processor_id_type, std::vector<stored_elem_type>> props_to_push;
100 for (
auto & [elem, elem_props_map] : props_map)
103 mooseAssert(elem,
"Null element found in material property map?");
107 mooseAssert(elem->id() <
mesh.max_elem_id(),
108 "Invalid (dangling? corrupted?) element in material property map?");
109 mooseAssert(elem->processor_id() <
mesh.n_processors(),
110 "Invalid (corrupted?) element in material property map?");
115 if (elem !=
mesh.query_elem_ptr(elem->id()))
118 std::set<processor_id_type> target_pids;
121 target_pids.insert(elem->processor_id());
122 else if (elem->subactive())
124 mooseAssert(elem->parent(),
125 "Invalid (corrupted?) subactive element in material property map");
126 mooseAssert(elem->parent()->refinement_flag() == Elem::JUST_COARSENED,
127 "Invalid (subactive child of not-just-coarsened) element in material " 129 target_pids.insert(elem->parent()->processor_id());
133 mooseAssert(elem->ancestor(),
134 "Unexpected relationship for element in material property map?");
135 mooseAssert(elem->has_children(),
136 "Ancestor element with no children in material property map?");
137 for (
const Elem & child : elem->child_ref_range())
138 target_pids.insert(child.processor_id());
143 bool remote_pid =
false, local_pid =
false;
145 if (target_pid == pid)
151 stored_props_type stored_props;
152 unsigned int n_q_points = 0;
153 for (
auto & [prop_id, prop_vals] : elem_props_map)
155 mooseAssert(!prop_vals.empty(),
156 "Empty MaterialProperties in stateful properties map?");
158 for (
const auto & prop : prop_vals)
159 n_q_points =
std::max(n_q_points, prop.size());
161 std::ostringstream oss;
163 stored_props[prop_id] = oss.str();
168 props_to_push[target_pid].emplace_back(
169 std::move(stored_props), elem->id(), n_q_points);
172 if (remote_pid && !local_pid)
173 elems_being_migrated.insert(elem);
176 auto recv_functor = [&, mat_prop_store_ptr = mat_prop_store](
179 for (
const auto & [elem_hash, elem_id, n_q_points] : data)
181 const Elem * elem =
mesh.elem_ptr(elem_id);
182 auto & elem_props = props_map[elem];
184 for (
const auto & [prop_id, prop_str] : elem_hash)
193 mat_prop_store_ptr->initProps(0, state, elem, prop_id, n_q_points);
195 mooseAssert(elem_props.contains(prop_id),
196 "Trying to load into a nonexistant property id?");
198 std::istringstream iss(prop_str);
204 Parallel::push_parallel_vector_data(
mesh.comm(), props_to_push, recv_functor);
208 for (
const Elem * elem : elems_being_migrated)
209 mat_prop_store->eraseProperty(elem);
HashMap is an abstraction for dictionary data type, we make it thread-safe by locking inserts...
Stores the stateful material properties computed by materials.
MooseMesh * _moose_mesh
Pointer to the MooseMesh object.
virtual std::string getInfo() const override
Method for returning relationship manager information (suitable for console output).
void dataLoad(std::istream &stream, PenetrationInfo *&pinfo, void *context)
std::map< const Elem *, const CouplingMatrix *, CompareDofObjectsByPIDAndThenID > map_type
std::unique_ptr< T > copyConstruct(const T &object)
Copy constructs the object object.
Factory & getFactory()
Retrieve a writable reference to the Factory associated with this App.
auto max(const L &left, const R &right)
RedistributeProperties(const InputParameters ¶meters)
uint8_t processor_id_type
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
std::vector< MaterialPropertyStorage * > _materials
virtual void operator()(const MeshBase::const_element_iterator &range_begin, const MeshBase::const_element_iterator &range_end, processor_id_type p, map_type &coupled_elements) override
This function doesn't actually add anything to coupled_elements - we solely use the redistribute() ov...
MooseApp & _app
The MOOSE application this is associated with.
registerMooseObject("MooseApp", RedistributeProperties)
virtual void redistribute() override
RelationshipManagers are used for describing what kinds of non-local resources are needed for an obje...
static InputParameters validParams()
void addMaterialPropertyStorage(MaterialPropertyStorage &mat_props)
Pushes the given pair ( mat_data , mat_props ) onto our list of _materials data to redistribute each ...
virtual bool operator>=(const RelationshipManager &rhs) const override
Whether this relationship manager provides more or the same amount and type of ghosting as the rhs...
void dataStore(std::ostream &stream, PenetrationInfo *&pinfo, void *context)
virtual std::unique_ptr< GhostingFunctor > clone() const override
Abstract GhostingFunctor code relies on clone(), which for us is just a copy construction into a new ...
static InputParameters validParams()
RedistributeProperties is used for its redistribute() callback, which ensures that any stateful prope...