46 #ifndef MUELU_COORDINATESTRANSFER_FACTORY_DEF_HPP
47 #define MUELU_COORDINATESTRANSFER_FACTORY_DEF_HPP
50 #include "Xpetra_MultiVectorFactory.hpp"
51 #include "Xpetra_MapFactory.hpp"
54 #include "MueLu_Aggregates.hpp"
56 #include "MueLu_Utilities.hpp"
63 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
70 validParamList->
set<
bool>(
"structured aggregation",
false,
"Flag specifying that the geometric data is transferred for StructuredAggregationFactory");
71 validParamList->
set<
bool>(
"aggregation coupled",
false,
"Flag specifying if the aggregation algorithm was used in coupled mode.");
72 validParamList->
set<
bool>(
"Geometric",
false,
"Flag specifying that the coordinates are transferred for GeneralGeometricPFactory");
73 validParamList->
set<
RCP<const FactoryBase> >(
"coarseCoordinates", Teuchos::null,
"Factory for coarse coordinates generation");
74 validParamList->
set<
RCP<const FactoryBase> >(
"gCoarseNodesPerDim", Teuchos::null,
"Factory providing the global number of nodes per spatial dimensions of the mesh");
75 validParamList->
set<
RCP<const FactoryBase> >(
"lCoarseNodesPerDim", Teuchos::null,
"Factory providing the local number of nodes per spatial dimensions of the mesh");
76 validParamList->
set<
RCP<const FactoryBase> >(
"numDimensions", Teuchos::null,
"Factory providing the number of spatial dimensions of the mesh");
77 validParamList->
set<
int>(
"write start", -1,
"first level at which coordinates should be written to file");
78 validParamList->
set<
int>(
"write end", -1,
"last level at which coordinates should be written to file");
79 validParamList->
set<
bool>(
"hybrid aggregation",
false,
"Flag specifying that hybrid aggregation data is transfered for HybridAggregationFactory");
80 validParamList->
set<
RCP<const FactoryBase> >(
"aggregationRegionTypeCoarse", Teuchos::null,
"Factory indicating what aggregation type is to be used on the coarse level of the region");
81 validParamList->
set<
bool>(
"interface aggregation",
false,
"Flag specifying that interface aggregation data is transfered for HybridAggregationFactory");
82 validParamList->
set<
RCP<const FactoryBase> >(
"coarseInterfacesDimensions", Teuchos::null,
"Factory providing coarseInterfacesDimensions");
83 validParamList->
set<
RCP<const FactoryBase> >(
"nodeOnCoarseInterface", Teuchos::null,
"Factory providing nodeOnCoarseInterface");
85 return validParamList;
88 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
90 static bool isAvailableCoords =
false;
93 if (pL.
get<
bool>(
"structured aggregation") ==
true) {
94 if (pL.
get<
bool>(
"aggregation coupled") ==
true) {
95 Input(fineLevel,
"gCoarseNodesPerDim");
97 Input(fineLevel,
"lCoarseNodesPerDim");
98 Input(fineLevel,
"numDimensions");
99 }
else if (pL.
get<
bool>(
"Geometric") ==
true) {
100 Input(coarseLevel,
"coarseCoordinates");
101 Input(coarseLevel,
"gCoarseNodesPerDim");
102 Input(coarseLevel,
"lCoarseNodesPerDim");
103 }
else if (pL.
get<
bool>(
"hybrid aggregation") ==
true) {
104 Input(fineLevel,
"aggregationRegionTypeCoarse");
105 Input(fineLevel,
"lCoarseNodesPerDim");
106 Input(fineLevel,
"numDimensions");
107 if (pL.
get<
bool>(
"interface aggregation") ==
true) {
108 Input(fineLevel,
"coarseInterfacesDimensions");
109 Input(fineLevel,
"nodeOnCoarseInterface");
113 isAvailableCoords = coarseLevel.
IsAvailable(
"Coordinates",
this);
115 if (isAvailableCoords ==
false) {
116 Input(fineLevel,
"Coordinates");
117 Input(fineLevel,
"Aggregates");
118 Input(fineLevel,
"CoarseMap");
123 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
129 GetOStream(
Runtime0) <<
"Transferring coordinates" << std::endl;
139 if (pL.
get<
bool>(
"hybrid aggregation") ==
true) {
140 std::string regionType = Get<std::string>(fineLevel,
"aggregationRegionTypeCoarse");
141 numDimensions = Get<int>(fineLevel,
"numDimensions");
142 lCoarseNodesPerDir = Get<Array<LO> >(fineLevel,
"lCoarseNodesPerDim");
143 Set<std::string>(coarseLevel,
"aggregationRegionType", regionType);
144 Set<int>(coarseLevel,
"numDimensions", numDimensions);
145 Set<Array<LO> >(coarseLevel,
"lNodesPerDim", lCoarseNodesPerDir);
147 if ((pL.
get<
bool>(
"interface aggregation") ==
true) && (regionType ==
"uncoupled")) {
148 Array<LO> coarseInterfacesDimensions = Get<Array<LO> >(fineLevel,
"coarseInterfacesDimensions");
149 Array<LO> nodeOnCoarseInterface = Get<Array<LO> >(fineLevel,
"nodeOnCoarseInterface");
150 Set<Array<LO> >(coarseLevel,
"interfacesDimensions", coarseInterfacesDimensions);
151 Set<Array<LO> >(coarseLevel,
"nodeOnInterface", nodeOnCoarseInterface);
154 }
else if (pL.
get<
bool>(
"structured aggregation") ==
true) {
155 if (pL.
get<
bool>(
"aggregation coupled") ==
true) {
156 gCoarseNodesPerDir = Get<Array<GO> >(fineLevel,
"gCoarseNodesPerDim");
157 Set<Array<GO> >(coarseLevel,
"gNodesPerDim", gCoarseNodesPerDir);
159 lCoarseNodesPerDir = Get<Array<LO> >(fineLevel,
"lCoarseNodesPerDim");
160 Set<Array<LO> >(coarseLevel,
"lNodesPerDim", lCoarseNodesPerDir);
161 numDimensions = Get<int>(fineLevel,
"numDimensions");
162 Set<int>(coarseLevel,
"numDimensions", numDimensions);
164 }
else if (pL.
get<
bool>(
"Geometric") ==
true) {
165 coarseCoords = Get<RCP<xdMV> >(coarseLevel,
"coarseCoordinates");
166 gCoarseNodesPerDir = Get<Array<GO> >(coarseLevel,
"gCoarseNodesPerDim");
167 lCoarseNodesPerDir = Get<Array<LO> >(coarseLevel,
"lCoarseNodesPerDim");
168 Set<Array<GO> >(coarseLevel,
"gNodesPerDim", gCoarseNodesPerDir);
169 Set<Array<LO> >(coarseLevel,
"lNodesPerDim", lCoarseNodesPerDir);
171 Set<RCP<xdMV> >(coarseLevel,
"Coordinates", coarseCoords);
174 if (coarseLevel.
IsAvailable(
"Coordinates",
this)) {
175 GetOStream(
Runtime0) <<
"Reusing coordinates" << std::endl;
179 fineCoords = Get<RCP<xdMV> >(fineLevel,
"Coordinates");
180 RCP<const Map> coarseMap = Get<RCP<const Map> >(fineLevel,
"CoarseMap");
186 if (rcp_dynamic_cast<const StridedMap>(coarseMap) != Teuchos::null)
187 blkSize = rcp_dynamic_cast<const StridedMap>(coarseMap)->getFixedBlockSize();
194 GO indexBase = coarseMap->getIndexBase();
196 size_t numElements = elementAList.
size() / blkSize;
200 for (LO i = 0; i < Teuchos::as<LO>(numElements); i++)
201 elementList[i] = (elementAList[i * blkSize] - indexBase) / blkSize + indexBase;
209 coarseCoordMap = coarseMap;
216 bool aggregatesCrossProcessors;
217 aggregates = Get<RCP<Aggregates> >(fineLevel,
"Aggregates");
218 aggregatesCrossProcessors = aggregates->AggregatesCrossProcessors();
222 if (aggregatesCrossProcessors) {
232 auto aggGraph = aggregates->GetGraph();
233 auto numAggs = aggGraph.numRows();
235 auto fineCoordsView = ghostedCoords->getDeviceLocalView(Xpetra::Access::ReadOnly);
236 auto coarseCoordsView = coarseCoords->getDeviceLocalView(Xpetra::Access::OverwriteAll);
242 const auto dim = ghostedCoords->getNumVectors();
245 for (
size_t j = 0; j < dim; j++) {
246 Kokkos::parallel_for(
247 "MueLu:CoordinatesTransferF:Build:coord", Kokkos::RangePolicy<local_ordinal_type, execution_space>(0, numAggs),
248 KOKKOS_LAMBDA(
const LO i) {
252 auto aggregate = aggGraph.rowConst(i);
255 for (
size_t colID = 0; colID < static_cast<size_t>(aggregate.length); colID++)
256 sum += fineCoordsRandomView(aggregate(colID), j);
258 coarseCoordsView(i, j) = sum / aggregate.length;
263 Set<RCP<xdMV> >(coarseLevel,
"Coordinates", coarseCoords);
266 int writeStart = pL.
get<
int>(
"write start"), writeEnd = pL.
get<
int>(
"write end");
267 if (writeStart == 0 && fineLevel.
GetLevelID() == 0 && writeStart <= writeEnd) {
268 std::ostringstream buf;
270 std::string fileName =
"coordinates_before_rebalance_level_" + buf.str() +
".m";
274 std::ostringstream buf;
276 std::string fileName =
"coordinates_before_rebalance_level_" + buf.str() +
".m";
283 #endif // MUELU_COORDINATESTRANSFER_FACTORY_DEF_HPP
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)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Timer to be used in factories. Similar to Monitor but with additional timers.
One-liner description of what is happening.
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.