ENH: Updated extractEulerianParticles and deps after change to barycentric tracking

This commit is contained in:
Andrew Heather
2017-12-22 13:19:41 +00:00
parent e60a77442c
commit 66f473b11c
14 changed files with 140 additions and 39 deletions

View File

@ -314,7 +314,8 @@ void Foam::functionObjects::extractEulerianParticles::collectParticles
tag, tag,
time, time,
d, d,
U U,
false // not looking to set cell owner etc.
); );
cloud_.addParticle(ip); cloud_.addParticle(ip);

View File

@ -76,10 +76,10 @@ Foam::Cloud<ParticleType>::Cloud
: :
cloud(pMesh, cloudName), cloud(pMesh, cloudName),
IDLList<ParticleType>(), IDLList<ParticleType>(),
geometryType_(IOPosition<Cloud<ParticleType>>::geometryType::COORDINATES),
polyMesh_(pMesh), polyMesh_(pMesh),
labels_(), labels_(),
globalPositionsPtr_() globalPositionsPtr_(),
geometryType_(IOPosition<Cloud<ParticleType>>::geometryType::COORDINATES)
{ {
checkPatches(); checkPatches();

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -75,9 +75,6 @@ class Cloud
{ {
// Private data // Private data
//- Geometry type
typename IOPosition<Cloud<ParticleType>>::geometryType geometryType_;
//- Reference to the mesh database //- Reference to the mesh database
const polyMesh& polyMesh_; const polyMesh& polyMesh_;
@ -109,6 +106,12 @@ class Cloud
void writeCloudUniformProperties() const; void writeCloudUniformProperties() const;
protected:
//- Geometry type
typename IOPosition<Cloud<ParticleType>>::geometryType geometryType_;
public: public:
friend class particle; friend class particle;

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -167,10 +167,10 @@ Foam::Cloud<ParticleType>::Cloud
) )
: :
cloud(pMesh, cloudName), cloud(pMesh, cloudName),
geometryType_(IOPosition<Cloud<ParticleType>>::geometryType::COORDINATES),
polyMesh_(pMesh), polyMesh_(pMesh),
labels_(), labels_(),
cellWallFacesPtr_() cellWallFacesPtr_(),
geometryType_(IOPosition<Cloud<ParticleType>>::geometryType::COORDINATES)
{ {
checkPatches(); checkPatches();

View File

@ -38,6 +38,7 @@ namespace Foam
Foam::injectedParticle::injectedParticle(const injectedParticle& p) Foam::injectedParticle::injectedParticle(const injectedParticle& p)
: :
particle(p), particle(p),
position_(p.position_),
tag_(p.tag_), tag_(p.tag_),
soi_(p.soi_), soi_(p.soi_),
d_(p.d_), d_(p.d_),
@ -52,6 +53,7 @@ Foam::injectedParticle::injectedParticle
) )
: :
particle(p, mesh), particle(p, mesh),
position_(p.position_),
tag_(p.tag_), tag_(p.tag_),
soi_(p.soi_), soi_(p.soi_),
d_(p.d_), d_(p.d_),

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd. \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -25,11 +25,18 @@ Class
Foam::injectedParticle Foam::injectedParticle
Description Description
Primarly stores particle properties so that it can be injected at a later
time. Note that this stores its own local position as opposed to the
base particle class barycentric coordinates since the particle is not
(usually) attached to a mesh, and instead used for post-processing.
SourceFiles SourceFiles
injectedParticle.C injectedParticle.C
injectedParticleIO.C injectedParticleIO.C
SeeAlso
Foam::functionObjects::extractEulerianParticles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef injectedParticle_H #ifndef injectedParticle_H
@ -74,6 +81,9 @@ protected:
// Particle properties // Particle properties
//- Position
point position_;
//- Tag //- Tag
label tag_; label tag_;
@ -125,7 +135,8 @@ public:
const label tag, const label tag,
const scalar soi, const scalar soi,
const scalar d, const scalar d,
const vector& U const vector& U,
const bool doLocate = true
); );
//- Construct from Istream //- Construct from Istream
@ -225,6 +236,11 @@ public:
objectRegistry& obr objectRegistry& obr
); );
//- Write the particle position and cell
// Note: This uses the local particle position, and bypasses the
// barycentric description
virtual void writePosition(Ostream&) const;
// Ostream Operator // Ostream Operator

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd. \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -41,6 +41,9 @@ Foam::injectedParticleCloud::injectedParticleCloud
: :
Cloud<injectedParticle>(mesh, cloudName, false) Cloud<injectedParticle>(mesh, cloudName, false)
{ {
geometryType_ =
IOPosition<Cloud<injectedParticle>>::geometryType::POSITIONS;
if (readFields) if (readFields)
{ {
injectedParticle::readFields(*this); injectedParticle::readFields(*this);

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd. \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -33,10 +33,12 @@ inline Foam::injectedParticle::injectedParticle
const label tag, const label tag,
const scalar soi, const scalar soi,
const scalar d, const scalar d,
const vector& U const vector& U,
const bool doLocate
) )
: :
particle(mesh, position, -1), particle(mesh, position, -1, -1, -1, doLocate),
position_(position),
tag_(tag), tag_(tag),
soi_(soi), soi_(soi),
d_(d), d_(d),

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd. \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -38,6 +38,7 @@ Foam::string Foam::injectedParticle::propertyTypes_ =
const std::size_t Foam::injectedParticle::sizeofFields const std::size_t Foam::injectedParticle::sizeofFields
( (
// Note: does not include position_
sizeof(label) + sizeof(scalar) + sizeof(scalar) + sizeof(vector) sizeof(label) + sizeof(scalar) + sizeof(scalar) + sizeof(vector)
); );
@ -52,7 +53,8 @@ Foam::injectedParticle::injectedParticle
bool newFormat bool newFormat
) )
: :
particle(mesh, is, readFields, newFormat), particle(mesh, is, readFields, false), // force to read old positions file
position_(Zero),
tag_(-1), tag_(-1),
soi_(0.0), soi_(0.0),
d_(0.0), d_(0.0),
@ -60,6 +62,11 @@ Foam::injectedParticle::injectedParticle
{ {
if (readFields) if (readFields)
{ {
// After the base particle class has read the fields from file and
// constructed the necessary barcentric co-ordinates we can update the
// particle position on this mesh
position_ = particle::position();
if (is.format() == IOstream::ASCII) if (is.format() == IOstream::ASCII)
{ {
tag_ = readLabel(is); tag_ = readLabel(is);
@ -84,6 +91,8 @@ void Foam::injectedParticle::readFields(Cloud<injectedParticle>& c)
return; return;
} }
// Note: not reading local position_ - defer to base particle class
particle::readFields(c); particle::readFields(c);
IOField<label> tag(c.fieldIOobject("tag", IOobject::MUST_READ)); IOField<label> tag(c.fieldIOobject("tag", IOobject::MUST_READ));
@ -100,7 +109,7 @@ void Foam::injectedParticle::readFields(Cloud<injectedParticle>& c)
label i = 0; label i = 0;
forAllIter(Cloud<injectedParticle>, c, iter) forAllIters(c, iter)
{ {
injectedParticle& p = iter(); injectedParticle& p = iter();
@ -116,8 +125,14 @@ void Foam::injectedParticle::readFields(Cloud<injectedParticle>& c)
void Foam::injectedParticle::writeFields(const Cloud<injectedParticle>& c) void Foam::injectedParticle::writeFields(const Cloud<injectedParticle>& c)
{ {
// Force writing positions instead of coordinates
particle::writeLagrangianCoordinates = false;
particle::writeLagrangianPositions = true;
particle::writeFields(c); particle::writeFields(c);
// Note: not writing local position_ - defer to base particle class
label np = c.size(); label np = c.size();
IOField<label> tag(c.fieldIOobject("tag", IOobject::NO_READ), np); IOField<label> tag(c.fieldIOobject("tag", IOobject::NO_READ), np);
@ -127,7 +142,7 @@ void Foam::injectedParticle::writeFields(const Cloud<injectedParticle>& c)
label i = 0; label i = 0;
forAllConstIter(Cloud<injectedParticle>, c, iter) forAllConstIters(c, iter)
{ {
const injectedParticle& p = iter(); const injectedParticle& p = iter();
@ -152,6 +167,10 @@ void Foam::injectedParticle::writeObjects
objectRegistry& obr objectRegistry& obr
) )
{ {
// Force writing positions instead of coordinates
particle::writeLagrangianCoordinates = false;
particle::writeLagrangianPositions = true;
particle::writeObjects(c, obr); particle::writeObjects(c, obr);
label np = c.size(); label np = c.size();
@ -163,7 +182,7 @@ void Foam::injectedParticle::writeObjects
label i = 0; label i = 0;
forAllConstIter(Cloud<injectedParticle>, c, iter) forAllConstIters(c, iter)
{ {
const injectedParticle& p = iter(); const injectedParticle& p = iter();
@ -177,6 +196,40 @@ void Foam::injectedParticle::writeObjects
} }
void Foam::injectedParticle::writePosition(Ostream& os) const
{
if (os.format() == IOstream::ASCII)
{
os << position_ << token::SPACE << cell();
}
else
{
struct oldParticle
{
vector position;
label celli;
label facei;
scalar stepFraction;
label tetFacei;
label tetPti;
label origProc;
label origId;
} p;
const size_t s =
offsetof(oldParticle, facei) - offsetof(oldParticle, position);
p.position = position_;
p.celli = cell();
os.write(reinterpret_cast<const char*>(&p.position), s);
}
// Check state of Ostream
os.check(FUNCTION_NAME);
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<< Foam::Ostream& Foam::operator<<
@ -185,6 +238,8 @@ Foam::Ostream& Foam::operator<<
const injectedParticle& p const injectedParticle& p
) )
{ {
// Note: not writing local position_ - defer to base particle class
if (os.format() == IOstream::ASCII) if (os.format() == IOstream::ASCII)
{ {
os << static_cast<const particle&>(p) os << static_cast<const particle&>(p)

View File

@ -37,6 +37,10 @@ Foam::label Foam::particle::particleCount_ = 0;
namespace Foam namespace Foam
{ {
defineTypeNameAndDebug(particle, 0); defineTypeNameAndDebug(particle, 0);
bool particle::writeLagrangianCoordinates
(
debug::infoSwitch("writeLagrangianCoordinates", 1)
);
bool particle::writeLagrangianPositions bool particle::writeLagrangianPositions
( (
debug::infoSwitch("writeLagrangianPositions", 0) debug::infoSwitch("writeLagrangianPositions", 0)

View File

@ -87,9 +87,6 @@ class particle
{ {
// Private member data // Private member data
//- Write particle positions file (v1706 format and earlier)
static bool writeLagrangianPositions;
//- Size in bytes of the position data //- Size in bytes of the position data
static const std::size_t sizeofPosition; static const std::size_t sizeofPosition;
@ -348,6 +345,14 @@ public:
//- Cumulative particle counter - used to provide unique ID //- Cumulative particle counter - used to provide unique ID
static label particleCount_; static label particleCount_;
//- Write particle coordinates file (v1712 and later)
//- Default is true
static bool writeLagrangianCoordinates;
//- Write particle positions file (v1706 format and earlier)
//- Default is false
static bool writeLagrangianPositions;
// Constructors // Constructors
@ -685,7 +690,7 @@ public:
void writeCoordinates(Ostream&) const; void writeCoordinates(Ostream&) const;
//- Write the particle position and cell //- Write the particle position and cell
void writePosition(Ostream&) const; virtual void writePosition(Ostream&) const;
// Friend Operators // Friend Operators

View File

@ -72,6 +72,7 @@ void Foam::particle::writeFields(const TrackCloudType& c)
{ {
label np = c.size(); label np = c.size();
if (writeLagrangianCoordinates)
{ {
IOPosition<TrackCloudType> ioP(c); IOPosition<TrackCloudType> ioP(c);
ioP.write(np > 0); ioP.write(np > 0);

View File

@ -27,14 +27,16 @@ copyLagrangianData()
exit 1 exit 1
fi fi
dir=$dir/${latestTime}/lagrangian udir=$dir/${latestTime}/uniform/lagrangian
ldir=$dir/${latestTime}/lagrangian
if [ -d $dir ] if [ -d $dir ]
then then
echo "Copying lagrangian data from $dir to 0 directory" echo "Copying lagrangian data from $ldir to 0 directory"
\cp -r $dir 0 \cp -r $ldir 0
mkdir 0/uniform && \cp -r $udir 0/uniform
else else
echo "Error: unable to find Lagrangian data in case $dir" echo "Error: unable to find Lagrangian data in case $ldir"
exit 1 exit 1
fi fi
} }
@ -46,10 +48,12 @@ copyLagrangianData ${eulerianCase}
runApplication blockMesh runApplication blockMesh
runApplication decomposePar #runApplication decomposePar
runParallel $(getApplication) #runParallel $(getApplication)
runApplication reconstructPar #runApplication reconstructPar
runApplication $(getApplication)
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------

View File

@ -27,14 +27,16 @@ copyLagrangianData()
exit 1 exit 1
fi fi
dir=$dir/${latestTime}/lagrangian udir=$dir/${latestTime}/uniform/lagrangian
ldir=$dir/${latestTime}/lagrangian
if [ -d $dir ] if [ -d $dir ]
then then
echo "Copying lagrangian data from $dir to 0 directory" echo "Copying lagrangian data from $ldir to 0 directory"
\cp -r $dir 0 \cp -r $ldir 0
mkdir 0/uniform && \cp -r $udir 0/uniform
else else
echo "Error: unable to find Lagrangian data in case $dir" echo "Error: unable to find Lagrangian data in case $ldir"
exit 1 exit 1
fi fi
} }
@ -46,10 +48,13 @@ copyLagrangianData ${eulerianCase}
runApplication blockMesh runApplication blockMesh
runApplication decomposePar #runApplication decomposePar
runParallel $(getApplication) #runParallel $(getApplication)
#runApplication reconstructPar
runApplication $(getApplication)
runApplication reconstructPar
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------