| 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_ENTITYSET_DEF_HPP |
| 11 |
#define _FROSCH_ENTITYSET_DEF_HPP |
| 12 |
|
| 13 |
#include <FROSch_EntitySet_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 |
EntitySet<SC,LO,GO,NO>::EntitySet(EntityType type) : |
| 24 |
Type_ (type) |
| 25 |
{ |
| 26 |
|
| 27 |
} |
| 28 |
|
| 29 |
template<class SC,class LO,class GO,class NO> |
| 30 |
EntitySet<SC,LO,GO,NO>::EntitySet(const EntitySet<SC,LO,GO,NO> &entitySet) : |
| 31 |
Type_ (entitySet.getEntityType()), |
| 32 |
EntityVector_ (entitySet.getEntityVector()) |
| 33 |
{ |
| 34 |
|
| 35 |
} |
| 36 |
|
| 37 |
template<class SC,class LO,class GO,class NO> |
| 38 |
EntitySet<SC,LO,GO,NO>::~EntitySet() |
| 39 |
{ |
| 40 |
|
| 41 |
} // Do we need sth here? |
| 42 |
|
| 43 |
template<class SC,class LO,class GO,class NO> |
| 44 |
int EntitySet<SC,LO,GO,NO>::addEntity(InterfaceEntityPtr entity) |
| 45 |
{ |
| 46 |
FROSCH_ASSERT(Type_==DefaultType||entity->getEntityType()==Type_,"FROSch::EntitySet: Entity to add is of wrong type."); |
| 47 |
EntityVector_.push_back(entity); |
| 48 |
EntityMapIsUpToDate_ = false; |
| 49 |
return 0; |
| 50 |
} |
| 51 |
|
| 52 |
template<class SC,class LO,class GO,class NO> |
| 53 |
int EntitySet<SC,LO,GO,NO>::addEntitySet(EntitySetPtr entitySet) |
| 54 |
{ |
| 55 |
for (UN i=0; i<entitySet->getNumEntities(); i++) { |
| 56 |
addEntity(entitySet->getEntity(i)); |
| 57 |
} |
| 58 |
return 0; |
| 59 |
} |
| 60 |
|
| 61 |
template<class SC,class LO,class GO,class NO> |
| 62 |
typename EntitySet<SC,LO,GO,NO>::EntitySetPtr EntitySet<SC,LO,GO,NO>::deepCopy() |
| 63 |
{ |
| 64 |
EntitySetPtr copy(new EntitySet<SC,LO,GO,NO>(Type_)); |
| 65 |
for (UN i=0; i<getNumEntities(); i++) { |
| 66 |
InterfaceEntityPtr entity(new InterfaceEntity<SC,LO,GO,NO>(getEntity(i)->getEntityType(), |
| 67 |
getEntity(i)->getDofsPerNode(), |
| 68 |
getEntity(i)->getMultiplicity(), |
| 69 |
getEntity(i)->getSubdomainsVector().getRawPtr())); |
| 70 |
for (UN j=0; j<getEntity(i)->getNumNodes(); j++) { |
| 71 |
entity->addNode(getEntity(i)->getNode(j).NodeIDGamma_, |
| 72 |
getEntity(i)->getNode(j).NodeIDLocal_, |
| 73 |
getEntity(i)->getNode(j).NodeIDGlobal_, |
| 74 |
getEntity(i)->getNode(j).DofsGamma_.size(), |
| 75 |
getEntity(i)->getNode(j).DofsGamma_, |
| 76 |
getEntity(i)->getNode(j).DofsLocal_, |
| 77 |
getEntity(i)->getNode(j).DofsGlobal_); |
| 78 |
} |
| 79 |
copy->addEntity(entity); |
| 80 |
} |
| 81 |
return copy; |
| 82 |
} |
| 83 |
|
| 84 |
template<class SC,class LO,class GO,class NO> |
| 85 |
int EntitySet<SC,LO,GO,NO>::buildEntityMap(ConstXMapPtr localToGlobalNodesMap) |
| 86 |
{ |
| 87 |
if (!EntityMapIsUpToDate_) { |
| 88 |
LO localNumberEntities = getNumEntities(); |
| 89 |
LO globalNumberEntities = 0; // AH 10/13/2017: Can we stick with LO here |
| 90 |
LO maxLocalNumberEntities = 0; |
| 91 |
reduceAll(*localToGlobalNodesMap->getComm(),REDUCE_SUM,localNumberEntities,ptr(&globalNumberEntities)); |
| 92 |
reduceAll(*localToGlobalNodesMap->getComm(),REDUCE_MAX,localNumberEntities,ptr(&maxLocalNumberEntities)); |
| 93 |
|
| 94 |
GOVec localToGlobalVector(0); |
| 95 |
const GO INVALID = Teuchos::OrdinalTraits<GO>::invalid(); |
| 96 |
if (globalNumberEntities>0) { |
| 97 |
// Set the Unique iD |
| 98 |
setUniqueIDToFirstGlobalNodeID(); |
| 99 |
|
| 100 |
GOVec entities(maxLocalNumberEntities); |
| 101 |
for (UN i=0; i<getNumEntities(); i++) { |
| 102 |
entities[i] = getEntity(i)->getUniqueID()+1; |
| 103 |
getEntity(i)->setLocalID(i); |
| 104 |
} |
| 105 |
XMapPtr entityMapping = MapFactory<LO,GO,NO>::Build(localToGlobalNodesMap->lib(),INVALID,entities(),0,localToGlobalNodesMap->getComm()); |
| 106 |
|
| 107 |
GOVec allEntities(maxLocalNumberEntities*localToGlobalNodesMap->getComm()->getSize(),0); |
| 108 |
//localToGlobalNodesMap->getComm().GatherAll(&(entities->at(0)),&(allEntities->at(0)),maxLocalNumberEntities); |
| 109 |
gatherAll(*localToGlobalNodesMap->getComm(),maxLocalNumberEntities,entities.getRawPtr(),maxLocalNumberEntities*localToGlobalNodesMap->getComm()->getSize(),allEntities.getRawPtr()); |
| 110 |
|
| 111 |
allEntities.push_back(0); // Um sicherzugehen, dass der erste Eintrag nach sort_unique eine 0 ist. |
| 112 |
|
| 113 |
sortunique(allEntities); |
| 114 |
|
| 115 |
localToGlobalVector.resize(localNumberEntities); |
| 116 |
int LocalID; |
| 117 |
for (UN i=1; i<allEntities.size(); i++) { // Wir fangen bei 1 an, weil wir am Anfang 1 auf die ID addiert haben |
| 118 |
LocalID = entityMapping->getLocalElement(allEntities[i]); |
| 119 |
if ( LocalID != -1) { |
| 120 |
localToGlobalVector[LocalID] = i-1; |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
} |
| 125 |
EntityMap_ = MapFactory<LO,GO,NO>::Build(localToGlobalNodesMap->lib(),INVALID,localToGlobalVector(),0,localToGlobalNodesMap->getComm()); |
| 126 |
EntityMapIsUpToDate_ = true; |
| 127 |
} |
| 128 |
return 0; |
| 129 |
} |
| 130 |
|
| 131 |
template<class SC,class LO,class GO,class NO> |
| 132 |
int EntitySet<SC,LO,GO,NO>::findAncestorsInSet(EntitySetPtr entitySet) |
| 133 |
{ |
| 134 |
for (UN i=0; i<getNumEntities(); i++) { |
| 135 |
getEntity(i)->findAncestorsInSet(entitySet); |
| 136 |
} |
| 137 |
return 0; |
| 138 |
} |
| 139 |
|
| 140 |
template<class SC,class LO,class GO,class NO> |
| 141 |
typename EntitySet<SC,LO,GO,NO>::EntitySetPtr EntitySet<SC,LO,GO,NO>::findRoots() |
| 142 |
{ |
| 143 |
EntitySetPtr Roots(new EntitySet<SC,LO,GO,NO>(DefaultType)); |
| 144 |
for (UN i=0; i<getNumEntities(); i++) { |
| 145 |
EntitySetPtr tmpRoots = getEntity(i)->findRoots(); |
| 146 |
if (tmpRoots.is_null()) { |
| 147 |
FROSCH_ASSERT(getEntity(i)->getAncestors()->getNumEntities()==0,"FROSch::EntitySet: getEntity(i)->getAncestors()->getNumEntities()!=0"); |
| 148 |
Roots->addEntity(getEntity(i)); |
| 149 |
} else { |
| 150 |
FROSCH_ASSERT(getEntity(i)->getAncestors()->getNumEntities()!=0,"FROSch::EntitySet: getEntity(i)->getAncestors()->getNumEntities()==0"); |
| 151 |
FROSCH_ASSERT(tmpRoots->getNumEntities()>0,"FROSch::EntitySet: tmpRoots->getNumEntities()<=0"); |
| 152 |
Roots->addEntitySet(tmpRoots); |
| 153 |
} |
| 154 |
} |
| 155 |
Roots->sortUnique(); |
| 156 |
return Roots; |
| 157 |
} |
| 158 |
|
| 159 |
template<class SC,class LO,class GO,class NO> |
| 160 |
typename EntitySet<SC,LO,GO,NO>::EntitySetPtr EntitySet<SC,LO,GO,NO>::findLeafs() |
| 161 |
{ |
| 162 |
EntitySetPtr Leafs(new EntitySet<SC,LO,GO,NO>(DefaultType)); |
| 163 |
for (UN i=0; i<getNumEntities(); i++) { |
| 164 |
if (getEntity(i)->getOffspring()->getNumEntities()==0) { |
| 165 |
Leafs->addEntity(getEntity(i)); |
| 166 |
} |
| 167 |
} |
| 168 |
Leafs->sortUnique(); |
| 169 |
return Leafs; |
| 170 |
} |
| 171 |
|
| 172 |
template<class SC,class LO,class GO,class NO> |
| 173 |
int EntitySet<SC,LO,GO,NO>::clearAncestors() |
| 174 |
{ |
| 175 |
for (UN i=0; i<getNumEntities(); i++) { |
| 176 |
getEntity(i)->clearAncestors(); |
| 177 |
} |
| 178 |
return 0; |
| 179 |
} |
| 180 |
|
| 181 |
template<class SC,class LO,class GO,class NO> |
| 182 |
int EntitySet<SC,LO,GO,NO>::clearOffspring() |
| 183 |
{ |
| 184 |
for (UN i=0; i<getNumEntities(); i++) { |
| 185 |
getEntity(i)->clearOffspring(); |
| 186 |
} |
| 187 |
return 0; |
| 188 |
} |
| 189 |
|
| 190 |
template<class SC,class LO,class GO,class NO> |
| 191 |
int EntitySet<SC,LO,GO,NO>::clearRoots() |
| 192 |
{ |
| 193 |
for (UN i=0; i<getNumEntities(); i++) { |
| 194 |
getEntity(i)->clearRoots(); |
| 195 |
} |
| 196 |
return 0; |
| 197 |
} |
| 198 |
|
| 199 |
template<class SC,class LO,class GO,class NO> |
| 200 |
int EntitySet<SC,LO,GO,NO>::clearLeafs() |
| 201 |
{ |
| 202 |
for (UN i=0; i<getNumEntities(); i++) { |
| 203 |
getEntity(i)->clearLeafs(); |
| 204 |
} |
| 205 |
return 0; |
| 206 |
} |
| 207 |
|
| 208 |
template<class SC,class LO,class GO,class NO> |
| 209 |
int EntitySet<SC,LO,GO,NO>::computeDistancesToRoots(UN dimension, |
| 210 |
ConstXMultiVectorPtr &nodeList, |
| 211 |
DistanceFunction distanceFunction) |
| 212 |
{ |
| 213 |
for (UN i=0; i<getNumEntities(); i++) { |
| 214 |
getEntity(i)->computeDistancesToRoots(dimension,nodeList,distanceFunction); |
| 215 |
} |
| 216 |
return 0; |
| 217 |
} |
| 218 |
|
| 219 |
template<class SC,class LO,class GO,class NO> |
| 220 |
int EntitySet<SC,LO,GO,NO>::divideUnconnectedEntities(ConstXMatrixPtr matrix, |
| 221 |
int pID) |
| 222 |
{ |
| 223 |
UN before = getNumEntities(); |
| 224 |
UN i=0; |
| 225 |
while (i<getNumEntities()) { |
| 226 |
InterfaceEntityPtr tmpEntity = getEntity(i)->divideEntity(matrix,pID); |
| 227 |
if (tmpEntity->getNumNodes()>0) { |
| 228 |
addEntity(tmpEntity); |
| 229 |
} |
| 230 |
i++; |
| 231 |
} |
| 232 |
if (getNumEntities()-before>0) EntityMapIsUpToDate_ = false; |
| 233 |
return getNumEntities()-before; |
| 234 |
} |
| 235 |
|
| 236 |
template<class SC,class LO,class GO,class NO> |
| 237 |
int EntitySet<SC,LO,GO,NO>::flagNodes() |
| 238 |
{ |
| 239 |
for (UN i=0; i<getNumEntities(); i++) { |
| 240 |
if (getEntity(i)->getNumNodes()==1) { |
| 241 |
getEntity(i)->resetEntityFlag(NodeFlag); |
| 242 |
} |
| 243 |
} |
| 244 |
return 0; |
| 245 |
} |
| 246 |
|
| 247 |
template<class SC,class LO,class GO,class NO> |
| 248 |
int EntitySet<SC,LO,GO,NO>::flagShortEntities() |
| 249 |
{ |
| 250 |
for (UN i=0; i<getNumEntities(); i++) { |
| 251 |
if (getEntity(i)->getNumNodes()==2) { |
| 252 |
getEntity(i)->resetEntityFlag(ShortFlag); |
| 253 |
} |
| 254 |
} |
| 255 |
return 0; |
| 256 |
} |
| 257 |
|
| 258 |
template<class SC,class LO,class GO,class NO> |
| 259 |
int EntitySet<SC,LO,GO,NO>::flagStraightEntities(UN dimension, |
| 260 |
ConstXMultiVectorPtr &nodeList) |
| 261 |
{ |
| 262 |
FROSCH_ASSERT(dimension==nodeList->getNumVectors(),"FROSch::EntitySet: Inconsistent Dimension."); |
| 263 |
|
| 264 |
bool straight; |
| 265 |
LO length,j; |
| 266 |
SCVec pt1(dimension); |
| 267 |
SCVec dir1(dimension); |
| 268 |
SCVec dir2(dimension); |
| 269 |
|
| 270 |
for (UN i=0; i<getNumEntities(); i++) { |
| 271 |
straight = true; |
| 272 |
length = getEntity(i)->getNumNodes(); |
| 273 |
|
| 274 |
j=2; |
| 275 |
|
| 276 |
if (length>2) { |
| 277 |
// Anfangssteigung berechnen |
| 278 |
for (UN k=0; k<dimension; k++) { |
| 279 |
pt1[k] = nodeList->getData(k)[getEntity(i)->getLocalNodeID(0)]; |
| 280 |
} |
| 281 |
|
| 282 |
for (UN k=0; k<dimension; k++) { |
| 283 |
dir1[k] = nodeList->getData(k)[getEntity(i)->getLocalNodeID(1)]-pt1[k]; |
| 284 |
} |
| 285 |
|
| 286 |
while (j<length) { |
| 287 |
// Steigung zum zweiten Punkt berechnen |
| 288 |
for (UN k=0; k<dimension; k++) { |
| 289 |
dir2[k] = nodeList->getData(k)[getEntity(i)->getLocalNodeID(j)]-pt1[k]; |
| 290 |
} |
| 291 |
|
| 292 |
if (!ismultiple<SC,LO>(dir1(),dir2())) { |
| 293 |
straight = false; |
| 294 |
break; |
| 295 |
} |
| 296 |
j++; |
| 297 |
} |
| 298 |
if (straight) { |
| 299 |
getEntity(i)->resetEntityFlag(StraightFlag); |
| 300 |
} |
| 301 |
} |
| 302 |
} |
| 303 |
return 0; |
| 304 |
} |
| 305 |
|
| 306 |
template<class SC,class LO,class GO,class NO> |
| 307 |
typename EntitySet<SC,LO,GO,NO>::EntitySetPtr EntitySet<SC,LO,GO,NO>::sortOutEntities(EntityFlag flag) |
| 308 |
{ |
| 309 |
UN before = getNumEntities(); |
| 310 |
EntitySetPtr removedEntities(new EntitySet<SC,LO,GO,NO>(DefaultType)); |
| 311 |
for (UN i=0; i<getNumEntities(); i++) { |
| 312 |
if (getEntity(i)->getEntityFlag()==flag) { |
| 313 |
removedEntities->addEntities(getEntity(i)); |
| 314 |
EntityVector_.erase(EntityVector_.begin()+i); |
| 315 |
i--; |
| 316 |
} |
| 317 |
} |
| 318 |
if (getNumEntities()-before>0) EntityMapIsUpToDate_ = false; |
| 319 |
return arcp(removedEntities); |
| 320 |
} |
| 321 |
|
| 322 |
template<class SC,class LO,class GO,class NO> |
| 323 |
int EntitySet<SC,LO,GO,NO>::removeEntity(UN iD) |
| 324 |
{ |
| 325 |
FROSCH_ASSERT(iD<getNumEntities(),"FROSch::EntitySet: Cannot access Entity because iD>=getNumEntities()."); |
| 326 |
EntityVector_.erase(EntityVector_.begin()+iD); |
| 327 |
EntityMapIsUpToDate_ = false; |
| 328 |
return 0; |
| 329 |
} |
| 330 |
|
| 331 |
template<class SC,class LO,class GO,class NO> |
| 332 |
int EntitySet<SC,LO,GO,NO>::removeNodesWithDofs(GOVecView dirichletBoundaryDofs) |
| 333 |
{ |
| 334 |
UN dofsPerNode = 0; |
| 335 |
if (getNumEntities()>0) dofsPerNode = EntityVector_[0]->getDofsPerNode(); |
| 336 |
for (UN i=0; i<getNumEntities(); i++) { |
| 337 |
UN length = getEntity(i)->getNumNodes(); |
| 338 |
for (UN j=0; j<length; j++) { |
| 339 |
UN itmp = length-1-j; |
| 340 |
UN k = 0; |
| 341 |
while (k<dofsPerNode) { |
| 342 |
GO dofGlobal = getEntity(i)->getGlobalDofID(itmp,k); |
| 343 |
if (binary_search(dirichletBoundaryDofs.begin(),dirichletBoundaryDofs.end(),dofGlobal)) { |
| 344 |
getEntity(i)->removeNode(itmp); |
| 345 |
break; |
| 346 |
} |
| 347 |
k++; |
| 348 |
} |
| 349 |
} |
| 350 |
} |
| 351 |
return 0; |
| 352 |
} |
| 353 |
|
| 354 |
template<class SC,class LO,class GO,class NO> |
| 355 |
int EntitySet<SC,LO,GO,NO>::removeEmptyEntities() |
| 356 |
{ |
| 357 |
UN before = getNumEntities(); |
| 358 |
for (UN i=0; i<getNumEntities(); i++) { |
| 359 |
if (getEntity(i)->getNumNodes()==0) { |
| 360 |
EntityVector_.erase(EntityVector_.begin()+i); |
| 361 |
i--; |
| 362 |
} |
| 363 |
} |
| 364 |
if (getNumEntities()-before>0) EntityMapIsUpToDate_ = false; |
| 365 |
return 0; |
| 366 |
} |
| 367 |
|
| 368 |
template<class SC,class LO,class GO,class NO> |
| 369 |
int EntitySet<SC,LO,GO,NO>::sortUnique() |
| 370 |
{ |
| 371 |
for (UN i=0; i<getNumEntities(); i++) { |
| 372 |
getEntity(i)->sortByGlobalID(); |
| 373 |
} |
| 374 |
|
| 375 |
std::sort(EntityVector_.begin(),EntityVector_.end(),compareInterfaceEntities<SC,LO,GO,NO>); |
| 376 |
EntityVector_.erase(unique(EntityVector_.begin(),EntityVector_.end(),equalInterfaceEntities<SC,LO,GO,NO>),EntityVector_.end()); |
| 377 |
EntityMapIsUpToDate_ = false; |
| 378 |
return 0; |
| 379 |
} |
| 380 |
|
| 381 |
template<class SC,class LO,class GO,class NO> |
| 382 |
bool EntitySet<SC,LO,GO,NO>::checkForVertices() |
| 383 |
{ |
| 384 |
for (UN i=0; i<getNumEntities(); i++) { |
| 385 |
if (getEntity(i)->getNumNodes()==1) { |
| 386 |
i--; |
| 387 |
return true; |
| 388 |
} |
| 389 |
} |
| 390 |
return false; |
| 391 |
} |
| 392 |
|
| 393 |
template<class SC,class LO,class GO,class NO> |
| 394 |
bool EntitySet<SC,LO,GO,NO>::checkForShortEdges() |
| 395 |
{ |
| 396 |
for (UN i=0; i<getNumEntities(); i++) { |
| 397 |
if (getEntity(i)->getNumNodes()==2) { |
| 398 |
i--; |
| 399 |
return true; |
| 400 |
} |
| 401 |
} |
| 402 |
return false; |
| 403 |
} |
| 404 |
|
| 405 |
template<class SC,class LO,class GO,class NO> |
| 406 |
bool EntitySet<SC,LO,GO,NO>::checkForStraightEdges(UN dimension, |
| 407 |
ConstXMultiVectorPtr &nodeList) |
| 408 |
{ |
| 409 |
FROSCH_ASSERT(dimension==nodeList->getNumVectors(),"FROSch::EntitySet: Inconsistent Dimension."); |
| 410 |
|
| 411 |
bool straight; |
| 412 |
LO length,j; |
| 413 |
SCVec pt1(dimension); |
| 414 |
SCVec dir1(dimension); |
| 415 |
SCVec dir2(dimension); |
| 416 |
|
| 417 |
for (UN i=0; i<getNumEntities(); i++) { |
| 418 |
straight = true; |
| 419 |
length = getEntity(i)->getNumNodes(); |
| 420 |
j=2; |
| 421 |
if (length>2) { |
| 422 |
// Anfangssteigung berechnen |
| 423 |
for (UN k=0; k<dimension; k++) { |
| 424 |
pt1[k] = nodeList->getData(k)[getEntity(i)->getLocalNodeID(0)]; |
| 425 |
} |
| 426 |
for (UN k=0; k<dimension; k++) { |
| 427 |
dir1[k] = nodeList->getData(k)[getEntity(i)->getLocalNodeID(1)]-pt1[k]; |
| 428 |
} |
| 429 |
|
| 430 |
while (j<length) { |
| 431 |
for (UN k=0; k<dimension; k++) { |
| 432 |
dir2[k] = nodeList->getData(k)[getEntity(i)->getLocalNodeID(j)]-pt1[k]; |
| 433 |
} |
| 434 |
if (!ismultiple<SC,LO>(dir1(),dir2())) { |
| 435 |
straight = false; |
| 436 |
break; |
| 437 |
} |
| 438 |
j++; |
| 439 |
} |
| 440 |
if (straight) { |
| 441 |
i--; |
| 442 |
return true; |
| 443 |
} |
| 444 |
} |
| 445 |
} |
| 446 |
return false; |
| 447 |
} |
| 448 |
|
| 449 |
template<class SC,class LO,class GO,class NO> |
| 450 |
bool EntitySet<SC,LO,GO,NO>::checkForEmptyEntities() |
| 451 |
{ |
| 452 |
for (UN i=0; i<getNumEntities(); i++) { |
| 453 |
if (getEntity(i)->getNumNodes()==0) { |
| 454 |
i--; |
| 455 |
return true; |
| 456 |
} |
| 457 |
} |
| 458 |
return false; |
| 459 |
} |
| 460 |
|
| 461 |
///////////////// |
| 462 |
// Set Methods // |
| 463 |
///////////////// |
| 464 |
|
| 465 |
template<class SC,class LO,class GO,class NO> |
| 466 |
int EntitySet<SC,LO,GO,NO>::setUniqueIDToFirstGlobalNodeID() |
| 467 |
{ |
| 468 |
for (UN i=0; i<getNumEntities(); i++) { |
| 469 |
getEntity(i)->sortByGlobalID(); |
| 470 |
getEntity(i)->setUniqueIDToFirstGlobalID(); |
| 471 |
} |
| 472 |
EntityMapIsUpToDate_ = false; |
| 473 |
return 0; |
| 474 |
} |
| 475 |
|
| 476 |
template<class SC,class LO,class GO,class NO> |
| 477 |
int EntitySet<SC,LO,GO,NO>::setRootID() |
| 478 |
{ |
| 479 |
for (UN i=0; i<getNumEntities(); i++) { |
| 480 |
getEntity(i)->setRootID(i); |
| 481 |
} |
| 482 |
return 0; |
| 483 |
} |
| 484 |
|
| 485 |
template<class SC,class LO,class GO,class NO> |
| 486 |
int EntitySet<SC,LO,GO,NO>::setLeafID() |
| 487 |
{ |
| 488 |
for (UN i=0; i<getNumEntities(); i++) { |
| 489 |
getEntity(i)->setLeafID(i); |
| 490 |
} |
| 491 |
return 0; |
| 492 |
} |
| 493 |
|
| 494 |
template<class SC,class LO,class GO,class NO> |
| 495 |
int EntitySet<SC,LO,GO,NO>::resetEntityType(EntityType type) |
| 496 |
{ |
| 497 |
Type_ = type; |
| 498 |
for (UN i=0; i<getNumEntities(); i++) { |
| 499 |
getEntity(i)->resetEntityType(type); |
| 500 |
} |
| 501 |
return 0; |
| 502 |
} |
| 503 |
|
| 504 |
///////////////// |
| 505 |
// Get Methods // |
| 506 |
///////////////// |
| 507 |
|
| 508 |
template<class SC,class LO,class GO,class NO> |
| 509 |
EntityType EntitySet<SC,LO,GO,NO>::getEntityType() const |
| 510 |
{ |
| 511 |
return Type_; |
| 512 |
} |
| 513 |
|
| 514 |
template<class SC,class LO,class GO,class NO> |
| 515 |
typename EntitySet<SC,LO,GO,NO>::UN EntitySet<SC,LO,GO,NO>::getNumEntities() const |
| 516 |
{ |
| 517 |
return EntityVector_.size(); |
| 518 |
} |
| 519 |
|
| 520 |
template<class SC,class LO,class GO,class NO> |
| 521 |
const typename EntitySet<SC,LO,GO,NO>::InterfaceEntityPtrVec & EntitySet<SC,LO,GO,NO>::getEntityVector() const |
| 522 |
{ |
| 523 |
return EntityVector_; |
| 524 |
} |
| 525 |
|
| 526 |
template<class SC,class LO,class GO,class NO> |
| 527 |
const typename EntitySet<SC,LO,GO,NO>::InterfaceEntityPtr EntitySet<SC,LO,GO,NO>::getEntity(UN iD) const |
| 528 |
{ |
| 529 |
FROSCH_ASSERT(iD<getNumEntities(),"FROSch::EntitySet: Cannot access Entity because iD>=getNumEntities()."); |
| 530 |
return EntityVector_[iD]; |
| 531 |
} |
| 532 |
|
| 533 |
template<class SC,class LO,class GO,class NO> |
| 534 |
const typename EntitySet<SC,LO,GO,NO>::XMapPtr EntitySet<SC,LO,GO,NO>::getEntityMap() const |
| 535 |
{ |
| 536 |
FROSCH_ASSERT(EntityMapIsUpToDate_,"FROSch::EntitySet: the entity map has not been built or is not up to date."); |
| 537 |
return EntityMap_; |
| 538 |
} |
| 539 |
|
| 540 |
template<class SC,class LO,class GO,class NO> |
| 541 |
const typename EntitySet<SC,LO,GO,NO>::SCVecPtr EntitySet<SC,LO,GO,NO>::getDirection(UN dimension, |
| 542 |
ConstXMultiVectorPtr &nodeList, |
| 543 |
UN iD) const |
| 544 |
{ |
| 545 |
FROSCH_ASSERT(iD<getNumEntities(),"FROSch::EntitySet: Cannot access Entity because iD>=getNumEntities()."); |
| 546 |
|
| 547 |
if (getEntity(iD)->getEntityFlag()==StraightFlag) { |
| 548 |
|
| 549 |
LO length = getEntity(iD)->getNumNodes(); |
| 550 |
LO j=2; |
| 551 |
|
| 552 |
FROSCH_ASSERT(length>2,"Edge is not a straight edge!"); |
| 553 |
|
| 554 |
bool straight=true; |
| 555 |
|
| 556 |
SCVec pt1(dimension); |
| 557 |
SCVec dir2(dimension); |
| 558 |
SCVecPtr dir1(dimension); |
| 559 |
|
| 560 |
// Anfangssteigung berechnen |
| 561 |
for (UN k=0; k<dimension; k++) { |
| 562 |
pt1[k] = nodeList->getData(k)[getEntity(iD)->getLocalNodeID(0)]; |
| 563 |
} |
| 564 |
for (UN k=0; k<dimension; k++) { |
| 565 |
dir1[k] = nodeList->getData(k)[getEntity(iD)->getLocalNodeID(1)]-pt1[k]; |
| 566 |
} |
| 567 |
|
| 568 |
while (j<length) { |
| 569 |
for (UN k=0; k<dimension; k++) { |
| 570 |
dir2[k] = nodeList->getData(k)[getEntity(iD)->getLocalNodeID(j)]-pt1[k]; |
| 571 |
} |
| 572 |
|
| 573 |
if (!ismultiple<SC,LO>(dir1(),dir2())) { |
| 574 |
straight = false; |
| 575 |
break; |
| 576 |
} |
| 577 |
j++; |
| 578 |
} |
| 579 |
|
| 580 |
FROSCH_ASSERT(straight,"FROSch::EntitySet: Edge is not straight!"); |
| 581 |
|
| 582 |
return dir1; |
| 583 |
|
| 584 |
} else if (getEntity(iD)->getEntityFlag()==ShortFlag) { |
| 585 |
|
| 586 |
int length = getEntity(iD)->getNumNodes(); |
| 587 |
|
| 588 |
FROSCH_ASSERT(length==2,"FROSch::EntitySet: Edge is not a short edge!"); |
| 589 |
|
| 590 |
SCVec pt1(dimension); |
| 591 |
SCVecPtr dir1(dimension); |
| 592 |
|
| 593 |
// Anfangssteigung berechnen |
| 594 |
for (UN k=0; k<dimension; k++) { |
| 595 |
pt1[k] = nodeList->getData(k)[getEntity(iD)->getLocalNodeID(0)]; |
| 596 |
} |
| 597 |
for (UN k=0; k<dimension; k++) { |
| 598 |
dir1[k] = nodeList->getData(k)[getEntity(iD)->getLocalNodeID(1)]-pt1[k]; |
| 599 |
} |
| 600 |
|
| 601 |
return dir1; |
| 602 |
|
| 603 |
} else { |
| 604 |
FROSCH_ASSERT(false,"FROSch::EntitySet: There is a problem while computing the direction of an edge!"); |
| 605 |
} |
| 606 |
} |
| 607 |
} |
| 608 |
|
| 609 |
#endif |