38 _is_serial_on_proc_0(true),
39 _n_nodes(0), _n_elem(0), _max_node_id(0), _max_elem_id(0),
40 _next_free_local_node_id(this->processor_id()),
41 _next_free_local_elem_id(this->processor_id()),
42 _next_free_unpartitioned_node_id(this->n_processors()),
43 _next_free_unpartitioned_elem_id(this->n_processors())
44 #ifdef LIBMESH_ENABLE_UNIQUE_ID
45 , _next_unpartitioned_unique_id(this->n_processors())
48 #ifdef LIBMESH_ENABLE_UNIQUE_ID 53 _partitioner = libmesh_make_unique<ParmetisPartitioner>();
69 _is_serial_on_proc_0(other_mesh._is_serial_on_proc_0),
70 _n_nodes(0), _n_elem(0), _max_node_id(0), _max_elem_id(0),
71 _next_free_local_node_id(this->processor_id()),
72 _next_free_local_elem_id(this->processor_id()),
73 _next_free_unpartitioned_node_id(this->n_processors()),
74 _next_free_unpartitioned_elem_id(this->n_processors())
89 #ifdef LIBMESH_ENABLE_UNIQUE_ID 106 _is_serial_on_proc_0(other_mesh.is_serial()),
107 _n_nodes(0), _n_elem(0), _max_node_id(0), _max_elem_id(0),
108 _next_free_local_node_id(this->processor_id()),
109 _next_free_local_elem_id(this->processor_id()),
110 _next_free_unpartitioned_node_id(this->n_processors()),
111 _next_free_unpartitioned_elem_id(this->n_processors())
116 #ifdef LIBMESH_ENABLE_UNIQUE_ID 130 parallel_object_only();
155 #ifdef LIBMESH_ENABLE_UNIQUE_ID 172 parallel_object_only();
185 parallel_object_only();
198 for (; rit != rend; ++rit)
201 libmesh_assert_equal_to(rit->second->id(), rit->first);
202 max_local = rit->first + 1;
212 #ifdef LIBMESH_ENABLE_UNIQUE_ID 216 parallel_object_only();
230 parallel_object_only();
243 parallel_object_only();
256 for (; rit != rend; ++rit)
259 libmesh_assert_equal_to(rit->second->id(), rit->first);
260 max_local = rit->first + 1;
279 libmesh_assert(
_nodes[i]);
280 libmesh_assert_equal_to (
_nodes[i]->
id(), i);
290 libmesh_assert(
_nodes[i]);
291 libmesh_assert_equal_to (
_nodes[i]->
id(), i);
301 std::map<dof_id_type, Node *>::const_iterator it =
_nodes.find(i);
302 if (it !=
_nodes.end().it)
304 const Node * n = it->second;
305 libmesh_assert (!n || n->
id() == i);
317 std::map<dof_id_type, Node *>::const_iterator it =
_nodes.find(i);
318 if (it !=
_nodes.end().it)
320 Node * n = it->second;
321 libmesh_assert (!n || n->
id() == i);
334 libmesh_assert_equal_to (
_elements[i]->
id(), i);
345 libmesh_assert_equal_to (
_elements[i]->
id(), i);
355 std::map<dof_id_type, Elem *>::const_iterator it =
_elements.find(i);
358 const Elem * e = it->second;
359 libmesh_assert (!e || e->
id() == i);
371 std::map<dof_id_type, Elem *>::const_iterator it =
_elements.find(i);
375 libmesh_assert (!e || e->
id() == i);
417 static_cast<dof_id_type>(e->
id()+1));
447 #ifdef LIBMESH_ENABLE_UNIQUE_ID 486 #ifdef LIBMESH_ENABLE_UNIQUE_ID 548 libmesh_assert_equal_to (el->
id(), old_id);
562 auto n_it =
_nodes.find(
id);
563 if (n_it !=
_nodes.end().it)
565 Node * n = n_it->second;
567 libmesh_assert_equal_to (n->
id(), id);
570 n->processor_id() = proc_id;
585 libmesh_assert(
_nodes[n.
id()] == &n);
628 static_cast<dof_id_type>(n->
id()+1));
658 #ifdef LIBMESH_ENABLE_UNIQUE_ID 734 libmesh_assert_equal_to (nd->
id(), old_id);
746 #ifdef LIBMESH_ENABLE_NODE_CONSTRAINTS 756 libmesh_assert (!
_nodes[new_id]);
843 template <
typename T>
847 parallel_object_only();
855 T * obj = objects[i];
858 libmesh_assert(!obj || obj->id() == i);
864 libmesh_assert(this->
comm().semiverify(obj ? &dofid :
nullptr));
868 const dof_id_type procid = obj && obj->valid_processor_id() ?
870 libmesh_assert(this->
comm().semiverify(obj ? &procid :
nullptr));
890 #if defined(LIBMESH_ENABLE_UNIQUE_ID) && !defined(NDEBUG) 893 libmesh_assert(this->
comm().semiverify(obj ? &uniqueid :
nullptr));
912 parallel_object_only();
923 libmesh_assert(this->
comm().semiverify((el && el->
active()) ? &p_level :
nullptr));
933 #if defined(LIBMESH_ENABLE_AMR) && !defined(NDEBUG) 935 parallel_object_only();
943 unsigned int refinement_flag = el ?
945 unsigned int p_refinement_flag = el ?
948 libmesh_assert(this->
comm().semiverify(el ? &refinement_flag :
nullptr));
952 libmesh_assert(this->
comm().semiverify((el && el->
active()) ? &p_refinement_flag :
nullptr));
954 #endif // LIBMESH_ENABLE_AMR 959 template <
typename T>
964 parallel_object_only();
972 std::unordered_map<processor_id_type, dof_id_type>
973 ghost_objects_from_proc;
975 object_iterator it = objects.
begin();
976 object_iterator
end = objects.
end();
984 it = objects.
erase(it);
989 unpartitioned_objects++;
991 ghost_objects_from_proc[obj_procid]++;
998 std::vector<dof_id_type> objects_on_proc(this->
n_processors(), 0);
999 auto this_it = ghost_objects_from_proc.find(this->
processor_id());
1001 ((this_it == ghost_objects_from_proc.end()) ? 0 : this_it->second,
1005 libmesh_assert(this->
comm().verify(unpartitioned_objects));
1007 if (ghost_objects_from_proc.count(p))
1008 libmesh_assert_less_equal (ghost_objects_from_proc[p], objects_on_proc[p]);
1010 libmesh_assert_less_equal (0, objects_on_proc[p]);
1014 std::vector<dof_id_type> first_object_on_proc(this->
n_processors());
1016 first_object_on_proc[i] = first_object_on_proc[i-1] +
1017 objects_on_proc[i-1];
1022 unpartitioned_objects;
1028 std::map<processor_id_type, std::vector<dof_id_type>>
1033 auto ghost_end = ghost_objects_from_proc.end();
1037 const auto p_it = ghost_objects_from_proc.find(p);
1038 if (p_it != ghost_end)
1039 requested_ids[p].reserve(p_it->second);
1043 for (it = objects.
begin(); it !=
end; ++it)
1047 obj->set_id(next_id++);
1049 requested_ids[obj->processor_id()].push_back(obj->id());
1054 auto gather_functor =
1058 &first_object_on_proc,
1063 std::vector<dof_id_type> & new_ids)
1065 std::size_t ids_size = ids.size();
1066 new_ids.resize(ids_size);
1068 for (std::size_t i=0; i != ids_size; ++i)
1070 T * obj = objects[ids[i]];
1071 libmesh_assert(obj);
1072 libmesh_assert_equal_to (obj->processor_id(), this->
processor_id());
1073 new_ids[i] = obj->id();
1075 libmesh_assert_greater_equal (new_ids[i],
1077 libmesh_assert_less (new_ids[i],
1083 auto action_functor =
1086 &first_object_on_proc,
1091 const std::vector<dof_id_type> & ids,
1092 const std::vector<dof_id_type> &
data)
1097 T * obj = objects[ids[i]];
1098 libmesh_assert (obj);
1099 libmesh_assert_equal_to (obj->processor_id(), pid);
1100 libmesh_assert_greater_equal (
data[i],
1101 first_object_on_proc[pid]);
1102 libmesh_assert_less (
data[i],
1103 first_object_on_proc[pid] +
1104 objects_on_proc[pid]);
1105 obj->set_id(
data[i]);
1111 (this->
comm(), requested_ids, gather_functor, action_functor, ex);
1113 #ifdef LIBMESH_ENABLE_UNIQUE_ID 1114 auto unique_gather_functor =
1121 std::vector<unique_id_type> &
data)
1123 std::size_t ids_size = ids.size();
1124 data.resize(ids_size);
1126 for (std::size_t i=0; i != ids_size; ++i)
1128 T * obj = objects[ids[i]];
1129 libmesh_assert(obj);
1130 libmesh_assert_equal_to (obj->processor_id(), this->
processor_id());
1135 auto unique_action_functor =
1138 const std::vector<dof_id_type> & ids,
1139 const std::vector<unique_id_type> &
data)
1143 T * obj = objects[ids[i]];
1144 libmesh_assert (obj);
1145 libmesh_assert_equal_to (obj->processor_id(), pid);
1147 obj->set_unique_id() = (
data[i]);
1153 (this->
comm(), requested_ids, unique_gather_functor,
1154 unique_action_functor, unique_ex);
1160 next_id += objects_on_proc[i];
1161 for (it = objects.
begin(); it !=
end; ++it)
1165 obj->set_id(next_id++);
1170 it = objects.
begin();
1177 T *
next = objects[obj->id()];
1191 libmesh_assert_not_equal_to (
next->id(), obj->id());
1192 objects[obj->id()] = obj;
1194 next = objects[obj->id()];
1196 objects[obj->id()] = obj;
1202 it = objects.
erase(it);
1207 return first_free_id;
1213 parallel_object_only();
1222 LOG_SCOPE(
"renumber_nodes_and_elements()",
"DistributedMesh");
1224 std::set<dof_id_type> used_nodes;
1242 else if (!used_nodes.count(nd->
id()))
1281 libmesh_assert_equal_to (this->
max_node_id(), pmax_node_id);
1282 libmesh_assert_equal_to (this->
max_elem_id(), pmax_elem_id);
1305 for (
auto & pr : nodes)
1306 if (pr.second !=
nullptr)
1307 pr.second->set_id() = pr.first;
1310 for (
const auto & pr : elems)
1311 if (pr.second !=
nullptr)
1312 pr.second->set_id() = pr.first;
1319 parallel_object_only();
1325 this->
comm().
sum(active_elements);
1333 return active_elements;
1355 libmesh_assert_equal_to (this->
max_node_id(), pmax_node_id);
1356 libmesh_assert_equal_to (this->
max_elem_id(), pmax_elem_id);
1370 while (e_it != e_end)
1378 while (n_it != n_end)
1380 n_it =
_nodes.erase(n_it);
1433 libmesh_assert_equal_to (this->
max_node_id(), pmax_node_id);
1434 libmesh_assert_equal_to (this->
max_elem_id(), pmax_elem_id);
virtual void copy_nodes_and_elements(const UnstructuredMesh &other_mesh, const bool skip_find_neighbors=false, dof_id_type element_id_offset=0, dof_id_type node_id_offset=0, unique_id_type unique_id_offset=0)
RefinementState refinement_flag() const
std::map< index_t, Val > maptype
virtual element_iterator active_local_elements_end() override
virtual void update_parallel_id_counts() override
unique_id_type & set_unique_id()
virtual dof_id_type parallel_n_nodes() const override
bool _skip_renumber_nodes_and_elements
mapvector< Elem *, dof_id_type > _elements
virtual const Elem * elem(const dof_id_type i) const
A geometric point in (x,y,z) space associated with a DOF.
void libmesh_assert_valid_parallel_object_ids(const mapvector< T *, dof_id_type > &) const
virtual unique_id_type parallel_max_unique_id() const =0
dof_id_type n_unpartitioned_nodes() const
virtual element_iterator active_pid_elements_begin(processor_id_type proc_id) override
const unsigned int invalid_uint
virtual void libmesh_assert_valid_parallel_ids() const override
virtual void fix_broken_node_and_element_numbering() override
virtual const Node * query_node_ptr(const dof_id_type i) const override
virtual void renumber_elem(dof_id_type old_id, dof_id_type new_id) override
bool _is_serial_on_proc_0
virtual dof_id_type max_node_id() const override
virtual void clear() override
void allgather(const T &send, std::vector< T, A > &recv) const
virtual void renumber_nodes_and_elements() override
RefinementState p_refinement_flag() const
dof_id_type _next_free_local_node_id
void remove(const Node *node)
virtual void allgather() override
virtual void own_node(Node &n) override
virtual dof_id_type n_active_elem() const override
The base class for all geometric element types.
IntRange< std::size_t > index_range(const std::vector< T > &vec)
uint8_t processor_id_type
dof_id_type n_local_nodes() const
const Parallel::Communicator & comm() const
unsigned int p_level() const
virtual void find_neighbors(const bool reset_remote_elements=false, const bool reset_current_list=true) override
void libmesh_assert_valid_parallel_flags() const
const BoundaryInfo & get_boundary_info() const
virtual void add_extra_ghost_elem(Elem *e)
dof_id_type n_unpartitioned_elem() const
long double max(long double a, double b)
virtual unique_id_type parallel_max_unique_id() const override
dof_id_type n_local_elem() const
virtual void delete_remote_elements() override
void libmesh_assert_valid_parallel_p_levels() const
virtual Elem * add_elem(Elem *e) override
unique_id_type _next_unique_id
dof_id_type renumber_dof_objects(mapvector< T *, dof_id_type > &)
processor_id_type n_processors() const
virtual dof_id_type parallel_n_elem() const override
mapvector< Node *, dof_id_type > _nodes
virtual Elem * insert_elem(Elem *e) override
void pull_parallel_vector_data(const Communicator &comm, const MapToVectors &queries, RequestContainer &reqs, GatherFunctor &gather_data, ActionFunctor &act_on_data, const datum *example)
virtual unsigned int n_nodes() const =0
static const unique_id_type invalid_unique_id
static const processor_id_type invalid_processor_id
std::set< Elem * > _extra_ghost_elems
Base class for Replicated and Distributed meshes.
virtual Node * insert_node(Node *n) override
virtual dof_id_type n_nodes() const override
std::unique_ptr< Partitioner > _partitioner
static const dof_id_type invalid_id
virtual void renumber_node(dof_id_type old_id, dof_id_type new_id) override
virtual Node * add_point(const Point &p, const dof_id_type id=DofObject::invalid_id, const processor_id_type proc_id=DofObject::invalid_processor_id) override
bool valid_unique_id() const
dof_id_type parallel_max_node_id() const
void allgather(DistributedMesh &mesh) const
virtual ~DistributedMesh()
Mesh data structure which is distributed across all processors.
virtual const Point & point(const dof_id_type i) const override
dof_id_type _next_free_unpartitioned_node_id
virtual const Elem * elem_ptr(const dof_id_type i) const override
virtual const Node & node(const dof_id_type i) const
virtual element_iterator active_pid_elements_end(processor_id_type proc_id) override
static std::unique_ptr< Node > build(const Node &n)
virtual void redistribute() override
virtual element_iterator active_local_elements_begin() override
dof_id_type _next_free_unpartitioned_elem_id
virtual const Node * node_ptr(const dof_id_type i) const override
DistributedMesh(const Parallel::Communicator &comm_in, unsigned char dim=1)
virtual void gather_to_zero() override
virtual dof_id_type n_elem() const override
virtual Node * add_node(Node *n) override
virtual SimpleRange< element_iterator > element_ptr_range() override
virtual const Node & node_ref(const dof_id_type i) const
virtual void update_post_partitioning() override
virtual const Elem * query_elem_ptr(const dof_id_type i) const override
unique_id_type _next_unpartitioned_unique_id
virtual void delete_node(Node *n) override
processor_id_type processor_id() const
void gather(const processor_id_type root_id, DistributedMesh &) const
dof_id_type _next_free_local_elem_id
processor_id_type processor_id() const
void delete_remote_elements(DistributedMesh &, const std::set< Elem *> &) const
virtual dof_id_type max_elem_id() const override
A geometric point in (x,y,z) space.
dof_id_type node_id(const unsigned int i) const
void redistribute(DistributedMesh &mesh, bool newly_coarsened_only=false) const
virtual bool is_serial() const override
dof_id_type parallel_max_elem_id() const
virtual void delete_elem(Elem *e) override