Commit dfe464dd authored by mattijs's avatar mattijs
Browse files

BUG: redistributePar: transfer particles correctly. Fixes #605.

parent ce8695d8
passivePositionParticleCloud.C
parLagrangianRedistributor.C
parFvFieldReconstructor.C
loadOrCreateMesh.C
......
......@@ -25,7 +25,7 @@ License
#include "ListOps.H"
#include "parLagrangianRedistributor.H"
#include "passiveParticleCloud.H"
#include "passivePositionParticleCloud.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
......@@ -133,7 +133,7 @@ void Foam::parLagrangianRedistributor::findClouds
Foam::autoPtr<Foam::mapDistributeBase>
Foam::parLagrangianRedistributor::redistributeLagrangianPositions
(
passiveParticleCloud& lpi
passivePositionParticleCloud& lpi
) const
{
//Debug(lpi.size());
......@@ -147,7 +147,7 @@ Foam::parLagrangianRedistributor::redistributeLagrangianPositions
{
// List of lists of particles to be transferred for all of the
// neighbour processors
List<IDLList<passiveParticle>> particleTransferLists
List<IDLList<passivePositionParticle>> particleTransferLists
(
Pstream::nProcs()
);
......@@ -156,17 +156,15 @@ Foam::parLagrangianRedistributor::redistributeLagrangianPositions
labelList destProc(lpi.size());
label particleI = 0;
forAllIter(passiveParticleCloud, lpi, iter)
forAllIter(passivePositionParticleCloud, lpi, iter)
{
passiveParticle& ppi = iter();
passivePositionParticle& ppi = iter();
label destProcI = destinationProcID_[ppi.cell()];
label destCellI = destinationCell_[ppi.cell()];
ppi.cell() = destCellI;
destProc[particleI++] = destProcI;
//Pout<< "Sending particle:" << ppi << " to processor " << destProcI
// << " to cell " << destCellI << endl;
particleTransferLists[destProcI].append(lpi.remove(&ppi));
}
......@@ -202,11 +200,11 @@ Foam::parLagrangianRedistributor::redistributeLagrangianPositions
lpi.rename(cloudName + "_old");
// New cloud on tgtMesh
passiveParticleCloud lagrangianPositions
passivePositionParticleCloud lagrangianPositions
(
tgtMesh_,
cloudName,
IDLList<passiveParticle>()
IDLList<passivePositionParticle>()
);
......@@ -222,32 +220,28 @@ Foam::parLagrangianRedistributor::redistributeLagrangianPositions
{
UIPstream particleStream(procI, pBufs);
IDLList<passiveParticle> newParticles
// Receive particles and locate them
IDLList<passivePositionParticle> newParticles
(
particleStream,
passiveParticle::iNew(tgtMesh_)
passivePositionParticle::iNew(tgtMesh_)
);
forAllIter
(
IDLList<passiveParticle>,
IDLList<passivePositionParticle>,
newParticles,
newpIter
)
{
passiveParticle& newp = newpIter();
newp.relocate();
passivePositionParticle& newp = newpIter();
lagrangianPositions.addParticle(newParticles.remove(&newp));
}
}
}
//OFstream::debug = 1;
//Debug(lagrangianPositions.size());
IOPosition<passiveParticleCloud>(lagrangianPositions).write();
//OFstream::debug = 0;
IOPosition<passivePositionParticleCloud>(lagrangianPositions).write();
// Restore cloud name
lpi.rename(cloudName);
......@@ -300,7 +294,7 @@ Foam::parLagrangianRedistributor::redistributeLagrangianPositions
) const
{
// Load cloud and send particle
passiveParticleCloud lpi(srcMesh_, cloudName, false);
passivePositionParticleCloud lpi(srcMesh_, cloudName, false);
return redistributeLagrangianPositions(lpi);
}
......
......@@ -49,7 +49,7 @@ namespace Foam
class mapDistributePolyMesh;
class mapDistributeBase;
class IOobjectList;
class passiveParticleCloud;
class passivePositionParticleCloud;
/*---------------------------------------------------------------------------*\
Class parLagrangianRedistributor Declaration
......@@ -112,7 +112,7 @@ public:
//- Redistribute and write lagrangian positions
autoPtr<mapDistributeBase> redistributeLagrangianPositions
(
passiveParticleCloud& cloud
passivePositionParticleCloud& cloud
) const;
//- Read, redistribute and write lagrangian positions
......@@ -153,7 +153,7 @@ public:
template<class Container>
static void readLagrangianFields
(
const passiveParticleCloud& cloud,
const passivePositionParticleCloud& cloud,
const IOobjectList& objects,
const HashSet<word>& selectedFields
);
......@@ -163,7 +163,7 @@ public:
void redistributeStoredLagrangianFields
(
const mapDistributeBase& map,
passiveParticleCloud& cloud
passivePositionParticleCloud& cloud
) const;
};
......
......@@ -29,7 +29,7 @@ License
#include "mapDistributePolyMesh.H"
#include "cloud.H"
#include "CompactIOField.H"
#include "passiveParticleCloud.H"
#include "passivePositionParticleCloud.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
......@@ -223,7 +223,7 @@ void Foam::parLagrangianRedistributor::redistributeLagrangianFieldFields
template<class Container>
void Foam::parLagrangianRedistributor::readLagrangianFields
(
const passiveParticleCloud& cloud,
const passivePositionParticleCloud& cloud,
const IOobjectList& objects,
const HashSet<word>& selectedFields
)
......@@ -272,7 +272,7 @@ template<class Container>
void Foam::parLagrangianRedistributor::redistributeStoredLagrangianFields
(
const mapDistributeBase& map,
passiveParticleCloud& cloud
passivePositionParticleCloud& cloud
) const
{
HashTable<Container*> fields
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ 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::passivePositionParticle
Description
Passive particle, transferring in old format (i.e. position instead of
coordinates). Used for e.g. redistributePar.
SourceFiles
passivePositionParticle.H
\*---------------------------------------------------------------------------*/
#ifndef passivePositionParticle_H
#define passivePositionParticle_H
#include "passiveParticle.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class passivePositionParticle Declaration
\*---------------------------------------------------------------------------*/
class passivePositionParticle
:
public passiveParticle
{
// Private member data
//- Cached position
point position_;
public:
// Constructors
//- Construct from Istream in old format
passivePositionParticle
(
const polyMesh& mesh,
Istream& is,
bool readFields,
bool newFormat
)
:
passiveParticle(mesh, is, readFields, newFormat),
position_(position())
{}
//- Construct as copy
passivePositionParticle(const passivePositionParticle& p)
:
passiveParticle(p),
position_(p.position_)
{}
//- Construct and return a clone
virtual autoPtr<particle> clone() const
{
return autoPtr<particle>(new passivePositionParticle(*this));
}
//- Factory class to read-construct particles used for
// parallel transfer
class iNew
{
const polyMesh& mesh_;
public:
iNew(const polyMesh& mesh)
:
mesh_(mesh)
{}
autoPtr<passivePositionParticle> operator()(Istream& is) const
{
return autoPtr<passivePositionParticle>
(
// Read in old format
new passivePositionParticle(mesh_, is, true, false)
);
}
};
// Friend Operators
friend Ostream& operator<<
(
Ostream& os,
const passivePositionParticle& ppi
)
{
// Copy data into old format structure. Exact opposite of
// particleIO.C reading old format.
struct oldParticle
{
vector position;
label celli;
label facei;
scalar stepFraction;
label tetFacei;
label tetPti;
label origProc;
label origId;
} p;
p.position = ppi.position_;
p.celli = ppi.cell();
p.facei = ppi.face();
p.stepFraction = ppi.stepFraction();
p.tetFacei = ppi.tetFace();
p.tetPti = ppi.tetPt();
p.origProc = ppi.origProc();
p.origId = ppi.origId();
if (os.format() == IOstream::ASCII)
{
os << p.position
<< token::SPACE << p.celli
<< token::SPACE << p.facei
<< token::SPACE << p.stepFraction
<< token::SPACE << p.tetFacei
<< token::SPACE << p.tetPti
<< token::SPACE << p.origProc
<< token::SPACE << p.origId;
}
else
{
const std::size_t sizeofFields
(
sizeof(oldParticle) - offsetof(oldParticle, position)
);
os.write
(
reinterpret_cast<const char*>(&p.position),
sizeofFields
);
}
return os;
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ 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 "passivePositionParticleCloud.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTemplateTypeNameAndDebug(Cloud<passivePositionParticle>, 0);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::passivePositionParticleCloud::passivePositionParticleCloud
(
const polyMesh& mesh,
const word& cloudName,
bool readFields
)
:
Cloud<passivePositionParticle>(mesh, cloudName, false)
{
if (readFields)
{
passivePositionParticle::readFields(*this);
}
}
Foam::passivePositionParticleCloud::passivePositionParticleCloud
(
const polyMesh& mesh,
const word& cloudName,
const IDLList<passivePositionParticle>& particles
)
:
Cloud<passivePositionParticle>(mesh, cloudName, particles)
{}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ 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::passivePositionParticleCloud
Description
A Cloud of passive position particles
SourceFiles
passivePositionParticleCloud.C
\*---------------------------------------------------------------------------*/
#ifndef passivePositionParticleCloud_H
#define passivePositionParticleCloud_H
#include "Cloud.H"
#include "passivePositionParticle.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class passivePositionParticleCloud Declaration
\*---------------------------------------------------------------------------*/
class passivePositionParticleCloud
:
public Cloud<passivePositionParticle>
{
// Private Member Functions
//- Disallow default bitwise copy construct
passivePositionParticleCloud(const passivePositionParticleCloud&);
//- Disallow default bitwise assignment
void operator=(const passivePositionParticleCloud&);
public:
// Constructors
//- Construct given mesh
passivePositionParticleCloud
(
const polyMesh&,
const word& cloudName = "defaultCloud",
bool readFields = true
);
//- Construct from mesh, cloud name, and a list of particles
passivePositionParticleCloud
(
const polyMesh& mesh,
const word& cloudName,
const IDLList<passivePositionParticle>& particles
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
......@@ -80,7 +80,7 @@ Usage
#include "parFvFieldReconstructor.H"
#include "parLagrangianRedistributor.H"
#include "unmappedPassiveParticleCloud.H"
#include "unmappedPassivePositionParticleCloud.H"
#include "hexRef8Data.H"
#include "meshRefinement.H"
#include "pointFields.H"
......@@ -1908,7 +1908,7 @@ void readLagrangian
const fvMesh& mesh,
const wordList& cloudNames,
const HashSet<word>& selectedLagrangianFields,
PtrList<unmappedPassiveParticleCloud>& clouds
PtrList<unmappedPassivePositionParticleCloud>& clouds
)
{
(void)mesh.tetBasePtIs();
......@@ -1919,13 +1919,13 @@ void readLagrangian
clouds.set
(
i,
new unmappedPassiveParticleCloud(mesh, cloudNames[i], false)
new unmappedPassivePositionParticleCloud(mesh, cloudNames[i], false)
);
//forAllConstIter
//(
// unmappedPassiveParticleCloud,
// unmappedPassivePositionParticleCloud,
// clouds[i],
// iter
//)
......@@ -2087,7 +2087,7 @@ void redistributeLagrangian
const fvMesh& mesh,
const label nOldCells,
const mapDistributePolyMesh& distMap,
PtrList<unmappedPassiveParticleCloud>& clouds
PtrList<unmappedPassivePositionParticleCloud>& clouds
)
{
if (clouds.size())
......@@ -2958,7 +2958,7 @@ int main(int argc, char *argv[])
);
// Read lagrangian fields and store on cloud (objectRegistry)
PtrList<unmappedPassiveParticleCloud> clouds(cloudNames.size());
PtrList<unmappedPassivePositionParticleCloud> clouds(cloudNames.size());
readLagrangian
(
mesh,
......
......@@ -22,21 +22,21 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::unmappedPassiveParticleCloud
Foam::unmappedPassivePositionParticleCloud
Description
passiveParticleCloud but with autoMap and writing disabled. Only used
for its objectRegistry to store lagrangian fields
passivePositionParticleCloud but with autoMap and writing disabled.
Only used for its objectRegistry to store lagrangian fields
SourceFiles
unmappedPassiveParticleCloud.C