Debian Codegraph @

packages/shylu/shylu_dd/frosch/src/CoarseSpaces/FROSch_GDSWStarInterfacePartitionOfUnity_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_GDSWSTARINTERFACEPARTITIONOFUNITY_DEF_HPP
11 #define _FROSCH_GDSWSTARINTERFACEPARTITIONOFUNITY_DEF_HPP
12
13 #include <FROSch_GDSWStarInterfacePartitionOfUnity_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 GDSWStarInterfacePartitionOfUnity<SC,LO,GO,NO>::GDSWStarInterfacePartitionOfUnity(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 GDSWInterfacePartitionOfUnity<SC,LO,GO,NO> (mpiComm,serialComm,dimension,dofsPerNode,nodesMap,dofsMaps,parameterList,verbosity,levelID)
33 {
34 FROSCH_DETAILTIMER_START_LEVELID(GDSWStarInterfacePartitionOfUnityTime,"GDSWStarInterfacePartitionOfUnity::GDSWStarInterfacePartitionOfUnity");
35 this->UseVertices_ = false;
36 this->UseShortEdges_ = false;
37 this->UseStraightEdges_ = false;
38 this->UseEdges_ = false;
39 this->UseFaces_ = false;
40
41 if (!this->ParameterList_->get("Type","Full").compare("Full")) {
42 UseRoots_ = true;
43 UseLeafs_ = true;
44 } else if (!this->ParameterList_->get("Type","Full").compare("Roots")) {
45 UseRoots_ = true;
46 UseLeafs_ = false;
47 } else if (!this->ParameterList_->get("Type","Full").compare("Leafs")) {
48 UseRoots_ = false;
49 UseLeafs_ = true;
50 } else if (!this->ParameterList_->get("Type","Full").compare("Custom")) {
51 UseRoots_ = this->ParameterList_->sublist("Custom").get("Roots",false);
52 UseLeafs_ = this->ParameterList_->sublist("Custom").get("Leafs",false);
53 } else {
54 FROSCH_ASSERT(false,"FROSch::GDSWStarInterfacePartitionOfUnity: Specify a valid Type.");
55 }
56
57 if (!this->ParameterList_->get("Distance Function","Constant").compare("Constant")) {
58 DistanceFunction_ = ConstantDistanceFunction;
59 } else if (!this->ParameterList_->get("Distance Function","Constant").compare("Inverse Euclidean")) {
60 DistanceFunction_ = InverseEuclideanDistanceFunction;
61 } else {
62 FROSCH_ASSERT(false,"FROSch::GDSWStarInterfacePartitionOfUnity: Specify a valid Distance Function.");
63 }
64 this->LocalPartitionOfUnity_ = ConstXMultiVectorPtrVecPtr(2);
65 this->PartitionOfUnityMaps_ = ConstXMapPtrVecPtr(2);
66 }
67
68 template <class SC,class LO,class GO,class NO>
69 int GDSWStarInterfacePartitionOfUnity<SC,LO,GO,NO>::computePartitionOfUnity(ConstXMultiVectorPtr nodeList)
70 {
71 FROSCH_DETAILTIMER_START_LEVELID(computePartitionOfUnityTime,"GDSWStarInterfacePartitionOfUnity::computePartitionOfUnity");
72 // Interface
73 UN dofsPerNode = this->DDInterface_->getInterface()->getEntity(0)->getDofsPerNode();
74 UN numInterfaceDofs = dofsPerNode*this->DDInterface_->getInterface()->getEntity(0)->getNumNodes();
75
76 this->DDInterface_->buildEntityHierarchy();
77
78 this->DDInterface_->computeDistancesToRoots(this->DDInterface_->getDimension(),nodeList,DistanceFunction_);
79
80 this->DDInterface_->buildEntityMaps(false,
81 false,
82 false,
83 false,
84 false,
85 UseRoots_,
86 UseLeafs_);
87
88 EntitySetVector_ = this->DDInterface_->getEntitySetVector();
89
90 // Map
91 if (UseRoots_) {
92 Roots_ = this->DDInterface_->getRoots();
93 this->PartitionOfUnityMaps_[0] = Roots_->getEntityMap();
94 }
95 if (UseLeafs_) {
96 Leafs_ = this->DDInterface_->getLeafs();
97 this->PartitionOfUnityMaps_[1] = Leafs_->getEntityMap();
98 }
99
100 if (this->Verbose_) {
101 cout
102 << "\n" << setw(FROSCH_OUTPUT_INDENT) << " "
103 << setw(89) << "-----------------------------------------------------------------------------------------"
104 << "\n" << setw(FROSCH_OUTPUT_INDENT) << " "
105 << "| "
106 << left << setw(74) << "> GDSW Star Interface Partition Of Unity " << right << setw(8) << "(Level " << setw(2) << this->LevelID_ << ")" << right
107 << " |"
108 << "\n" << setw(FROSCH_OUTPUT_INDENT) << " "
109 << setw(89) << "========================================================================================="
110 << "\n" << setw(FROSCH_OUTPUT_INDENT) << " "
111 << "| " << left << setw(41) << "Roots" << right
112 << " | " << setw(41) << boolalpha << UseRoots_ << noboolalpha
113 << " |"
114 << "\n" << setw(FROSCH_OUTPUT_INDENT) << " "
115 << "| " << left << setw(41) << "Leafs" << right
116 << " | " << setw(41) << boolalpha << UseLeafs_ << noboolalpha
117 << " |"
118 << "\n" << setw(FROSCH_OUTPUT_INDENT) << " "
119 << setw(89) << "-----------------------------------------------------------------------------------------"
120 << endl;
121 }
122
123 // Build Partition Of Unity Vectors
124 XMapPtr serialInterfaceMap = MapFactory<LO,GO,NO>::Build(this->DDInterface_->getNodesMap()->lib(),numInterfaceDofs,0,this->SerialComm_);
125
126 if (UseRoots_ && Roots_->getNumEntities()>0) {
127 XMultiVectorPtr tmpVector = MultiVectorFactory<SC,LO,GO,NO>::Build(serialInterfaceMap,Roots_->getNumEntities());
128
129 // Loop over EntitySetVector_
130 for (UN i=0; i<EntitySetVector_.size(); i++) {
131 // Loop over entities
132 for (UN j=0; j<EntitySetVector_[i]->getNumEntities(); j++) {
133 InterfaceEntityPtr tmpEntity = EntitySetVector_[i]->getEntity(j);
134 LO leafID = tmpEntity->getLeafID();
135 // If the entity is a leaf, it will obtain its own partition of unity function
136 if (leafID==-1) {
137 LO rootID = tmpEntity->getRootID();
138 UN numRoots = tmpEntity->getRoots()->getNumEntities();
139 if (rootID==-1) {
140 FROSCH_ASSERT(numRoots!=0,"FROSch::GDSWStarInterfacePartitionOfUnity: rootID==-1 but numRoots==0!");
141 for (UN m=0; m<numRoots; m++) {
142 InterfaceEntityPtr tmpRoot = tmpEntity->getRoots()->getEntity(m);
143 LO index = tmpRoot->getRootID();
144 // Offspring: loop over nodes
145 for (UN l=0; l<tmpEntity->getNumNodes(); l++) {
146 SC value = tmpEntity->getDistanceToRoot(l,m)/tmpEntity->getDistanceToRoot(l,numRoots);
147 for (UN k=0; k<dofsPerNode; k++) {
148 tmpVector->replaceLocalValue(tmpEntity->getGammaDofID(l,k),index,value*ScalarTraits<SC>::one());
149 }
150 }
151 }
152 } else {
153 // Coarse node: loop over nodes
154 for (UN l=0; l<EntitySetVector_[i]->getEntity(j)->getNumNodes(); l++) {
155 for (UN k=0; k<dofsPerNode; k++) {
156 tmpVector->replaceLocalValue(tmpEntity->getGammaDofID(l,k),rootID,ScalarTraits<SC>::one());
157 }
158 }
159 }
160 }
161 }
162 }
163 this->LocalPartitionOfUnity_[0] = tmpVector;
164 }
165
166 if (UseLeafs_ && Leafs_->getNumEntities()>0) {
167 XMultiVectorPtr tmpVector = MultiVectorFactory<SC,LO,GO,NO>::Build(serialInterfaceMap,Leafs_->getNumEntities());
168
169 for (UN i=0; i<Leafs_->getNumEntities(); i++) {
170 InterfaceEntityPtr tmpEntity = Leafs_->getEntity(i);
171 LO leafID = tmpEntity->getLeafID();
172 FROSCH_ASSERT(leafID==LO(i),"FROSch::GDSWStarInterfacePartitionOfUnity: leafID!=i!");
173 for (UN j=0; j<Leafs_->getEntity(i)->getNumNodes(); j++) {
174 for (UN k=0; k<dofsPerNode; k++) {
175 tmpVector->replaceLocalValue(Leafs_->getEntity(i)->getGammaDofID(j,k),leafID,ScalarTraits<SC>::one());
176 }
177 }
178 }
179 this->LocalPartitionOfUnity_[1] = tmpVector;
180 }
181
182 return 0;
183 }
184
185 }
186
187 #endif