mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
cloud rereading
This commit is contained in:
@ -38,7 +38,7 @@ Description
|
|||||||
#include "Time.H"
|
#include "Time.H"
|
||||||
#include "timeSelector.H"
|
#include "timeSelector.H"
|
||||||
#include "OFstream.H"
|
#include "OFstream.H"
|
||||||
#include "passiveParticle.H"
|
#include "passiveParticleCloud.H"
|
||||||
|
|
||||||
using namespace Foam;
|
using namespace Foam;
|
||||||
|
|
||||||
@ -61,7 +61,8 @@ int main(int argc, char *argv[])
|
|||||||
fileName vtkPath(runTime.path()/"VTK");
|
fileName vtkPath(runTime.path()/"VTK");
|
||||||
mkDir(vtkPath);
|
mkDir(vtkPath);
|
||||||
|
|
||||||
Info<< "Scanning times to determine track data" << nl << endl;
|
Info<< "Scanning times to determine track data for cloud " << cloudName
|
||||||
|
<< nl << endl;
|
||||||
|
|
||||||
labelList maxIds(Pstream::nProcs(), -1);
|
labelList maxIds(Pstream::nProcs(), -1);
|
||||||
forAll(timeDirs, timeI)
|
forAll(timeDirs, timeI)
|
||||||
@ -69,35 +70,33 @@ int main(int argc, char *argv[])
|
|||||||
runTime.setTime(timeDirs[timeI], timeI);
|
runTime.setTime(timeDirs[timeI], timeI);
|
||||||
Info<< "Time = " << runTime.timeName() << endl;
|
Info<< "Time = " << runTime.timeName() << endl;
|
||||||
|
|
||||||
IOobject positionsHeader
|
Info<< " Reading particle positions" << endl;
|
||||||
(
|
passiveParticleCloud myCloud(mesh, cloudName);
|
||||||
"positions",
|
Info<< " Read " << returnReduce(myCloud.size(), sumOp<label>())
|
||||||
runTime.timeName(),
|
<< " particles" << endl;
|
||||||
cloud::prefix/cloudName,
|
|
||||||
mesh,
|
|
||||||
IOobject::MUST_READ,
|
|
||||||
IOobject::NO_WRITE,
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
if (positionsHeader.headerOk())
|
forAllConstIter(passiveParticleCloud, myCloud, iter)
|
||||||
{
|
{
|
||||||
Info<< " Reading particle positions" << endl;
|
label origId = iter().origId();
|
||||||
Cloud<passiveParticle> myCloud(mesh, cloudName, false);
|
label origProc = iter().origProc();
|
||||||
|
|
||||||
forAllConstIter(Cloud<passiveParticle>, myCloud, iter)
|
maxIds[origProc] = max(maxIds[origProc], origId);
|
||||||
{
|
|
||||||
label origId = iter().origId();
|
|
||||||
label origProc = iter().origProc();
|
|
||||||
|
|
||||||
maxIds[origProc] = max(maxIds[origProc], origId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Pstream::listCombineGather(maxIds, maxOp<label>());
|
Pstream::listCombineGather(maxIds, maxEqOp<label>());
|
||||||
Pstream::listCombineScatter(maxIds);
|
Pstream::listCombineScatter(maxIds);
|
||||||
|
|
||||||
labelList numIds = maxIds + 1;
|
labelList numIds = maxIds + 1;
|
||||||
|
|
||||||
|
Info<< nl << "Particle statistics:" << endl;
|
||||||
|
forAll(maxIds, procI)
|
||||||
|
{
|
||||||
|
Info<< " Found " << numIds[procI] << " particles originating"
|
||||||
|
<< " from processor " << procI << endl;
|
||||||
|
}
|
||||||
|
Info<< nl << endl;
|
||||||
|
|
||||||
|
|
||||||
// calc starting ids for particles on each processor
|
// calc starting ids for particles on each processor
|
||||||
List<label> startIds(numIds.size(), 0);
|
List<label> startIds(numIds.size(), 0);
|
||||||
for (label i = 0; i < numIds.size()-1; i++)
|
for (label i = 0; i < numIds.size()-1; i++)
|
||||||
@ -106,98 +105,87 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
label nParticle = startIds[startIds.size()-1] + numIds[startIds.size()-1];
|
label nParticle = startIds[startIds.size()-1] + numIds[startIds.size()-1];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// number of tracks to generate
|
// number of tracks to generate
|
||||||
label nTracks = nParticle/sampleFrequency;
|
label nTracks = nParticle/sampleFrequency;
|
||||||
|
|
||||||
// storage for all particle tracks
|
// storage for all particle tracks
|
||||||
List<DynamicList<vector> > allTracks(nTracks);
|
List<DynamicList<vector> > allTracks(nTracks);
|
||||||
|
|
||||||
Info<< "\nGenerating " << nTracks << " particle tracks" << nl << endl;
|
Info<< "\nGenerating " << nTracks << " particle tracks for cloud "
|
||||||
|
<< cloudName << nl << endl;
|
||||||
|
|
||||||
forAll(timeDirs, timeI)
|
forAll(timeDirs, timeI)
|
||||||
{
|
{
|
||||||
runTime.setTime(timeDirs[timeI], timeI);
|
runTime.setTime(timeDirs[timeI], timeI);
|
||||||
Info<< "Time = " << runTime.timeName() << endl;
|
Info<< "Time = " << runTime.timeName() << endl;
|
||||||
|
|
||||||
IOobject positionsHeader
|
List<pointField> allPositions(Pstream::nProcs());
|
||||||
|
List<labelField> allOrigIds(Pstream::nProcs());
|
||||||
|
List<labelField> allOrigProcs(Pstream::nProcs());
|
||||||
|
|
||||||
|
// Read particles. Will be size 0 if no particles.
|
||||||
|
Info<< " Reading particle positions" << endl;
|
||||||
|
passiveParticleCloud myCloud(mesh, cloudName);
|
||||||
|
|
||||||
|
// collect the track data on all processors that have positions
|
||||||
|
allPositions[Pstream::myProcNo()].setSize
|
||||||
(
|
(
|
||||||
"positions",
|
myCloud.size(),
|
||||||
runTime.timeName(),
|
point::zero
|
||||||
cloud::prefix/cloudName,
|
|
||||||
mesh,
|
|
||||||
IOobject::MUST_READ,
|
|
||||||
IOobject::NO_WRITE,
|
|
||||||
false
|
|
||||||
);
|
);
|
||||||
|
allOrigIds[Pstream::myProcNo()].setSize(myCloud.size(), 0);
|
||||||
|
allOrigProcs[Pstream::myProcNo()].setSize(myCloud.size(), 0);
|
||||||
|
|
||||||
if (positionsHeader.headerOk())
|
label i = 0;
|
||||||
|
forAllConstIter(passiveParticleCloud, myCloud, iter)
|
||||||
{
|
{
|
||||||
Info<< " Reading particle positions" << endl;
|
allPositions[Pstream::myProcNo()][i] = iter().position();
|
||||||
Cloud<passiveParticle> myCloud(mesh, cloudName, false);
|
allOrigIds[Pstream::myProcNo()][i] = iter().origId();
|
||||||
|
allOrigProcs[Pstream::myProcNo()][i] = iter().origProc();
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
// collect the track data on the master processor
|
// collect the track data on the master processor
|
||||||
List<pointField> allPositions(Pstream::nProcs());
|
Pstream::gatherList(allPositions);
|
||||||
allPositions[Pstream::myProcNo()].setSize
|
Pstream::gatherList(allOrigIds);
|
||||||
(
|
Pstream::gatherList(allOrigProcs);
|
||||||
myCloud.size(),
|
|
||||||
point::zero
|
|
||||||
);
|
|
||||||
|
|
||||||
List<labelField> allOrigIds(Pstream::nProcs());
|
Info<< " Constructing tracks" << nl << endl;
|
||||||
allOrigIds[Pstream::myProcNo()].setSize(myCloud.size(), 0);
|
if (Pstream::master())
|
||||||
|
{
|
||||||
List<labelField> allOrigProcs(Pstream::nProcs());
|
forAll(allPositions, procI)
|
||||||
allOrigProcs[Pstream::myProcNo()].setSize(myCloud.size(), 0);
|
|
||||||
|
|
||||||
label i = 0;
|
|
||||||
forAllConstIter(Cloud<passiveParticle>, myCloud, iter)
|
|
||||||
{
|
{
|
||||||
allPositions[Pstream::myProcNo()][i] = iter().position();
|
forAll(allPositions[procI], i)
|
||||||
allOrigIds[Pstream::myProcNo()][i] = iter().origId();
|
|
||||||
allOrigProcs[Pstream::myProcNo()][i] = iter().origProc();
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
Pstream::gatherList(allPositions);
|
|
||||||
Pstream::gatherList(allOrigIds);
|
|
||||||
Pstream::gatherList(allOrigProcs);
|
|
||||||
|
|
||||||
Info<< " Constructing tracks" << nl << endl;
|
|
||||||
if (Pstream::master())
|
|
||||||
{
|
|
||||||
forAll(allPositions, procI)
|
|
||||||
{
|
{
|
||||||
forAll(allPositions[procI], i)
|
label globalId =
|
||||||
{
|
startIds[allOrigProcs[procI][i]]
|
||||||
label globalId =
|
+ allOrigIds[procI][i];
|
||||||
startIds[allOrigProcs[procI][i]]
|
|
||||||
+ allOrigIds[procI][i];
|
|
||||||
|
|
||||||
if (globalId % sampleFrequency == 0)
|
if (globalId % sampleFrequency == 0)
|
||||||
|
{
|
||||||
|
label trackId = globalId/sampleFrequency;
|
||||||
|
if (allTracks[trackId].size() < maxPositions)
|
||||||
{
|
{
|
||||||
label trackId = globalId/sampleFrequency;
|
allTracks[trackId].append
|
||||||
if (allTracks[trackId].size() < maxPositions)
|
(
|
||||||
{
|
allPositions[procI][i]
|
||||||
allTracks[trackId].append
|
);
|
||||||
(
|
|
||||||
allPositions[procI][i]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
Info<< " No particles read" << nl << endl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Pstream::master())
|
if (Pstream::master())
|
||||||
{
|
{
|
||||||
Info<< "\nWriting particle tracks" << nl << endl;
|
|
||||||
|
|
||||||
OFstream vtkTracks(vtkPath/"particleTracks.vtk");
|
OFstream vtkTracks(vtkPath/"particleTracks.vtk");
|
||||||
|
|
||||||
|
Info<< "\nWriting particle tracks to " << vtkTracks.name()
|
||||||
|
<< nl << endl;
|
||||||
|
|
||||||
// Total number of points in tracks + 1 per track
|
// Total number of points in tracks + 1 per track
|
||||||
label nPoints = 0;
|
label nPoints = 0;
|
||||||
forAll(allTracks, trackI)
|
forAll(allTracks, trackI)
|
||||||
|
|||||||
@ -117,6 +117,7 @@ void Foam::Particle<ParticleType>::readFields
|
|||||||
}
|
}
|
||||||
|
|
||||||
IOobject procIO(c.fieldIOobject("origProcId", IOobject::MUST_READ));
|
IOobject procIO(c.fieldIOobject("origProcId", IOobject::MUST_READ));
|
||||||
|
|
||||||
if (procIO.headerOk())
|
if (procIO.headerOk())
|
||||||
{
|
{
|
||||||
IOField<label> origProcId(procIO);
|
IOField<label> origProcId(procIO);
|
||||||
|
|||||||
@ -49,7 +49,9 @@ Foam::indexedParticleCloud::indexedParticleCloud
|
|||||||
)
|
)
|
||||||
:
|
:
|
||||||
Cloud<indexedParticle>(mesh, cloudName, false)
|
Cloud<indexedParticle>(mesh, cloudName, false)
|
||||||
{}
|
{
|
||||||
|
indexedParticle::readFields(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|||||||
@ -47,7 +47,9 @@ Foam::passiveParticleCloud::passiveParticleCloud
|
|||||||
)
|
)
|
||||||
:
|
:
|
||||||
Cloud<passiveParticle>(mesh, cloudName, false)
|
Cloud<passiveParticle>(mesh, cloudName, false)
|
||||||
{}
|
{
|
||||||
|
readFields();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|||||||
Reference in New Issue
Block a user