STYLE: consolidate positionsCompat1706 structure (issue #721)

This commit is contained in:
Mark Olesen
2018-02-19 11:57:57 +01:00
parent 3c35c3535e
commit cbbb9753eb
5 changed files with 38 additions and 55 deletions

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) 2017 OpenCFD Ltd. \\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -122,17 +122,7 @@ public:
{ {
// Copy data into old format structure. Exact opposite of // Copy data into old format structure. Exact opposite of
// particleIO.C reading old format. // particleIO.C reading old format.
struct oldParticle particle::positionsCompat1706 p;
{
vector position;
label celli;
label facei;
scalar stepFraction;
label tetFacei;
label tetPti;
label origProc;
label origId;
} p;
p.position = ppi.position_; p.position = ppi.position_;
p.celli = ppi.cell(); p.celli = ppi.cell();
@ -158,7 +148,8 @@ public:
{ {
const std::size_t sizeofFields const std::size_t sizeofFields
( (
sizeof(oldParticle) - offsetof(oldParticle, position) sizeof(particle::positionsCompat1706)
- offsetof(particle::positionsCompat1706, position)
); );
os.write os.write

View File

@ -23,8 +23,6 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "IOPosition.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
template<class CloudType> template<class CloudType>

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-2017 OpenCFD Ltd. \\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -204,20 +204,12 @@ void Foam::injectedParticle::writePosition(Ostream& os) const
} }
else else
{ {
struct oldParticle positionsCompat1706 p;
{
vector position;
label celli;
label facei;
scalar stepFraction;
label tetFacei;
label tetPti;
label origProc;
label origId;
} p;
const size_t s = const size_t s =
offsetof(oldParticle, facei) - offsetof(oldParticle, position); (
offsetof(positionsCompat1706, facei)
- offsetof(positionsCompat1706, position));
p.position = position_; p.position = position_;
p.celli = cell(); p.celli = cell();

View File

@ -126,6 +126,20 @@ public:
}; };
//- Old particle positions content for OpenFOAM-1706 and earlier
struct positionsCompat1706
{
vector position;
label celli;
label facei;
scalar stepFraction;
label tetFacei;
label tetPti;
label origProc;
label origId;
};
private: private:
// Private data // Private data

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 | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -86,17 +86,7 @@ Foam::particle::particle
} }
else else
{ {
struct oldParticle positionsCompat1706 p;
{
vector position;
label celli;
label facei;
scalar stepFraction;
label tetFacei;
label tetPti;
label origProc;
label origId;
} p;
if (is.format() == IOstream::ASCII) if (is.format() == IOstream::ASCII)
{ {
@ -118,15 +108,20 @@ Foam::particle::particle
{ {
// Read whole struct // Read whole struct
const size_t s = const size_t s =
sizeof(oldParticle) - offsetof(oldParticle, position); (
sizeof(positionsCompat1706)
- offsetof(positionsCompat1706, position)
);
is.read(reinterpret_cast<char*>(&p.position), s); is.read(reinterpret_cast<char*>(&p.position), s);
} }
else else
{ {
// Read only position and cell // Read only position and cell
const size_t s = const size_t s =
offsetof(oldParticle, facei) (
- offsetof(oldParticle, position); offsetof(positionsCompat1706, facei)
- offsetof(positionsCompat1706, position)
);
is.read(reinterpret_cast<char*>(&p.position), s); is.read(reinterpret_cast<char*>(&p.position), s);
} }
} }
@ -181,20 +176,13 @@ void Foam::particle::writePosition(Ostream& os) const
} }
else else
{ {
struct oldParticle positionsCompat1706 p;
{
vector position;
label celli;
label facei;
scalar stepFraction;
label tetFacei;
label tetPti;
label origProc;
label origId;
} p;
const size_t s = const size_t s =
offsetof(oldParticle, facei) - offsetof(oldParticle, position); (
offsetof(positionsCompat1706, facei)
- offsetof(positionsCompat1706, position)
);
p.position = position(); p.position = position();
p.celli = celli_; p.celli = celli_;