Skip to content

Commit 9d8aef7

Browse files
committed
Add a _mesh_local_subdomains cache
1 parent ee0cca4 commit 9d8aef7

3 files changed

Lines changed: 36 additions & 2 deletions

File tree

include/mesh/mesh_base.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,7 @@ class MeshBase : public ParallelObject
13291329
* Recalculate any cached data after elements and nodes have been
13301330
* repartitioned.
13311331
*/
1332-
virtual void update_post_partitioning () {}
1332+
virtual void update_post_partitioning ();
13331333

13341334
/**
13351335
* If false is passed in then this mesh will no longer be renumbered
@@ -1993,6 +1993,15 @@ class MeshBase : public ParallelObject
19931993
const std::set<subdomain_id_type> & get_mesh_subdomains() const
19941994
{ libmesh_assert(this->is_prepared()); return _mesh_subdomains; }
19951995

1996+
1997+
/**
1998+
* \return The cached mesh subdomains. As long as the mesh is prepared, this
1999+
* should contain all the subdomain ids across processors. Relies on the mesh
2000+
* being prepared
2001+
*/
2002+
const std::set<subdomain_id_type> & get_mesh_local_subdomains() const
2003+
{ libmesh_assert(this->is_prepared()); return _mesh_local_subdomains; }
2004+
19962005
#ifdef LIBMESH_ENABLE_PERIODIC
19972006
/**
19982007
* Register a pair of boundaries as disjoint neighbor boundary pairs.
@@ -2257,6 +2266,12 @@ class MeshBase : public ParallelObject
22572266
*/
22582267
std::set<subdomain_id_type> _mesh_subdomains;
22592268

2269+
/**
2270+
* We also cache the subdomain ids of the elements owned by this
2271+
* processor.
2272+
*/
2273+
std::set<subdomain_id_type> _mesh_local_subdomains;
2274+
22602275
/**
22612276
* Map from "element set code" to list of set ids to which that element
22622277
* belongs (and vice-versa). Remarks:

src/mesh/distributed_mesh.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ void DistributedMesh::redistribute ()
10601060

10611061
void DistributedMesh::update_post_partitioning ()
10621062
{
1063-
// this->recalculate_n_partitions();
1063+
this->UnstructuredMesh::update_post_partitioning();
10641064

10651065
// Partitioning changes our numbers of unpartitioned objects
10661066
this->update_parallel_id_counts();

src/mesh/mesh_base.C

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ MeshBase::MeshBase (const MeshBase & other_mesh) :
120120
_elem_default_orders(other_mesh._elem_default_orders),
121121
_supported_nodal_order(other_mesh._supported_nodal_order),
122122
_mesh_subdomains(other_mesh._mesh_subdomains),
123+
_mesh_local_subdomains(other_mesh._mesh_local_subdomains),
123124
_elemset_codes_inverse_map(other_mesh._elemset_codes_inverse_map),
124125
_all_elemset_ids(other_mesh._all_elemset_ids),
125126
_spatial_dimension(other_mesh._spatial_dimension),
@@ -209,6 +210,7 @@ MeshBase& MeshBase::operator= (MeshBase && other_mesh)
209210
_elem_default_orders = std::move(other_mesh.elem_default_orders());
210211
_supported_nodal_order = other_mesh.supported_nodal_order();
211212
_mesh_subdomains = other_mesh._mesh_subdomains;
213+
_mesh_local_subdomains = other_mesh._mesh_local_subdomains;
212214
_elemset_codes = std::move(other_mesh._elemset_codes);
213215
_elemset_codes_inverse_map = std::move(other_mesh._elemset_codes_inverse_map);
214216
_all_elemset_ids = std::move(other_mesh._all_elemset_ids);
@@ -325,6 +327,8 @@ bool MeshBase::locally_equals (const MeshBase & other_mesh) const
325327
return false;
326328
if (_mesh_subdomains != other_mesh._mesh_subdomains)
327329
return false;
330+
if (_mesh_local_subdomains != other_mesh._mesh_local_subdomains)
331+
return false;
328332
if (_all_elemset_ids != other_mesh._all_elemset_ids)
329333
return false;
330334
if (_elem_integer_names != other_mesh._elem_integer_names)
@@ -1112,6 +1116,16 @@ void MeshBase::redistribute()
11121116

11131117

11141118

1119+
void MeshBase::update_post_partitioning()
1120+
{
1121+
_mesh_local_subdomains.clear();
1122+
1123+
for (const Elem * elem : this->active_local_element_ptr_range())
1124+
_mesh_local_subdomains.insert(elem->subdomain_id());
1125+
}
1126+
1127+
1128+
11151129
subdomain_id_type MeshBase::n_subdomains() const
11161130
{
11171131
// This requires an inspection on every processor
@@ -1860,13 +1874,16 @@ void MeshBase::cache_elem_data()
18601874
_elem_dims.clear();
18611875
_elem_default_orders.clear();
18621876
_mesh_subdomains.clear();
1877+
_mesh_local_subdomains.clear();
18631878
_supported_nodal_order = MAXIMUM;
18641879

18651880
for (const auto & elem : this->active_element_ptr_range())
18661881
{
18671882
_elem_dims.insert(cast_int<unsigned char>(elem->dim()));
18681883
_elem_default_orders.insert(elem->default_order());
18691884
_mesh_subdomains.insert(elem->subdomain_id());
1885+
if (elem->processor_id() == this->processor_id())
1886+
_mesh_local_subdomains.insert(elem->subdomain_id());
18701887
_supported_nodal_order =
18711888
static_cast<Order>
18721889
(std::min(static_cast<int>(_supported_nodal_order),
@@ -2220,6 +2237,7 @@ MeshBase::copy_cached_data(const MeshBase & other_mesh)
22202237
this->_elem_default_orders = other_mesh._elem_default_orders;
22212238
this->_supported_nodal_order = other_mesh._supported_nodal_order;
22222239
this->_mesh_subdomains = other_mesh._mesh_subdomains;
2240+
this->_mesh_local_subdomains = other_mesh._mesh_local_subdomains;
22232241
}
22242242

22252243

@@ -2474,6 +2492,7 @@ MeshBase::copy_constraint_rows(const SparseMatrix<T> & constraint_operator,
24742492
(std::min(static_cast<int>(this->_supported_nodal_order),
24752493
static_cast<int>(added_elem->supported_nodal_order())));
24762494
this->_mesh_subdomains.insert(new_sbd_id);
2495+
this->_mesh_local_subdomains.insert(new_sbd_id);
24772496
node_to_elem_ptrs.emplace(n, std::make_pair(added_elem->id(), 0));
24782497
existing_unconstrained_columns.emplace(j,n->id());
24792498

0 commit comments

Comments
 (0)