10 #ifndef MUELU_COORDINATESTRANSFER_FACTORY_DEF_HPP
11 #define MUELU_COORDINATESTRANSFER_FACTORY_DEF_HPP
14 #include "Xpetra_MultiVectorFactory.hpp"
15 #include "Xpetra_MapFactory.hpp"
18 #include "MueLu_Aggregates.hpp"
20 #include "MueLu_Utilities.hpp"
27 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
30 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
33 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
40 validParamList->
set<
bool>(
"structured aggregation",
false,
"Flag specifying that the geometric data is transferred for StructuredAggregationFactory");
41 validParamList->
set<
bool>(
"aggregation coupled",
false,
"Flag specifying if the aggregation algorithm was used in coupled mode.");
42 validParamList->
set<
bool>(
"Geometric",
false,
"Flag specifying that the coordinates are transferred for GeneralGeometricPFactory");
43 validParamList->
set<
RCP<const FactoryBase> >(
"coarseCoordinates", Teuchos::null,
"Factory for coarse coordinates generation");
44 validParamList->
set<
RCP<const FactoryBase> >(
"gCoarseNodesPerDim", Teuchos::null,
"Factory providing the global number of nodes per spatial dimensions of the mesh");
45 validParamList->
set<
RCP<const FactoryBase> >(
"lCoarseNodesPerDim", Teuchos::null,
"Factory providing the local number of nodes per spatial dimensions of the mesh");
46 validParamList->
set<
RCP<const FactoryBase> >(
"numDimensions", Teuchos::null,
"Factory providing the number of spatial dimensions of the mesh");
47 validParamList->
set<
int>(
"write start", -1,
"first level at which coordinates should be written to file");
48 validParamList->
set<
int>(
"write end", -1,
"last level at which coordinates should be written to file");
49 validParamList->
set<
bool>(
"hybrid aggregation",
false,
"Flag specifying that hybrid aggregation data is transfered for HybridAggregationFactory");
50 validParamList->
set<
RCP<const FactoryBase> >(
"aggregationRegionTypeCoarse", Teuchos::null,
"Factory indicating what aggregation type is to be used on the coarse level of the region");
51 validParamList->
set<
bool>(
"interface aggregation",
false,
"Flag specifying that interface aggregation data is transfered for HybridAggregationFactory");
52 validParamList->
set<
RCP<const FactoryBase> >(
"coarseInterfacesDimensions", Teuchos::null,
"Factory providing coarseInterfacesDimensions");
53 validParamList->
set<
RCP<const FactoryBase> >(
"nodeOnCoarseInterface", Teuchos::null,
"Factory providing nodeOnCoarseInterface");
55 return validParamList;
58 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
60 static bool isAvailableCoords =
false;
63 if (pL.
get<
bool>(
"structured aggregation") ==
true) {
64 if (pL.
get<
bool>(
"aggregation coupled") ==
true) {
65 Input(fineLevel,
"gCoarseNodesPerDim");
67 Input(fineLevel,
"lCoarseNodesPerDim");
68 Input(fineLevel,
"numDimensions");
69 }
else if (pL.
get<
bool>(
"Geometric") ==
true) {
70 Input(coarseLevel,
"coarseCoordinates");
71 Input(coarseLevel,
"gCoarseNodesPerDim");
72 Input(coarseLevel,
"lCoarseNodesPerDim");
73 }
else if (pL.
get<
bool>(
"hybrid aggregation") ==
true) {
74 Input(fineLevel,
"aggregationRegionTypeCoarse");
75 Input(fineLevel,
"lCoarseNodesPerDim");
76 Input(fineLevel,
"numDimensions");
77 if (pL.
get<
bool>(
"interface aggregation") ==
true) {
78 Input(fineLevel,
"coarseInterfacesDimensions");
79 Input(fineLevel,
"nodeOnCoarseInterface");
83 isAvailableCoords = coarseLevel.
IsAvailable(
"Coordinates",
this);
85 if (isAvailableCoords ==
false) {
86 Input(fineLevel,
"Coordinates");
87 Input(fineLevel,
"Aggregates");
88 Input(fineLevel,
"CoarseMap");
93 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
99 GetOStream(
Runtime0) <<
"Transferring coordinates" << std::endl;
109 if (pL.
get<
bool>(
"hybrid aggregation") ==
true) {
110 std::string regionType = Get<std::string>(fineLevel,
"aggregationRegionTypeCoarse");
111 numDimensions = Get<int>(fineLevel,
"numDimensions");
112 lCoarseNodesPerDir = Get<Array<LO> >(fineLevel,
"lCoarseNodesPerDim");
113 Set<std::string>(coarseLevel,
"aggregationRegionType", regionType);
114 Set<int>(coarseLevel,
"numDimensions", numDimensions);
115 Set<Array<LO> >(coarseLevel,
"lNodesPerDim", lCoarseNodesPerDir);
117 if ((pL.
get<
bool>(
"interface aggregation") ==
true) && (regionType ==
"uncoupled")) {
118 Array<LO> coarseInterfacesDimensions = Get<Array<LO> >(fineLevel,
"coarseInterfacesDimensions");
119 Array<LO> nodeOnCoarseInterface = Get<Array<LO> >(fineLevel,
"nodeOnCoarseInterface");
120 Set<Array<LO> >(coarseLevel,
"interfacesDimensions", coarseInterfacesDimensions);
121 Set<Array<LO> >(coarseLevel,
"nodeOnInterface", nodeOnCoarseInterface);
124 }
else if (pL.
get<
bool>(
"structured aggregation") ==
true) {
125 if (pL.
get<
bool>(
"aggregation coupled") ==
true) {
126 gCoarseNodesPerDir = Get<Array<GO> >(fineLevel,
"gCoarseNodesPerDim");
127 Set<Array<GO> >(coarseLevel,
"gNodesPerDim", gCoarseNodesPerDir);
129 lCoarseNodesPerDir = Get<Array<LO> >(fineLevel,
"lCoarseNodesPerDim");
130 Set<Array<LO> >(coarseLevel,
"lNodesPerDim", lCoarseNodesPerDir);
131 numDimensions = Get<int>(fineLevel,
"numDimensions");
132 Set<int>(coarseLevel,
"numDimensions", numDimensions);
134 }
else if (pL.
get<
bool>(
"Geometric") ==
true) {
135 coarseCoords = Get<RCP<xdMV> >(coarseLevel,
"coarseCoordinates");
136 gCoarseNodesPerDir = Get<Array<GO> >(coarseLevel,
"gCoarseNodesPerDim");
137 lCoarseNodesPerDir = Get<Array<LO> >(coarseLevel,
"lCoarseNodesPerDim");
138 Set<Array<GO> >(coarseLevel,
"gNodesPerDim", gCoarseNodesPerDir);
139 Set<Array<LO> >(coarseLevel,
"lNodesPerDim", lCoarseNodesPerDir);
141 Set<RCP<xdMV> >(coarseLevel,
"Coordinates", coarseCoords);
144 if (coarseLevel.
IsAvailable(
"Coordinates",
this)) {
145 GetOStream(
Runtime0) <<
"Reusing coordinates" << std::endl;
149 fineCoords = Get<RCP<xdMV> >(fineLevel,
"Coordinates");
150 RCP<const Map> coarseMap = Get<RCP<const Map> >(fineLevel,
"CoarseMap");
156 if (rcp_dynamic_cast<const StridedMap>(coarseMap) != Teuchos::null)
157 blkSize = rcp_dynamic_cast<const StridedMap>(coarseMap)->getFixedBlockSize();
164 GO indexBase = coarseMap->getIndexBase();
166 size_t numElements = elementAList.
size() / blkSize;
170 for (LO i = 0; i < Teuchos::as<LO>(numElements); i++)
171 elementList[i] = (elementAList[i * blkSize] - indexBase) / blkSize + indexBase;
179 coarseCoordMap = coarseMap;
186 bool aggregatesCrossProcessors;
187 aggregates = Get<RCP<Aggregates> >(fineLevel,
"Aggregates");
188 aggregatesCrossProcessors = aggregates->AggregatesCrossProcessors();
192 if (aggregatesCrossProcessors) {
202 auto aggGraph = aggregates->GetGraph();
203 auto numAggs = aggGraph.numRows();
205 auto fineCoordsView = ghostedCoords->getDeviceLocalView(Xpetra::Access::ReadOnly);
206 auto coarseCoordsView = coarseCoords->getDeviceLocalView(Xpetra::Access::OverwriteAll);
212 const auto dim = ghostedCoords->getNumVectors();
215 for (
size_t j = 0; j < dim; j++) {
216 Kokkos::parallel_for(
217 "MueLu:CoordinatesTransferF:Build:coord", Kokkos::RangePolicy<local_ordinal_type, execution_space>(0, numAggs),
218 KOKKOS_LAMBDA(
const LO i) {
222 auto aggregate = aggGraph.rowConst(i);
225 for (
size_t colID = 0; colID < static_cast<size_t>(aggregate.length); colID++)
226 sum += fineCoordsRandomView(aggregate(colID), j);
228 coarseCoordsView(i, j) = sum / aggregate.length;
233 Set<RCP<xdMV> >(coarseLevel,
"Coordinates", coarseCoords);
236 int writeStart = pL.
get<
int>(
"write start"), writeEnd = pL.
get<
int>(
"write end");
237 if (writeStart == 0 && fineLevel.
GetLevelID() == 0 && writeStart <= writeEnd) {
238 std::ostringstream buf;
240 std::string fileName =
"coordinates_before_rebalance_level_" + buf.str() +
".m";
244 std::ostringstream buf;
246 std::string fileName =
"coordinates_before_rebalance_level_" + buf.str() +
".m";
253 #endif // MUELU_COORDINATESTRANSFER_FACTORY_DEF_HPP
CoordinatesTransferFactory()
Constructor.
void Build(Level &fineLevel, Level &coarseLevel) const
Build an object with this factory.
void DeclareInput(Level &finelevel, Level &coarseLevel) const
Specifies the data that this class needs, and the factories that generate that data.
T & get(const std::string &name, T def_value)
Timer to be used in factories. Similar to Monitor but with additional timers.
One-liner description of what is happening.
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
virtual ~CoordinatesTransferFactory()
Destructor.
RequestMode GetRequestMode() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Class that holds all level-specific information.
Timer to be used in factories. Similar to SubMonitor but adds a timer level by level.
int GetLevelID() const
Return level number.
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
bool IsAvailable(const std::string &ename, const FactoryBase *factory=NoFactory::get()) const
Test whether a need's value has been saved.