Particle backwards compatibility

This commit is contained in:
mattijs
2009-07-07 15:47:05 +01:00
parent f3b6566f32
commit 4e2d5a9071
30 changed files with 477 additions and 126 deletions

View File

@ -56,7 +56,7 @@ Foam::trackedParticle::trackedParticle
bool readFields
)
:
ExactParticle<trackedParticle>(c, is)
ExactParticle<trackedParticle>(c, is, readFields)
{
if (readFields)
{

View File

@ -42,15 +42,12 @@ Foam::Cloud<ParticleType>::Cloud
)
:
cloud(pMesh),
IDLList<ParticleType>(particles),
IDLList<ParticleType>(),
polyMesh_(pMesh),
allFaces_(pMesh.faces()),
points_(pMesh.points()),
cellFaces_(pMesh.cells()),
allFaceCentres_(pMesh.faceCentres()),
owner_(pMesh.faceOwner()),
neighbour_(pMesh.faceNeighbour())
{}
particleCount_(0)
{
IDLList<ParticleType>::operator=(particles);
}
template<class ParticleType>
@ -62,19 +59,31 @@ Foam::Cloud<ParticleType>::Cloud
)
:
cloud(pMesh, cloudName),
IDLList<ParticleType>(particles),
IDLList<ParticleType>(),
polyMesh_(pMesh),
allFaces_(pMesh.faces()),
points_(pMesh.points()),
cellFaces_(pMesh.cells()),
allFaceCentres_(pMesh.faceCentres()),
owner_(pMesh.faceOwner()),
neighbour_(pMesh.faceNeighbour())
{}
particleCount_(0)
{
IDLList<ParticleType>::operator=(particles);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class ParticleType>
Foam::label Foam::Cloud<ParticleType>::getNewParticleID() const
{
label id = particleCount_++;
if (id == labelMax)
{
WarningIn("Cloud<ParticleType>::getNewParticleID() const")
<< "Particle counter has overflowed. This might cause problems"
<< " when reconstructing particle tracks." << endl;
}
return id;
}
template<class ParticleType>
void Foam::Cloud<ParticleType>::addParticle(ParticleType* pPtr)
{

View File

@ -50,6 +50,9 @@ namespace Foam
template<class ParticleType>
class Cloud;
template<class ParticleType>
class IOPosition;
template<class ParticleType>
Ostream& operator<<
(
@ -71,12 +74,9 @@ class Cloud
// Private data
const polyMesh& polyMesh_;
const faceList& allFaces_;
const vectorField& points_;
const cellList& cellFaces_;
const vectorField& allFaceCentres_;
const unallocLabelList& owner_;
const unallocLabelList& neighbour_;
//- Overall count of particles ever created. Never decreases.
mutable label particleCount_;
//- Temporary storage for addressing. Used in findFaces.
mutable DynamicList<label> labels_;
@ -92,6 +92,8 @@ public:
template<class ParticleT>
friend class Particle;
template<class ParticleT>
friend class IOPosition;
typedef ParticleType particleType;
@ -218,6 +220,9 @@ public:
return IDLList<ParticleType>::clear();
};
//- Get unique particle creation id
label getNewParticleID() const;
//- Transfer particle to cloud
void addParticle(ParticleType* pPtr);
@ -251,13 +256,15 @@ public:
const IOField<DataType>& data
) const;
//- Read the field data for the cloud of particles
void readFields();
//- Read the field data for the cloud of particles. Dummy at
// this level.
virtual void readFields();
// Write
//- Write the field data for the cloud of particles
//- Write the field data for the cloud of particles Dummy at
// this level.
virtual void writeFields() const;
//- Write using given format, version and compression.

View File

@ -67,12 +67,7 @@ Foam::Cloud<ParticleType>::Cloud
:
cloud(pMesh),
polyMesh_(pMesh),
allFaces_(pMesh.faces()),
points_(pMesh.points()),
cellFaces_(pMesh.cells()),
allFaceCentres_(pMesh.faceCentres()),
owner_(pMesh.faceOwner()),
neighbour_(pMesh.faceNeighbour())
particleCount_(0)
{
initCloud(checkClass);
}
@ -88,12 +83,7 @@ Foam::Cloud<ParticleType>::Cloud
:
cloud(pMesh, cloudName),
polyMesh_(pMesh),
allFaces_(pMesh.faces()),
points_(pMesh.points()),
cellFaces_(pMesh.cells()),
allFaceCentres_(pMesh.faceCentres()),
owner_(pMesh.faceOwner()),
neighbour_(pMesh.faceNeighbour())
particleCount_(0)
{
initCloud(checkClass);
}

View File

@ -34,6 +34,7 @@ Foam::word Foam::IOPosition<ParticleType>::particlePropertiesName
"particleProperties"
);
// * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * * //
template<class ParticleType>
@ -58,7 +59,7 @@ void Foam::IOPosition<ParticleType>::readParticleProperties()
if (propsDict.found(procName))
{
propsDict.subDict(procName).lookup("particleCount")
>> Particle<ParticleType>::particleCount;
>> cloud_.particleCount_;
}
}
}
@ -83,11 +84,7 @@ void Foam::IOPosition<ParticleType>::writeParticleProperties() const
word procName("processor" + Foam::name(Pstream::myProcNo()));
propsDict.add(procName, dictionary());
propsDict.subDict(procName).add
(
"particleCount",
Particle<ParticleType>::particleCount
);
propsDict.subDict(procName).add("particleCount", cloud_.particleCount_);
propsDict.regIOobject::write();
}
@ -135,13 +132,20 @@ bool Foam::IOPosition<ParticleType>::write() const
template<class ParticleType>
bool Foam::IOPosition<ParticleType>::writeData(Ostream& os) const
{
// Write global cloud data
writeParticleProperties();
os<< cloud_.size() << nl << token::BEGIN_LIST << nl;
forAllConstIter(typename Cloud<ParticleType>, cloud_, iter)
{
os<< static_cast<const Particle<ParticleType>&>(iter()) << nl;
// Prevent writing additional fields
static_cast<const Particle<ParticleType>&>(iter()).write
(
os,
false
);
os << nl;
}
os<< token::END_LIST << endl;
@ -157,6 +161,7 @@ void Foam::IOPosition<ParticleType>::readData
bool checkClass
)
{
// Read global cloud data. Resets count on cloud.
readParticleProperties();
Istream& is = readStream(checkClass ? typeName : "");
@ -172,6 +177,7 @@ void Foam::IOPosition<ParticleType>::readData
for (label i=0; i<s; i++)
{
// Do not read any fields, position only
c.append(new ParticleType(c, is, false));
}
@ -202,6 +208,7 @@ void Foam::IOPosition<ParticleType>::readData
)
{
is.putBack(lastToken);
// Do not read any fields, position only
c.append(new ParticleType(c, is, false));
is >> lastToken;
}

View File

@ -26,7 +26,7 @@ Class
Foam::IOPosition
Description
Helper IO class to write particle positions
Helper IO class to read and write particle positions
SourceFiles
IOPosition.C
@ -72,7 +72,7 @@ public:
// Static data
//- Runtime type name information
//- Runtime type name information. Use cloud type.
virtual const word& type() const
{
return cloud_.type();
@ -90,11 +90,11 @@ public:
// Member functions
void readData(Cloud<ParticleType>& c, bool checkClass);
virtual void readData(Cloud<ParticleType>& c, bool checkClass);
bool write() const;
virtual bool write() const;
bool writeData(Ostream& os) const;
virtual bool writeData(Ostream& os) const;
};

View File

@ -33,12 +33,6 @@ License
#include "wallPolyPatch.H"
#include "transform.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
template<class ParticleType>
Foam::label Foam::Particle<ParticleType>::particleCount = 0;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class ParticleType>
@ -184,7 +178,7 @@ Foam::Particle<ParticleType>::Particle
facei_(-1),
stepFraction_(0.0),
origProc_(Pstream::myProcNo()),
origId_(particleCount++)
origId_(cloud_.getNewParticleID())
{}
@ -313,13 +307,13 @@ Foam::scalar Foam::Particle<ParticleType>::trackToFace
// change cell
if (internalFace) // Internal face
{
if (celli_ == cloud_.owner_[facei_])
if (celli_ == mesh.faceOwner()[facei_])
{
celli_ = cloud_.neighbour_[facei_];
celli_ = mesh.faceNeighbour()[facei_];
}
else if (celli_ == cloud_.neighbour_[facei_])
else if (celli_ == mesh.faceNeighbour()[facei_])
{
celli_ = cloud_.owner_[facei_];
celli_ = mesh.faceOwner()[facei_];
}
else
{

View File

@ -279,9 +279,6 @@ public:
//- String representation of properties
static string propHeader;
//- Cumulative particle count used for particle id
static label particleCount;
// Constructors
@ -330,7 +327,15 @@ public:
autoPtr<ParticleType> operator()(Istream& is) const
{
return autoPtr<ParticleType>(new ParticleType(cloud_, is));
return autoPtr<ParticleType>
(
new ParticleType
(
cloud_,
is,
true
)
);
}
};
@ -454,9 +459,14 @@ public:
// I-O
//- Read the fields associated with the owner cloud
static void readFields(Cloud<ParticleType>& c);
//- Write the fields associated with the owner cloud
static void writeFields(const Cloud<ParticleType>& c);
//- Write the particle data
void write(Ostream& os, bool writeFields) const;
// Ostream Operator

View File

@ -50,23 +50,49 @@ Foam::Particle<ParticleType>::Particle
origProc_(Pstream::myProcNo()),
origId_(-1)
{
// readFields : read additional data. Should be consistent with writeFields.
if (is.format() == IOstream::ASCII)
{
is >> position_ >> celli_ >> origProc_ >> origId_;
is >> position_ >> celli_;
if (readFields)
{
is >> origProc_ >> origId_;
}
else
{
origId_ = cloud_.getNewParticleID();
}
}
else
{
// In binary read all particle data - needed for parallel transfer
is.read
(
reinterpret_cast<char*>(&position_),
sizeof(position_)
+ sizeof(celli_)
+ sizeof(facei_)
+ sizeof(stepFraction_)
+ sizeof(origProc_)
+ sizeof(origId_)
);
if (readFields)
{
is.read
(
reinterpret_cast<char*>(&position_),
sizeof(position_)
+ sizeof(celli_)
+ sizeof(facei_)
+ sizeof(stepFraction_)
+ sizeof(origProc_)
+ sizeof(origId_)
);
}
else
{
is.read
(
reinterpret_cast<char*>(&position_),
sizeof(position_)
+ sizeof(celli_)
+ sizeof(facei_)
+ sizeof(stepFraction_)
);
origId_ = cloud_.getNewParticleID();
}
}
if (celli_ == -1)
@ -79,6 +105,38 @@ Foam::Particle<ParticleType>::Particle
}
template<class ParticleType>
void Foam::Particle<ParticleType>::readFields
(
Cloud<ParticleType>& c
)
{
if (!c.size())
{
return;
}
IOobject procIO(c.fieldIOobject("origProcId", IOobject::MUST_READ));
if (procIO.headerOk())
{
IOField<label> origProcId(procIO);
c.checkFieldIOobject(c, origProcId);
IOField<label> origId(c.fieldIOobject("origId", IOobject::MUST_READ));
c.checkFieldIOobject(c, origId);
label i = 0;
forAllIter(typename Cloud<ParticleType>, c, iter)
{
ParticleType& p = iter();
p.origProc_ = origProcId[i];
p.origId_ = origId[i];
i++;
}
}
}
template<class ParticleType>
void Foam::Particle<ParticleType>::writeFields
(
@ -88,36 +146,91 @@ void Foam::Particle<ParticleType>::writeFields
// Write the cloud position file
IOPosition<ParticleType> ioP(c);
ioP.write();
label np = c.size();
IOField<label> origProc
(
c.fieldIOobject
(
"origProcId",
IOobject::NO_READ
),
np
);
IOField<label> origId(c.fieldIOobject("origId", IOobject::NO_READ), np);
label i = 0;
forAllConstIter(typename Cloud<ParticleType>, c, iter)
{
origProc[i] = iter().origProc_;
origId[i] = iter().origId_;
i++;
}
origProc.write();
origId.write();
}
template<class ParticleType>
void Foam::Particle<ParticleType>::write(Ostream& os, bool writeFields) const
{
if (os.format() == IOstream::ASCII)
{
if (writeFields)
{
// Write the additional entries
os << position_
<< token::SPACE << celli_
<< token::SPACE << origProc_
<< token::SPACE << origId_;
}
else
{
os << position_
<< token::SPACE << celli_;
}
}
else
{
// In binary write both celli_ and facei_, needed for parallel transfer
if (writeFields)
{
os.write
(
reinterpret_cast<const char*>(&position_),
sizeof(position_)
+ sizeof(celli_)
+ sizeof(facei_)
+ sizeof(stepFraction_)
+ sizeof(origProc_)
+ sizeof(origId_)
);
}
else
{
os.write
(
reinterpret_cast<const char*>(&position_),
sizeof(position_)
+ sizeof(celli_)
+ sizeof(facei_)
+ sizeof(stepFraction_)
);
}
}
// Check state of Ostream
os.check("Particle<ParticleType>::write(Ostream& os, bool) const");
}
template<class ParticleType>
Foam::Ostream& Foam::operator<<(Ostream& os, const Particle<ParticleType>& p)
{
if (os.format() == IOstream::ASCII)
{
os << p.position_
<< token::SPACE << p.celli_
<< token::SPACE << p.origProc_
<< token::SPACE << p.origId_;
}
else
{
// In binary write both celli_ and facei_, needed for parallel transfer
os.write
(
reinterpret_cast<const char*>(&p.position_),
sizeof(p.position_)
+ sizeof(p.celli_)
+ sizeof(p.facei_)
+ sizeof(p.stepFraction_)
+ sizeof(p.origProc_)
+ sizeof(p.origId_)
);
}
// Check state of Ostream
os.check("Ostream& operator<<(Ostream&, const Particle<ParticleType>&)");
// Write all data
p.write(os, true);
return os;
}

View File

@ -84,7 +84,7 @@ public:
bool readFields = true
)
:
Particle<indexedParticle>(c, is)
Particle<indexedParticle>(c, is, readFields)
{}
//- Construct as a copy

View File

@ -22,12 +22,9 @@ License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#include "indexedParticle.H"
#include "Cloud.H"
#include "indexedParticleCloud.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -43,4 +40,23 @@ defineTemplateTypeNameAndDebug(Cloud<indexedParticle>, 0);
} // End namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::indexedParticleCloud::indexedParticleCloud
(
const polyMesh& mesh,
const word& cloudName
)
:
Cloud<indexedParticle>(mesh, cloudName, false)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::indexedParticleCloud::writeFields() const
{
indexedParticle::writeFields(*this);
}
// ************************************************************************* //

View File

@ -0,0 +1,91 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::indexedParticleCloud
Description
A Cloud of particles carrying an additional index.
SourceFiles
indexedParticleCloud.C
\*---------------------------------------------------------------------------*/
#ifndef indexedParticleCloud_H
#define indexedParticleCloud_H
#include "Cloud.H"
#include "indexedParticle.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class indexedParticleCloud Declaration
\*---------------------------------------------------------------------------*/
class indexedParticleCloud
:
public Cloud<indexedParticle>
{
// Private Member Functions
//- Disallow default bitwise copy construct
indexedParticleCloud(const indexedParticleCloud&);
//- Disallow default bitwise assignment
void operator=(const indexedParticleCloud&);
public:
// Constructors
//- Construct given mesh
indexedParticleCloud
(
const polyMesh&,
const word& cloudName = "defaultCloud"
);
// Member Functions
//- Write fields
virtual void writeFields() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -28,9 +28,6 @@ Class
Description
SourceFiles
passiveParticleI.H
passiveParticle.C
passiveParticleIO.C
\*---------------------------------------------------------------------------*/
@ -78,7 +75,7 @@ public:
bool readFields = true
)
:
Particle<passiveParticle>(c, is)
Particle<passiveParticle>(c, is, readFields)
{}
//- Construct as copy

View File

@ -22,12 +22,9 @@ License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#include "passiveParticle.H"
#include "Cloud.H"
#include "passiveParticleCloud.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -39,8 +36,32 @@ namespace Foam
defineParticleTypeNameAndDebug(passiveParticle, 0);
defineTemplateTypeNameAndDebug(Cloud<passiveParticle>, 0);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
};
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::passiveParticleCloud::passiveParticleCloud
(
const polyMesh& mesh,
const word& cloudName
)
:
Cloud<passiveParticle>(mesh, cloudName, false)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::passiveParticleCloud::readFields()
{
passiveParticle::readFields(*this);
}
void Foam::passiveParticleCloud::writeFields() const
{
passiveParticle::writeFields(*this);
}
} // End namespace Foam
// ************************************************************************* //

View File

@ -0,0 +1,94 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::passiveParticleCloud
Description
A Cloud of passive particles
SourceFiles
passiveParticleCloud.C
\*---------------------------------------------------------------------------*/
#ifndef passiveParticleCloud_H
#define passiveParticleCloud_H
#include "Cloud.H"
#include "passiveParticle.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class passiveParticleCloud Declaration
\*---------------------------------------------------------------------------*/
class passiveParticleCloud
:
public Cloud<passiveParticle>
{
// Private Member Functions
//- Disallow default bitwise copy construct
passiveParticleCloud(const passiveParticleCloud&);
//- Disallow default bitwise assignment
void operator=(const passiveParticleCloud&);
public:
// Constructors
//- Construct given mesh
passiveParticleCloud
(
const polyMesh&,
const word& cloudName = "defaultCloud"
);
// Member Functions
//- Read fields
virtual void readFields();
//- Write fields
virtual void writeFields() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -87,7 +87,7 @@ public:
// Member Functions
//- Write fields
void writeFields() const;
virtual void writeFields() const;
};

0
src/lagrangian/coalCombustion/Make/files Executable file → Normal file
View File

0
src/lagrangian/coalCombustion/Make/options Executable file → Normal file
View File

View File

@ -36,7 +36,7 @@ Foam::parcel::parcel
bool readFields
)
:
Particle<parcel>(cloud, is),
Particle<parcel>(cloud, is, readFields),
liquidComponents_
(

View File

@ -345,7 +345,7 @@ public:
// I/O
//- Write fields
void writeFields() const;
virtual void writeFields() const;
};

View File

@ -91,7 +91,7 @@ public:
// Member functions
//- Write fields
void writeFields() const;
virtual void writeFields() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -59,6 +59,7 @@ submodels/addOns/radiation/scatter/cloudScatter/cloudScatter.C
/* data entries */
submodels/IO/DataEntry/makeDataEntries.C
submodels/IO/DataEntry/polynomial/polynomial.C
submodels/IO/DataEntry/polynomial/polynomialIO.C
/* integration schemes */

View File

@ -92,7 +92,7 @@ public:
// Member Functions
//- Write fields
void writeFields() const;
virtual void writeFields() const;
};

View File

@ -92,7 +92,7 @@ public:
// Member Functions
//- Write fields
void writeFields() const;
virtual void writeFields() const;
};

View File

@ -87,7 +87,7 @@ public:
// Member functions
//- Write fields
void writeFields() const;
virtual void writeFields() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -90,7 +90,7 @@ public:
// Member Functions
//- Write fields
void writeFields() const;
virtual void writeFields() const;
};

View File

@ -233,7 +233,8 @@ void Foam::InjectionModel<CloudType>::postInjectCheck(const label parcelsAdded)
{
if (parcelsAdded > 0)
{
Pout<< "\n--> Cloud: " << owner_.name() << nl
Pout<< nl
<< "--> Cloud: " << owner_.name() << nl
<< " Added " << parcelsAdded
<< " new parcels" << nl << endl;
}

0
src/lagrangian/molecularDynamics/molecule/Make/files Executable file → Normal file
View File

0
src/lagrangian/molecularDynamics/molecule/Make/options Executable file → Normal file
View File

View File

@ -108,10 +108,10 @@ public:
void move(const dimensionedVector& g);
// I-O
// Write
//- Write fields
void writeFields() const;
virtual void writeFields() const;
};