Skip to content

Commit 0071d63

Browse files
committed
Pass only retained nodes to MueLu
1 parent e6b2ae9 commit 0071d63

17 files changed

+109
-40
lines changed

src/core/fem/src/discretization/4C_fem_discretization.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -563,12 +563,13 @@ void Core::FE::Discretization::replace_dof_set(
563563

564564
/*----------------------------------------------------------------------*
565565
*----------------------------------------------------------------------*/
566-
std::map<int, std::vector<int>>* Core::FE::Discretization::get_all_pbc_coupled_col_nodes()
566+
const std::map<int, std::vector<int>>* Core::FE::Discretization::get_all_pbc_coupled_col_nodes()
567+
const
567568
{
568569
// check for pbcs
569570
for (int nds = 0; nds < num_dof_sets(); nds++)
570571
{
571-
std::shared_ptr<Core::DOFSets::PBCDofSet> pbcdofset =
572+
std::shared_ptr<const Core::DOFSets::PBCDofSet> pbcdofset =
572573
std::dynamic_pointer_cast<Core::DOFSets::PBCDofSet>(dofsets_[nds]);
573574

574575
if (pbcdofset != nullptr)
@@ -584,8 +585,8 @@ std::map<int, std::vector<int>>* Core::FE::Discretization::get_all_pbc_coupled_c
584585

585586
/*----------------------------------------------------------------------*
586587
*----------------------------------------------------------------------*/
587-
std::shared_ptr<std::map<int, int>>
588-
Core::FE::Discretization::get_pbc_slave_to_master_node_connectivity()
588+
std::shared_ptr<const std::map<int, int>>
589+
Core::FE::Discretization::get_pbc_slave_to_master_node_connectivity() const
589590
{
590591
// check for pbcs
591592
for (int nds = 0; nds < num_dof_sets(); nds++)

src/core/fem/src/discretization/4C_fem_discretization.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,12 +622,12 @@ namespace Core::FE
622622
/*!
623623
\brief Get master to slave coupling in case of periodic boundary conditions
624624
*/
625-
std::map<int, std::vector<int>>* get_all_pbc_coupled_col_nodes();
625+
const std::map<int, std::vector<int>>* get_all_pbc_coupled_col_nodes() const;
626626

627627
/*!
628628
\brief Get slave to master connectivity in case of periodic boundary conditions
629629
*/
630-
std::shared_ptr<std::map<int, int>> get_pbc_slave_to_master_node_connectivity();
630+
std::shared_ptr<const std::map<int, int>> get_pbc_slave_to_master_node_connectivity() const;
631631

632632
//@}
633633

src/core/fem/src/discretization/4C_fem_discretization_faces.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ void Core::FE::DiscretizationFaces::build_faces(const bool verbose)
239239
std::map<std::vector<int>, std::shared_ptr<Core::Elements::Element>> faces;
240240

241241
// get pbcs
242-
std::map<int, std::vector<int>>* col_pbcmapmastertoslave = get_all_pbc_coupled_col_nodes();
242+
const std::map<int, std::vector<int>>* col_pbcmapmastertoslave = get_all_pbc_coupled_col_nodes();
243243

244244
std::map<std::vector<int>, InternalFacesData>::iterator face_it;
245245
for (face_it = surfmapdata.begin(); face_it != surfmapdata.end(); ++face_it)
@@ -383,11 +383,11 @@ void Core::FE::DiscretizationFaces::build_faces(const bool verbose)
383383
for (std::size_t rr = 0; rr < mymasternodeids.size(); rr++)
384384
{
385385
// this master node has one slave node
386-
if (((*col_pbcmapmastertoslave)[mymasternodeids[rr]]).size() == 1)
386+
if (((*col_pbcmapmastertoslave).at(mymasternodeids[rr])).size() == 1)
387387
{
388-
myslavenodeids.push_back(((*col_pbcmapmastertoslave)[mymasternodeids[rr]])[0]);
388+
myslavenodeids.push_back(((*col_pbcmapmastertoslave).at(mymasternodeids[rr]))[0]);
389389
local_pbcmapmastertoslave[mymasternodeids[rr]] =
390-
((*col_pbcmapmastertoslave)[mymasternodeids[rr]])[0];
390+
((*col_pbcmapmastertoslave).at(mymasternodeids[rr]))[0];
391391
}
392392
// this master node has several slave nodes
393393
// it is a corner or edge node of two or three pbc sets
@@ -443,7 +443,7 @@ void Core::FE::DiscretizationFaces::build_faces(const bool verbose)
443443
// this special case is marked by flag
444444
bool three_sets_edge_node = false;
445445
if (numpbcpairs == 3 and
446-
((*col_pbcmapmastertoslave)[mymasternodeids[rr]]).size() == 3)
446+
((*col_pbcmapmastertoslave).at(mymasternodeids[rr])).size() == 3)
447447
three_sets_edge_node = true;
448448

449449
// pbc id of master face also for the slave
@@ -459,10 +459,10 @@ void Core::FE::DiscretizationFaces::build_faces(const bool verbose)
459459
// check which node fulfills above conditions
460460
int actslaveid = -999;
461461
for (std::size_t islave = 0;
462-
islave < ((*col_pbcmapmastertoslave)[mymasternodeids[rr]]).size(); islave++)
462+
islave < ((*col_pbcmapmastertoslave).at(mymasternodeids[rr])).size(); islave++)
463463
{
464464
// get id
465-
actslaveid = ((*col_pbcmapmastertoslave)[mymasternodeids[rr]])[islave];
465+
actslaveid = ((*col_pbcmapmastertoslave).at(mymasternodeids[rr]))[islave];
466466

467467
// check first criterion -> (i)
468468
if ((slavetopbcset[slavepbcid]).find(actslaveid) !=
@@ -547,7 +547,7 @@ void Core::FE::DiscretizationFaces::build_faces(const bool verbose)
547547

548548
// first, look for masters with more than one slave
549549
// then, check whether node id (i.e. actnodeid) is contained in slave list
550-
std::map<int, std::vector<int>>::iterator master_it;
550+
std::map<int, std::vector<int>>::const_iterator master_it;
551551
for (master_it = col_pbcmapmastertoslave->begin();
552552
master_it != col_pbcmapmastertoslave->end(); master_it++)
553553
{

src/core/fem/src/discretization/4C_fem_discretization_partition.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ void Core::FE::Discretization::extended_ghosting(const Core::LinAlg::Map& elecol
569569
{
570570
have_pbc = true;
571571
// fill content of pbcmap int std::map<int, std::set<int> > in preparation for gather_all
572-
std::map<int, std::vector<int>>* tmp = pbcdofset->get_coupled_nodes();
572+
const std::map<int, std::vector<int>>* tmp = pbcdofset->get_coupled_nodes();
573573
for (auto& [gid, nodes] : *tmp) pbcmap[gid].insert(nodes.begin(), nodes.end());
574574

575575
// it is assumed that, if one pbc set is available, all other potential dofsets hold the same

src/core/fem/src/discretization/4C_fem_discretization_utils.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "4C_fem_discretization_utils.hpp"
99

10+
#include "4C_comm_mpi_utils.hpp"
1011
#include "4C_fem_discretization.hpp"
1112
#include "4C_fem_general_element.hpp"
1213
#include "4C_fem_general_node.hpp"
@@ -48,6 +49,57 @@ std::shared_ptr<Core::LinAlg::MultiVector<double>> Core::FE::extract_node_coordi
4849
return coordinates;
4950
}
5051

52+
std::unique_ptr<Core::LinAlg::MultiVector<double>> Core::FE::extract_retained_node_coordinates(
53+
const Discretization& discretization, const Core::LinAlg::Map& node_row_map)
54+
{
55+
std::set<int> skipped_nodes = {};
56+
if (discretization.get_pbc_slave_to_master_node_connectivity())
57+
{
58+
const auto& pbcconnectivity = *(discretization.get_pbc_slave_to_master_node_connectivity());
59+
for (const auto& [slave, _] : pbcconnectivity)
60+
{
61+
skipped_nodes.insert(slave);
62+
}
63+
}
64+
std::set<int> fully_redundant_skipped_nodes =
65+
Core::Communication::all_reduce(skipped_nodes, node_row_map.get_comm());
66+
67+
std::vector<int> my_filtered_global_node_ids{};
68+
my_filtered_global_node_ids.reserve(node_row_map.num_my_elements());
69+
for (int lid = 0; lid < node_row_map.num_my_elements(); ++lid)
70+
{
71+
const int gid = node_row_map.gid(lid);
72+
73+
// filter pbc slave nodes
74+
if (fully_redundant_skipped_nodes.contains(gid)) continue;
75+
my_filtered_global_node_ids.emplace_back(gid);
76+
}
77+
Core::LinAlg::Map filtered_row_map(
78+
node_row_map.num_global_elements() - static_cast<int>(fully_redundant_skipped_nodes.size()),
79+
static_cast<int>(my_filtered_global_node_ids.size()), my_filtered_global_node_ids.data(), 0,
80+
node_row_map.get_comm());
81+
82+
std::unique_ptr<Core::LinAlg::MultiVector<double>> coordinates =
83+
std::make_unique<Core::LinAlg::MultiVector<double>>(filtered_row_map, 3, true);
84+
85+
for (int lid = 0; lid < filtered_row_map.num_my_elements(); ++lid)
86+
{
87+
const int gid = filtered_row_map.gid(lid);
88+
if (!discretization.have_global_node(gid)) continue;
89+
90+
auto x = discretization.g_node(gid)->x();
91+
for (size_t dim = 0; dim < 3; ++dim)
92+
{
93+
if (dim >= discretization.n_dim())
94+
coordinates->replace_local_value(lid, dim, 0.0);
95+
else
96+
coordinates->replace_local_value(lid, dim, x[dim]);
97+
}
98+
}
99+
100+
return coordinates;
101+
}
102+
51103

52104
/*----------------------------------------------------------------------------*
53105
*----------------------------------------------------------------------------*/

src/core/fem/src/discretization/4C_fem_discretization_utils.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ namespace Core::FE
6060
std::shared_ptr<Core::LinAlg::MultiVector<double>> extract_node_coordinates(
6161
const Core::FE::Discretization& discretization, const Core::LinAlg::Map& node_row_map);
6262

63+
/**
64+
* Similar to the other extract_node_coordinates function, but allows to specify a node row map
65+
* and filters all eliminated nodes (e.g., in periodic boundary conditions).
66+
*
67+
* @note Eliminated nodes (e.g., when using periodic boundary conditions) are skipped.
68+
*
69+
* The map has to be a submap of the overall full node rowmap of this discretization.
70+
*/
71+
std::unique_ptr<Core::LinAlg::MultiVector<double>> extract_retained_node_coordinates(
72+
const Core::FE::Discretization& discretization, const Core::LinAlg::Map& node_row_map);
73+
6374

6475
/** \brief Evaluate the elements of the given discretization and fill the
6576
* system matrix and vector

src/core/fem/src/dofset/4C_fem_dofset_pbc.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,14 @@ namespace Core::DOFSets
7070
virtual void set_coupled_nodes(std::shared_ptr<std::map<int, std::vector<int>>> couplednodes);
7171

7272
/// Get coupled nodes map (corresponding col format)
73-
std::map<int, std::vector<int>>* get_coupled_nodes() { return perbndcouples_.get(); }
73+
[[nodiscard]] const std::map<int, std::vector<int>>* get_coupled_nodes() const
74+
{
75+
return perbndcouples_.get();
76+
}
7477

7578
/// Get connectivity map between slave node and its master node
76-
virtual std::shared_ptr<std::map<int, int>> get_slave_to_master_node_connectivity()
79+
[[nodiscard]] virtual std::shared_ptr<const std::map<int, int>>
80+
get_slave_to_master_node_connectivity() const
7781
{
7882
return perbnd_slavetomaster_;
7983
};

src/core/fem/src/general/utils/4C_fem_general_l2_projection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ std::shared_ptr<Core::LinAlg::MultiVector<double>> Core::FE::compute_nodal_l2_pr
135135
// build inverse map from slave to master nodes
136136
std::map<int, int> slavetomastercolnodesmap;
137137

138-
std::map<int, std::vector<int>>* allcoupledcolnodes = dis.get_all_pbc_coupled_col_nodes();
138+
const std::map<int, std::vector<int>>* allcoupledcolnodes = dis.get_all_pbc_coupled_col_nodes();
139139
if (allcoupledcolnodes)
140140
{
141141
for (auto [master_gid, slave_gids] : *allcoupledcolnodes)

src/core/fem/src/general/utils/4C_fem_general_utils_superconvergent_patch_recovery.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ std::shared_ptr<Core::LinAlg::MultiVector<double>> Core::FE::compute_superconver
4141
// handle pbcs if existing
4242
// build inverse map from slave to master nodes
4343
std::map<int, int> slavetomastercolnodesmap;
44-
std::map<int, std::vector<int>>* allcoupledcolnodes = dis.get_all_pbc_coupled_col_nodes();
44+
const std::map<int, std::vector<int>>* allcoupledcolnodes = dis.get_all_pbc_coupled_col_nodes();
4545

4646
if (allcoupledcolnodes)
4747
{
@@ -432,8 +432,7 @@ std::shared_ptr<Core::LinAlg::MultiVector<double>> Core::FE::compute_superconver
432432
// this will result in off processor assembling (boundary node as ghost node)
433433
if (closestnode->owner() != myrank) continue;
434434

435-
std::map<int, std::vector<int>>::iterator masternode =
436-
allcoupledcolnodes->find(closestnodeid);
435+
auto masternode = allcoupledcolnodes->find(closestnodeid);
437436

438437
int numslavenodes = -1;
439438
if (masternode != allcoupledcolnodes->end())

src/core/linear_solver/src/method/4C_linear_solver_method_parameters.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ void Core::LinearSolver::Parameters::compute_solver_parameters(
8686
{
8787
std::shared_ptr<Core::LinAlg::MultiVector<double>> coordinates;
8888
if (nullspace_node_map == nullptr)
89-
coordinates = extract_node_coordinates(dis);
89+
coordinates = extract_retained_node_coordinates(dis, *dis.node_row_map());
9090
else
91-
coordinates = extract_node_coordinates(dis, *nullspace_node_map);
91+
coordinates = extract_retained_node_coordinates(dis, *nullspace_node_map);
9292

9393
solverlist.set<std::shared_ptr<Core::LinAlg::MultiVector<double>>>("Coordinates", coordinates);
9494
}

0 commit comments

Comments
 (0)