17#ifndef MUELU_COARSEMAPFACTORY_DEF_HPP_
18#define MUELU_COARSEMAPFACTORY_DEF_HPP_
20#include <Teuchos_Array.hpp>
22#include <Xpetra_MultiVector.hpp>
23#include <Xpetra_StridedMapFactory.hpp>
27#include "MueLu_Aggregates.hpp"
32template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
35template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
38template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
40 RCP<ParameterList> validParamList = rcp(
new ParameterList());
42 validParamList->set<RCP<const FactoryBase> >(
"Aggregates", Teuchos::null,
"Generating factory for aggregates.");
43 validParamList->set<RCP<const FactoryBase> >(
"Nullspace", Teuchos::null,
"Generating factory for null space.");
45 validParamList->set<std::string>(
"Striding info",
"{}",
"Striding information");
46 validParamList->set<
LocalOrdinal>(
"Strided block id", -1,
"Strided block id");
56 validParamList->set<std::string>(
"Domain GID offsets",
"{0}",
"vector with offsets for GIDs for each level. If no offset GID value is given for the level we use 0 as default.");
58 return validParamList;
61template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
63 Input(currentLevel,
"Aggregates");
64 Input(currentLevel,
"Nullspace");
67template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
70 stridingInfo_ = stridingInfo;
74 std::string strStridingInfo;
75 strStridingInfo.clear();
76 SetParameter(
"Striding info", ParameterEntry(strStridingInfo));
79template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
83 GlobalOrdinal domainGIDOffset = GetDomainGIDOffset(currentLevel);
84 BuildCoarseMap(currentLevel, domainGIDOffset);
87template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
90 RCP<Aggregates> aggregates = Get<RCP<Aggregates> >(currentLevel,
"Aggregates");
92 RCP<const Map> aggMap = aggregates->GetMap();
94 RCP<MultiVector> nullspace = Get<RCP<MultiVector> >(currentLevel,
"Nullspace");
96 const size_t NSDim = nullspace->getNumVectors();
97 RCP<const Teuchos::Comm<int> > comm = aggMap->getComm();
98 const ParameterList& pL = GetParameterList();
104 if (pL.isParameter(
"Striding info")) {
105 std::string strStridingInfo = pL.get<std::string>(
"Striding info");
106 if (strStridingInfo.empty() ==
false) {
107 Teuchos::Array<size_t> arrayVal = Teuchos::fromStringToArray<size_t>(strStridingInfo);
108 stridingInfo_ = Teuchos::createVector(arrayVal);
112 CheckForConsistentStridingInformation(stridedBlockId, NSDim);
114 GetOStream(
Statistics2) <<
"domainGIDOffset: " << domainGIDOffset <<
" block size: " << getFixedBlockSize() <<
" stridedBlockId: " << stridedBlockId << std::endl;
117 GlobalOrdinal nCoarseDofsGlobal = aggregates->GetNumGlobalAggregatesComputeIfNeeded() * getFixedBlockSize();
121 RCP<const Map> coarseMap = StridedMapFactory::Build(aggMap->lib(),
130 Set(currentLevel,
"CoarseMap", coarseMap);
133template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
135 Level& currentLevel)
const {
136 GlobalOrdinal domainGidOffset = Teuchos::ScalarTraits<GlobalOrdinal>::zero();
138 std::vector<GlobalOrdinal> domainGidOffsets;
139 domainGidOffsets.clear();
140 const ParameterList& pL = GetParameterList();
141 if (pL.isParameter(
"Domain GID offsets")) {
142 std::string strDomainGIDs = pL.get<std::string>(
"Domain GID offsets");
143 if (strDomainGIDs.empty() ==
false) {
144 Teuchos::Array<GlobalOrdinal> arrayVal = Teuchos::fromStringToArray<GlobalOrdinal>(strDomainGIDs);
145 domainGidOffsets = Teuchos::createVector(arrayVal);
146 if (currentLevel.
GetLevelID() < Teuchos::as<int>(domainGidOffsets.size())) {
147 domainGidOffset = domainGidOffsets[currentLevel.
GetLevelID()];
152 return domainGidOffset;
155template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
157 const LocalOrdinal stridedBlockId,
const size_t nullspaceDimension)
const {
159 if (stridedBlockId == -1) {
161 TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo_.size() > 1,
Exceptions::RuntimeError,
"MueLu::CoarseMapFactory::Build(): stridingInfo_.size() but must be one");
162 stridingInfo_.clear();
163 stridingInfo_.push_back(nullspaceDimension);
164 TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo_.size() != 1,
Exceptions::RuntimeError,
"MueLu::CoarseMapFactory::Build(): stridingInfo_.size() but must be one");
168 TEUCHOS_TEST_FOR_EXCEPTION(stridedBlockId > Teuchos::as<LO>(stridingInfo_.size() - 1),
Exceptions::RuntimeError,
"MueLu::CoarseMapFactory::Build(): it is stridingInfo_.size() <= stridedBlockId_. error.");
169 size_t stridedBlockSize = stridingInfo_[stridedBlockId];
170 TEUCHOS_TEST_FOR_EXCEPTION(stridedBlockSize != nullspaceDimension,
Exceptions::RuntimeError,
"MueLu::CoarseMapFactory::Build(): dimension of strided block != nullspaceDimension. error.");
MueLu::DefaultLocalOrdinal LocalOrdinal
MueLu::DefaultGlobalOrdinal GlobalOrdinal
virtual void BuildCoarseMap(Level ¤tLevel, const GlobalOrdinal domainGIDOffset) const
Build the coarse map using the domain GID offset.
virtual void CheckForConsistentStridingInformation(LocalOrdinal stridedBlockId, const size_t nullspaceDimension) const
RCP< const ParameterList > GetValidParameterList() const override
Return a const parameter list of valid parameters that setParameterList() will accept.
virtual GlobalOrdinal GetDomainGIDOffset(Level ¤tLevel) const
Extract domain GID offset from user data.
void Build(Level ¤tLevel) const override
Build an object with this factory.
virtual void setStridingData(std::vector< size_t > stridingInfo)
setStridingData set striding vector for the domain DOF map (= coarse map), e.g. (2,...
void DeclareInput(Level ¤tLevel) const override
Specifies the data that this class needs, and the factories that generate that data.
Exception throws to report errors in the internal logical of the program.
Timer to be used in factories. Similar to Monitor but with additional timers.
Class that holds all level-specific information.
int GetLevelID() const
Return level number.
Namespace for MueLu classes and methods.
@ Statistics2
Print even more statistics.