Debian Codegraph @

packages/shylu/shylu_dd/frosch/src/SchwarzOperators/FROSch_RGDSWCoarseOperator_def.hpp

raw
1 // @HEADER
2 // *****************************************************************************
3 // ShyLU: Scalable Hybrid LU Preconditioner and Solver
4 //
5 // Copyright 2011 NTESS and the ShyLU contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9
10 #ifndef _FROSCH_RGDSWCOARSEOPERATOR_DEF_HPP
11 #define _FROSCH_RGDSWCOARSEOPERATOR_DEF_HPP
12
13 #include <FROSch_RGDSWCoarseOperator_decl.hpp>
14
15
16 namespace FROSch {
17
18 using namespace std;
19 using namespace Teuchos;
20 using namespace Xpetra;
21
22 template <class SC,class LO,class GO,class NO>
23 RGDSWCoarseOperator<SC,LO,GO,NO>::RGDSWCoarseOperator(ConstXMatrixPtr k,
24 ParameterListPtr parameterList) :
25 GDSWCoarseOperator<SC,LO,GO,NO> (k,parameterList)
26 {
27 FROSCH_DETAILTIMER_START_LEVELID(rGDSWCoarseOperatorTime,"RGDSWCoarseOperator::RGDSWCoarseOperator");
28 }
29
30 template <class SC,class LO,class GO,class NO>
31 int RGDSWCoarseOperator<SC,LO,GO,NO>::resetCoarseSpaceBlock(UN blockId,
32 UN dimension,
33 UN dofsPerNode,
34 ConstXMapPtr nodesMap,
35 ConstXMapPtrVecPtr dofsMaps,
36 GOVecPtr dirichletBoundaryDofs,
37 ConstXMultiVectorPtr nodeList)
38 {
39 FROSCH_DETAILTIMER_START_LEVELID(resetCoarseSpaceBlockTime,"RGDSWCoarseOperator::resetCoarseSpaceBlock");
40 FROSCH_ASSERT(dofsMaps.size()==dofsPerNode,"dofsMaps.size()!=dofsPerNode");
41 FROSCH_ASSERT(blockId<=this->NumberOfBlocks_,"Block does not exist yet and can therefore not be reset.");
42
43 if (!this->DistributionList_->get("Type","linear").compare("ZoltanDual")) {
44 FROSCH_ASSERT(false,"RGDSWCoarseOperator:: Distribution Type ZoltanDual only works for IPOUHarmonicCoarseOperator");
45 }
46
47 // Process the parameter list
48 stringstream blockIdStringstream;
49 blockIdStringstream << blockId+1;
50 string blockIdString = blockIdStringstream.str();
51 RCP<ParameterList> coarseSpaceList = sublist(sublist(this->ParameterList_,"Blocks"),blockIdString.c_str());
52
53 CommunicationStrategy communicationStrategy = CreateOneToOneMap;
54 if (!coarseSpaceList->get("Interface Communication Strategy","CreateOneToOneMap").compare("CrsMatrix")) {
55 communicationStrategy = CommCrsMatrix;
56 } else if (!coarseSpaceList->get("Interface Communication Strategy","CreateOneToOneMap").compare("CrsGraph")) {
57 communicationStrategy = CommCrsGraph;
58 } else if (!coarseSpaceList->get("Interface Communication Strategy","CreateOneToOneMap").compare("CreateOneToOneMap")) {
59 communicationStrategy = CreateOneToOneMap;
60 } else {
61 FROSCH_ASSERT(false,"FROSch::RGDSWCoarseOperator: Specify a valid communication strategy for the identification of the interface components.");
62 }
63
64 Verbosity verbosity = All;
65 if (!coarseSpaceList->get("Verbosity","All").compare("None")) {
66 verbosity = None;
67 } else if (!coarseSpaceList->get("Verbosity","All").compare("All")) {
68 verbosity = All;
69 } else {
70 FROSCH_ASSERT(false,"FROSch::RGDSWCoarseOperator: Specify a valid verbosity level.");
71 }
72
73 bool useForCoarseSpace = coarseSpaceList->get("Use For Coarse Space",false);
74 string option = coarseSpaceList->get("Option","1");
75 DistanceFunction distanceFunction = ConstantDistanceFunction;
76 if (!option.compare("1")) {
77
78 } else if (!option.compare("2.2")) {
79 distanceFunction = InverseEuclideanDistanceFunction;
80 } else {
81 FROSCH_ASSERT(false,"Option is unknown!");
82 }
83
84 bool useRotations = coarseSpaceList->get("Rotations",true);
85 if (useRotations && nodeList.is_null()) {
86 //FROSCH_ASSERT(option==1,"Only option 1 can be constructed without a valid node list.");
87 useRotations = false;
88 FROSCH_WARNING("FROSch::RGDSWCoarseOperator",this->Verbose_,"Rotations cannot be used since nodeList.is_null().");
89 }
90
91 if (useForCoarseSpace) {
92 this->NumberOfBlocks_++;
93
94 this->GammaDofs_.resize(this->GammaDofs_.size()+1);
95 this->IDofs_.resize(this->IDofs_.size()+1);
96 this->InterfaceCoarseSpaces_.resize(this->InterfaceCoarseSpaces_.size()+1);
97 this->DofsMaps_.resize(this->DofsMaps_.size()+1);
98 this->DofsPerNode_.resize(this->DofsPerNode_.size()+1);
99
100 this->DofsMaps_[blockId] = dofsMaps;
101 this->DofsPerNode_[blockId] = dofsPerNode;
102
103 Array<GO> tmpDirichletBoundaryDofs(dirichletBoundaryDofs()); // Here, we do a copy. Maybe, this is not necessary
104 sortunique(tmpDirichletBoundaryDofs);
105
106 this->DDInterface_.reset(new DDInterface<SC,LO,GO,NO>(dimension,this->DofsPerNode_[blockId],nodesMap.getConst(),verbosity,this->LevelID_,communicationStrategy));
107 this->DDInterface_->resetGlobalDofs(dofsMaps);
108 this->DDInterface_->removeDirichletNodes(tmpDirichletBoundaryDofs);
109
110 EntitySetPtr interface = this->DDInterface_->getInterface();
111 EntitySetPtr interior = this->DDInterface_->getInterior();
112
113 if (this->Verbose_) {
114 cout
115 << "\n" << setw(FROSCH_OUTPUT_INDENT) << " "
116 << setw(89) << "-----------------------------------------------------------------------------------------"
117 << "\n" << setw(FROSCH_OUTPUT_INDENT) << " "
118 << "| "
119 << left << setw(74) << "RGDSWCoarseOperator " << right << setw(8) << "(Level " << setw(2) << this->LevelID_ << ")"
120 << " |"
121 << "\n" << setw(FROSCH_OUTPUT_INDENT) << " "
122 << setw(89) << "========================================================================================="
123 << "\n" << setw(FROSCH_OUTPUT_INDENT) << " "
124 << "| " << left << setw(41) << "Block" << right
125 << " | " << setw(41) << blockId
126 << " |"
127 << "\n" << setw(FROSCH_OUTPUT_INDENT) << " "
128 << "| " << left << setw(41) << "Spatial dimensions" << right
129 << " | " << setw(41) << dimension
130 << " |"
131 << "\n" << setw(FROSCH_OUTPUT_INDENT) << " "
132 << "| " << left << setw(41) << "Number of degrees of freedom per node" << right
133 << " | " << setw(41) << dofsPerNode
134 << " |"
135 << "\n" << setw(FROSCH_OUTPUT_INDENT) << " "
136 << "| " << left << setw(41) << "Option" << right
137 << " | " << setw(41) << option
138 << " |"
139 << "\n" << setw(FROSCH_OUTPUT_INDENT) << " "
140 << setw(89) << "-----------------------------------------------------------------------------------------"
141 << endl;
142 }
143
144 // Check for interface
145 if (interface->getEntity(0)->getNumNodes()==0) {
146 FROSCH_NOTIFICATION("FROSch::RGDSWCoarseOperator",this->Verbose_,"No interface found => Volume functions will be used instead.");
147 this->computeVolumeFunctions(blockId,dimension,nodesMap,nodeList,interior);
148 } else {
149 this->GammaDofs_[blockId] = LOVecPtr(this->DofsPerNode_[blockId]*interface->getEntity(0)->getNumNodes());
150 this->IDofs_[blockId] = LOVecPtr(this->DofsPerNode_[blockId]*interior->getEntity(0)->getNumNodes());
151 for (UN k=0; k<this->DofsPerNode_[blockId]; k++) {
152 for (UN i=0; i<interface->getEntity(0)->getNumNodes(); i++) {
153 this->GammaDofs_[blockId][this->DofsPerNode_[blockId]*i+k] = interface->getEntity(0)->getLocalDofID(i,k);
154 }
155 for (UN i=0; i<interior->getEntity(0)->getNumNodes(); i++) {
156 this->IDofs_[blockId][this->DofsPerNode_[blockId]*i+k] = interior->getEntity(0)->getLocalDofID(i,k);
157 }
158 }
159
160 this->InterfaceCoarseSpaces_[blockId].reset(new CoarseSpace<SC,LO,GO,NO>(this->MpiComm_,this->SerialComm_));
161
162 if (this->ParameterList_->get("Test Unconnected Interface",true)) {
163 this->DDInterface_->divideUnconnectedEntities(this->K_);
164 }
165
166 this->DDInterface_->buildEntityHierarchy();
167
168 this->DDInterface_->computeDistancesToRoots(dimension,nodeList,distanceFunction);
169
170 //////////////////////////
171 // Root Basis Functions //
172 //////////////////////////
173 EntitySetPtrVecPtr entitySetVector = this->DDInterface_->getEntitySetVector();
174 this->DDInterface_->buildEntityMaps(false,
175 false,
176 false,
177 false,
178 false,
179 true);
180
181 XMultiVectorPtrVecPtr translations = this->computeTranslations(blockId,this->DDInterface_->getRoots(),entitySetVector,distanceFunction);
182 for (UN i=0; i<translations.size(); i++) {
183 this->InterfaceCoarseSpaces_[blockId]->addSubspace(this->DDInterface_->getRoots()->getEntityMap(),null,translations[i]);
184 }
185
186 if (useRotations) {
187 XMultiVectorPtrVecPtr rotations = this->computeRotations(blockId,dimension,nodeList,this->DDInterface_->getRoots(),entitySetVector,distanceFunction);
188 for (UN i=0; i<rotations.size(); i++) { this->InterfaceCoarseSpaces_[blockId]->addSubspace(this->DDInterface_->getRoots()->getEntityMap(),null,rotations[i]);
189 }
190 }
191
192 this->InterfaceCoarseSpaces_[blockId]->assembleCoarseSpace();
193
194 if (this->Verbose_) {
195 cout
196 << "\n" << setw(FROSCH_OUTPUT_INDENT) << " "
197 << setw(89) << "-----------------------------------------------------------------------------------------"
198 << "\n" << setw(FROSCH_OUTPUT_INDENT) << " "
199 << "| "
200 << left << setw(74) << "> RGDSW coarse space " << right << setw(8) << "(Level " << setw(2) << this->LevelID_ << ")"
201 << " |"
202 << "\n" << setw(FROSCH_OUTPUT_INDENT) << " "
203 << setw(89) << "========================================================================================="
204 << "\n" << setw(FROSCH_OUTPUT_INDENT) << " "
205 << "| " << left << setw(19) << "Coarse nodes " << " | " << setw(19) << "Translations " << right
206 << " | " << setw(41) << boolalpha << useForCoarseSpace << noboolalpha
207 << " |"
208 << "\n" << setw(FROSCH_OUTPUT_INDENT) << " "
209 << "| " << left << setw(19) << "Coarse nodes " << " | " << setw(19) << "Rotations " << right
210 << " | " << setw(41) << boolalpha << useRotations << noboolalpha
211 << " |"
212 << "\n" << setw(FROSCH_OUTPUT_INDENT) << " "
213 << setw(89) << "-----------------------------------------------------------------------------------------"
214 << endl;
215 }
216 }
217 }
218 return 0;
219 }
220
221 template<class SC,class LO,class GO,class NO>
222 typename RGDSWCoarseOperator<SC,LO,GO,NO>::XMapPtr RGDSWCoarseOperator<SC,LO,GO,NO>::BuildRepeatedMapCoarseLevel(ConstXMapPtr &nodesMap,
223 UN dofsPerNode,
224 ConstXMapPtrVecPtr dofsMaps,
225 UN partitionType)
226 {
227 FROSCH_ASSERT(false,"For RGDSWCoarseOperator the ZoltanDual Option is not implemented!");
228 }
229
230 template <class SC,class LO,class GO,class NO>
231 typename RGDSWCoarseOperator<SC,LO,GO,NO>::XMultiVectorPtrVecPtr RGDSWCoarseOperator<SC,LO,GO,NO>::computeTranslations(UN blockId,
232 EntitySetPtr Roots,
233 EntitySetPtrVecPtr entitySetVector,
234 DistanceFunction distanceFunction)
235 {
236 FROSCH_DETAILTIMER_START_LEVELID(computeTranslationsTime,"RGDSWCoarseOperator::computeTranslations");
237 XMultiVectorPtrVecPtr translations(this->DofsPerNode_[blockId]);
238 XMapPtr serialGammaMap = MapFactory<LO,GO,NO>::Build(this->K_->getRangeMap()->lib(),this->GammaDofs_[blockId].size(),0,this->SerialComm_);
239 for (UN i=0; i<this->DofsPerNode_[blockId]; i++) {
240 if (Roots->getNumEntities()>0) {
241 translations[i] = MultiVectorFactory<SC,LO,GO,NO>::Build(serialGammaMap,Roots->getNumEntities());
242 } else {
243 translations[i] = null;
244 }
245 }
246
247 // Loop over Dofs
248 for (UN k=0; k<this->DofsPerNode_[blockId]; k++) {
249 // Loop over entitySetVector
250 for (UN i=0; i<entitySetVector.size(); i++) {
251 // Loop over entities
252 for (UN j=0; j<entitySetVector[i]->getNumEntities(); j++) {
253 InterfaceEntityPtr tmpEntity = entitySetVector[i]->getEntity(j);
254 LO rootID = tmpEntity->getRootID();
255 UN numRoots = tmpEntity->getRoots()->getNumEntities();
256 if (rootID==-1) {
257 //if (numRoots==0) cout << rootID << " " << numRoots << " " << tmpEntity->getAncestors()->getNumEntities() << endl;
258 FROSCH_ASSERT(numRoots!=0,"rootID==-1 but numRoots==0!");
259 for (UN m=0; m<numRoots; m++) {
260 InterfaceEntityPtr tmpRoot = tmpEntity->getRoots()->getEntity(m);
261 LO index = tmpRoot->getRootID();
262 // Offspring: loop over nodes
263 for (UN l=0; l<tmpEntity->getNumNodes(); l++) {
264 SC value = tmpEntity->getDistanceToRoot(l,m)/tmpEntity->getDistanceToRoot(l,numRoots);
265 translations[k]->replaceLocalValue(tmpEntity->getGammaDofID(l,k),index,value);
266 }
267 }
268 } else {
269 // Coarse node: loop over nodes
270 for (UN l=0; l<entitySetVector[i]->getEntity(j)->getNumNodes(); l++) {
271 translations[k]->replaceLocalValue(tmpEntity->getGammaDofID(l,k),rootID,ScalarTraits<SC>::one());
272 }
273 }
274 }
275 }
276 }
277 return translations;
278 }
279
280 template <class SC,class LO,class GO,class NO>
281 typename RGDSWCoarseOperator<SC,LO,GO,NO>::XMultiVectorPtrVecPtr RGDSWCoarseOperator<SC,LO,GO,NO>::computeRotations(UN blockId,
282 UN dimension,
283 ConstXMultiVectorPtr nodeList,
284 EntitySetPtr Roots,
285 EntitySetPtrVecPtr entitySetVector,
286 DistanceFunction distanceFunction)
287 {
288 FROSCH_DETAILTIMER_START_LEVELID(computeRotationsTime,"RGDSWCoarseOperator::computeRotations");
289 FROSCH_ASSERT(nodeList->getNumVectors()==dimension,"dimension of the nodeList is wrong.");
290 FROSCH_ASSERT(dimension==this->DofsPerNode_[blockId],"dimension!=this->DofsPerNode_[blockId]");
291
292 UN rotationsPerEntity = 0;
293 switch (dimension) {
294 case 1:
295 return null;
296 case 2:
297 rotationsPerEntity = 1;
298 break;
299 case 3:
300 rotationsPerEntity = 3;
301 break;
302 default:
303 FROSCH_ASSERT(false,"The dimension is neither 2 nor 3!");
304 }
305
306 XMultiVectorPtrVecPtr rotations(rotationsPerEntity);
307 XMapPtr serialGammaMap = MapFactory<LO,GO,NO>::Build(this->K_->getRangeMap()->lib(),this->GammaDofs_[blockId].size(),0,this->SerialComm_);
308 for (UN i=0; i<rotationsPerEntity; i++) {
309 if (Roots->getNumEntities()>0) {
310 rotations[i] = MultiVectorFactory<SC,LO,GO,NO>::Build(serialGammaMap,Roots->getNumEntities());
311 } else {
312 rotations[i] = null;
313 }
314 }
315
316 SC x,y,z,rx,ry,rz;
317 // Loop over entitySetVector
318 for (UN i=0; i<entitySetVector.size(); i++) {
319 // Loop over entities
320 for (UN j=0; j<entitySetVector[i]->getNumEntities(); j++) {
321 InterfaceEntityPtr tmpEntity = entitySetVector[i]->getEntity(j);
322 LO rootID = tmpEntity->getRootID();
323 UN numRoots = tmpEntity->getRoots()->getNumEntities();
324 if (rootID==-1) {
325 FROSCH_ASSERT(numRoots!=0,"rootID==-1 but numRoots==0!");
326 for (UN m=0; m<numRoots; m++) {
327 InterfaceEntityPtr tmpRoot = tmpEntity->getRoots()->getEntity(m);
328 LO index = tmpRoot->getRootID();
329 // Offspring: loop over nodes
330 for (UN l=0; l<tmpEntity->getNumNodes(); l++) {
331 SC value = tmpEntity->getDistanceToRoot(l,m)/tmpEntity->getDistanceToRoot(l,numRoots);
332
333 // Rotations
334 x = nodeList->getData(0)[tmpEntity->getLocalNodeID(l)];
335 y = nodeList->getData(1)[tmpEntity->getLocalNodeID(l)];
336
337 // Rotation 1
338 rx = y;
339 ry = -x;
340 rz = 0;
341 rotations[0]->replaceLocalValue(tmpEntity->getGammaDofID(l,0),index,value*rx);
342 rotations[0]->replaceLocalValue(tmpEntity->getGammaDofID(l,1),index,value*ry);
343 if (dimension == 3) {
344 z = nodeList->getData(2)[tmpEntity->getLocalNodeID(l)];
345
346 rotations[0]->replaceLocalValue(tmpEntity->getGammaDofID(l,2),index,value*rz);
347
348 // Rotation 2
349 rx = -z;
350 ry = 0;
351 rz = x;
352 rotations[1]->replaceLocalValue(tmpEntity->getGammaDofID(l,0),index,value*rx);
353 rotations[1]->replaceLocalValue(tmpEntity->getGammaDofID(l,1),index,value*ry);
354 rotations[1]->replaceLocalValue(tmpEntity->getGammaDofID(l,2),index,value*rz);
355
356 // Rotation 3
357 rx = 0;
358 ry = z;
359 rz = -y;
360 rotations[2]->replaceLocalValue(tmpEntity->getGammaDofID(l,0),index,value*rx);
361 rotations[2]->replaceLocalValue(tmpEntity->getGammaDofID(l,1),index,value*ry);
362 rotations[2]->replaceLocalValue(tmpEntity->getGammaDofID(l,2),index,value*rz);
363 }
364 }
365 }
366 } else {
367 // Coarse node: loop over nodes
368 for (UN l=0; l<entitySetVector[i]->getEntity(j)->getNumNodes(); l++) {
369 // Rotations
370 x = nodeList->getData(0)[tmpEntity->getLocalNodeID(l)];
371 y = nodeList->getData(1)[tmpEntity->getLocalNodeID(l)];
372
373 // Rotation 1
374 rx = y;
375 ry = -x;
376 rz = 0;
377 rotations[0]->replaceLocalValue(tmpEntity->getGammaDofID(l,0),rootID,rx);
378 rotations[0]->replaceLocalValue(tmpEntity->getGammaDofID(l,1),rootID,ry);
379 if (dimension == 3) {
380 z = nodeList->getData(2)[tmpEntity->getLocalNodeID(l)];
381
382 rotations[0]->replaceLocalValue(tmpEntity->getGammaDofID(l,2),rootID,rz);
383
384 // Rotation 2
385 rx = -z;
386 ry = 0;
387 rz = x;
388 rotations[1]->replaceLocalValue(tmpEntity->getGammaDofID(l,0),rootID,rx);
389 rotations[1]->replaceLocalValue(tmpEntity->getGammaDofID(l,1),rootID,ry);
390 rotations[1]->replaceLocalValue(tmpEntity->getGammaDofID(l,2),rootID,rz);
391
392 // Rotation 3
393 rx = 0;
394 ry = z;
395 rz = -y;
396 rotations[2]->replaceLocalValue(tmpEntity->getGammaDofID(l,0),rootID,rx);
397 rotations[2]->replaceLocalValue(tmpEntity->getGammaDofID(l,1),rootID,ry);
398 rotations[2]->replaceLocalValue(tmpEntity->getGammaDofID(l,2),rootID,rz);
399 }
400 }
401 }
402 }
403 }
404 return rotations;
405 }
406 }
407
408 #endif