ENH: mapFields - deprecated old utility in favour of mapFieldsNew and renamed

This commit is contained in:
andy
2014-01-14 10:41:50 +00:00
parent 2e7d16238c
commit e5a5b89509
48 changed files with 1198 additions and 4706 deletions

View File

@ -57,18 +57,13 @@ graphField/makeGraph.C
meshToMesh = meshToMeshInterpolation/meshToMesh
$(meshToMesh)/meshToMesh.C
$(meshToMesh)/calculateMeshToMeshAddressing.C
$(meshToMesh)/calculateMeshToMeshWeights.C
meshToMeshNew = meshToMeshInterpolation/meshToMeshNew
$(meshToMeshNew)/meshToMeshNew.C
$(meshToMeshNew)/meshToMeshNewParallelOps.C
meshToMeshNewMethods = meshToMeshInterpolation/meshToMeshNew/calcMethod
$(meshToMeshNewMethods)/meshToMeshMethod/meshToMeshMethod.C
$(meshToMeshNewMethods)/meshToMeshMethod/meshToMeshMethodNew.C
$(meshToMeshNewMethods)/cellVolumeWeight/cellVolumeWeightMethod.C
$(meshToMeshNewMethods)/direct/directMethod.C
$(meshToMeshNewMethods)/mapNearest/mapNearestMethod.C
$(meshToMesh)/meshToMeshParallelOps.C
meshToMeshMethods = meshToMeshInterpolation/meshToMesh/calcMethod
$(meshToMeshMethods)/meshToMeshMethod/meshToMeshMethod.C
$(meshToMeshMethods)/meshToMeshMethod/meshToMeshMethodNew.C
$(meshToMeshMethods)/cellVolumeWeight/cellVolumeWeightMethod.C
$(meshToMeshMethods)/direct/directMethod.C
$(meshToMeshMethods)/mapNearest/mapNearestMethod.C
LIB = $(FOAM_LIBBIN)/libsampling

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013-2014 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013-2014 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013-2014 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013-2014 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013-2014 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013-2014 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013-2014 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013-2014 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013-2014 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013-2014 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License

View File

@ -1,343 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
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 <http://www.gnu.org/licenses/>.
Description
private member of meshToMesh.
Calculates mesh to mesh addressing pattern (for each cell from one mesh
find the closest cell centre in the other mesh).
\*---------------------------------------------------------------------------*/
#include "meshToMesh.H"
#include "SubField.H"
#include "indexedOctree.H"
#include "treeDataCell.H"
#include "treeDataFace.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::meshToMesh::calcAddressing()
{
if (debug)
{
Info<< "meshToMesh::calculateAddressing() : "
<< "calculating mesh-to-mesh cell addressing" << endl;
}
// set reference to cells
const cellList& fromCells = fromMesh_.cells();
const pointField& fromPoints = fromMesh_.points();
// In an attempt to preserve the efficiency of linear search and prevent
// failure, a RESCUE mechanism will be set up. Here, we shall mark all
// cells next to the solid boundaries. If such a cell is found as the
// closest, the relationship between the origin and cell will be examined.
// If the origin is outside the cell, a global n-squared search is
// triggered.
// SETTING UP RESCUE
// visit all boundaries and mark the cell next to the boundary.
if (debug)
{
Info<< "meshToMesh::calculateAddressing() : "
<< "Setting up rescue" << endl;
}
List<bool> boundaryCell(fromCells.size(), false);
// set reference to boundary
const polyPatchList& patchesFrom = fromMesh_.boundaryMesh();
forAll(patchesFrom, patchI)
{
// get reference to cells next to the boundary
const labelUList& bCells = patchesFrom[patchI].faceCells();
forAll(bCells, faceI)
{
boundaryCell[bCells[faceI]] = true;
}
}
treeBoundBox meshBb(fromPoints);
scalar typDim = meshBb.avgDim()/(2.0*cbrt(scalar(fromCells.size())));
treeBoundBox shiftedBb
(
meshBb.min(),
meshBb.max() + vector(typDim, typDim, typDim)
);
if (debug)
{
Info<< "\nMesh" << endl;
Info<< " bounding box : " << meshBb << endl;
Info<< " bounding box (shifted) : " << shiftedBb << endl;
Info<< " typical dimension :" << shiftedBb.typDim() << endl;
}
indexedOctree<treeDataCell> oc
(
treeDataCell(false, fromMesh_, polyMesh::FACEDIAGTETS),
shiftedBb, // overall bounding box
8, // maxLevel
10, // leafsize
6.0 // duplicity
);
if (debug)
{
oc.print(Pout, false, 0);
}
cellAddresses
(
cellAddressing_,
toMesh_.cellCentres(),
fromMesh_,
boundaryCell,
oc
);
forAll(toMesh_.boundaryMesh(), patchi)
{
const polyPatch& toPatch = toMesh_.boundaryMesh()[patchi];
if (cuttingPatches_.found(toPatch.name()))
{
boundaryAddressing_[patchi].setSize(toPatch.size());
cellAddresses
(
boundaryAddressing_[patchi],
toPatch.faceCentres(),
fromMesh_,
boundaryCell,
oc
);
}
else if
(
patchMap_.found(toPatch.name())
&& fromMeshPatches_.found(patchMap_.find(toPatch.name())())
)
{
const polyPatch& fromPatch = fromMesh_.boundaryMesh()
[
fromMeshPatches_.find(patchMap_.find(toPatch.name())())()
];
if (fromPatch.empty())
{
WarningIn("meshToMesh::calcAddressing()")
<< "Source patch " << fromPatch.name()
<< " has no faces. Not performing mapping for it."
<< endl;
boundaryAddressing_[patchi] = -1;
}
else
{
treeBoundBox wallBb(fromPatch.localPoints());
scalar typDim =
wallBb.avgDim()/(2.0*sqrt(scalar(fromPatch.size())));
treeBoundBox shiftedBb
(
wallBb.min(),
wallBb.max() + vector(typDim, typDim, typDim)
);
// Note: allow more levels than in meshSearch. Assume patch
// is not as big as all boundary faces
indexedOctree<treeDataFace> oc
(
treeDataFace(false, fromPatch),
shiftedBb, // overall search domain
12, // maxLevel
10, // leafsize
6.0 // duplicity
);
const vectorField::subField centresToBoundary =
toPatch.faceCentres();
boundaryAddressing_[patchi].setSize(toPatch.size());
scalar distSqr = sqr(wallBb.mag());
forAll(toPatch, toi)
{
boundaryAddressing_[patchi][toi] = oc.findNearest
(
centresToBoundary[toi],
distSqr
).index();
}
}
}
}
if (debug)
{
Info<< "meshToMesh::calculateAddressing() : "
<< "finished calculating mesh-to-mesh cell addressing" << endl;
}
}
void Foam::meshToMesh::cellAddresses
(
labelList& cellAddressing_,
const pointField& points,
const fvMesh& fromMesh,
const List<bool>& boundaryCell,
const indexedOctree<treeDataCell>& oc
) const
{
// the implemented search method is a simple neighbour array search.
// It starts from a cell zero, searches its neighbours and finds one
// which is nearer to the target point than the current position.
// The location of the "current position" is reset to that cell and
// search through the neighbours continues. The search is finished
// when all the neighbours of the cell are farther from the target
// point than the current cell
// set curCell label to zero (start)
register label curCell = 0;
// set reference to cell to cell addressing
const vectorField& centresFrom = fromMesh.cellCentres();
const labelListList& cc = fromMesh.cellCells();
forAll(points, toI)
{
// pick up target position
const vector& p = points[toI];
// set the sqr-distance
scalar distSqr = magSqr(p - centresFrom[curCell]);
bool closer;
do
{
closer = false;
// set the current list of neighbouring cells
const labelList& neighbours = cc[curCell];
forAll(neighbours, nI)
{
scalar curDistSqr =
magSqr(p - centresFrom[neighbours[nI]]);
// search through all the neighbours.
// If the cell is closer, reset current cell and distance
if (curDistSqr < (1 - SMALL)*distSqr)
{
curCell = neighbours[nI];
distSqr = curDistSqr;
closer = true; // a closer neighbour has been found
}
}
} while (closer);
cellAddressing_[toI] = -1;
// Check point is actually in the nearest cell
if (fromMesh.pointInCell(p, curCell))
{
cellAddressing_[toI] = curCell;
}
else
{
// If curCell is a boundary cell then the point maybe either outside
// the domain or in an other region of the doamin, either way use
// the octree search to find it.
if (boundaryCell[curCell])
{
cellAddressing_[toI] = oc.findInside(p);
}
else
{
// If not on the boundary search the neighbours
bool found = false;
// set the current list of neighbouring cells
const labelList& neighbours = cc[curCell];
forAll(neighbours, nI)
{
// search through all the neighbours.
// If point is in neighbour reset current cell
if (fromMesh.pointInCell(p, neighbours[nI]))
{
cellAddressing_[toI] = neighbours[nI];
found = true;
break;
}
}
if (!found)
{
// If still not found search the neighbour-neighbours
// set the current list of neighbouring cells
const labelList& neighbours = cc[curCell];
forAll(neighbours, nI)
{
// set the current list of neighbour-neighbouring cells
const labelList& nn = cc[neighbours[nI]];
forAll(nn, nI)
{
// search through all the neighbours.
// If point is in neighbour reset current cell
if (fromMesh.pointInCell(p, nn[nI]))
{
cellAddressing_[toI] = nn[nI];
found = true;
break;
}
}
if (found) break;
}
}
if (!found)
{
// Still not found so us the octree
cellAddressing_[toI] = oc.findInside(p);
}
}
}
}
}
// ************************************************************************* //

View File

@ -1,274 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "meshToMesh.H"
#include "tetOverlapVolume.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::meshToMesh::calculateInverseDistanceWeights() const
{
if (debug)
{
Info<< "meshToMesh::calculateInverseDistanceWeights() : "
<< "calculating inverse distance weighting factors" << endl;
}
if (inverseDistanceWeightsPtr_)
{
FatalErrorIn("meshToMesh::calculateInverseDistanceWeights()")
<< "weighting factors already calculated"
<< exit(FatalError);
}
//- Initialise overlap volume to zero
V_ = 0.0;
inverseDistanceWeightsPtr_ = new scalarListList(toMesh_.nCells());
scalarListList& invDistCoeffs = *inverseDistanceWeightsPtr_;
// get reference to source mesh data
const labelListList& cc = fromMesh_.cellCells();
const vectorField& centreFrom = fromMesh_.C().internalField();
const vectorField& centreTo = toMesh_.C().internalField();
forAll(cellAddressing_, celli)
{
if (cellAddressing_[celli] != -1)
{
const vector& target = centreTo[celli];
scalar m = mag(target - centreFrom[cellAddressing_[celli]]);
const labelList& neighbours = cc[cellAddressing_[celli]];
// if the nearest cell is a boundary cell or there is a direct hit,
// pick up the value
label directCelli = -1;
if (m < directHitTol || neighbours.empty())
{
directCelli = celli;
}
else
{
forAll(neighbours, ni)
{
scalar nm = mag(target - centreFrom[neighbours[ni]]);
if (nm < directHitTol)
{
directCelli = neighbours[ni];
break;
}
}
}
if (directCelli != -1)
{
// Direct hit
invDistCoeffs[directCelli].setSize(1);
invDistCoeffs[directCelli][0] = 1.0;
V_ += fromMesh_.V()[cellAddressing_[directCelli]];
}
else
{
invDistCoeffs[celli].setSize(neighbours.size() + 1);
// The first coefficient corresponds to the centre cell.
// The rest is ordered in the same way as the cellCells list.
scalar invDist = 1.0/m;
invDistCoeffs[celli][0] = invDist;
scalar sumInvDist = invDist;
// now add the neighbours
forAll(neighbours, ni)
{
invDist = 1.0/mag(target - centreFrom[neighbours[ni]]);
invDistCoeffs[celli][ni + 1] = invDist;
sumInvDist += invDist;
}
// divide by the total inverse-distance
forAll(invDistCoeffs[celli], i)
{
invDistCoeffs[celli][i] /= sumInvDist;
}
V_ +=
invDistCoeffs[celli][0]
*fromMesh_.V()[cellAddressing_[celli]];
for (label i = 1; i < invDistCoeffs[celli].size(); i++)
{
V_ +=
invDistCoeffs[celli][i]*fromMesh_.V()[neighbours[i-1]];
}
}
}
}
}
void Foam::meshToMesh::calculateInverseVolumeWeights() const
{
if (debug)
{
Info<< "meshToMesh::calculateInverseVolumeWeights() : "
<< "calculating inverse volume weighting factors" << endl;
}
if (inverseVolumeWeightsPtr_)
{
FatalErrorIn("meshToMesh::calculateInverseVolumeWeights()")
<< "weighting factors already calculated"
<< exit(FatalError);
}
//- Initialise overlap volume to zero
V_ = 0.0;
inverseVolumeWeightsPtr_ = new scalarListList(toMesh_.nCells());
scalarListList& invVolCoeffs = *inverseVolumeWeightsPtr_;
const labelListList& cellToCell = cellToCellAddressing();
tetOverlapVolume overlapEngine;
forAll(cellToCell, celli)
{
const labelList& overlapCells = cellToCell[celli];
if (overlapCells.size() > 0)
{
invVolCoeffs[celli].setSize(overlapCells.size());
forAll(overlapCells, j)
{
label cellFrom = overlapCells[j];
treeBoundBox bbFromMesh
(
pointField
(
fromMesh_.points(),
fromMesh_.cellPoints()[cellFrom]
)
);
scalar v = overlapEngine.cellCellOverlapVolumeMinDecomp
(
toMesh_,
celli,
fromMesh_,
cellFrom,
bbFromMesh
);
invVolCoeffs[celli][j] = v/toMesh_.V()[celli];
V_ += v;
}
}
}
}
void Foam::meshToMesh::calculateCellToCellAddressing() const
{
if (debug)
{
Info<< "meshToMesh::calculateCellToCellAddressing() : "
<< "calculating cell to cell addressing" << endl;
}
if (cellToCellAddressingPtr_)
{
FatalErrorIn("meshToMesh::calculateCellToCellAddressing()")
<< "addressing already calculated"
<< exit(FatalError);
}
//- Initialise overlap volume to zero
V_ = 0.0;
tetOverlapVolume overlapEngine;
cellToCellAddressingPtr_ = new labelListList(toMesh_.nCells());
labelListList& cellToCell = *cellToCellAddressingPtr_;
forAll(cellToCell, iTo)
{
const labelList overLapCells =
overlapEngine.overlappingCells(fromMesh_, toMesh_, iTo);
if (overLapCells.size() > 0)
{
//Info << "To " << iTo << endl;
//Info << "cellToCell " << overLapCells << endl;
cellToCell[iTo].setSize(overLapCells.size());
forAll(overLapCells, j)
{
cellToCell[iTo][j] = overLapCells[j];
V_ += fromMesh_.V()[overLapCells[j]];
}
}
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
const Foam::scalarListList& Foam::meshToMesh::inverseDistanceWeights() const
{
if (!inverseDistanceWeightsPtr_)
{
calculateInverseDistanceWeights();
}
return *inverseDistanceWeightsPtr_;
}
const Foam::scalarListList& Foam::meshToMesh::inverseVolumeWeights() const
{
if (!inverseVolumeWeightsPtr_)
{
calculateInverseVolumeWeights();
}
return *inverseVolumeWeightsPtr_;
}
const Foam::labelListList& Foam::meshToMesh::cellToCellAddressing() const
{
if (!cellToCellAddressingPtr_)
{
calculateCellToCellAddressing();
}
return *cellToCellAddressingPtr_;
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012-2014 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -24,193 +24,553 @@ License
\*---------------------------------------------------------------------------*/
#include "meshToMesh.H"
#include "processorFvPatch.H"
#include "demandDrivenData.H"
#include "Time.H"
#include "globalIndex.H"
#include "meshToMeshMethod.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(meshToMesh, 0);
defineTypeNameAndDebug(meshToMesh, 0);
template<>
const char* Foam::NamedEnum
<
Foam::meshToMesh::interpolationMethod,
3
>::names[] =
{
"direct",
"mapNearest",
"cellVolumeWeight"
};
const NamedEnum<meshToMesh::interpolationMethod, 3>
meshToMesh::interpolationMethodNames_;
}
const Foam::scalar Foam::meshToMesh::directHitTol = 1e-5;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::labelList Foam::meshToMesh::maskCells
(
const polyMesh& src,
const polyMesh& tgt
) const
{
boundBox intersectBb
(
max(src.bounds().min(), tgt.bounds().min()),
min(src.bounds().max(), tgt.bounds().max())
);
intersectBb.inflate(0.01);
const cellList& srcCells = src.cells();
const faceList& srcFaces = src.faces();
const pointField& srcPts = src.points();
DynamicList<label> cells(src.size());
forAll(srcCells, srcI)
{
boundBox cellBb(srcCells[srcI].points(srcFaces, srcPts), false);
if (intersectBb.overlaps(cellBb))
{
cells.append(srcI);
}
}
if (debug)
{
Pout<< "participating source mesh cells: " << cells.size() << endl;
}
return cells;
}
void Foam::meshToMesh::normaliseWeights
(
const word& descriptor,
const labelListList& addr,
scalarListList& wght
) const
{
const label nCell = returnReduce(wght.size(), sumOp<label>());
if (nCell > 0)
{
forAll(wght, cellI)
{
scalarList& w = wght[cellI];
scalar s = sum(w);
forAll(w, i)
{
// note: normalise by s instead of cell volume since
// 1-to-1 methods duplicate contributions in parallel
w[i] /= s;
}
}
}
}
void Foam::meshToMesh::calcAddressing
(
const polyMesh& src,
const polyMesh& tgt
)
{
autoPtr<meshToMeshMethod> methodPtr
(
meshToMeshMethod::New
(
interpolationMethodNames_[method_],
src,
tgt
)
);
methodPtr->calculate
(
srcToTgtCellAddr_,
srcToTgtCellWght_,
tgtToSrcCellAddr_,
tgtToSrcCellWght_
);
V_ = methodPtr->V();
if (debug)
{
methodPtr->writeConnectivity(src, tgt, srcToTgtCellAddr_);
}
}
void Foam::meshToMesh::calculate()
{
Info<< "Creating mesh-to-mesh addressing for " << srcRegion_.name()
<< " and " << tgtRegion_.name() << " regions using "
<< interpolationMethodNames_[method_] << endl;
singleMeshProc_ = calcDistribution(srcRegion_, tgtRegion_);
if (singleMeshProc_ == -1)
{
// create global indexing for src and tgt meshes
globalIndex globalSrcCells(srcRegion_.nCells());
globalIndex globalTgtCells(tgtRegion_.nCells());
// Create processor map of overlapping cells. This map gets
// (possibly remote) cells from the tgt mesh such that they (together)
// cover all of the src mesh
autoPtr<mapDistribute> mapPtr = calcProcMap(srcRegion_, tgtRegion_);
const mapDistribute& map = mapPtr();
pointField newTgtPoints;
faceList newTgtFaces;
labelList newTgtFaceOwners;
labelList newTgtFaceNeighbours;
labelList newTgtCellIDs;
distributeAndMergeCells
(
map,
tgtRegion_,
globalTgtCells,
newTgtPoints,
newTgtFaces,
newTgtFaceOwners,
newTgtFaceNeighbours,
newTgtCellIDs
);
// create a new target mesh
polyMesh newTgt
(
IOobject
(
"newTgt." + Foam::name(Pstream::myProcNo()),
tgtRegion_.time().timeName(),
tgtRegion_.time(),
IOobject::NO_READ
),
xferMove(newTgtPoints),
xferMove(newTgtFaces),
xferMove(newTgtFaceOwners),
xferMove(newTgtFaceNeighbours),
false // no parallel comms
);
// create some dummy patch info
List<polyPatch*> patches(1);
patches[0] = new polyPatch
(
"defaultFaces",
newTgt.nFaces() - newTgt.nInternalFaces(),
newTgt.nInternalFaces(),
0,
newTgt.boundaryMesh(),
word::null
);
newTgt.addPatches(patches);
// force calculation of tet-base points used for point-in-cell
(void)newTgt.tetBasePtIs();
// force construction of cell tree
// (void)newTgt.cellTree();
if (debug)
{
Pout<< "Created newTgt mesh:" << nl
<< " old cells = " << tgtRegion_.nCells()
<< ", new cells = " << newTgt.nCells() << nl
<< " old faces = " << tgtRegion_.nFaces()
<< ", new faces = " << newTgt.nFaces() << endl;
if (debug > 1)
{
Pout<< "Writing newTgt mesh: " << newTgt.name() << endl;
newTgt.write();
}
}
calcAddressing(srcRegion_, newTgt);
// per source cell the target cell address in newTgt mesh
forAll(srcToTgtCellAddr_, i)
{
labelList& addressing = srcToTgtCellAddr_[i];
forAll(addressing, addrI)
{
addressing[addrI] = newTgtCellIDs[addressing[addrI]];
}
}
// convert target addresses in newTgtMesh into global cell numbering
forAll(tgtToSrcCellAddr_, i)
{
labelList& addressing = tgtToSrcCellAddr_[i];
forAll(addressing, addrI)
{
addressing[addrI] = globalSrcCells.toGlobal(addressing[addrI]);
}
}
// set up as a reverse distribute
mapDistribute::distribute
(
Pstream::nonBlocking,
List<labelPair>(),
tgtRegion_.nCells(),
map.constructMap(),
map.subMap(),
tgtToSrcCellAddr_,
ListPlusEqOp<label>(),
labelList()
);
// set up as a reverse distribute
mapDistribute::distribute
(
Pstream::nonBlocking,
List<labelPair>(),
tgtRegion_.nCells(),
map.constructMap(),
map.subMap(),
tgtToSrcCellWght_,
ListPlusEqOp<scalar>(),
scalarList()
);
// weights normalisation
normaliseWeights
(
"source",
srcToTgtCellAddr_,
srcToTgtCellWght_
);
normaliseWeights
(
"target",
tgtToSrcCellAddr_,
tgtToSrcCellWght_
);
// cache maps and reset addresses
List<Map<label> > cMap;
srcMapPtr_.reset
(
new mapDistribute(globalSrcCells, tgtToSrcCellAddr_, cMap)
);
tgtMapPtr_.reset
(
new mapDistribute(globalTgtCells, srcToTgtCellAddr_, cMap)
);
// collect volume intersection contributions
reduce(V_, sumOp<scalar>());
}
else
{
calcAddressing(srcRegion_, tgtRegion_);
normaliseWeights
(
"source",
srcToTgtCellAddr_,
srcToTgtCellWght_
);
normaliseWeights
(
"target",
tgtToSrcCellAddr_,
tgtToSrcCellWght_
);
}
Info<< " Overlap volume: " << V_ << endl;
}
Foam::AMIPatchToPatchInterpolation::interpolationMethod
Foam::meshToMesh::interpolationMethodAMI
(
const interpolationMethod method
) const
{
switch (method_)
{
case imDirect:
{
return AMIPatchToPatchInterpolation::imDirect;
break;
}
case imMapNearest:
{
return AMIPatchToPatchInterpolation::imMapNearest;
break;
}
case imCellVolumeWeight:
{
return AMIPatchToPatchInterpolation::imFaceAreaWeight;
break;
}
default:
{
FatalErrorIn
(
"Foam::AMIPatchToPatchInterpolation::interpolationMethod"
"Foam::meshToMesh::interpolationMethodAMI"
"("
"const interpolationMethod method"
") const"
)
<< "Unhandled enumeration " << method_
<< abort(FatalError);
}
}
return AMIPatchToPatchInterpolation::imDirect;
}
const Foam::PtrList<Foam::AMIPatchToPatchInterpolation>&
Foam::meshToMesh::patchAMIs() const
{
if (patchAMIs_.empty())
{
const word amiMethod =
AMIPatchToPatchInterpolation::interpolationMethodToWord
(
interpolationMethodAMI(method_)
);
patchAMIs_.setSize(srcPatchID_.size());
forAll(srcPatchID_, i)
{
label srcPatchI = srcPatchID_[i];
label tgtPatchI = tgtPatchID_[i];
const polyPatch& srcPP = srcRegion_.boundaryMesh()[srcPatchI];
const polyPatch& tgtPP = tgtRegion_.boundaryMesh()[tgtPatchI];
Info<< "Creating AMI between source patch " << srcPP.name()
<< " and target patch " << tgtPP.name()
<< " using " << amiMethod
<< endl;
Info<< incrIndent;
patchAMIs_.set
(
i,
new AMIPatchToPatchInterpolation
(
srcPP,
tgtPP,
faceAreaIntersect::tmMesh,
interpolationMethodAMI(method_),
true // flip target patch since patch normals are aligned
)
);
Info<< decrIndent;
}
}
return patchAMIs_;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::meshToMesh::meshToMesh
(
const fvMesh& meshFrom,
const fvMesh& meshTo,
const HashTable<word>& patchMap,
const wordList& cuttingPatchNames
const polyMesh& src,
const polyMesh& tgt,
const interpolationMethod& method,
bool interpAllPatches
)
:
fromMesh_(meshFrom),
toMesh_(meshTo),
patchMap_(patchMap),
cellAddressing_(toMesh_.nCells()),
boundaryAddressing_(toMesh_.boundaryMesh().size()),
inverseDistanceWeightsPtr_(NULL),
inverseVolumeWeightsPtr_(NULL),
cellToCellAddressingPtr_(NULL),
V_(0.0)
srcRegion_(src),
tgtRegion_(tgt),
srcPatchID_(),
tgtPatchID_(),
patchAMIs_(),
cuttingPatches_(),
srcToTgtCellAddr_(),
tgtToSrcCellAddr_(),
srcToTgtCellWght_(),
tgtToSrcCellWght_(),
method_(method),
V_(0.0),
singleMeshProc_(-1),
srcMapPtr_(NULL),
tgtMapPtr_(NULL)
{
forAll(fromMesh_.boundaryMesh(), patchi)
if (interpAllPatches)
{
fromMeshPatches_.insert
(
fromMesh_.boundaryMesh()[patchi].name(),
patchi
);
}
const polyBoundaryMesh& srcBM = src.boundaryMesh();
const polyBoundaryMesh& tgtBM = tgt.boundaryMesh();
forAll(toMesh_.boundaryMesh(), patchi)
{
toMeshPatches_.insert
(
toMesh_.boundaryMesh()[patchi].name(),
patchi
);
}
forAll(cuttingPatchNames, i)
{
if (toMeshPatches_.found(cuttingPatchNames[i]))
DynamicList<label> srcPatchID(src.boundaryMesh().size());
DynamicList<label> tgtPatchID(tgt.boundaryMesh().size());
forAll(srcBM, patchI)
{
cuttingPatches_.insert
(
cuttingPatchNames[i],
toMeshPatches_.find(cuttingPatchNames[i])()
);
}
else
{
WarningIn
(
"meshToMesh::meshToMesh"
"(const fvMesh& meshFrom, const fvMesh& meshTo,"
"const HashTable<word>& patchMap,"
"const wordList& cuttingPatchNames)"
) << "Cannot find cutting-patch " << cuttingPatchNames[i]
<< " in destination mesh" << endl;
const polyPatch& pp = srcBM[patchI];
if (!polyPatch::constraintType(pp.type()))
{
srcPatchID.append(pp.index());
label tgtPatchI = tgt.boundaryMesh().findPatchID(pp.name());
if (tgtPatchI != -1)
{
tgtPatchID.append(tgtPatchI);
}
else
{
FatalErrorIn
(
"Foam::meshToMesh::meshToMesh"
"("
"const polyMesh&, "
"const polyMesh&, "
"const interpolationMethod&, "
"bool"
")"
) << "Source patch " << pp.name()
<< " not found in target mesh. "
<< "Available target patches are " << tgtBM.names()
<< exit(FatalError);
}
}
}
srcPatchID_.transfer(srcPatchID);
tgtPatchID_.transfer(tgtPatchID);
}
forAll(toMesh_.boundaryMesh(), patchi)
{
// Add the processor patches in the toMesh to the cuttingPatches list
if (isA<processorPolyPatch>(toMesh_.boundaryMesh()[patchi]))
{
cuttingPatches_.insert
(
toMesh_.boundaryMesh()[patchi].name(),
patchi
);
}
}
// calculate volume addressing and weights
calculate();
calcAddressing();
// calculate patch addressing and weights
(void)patchAMIs();
}
Foam::meshToMesh::meshToMesh
(
const fvMesh& meshFrom,
const fvMesh& meshTo
const polyMesh& src,
const polyMesh& tgt,
const interpolationMethod& method,
const HashTable<word>& patchMap,
const wordList& cuttingPatches
)
:
fromMesh_(meshFrom),
toMesh_(meshTo),
cellAddressing_(toMesh_.nCells()),
boundaryAddressing_(toMesh_.boundaryMesh().size()),
inverseDistanceWeightsPtr_(NULL),
inverseVolumeWeightsPtr_(NULL),
cellToCellAddressingPtr_(NULL),
V_(0.0)
srcRegion_(src),
tgtRegion_(tgt),
srcPatchID_(),
tgtPatchID_(),
patchAMIs_(),
cuttingPatches_(),
srcToTgtCellAddr_(),
tgtToSrcCellAddr_(),
srcToTgtCellWght_(),
tgtToSrcCellWght_(),
method_(method),
V_(0.0),
singleMeshProc_(-1),
srcMapPtr_(NULL),
tgtMapPtr_(NULL)
{
// check whether both meshes have got the same number
// of boundary patches
if (fromMesh_.boundary().size() != toMesh_.boundary().size())
srcPatchID_.setSize(patchMap.size());
tgtPatchID_.setSize(patchMap.size());
label i = 0;
forAllConstIter(HashTable<word>, patchMap, iter)
{
FatalErrorIn
(
"meshToMesh::meshToMesh"
"(const fvMesh& meshFrom, const fvMesh& meshTo)"
) << "Incompatible meshes: different number of patches, "
<< "fromMesh = " << fromMesh_.boundary().size()
<< ", toMesh = " << toMesh_.boundary().size()
<< exit(FatalError);
const word& tgtPatchName = iter.key();
const word& srcPatchName = iter();
const polyPatch& srcPatch = srcRegion_.boundaryMesh()[srcPatchName];
const polyPatch& tgtPatch = tgtRegion_.boundaryMesh()[tgtPatchName];
srcPatchID_[i] = srcPatch.index();
tgtPatchID_[i] = tgtPatch.index();
i++;
}
forAll(fromMesh_.boundaryMesh(), patchi)
// calculate volume addressing and weights
calculate();
// calculate patch addressing and weights
(void)patchAMIs();
// set IDs of cutting patches on target mesh
cuttingPatches_.setSize(cuttingPatches.size());
forAll(cuttingPatches_, i)
{
if
(
fromMesh_.boundaryMesh()[patchi].name()
!= toMesh_.boundaryMesh()[patchi].name()
)
{
FatalErrorIn
(
"meshToMesh::meshToMesh"
"(const fvMesh& meshFrom, const fvMesh& meshTo)"
) << "Incompatible meshes: different patch names for patch "
<< patchi
<< ", fromMesh = " << fromMesh_.boundary()[patchi].name()
<< ", toMesh = " << toMesh_.boundary()[patchi].name()
<< exit(FatalError);
}
if
(
fromMesh_.boundaryMesh()[patchi].type()
!= toMesh_.boundaryMesh()[patchi].type()
)
{
FatalErrorIn
(
"meshToMesh::meshToMesh"
"(const fvMesh& meshFrom, const fvMesh& meshTo)"
) << "Incompatible meshes: different patch types for patch "
<< patchi
<< ", fromMesh = " << fromMesh_.boundary()[patchi].type()
<< ", toMesh = " << toMesh_.boundary()[patchi].type()
<< exit(FatalError);
}
fromMeshPatches_.insert
(
fromMesh_.boundaryMesh()[patchi].name(),
patchi
);
toMeshPatches_.insert
(
toMesh_.boundaryMesh()[patchi].name(),
patchi
);
patchMap_.insert
(
toMesh_.boundaryMesh()[patchi].name(),
fromMesh_.boundaryMesh()[patchi].name()
);
const word& patchName = cuttingPatches[i];
cuttingPatches_[i] = tgt.boundaryMesh().findPatchID(patchName);
}
calcAddressing();
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::meshToMesh::~meshToMesh()
{
deleteDemandDrivenData(inverseDistanceWeightsPtr_);
deleteDemandDrivenData(inverseVolumeWeightsPtr_);
deleteDemandDrivenData(cellToCellAddressingPtr_);
}
{}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012-2014 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -25,286 +25,456 @@ Class
Foam::meshToMesh
Description
mesh to mesh interpolation class.
Class to calculate the cell-addressing between two overlapping meshes
Note
This class is due to be deprecated in favour of meshToMeshNew
Mapping is performed using a run-time selectable interpolation mothod
SeeAlso
meshToMeshMethod
SourceFiles
meshToMesh.C
calculateMeshToMeshAddressing.C
calculateMeshToMeshWeights.C
meshToMeshInterpolate.C
meshToMeshParallelOps.C
meshToMeshTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef meshtoMesh_H
#define meshtoMesh_H
#ifndef meshToMesh_H
#define meshToMesh_H
#include "fvMesh.H"
#include "HashTable.H"
#include "fvPatchMapper.H"
#include "scalarList.H"
#include "className.H"
#include "polyMesh.H"
#include "boundBox.H"
#include "mapDistribute.H"
#include "volFieldsFwd.H"
#include "NamedEnum.H"
#include "AMIPatchToPatchInterpolation.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<class Type>
class indexedOctree;
class treeDataCell;
/*---------------------------------------------------------------------------*\
Class meshToMesh Declaration
Class meshToMesh Declaration
\*---------------------------------------------------------------------------*/
class meshToMesh
{
public:
// Public data types
//- Enumeration specifying interpolation method
enum interpolationMethod
{
imDirect,
imMapNearest,
imCellVolumeWeight
};
static const NamedEnum<interpolationMethod, 3>
interpolationMethodNames_;
private:
// Private data
// mesh references
//- Reference to the source mesh
const polyMesh& srcRegion_;
const fvMesh& fromMesh_;
const fvMesh& toMesh_;
//- Reference to the target mesh
const polyMesh& tgtRegion_;
//- fromMesh patch labels
HashTable<label> fromMeshPatches_;
//- List of target patch IDs per source patch (local index)
List<label> srcPatchID_;
//- toMesh patch labels
HashTable<label> toMeshPatches_;
//- List of source patch IDs per target patch (local index)
List<label> tgtPatchID_;
//- Patch map
HashTable<word> patchMap_;
//- List of AMIs between source and target patches
mutable PtrList<AMIPatchToPatchInterpolation> patchAMIs_;
//- toMesh patch labels which cut the from-mesh
HashTable<label> cuttingPatches_;
//- Cutting patches whose values are set using a zero-gradient condition
List<label> cuttingPatches_;
//- Cell addressing
labelList cellAddressing_;
//- Source to target cell addressing
labelListList srcToTgtCellAddr_;
//- Boundary addressing
labelListList boundaryAddressing_;
//- Target to source cell addressing
labelListList tgtToSrcCellAddr_;
//- Inverse-distance interpolation weights
mutable scalarListList* inverseDistanceWeightsPtr_;
//- Source to target cell interplation weights
scalarListList srcToTgtCellWght_;
//- Inverse-volume interpolation weights
mutable scalarListList* inverseVolumeWeightsPtr_;
//- Target to source cell interpolation weights
scalarListList tgtToSrcCellWght_;
//- Cell to cell overlap addressing
mutable labelListList* cellToCellAddressingPtr_;
//- Interpolation method
interpolationMethod method_;
//- Overlap volume
mutable scalar V_;
//- Cell total volume in overlap region [m3]
scalar V_;
//- Index of processor that holds all of both sides. -1 in all other
// cases
label singleMeshProc_;
//- Source map pointer - parallel running only
autoPtr<mapDistribute> srcMapPtr_;
//- Target map pointer - parallel running only
autoPtr<mapDistribute> tgtMapPtr_;
// Private Member Functions
void calcAddressing();
//- Helper function to add a constant offset to a list
template<class Type>
void add(UList<Type>& fld, const label offset) const;
void cellAddresses
//- Return src cell IDs for the overlap region
labelList maskCells(const polyMesh& src, const polyMesh& tgt) const;
//- Normalise the interpolation weights
void normaliseWeights
(
labelList& cells,
const pointField& points,
const fvMesh& fromMesh,
const List<bool>& boundaryCell,
const indexedOctree<treeDataCell>& oc
const word& descriptor,
const labelListList& addr,
scalarListList& wght
) const;
void calculateInverseDistanceWeights() const;
//- Calculate the addressing between overalping regions of src and tgt
// meshes
void calcAddressing(const polyMesh& src, const polyMesh& tgt);
void calculateInverseVolumeWeights() const;
//- Calculate - main driver function
void calculate();
void calculateCellToCellAddressing() const;
//- Conversion between mesh and patch interpolation methods
AMIPatchToPatchInterpolation::interpolationMethod
interpolationMethodAMI
(
const interpolationMethod method
) const;
const scalarListList& inverseDistanceWeights() const;
const scalarListList& inverseVolumeWeights() const;
const labelListList& cellToCellAddressing() const;
//- Return the list of AMIs between source and target patches
const PtrList<AMIPatchToPatchInterpolation>& patchAMIs() const;
// Private static data members
// Parallel operations
//- Direct hit tolerance
static const scalar directHitTol;
//- Determine whether the meshes are split across multiple pocessors
label calcDistribution
(
const polyMesh& src,
const polyMesh& tgt
) const;
//- Determine which processor bounding-boxes overlap
label calcOverlappingProcs
(
const List<boundBox>& procBb,
const boundBox& bb,
boolList& overlaps
) const;
//- Calculate the mapping between processors
autoPtr<mapDistribute> calcProcMap
(
const polyMesh& src,
const polyMesh& tgt
) const;
//- Distribute mesh info from 'my' processor to others
void distributeCells
(
const mapDistribute& map,
const polyMesh& tgtMesh,
const globalIndex& globalI,
List<pointField>& points,
List<label>& nInternalFaces,
List<faceList>& faces,
List<labelList>& faceOwner,
List<labelList>& faceNeighbour,
List<labelList>& cellIDs,
List<labelList>& nbrProcIDs,
List<labelList>& procLocalFaceIDs
) const;
//- Collect pieces of tgt mesh from other procssors and restructure
void distributeAndMergeCells
(
const mapDistribute& map,
const polyMesh& tgt,
const globalIndex& globalI,
pointField& tgtPoints,
faceList& tgtFaces,
labelList& tgtFaceOwners,
labelList& tgtFaceNeighbours,
labelList& tgtCellIDs
) const;
//- Disallow default bitwise copy construct
meshToMesh(const meshToMesh&);
//- Disallow default bitwise assignment
void operator=(const meshToMesh&);
public:
// Declare name of the class and its debug switch
ClassName("meshToMesh");
//- Run-time type information
TypeName("meshToMesh");
//- Enumeration specifying required accuracy
enum order
{
MAP,
INTERPOLATE,
CELL_POINT_INTERPOLATE,
CELL_VOLUME_WEIGHT
};
//- Construct from source and target meshes
meshToMesh
(
const polyMesh& src,
const polyMesh& tgt,
const interpolationMethod& method,
const bool interpAllPatches = true
);
// Constructors
//- Construct from the two meshes, the patch name map for the patches
// to be interpolated and the names of the toMesh-patches which
// cut the fromMesh
meshToMesh
(
const fvMesh& fromMesh,
const fvMesh& toMesh,
const HashTable<word>& patchMap,
const wordList& cuttingPatchNames
);
//- Construct from the two meshes assuming there is an exact mapping
// between the patches
meshToMesh
(
const fvMesh& fromMesh,
const fvMesh& toMesh
);
//- Construct from source and target meshes
meshToMesh
(
const polyMesh& src,
const polyMesh& tgt,
const interpolationMethod& method,
const HashTable<word>& patchMap,
const wordList& cuttingPatches
);
//- Destructor
~meshToMesh();
virtual ~meshToMesh();
// Member Functions
// Access
const fvMesh& fromMesh() const
{
return fromMesh_;
}
//- Return const access to the source mesh
inline const polyMesh& srcRegion() const;
const fvMesh& toMesh() const
{
return toMesh_;
}
//- Return const access to the target mesh
inline const polyMesh& tgtRegion() const;
//- From toMesh cells to fromMesh cells
const labelList& cellAddressing() const
{
return cellAddressing_;
}
//- Return const access to the source to target cell addressing
inline const labelListList& srcToTgtCellAddr() const;
//- Overlap volume
scalar V() const
{
return V_;
}
//- Return const access to the target to source cell addressing
inline const labelListList& tgtToSrcCellAddr() const;
//- Return const access to the source to target cell weights
inline const scalarListList& srcToTgtCellWght() const;
//- Return const access to the target to source cell weights
inline const scalarListList& tgtToSrcCellWght() const;
//- Return const access to the overlap volume
inline scalar V() const;
// Interpolation
// Evaluation
//- Map field
template<class Type, class CombineOp>
void mapField
(
Field<Type>&,
const Field<Type>&,
const labelList& adr,
const CombineOp& cop
) const;
// Source-to-target field mapping
//- Interpolate field using inverse-distance weights
template<class Type, class CombineOp>
void interpolateField
(
Field<Type>&,
const GeometricField<Type, fvPatchField, volMesh>&,
const labelList& adr,
const scalarListList& weights,
const CombineOp& cop
) const;
//- Map field from src to tgt mesh with defined operation
// Values passed in via 'result' are used to initialise the
// return value
template<class Type, class CombineOp>
void mapSrcToTgt
(
const UList<Type>& srcFld,
const CombineOp& cop,
List<Type>& result
) const;
//- Interpolate field using inverse-volume weights
template<class Type, class CombineOp>
void interpolateField
(
Field<Type>&,
const GeometricField<Type, fvPatchField, volMesh>&,
const labelListList& adr,
const scalarListList& weights,
const CombineOp& cop
) const;
//- Return the src field mapped to the tgt mesh with a defined
// operation. Initial values of the result are set to zero
template<class Type, class CombineOp>
tmp<Field<Type> > mapSrcToTgt
(
const Field<Type>& srcFld,
const CombineOp& cop
) const;
//- Convenience function to map a tmp field to the tgt mesh
// with a defined operation
template<class Type, class CombineOp>
tmp<Field<Type> > mapSrcToTgt
(
const tmp<Field<Type> >& tsrcFld,
const CombineOp& cop
) const;
//- Convenience function to map a field to the tgt mesh with a
// default operation (plusEqOp)
template<class Type>
tmp<Field<Type> > mapSrcToTgt
(
const Field<Type>& srcFld
) const;
//- Convenience function to map a tmp field to the tgt mesh
// with a default operation (plusEqOp)
template<class Type>
tmp<Field<Type> > mapSrcToTgt
(
const tmp<Field<Type> >& tsrcFld
) const;
//- Interpolate field using cell-point interpolation
template<class Type, class CombineOp>
void interpolateField
(
Field<Type>&,
const GeometricField<Type, fvPatchField, volMesh>&,
const labelList& adr,
const vectorField& centres,
const CombineOp& cop
)const;
// Target-to-source field mapping
//- Map field from tgt to src mesh with defined operation
// Values passed in via 'result' are used to initialise the
// return value
template<class Type, class CombineOp>
void mapTgtToSrc
(
const UList<Type>& tgtFld,
const CombineOp& cop,
List<Type>& result
) const;
//- Return the tgt field mapped to the src mesh with a defined
// operation. Initial values of the result are set to zero
template<class Type, class CombineOp>
tmp<Field<Type> > mapTgtToSrc
(
const Field<Type>& tgtFld,
const CombineOp& cop
) const;
//- Convenience function to map a tmp field to the src mesh
// with a defined operation
template<class Type, class CombineOp>
tmp<Field<Type> > mapTgtToSrc
(
const tmp<Field<Type> >& ttgtFld,
const CombineOp& cop
) const;
//- Convenience function to map a field to the src mesh with a
// default operation (plusEqOp)
template<class Type>
tmp<Field<Type> > mapTgtToSrc
(
const Field<Type>& tgtFld
) const;
//- Convenience function to map a tmp field to the src mesh
// with a default operation (plusEqOp)
template<class Type>
tmp<Field<Type> > mapTgtToSrc
(
const tmp<Field<Type> >& ttgtFld
) const;
//- Interpolate internal volume field
template<class Type, class CombineOp>
void interpolateInternalField
(
Field<Type>&,
const GeometricField<Type, fvPatchField, volMesh>&,
order=INTERPOLATE,
const CombineOp& cop = eqOp<Type>()
) const;
// Source-to-target volume field mapping
template<class Type, class CombineOp>
void interpolateInternalField
(
Field<Type>&,
const tmp<GeometricField<Type, fvPatchField, volMesh> >&,
order=INTERPOLATE,
const CombineOp& cop = eqOp<Type>()
) const;
//- Interpolate a field with a defined operation. Values
// passed in via 'result' are used to initialise the return
// value
template<class Type, class CombineOp>
void mapSrcToTgt
(
const GeometricField<Type, fvPatchField, volMesh>& field,
const CombineOp& cop,
GeometricField<Type, fvPatchField, volMesh>& result
) const;
//- Interpolate a field with a defined operation. The initial
// values of the result are set to zero
template<class Type, class CombineOp>
tmp<GeometricField<Type, fvPatchField, volMesh> > mapSrcToTgt
(
const GeometricField<Type, fvPatchField, volMesh>& field,
const CombineOp& cop
) const;
//- Interpolate a tmp field with a defined operation. The
// initial values of the result are set to zero
template<class Type, class CombineOp>
tmp<GeometricField<Type, fvPatchField, volMesh> > mapSrcToTgt
(
const tmp<GeometricField<Type, fvPatchField, volMesh> >&
tfield,
const CombineOp& cop
) const;
//- Convenience function to map a field with a default
// operation (plusEqOp)
template<class Type>
tmp<GeometricField<Type, fvPatchField, volMesh> > mapSrcToTgt
(
const GeometricField<Type, fvPatchField, volMesh>& field
) const;
//- Convenience function to map a tmp field with a default
// operation (plusEqOp)
template<class Type>
tmp<GeometricField<Type, fvPatchField, volMesh> > mapSrcToTgt
(
const tmp<GeometricField<Type, fvPatchField, volMesh> >&
tfield
) const;
//- Interpolate volume field
template<class Type, class CombineOp>
void interpolate
(
GeometricField<Type, fvPatchField, volMesh>&,
const GeometricField<Type, fvPatchField, volMesh>&,
order=INTERPOLATE,
const CombineOp& cop = eqOp<Type>()
) const;
// Target-to-source volume field mapping
template<class Type, class CombineOp>
void interpolate
(
GeometricField<Type, fvPatchField, volMesh>&,
const tmp<GeometricField<Type, fvPatchField, volMesh> >&,
order=INTERPOLATE,
const CombineOp& cop = eqOp<Type>()
) const;
//- Interpolate a field with a defined operation. Values
// passed in via 'result' are used to initialise the return
// value
template<class Type, class CombineOp>
void mapTgtToSrc
(
const GeometricField<Type, fvPatchField, volMesh>& field,
const CombineOp& cop,
GeometricField<Type, fvPatchField, volMesh>& result
) const;
//- Interpolate a field with a defined operation. The initial
// values of the result are set to zero
template<class Type, class CombineOp>
tmp<GeometricField<Type, fvPatchField, volMesh> > mapTgtToSrc
(
const GeometricField<Type, fvPatchField, volMesh>& field,
const CombineOp& cop
) const;
//- Interpolate volume field
template<class Type, class CombineOp>
tmp<GeometricField<Type, fvPatchField, volMesh> > interpolate
(
const GeometricField<Type, fvPatchField, volMesh>&,
order=INTERPOLATE,
const CombineOp& cop = eqOp<Type>()
) const;
//- Interpolate a tmp field with a defined operation. The
// initial values of the result are set to zero
template<class Type, class CombineOp>
tmp<GeometricField<Type, fvPatchField, volMesh> > mapTgtToSrc
(
const tmp<GeometricField<Type, fvPatchField, volMesh> >&
tfield,
const CombineOp& cop
) const;
template<class Type, class CombineOp>
tmp<GeometricField<Type, fvPatchField, volMesh> > interpolate
(
const tmp<GeometricField<Type, fvPatchField, volMesh> >&,
order=INTERPOLATE,
const CombineOp& cop = eqOp<Type>()
) const;
//- Convenience function to map a field with a default
// operation (plusEqOp)
template<class Type>
tmp<GeometricField<Type, fvPatchField, volMesh> > mapTgtToSrc
(
const GeometricField<Type, fvPatchField, volMesh>& field
) const;
//- Convenience function to map a tmp field with a default
// operation (plusEqOp)
template<class Type>
tmp<GeometricField<Type, fvPatchField, volMesh> > mapTgtToSrc
(
const tmp<GeometricField<Type, fvPatchField, volMesh> >&
tfield
) const;
};
@ -314,8 +484,12 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "meshToMeshI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "meshToMeshInterpolate.C"
#include "meshToMeshTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012-2014 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -23,51 +23,51 @@ License
\*---------------------------------------------------------------------------*/
#include "meshToMeshNew.H"
#include "meshToMesh.H"
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
inline const Foam::polyMesh& Foam::meshToMeshNew::srcRegion() const
inline const Foam::polyMesh& Foam::meshToMesh::srcRegion() const
{
return srcRegion_;
}
inline const Foam::polyMesh& Foam::meshToMeshNew::tgtRegion() const
inline const Foam::polyMesh& Foam::meshToMesh::tgtRegion() const
{
return tgtRegion_;
}
inline const Foam::labelListList&
Foam::meshToMeshNew::srcToTgtCellAddr() const
Foam::meshToMesh::srcToTgtCellAddr() const
{
return srcToTgtCellAddr_;
}
inline const Foam::labelListList&
Foam::meshToMeshNew::tgtToSrcCellAddr() const
Foam::meshToMesh::tgtToSrcCellAddr() const
{
return tgtToSrcCellAddr_;
}
inline const Foam::scalarListList&
Foam::meshToMeshNew::srcToTgtCellWght() const
Foam::meshToMesh::srcToTgtCellWght() const
{
return srcToTgtCellWght_;
}
inline const Foam::scalarListList&
Foam::meshToMeshNew::tgtToSrcCellWght() const
Foam::meshToMesh::tgtToSrcCellWght() const
{
return tgtToSrcCellWght_;
}
inline Foam::scalar Foam::meshToMeshNew::V() const
inline Foam::scalar Foam::meshToMesh::V() const
{
return V_;
}

View File

@ -1,499 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "meshToMesh.H"
#include "volFields.H"
#include "interpolationCellPoint.H"
#include "SubField.H"
#include "mixedFvPatchField.H"
#include "directFvPatchFieldMapper.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type, class CombineOp>
void Foam::meshToMesh::mapField
(
Field<Type>& toF,
const Field<Type>& fromVf,
const labelList& adr,
const CombineOp& cop
) const
{
// Direct mapping of nearest-cell values
forAll(toF, celli)
{
if (adr[celli] != -1)
{
cop(toF[celli], fromVf[adr[celli]]);
}
}
//toF.map(fromVf, adr);
}
template<class Type, class CombineOp>
void Foam::meshToMesh::interpolateField
(
Field<Type>& toF,
const GeometricField<Type, fvPatchField, volMesh>& fromVf,
const labelListList& adr,
const scalarListList& weights,
const CombineOp& cop
) const
{
// Inverse volume weighted interpolation
forAll(toF, celli)
{
const labelList& overlapCells = adr[celli];
const scalarList& w = weights[celli];
Type f = pTraits<Type>::zero;
forAll(overlapCells, i)
{
label fromCelli = overlapCells[i];
f += fromVf[fromCelli]*w[i];
cop(toF[celli], f);
}
}
}
template<class Type, class CombineOp>
void Foam::meshToMesh::interpolateField
(
Field<Type>& toF,
const GeometricField<Type, fvPatchField, volMesh>& fromVf,
const labelList& adr,
const scalarListList& weights,
const CombineOp& cop
) const
{
// Inverse distance weighted interpolation
// get reference to cellCells
const labelListList& cc = fromMesh_.cellCells();
forAll(toF, celli)
{
if (adr[celli] != -1)
{
const labelList& neighbours = cc[adr[celli]];
const scalarList& w = weights[celli];
Type f = fromVf[adr[celli]]*w[0];
for (label ni = 1; ni < w.size(); ni++)
{
f += fromVf[neighbours[ni - 1]]*w[ni];
}
cop(toF[celli], f);
}
}
}
template<class Type, class CombineOp>
void Foam::meshToMesh::interpolateField
(
Field<Type>& toF,
const GeometricField<Type, fvPatchField, volMesh>& fromVf,
const labelList& adr,
const vectorField& centres,
const CombineOp& cop
) const
{
// Cell-Point interpolation
interpolationCellPoint<Type> interpolator(fromVf);
forAll(toF, celli)
{
if (adr[celli] != -1)
{
cop
(
toF[celli],
interpolator.interpolate
(
centres[celli],
adr[celli]
)
);
}
}
}
template<class Type, class CombineOp>
void Foam::meshToMesh::interpolateInternalField
(
Field<Type>& toF,
const GeometricField<Type, fvPatchField, volMesh>& fromVf,
meshToMesh::order ord,
const CombineOp& cop
) const
{
if (fromVf.mesh() != fromMesh_)
{
FatalErrorIn
(
"meshToMesh::interpolateInternalField(Field<Type>&, "
"const GeometricField<Type, fvPatchField, volMesh>&, "
"meshToMesh::order, const CombineOp&) const"
) << "the argument field does not correspond to the right mesh. "
<< "Field size: " << fromVf.size()
<< " mesh size: " << fromMesh_.nCells()
<< exit(FatalError);
}
if (toF.size() != toMesh_.nCells())
{
FatalErrorIn
(
"meshToMesh::interpolateInternalField(Field<Type>&, "
"const GeometricField<Type, fvPatchField, volMesh>&, "
"meshToMesh::order, const CombineOp&) const"
) << "the argument field does not correspond to the right mesh. "
<< "Field size: " << toF.size()
<< " mesh size: " << toMesh_.nCells()
<< exit(FatalError);
}
switch(ord)
{
case MAP:
mapField(toF, fromVf, cellAddressing_, cop);
break;
case INTERPOLATE:
{
interpolateField
(
toF,
fromVf,
cellAddressing_,
inverseDistanceWeights(),
cop
);
break;
}
case CELL_POINT_INTERPOLATE:
{
interpolateField
(
toF,
fromVf,
cellAddressing_,
toMesh_.cellCentres(),
cop
);
break;
}
case CELL_VOLUME_WEIGHT:
{
const labelListList& cellToCell = cellToCellAddressing();
const scalarListList& invVolWeights = inverseVolumeWeights();
interpolateField
(
toF,
fromVf,
cellToCell,
invVolWeights,
cop
);
break;
}
default:
FatalErrorIn
(
"meshToMesh::interpolateInternalField(Field<Type>&, "
"const GeometricField<Type, fvPatchField, volMesh>&, "
"meshToMesh::order, const CombineOp&) const"
) << "unknown interpolation scheme " << ord
<< exit(FatalError);
}
}
template<class Type, class CombineOp>
void Foam::meshToMesh::interpolateInternalField
(
Field<Type>& toF,
const tmp<GeometricField<Type, fvPatchField, volMesh> >& tfromVf,
meshToMesh::order ord,
const CombineOp& cop
) const
{
interpolateInternalField(toF, tfromVf(), ord, cop);
tfromVf.clear();
}
template<class Type, class CombineOp>
void Foam::meshToMesh::interpolate
(
GeometricField<Type, fvPatchField, volMesh>& toVf,
const GeometricField<Type, fvPatchField, volMesh>& fromVf,
meshToMesh::order ord,
const CombineOp& cop
) const
{
interpolateInternalField(toVf, fromVf, ord, cop);
forAll(toMesh_.boundaryMesh(), patchi)
{
const fvPatch& toPatch = toMesh_.boundary()[patchi];
if (cuttingPatches_.found(toPatch.name()))
{
switch(ord)
{
case MAP:
{
mapField
(
toVf.boundaryField()[patchi],
fromVf,
boundaryAddressing_[patchi],
cop
);
break;
}
case INTERPOLATE:
{
interpolateField
(
toVf.boundaryField()[patchi],
fromVf,
boundaryAddressing_[patchi],
toPatch.Cf(),
cop
);
break;
}
case CELL_POINT_INTERPOLATE:
{
interpolateField
(
toVf.boundaryField()[patchi],
fromVf,
boundaryAddressing_[patchi],
toPatch.Cf(),
cop
);
break;
}
case CELL_VOLUME_WEIGHT:
{
// Do nothing
break;
}
default:
FatalErrorIn
(
"meshToMesh::interpolate("
"GeometricField<Type, fvPatchField, volMesh>&, "
"const GeometricField<Type, fvPatchField, volMesh>&, "
"meshToMesh::order, const CombineOp&) const"
) << "unknown interpolation scheme " << ord
<< exit(FatalError);
}
if (isA<mixedFvPatchField<Type> >(toVf.boundaryField()[patchi]))
{
refCast<mixedFvPatchField<Type> >
(
toVf.boundaryField()[patchi]
).refValue() = toVf.boundaryField()[patchi];
}
}
else if
(
patchMap_.found(toPatch.name())
&& fromMeshPatches_.found(patchMap_.find(toPatch.name())())
)
{
/*
toVf.boundaryField()[patchi].map
(
fromVf.boundaryField()
[
fromMeshPatches_.find(patchMap_.find(toPatch.name())())()
],
boundaryAddressing_[patchi]
);
*/
mapField
(
toVf.boundaryField()[patchi],
fromVf.boundaryField()
[
fromMeshPatches_.find(patchMap_.find(toPatch.name())())()
],
boundaryAddressing_[patchi],
cop
);
}
}
}
template<class Type, class CombineOp>
void Foam::meshToMesh::interpolate
(
GeometricField<Type, fvPatchField, volMesh>& toVf,
const tmp<GeometricField<Type, fvPatchField, volMesh> >& tfromVf,
meshToMesh::order ord,
const CombineOp& cop
) const
{
interpolate(toVf, tfromVf(), ord, cop);
tfromVf.clear();
}
template<class Type, class CombineOp>
Foam::tmp< Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh> >
Foam::meshToMesh::interpolate
(
const GeometricField<Type, fvPatchField, volMesh>& fromVf,
meshToMesh::order ord,
const CombineOp& cop
) const
{
// Create and map the internal-field values
Field<Type> internalField(toMesh_.nCells());
interpolateInternalField(internalField, fromVf, ord, cop);
// check whether both meshes have got the same number
// of boundary patches
if (fromMesh_.boundary().size() != toMesh_.boundary().size())
{
FatalErrorIn
(
"meshToMesh::interpolate"
"(const GeometricField<Type, fvPatchField, volMesh>&,"
"meshToMesh::order, const CombineOp&) const"
) << "Incompatible meshes: different number of boundaries, "
"only internal field may be interpolated"
<< exit(FatalError);
}
// 1. Create the complete field with dummy patch fields
PtrList<fvPatchField<Type> > patchFields
(
boundaryAddressing_.size()
);
forAll(boundaryAddressing_, patchI)
{
patchFields.set
(
patchI,
fvPatchField<Type>::New
(
calculatedFvPatchField<Type>::typeName,
toMesh_.boundary()[patchI],
DimensionedField<Type, volMesh>::null()
)
);
}
// Create the complete field from the pieces
tmp<GeometricField<Type, fvPatchField, volMesh> > ttoF
(
new GeometricField<Type, fvPatchField, volMesh>
(
IOobject
(
"interpolated(" + fromVf.name() + ')',
toMesh_.time().timeName(),
toMesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
toMesh_,
fromVf.dimensions(),
internalField,
patchFields
)
);
GeometricField<Type, fvPatchField, volMesh>& toF = ttoF();
// 2. Change the fvPatchFields to the correct type using a mapper
// constructor (with reference to the now correct internal field)
typename GeometricField<Type, fvPatchField, volMesh>::
GeometricBoundaryField& bf = toF.boundaryField();
forAll(boundaryAddressing_, patchI)
{
bf.set
(
patchI,
fvPatchField<Type>::New
(
fromVf.boundaryField()[patchI],
toMesh_.boundary()[patchI],
toF.dimensionedInternalField(),
directFvPatchFieldMapper
(
boundaryAddressing_[patchI]
)
)
);
}
return ttoF;
}
template<class Type, class CombineOp>
Foam::tmp< Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh> >
Foam::meshToMesh::interpolate
(
const tmp<GeometricField<Type, fvPatchField, volMesh> >& tfromVf,
meshToMesh::order ord,
const CombineOp& cop
) const
{
tmp<GeometricField<Type, fvPatchField, volMesh> > tint =
interpolate(tfromVf(), ord, cop);
tfromVf.clear();
return tint;
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012-2014 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -23,7 +23,7 @@ License
\*---------------------------------------------------------------------------*/
#include "meshToMeshNew.H"
#include "meshToMesh.H"
#include "OFstream.H"
#include "Time.H"
#include "globalIndex.H"
@ -33,7 +33,7 @@ License
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::label Foam::meshToMeshNew::calcDistribution
Foam::label Foam::meshToMesh::calcDistribution
(
const polyMesh& src,
const polyMesh& tgt
@ -63,7 +63,7 @@ Foam::label Foam::meshToMeshNew::calcDistribution
procI = -1;
if (debug)
{
Info<< "meshToMeshNew::calcDistribution: "
Info<< "meshToMesh::calcDistribution: "
<< "Meshes split across multiple processors" << endl;
}
}
@ -72,7 +72,7 @@ Foam::label Foam::meshToMeshNew::calcDistribution
procI = findIndex(cellsPresentOnProc, 1);
if (debug)
{
Info<< "meshToMeshNew::calcDistribution: "
Info<< "meshToMesh::calcDistribution: "
<< "Meshes local to processor" << procI << endl;
}
}
@ -82,7 +82,7 @@ Foam::label Foam::meshToMeshNew::calcDistribution
}
Foam::label Foam::meshToMeshNew::calcOverlappingProcs
Foam::label Foam::meshToMesh::calcOverlappingProcs
(
const List<boundBox>& procBb,
const boundBox& bb,
@ -108,7 +108,7 @@ Foam::label Foam::meshToMeshNew::calcOverlappingProcs
}
Foam::autoPtr<Foam::mapDistribute> Foam::meshToMeshNew::calcProcMap
Foam::autoPtr<Foam::mapDistribute> Foam::meshToMesh::calcProcMap
(
const polyMesh& src,
const polyMesh& tgt
@ -255,7 +255,7 @@ Foam::autoPtr<Foam::mapDistribute> Foam::meshToMeshNew::calcProcMap
}
void Foam::meshToMeshNew::distributeCells
void Foam::meshToMesh::distributeCells
(
const mapDistribute& map,
const polyMesh& tgtMesh,
@ -495,7 +495,7 @@ void Foam::meshToMeshNew::distributeCells
}
void Foam::meshToMeshNew::distributeAndMergeCells
void Foam::meshToMesh::distributeAndMergeCells
(
const mapDistribute& map,
const polyMesh& tgt,
@ -791,7 +791,7 @@ void Foam::meshToMeshNew::distributeAndMergeCells
{
FatalErrorIn
(
"void Foam::meshToMeshNew::"
"void Foam::meshToMesh::"
"distributeAndMergeCells"
"("
"const mapDistribute&, "

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012-2014 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -61,7 +61,7 @@ namespace Foam
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
template<class Type>
void Foam::meshToMeshNew::add
void Foam::meshToMesh::add
(
UList<Type>& fld,
const label offset
@ -75,7 +75,7 @@ void Foam::meshToMeshNew::add
template<class Type, class CombineOp>
void Foam::meshToMeshNew::mapSrcToTgt
void Foam::meshToMesh::mapSrcToTgt
(
const UList<Type>& srcField,
const CombineOp& cop,
@ -86,7 +86,7 @@ void Foam::meshToMeshNew::mapSrcToTgt
{
FatalErrorIn
(
"void Foam::meshToMeshNew::mapSrcToTgt"
"void Foam::meshToMesh::mapSrcToTgt"
"("
"const UList<Type>&, "
"const CombineOp&, "
@ -150,7 +150,7 @@ void Foam::meshToMeshNew::mapSrcToTgt
template<class Type, class CombineOp>
Foam::tmp<Foam::Field<Type> > Foam::meshToMeshNew::mapSrcToTgt
Foam::tmp<Foam::Field<Type> > Foam::meshToMesh::mapSrcToTgt
(
const Field<Type>& srcField,
const CombineOp& cop
@ -172,7 +172,7 @@ Foam::tmp<Foam::Field<Type> > Foam::meshToMeshNew::mapSrcToTgt
template<class Type, class CombineOp>
Foam::tmp<Foam::Field<Type> > Foam::meshToMeshNew::mapSrcToTgt
Foam::tmp<Foam::Field<Type> > Foam::meshToMesh::mapSrcToTgt
(
const tmp<Field<Type> >& tsrcField,
const CombineOp& cop
@ -183,7 +183,7 @@ Foam::tmp<Foam::Field<Type> > Foam::meshToMeshNew::mapSrcToTgt
template<class Type>
Foam::tmp<Foam::Field<Type> > Foam::meshToMeshNew::mapSrcToTgt
Foam::tmp<Foam::Field<Type> > Foam::meshToMesh::mapSrcToTgt
(
const Field<Type>& srcField
) const
@ -193,7 +193,7 @@ Foam::tmp<Foam::Field<Type> > Foam::meshToMeshNew::mapSrcToTgt
template<class Type>
Foam::tmp<Foam::Field<Type> > Foam::meshToMeshNew::mapSrcToTgt
Foam::tmp<Foam::Field<Type> > Foam::meshToMesh::mapSrcToTgt
(
const tmp<Field<Type> >& tsrcField
) const
@ -203,7 +203,7 @@ Foam::tmp<Foam::Field<Type> > Foam::meshToMeshNew::mapSrcToTgt
template<class Type, class CombineOp>
void Foam::meshToMeshNew::mapTgtToSrc
void Foam::meshToMesh::mapTgtToSrc
(
const UList<Type>& tgtField,
const CombineOp& cop,
@ -214,7 +214,7 @@ void Foam::meshToMeshNew::mapTgtToSrc
{
FatalErrorIn
(
"void Foam::meshToMeshNew::mapTgtToSrc"
"void Foam::meshToMesh::mapTgtToSrc"
"("
"const UList<Type>&, "
"const CombineOp&, "
@ -276,7 +276,7 @@ void Foam::meshToMeshNew::mapTgtToSrc
template<class Type, class CombineOp>
Foam::tmp<Foam::Field<Type> > Foam::meshToMeshNew::mapTgtToSrc
Foam::tmp<Foam::Field<Type> > Foam::meshToMesh::mapTgtToSrc
(
const Field<Type>& tgtField,
const CombineOp& cop
@ -298,7 +298,7 @@ Foam::tmp<Foam::Field<Type> > Foam::meshToMeshNew::mapTgtToSrc
template<class Type, class CombineOp>
Foam::tmp<Foam::Field<Type> > Foam::meshToMeshNew::mapTgtToSrc
Foam::tmp<Foam::Field<Type> > Foam::meshToMesh::mapTgtToSrc
(
const tmp<Field<Type> >& ttgtField,
const CombineOp& cop
@ -309,7 +309,7 @@ Foam::tmp<Foam::Field<Type> > Foam::meshToMeshNew::mapTgtToSrc
template<class Type>
Foam::tmp<Foam::Field<Type> > Foam::meshToMeshNew::mapTgtToSrc
Foam::tmp<Foam::Field<Type> > Foam::meshToMesh::mapTgtToSrc
(
const Field<Type>& tgtField
) const
@ -319,7 +319,7 @@ Foam::tmp<Foam::Field<Type> > Foam::meshToMeshNew::mapTgtToSrc
template<class Type>
Foam::tmp<Foam::Field<Type> > Foam::meshToMeshNew::mapTgtToSrc
Foam::tmp<Foam::Field<Type> > Foam::meshToMesh::mapTgtToSrc
(
const tmp<Field<Type> >& ttgtField
) const
@ -329,7 +329,7 @@ Foam::tmp<Foam::Field<Type> > Foam::meshToMeshNew::mapTgtToSrc
template<class Type, class CombineOp>
void Foam::meshToMeshNew::mapSrcToTgt
void Foam::meshToMesh::mapSrcToTgt
(
const GeometricField<Type, fvPatchField, volMesh>& field,
const CombineOp& cop,
@ -369,7 +369,7 @@ void Foam::meshToMeshNew::mapSrcToTgt
template<class Type, class CombineOp>
Foam::tmp<Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh> >
Foam::meshToMeshNew::mapSrcToTgt
Foam::meshToMesh::mapSrcToTgt
(
const GeometricField<Type, fvPatchField, volMesh>& field,
const CombineOp& cop
@ -409,7 +409,7 @@ Foam::meshToMeshNew::mapSrcToTgt
template<class Type, class CombineOp>
Foam::tmp<Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh> >
Foam::meshToMeshNew::mapSrcToTgt
Foam::meshToMesh::mapSrcToTgt
(
const tmp<GeometricField<Type, fvPatchField, volMesh> >& tfield,
const CombineOp& cop
@ -421,7 +421,7 @@ Foam::meshToMeshNew::mapSrcToTgt
template<class Type>
Foam::tmp<Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh> >
Foam::meshToMeshNew::mapSrcToTgt
Foam::meshToMesh::mapSrcToTgt
(
const GeometricField<Type, fvPatchField, volMesh>& field
) const
@ -432,7 +432,7 @@ Foam::meshToMeshNew::mapSrcToTgt
template<class Type>
Foam::tmp<Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh> >
Foam::meshToMeshNew::mapSrcToTgt
Foam::meshToMesh::mapSrcToTgt
(
const tmp<GeometricField<Type, fvPatchField, volMesh> >& tfield
) const
@ -442,7 +442,7 @@ Foam::meshToMeshNew::mapSrcToTgt
template<class Type, class CombineOp>
void Foam::meshToMeshNew::mapTgtToSrc
void Foam::meshToMesh::mapTgtToSrc
(
const GeometricField<Type, fvPatchField, volMesh>& field,
const CombineOp& cop,
@ -482,7 +482,7 @@ void Foam::meshToMeshNew::mapTgtToSrc
template<class Type, class CombineOp>
Foam::tmp<Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh> >
Foam::meshToMeshNew::mapTgtToSrc
Foam::meshToMesh::mapTgtToSrc
(
const GeometricField<Type, fvPatchField, volMesh>& field,
const CombineOp& cop
@ -522,7 +522,7 @@ Foam::meshToMeshNew::mapTgtToSrc
template<class Type, class CombineOp>
Foam::tmp<Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh> >
Foam::meshToMeshNew::mapTgtToSrc
Foam::meshToMesh::mapTgtToSrc
(
const tmp<GeometricField<Type, fvPatchField, volMesh> >& tfield,
const CombineOp& cop
@ -534,7 +534,7 @@ Foam::meshToMeshNew::mapTgtToSrc
template<class Type>
Foam::tmp<Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh> >
Foam::meshToMeshNew::mapTgtToSrc
Foam::meshToMesh::mapTgtToSrc
(
const GeometricField<Type, fvPatchField, volMesh>& field
) const
@ -545,7 +545,7 @@ Foam::meshToMeshNew::mapTgtToSrc
template<class Type>
Foam::tmp<Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh> >
Foam::meshToMeshNew::mapTgtToSrc
Foam::meshToMesh::mapTgtToSrc
(
const tmp<GeometricField<Type, fvPatchField, volMesh> >& tfield
) const

View File

@ -1,576 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "meshToMeshNew.H"
#include "Time.H"
#include "globalIndex.H"
#include "meshToMeshMethod.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(meshToMeshNew, 0);
template<>
const char* Foam::NamedEnum
<
Foam::meshToMeshNew::interpolationMethod,
3
>::names[] =
{
"direct",
"mapNearest",
"cellVolumeWeight"
};
const NamedEnum<meshToMeshNew::interpolationMethod, 3>
meshToMeshNew::interpolationMethodNames_;
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::labelList Foam::meshToMeshNew::maskCells
(
const polyMesh& src,
const polyMesh& tgt
) const
{
boundBox intersectBb
(
max(src.bounds().min(), tgt.bounds().min()),
min(src.bounds().max(), tgt.bounds().max())
);
intersectBb.inflate(0.01);
const cellList& srcCells = src.cells();
const faceList& srcFaces = src.faces();
const pointField& srcPts = src.points();
DynamicList<label> cells(src.size());
forAll(srcCells, srcI)
{
boundBox cellBb(srcCells[srcI].points(srcFaces, srcPts), false);
if (intersectBb.overlaps(cellBb))
{
cells.append(srcI);
}
}
if (debug)
{
Pout<< "participating source mesh cells: " << cells.size() << endl;
}
return cells;
}
void Foam::meshToMeshNew::normaliseWeights
(
const word& descriptor,
const labelListList& addr,
scalarListList& wght
) const
{
const label nCell = returnReduce(wght.size(), sumOp<label>());
if (nCell > 0)
{
forAll(wght, cellI)
{
scalarList& w = wght[cellI];
scalar s = sum(w);
forAll(w, i)
{
// note: normalise by s instead of cell volume since
// 1-to-1 methods duplicate contributions in parallel
w[i] /= s;
}
}
}
}
void Foam::meshToMeshNew::calcAddressing
(
const polyMesh& src,
const polyMesh& tgt
)
{
autoPtr<meshToMeshMethod> methodPtr
(
meshToMeshMethod::New
(
interpolationMethodNames_[method_],
src,
tgt
)
);
methodPtr->calculate
(
srcToTgtCellAddr_,
srcToTgtCellWght_,
tgtToSrcCellAddr_,
tgtToSrcCellWght_
);
V_ = methodPtr->V();
if (debug)
{
methodPtr->writeConnectivity(src, tgt, srcToTgtCellAddr_);
}
}
void Foam::meshToMeshNew::calculate()
{
Info<< "Creating mesh-to-mesh addressing for " << srcRegion_.name()
<< " and " << tgtRegion_.name() << " regions using "
<< interpolationMethodNames_[method_] << endl;
singleMeshProc_ = calcDistribution(srcRegion_, tgtRegion_);
if (singleMeshProc_ == -1)
{
// create global indexing for src and tgt meshes
globalIndex globalSrcCells(srcRegion_.nCells());
globalIndex globalTgtCells(tgtRegion_.nCells());
// Create processor map of overlapping cells. This map gets
// (possibly remote) cells from the tgt mesh such that they (together)
// cover all of the src mesh
autoPtr<mapDistribute> mapPtr = calcProcMap(srcRegion_, tgtRegion_);
const mapDistribute& map = mapPtr();
pointField newTgtPoints;
faceList newTgtFaces;
labelList newTgtFaceOwners;
labelList newTgtFaceNeighbours;
labelList newTgtCellIDs;
distributeAndMergeCells
(
map,
tgtRegion_,
globalTgtCells,
newTgtPoints,
newTgtFaces,
newTgtFaceOwners,
newTgtFaceNeighbours,
newTgtCellIDs
);
// create a new target mesh
polyMesh newTgt
(
IOobject
(
"newTgt." + Foam::name(Pstream::myProcNo()),
tgtRegion_.time().timeName(),
tgtRegion_.time(),
IOobject::NO_READ
),
xferMove(newTgtPoints),
xferMove(newTgtFaces),
xferMove(newTgtFaceOwners),
xferMove(newTgtFaceNeighbours),
false // no parallel comms
);
// create some dummy patch info
List<polyPatch*> patches(1);
patches[0] = new polyPatch
(
"defaultFaces",
newTgt.nFaces() - newTgt.nInternalFaces(),
newTgt.nInternalFaces(),
0,
newTgt.boundaryMesh(),
word::null
);
newTgt.addPatches(patches);
// force calculation of tet-base points used for point-in-cell
(void)newTgt.tetBasePtIs();
// force construction of cell tree
// (void)newTgt.cellTree();
if (debug)
{
Pout<< "Created newTgt mesh:" << nl
<< " old cells = " << tgtRegion_.nCells()
<< ", new cells = " << newTgt.nCells() << nl
<< " old faces = " << tgtRegion_.nFaces()
<< ", new faces = " << newTgt.nFaces() << endl;
if (debug > 1)
{
Pout<< "Writing newTgt mesh: " << newTgt.name() << endl;
newTgt.write();
}
}
calcAddressing(srcRegion_, newTgt);
// per source cell the target cell address in newTgt mesh
forAll(srcToTgtCellAddr_, i)
{
labelList& addressing = srcToTgtCellAddr_[i];
forAll(addressing, addrI)
{
addressing[addrI] = newTgtCellIDs[addressing[addrI]];
}
}
// convert target addresses in newTgtMesh into global cell numbering
forAll(tgtToSrcCellAddr_, i)
{
labelList& addressing = tgtToSrcCellAddr_[i];
forAll(addressing, addrI)
{
addressing[addrI] = globalSrcCells.toGlobal(addressing[addrI]);
}
}
// set up as a reverse distribute
mapDistribute::distribute
(
Pstream::nonBlocking,
List<labelPair>(),
tgtRegion_.nCells(),
map.constructMap(),
map.subMap(),
tgtToSrcCellAddr_,
ListPlusEqOp<label>(),
labelList()
);
// set up as a reverse distribute
mapDistribute::distribute
(
Pstream::nonBlocking,
List<labelPair>(),
tgtRegion_.nCells(),
map.constructMap(),
map.subMap(),
tgtToSrcCellWght_,
ListPlusEqOp<scalar>(),
scalarList()
);
// weights normalisation
normaliseWeights
(
"source",
srcToTgtCellAddr_,
srcToTgtCellWght_
);
normaliseWeights
(
"target",
tgtToSrcCellAddr_,
tgtToSrcCellWght_
);
// cache maps and reset addresses
List<Map<label> > cMap;
srcMapPtr_.reset
(
new mapDistribute(globalSrcCells, tgtToSrcCellAddr_, cMap)
);
tgtMapPtr_.reset
(
new mapDistribute(globalTgtCells, srcToTgtCellAddr_, cMap)
);
// collect volume intersection contributions
reduce(V_, sumOp<scalar>());
}
else
{
calcAddressing(srcRegion_, tgtRegion_);
normaliseWeights
(
"source",
srcToTgtCellAddr_,
srcToTgtCellWght_
);
normaliseWeights
(
"target",
tgtToSrcCellAddr_,
tgtToSrcCellWght_
);
}
Info<< " Overlap volume: " << V_ << endl;
}
Foam::AMIPatchToPatchInterpolation::interpolationMethod
Foam::meshToMeshNew::interpolationMethodAMI
(
const interpolationMethod method
) const
{
switch (method_)
{
case imDirect:
{
return AMIPatchToPatchInterpolation::imDirect;
break;
}
case imMapNearest:
{
return AMIPatchToPatchInterpolation::imMapNearest;
break;
}
case imCellVolumeWeight:
{
return AMIPatchToPatchInterpolation::imFaceAreaWeight;
break;
}
default:
{
FatalErrorIn
(
"Foam::AMIPatchToPatchInterpolation::interpolationMethod"
"Foam::meshToMeshNew::interpolationMethodAMI"
"("
"const interpolationMethod method"
") const"
)
<< "Unhandled enumeration " << method_
<< abort(FatalError);
}
}
return AMIPatchToPatchInterpolation::imDirect;
}
const Foam::PtrList<Foam::AMIPatchToPatchInterpolation>&
Foam::meshToMeshNew::patchAMIs() const
{
if (patchAMIs_.empty())
{
const word amiMethod =
AMIPatchToPatchInterpolation::interpolationMethodToWord
(
interpolationMethodAMI(method_)
);
patchAMIs_.setSize(srcPatchID_.size());
forAll(srcPatchID_, i)
{
label srcPatchI = srcPatchID_[i];
label tgtPatchI = tgtPatchID_[i];
const polyPatch& srcPP = srcRegion_.boundaryMesh()[srcPatchI];
const polyPatch& tgtPP = tgtRegion_.boundaryMesh()[tgtPatchI];
Info<< "Creating AMI between source patch " << srcPP.name()
<< " and target patch " << tgtPP.name()
<< " using " << amiMethod
<< endl;
Info<< incrIndent;
patchAMIs_.set
(
i,
new AMIPatchToPatchInterpolation
(
srcPP,
tgtPP,
faceAreaIntersect::tmMesh,
interpolationMethodAMI(method_),
true // flip target patch since patch normals are aligned
)
);
Info<< decrIndent;
}
}
return patchAMIs_;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::meshToMeshNew::meshToMeshNew
(
const polyMesh& src,
const polyMesh& tgt,
const interpolationMethod& method,
bool interpAllPatches
)
:
srcRegion_(src),
tgtRegion_(tgt),
srcPatchID_(),
tgtPatchID_(),
patchAMIs_(),
cuttingPatches_(),
srcToTgtCellAddr_(),
tgtToSrcCellAddr_(),
srcToTgtCellWght_(),
tgtToSrcCellWght_(),
method_(method),
V_(0.0),
singleMeshProc_(-1),
srcMapPtr_(NULL),
tgtMapPtr_(NULL)
{
if (interpAllPatches)
{
const polyBoundaryMesh& srcBM = src.boundaryMesh();
const polyBoundaryMesh& tgtBM = tgt.boundaryMesh();
DynamicList<label> srcPatchID(src.boundaryMesh().size());
DynamicList<label> tgtPatchID(tgt.boundaryMesh().size());
forAll(srcBM, patchI)
{
const polyPatch& pp = srcBM[patchI];
if (!polyPatch::constraintType(pp.type()))
{
srcPatchID.append(pp.index());
label tgtPatchI = tgt.boundaryMesh().findPatchID(pp.name());
if (tgtPatchI != -1)
{
tgtPatchID.append(tgtPatchI);
}
else
{
FatalErrorIn
(
"Foam::meshToMeshNew::meshToMeshNew"
"("
"const polyMesh&, "
"const polyMesh&, "
"const interpolationMethod&, "
"bool"
")"
) << "Source patch " << pp.name()
<< " not found in target mesh. "
<< "Available target patches are " << tgtBM.names()
<< exit(FatalError);
}
}
}
srcPatchID_.transfer(srcPatchID);
tgtPatchID_.transfer(tgtPatchID);
}
// calculate volume addressing and weights
calculate();
// calculate patch addressing and weights
(void)patchAMIs();
}
Foam::meshToMeshNew::meshToMeshNew
(
const polyMesh& src,
const polyMesh& tgt,
const interpolationMethod& method,
const HashTable<word>& patchMap,
const wordList& cuttingPatches
)
:
srcRegion_(src),
tgtRegion_(tgt),
srcPatchID_(),
tgtPatchID_(),
patchAMIs_(),
cuttingPatches_(),
srcToTgtCellAddr_(),
tgtToSrcCellAddr_(),
srcToTgtCellWght_(),
tgtToSrcCellWght_(),
method_(method),
V_(0.0),
singleMeshProc_(-1),
srcMapPtr_(NULL),
tgtMapPtr_(NULL)
{
srcPatchID_.setSize(patchMap.size());
tgtPatchID_.setSize(patchMap.size());
label i = 0;
forAllConstIter(HashTable<word>, patchMap, iter)
{
const word& tgtPatchName = iter.key();
const word& srcPatchName = iter();
const polyPatch& srcPatch = srcRegion_.boundaryMesh()[srcPatchName];
const polyPatch& tgtPatch = tgtRegion_.boundaryMesh()[tgtPatchName];
srcPatchID_[i] = srcPatch.index();
tgtPatchID_[i] = tgtPatch.index();
i++;
}
// calculate volume addressing and weights
calculate();
// calculate patch addressing and weights
(void)patchAMIs();
// set IDs of cutting patches on target mesh
cuttingPatches_.setSize(cuttingPatches.size());
forAll(cuttingPatches_, i)
{
const word& patchName = cuttingPatches[i];
cuttingPatches_[i] = tgt.boundaryMesh().findPatchID(patchName);
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::meshToMeshNew::~meshToMeshNew()
{}
// ************************************************************************* //

View File

@ -1,499 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
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 <http://www.gnu.org/licenses/>.
Class
Foam::meshToMeshNew
Description
Class to calculate the cell-addressing between two overlapping meshes
Mapping is performed using a run-time selectable interpolation mothod
SeeAlso
meshToMeshMethod
SourceFiles
meshToMeshNew.C
meshToMeshNewParallelOps.C
meshToMeshNewTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef meshToMeshNew_H
#define meshToMeshNew_H
#include "polyMesh.H"
#include "boundBox.H"
#include "mapDistribute.H"
#include "volFieldsFwd.H"
#include "NamedEnum.H"
#include "AMIPatchToPatchInterpolation.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class meshToMeshNew Declaration
\*---------------------------------------------------------------------------*/
class meshToMeshNew
{
public:
// Public data types
//- Enumeration specifying interpolation method
enum interpolationMethod
{
imDirect,
imMapNearest,
imCellVolumeWeight
};
static const NamedEnum<interpolationMethod, 3>
interpolationMethodNames_;
private:
// Private data
//- Reference to the source mesh
const polyMesh& srcRegion_;
//- Reference to the target mesh
const polyMesh& tgtRegion_;
//- List of target patch IDs per source patch (local index)
List<label> srcPatchID_;
//- List of source patch IDs per target patch (local index)
List<label> tgtPatchID_;
//- List of AMIs between source and target patches
mutable PtrList<AMIPatchToPatchInterpolation> patchAMIs_;
//- Cutting patches whose values are set using a zero-gradient condition
List<label> cuttingPatches_;
//- Source to target cell addressing
labelListList srcToTgtCellAddr_;
//- Target to source cell addressing
labelListList tgtToSrcCellAddr_;
//- Source to target cell interplation weights
scalarListList srcToTgtCellWght_;
//- Target to source cell interpolation weights
scalarListList tgtToSrcCellWght_;
//- Interpolation method
interpolationMethod method_;
//- Cell total volume in overlap region [m3]
scalar V_;
//- Index of processor that holds all of both sides. -1 in all other
// cases
label singleMeshProc_;
//- Source map pointer - parallel running only
autoPtr<mapDistribute> srcMapPtr_;
//- Target map pointer - parallel running only
autoPtr<mapDistribute> tgtMapPtr_;
// Private Member Functions
//- Helper function to add a constant offset to a list
template<class Type>
void add(UList<Type>& fld, const label offset) const;
//- Return src cell IDs for the overlap region
labelList maskCells(const polyMesh& src, const polyMesh& tgt) const;
//- Normalise the interpolation weights
void normaliseWeights
(
const word& descriptor,
const labelListList& addr,
scalarListList& wght
) const;
//- Calculate the addressing between overalping regions of src and tgt
// meshes
void calcAddressing(const polyMesh& src, const polyMesh& tgt);
//- Calculate - main driver function
void calculate();
//- Conversion between mesh and patch interpolation methods
AMIPatchToPatchInterpolation::interpolationMethod
interpolationMethodAMI
(
const interpolationMethod method
) const;
//- Return the list of AMIs between source and target patches
const PtrList<AMIPatchToPatchInterpolation>& patchAMIs() const;
// Parallel operations
//- Determine whether the meshes are split across multiple pocessors
label calcDistribution
(
const polyMesh& src,
const polyMesh& tgt
) const;
//- Determine which processor bounding-boxes overlap
label calcOverlappingProcs
(
const List<boundBox>& procBb,
const boundBox& bb,
boolList& overlaps
) const;
//- Calculate the mapping between processors
autoPtr<mapDistribute> calcProcMap
(
const polyMesh& src,
const polyMesh& tgt
) const;
//- Distribute mesh info from 'my' processor to others
void distributeCells
(
const mapDistribute& map,
const polyMesh& tgtMesh,
const globalIndex& globalI,
List<pointField>& points,
List<label>& nInternalFaces,
List<faceList>& faces,
List<labelList>& faceOwner,
List<labelList>& faceNeighbour,
List<labelList>& cellIDs,
List<labelList>& nbrProcIDs,
List<labelList>& procLocalFaceIDs
) const;
//- Collect pieces of tgt mesh from other procssors and restructure
void distributeAndMergeCells
(
const mapDistribute& map,
const polyMesh& tgt,
const globalIndex& globalI,
pointField& tgtPoints,
faceList& tgtFaces,
labelList& tgtFaceOwners,
labelList& tgtFaceNeighbours,
labelList& tgtCellIDs
) const;
//- Disallow default bitwise copy construct
meshToMeshNew(const meshToMeshNew&);
//- Disallow default bitwise assignment
void operator=(const meshToMeshNew&);
public:
//- Run-time type information
TypeName("meshToMeshNew");
//- Construct from source and target meshes
meshToMeshNew
(
const polyMesh& src,
const polyMesh& tgt,
const interpolationMethod& method,
const bool interpAllPatches = true
);
//- Construct from source and target meshes
meshToMeshNew
(
const polyMesh& src,
const polyMesh& tgt,
const interpolationMethod& method,
const HashTable<word>& patchMap,
const wordList& cuttingPatches
);
//- Destructor
virtual ~meshToMeshNew();
// Member Functions
// Access
//- Return const access to the source mesh
inline const polyMesh& srcRegion() const;
//- Return const access to the target mesh
inline const polyMesh& tgtRegion() const;
//- Return const access to the source to target cell addressing
inline const labelListList& srcToTgtCellAddr() const;
//- Return const access to the target to source cell addressing
inline const labelListList& tgtToSrcCellAddr() const;
//- Return const access to the source to target cell weights
inline const scalarListList& srcToTgtCellWght() const;
//- Return const access to the target to source cell weights
inline const scalarListList& tgtToSrcCellWght() const;
//- Return const access to the overlap volume
inline scalar V() const;
// Evaluation
// Source-to-target field mapping
//- Map field from src to tgt mesh with defined operation
// Values passed in via 'result' are used to initialise the
// return value
template<class Type, class CombineOp>
void mapSrcToTgt
(
const UList<Type>& srcFld,
const CombineOp& cop,
List<Type>& result
) const;
//- Return the src field mapped to the tgt mesh with a defined
// operation. Initial values of the result are set to zero
template<class Type, class CombineOp>
tmp<Field<Type> > mapSrcToTgt
(
const Field<Type>& srcFld,
const CombineOp& cop
) const;
//- Convenience function to map a tmp field to the tgt mesh
// with a defined operation
template<class Type, class CombineOp>
tmp<Field<Type> > mapSrcToTgt
(
const tmp<Field<Type> >& tsrcFld,
const CombineOp& cop
) const;
//- Convenience function to map a field to the tgt mesh with a
// default operation (plusEqOp)
template<class Type>
tmp<Field<Type> > mapSrcToTgt
(
const Field<Type>& srcFld
) const;
//- Convenience function to map a tmp field to the tgt mesh
// with a default operation (plusEqOp)
template<class Type>
tmp<Field<Type> > mapSrcToTgt
(
const tmp<Field<Type> >& tsrcFld
) const;
// Target-to-source field mapping
//- Map field from tgt to src mesh with defined operation
// Values passed in via 'result' are used to initialise the
// return value
template<class Type, class CombineOp>
void mapTgtToSrc
(
const UList<Type>& tgtFld,
const CombineOp& cop,
List<Type>& result
) const;
//- Return the tgt field mapped to the src mesh with a defined
// operation. Initial values of the result are set to zero
template<class Type, class CombineOp>
tmp<Field<Type> > mapTgtToSrc
(
const Field<Type>& tgtFld,
const CombineOp& cop
) const;
//- Convenience function to map a tmp field to the src mesh
// with a defined operation
template<class Type, class CombineOp>
tmp<Field<Type> > mapTgtToSrc
(
const tmp<Field<Type> >& ttgtFld,
const CombineOp& cop
) const;
//- Convenience function to map a field to the src mesh with a
// default operation (plusEqOp)
template<class Type>
tmp<Field<Type> > mapTgtToSrc
(
const Field<Type>& tgtFld
) const;
//- Convenience function to map a tmp field to the src mesh
// with a default operation (plusEqOp)
template<class Type>
tmp<Field<Type> > mapTgtToSrc
(
const tmp<Field<Type> >& ttgtFld
) const;
// Source-to-target volume field mapping
//- Interpolate a field with a defined operation. Values
// passed in via 'result' are used to initialise the return
// value
template<class Type, class CombineOp>
void mapSrcToTgt
(
const GeometricField<Type, fvPatchField, volMesh>& field,
const CombineOp& cop,
GeometricField<Type, fvPatchField, volMesh>& result
) const;
//- Interpolate a field with a defined operation. The initial
// values of the result are set to zero
template<class Type, class CombineOp>
tmp<GeometricField<Type, fvPatchField, volMesh> > mapSrcToTgt
(
const GeometricField<Type, fvPatchField, volMesh>& field,
const CombineOp& cop
) const;
//- Interpolate a tmp field with a defined operation. The
// initial values of the result are set to zero
template<class Type, class CombineOp>
tmp<GeometricField<Type, fvPatchField, volMesh> > mapSrcToTgt
(
const tmp<GeometricField<Type, fvPatchField, volMesh> >&
tfield,
const CombineOp& cop
) const;
//- Convenience function to map a field with a default
// operation (plusEqOp)
template<class Type>
tmp<GeometricField<Type, fvPatchField, volMesh> > mapSrcToTgt
(
const GeometricField<Type, fvPatchField, volMesh>& field
) const;
//- Convenience function to map a tmp field with a default
// operation (plusEqOp)
template<class Type>
tmp<GeometricField<Type, fvPatchField, volMesh> > mapSrcToTgt
(
const tmp<GeometricField<Type, fvPatchField, volMesh> >&
tfield
) const;
// Target-to-source volume field mapping
//- Interpolate a field with a defined operation. Values
// passed in via 'result' are used to initialise the return
// value
template<class Type, class CombineOp>
void mapTgtToSrc
(
const GeometricField<Type, fvPatchField, volMesh>& field,
const CombineOp& cop,
GeometricField<Type, fvPatchField, volMesh>& result
) const;
//- Interpolate a field with a defined operation. The initial
// values of the result are set to zero
template<class Type, class CombineOp>
tmp<GeometricField<Type, fvPatchField, volMesh> > mapTgtToSrc
(
const GeometricField<Type, fvPatchField, volMesh>& field,
const CombineOp& cop
) const;
//- Interpolate a tmp field with a defined operation. The
// initial values of the result are set to zero
template<class Type, class CombineOp>
tmp<GeometricField<Type, fvPatchField, volMesh> > mapTgtToSrc
(
const tmp<GeometricField<Type, fvPatchField, volMesh> >&
tfield,
const CombineOp& cop
) const;
//- Convenience function to map a field with a default
// operation (plusEqOp)
template<class Type>
tmp<GeometricField<Type, fvPatchField, volMesh> > mapTgtToSrc
(
const GeometricField<Type, fvPatchField, volMesh>& field
) const;
//- Convenience function to map a tmp field with a default
// operation (plusEqOp)
template<class Type>
tmp<GeometricField<Type, fvPatchField, volMesh> > mapTgtToSrc
(
const tmp<GeometricField<Type, fvPatchField, volMesh> >&
tfield
) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "meshToMeshNewI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "meshToMeshNewTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //