| 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_PARTITIONOFUNITYBASIS_DEF_HPP |
| 11 |
#define _FROSCH_PARTITIONOFUNITYBASIS_DEF_HPP |
| 12 |
|
| 13 |
#include <FROSch_LocalPartitionOfUnityBasis_decl.hpp> |
| 14 |
|
| 15 |
|
| 16 |
namespace FROSch { |
| 17 |
|
| 18 |
using namespace Teuchos; |
| 19 |
using namespace Xpetra; |
| 20 |
|
| 21 |
template<class SC,class LO,class GO,class NO> |
| 22 |
LocalPartitionOfUnityBasis<SC,LO,GO,NO>::LocalPartitionOfUnityBasis(CommPtr mpiComm, |
| 23 |
CommPtr serialComm, |
| 24 |
UN dofsPerNode, |
| 25 |
ParameterListPtr parameterList, |
| 26 |
ConstXMultiVectorPtr nullSpaceBasis, |
| 27 |
ConstXMultiVectorPtrVecPtr partitionOfUnity, |
| 28 |
ConstXMapPtrVecPtr partitionOfUnityMaps) : |
| 29 |
MpiComm_ (mpiComm), |
| 30 |
SerialComm_ (serialComm), |
| 31 |
DofsPerNode_ (dofsPerNode), |
| 32 |
ParameterList_ (parameterList), |
| 33 |
PartitionOfUnity_ (partitionOfUnity), |
| 34 |
NullspaceBasis_ (nullSpaceBasis), |
| 35 |
PartitionOfUnityMaps_ (partitionOfUnityMaps) |
| 36 |
{ |
| 37 |
|
| 38 |
} |
| 39 |
|
| 40 |
template<class SC,class LO,class GO,class NO> |
| 41 |
int LocalPartitionOfUnityBasis<SC,LO,GO,NO>::addPartitionOfUnity(ConstXMultiVectorPtrVecPtr partitionOfUnity, |
| 42 |
ConstXMapPtrVecPtr partitionOfUnityMaps) |
| 43 |
{ |
| 44 |
PartitionOfUnity_ = partitionOfUnity; |
| 45 |
PartitionOfUnityMaps_ = partitionOfUnityMaps; |
| 46 |
return 0; |
| 47 |
} |
| 48 |
|
| 49 |
template<class SC,class LO,class GO,class NO> |
| 50 |
int LocalPartitionOfUnityBasis<SC,LO,GO,NO>::addGlobalBasis(ConstXMultiVectorPtr nullSpaceBasis) |
| 51 |
{ |
| 52 |
NullspaceBasis_ = nullSpaceBasis; |
| 53 |
return 0; |
| 54 |
} |
| 55 |
|
| 56 |
template<class SC,class LO,class GO,class NO> |
| 57 |
int LocalPartitionOfUnityBasis<SC,LO,GO,NO>::buildLocalPartitionOfUnityBasis() |
| 58 |
{ |
| 59 |
FROSCH_ASSERT(!NullspaceBasis_.is_null(),"Nullspace Basis is not set."); |
| 60 |
FROSCH_ASSERT(!PartitionOfUnity_.is_null(),"Partition Of Unity is not set."); |
| 61 |
FROSCH_ASSERT(!PartitionOfUnityMaps_.is_null(),"Partition Of Unity Map is not set."); |
| 62 |
|
| 63 |
LocalPartitionOfUnitySpace_ = CoarseSpacePtr(new CoarseSpace<SC,LO,GO,NO>(this->MpiComm_,this->SerialComm_)); |
| 64 |
|
| 65 |
XMultiVectorPtrVecPtr2D tmpBasis(PartitionOfUnity_.size()); |
| 66 |
ConstXMapPtr nullspaceBasisMap = NullspaceBasis_->getMap(); |
| 67 |
for (UN i=0; i<PartitionOfUnity_.size(); i++) { |
| 68 |
if (!PartitionOfUnity_[i].is_null()) { |
| 69 |
FROSCH_ASSERT(PartitionOfUnityMaps_[i]->getLocalNumElements()>0,"PartitionOfUnityMaps_[i]->getLocalNumElements()==0"); |
| 70 |
tmpBasis[i] = XMultiVectorPtrVecPtr(PartitionOfUnity_[i]->getNumVectors()); |
| 71 |
for (UN j=0; j<PartitionOfUnity_[i]->getNumVectors(); j++) { |
| 72 |
XMultiVectorPtr tmpBasisJ = MultiVectorFactory<SC,LO,GO,NO>::Build(nullspaceBasisMap,NullspaceBasis_->getNumVectors()); |
| 73 |
tmpBasisJ->elementWiseMultiply(ScalarTraits<SC>::one(),*PartitionOfUnity_[i]->getVector(j),*NullspaceBasis_,ScalarTraits<SC>::one()); |
| 74 |
tmpBasis[i][j] = tmpBasisJ; |
| 75 |
} |
| 76 |
} else { |
| 77 |
FROSCH_ASSERT(PartitionOfUnityMaps_[i]->getLocalNumElements()==0,"PartitionOfUnityMaps_[i]->getLocalNumElements()!=0"); |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
// Kann man das schöner machen? |
| 82 |
for (UN i=0; i<PartitionOfUnity_.size(); i++) { |
| 83 |
if (!PartitionOfUnityMaps_[i].is_null()) { |
| 84 |
if (!PartitionOfUnity_[i].is_null()) { |
| 85 |
ConstXMapPtr partitionOfUnityMap_i = PartitionOfUnity_[i]->getMap(); |
| 86 |
for (UN j=0; j<NullspaceBasis_->getNumVectors(); j++) { |
| 87 |
XMultiVectorPtr entityBasis = MultiVectorFactory<SC,LO,GO,NO >::Build(partitionOfUnityMap_i,PartitionOfUnity_[i]->getNumVectors()); |
| 88 |
entityBasis->scale(ScalarTraits<SC>::zero()); |
| 89 |
for (UN k=0; k<PartitionOfUnity_[i]->getNumVectors(); k++) { |
| 90 |
if (j<tmpBasis[i][k]->getNumVectors()) { |
| 91 |
entityBasis->getDataNonConst(k).deepCopy(tmpBasis[i][k]->getData(j)()); // Here, we copy data. Do we need to do this? |
| 92 |
} |
| 93 |
} |
| 94 |
LocalPartitionOfUnitySpace_->addSubspace(PartitionOfUnityMaps_[i],null,entityBasis); |
| 95 |
} |
| 96 |
} else { |
| 97 |
for (UN j=0; j<NullspaceBasis_->getNumVectors(); j++) { |
| 98 |
LocalPartitionOfUnitySpace_->addSubspace(PartitionOfUnityMaps_[i]); |
| 99 |
} |
| 100 |
} |
| 101 |
} else { |
| 102 |
FROSCH_WARNING("FROSch::LocalPartitionOfUnityBasis",this->MpiComm_->getRank()==0,"PartitionOfUnityMaps_[i].is_null()"); |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
LocalPartitionOfUnitySpace_->assembleCoarseSpace(); |
| 107 |
|
| 108 |
return 0; |
| 109 |
} |
| 110 |
|
| 111 |
template<class SC,class LO,class GO,class NO> |
| 112 |
typename LocalPartitionOfUnityBasis<SC,LO,GO,NO>::XMultiVectorPtrVecPtr LocalPartitionOfUnityBasis<SC,LO,GO,NO>::getPartitionOfUnity() const |
| 113 |
{ |
| 114 |
FROSCH_ASSERT(!PartitionOfUnity_.is_null(),"Partition Of Unity is not set."); |
| 115 |
return PartitionOfUnity_; |
| 116 |
} |
| 117 |
|
| 118 |
template<class SC,class LO,class GO,class NO> |
| 119 |
typename LocalPartitionOfUnityBasis<SC,LO,GO,NO>::XMultiVectorPtr LocalPartitionOfUnityBasis<SC,LO,GO,NO>::getNullspaceBasis() const |
| 120 |
{ |
| 121 |
FROSCH_ASSERT(!NullspaceBasis_.is_null(),"Nullspace Basis is not set."); |
| 122 |
return NullspaceBasis_; |
| 123 |
} |
| 124 |
|
| 125 |
template<class SC,class LO,class GO,class NO> |
| 126 |
typename LocalPartitionOfUnityBasis<SC,LO,GO,NO>::CoarseSpacePtr LocalPartitionOfUnityBasis<SC,LO,GO,NO>::getLocalPartitionOfUnitySpace() const |
| 127 |
{ |
| 128 |
FROSCH_ASSERT(!LocalPartitionOfUnitySpace_.is_null(),"Local Partition Of Unity Space is not built yet."); |
| 129 |
return LocalPartitionOfUnitySpace_; |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
#endif |