Commit 316cb830 authored by mattijs's avatar mattijs
Browse files

BUG: lduPrimitiveMesh: hold, not refer to, interfaces

parent d7cadf49
......@@ -311,7 +311,6 @@ $(GAMGAgglomeration)/GAMGAgglomerateLduAddressing.C
pairGAMGAgglomeration = $(GAMGAgglomerations)/pairGAMGAgglomeration
$(pairGAMGAgglomeration)/pairGAMGAgglomeration.C
$(pairGAMGAgglomeration)/pairGAMGAgglomerate.C
$(pairGAMGAgglomeration)/pairGAMGAgglomerationCombineLevels.C
algebraicPairGAMGAgglomeration = $(GAMGAgglomerations)/algebraicPairGAMGAgglomeration
$(algebraicPairGAMGAgglomeration)/algebraicPairGAMGAgglomeration.C
......
......@@ -25,6 +25,7 @@ License
#include "GAMGAgglomeration.H"
#include "GAMGInterface.H"
#include "processorGAMGInterface.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
......@@ -260,27 +261,7 @@ void Foam::GAMGAgglomeration::agglomerateLduAddressing
// Create coarse-level interfaces
// Get reference to fine-level interfaces
const lduInterfacePtrsList& fineInterfaces =
interfaceLevels_[fineLevelIndex];
// Create coarse-level interfaces
primitiveInterfaces_.set
(
fineLevelIndex + 1,
new PtrList<const lduInterface>(fineInterfaces.size())
);
PtrList<const lduInterface>& coarsePrimInterfaces =
primitiveInterfaces_[fineLevelIndex + 1];
interfaceLevels_.set
(
fineLevelIndex + 1,
new lduInterfacePtrsList(fineInterfaces.size())
);
lduInterfacePtrsList& coarseInterfaces =
interfaceLevels_[fineLevelIndex + 1];
labelListList coarseInterfaceAddr(fineInterfaces.size());
const lduInterfacePtrsList& fineInterfaces = interfaceLevel(fineLevelIndex);
nPatchFaces_.set(fineLevelIndex, new labelList(fineInterfaces.size(), 0));
labelList& nPatchFaces = nPatchFaces_[fineLevelIndex];
......@@ -314,17 +295,33 @@ void Foam::GAMGAgglomeration::agglomerateLduAddressing
// Add the coarse level
meshLevels_.set
(
fineLevelIndex,
new lduPrimitiveMesh
(
nCoarseCells,
coarseOwner,
coarseNeighbour,
fineMesh.comm(),
true
)
);
labelListList coarseInterfaceAddr(fineInterfaces.size());
lduInterfacePtrsList coarseInterfaces(fineInterfaces.size());
forAll(fineInterfaces, inti)
{
if (fineInterfaces.set(inti))
{
coarsePrimInterfaces.set
coarseInterfaces.set
(
inti,
GAMGInterface::New
(
inti,
coarseInterfaces,
meshLevels_[fineLevelIndex].rawInterfaces(),
fineInterfaces[inti],
fineInterfaces[inti].interfaceInternalField(restrictMap),
fineInterfaces[inti].internalFieldTransfer
......@@ -337,7 +334,6 @@ void Foam::GAMGAgglomeration::agglomerateLduAddressing
).ptr()
);
coarseInterfaces.set(inti, &coarsePrimInterfaces[inti]);
coarseInterfaceAddr[inti] = coarseInterfaces[inti].faceCells();
nPatchFaces[inti] = coarseInterfaceAddr[inti].size();
patchFineToCoarse[inti] = refCast<const GAMGInterface>
......@@ -347,6 +343,16 @@ void Foam::GAMGAgglomeration::agglomerateLduAddressing
}
}
meshLevels_[fineLevelIndex].addInterfaces
(
coarseInterfaces,
coarseInterfaceAddr,
lduPrimitiveMesh::nonBlockingSchedule<processorGAMGInterface>
(
coarseInterfaces
)
);
if (debug)
{
......@@ -358,24 +364,6 @@ void Foam::GAMGAgglomeration::agglomerateLduAddressing
<< " nFaces:" << nCoarseFaces
<< endl;
}
// Set the coarse ldu addressing onto the list
meshLevels_.set
(
fineLevelIndex,
new lduPrimitiveMesh
(
nCoarseCells,
coarseOwner,
coarseNeighbour,
coarseInterfaceAddr,
coarseInterfaces,
fineMeshAddr.patchSchedule(),
fineMesh.comm(),
true
)
);
}
......@@ -407,63 +395,38 @@ void Foam::GAMGAgglomeration::procAgglomerateLduAddressing
procBoundaryMap_.set(levelIndex, new labelListList(0));
procBoundaryFaceMap_.set(levelIndex, new labelListListList(0));
autoPtr<lduPrimitiveMesh> allMesh;
{
// Collect meshes
PtrList<lduMesh> otherMeshes;
lduPrimitiveMesh::gather(meshComm, myMesh, procIDs, otherMeshes);
if (Pstream::myProcNo(meshComm) == procIDs[0])
{
// Combine all addressing
labelList procFaceOffsets;
allMesh.reset
(
new lduPrimitiveMesh
(
allMeshComm,
procAgglomMap,
procIDs,
myMesh,
otherMeshes,
procCellOffsets_[levelIndex],
procFaceOffsets,
procFaceMap_[levelIndex],
procBoundaryMap_[levelIndex],
procBoundaryFaceMap_[levelIndex]
)
);
}
}
// Collect meshes
PtrList<lduPrimitiveMesh> otherMeshes;
lduPrimitiveMesh::gather(meshComm, myMesh, procIDs, otherMeshes);
if (Pstream::myProcNo(meshComm) == procIDs[0])
{
// Combine all addressing
// ~~~~~~~~~~~~~~~~~~~~~~
meshLevels_.set(levelIndex-1, allMesh);
const lduPrimitiveMesh& levelMesh = meshLevels_[levelIndex-1];
const lduInterfacePtrsList& rawInterfaces = levelMesh.rawInterfaces();
lduInterfacePtrsList& levelInterfaces = interfaceLevels_[levelIndex];
levelInterfaces.setSize(rawInterfaces.size());
forAll(rawInterfaces, inti)
{
if (rawInterfaces.set(inti))
{
levelInterfaces.set(inti, &rawInterfaces[inti]);
}
else
{
levelInterfaces.set(inti, NULL);
}
}
labelList procFaceOffsets;
meshLevels_.set
(
levelIndex-1,
new lduPrimitiveMesh
(
allMeshComm,
procAgglomMap,
procIDs,
myMesh,
otherMeshes,
procCellOffsets_[levelIndex],
procFaceOffsets,
procFaceMap_[levelIndex],
procBoundaryMap_[levelIndex],
procBoundaryFaceMap_[levelIndex]
)
);
}
// Combine restrict addressing
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
......@@ -565,6 +528,105 @@ void Foam::GAMGAgglomeration::procAgglomerateRestrictAddressing
}
void Foam::GAMGAgglomeration::combineLevels(const label curLevel)
{
label prevLevel = curLevel - 1;
// Set the previous level nCells to the current
nCells_[prevLevel] = nCells_[curLevel];
nFaces_[prevLevel] = nFaces_[curLevel];
// Map the restrictAddressing from the coarser level into the previous
// finer level
const labelList& curResAddr = restrictAddressing_[curLevel];
labelList& prevResAddr = restrictAddressing_[prevLevel];
const labelList& curFaceResAddr = faceRestrictAddressing_[curLevel];
labelList& prevFaceResAddr = faceRestrictAddressing_[prevLevel];
const boolList& curFaceFlipMap = faceFlipMap_[curLevel];
boolList& prevFaceFlipMap = faceFlipMap_[prevLevel];
forAll(prevFaceResAddr, i)
{
if (prevFaceResAddr[i] >= 0)
{
label fineFaceI = prevFaceResAddr[i];
prevFaceResAddr[i] = curFaceResAddr[fineFaceI];
prevFaceFlipMap[i] = curFaceFlipMap[fineFaceI];
}
else
{
label fineFaceI = -prevFaceResAddr[i] - 1;
prevFaceResAddr[i] = -curResAddr[fineFaceI] - 1;
prevFaceFlipMap[i] = curFaceFlipMap[fineFaceI];
}
}
// Delete the restrictAddressing for the coarser level
faceRestrictAddressing_.set(curLevel, NULL);
faceFlipMap_.set(curLevel, NULL);
forAll(prevResAddr, i)
{
prevResAddr[i] = curResAddr[prevResAddr[i]];
}
const labelListList& curPatchFaceResAddr =
patchFaceRestrictAddressing_[curLevel];
labelListList& prevPatchFaceResAddr =
patchFaceRestrictAddressing_[prevLevel];
forAll(prevPatchFaceResAddr, inti)
{
const labelList& curResAddr = curPatchFaceResAddr[inti];
labelList& prevResAddr = prevPatchFaceResAddr[inti];
forAll(prevResAddr, i)
{
label fineFaceI = prevResAddr[i];
prevResAddr[i] = curResAddr[fineFaceI];
}
}
// Delete the restrictAddressing for the coarser level
restrictAddressing_.set(curLevel, NULL);
// Patch faces
nPatchFaces_[prevLevel] = nPatchFaces_[curLevel];
// Adapt the restrict addressing for the patches
const lduInterfacePtrsList& curInterLevel =
meshLevels_[curLevel].rawInterfaces();
const lduInterfacePtrsList& prevInterLevel =
meshLevels_[prevLevel].rawInterfaces();
forAll(prevInterLevel, inti)
{
if (prevInterLevel.set(inti))
{
GAMGInterface& prevInt = refCast<GAMGInterface>
(
const_cast<lduInterface&>
(
prevInterLevel[inti]
)
);
const GAMGInterface& curInt = refCast<const GAMGInterface>
(
curInterLevel[inti]
);
prevInt.combine(curInt);
}
}
// Delete the matrix addressing and coefficients from the previous level
// and replace with the corresponding entry from the coarser level
meshLevels_.set(prevLevel, meshLevels_.set(curLevel, NULL));
}
//void Foam::GAMGAgglomeration::gatherList
//(
// const label comm,
......@@ -660,5 +722,4 @@ void Foam::GAMGAgglomeration::calculateRegionMaster
}
// ************************************************************************* //
......@@ -54,8 +54,6 @@ void Foam::GAMGAgglomeration::compactLevels(const label nCreatedLevels)
nPatchFaces_.setSize(nCreatedLevels);
patchFaceRestrictAddressing_.setSize(nCreatedLevels);
meshLevels_.setSize(nCreatedLevels);
primitiveInterfaces_.setSize(nCreatedLevels + 1);
interfaceLevels_.setSize(nCreatedLevels + 1);
// Have procCommunicator_ always, even if not procAgglomerating
procCommunicator_.setSize(nCreatedLevels + 1);
......@@ -142,9 +140,7 @@ Foam::GAMGAgglomeration::GAMGAgglomeration
nPatchFaces_(maxLevels_),
patchFaceRestrictAddressing_(maxLevels_),
meshLevels_(maxLevels_),
primitiveInterfaces_(maxLevels_ + 1),
interfaceLevels_(maxLevels_ + 1)
meshLevels_(maxLevels_)
{
procCommunicator_.setSize(maxLevels_ + 1, -1);
if (processorAgglomerate())
......@@ -351,7 +347,14 @@ const Foam::lduInterfacePtrsList& Foam::GAMGAgglomeration::interfaceLevel
const label i
) const
{
return interfaceLevels_[i];
if (i == 0)
{
return meshInterfaces_;
}
else
{
return meshLevels_[i - 1].rawInterfaces();
}
}
......@@ -370,8 +373,6 @@ void Foam::GAMGAgglomeration::clearLevel(const label i)
faceFlipMap_.set(i, NULL);
nPatchFaces_.set(i, NULL);
patchFaceRestrictAddressing_.set(i, NULL);
primitiveInterfaces_.set(i, NULL);
interfaceLevels_.set(i, NULL);
}
}
}
......
......@@ -75,6 +75,8 @@ protected:
autoPtr<GAMGProcAgglomeration> procAgglomeratorPtr_;
//- Cached mesh interfaces
lduInterfacePtrsList meshInterfaces_;
//- The number of cells in each level
labelList nCells_;
......@@ -112,12 +114,6 @@ protected:
//- Hierarchy of mesh addressing
PtrList<lduPrimitiveMesh> meshLevels_;
//- Hierarchy of interfaces
PtrList<PtrList<const lduInterface> > primitiveInterfaces_;
//- Hierarchy of interfaces in lduInterfacePtrsList form
PtrList<lduInterfacePtrsList> interfaceLevels_;
// Processor agglomeration
......@@ -149,6 +145,9 @@ protected:
//- Assemble coarse mesh addressing
void agglomerateLduAddressing(const label fineLevelIndex);
//- Combine a level with the previous one
void combineLevels(const label curLevel);
//- Shrink the number of levels to that specified
void compactLevels(const label nCreatedLevels);
......
......@@ -53,11 +53,7 @@ Foam::dummyAgglomeration::dummyAgglomeration
nLevels_(readLabel(controlDict.lookup("nLevels")))
{
// Get the finest-level interfaces from the mesh
interfaceLevels_.set
(
0,
new lduInterfacePtrsList(mesh.interfaces())
);
meshInterfaces_ = mesh.interfaces();
const label nCoarseCells = mesh.lduAddr().size();
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -205,11 +205,7 @@ void Foam::pairGAMGAgglomeration::agglomerate
)
{
// Get the finest-level interfaces from the mesh
interfaceLevels_.set
(
0,
new lduInterfacePtrsList(mesh.interfaces())
);
meshInterfaces_ = mesh.interfaces();
// Start geometric agglomeration from the given faceWeights
scalarField* faceWeightsPtr = const_cast<scalarField*>(&faceWeights);
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -30,7 +30,6 @@ Description
SourceFiles
pairGAMGAgglomeration.C
pairGAMGAgglomerate.C
pairGAMGAgglomerationCombineLevels.C
\*---------------------------------------------------------------------------*/
......@@ -77,8 +76,6 @@ protected:
const scalarField& faceWeights
);
void combineLevels(const label curLevel);
//- Disallow default bitwise copy construct
pairGAMGAgglomeration(const pairGAMGAgglomeration&);
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 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 "pairGAMGAgglomeration.H"
#include "lduInterfacePtrsList.H"
#include "GAMGInterface.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::pairGAMGAgglomeration::combineLevels(const label curLevel)
{
label prevLevel = curLevel - 1;
// Set the previous level nCells to the current
nCells_[prevLevel] = nCells_[curLevel];
// Map the restrictAddressing from the coarser level into the previous
// finer level
const labelList& curResAddr = restrictAddressing_[curLevel];
labelList& prevResAddr = restrictAddressing_[prevLevel];
const labelList& curFaceResAddr = faceRestrictAddressing_[curLevel];
labelList& prevFaceResAddr = faceRestrictAddressing_[prevLevel];
forAll(prevFaceResAddr, i)
{
if (prevFaceResAddr[i] >= 0)
{
prevFaceResAddr[i] = curFaceResAddr[prevFaceResAddr[i]];
}
else
{
prevFaceResAddr[i] = -curResAddr[-prevFaceResAddr[i] - 1] - 1;
}
}
// Delete the restrictAddressing for the coarser level
faceRestrictAddressing_.set(curLevel, NULL);
forAll(prevResAddr, i)
{
prevResAddr[i] = curResAddr[prevResAddr[i]];
}
// Delete the restrictAddressing for the coarser level
restrictAddressing_.set(curLevel, NULL);
// Delete the matrix addressing and coefficients from the previous level
// and replace with the corresponding entried from the coarser level
meshLevels_.set(prevLevel, meshLevels_.set(curLevel, NULL));
// Same for the lduInterfaceFields taking care to delete the sub-entries
// held on List<T*>
const lduInterfacePtrsList& curInterLevel = interfaceLevels_[curLevel+1];
lduInterfacePtrsList& prevInterLevel = interfaceLevels_[prevLevel+1];
forAll(prevInterLevel, inti)
{
if (prevInterLevel.set(inti))
{
refCast<GAMGInterface>(const_cast<lduInterface&>
(
prevInterLevel[inti]
)).combine(refCast<const GAMGInterface>(curInterLevel[inti]));
delete curInterLevel(inti);
}
}
interfaceLevels_.set(curLevel+1, NULL);
}
// ************************************************************************* //
......@@ -65,11 +65,7 @@ Foam::processorGAMGInterface::processorGAMGInterface
(
index,
coarseInterfaces