// @HEADER // ***************************************************************************** // ShyLU: Scalable Hybrid LU Preconditioner and Solver // // Copyright 2011 NTESS and the ShyLU contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #ifndef _FROSCH_INTERFACEENTITY_DEF_HPP #define _FROSCH_INTERFACEENTITY_DEF_HPP #include namespace FROSch { using namespace std; using namespace Teuchos; using namespace Xpetra; template bool Node::operator< (const Node &n) const { return NodeIDGlobal_ bool Node::operator== (const Node &n) const { return NodeIDGlobal_==n.NodeIDGlobal_; } template InterfaceEntity::InterfaceEntity(EntityType type, UN dofsPerNode, UN multiplicity, const int *subdomains, EntityFlag flag) : Type_ (type), Flag_ (flag), SubdomainsVector_ (multiplicity), DofsPerNode_ (dofsPerNode), Multiplicity_ (multiplicity) { for (UN i=0; i(DefaultType)); Offspring_.reset(new EntitySet(DefaultType)); Roots_.reset(new EntitySet(DefaultType)); } template InterfaceEntity::~InterfaceEntity() { } // Do we need sth here? template int InterfaceEntity::addNode(LO nodeIDGamma, LO nodeIDLocal, GO nodeIDGlobal, UN nDofs, const LOVecPtr dofsGamma, const LOVecPtr dofsLocal, const GOVecPtr dofsGlobal) { FROSCH_ASSERT(nDofs<=DofsPerNode_,"nDofs>NumDofs_."); FROSCH_ASSERT(dofsGamma.size()==nDofs,"dofIDs.size()!=nDofs"); FROSCH_ASSERT(dofsLocal.size()==nDofs,"dofIDs.size()!=nDofs"); FROSCH_ASSERT(dofsGlobal.size()==nDofs,"dofIDs.size()!=nDofs"); Node node; node.NodeIDGamma_ = nodeIDGamma; node.NodeIDLocal_ = nodeIDLocal; node.NodeIDGlobal_ = nodeIDGlobal; node.DofsGamma_.deepCopy(dofsGamma()); node.DofsLocal_.deepCopy(dofsLocal()); node.DofsGlobal_.deepCopy(dofsGlobal()); NodeVector_.push_back(node); return 0; } template int InterfaceEntity::addNode(const NodePtr &node) { return addNode(*node); } template int InterfaceEntity::addNode(const Node &node) { FROSCH_ASSERT(node.DofsGamma_.size()<=DofsPerNode_,"node.DofsGamma_ is too large."); FROSCH_ASSERT(node.DofsLocal_.size()<=DofsPerNode_,"node.DofsLocal_ is too large."); FROSCH_ASSERT(node.DofsGlobal_.size()<=DofsPerNode_,"node.DofsGlobal_ is too large."); NodeVector_.push_back(node); return 0; } template int InterfaceEntity::resetGlobalDofs(UN iD, UN nDofs, UN *dofIDs, GO *dofsGlobal) { FROSCH_ASSERT(iDgetNumNodes()"); FROSCH_ASSERT(nDofs<=DofsPerNode_,"nDofs>DofsPerNode_."); for (unsigned i=0; i int InterfaceEntity::removeNode(UN iD) { FROSCH_ASSERT(iDgetNumNodes()"); NodeVector_.erase(NodeVector_.begin()+iD); return 0; } template int InterfaceEntity::sortByGlobalID() { sortunique(NodeVector_); return 0; } template int InterfaceEntity::setUniqueID(GO uniqueID) { UniqueID_ = uniqueID; return 0; } template int InterfaceEntity::setLocalID(LO localID) { LocalID_ = localID; return 0; } template int InterfaceEntity::setRootID(LO rootID) { RootID_ = rootID; return 0; } template int InterfaceEntity::setLeafID(LO leafID) { LeafID_ = leafID; return 0; } template int InterfaceEntity::setUniqueIDToFirstGlobalID() { UniqueID_ = NodeVector_[0].NodeIDGlobal_; return 0; } template int InterfaceEntity::resetEntityType(EntityType type) { Type_ = type; return 0; } template int InterfaceEntity::resetEntityFlag(EntityFlag flag) { Flag_ = flag; return 0; } template int InterfaceEntity::findAncestorsInSet(EntitySetPtr entitySet) { EntitySetPtr ancestors(new EntitySet(*entitySet)); IntVec tmpVector; for (UN i=0; igetNumEntities(); for (UN j=0; jgetEntity(length-1-j)->getSubdomainsVector(); if (ancestors->getEntity(length-1-j)->getMultiplicity()<=this->getMultiplicity() || !binary_search(tmpVector.begin(),tmpVector.end(),SubdomainsVector_[i])) { ancestors->removeEntity(length-1-j); } } } for (UN i=0; igetNumEntities(); i++) { Ancestors_->addEntity(ancestors->getEntity(i)); } Ancestors_->sortUnique(); // this is offspring of each ancestor for (UN i=0; igetNumEntities(); i++) { InterfaceEntityPtr thisEntity = rcpFromRef(*this); FROSCH_ASSERT(!thisEntity.is_null(),"FROSch::InterfaceEntity: thisEntity.is_null()"); Ancestors_->getEntity(i)->addOffspring(thisEntity); } return 0; } template int InterfaceEntity::clearAncestors() { Ancestors_.reset(new EntitySet(DefaultType)); return 0; } template int InterfaceEntity::addOffspring(InterfaceEntityPtr interfaceEntity) { Offspring_->addEntity(interfaceEntity); Offspring_->sortUnique(); return 0; } template int InterfaceEntity::clearOffspring() { Offspring_.reset(new EntitySet(DefaultType)); return 0; } template typename InterfaceEntity::EntitySetPtr InterfaceEntity::findRoots() { if (Roots_->getNumEntities()) { FROSCH_ASSERT(Ancestors_->getNumEntities()!=0,"Ancestors_->getNumEntities()==0"); return Roots_; } for (UN i=0; igetNumEntities(); i++) { EntitySetPtr tmpRoots = Ancestors_->getEntity(i)->findRoots(); if (tmpRoots.is_null()) { FROSCH_ASSERT(Ancestors_->getEntity(i)->getAncestors()->getNumEntities()==0,"EntityVector_[i]->getAncestors()->getNumEntities()!=0"); Roots_->addEntity(Ancestors_->getEntity(i)); } else { FROSCH_ASSERT(Ancestors_->getEntity(i)->getAncestors()->getNumEntities()!=0,"EntityVector_[i]->getAncestors()->getNumEntities()==0"); FROSCH_ASSERT(tmpRoots->getNumEntities()>0,"tmpRoots->getNumEntities()<=0"); Roots_->addEntitySet(tmpRoots); } } Roots_->sortUnique(); if (Roots_->getNumEntities()) { FROSCH_ASSERT(Ancestors_->getNumEntities()!=0,"Ancestors_->getNumEntities()==0"); return Roots_; } else { return null; } } template int InterfaceEntity::clearRoots() { Roots_.reset(new EntitySet(DefaultType)); return 0; } template int InterfaceEntity::computeDistancesToRoots(UN dimension, ConstXMultiVectorPtr &nodeList, DistanceFunction distanceFunction) { if (Roots_->getNumEntities()>0) { DistancesVector_.resize(getNumNodes()); for (UN i=0; igetNumEntities()+1,numeric_limits::max()); } switch (distanceFunction) { case ConstantDistanceFunction: for (UN i=0; igetNumEntities(); j++) { DistancesVector_[i][j] = ScalarTraits::one(); // AH 08/08/2019 TODO: Make a MultiVector out of this and use putScalar() } } break; case InverseEuclideanDistanceFunction: FROSCH_ASSERT(!nodeList.is_null(),"FROSch::InterfaceEntity: The inverse euclidean distance cannot be calculated without coordinates of the nodes!"); FROSCH_ASSERT(dimension==nodeList->getNumVectors(),"FROSch::InterfaceEntity: Inconsistent Dimension."); for (UN i=0; igetNumEntities(); i++) { for (UN j=0; jgetEntity(i)->getNumNodes(); j++) { // Coordinates of the nodes of the coarse node SCVecPtr CN(dimension); for (UN k=0; kgetData(k)[Roots_->getEntity(i)->getLocalNodeID(j)]; } for (UN k=0; k::zero(); // Compute quadratic distance for (UN l=0; lgetData(l)[this->getLocalNodeID(k)]-CN[l]) * (nodeList->getData(l)[this->getLocalNodeID(k)]-CN[l]); } // Compute inverse euclidean distance distance = sqrt(distance); DistancesVector_[k][i] = min(DistancesVector_[k][i],distance); } } } for (UN i=0; igetNumEntities(); j++) { DistancesVector_[i][j] = ScalarTraits::one()/DistancesVector_[i][j]; } } break; default: FROSCH_ASSERT(false,"FROSch::InterfaceEntity: Specify a valid Distance Function."); } // In the last "row", we store the sum of the distances for all coarse nodes for (UN i=0; igetNumEntities()] = ScalarTraits::zero(); for (UN j=0; jgetNumEntities(); j++) { DistancesVector_[i][Roots_->getNumEntities()] += DistancesVector_[i][j]; } } } return 0; } template typename InterfaceEntity::InterfaceEntityPtr InterfaceEntity::divideEntity(ConstXMatrixPtr matrix, int pID) { InterfaceEntityPtr entity(new InterfaceEntity(Type_,DofsPerNode_,Multiplicity_,&(SubdomainsVector_[0]))); if (getNumNodes()>=2) { sortByGlobalID(); GOVecPtr mapVector(getNumNodes()); for (UN i=0; i::Build(localMatrix->getRowMap()); iterationVector->getDataNonConst(0)[0] = ScalarTraits::one(); for (UN i=0; iapply(*iterationVector,*iterationVector); } for (UN i=0; igetData(0)[i])<1.0e-10) { entity->addNode(getNode(i)); removeNode(i); } } } return entity; } ///////////////// // Get Methods // ///////////////// template EntityType InterfaceEntity::getEntityType() const { return Type_; } template EntityFlag InterfaceEntity::getEntityFlag() const { return Flag_; } template typename InterfaceEntity::UN InterfaceEntity::getDofsPerNode() const { return DofsPerNode_; } template typename InterfaceEntity::UN InterfaceEntity::getMultiplicity() const { return Multiplicity_; } template GO InterfaceEntity::getUniqueID() const { return UniqueID_; } template LO InterfaceEntity::getLocalID() const { return LocalID_; } template LO InterfaceEntity::getRootID() const { return RootID_; } template LO InterfaceEntity::getLeafID() const { return LeafID_; } template const Node& InterfaceEntity::getNode(UN iDNode) const { return NodeVector_[iDNode]; } template LO InterfaceEntity::getGammaNodeID(UN iDNode) const { return NodeVector_[iDNode].NodeIDGamma_; } template LO InterfaceEntity::getLocalNodeID(UN iDNode) const { return NodeVector_[iDNode].NodeIDLocal_; } template GO InterfaceEntity::getGlobalNodeID(UN iDNode) const { return NodeVector_[iDNode].NodeIDGlobal_; } template LO InterfaceEntity::getGammaDofID(UN iDNode, UN iDDof) const { return NodeVector_[iDNode].DofsGamma_[iDDof]; } template LO InterfaceEntity::getLocalDofID(UN iDNode, UN iDDof) const { return NodeVector_[iDNode].DofsLocal_[iDDof]; } template GO InterfaceEntity::getGlobalDofID(UN iDNode, UN iDDof) const { return NodeVector_[iDNode].DofsGlobal_[iDDof]; } template const typename InterfaceEntity::IntVec & InterfaceEntity::getSubdomainsVector() const { return SubdomainsVector_; } template typename InterfaceEntity::UN InterfaceEntity::getNumNodes() const { return NodeVector_.size(); } template const typename InterfaceEntity::EntitySetPtr InterfaceEntity::getAncestors() const { return Ancestors_; } template const typename InterfaceEntity::EntitySetPtr InterfaceEntity::getOffspring() const { return Offspring_; } template const typename InterfaceEntity::EntitySetPtr InterfaceEntity::getRoots() const { return Roots_; } template SC InterfaceEntity::getDistanceToRoot(UN iDNode, UN iDRoot) const { FROSCH_ASSERT(iDNode=getNumNodes()"); FROSCH_ASSERT(iDRootgetNumEntities()+1,"iDNode>=Roots_->getNumEntities()+1"); return DistancesVector_[iDNode][iDRoot]; } template bool compareInterfaceEntities(RCP > iEa, RCP > iEb) { return iEa->getUniqueID()getUniqueID(); } template bool equalInterfaceEntities(RCP > iEa, RCP > iEb) { return iEa->getUniqueID()==iEb->getUniqueID(); } } #endif