| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// MueLu: A package for multigrid based preconditioning |
| 4 |
// |
| 5 |
// Copyright 2012 NTESS and the MueLu contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
#ifndef MUELUTESTS_CONTACT_HELPERS_HPP_ |
| 11 |
#define MUELUTESTS_CONTACT_HELPERS_HPP_ |
| 12 |
|
| 13 |
// MueLu |
| 14 |
#include "MueLu_UncoupledAggregationFactory.hpp" |
| 15 |
#include "MueLu_SegregatedAFactory.hpp" |
| 16 |
|
| 17 |
// Xpetra |
| 18 |
#include <Xpetra_MatrixUtils.hpp> |
| 19 |
#include <Xpetra_MapFactory.hpp> |
| 20 |
#include <Xpetra_StridedMapFactory.hpp> |
| 21 |
|
| 22 |
namespace MueLuTests { |
| 23 |
|
| 24 |
template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node> |
| 25 |
Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>> createRedundantMaps( |
| 26 |
Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>> localDropMap) { |
| 27 |
#include "MueLu_UseShortNames.hpp" |
| 28 |
|
| 29 |
Teuchos::RCP<const Teuchos::Comm<int>> comm = localDropMap->getComm(); |
| 30 |
|
| 31 |
Teuchos::Array<GO> localDropMapGIDList = localDropMap->getLocalElementList(); |
| 32 |
const int GIDListSize = localDropMap->getMaxAllGlobalIndex() + 1; |
| 33 |
|
| 34 |
// Create a list of GID with only an incomplete/partial set of GIDs, which can then be completed by reduceAll |
| 35 |
Teuchos::Array<GO> partialDropMapGIDList(GIDListSize, -Teuchos::ScalarTraits<GlobalOrdinal>::one()); |
| 36 |
Teuchos::Array<GO> redundantDropMapGIDList(GIDListSize, -Teuchos::ScalarTraits<GlobalOrdinal>::one()); |
| 37 |
|
| 38 |
for (GO gid : localDropMapGIDList) { |
| 39 |
partialDropMapGIDList[gid] = gid; |
| 40 |
} |
| 41 |
|
| 42 |
Teuchos::reduceAll(*comm, Teuchos::REDUCE_MAX, GIDListSize, &partialDropMapGIDList[0], |
| 43 |
&redundantDropMapGIDList[0]); |
| 44 |
redundantDropMapGIDList.erase(std::remove(redundantDropMapGIDList.begin(), redundantDropMapGIDList.end(), -1), |
| 45 |
redundantDropMapGIDList.end()); |
| 46 |
Teuchos::RCP<const Map> redundantDropMap = MapFactory::Build( |
| 47 |
localDropMap->lib(), Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid(), redundantDropMapGIDList, 0, comm); |
| 48 |
|
| 49 |
return redundantDropMap; |
| 50 |
} |
| 51 |
|
| 52 |
template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node> |
| 53 |
void checkAggregatesBlockmap(Teuchos::RCP<MueLu::Aggregates<LocalOrdinal, GlobalOrdinal, Node>> aggregates, |
| 54 |
std::vector<size_t> &stridingInfo, |
| 55 |
Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>> blockmap) { |
| 56 |
#include "MueLu_UseShortNames.hpp" |
| 57 |
|
| 58 |
// Lists of nodes in each aggregate |
| 59 |
struct { |
| 60 |
// GH: For now, copy everything to host until we properly set this factory to run device code |
| 61 |
// Instead, we'll copy data into HostMirrors and run the algorithms on host, saving optimization for later. |
| 62 |
typename Aggregates::LO_view ptr, nodes, unaggregated; |
| 63 |
typename Aggregates::LO_view::HostMirror ptr_h, nodes_h, unaggregated_h; |
| 64 |
} nodesInAgg; |
| 65 |
aggregates->ComputeNodesInAggregate(nodesInAgg.ptr, nodesInAgg.nodes, nodesInAgg.unaggregated); |
| 66 |
nodesInAgg.ptr_h = Kokkos::create_mirror_view(nodesInAgg.ptr); |
| 67 |
nodesInAgg.nodes_h = Kokkos::create_mirror_view(nodesInAgg.nodes); |
| 68 |
nodesInAgg.unaggregated_h = Kokkos::create_mirror_view(nodesInAgg.unaggregated); |
| 69 |
Kokkos::deep_copy(nodesInAgg.ptr_h, nodesInAgg.ptr); |
| 70 |
Kokkos::deep_copy(nodesInAgg.nodes_h, nodesInAgg.nodes); |
| 71 |
Kokkos::deep_copy(nodesInAgg.unaggregated_h, nodesInAgg.unaggregated); |
| 72 |
|
| 73 |
// Create redundant maps to be absolutely sure no entry is missed during the check |
| 74 |
Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>> blockmap_final; |
| 75 |
blockmap_final = MueLuTests::createRedundantMaps<SC, LO, GO, NO>(blockmap); |
| 76 |
|
| 77 |
// Loop over all aggregates |
| 78 |
for (LO aggregate = 0; aggregate < (LO)nodesInAgg.ptr_h.extent(0) - 1; aggregate++) { |
| 79 |
bool aggContainsNodesInBlockmap = false; |
| 80 |
bool aggContainsNodesNotInBlockmap = false; |
| 81 |
// Loop over all nodes contained in the aggregate |
| 82 |
for (LO nodeIter = nodesInAgg.ptr_h[aggregate]; nodeIter < (LO)nodesInAgg.ptr_h[aggregate + 1]; nodeIter++) { |
| 83 |
LO node = nodesInAgg.nodes_h[nodeIter]; |
| 84 |
// Loop over all node dofs |
| 85 |
for (LO i = 0; i < (LO)stridingInfo[0]; i++) { |
| 86 |
// Check if dof is contained in rowmap (inner + interface dofs) of one of the bodies in contact |
| 87 |
if (blockmap_final->isNodeGlobalElement(node * stridingInfo[0] + i)) { |
| 88 |
aggContainsNodesInBlockmap = true; |
| 89 |
} else { |
| 90 |
aggContainsNodesNotInBlockmap = true; |
| 91 |
} |
| 92 |
} |
| 93 |
} |
| 94 |
// Aggregates must not cross from one solid body to next and respect contact interface |
| 95 |
TEUCHOS_TEST_FOR_EXCEPTION(aggContainsNodesInBlockmap == aggContainsNodesNotInBlockmap, |
| 96 |
MueLu::Exceptions::RuntimeError, |
| 97 |
"Aggregate " << aggregate << " crosses contact interface! Not allowed. Error in segregated aggregation procedure. \n") |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node> |
| 102 |
void checkAggregatesMapPair(Teuchos::RCP<MueLu::Aggregates<LocalOrdinal, GlobalOrdinal, Node>> aggregates, |
| 103 |
std::vector<size_t> &stridingInfo, |
| 104 |
Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>> integration_side_map, |
| 105 |
Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>> projection_side_map) { |
| 106 |
#include "MueLu_UseShortNames.hpp" |
| 107 |
|
| 108 |
// Lists of nodes in each aggregate |
| 109 |
struct { |
| 110 |
// GH: For now, copy everything to host until we properly set this factory to run device code |
| 111 |
// Instead, we'll copy data into HostMirrors and run the algorithms on host, saving optimization for later. |
| 112 |
typename Aggregates::LO_view ptr, nodes, unaggregated; |
| 113 |
typename Aggregates::LO_view::HostMirror ptr_h, nodes_h, unaggregated_h; |
| 114 |
} nodesInAgg; |
| 115 |
aggregates->ComputeNodesInAggregate(nodesInAgg.ptr, nodesInAgg.nodes, nodesInAgg.unaggregated); |
| 116 |
nodesInAgg.ptr_h = Kokkos::create_mirror_view(nodesInAgg.ptr); |
| 117 |
nodesInAgg.nodes_h = Kokkos::create_mirror_view(nodesInAgg.nodes); |
| 118 |
nodesInAgg.unaggregated_h = Kokkos::create_mirror_view(nodesInAgg.unaggregated); |
| 119 |
Kokkos::deep_copy(nodesInAgg.ptr_h, nodesInAgg.ptr); |
| 120 |
Kokkos::deep_copy(nodesInAgg.nodes_h, nodesInAgg.nodes); |
| 121 |
Kokkos::deep_copy(nodesInAgg.unaggregated_h, nodesInAgg.unaggregated); |
| 122 |
|
| 123 |
// Create redundant maps to be absolutely sure no entry is missed during the check |
| 124 |
Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>> integration_side_map_final; |
| 125 |
Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>> projection_side_map_final; |
| 126 |
integration_side_map_final = MueLuTests::createRedundantMaps<SC, LO, GO, NO>(integration_side_map); |
| 127 |
projection_side_map_final = MueLuTests::createRedundantMaps<SC, LO, GO, NO>(projection_side_map); |
| 128 |
|
| 129 |
// Loop over all aggregates |
| 130 |
for (LO aggregate = 0; aggregate < (LO)nodesInAgg.ptr_h.extent(0) - 1; aggregate++) { |
| 131 |
bool aggContainsNodesInIntegrationSideMap = false; |
| 132 |
bool aggContainsNodesInProjectionSideMap = false; |
| 133 |
// Loop over all nodes contained in the aggregate |
| 134 |
for (LO nodeIter = nodesInAgg.ptr_h[aggregate]; nodeIter < (LO)nodesInAgg.ptr_h[aggregate + 1]; nodeIter++) { |
| 135 |
LO node = nodesInAgg.nodes_h[nodeIter]; |
| 136 |
// Loop over all node dofs |
| 137 |
for (LO i = 0; i < (LO)stridingInfo[0]; i++) { |
| 138 |
// Check if dof is contained in interface mapping of one of the bodies in contact |
| 139 |
if (integration_side_map_final->isNodeGlobalElement(node * stridingInfo[0] + i)) { |
| 140 |
aggContainsNodesInIntegrationSideMap = true; |
| 141 |
} |
| 142 |
if (projection_side_map_final->isNodeGlobalElement(node * stridingInfo[0] + i)) { |
| 143 |
aggContainsNodesInProjectionSideMap = true; |
| 144 |
} |
| 145 |
} |
| 146 |
} |
| 147 |
// Aggregates must not cross from one solid body to next and respect contact interface |
| 148 |
TEUCHOS_TEST_FOR_EXCEPTION((aggContainsNodesInIntegrationSideMap == true) && (aggContainsNodesInProjectionSideMap == true), |
| 149 |
MueLu::Exceptions::RuntimeError, |
| 150 |
"Aggregate " << aggregate << " crosses contact interface! Not allowed. Error in segregated aggregation procedure. \n") |
| 151 |
} |
| 152 |
} |
| 153 |
} // namespace MueLuTests |
| 154 |
|
| 155 |
#endif |