Skip to content

Commit 25f5d87

Browse files
committed
Factor out added_side node offset calculations
1 parent 6e0c302 commit 25f5d87

2 files changed

Lines changed: 70 additions & 54 deletions

File tree

include/mesh/exodusII_io_helper.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,12 @@ class ExodusII_IO_Helper : public ParallelObject
952952
dof_id_type added_node_offset_on(processor_id_type p) const;
953953

954954
protected:
955+
/**
956+
* Calculate _added_side_node_offsets needed to add "fake" side
957+
* elements to the given mesh
958+
*/
959+
void calculate_added_side_node_offsets(const MeshBase & mesh);
960+
955961
/**
956962
* When appending: during initialization, check that variable names
957963
* in the file match those you attempt to initialize with.

src/mesh/exodusII_io_helper.C

Lines changed: 64 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2310,60 +2310,9 @@ void ExodusII_IO_Helper::initialize(std::string str_title, const MeshBase & mesh
23102310
num_elem = n_active_elem;
23112311
num_nodes = 0;
23122312

2313-
// If we're adding face elements they'll need copies of their nodes.
2314-
// We also have to count of how many nodes (and gaps between nodes!)
2315-
// are on each processor, to calculate offsets for any nodal data
2316-
// writing later.
2317-
_added_side_node_offsets.clear();
2318-
if (_add_sides)
2319-
{
2320-
dof_id_type num_side_elem = 0;
2321-
dof_id_type num_local_side_nodes = 0;
2322-
2323-
for (const auto & elem : mesh.active_local_element_ptr_range())
2324-
{
2325-
for (auto s : elem->side_index_range())
2326-
{
2327-
if (EquationSystems::redundant_added_side(*elem,s))
2328-
continue;
2329-
2330-
num_side_elem++;
2331-
num_local_side_nodes += elem->nodes_on_side(s).size();
2332-
}
2333-
}
2334-
2335-
mesh.comm().sum(num_side_elem);
2336-
num_elem += num_side_elem;
2337-
2338-
mesh.comm().allgather(num_local_side_nodes, _added_side_node_offsets);
2339-
const processor_id_type n_proc = mesh.n_processors();
2340-
libmesh_assert_equal_to(n_proc, _added_side_node_offsets.size());
2341-
2342-
for (auto p : make_range(n_proc-1))
2343-
_added_side_node_offsets[p+1] += _added_side_node_offsets[p];
2344-
2345-
num_nodes = _added_side_node_offsets[n_proc-1];
2346-
2347-
dof_id_type n_local_nodes = cast_int<dof_id_type>
2348-
(std::distance(mesh.local_nodes_begin(),
2349-
mesh.local_nodes_end()));
2350-
dof_id_type n_total_nodes = n_local_nodes;
2351-
mesh.comm().sum(n_total_nodes);
2352-
2353-
const dof_id_type max_nn = mesh.max_node_id();
2354-
const dof_id_type n_gaps = max_nn - n_total_nodes;
2355-
const dof_id_type gaps_per_processor = n_gaps / n_proc;
2356-
const dof_id_type remainder_gaps = n_gaps % n_proc;
2357-
2358-
n_local_nodes = n_local_nodes + // Actual nodes
2359-
gaps_per_processor + // Our even share of gaps
2360-
(mesh.processor_id() < remainder_gaps); // Leftovers
2361-
2362-
mesh.comm().allgather(n_local_nodes, _true_node_offsets);
2363-
for (auto p : make_range(n_proc-1))
2364-
_true_node_offsets[p+1] += _true_node_offsets[p];
2365-
libmesh_assert_equal_to(_true_node_offsets[n_proc-1], mesh.max_node_id());
2366-
}
2313+
// If we're adding face elements they'll need copies of their nodes,
2314+
// and we'll need to manage the extra copies.
2315+
this->calculate_added_side_node_offsets(mesh);
23672316

23682317
// If _write_as_dimension is nonzero, use it to set num_dim in the Exodus file.
23692318
if (_write_as_dimension)
@@ -4949,6 +4898,67 @@ void ExodusII_IO_Helper::build_subdomain_map(const MeshBase & mesh, bool local)
49494898

49504899

49514900

4901+
void ExodusII_IO_Helper::calculate_added_side_node_offsets(const MeshBase & mesh)
4902+
{
4903+
4904+
// If we're adding face elements they'll need copies of their nodes.
4905+
// We also have to count of how many nodes (and gaps between nodes!)
4906+
// are on each processor, to calculate offsets for any nodal data
4907+
// writing later.
4908+
_added_side_node_offsets.clear();
4909+
if (!_add_sides)
4910+
return;
4911+
4912+
dof_id_type num_side_elem = 0;
4913+
dof_id_type num_local_side_nodes = 0;
4914+
4915+
for (const auto & elem : mesh.active_local_element_ptr_range())
4916+
{
4917+
for (auto s : elem->side_index_range())
4918+
{
4919+
if (EquationSystems::redundant_added_side(*elem,s))
4920+
continue;
4921+
4922+
num_side_elem++;
4923+
num_local_side_nodes += elem->nodes_on_side(s).size();
4924+
}
4925+
}
4926+
4927+
mesh.comm().sum(num_side_elem);
4928+
num_elem += num_side_elem;
4929+
4930+
mesh.comm().allgather(num_local_side_nodes, _added_side_node_offsets);
4931+
const processor_id_type n_proc = mesh.n_processors();
4932+
libmesh_assert_equal_to(n_proc, _added_side_node_offsets.size());
4933+
4934+
for (auto p : make_range(n_proc-1))
4935+
_added_side_node_offsets[p+1] += _added_side_node_offsets[p];
4936+
4937+
num_nodes = _added_side_node_offsets[n_proc-1];
4938+
4939+
dof_id_type n_local_nodes = cast_int<dof_id_type>
4940+
(std::distance(mesh.local_nodes_begin(),
4941+
mesh.local_nodes_end()));
4942+
dof_id_type n_total_nodes = n_local_nodes;
4943+
mesh.comm().sum(n_total_nodes);
4944+
4945+
const dof_id_type max_nn = mesh.max_node_id();
4946+
const dof_id_type n_gaps = max_nn - n_total_nodes;
4947+
const dof_id_type gaps_per_processor = n_gaps / n_proc;
4948+
const dof_id_type remainder_gaps = n_gaps % n_proc;
4949+
4950+
n_local_nodes = n_local_nodes + // Actual nodes
4951+
gaps_per_processor + // Our even share of gaps
4952+
(mesh.processor_id() < remainder_gaps); // Leftovers
4953+
4954+
mesh.comm().allgather(n_local_nodes, _true_node_offsets);
4955+
for (auto p : make_range(n_proc-1))
4956+
_true_node_offsets[p+1] += _true_node_offsets[p];
4957+
libmesh_assert_equal_to(_true_node_offsets[n_proc-1], mesh.max_node_id());
4958+
}
4959+
4960+
4961+
49524962
dof_id_type ExodusII_IO_Helper::node_id_to_vec_id(dof_id_type n) const
49534963
{
49544964
if (_added_side_node_offsets.empty())

0 commit comments

Comments
 (0)