| 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_CONSTANTPARTITIONOFUNITY_DEF_HPP |
| 11 |
#define _FROSCH_CONSTANTPARTITIONOFUNITY_DEF_HPP |
| 12 |
|
| 13 |
#include <FROSch_ConstantPartitionOfUnity_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 |
ConstantPartitionOfUnity<SC,LO,GO,NO>::ConstantPartitionOfUnity(CommPtr mpiComm, |
| 24 |
CommPtr serialComm, |
| 25 |
UN dimension, |
| 26 |
UN dofsPerNode, |
| 27 |
ConstXMapPtr nodesMap, |
| 28 |
ConstXMapPtrVecPtr dofsMaps, |
| 29 |
ParameterListPtr parameterList, |
| 30 |
Verbosity verbosity, |
| 31 |
UN levelID, |
| 32 |
DDInterfacePtr ddInterface) : |
| 33 |
PartitionOfUnity<SC,LO,GO,NO> (mpiComm,serialComm,dofsPerNode,nodesMap,dofsMaps,parameterList,verbosity,levelID), |
| 34 |
DDInterface_ (ddInterface) |
| 35 |
{ |
| 36 |
FROSCH_DETAILTIMER_START_LEVELID(constantPartitionOfUnityTime,"ConstantPartitionOfUnity::ConstantPartitionOfUnity"); |
| 37 |
|
| 38 |
if (!this->ParameterList_->get("Type","Full").compare("Full")) { |
| 39 |
UseVolumes_ = true; |
| 40 |
} else if (!this->ParameterList_->get("Type","Full").compare("Volumes")) { |
| 41 |
UseVolumes_ = true; |
| 42 |
} else if (!this->ParameterList_->get("Type","Full").compare("Custom")) { |
| 43 |
UseVolumes_ = this->ParameterList_->sublist("Custom").get("Volumes",false); |
| 44 |
} else { |
| 45 |
FROSCH_ASSERT(false,"FROSch::ConstantPartitionOfUnity: Specify a valid Type."); |
| 46 |
} |
| 47 |
|
| 48 |
CommunicationStrategy communicationStrategy = CreateOneToOneMap; |
| 49 |
if (!this->ParameterList_->get("Interface Communication Strategy","CreateOneToOneMap").compare("CrsMatrix")) { |
| 50 |
communicationStrategy = CommCrsMatrix; |
| 51 |
} else if (!this->ParameterList_->get("Interface Communication Strategy","CreateOneToOneMap").compare("CrsGraph")) { |
| 52 |
communicationStrategy = CommCrsGraph; |
| 53 |
} else if (!this->ParameterList_->get("Interface Communication Strategy","CreateOneToOneMap").compare("CreateOneToOneMap")) { |
| 54 |
communicationStrategy = CreateOneToOneMap; |
| 55 |
} else { |
| 56 |
FROSCH_ASSERT(false,"FROSch::InterfacePartitionOfUnity: Specify a valid communication strategy for the identification of the interface components."); |
| 57 |
} |
| 58 |
|
| 59 |
if (DDInterface_.is_null()) DDInterface_.reset(new DDInterface<SC,LO,GO,NO>(dimension,dofsPerNode,nodesMap.getConst(),this->Verbosity_,this->LevelID_,communicationStrategy)); |
| 60 |
FROSCH_ASSERT(DDInterface_->getInterface()->getEntity(0)->getNumNodes()==0,"FROSch::ConstantPartitionOfUnity: Is only reasonable if there is no interface."); |
| 61 |
DDInterface_->resetGlobalDofs(dofsMaps); |
| 62 |
Volumes_ = DDInterface_->getInterior()->deepCopy(); |
| 63 |
|
| 64 |
this->LocalPartitionOfUnity_ = ConstXMultiVectorPtrVecPtr(1); |
| 65 |
this->PartitionOfUnityMaps_ = ConstXMapPtrVecPtr(1); |
| 66 |
} |
| 67 |
|
| 68 |
template <class SC,class LO,class GO,class NO> |
| 69 |
ConstantPartitionOfUnity<SC,LO,GO,NO>::~ConstantPartitionOfUnity() |
| 70 |
{ |
| 71 |
|
| 72 |
} |
| 73 |
|
| 74 |
template <class SC,class LO,class GO,class NO> |
| 75 |
int ConstantPartitionOfUnity<SC,LO,GO,NO>::removeDirichletNodes(GOVecView dirichletBoundaryDofs, |
| 76 |
ConstXMultiVectorPtr nodeList) |
| 77 |
{ |
| 78 |
FROSCH_DETAILTIMER_START_LEVELID(removeDirichletNodesTime,"ConstantPartitionOfUnity::removeDirichletNodes"); |
| 79 |
if (!dirichletBoundaryDofs.is_null()) { |
| 80 |
GOVec tmpDirichletBoundaryDofs(dirichletBoundaryDofs()); |
| 81 |
sortunique(tmpDirichletBoundaryDofs); |
| 82 |
Volumes_->removeNodesWithDofs(tmpDirichletBoundaryDofs()); |
| 83 |
Volumes_->removeEmptyEntities(); |
| 84 |
Volumes_->setUniqueIDToFirstGlobalNodeID(); |
| 85 |
} |
| 86 |
return 0; |
| 87 |
} |
| 88 |
|
| 89 |
template <class SC,class LO,class GO,class NO> |
| 90 |
int ConstantPartitionOfUnity<SC,LO,GO,NO>::computePartitionOfUnity(ConstXMultiVectorPtr nodeList) |
| 91 |
{ |
| 92 |
FROSCH_DETAILTIMER_START_LEVELID(computePartitionOfUnityTime,"ConstantPartitionOfUnity::computePartitionOfUnity"); |
| 93 |
// Interface |
| 94 |
UN dofsPerNode = DDInterface_->getInterior()->getEntity(0)->getDofsPerNode(); |
| 95 |
UN numInteriorDofs = dofsPerNode*DDInterface_->getInterior()->getEntity(0)->getNumNodes(); |
| 96 |
|
| 97 |
if (UseVolumes_) Volumes_->buildEntityMap(DDInterface_->getNodesMap()); |
| 98 |
|
| 99 |
if (this->Verbosity_==All) { |
| 100 |
FROSCH_DETAILTIMER_START_LEVELID(printStatisticsTime,"print statistics"); |
| 101 |
// Count entities |
| 102 |
GOVec globalVec(1); |
| 103 |
LOVec localVec(1); |
| 104 |
LOVec sumVec(1); |
| 105 |
SCVec avgVec(1); |
| 106 |
LOVec minVec(1); |
| 107 |
LOVec maxVec(1); |
| 108 |
if (UseVolumes_) { |
| 109 |
globalVec[0] = Volumes_->getEntityMap()->getMaxAllGlobalIndex(); |
| 110 |
if (DDInterface_->getNodesMap()->lib()==UseEpetra || Volumes_->getEntityMap()->getGlobalNumElements()>0) { |
| 111 |
globalVec[0] += 1; |
| 112 |
} |
| 113 |
if (globalVec[0]<0) globalVec[0] = 0; |
| 114 |
localVec[0] = (LO) max((LO) Volumes_->getEntityMap()->getLocalNumElements(),(LO) 0); |
| 115 |
reduceAll(*this->MpiComm_,REDUCE_SUM,localVec[0],ptr(&sumVec[0])); |
| 116 |
avgVec[0] = max(sumVec[0]/double(this->MpiComm_->getSize()),0.0); |
| 117 |
reduceAll(*this->MpiComm_,REDUCE_MIN,localVec[0],ptr(&minVec[0])); |
| 118 |
reduceAll(*this->MpiComm_,REDUCE_MAX,localVec[0],ptr(&maxVec[0])); |
| 119 |
} else { |
| 120 |
globalVec[0] = -1; |
| 121 |
localVec[0] = -1; |
| 122 |
avgVec[0] = -1; |
| 123 |
minVec[0] = -1; |
| 124 |
maxVec[0] = -1; |
| 125 |
} |
| 126 |
|
| 127 |
if (globalVec[0]<0) { |
| 128 |
globalVec[0] = -1; |
| 129 |
} |
| 130 |
|
| 131 |
if (this->Verbose_) { |
| 132 |
cout |
| 133 |
<< "\n" << setw(FROSCH_OUTPUT_INDENT) << " " |
| 134 |
<< setw(89) << "-----------------------------------------------------------------------------------------" |
| 135 |
<< "\n" << setw(FROSCH_OUTPUT_INDENT) << " " |
| 136 |
<< "| " |
| 137 |
<< left << setw(74) << "> Volumes statistics " << right << setw(8) << "(Level " << setw(2) << this->LevelID_ << ")" << right |
| 138 |
<< " |" |
| 139 |
<< "\n" << setw(FROSCH_OUTPUT_INDENT) << " " |
| 140 |
<< setw(89) << "=========================================================================================" |
| 141 |
<< "\n" << setw(FROSCH_OUTPUT_INDENT) << " " |
| 142 |
<< "| " << left << setw(20) << " " << right |
| 143 |
<< " | " << setw(10) << "total" |
| 144 |
<< " | " << setw(10) << "avg" |
| 145 |
<< " | " << setw(10) << "min" |
| 146 |
<< " | " << setw(10) << "max" |
| 147 |
<< " | " << setw(10) << "global sum" |
| 148 |
<< " |" |
| 149 |
<< "\n" << setw(FROSCH_OUTPUT_INDENT) << " " |
| 150 |
<< setw(89) << "-----------------------------------------------------------------------------------------" |
| 151 |
<< "\n" << setw(FROSCH_OUTPUT_INDENT) << " " |
| 152 |
<< "| " << left << setw(20) << "Volumes" << right |
| 153 |
<< " | "; globalVec[0]<0 ? cout << setw(10) << " " : cout << setw(10) << globalVec[0]; cout |
| 154 |
<< " | "; avgVec[0]<0 ? cout << setw(10) << " " : cout << setw(10) << setprecision(5) << avgVec[0]; cout |
| 155 |
<< " | "; minVec[0]<0 ? cout << setw(10) << " " : cout << setw(10) << minVec[0]; cout |
| 156 |
<< " | "; maxVec[0]<0 ? cout << setw(10) << " " : cout << setw(10) << maxVec[0]; cout |
| 157 |
<< " | "; sumVec[0]<0 ? cout << setw(10) << " " : cout << setw(10) << sumVec[0]; cout |
| 158 |
<< " |" |
| 159 |
<< "\n" << setw(FROSCH_OUTPUT_INDENT) << " " |
| 160 |
<< setw(89) << "-----------------------------------------------------------------------------------------" |
| 161 |
<< endl; |
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
// Maps |
| 166 |
if (UseVolumes_) { |
| 167 |
this->PartitionOfUnityMaps_[0] = Volumes_->getEntityMap(); |
| 168 |
} |
| 169 |
|
| 170 |
if (this->Verbose_) { |
| 171 |
cout |
| 172 |
<< "\n" << setw(FROSCH_OUTPUT_INDENT) << " " |
| 173 |
<< setw(89) << "-----------------------------------------------------------------------------------------" |
| 174 |
<< "\n" << setw(FROSCH_OUTPUT_INDENT) << " " |
| 175 |
<< "| " |
| 176 |
<< left << setw(74) << "> Constant Partition Of Unity " << right << setw(8) << "(Level " << setw(2) << this->LevelID_ << ")" |
| 177 |
<< " |" |
| 178 |
<< "\n" << setw(FROSCH_OUTPUT_INDENT) << " " |
| 179 |
<< setw(89) << "=========================================================================================" |
| 180 |
<< "\n" << setw(FROSCH_OUTPUT_INDENT) << " " |
| 181 |
<< "| " << left << setw(41) << "Volumes" << right |
| 182 |
<< " | " << setw(41) << boolalpha << UseVolumes_ << noboolalpha |
| 183 |
<< " |" |
| 184 |
<< "\n" << setw(FROSCH_OUTPUT_INDENT) << " " |
| 185 |
<< setw(89) << "-----------------------------------------------------------------------------------------" |
| 186 |
<< endl; |
| 187 |
} |
| 188 |
|
| 189 |
// Build Partition Of Unity Vectors |
| 190 |
XMapPtr serialMap = MapFactory<LO,GO,NO>::Build(DDInterface_->getNodesMap()->lib(),numInteriorDofs,0,this->SerialComm_); |
| 191 |
|
| 192 |
if (UseVolumes_ && Volumes_->getNumEntities()>0) { |
| 193 |
XMultiVectorPtr tmpVector = MultiVectorFactory<SC,LO,GO,NO>::Build(serialMap,Volumes_->getNumEntities()); |
| 194 |
|
| 195 |
for (UN i=0; i<Volumes_->getNumEntities(); i++) { |
| 196 |
for (UN j=0; j<Volumes_->getEntity(i)->getNumNodes(); j++) { |
| 197 |
for (UN k=0; k<dofsPerNode; k++) { |
| 198 |
tmpVector->replaceLocalValue(Volumes_->getEntity(i)->getGammaDofID(j,k),i,ScalarTraits<SC>::one()); |
| 199 |
} |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
this->LocalPartitionOfUnity_[0] = tmpVector; |
| 204 |
} |
| 205 |
return 0; |
| 206 |
} |
| 207 |
} |
| 208 |
|
| 209 |
#endif |