/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see .
\*---------------------------------------------------------------------------*/
#include "mapDistribute.H"
#include "globalIndexAndTransform.H"
#include "transformField.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(mapDistribute, 0);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<>
void Foam::mapDistribute::transform::operator()
(
const vectorTensorTransform&,
const bool,
List&
) const
{}
template<>
void Foam::mapDistribute::transform::operator()
(
const coupledPolyPatch&,
UList&
) const
{}
template<>
void Foam::mapDistribute::transform::operator()
(
const coupledPolyPatch&,
Map&
) const
{}
template<>
void Foam::mapDistribute::transform::operator()
(
const coupledPolyPatch&,
EdgeMap&
) const
{}
template<>
void Foam::mapDistribute::transform::operator()
(
const vectorTensorTransform&,
const bool,
List&
) const
{}
template<>
void Foam::mapDistribute::transform::operator()
(
const coupledPolyPatch&,
UList&
) const
{}
template<>
void Foam::mapDistribute::transform::operator()
(
const coupledPolyPatch&,
Map&
) const
{}
template<>
void Foam::mapDistribute::transform::operator()
(
const coupledPolyPatch&,
EdgeMap&
) const
{}
template<>
void Foam::mapDistribute::transform::operator()
(
const vectorTensorTransform&,
const bool,
List&
) const
{}
template<>
void Foam::mapDistribute::transform::operator()
(
const coupledPolyPatch&,
UList&
) const
{}
template<>
void Foam::mapDistribute::transform::operator()
(
const coupledPolyPatch&,
Map&
) const
{}
template<>
void Foam::mapDistribute::transform::operator()
(
const coupledPolyPatch&,
EdgeMap&
) const
{}
void Foam::mapDistribute::printLayout(Ostream& os) const
{
mapDistributeBase::printLayout(os);
forAll(transformElements_, trafoI)
{
if (transformElements_[trafoI].size() > 0)
{
os << "transform " << trafoI << ':' << endl
<< " start : " << transformStart_[trafoI] << endl
<< " size : " << transformElements_[trafoI].size() << endl;
}
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
//- Construct null
Foam::mapDistribute::mapDistribute()
:
mapDistributeBase()
{}
//- Construct from components
Foam::mapDistribute::mapDistribute
(
const label constructSize,
const Xfer& subMap,
const Xfer& constructMap,
const bool subHasFlip,
const bool constructHasFlip
)
:
mapDistributeBase
(
constructSize,
subMap,
constructMap,
subHasFlip,
constructHasFlip
)
{}
//- Construct from components
Foam::mapDistribute::mapDistribute
(
const label constructSize,
const Xfer& subMap,
const Xfer& constructMap,
const Xfer& transformElements,
const Xfer& transformStart,
const bool subHasFlip,
const bool constructHasFlip
)
:
mapDistributeBase
(
constructSize,
subMap,
constructMap,
subHasFlip,
constructHasFlip
),
transformElements_(transformElements),
transformStart_(transformStart)
{}
Foam::mapDistribute::mapDistribute
(
const labelList& sendProcs,
const labelList& recvProcs
)
:
mapDistributeBase(sendProcs, recvProcs)
{}
Foam::mapDistribute::mapDistribute
(
const globalIndex& globalNumbering,
labelList& elements,
List >& compactMap,
const int tag
)
:
mapDistributeBase
(
globalNumbering,
elements,
compactMap,
tag
)
{}
Foam::mapDistribute::mapDistribute
(
const globalIndex& globalNumbering,
labelListList& cellCells,
List >& compactMap,
const int tag
)
:
mapDistributeBase
(
globalNumbering,
cellCells,
compactMap,
tag
)
{}
Foam::mapDistribute::mapDistribute
(
const globalIndex& globalNumbering,
labelList& elements,
const globalIndexAndTransform& globalTransforms,
const labelPairList& transformedElements,
labelList& transformedIndices,
List >& compactMap,
const int tag
)
:
mapDistributeBase()
{
// Construct per processor compact addressing of the global elements
// needed. The ones from the local processor are not included since
// these are always all needed.
calcCompactAddressing
(
globalNumbering,
elements,
compactMap
);
// Add all (non-local) transformed elements needed.
forAll(transformedElements, i)
{
labelPair elem = transformedElements[i];
label procI = globalIndexAndTransform::processor(elem);
if (procI != Pstream::myProcNo())
{
label index = globalIndexAndTransform::index(elem);
label nCompact = compactMap[procI].size();
compactMap[procI].insert(index, nCompact);
}
}
// Exchange what I need with processor that supplies it. Renumber elements
// into compact numbering
labelList compactStart;
exchangeAddressing
(
tag,
globalNumbering,
elements,
compactMap,
compactStart
);
// Renumber the transformed elements
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Count per transformIndex
label nTrafo = globalTransforms.transformPermutations().size();
labelList nPerTransform(nTrafo, 0);
forAll(transformedElements, i)
{
labelPair elem = transformedElements[i];
label trafoI = globalIndexAndTransform::transformIndex(elem);
nPerTransform[trafoI]++;
}
// Offset per transformIndex
transformStart_.setSize(nTrafo);
transformElements_.setSize(nTrafo);
forAll(transformStart_, trafoI)
{
transformStart_[trafoI] = constructSize_;
constructSize_ += nPerTransform[trafoI];
transformElements_[trafoI].setSize(nPerTransform[trafoI]);
}
// Sort transformed elements into their new slot.
nPerTransform = 0;
transformedIndices.setSize(transformedElements.size());
forAll(transformedElements, i)
{
labelPair elem = transformedElements[i];
label procI = globalIndexAndTransform::processor(elem);
label index = globalIndexAndTransform::index(elem);
label trafoI = globalIndexAndTransform::transformIndex(elem);
// Get compact index for untransformed element
label rawElemI =
(
procI == Pstream::myProcNo()
? index
: compactMap[procI][index]
);
label& n = nPerTransform[trafoI];
// index of element to transform
transformElements_[trafoI][n] = rawElemI;
// destination of transformed element
transformedIndices[i] = transformStart_[trafoI]+n;
n++;
}
if (debug)
{
printLayout(Pout);
}
}
Foam::mapDistribute::mapDistribute
(
const globalIndex& globalNumbering,
labelListList& cellCells,
const globalIndexAndTransform& globalTransforms,
const List& transformedElements,
labelListList& transformedIndices,
List >& compactMap,
const int tag
)
:
mapDistributeBase()
{
// Construct per processor compact addressing of the global elements
// needed. The ones from the local processor are not included since
// these are always all needed.
calcCompactAddressing
(
globalNumbering,
cellCells,
compactMap
);
// Add all (non-local) transformed elements needed.
forAll(transformedElements, cellI)
{
const labelPairList& elems = transformedElements[cellI];
forAll(elems, i)
{
label procI = globalIndexAndTransform::processor(elems[i]);
if (procI != Pstream::myProcNo())
{
label index = globalIndexAndTransform::index(elems[i]);
label nCompact = compactMap[procI].size();
compactMap[procI].insert(index, nCompact);
}
}
}
// Exchange what I need with processor that supplies it. Renumber elements
// into compact numbering
labelList compactStart;
exchangeAddressing
(
tag,
globalNumbering,
cellCells,
compactMap,
compactStart
);
// Renumber the transformed elements
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Count per transformIndex
label nTrafo = globalTransforms.transformPermutations().size();
labelList nPerTransform(nTrafo, 0);
forAll(transformedElements, cellI)
{
const labelPairList& elems = transformedElements[cellI];
forAll(elems, i)
{
label trafoI = globalIndexAndTransform::transformIndex(elems[i]);
nPerTransform[trafoI]++;
}
}
// Offset per transformIndex
transformStart_.setSize(nTrafo);
transformElements_.setSize(nTrafo);
forAll(transformStart_, trafoI)
{
transformStart_[trafoI] = constructSize_;
constructSize_ += nPerTransform[trafoI];
transformElements_[trafoI].setSize(nPerTransform[trafoI]);
}
// Sort transformed elements into their new slot.
nPerTransform = 0;
transformedIndices.setSize(transformedElements.size());
forAll(transformedElements, cellI)
{
const labelPairList& elems = transformedElements[cellI];
transformedIndices[cellI].setSize(elems.size());
forAll(elems, i)
{
label procI = globalIndexAndTransform::processor(elems[i]);
label index = globalIndexAndTransform::index(elems[i]);
label trafoI = globalIndexAndTransform::transformIndex(elems[i]);
// Get compact index for untransformed element
label rawElemI =
(
procI == Pstream::myProcNo()
? index
: compactMap[procI][index]
);
label& n = nPerTransform[trafoI];
// index of element to transform
transformElements_[trafoI][n] = rawElemI;
// destination of transformed element
transformedIndices[cellI][i] = transformStart_[trafoI]+n;
n++;
}
}
if (debug)
{
printLayout(Pout);
}
}
Foam::mapDistribute::mapDistribute
(
const mapDistribute& map
)
:
mapDistributeBase(map),
transformElements_(map.transformElements_),
transformStart_(map.transformStart_)
{}
Foam::mapDistribute::mapDistribute
(
const Xfer& map
)
:
mapDistributeBase
(
map().constructSize_,
map().subMap_.xfer(),
map().constructMap_.xfer(),
map().subHasFlip(),
map().constructHasFlip()
),
transformElements_(map().transformElements_.xfer()),
transformStart_(map().transformStart_.xfer())
{}
Foam::mapDistribute::mapDistribute(Istream& is)
{
is >> *this;
}
Foam::autoPtr Foam::mapDistribute::clone() const
{
return autoPtr(new mapDistribute(*this));
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
Foam::label Foam::mapDistribute::whichTransform(const label index)
const
{
return findLower(transformStart_, index+1);
}
void Foam::mapDistribute::transfer(mapDistribute& rhs)
{
mapDistributeBase::transfer(rhs);
transformElements_.transfer(rhs.transformElements_);
transformStart_.transfer(rhs.transformStart_);
}
Foam::Xfer Foam::mapDistribute::xfer()
{
return xferMove(*this);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
void Foam::mapDistribute::operator=(const mapDistribute& rhs)
{
// Check for assignment to self
if (this == &rhs)
{
FatalErrorIn
(
"Foam::mapDistribute::operator="
"(const Foam::mapDistribute&)"
) << "Attempted assignment to self"
<< abort(FatalError);
}
mapDistributeBase::operator=(rhs);
transformElements_ = rhs.transformElements_;
transformStart_ = rhs.transformStart_;
}
// * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * * //
Foam::Istream& Foam::operator>>(Istream& is, mapDistribute& map)
{
is.fatalCheck("operator>>(Istream&, mapDistribute&)");
is >> static_cast(map)
>> map.transformElements_ >> map.transformStart_;
return is;
}
// * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<<(Ostream& os, const mapDistribute& map)
{
os << static_cast(map) << token::NL
<< map.transformElements_ << token::NL
<< map.transformStart_;
return os;
}
// ************************************************************************* //