MueLu Version of the Day
Loading...
Searching...
No Matches
MueLu_CoarseMapFactory_def.hpp
Go to the documentation of this file.
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/*
11 * MueLu_CoarseMapFactory_def.hpp
12 *
13 * Created on: Oct 12, 2012
14 * Author: wiesner
15 */
16
17#ifndef MUELU_COARSEMAPFACTORY_DEF_HPP_
18#define MUELU_COARSEMAPFACTORY_DEF_HPP_
19
20#include <Teuchos_Array.hpp>
21
22#include <Xpetra_MultiVector.hpp>
23#include <Xpetra_StridedMapFactory.hpp>
24
26#include "MueLu_Level.hpp"
27#include "MueLu_Aggregates.hpp"
28#include "MueLu_Monitor.hpp"
29
30namespace MueLu {
31
32template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
34
35template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
37
38template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
40 RCP<ParameterList> validParamList = rcp(new ParameterList());
41
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.");
44
45 validParamList->set<std::string>("Striding info", "{}", "Striding information");
46 validParamList->set<LocalOrdinal>("Strided block id", -1, "Strided block id");
47
48 // Domain GID offsets: list of offset values for domain gids (coarse gids) of tentative prolongator (default = 0).
49 // For each multigrid level we can define a different offset value, ie for the prolongator between
50 // level 0 and level 1 we use the offset entry domainGidOffsets_[0], for the prolongator between
51 // level 1 and level 2 we use domainGidOffsets_[1]...
52 // If the vector domainGidOffsets_ is too short and does not contain a sufficient number of gid offset
53 // values for all levels, a gid offset of 0 is used for all the remaining levels!
54 // The GIDs for the domain dofs of Ptent start with domainGidOffset, are contiguous and distributed
55 // equally over the procs (unless some reordering is done).
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.");
57
58 return validParamList;
59}
60
61template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
63 Input(currentLevel, "Aggregates");
64 Input(currentLevel, "Nullspace");
65}
66
67template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
69 // store striding map in internal variable
70 stridingInfo_ = stridingInfo;
71
72 // try to remove string "Striding info" from parameter list to make sure,
73 // that stridingInfo_ is not replaced in the Build call.
74 std::string strStridingInfo;
75 strStridingInfo.clear();
76 SetParameter("Striding info", ParameterEntry(strStridingInfo));
77}
78
79template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
81 FactoryMonitor m(*this, "Build", currentLevel);
82
83 GlobalOrdinal domainGIDOffset = GetDomainGIDOffset(currentLevel);
84 BuildCoarseMap(currentLevel, domainGIDOffset);
85}
86
87template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
89 Level& currentLevel, const GlobalOrdinal domainGIDOffset) const {
90 RCP<Aggregates> aggregates = Get<RCP<Aggregates> >(currentLevel, "Aggregates");
91 GlobalOrdinal numAggs = aggregates->GetNumAggregates();
92 RCP<const Map> aggMap = aggregates->GetMap();
93
94 RCP<MultiVector> nullspace = Get<RCP<MultiVector> >(currentLevel, "Nullspace");
95
96 const size_t NSDim = nullspace->getNumVectors();
97 RCP<const Teuchos::Comm<int> > comm = aggMap->getComm();
98 const ParameterList& pL = GetParameterList();
99
100 LocalOrdinal stridedBlockId = pL.get<LocalOrdinal>("Strided block id");
101
102 // read in stridingInfo from parameter list and fill the internal member variable
103 // read the data only if the parameter "Striding info" exists and is non-empty
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);
109 }
110 }
111
112 CheckForConsistentStridingInformation(stridedBlockId, NSDim);
113
114 GetOStream(Statistics2) << "domainGIDOffset: " << domainGIDOffset << " block size: " << getFixedBlockSize() << " stridedBlockId: " << stridedBlockId << std::endl;
115
116 // number of coarse level dofs (fixed by number of aggregates and blocksize data)
117 GlobalOrdinal nCoarseDofs = numAggs * getFixedBlockSize();
118 GlobalOrdinal indexBase = aggMap->getIndexBase();
119
120 RCP<const Map> coarseMap = StridedMapFactory::Build(aggMap->lib(),
121 Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid(),
122 nCoarseDofs,
123 indexBase,
124 stridingInfo_,
125 comm,
126 stridedBlockId,
127 domainGIDOffset);
128
129 Set(currentLevel, "CoarseMap", coarseMap);
130}
131
132template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
134 Level& currentLevel) const {
135 GlobalOrdinal domainGidOffset = Teuchos::ScalarTraits<GlobalOrdinal>::zero();
136
137 std::vector<GlobalOrdinal> domainGidOffsets;
138 domainGidOffsets.clear();
139 const ParameterList& pL = GetParameterList();
140 if (pL.isParameter("Domain GID offsets")) {
141 std::string strDomainGIDs = pL.get<std::string>("Domain GID offsets");
142 if (strDomainGIDs.empty() == false) {
143 Teuchos::Array<GlobalOrdinal> arrayVal = Teuchos::fromStringToArray<GlobalOrdinal>(strDomainGIDs);
144 domainGidOffsets = Teuchos::createVector(arrayVal);
145 if (currentLevel.GetLevelID() < Teuchos::as<int>(domainGidOffsets.size())) {
146 domainGidOffset = domainGidOffsets[currentLevel.GetLevelID()];
147 }
148 }
149 }
150
151 return domainGidOffset;
152}
153
154template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
156 const LocalOrdinal stridedBlockId, const size_t nullspaceDimension) const {
157 // check for consistency of striding information with NSDim and nCoarseDofs
158 if (stridedBlockId == -1) {
159 // this means we have no real strided map but only a block map with constant blockSize "nullspaceDimension"
160 TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo_.size() > 1, Exceptions::RuntimeError, "MueLu::CoarseMapFactory::Build(): stridingInfo_.size() but must be one");
161 stridingInfo_.clear();
162 stridingInfo_.push_back(nullspaceDimension);
163 TEUCHOS_TEST_FOR_EXCEPTION(stridingInfo_.size() != 1, Exceptions::RuntimeError, "MueLu::CoarseMapFactory::Build(): stridingInfo_.size() but must be one");
164
165 } else {
166 // stridedBlockId > -1, set by user
167 TEUCHOS_TEST_FOR_EXCEPTION(stridedBlockId > Teuchos::as<LO>(stridingInfo_.size() - 1), Exceptions::RuntimeError, "MueLu::CoarseMapFactory::Build(): it is stridingInfo_.size() <= stridedBlockId_. error.");
168 size_t stridedBlockSize = stridingInfo_[stridedBlockId];
169 TEUCHOS_TEST_FOR_EXCEPTION(stridedBlockSize != nullspaceDimension, Exceptions::RuntimeError, "MueLu::CoarseMapFactory::Build(): dimension of strided block != nullspaceDimension. error.");
170 }
171}
172
173} // namespace MueLu
174
175#endif /* MUELU_COARSEMAPFACTORY_DEF_HPP_ */
MueLu::DefaultLocalOrdinal LocalOrdinal
MueLu::DefaultGlobalOrdinal GlobalOrdinal
virtual void BuildCoarseMap(Level &currentLevel, 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 &currentLevel) const
Extract domain GID offset from user data.
void Build(Level &currentLevel) 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 &currentLevel) 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.