Skip to content

Commit 434c10b

Browse files
committed
Use caches when returning or counting subdomains
Especially n_subdomains() should be an O(1) call, not O(N).
1 parent 9d8aef7 commit 434c10b

2 files changed

Lines changed: 9 additions & 26 deletions

File tree

include/mesh/mesh_base.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,6 +1492,8 @@ class MeshBase : public ParallelObject
14921492
* materials in a solid mechanics application, or regions where different
14931493
* physical processes are important. The subdomain mapping is independent
14941494
* from the parallel decomposition.
1495+
*
1496+
* This relies on the mesh cached element data being prepared.
14951497
*/
14961498
subdomain_id_type n_subdomains () const;
14971499

@@ -1501,6 +1503,8 @@ class MeshBase : public ParallelObject
15011503
* materials in a solid mechanics application, or regions where different
15021504
* physical processes are important. The subdomain mapping is independent
15031505
* from the parallel decomposition.
1506+
*
1507+
* This relies on the mesh cached element data being prepared.
15041508
*/
15051509
subdomain_id_type n_local_subdomains () const;
15061510

src/mesh/mesh_base.C

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,26 +1080,12 @@ void MeshBase::remove_ghosting_functor(GhostingFunctor & ghosting_functor)
10801080

10811081
void MeshBase::subdomain_ids (std::set<subdomain_id_type> & ids, const bool global /* = true */) const
10821082
{
1083-
// This requires an inspection on every processor
1084-
if (global)
1085-
parallel_object_only();
1086-
1087-
ids.clear();
1088-
1089-
for (const auto & elem : this->active_local_element_ptr_range())
1090-
ids.insert(elem->subdomain_id());
1083+
libmesh_assert(this->has_cached_elem_data());
10911084

10921085
if (global)
1093-
{
1094-
// Only include the unpartitioned elements if the user requests the global IDs.
1095-
// In the case of the local subdomain IDs, it doesn't make sense to include the
1096-
// unpartitioned elements because said elements do not have a sense of locality.
1097-
for (const auto & elem : this->active_unpartitioned_element_ptr_range())
1098-
ids.insert(elem->subdomain_id());
1099-
1100-
// Some subdomains may only live on other processors
1101-
this->comm().set_union(ids);
1102-
}
1086+
ids = this->get_mesh_subdomains();
1087+
else
1088+
ids = this->get_mesh_local_subdomains();
11031089
}
11041090

11051091

@@ -1128,14 +1114,7 @@ void MeshBase::update_post_partitioning()
11281114

11291115
subdomain_id_type MeshBase::n_subdomains() const
11301116
{
1131-
// This requires an inspection on every processor
1132-
parallel_object_only();
1133-
1134-
std::set<subdomain_id_type> ids;
1135-
1136-
this->subdomain_ids (ids);
1137-
1138-
return cast_int<subdomain_id_type>(ids.size());
1117+
return cast_int<subdomain_id_type>(this->get_mesh_subdomains().size());
11391118
}
11401119

11411120

0 commit comments

Comments
 (0)