// // Software License for AMDiS // // Copyright (c) 2010 Dresden University of Technology // All rights reserved. // Authors: Simon Vey, Thomas Witkowski et al. // // This file is part of AMDiS // // See also license.opensource.txt in the distribution. #include "parallel/InteriorBoundary.h" #include "FiniteElemSpace.h" #include "BasisFunction.h" #include "Serializer.h" #include "VertexVector.h" namespace AMDiS { AtomicBoundary& InteriorBoundary::getNewAtomic(int rank) { int size = boundary[rank].size(); boundary[rank].resize(size + 1); return boundary[rank][size]; } bool InteriorBoundary::operator==(const InteriorBoundary& other) const { InteriorBoundary& other2 = const_cast(other); if (boundary.size() != other2.boundary.size()) return false; for (unsigned int level = 0; level < boundary.size(); level++) { for (RankToBoundMap::const_iterator it = boundary.begin(); it != boundary.end(); ++it) { if (other2.boundary.count(it->first) == 0) return false; if (other2.boundary[it->first].size() != it->second.size()) return false; for (unsigned int i = 0; i < it->second.size(); i++) { std::vector::iterator bIt = find(other2.boundary[it->first].begin(), other2.boundary[it->first].end(), it->second[i]); if (bIt == other2.boundary[it->first].end()) return false; } } } return true; } void InteriorBoundary::clear() { FUNCNAME("InteriorBoundary::clear()"); boundary.clear(); } void InteriorBoundary::serialize(std::ostream &out) { FUNCNAME("InteriorBoundary::serialize()"); ERROR_EXIT("REWRITE TO MULTILEVEL STRUCTURE!\n"); #if 0 int mSize = boundary.size(); SerUtil::serialize(out, mSize); for (RankToBoundMap::iterator it = boundary.begin(); it != boundary.end(); ++it) { int rank = it->first; int boundSize = it->second.size(); SerUtil::serialize(out, rank); SerUtil::serialize(out, boundSize); for (int i = 0; i < boundSize; i++) { AtomicBoundary &bound = (it->second)[i]; SerUtil::serialize(out, bound.rankObj.elIndex); SerUtil::serialize(out, bound.rankObj.elType); SerUtil::serialize(out, bound.rankObj.subObj); SerUtil::serialize(out, bound.rankObj.ithObj); SerUtil::serialize(out, bound.rankObj.reverseMode); serializeExcludeList(out, bound.rankObj.excludedSubstructures); SerUtil::serialize(out, bound.neighObj.elIndex); SerUtil::serialize(out, bound.neighObj.elType); SerUtil::serialize(out, bound.neighObj.subObj); SerUtil::serialize(out, bound.neighObj.ithObj); SerUtil::serialize(out, bound.neighObj.reverseMode); serializeExcludeList(out, bound.neighObj.excludedSubstructures); SerUtil::serialize(out, bound.type); } } #endif } void InteriorBoundary::deserialize(std::istream &in, std::map &elIndexMap) { FUNCNAME("InteriorBoundary::deserialize()"); ERROR_EXIT("REWRITE TO MULTILEVEL STRUCTURE!\n"); #if 0 int mSize = 0; SerUtil::deserialize(in, mSize); for (int i = 0; i < mSize; i++) { int rank = 0; int boundSize = 0; SerUtil::deserialize(in, rank); SerUtil::deserialize(in, boundSize); boundary[rank].resize(boundSize); for (int i = 0; i < boundSize; i++) { AtomicBoundary &bound = boundary[rank][i]; SerUtil::deserialize(in, bound.rankObj.elIndex); SerUtil::deserialize(in, bound.rankObj.elType); SerUtil::deserialize(in, bound.rankObj.subObj); SerUtil::deserialize(in, bound.rankObj.ithObj); SerUtil::deserialize(in, bound.rankObj.reverseMode); deserializeExcludeList(in, bound.rankObj.excludedSubstructures); SerUtil::deserialize(in, bound.neighObj.elIndex); SerUtil::deserialize(in, bound.neighObj.elType); SerUtil::deserialize(in, bound.neighObj.subObj); SerUtil::deserialize(in, bound.neighObj.ithObj); SerUtil::deserialize(in, bound.neighObj.reverseMode); deserializeExcludeList(in, bound.neighObj.excludedSubstructures); SerUtil::deserialize(in, bound.type); TEST_EXIT_DBG(elIndexMap.count(bound.rankObj.elIndex) == 1) ("Cannot find element with index %d for deserialization!\n", bound.rankObj.elIndex); TEST_EXIT_DBG(elIndexMap[bound.rankObj.elIndex]->getIndex() == bound.rankObj.elIndex)("Should not happen!\n"); bound.rankObj.el = elIndexMap[bound.rankObj.elIndex]; // For the case of periodic interior boundaries, a rank may have an // boundary with itself. In this case, also the pointer to the neighbour // object must be set correctly. if (elIndexMap.count(bound.neighObj.elIndex)) bound.neighObj.el = elIndexMap[bound.neighObj.elIndex]; else bound.neighObj.el = NULL; } } #endif } void InteriorBoundary::serializeExcludeList(std::ostream &out, ExcludeList &list) { int size = list.size(); SerUtil::serialize(out, size); for (int i = 0; i < size; i++) { SerUtil::serialize(out, list[i].first); SerUtil::serialize(out, list[i].second); } } void InteriorBoundary::deserializeExcludeList(std::istream &in, ExcludeList &list) { int size = 0; SerUtil::deserialize(in, size); list.resize(0); list.reserve(size); for (int i = 0; i < size; i++) { GeoIndex a; int b; SerUtil::deserialize(in, a); SerUtil::deserialize(in, b); list.push_back(std::make_pair(a, b)); } } }