From fef0206bdb4e1166dc134469c3e09be788a59d0c Mon Sep 17 00:00:00 2001 From: Will Bainbridge Date: Wed, 14 Sep 2022 16:30:38 +0100 Subject: [PATCH] IOList, GlobalIOList, CompactIOList: Templated on container type This reduces duplication and inconsistency between the List, Field, Map, and PtrList variants. It also allows for future extension to other container types such as DynamicList. --- .../manipulation/createPatch/createPatch.C | 6 - .../decomposePar/lagrangianFieldDecomposer.H | 11 +- ...lagrangianFieldDecomposerDecomposeFields.C | 21 +- .../reconstructPar/reconstructLagrangian.H | 2 +- .../reconstructLagrangianFields.C | 10 +- .../graphics/PVReaders/vtkPVFoam/vtkPVFoam.H | 3 - .../mapFields/MapLagrangianFields.H | 10 +- .../mapFieldsPar/MapLagrangianFields.H | 10 +- src/OpenFOAM/Make/files | 4 - .../IOobjects/CompactIOField/CompactIOField.C | 340 ------------- .../IOobjects/CompactIOField/CompactIOField.H | 88 +--- .../IOobjects/CompactIOList/CompactIOList.C | 456 ++++++++++++++---- .../IOobjects/CompactIOList/CompactIOList.H | 256 ++++++++-- .../IOobjects/CompactIOList/ListCompactIO.C | 262 ---------- .../IOobjects/CompactIOList/ListCompactIO.H | 173 ------- .../IOobjects/GlobalIOField/GlobalIOField.C | 170 ------- .../IOobjects/GlobalIOField/GlobalIOField.H | 66 +-- .../IOobjects/GlobalIOField/GlobalIOFields.C | 45 -- .../IOobjects/GlobalIOField/GlobalIOFields.H | 74 --- .../db/IOobjects/GlobalIOList/GlobalIOList.C | 214 +++++--- .../db/IOobjects/GlobalIOList/GlobalIOList.H | 85 +++- .../db/IOobjects/GlobalIOList/GlobalIOLists.C | 45 -- .../db/IOobjects/GlobalIOList/GlobalIOLists.H | 93 ---- src/OpenFOAM/db/IOobjects/IOField/IOField.C | 222 +-------- src/OpenFOAM/db/IOobjects/IOField/IOField.H | 48 +- src/OpenFOAM/db/IOobjects/IOList/IOList.C | 261 ++++++++-- src/OpenFOAM/db/IOobjects/IOList/IOList.H | 117 +++-- src/OpenFOAM/db/IOobjects/IOMap/IOMap.C | 184 ------- src/OpenFOAM/db/IOobjects/IOMap/IOMap.H | 69 +-- .../db/IOobjects/IOPtrList/IOPtrList.C | 143 +----- .../db/IOobjects/IOPtrList/IOPtrList.H | 48 +- .../diagTensorField/diagTensorFieldIOField.H | 5 +- .../Fields/labelField/labelFieldIOField.H | 4 +- .../Fields/scalarField/scalarFieldIOField.H | 4 +- .../fields/Fields/scalarField/scalarIOField.C | 8 +- .../fields/Fields/scalarField/scalarIOField.H | 4 +- .../sphericalTensorFieldIOField.H | 6 +- .../symmTensorField/symmTensorFieldIOField.H | 5 +- .../Fields/tensorField/tensorFieldIOField.H | 4 +- .../vector2DField/vector2DFieldIOField.H | 4 +- .../Fields/vectorField/vectorFieldIOField.H | 4 +- .../fields/Fields/vectorField/vectorIOField.C | 8 +- .../fields/Fields/vectorField/vectorIOField.H | 4 +- .../meshes/meshShapes/cell/cellIOList.H | 4 +- .../meshes/meshShapes/edge/edgeIOList.H | 4 +- .../meshes/meshShapes/face/faceIOList.H | 4 +- .../Scalar/lists/scalarListIOList.H | 4 +- .../Vector/lists/vectorListIOList.H | 4 +- .../primitives/ints/lists/labelListIOList.H | 4 +- .../primitives/strings/word/wordIOList.C | 3 +- .../primitives/strings/word/wordIOList.H | 4 +- src/conversion/Make/files | 1 + .../meshTables/dictionaryIOMap.C} | 17 +- src/lagrangian/basic/Cloud/Cloud.H | 2 +- src/lagrangian/basic/Cloud/CloudIO.C | 2 +- .../parcel/parcelCloudList/parcelCloudList.C | 2 +- 56 files changed, 1266 insertions(+), 2385 deletions(-) delete mode 100644 src/OpenFOAM/db/IOobjects/CompactIOField/CompactIOField.C delete mode 100644 src/OpenFOAM/db/IOobjects/CompactIOList/ListCompactIO.C delete mode 100644 src/OpenFOAM/db/IOobjects/CompactIOList/ListCompactIO.H delete mode 100644 src/OpenFOAM/db/IOobjects/GlobalIOField/GlobalIOField.C delete mode 100644 src/OpenFOAM/db/IOobjects/GlobalIOField/GlobalIOFields.C delete mode 100644 src/OpenFOAM/db/IOobjects/GlobalIOField/GlobalIOFields.H delete mode 100644 src/OpenFOAM/db/IOobjects/GlobalIOList/GlobalIOLists.C delete mode 100644 src/OpenFOAM/db/IOobjects/GlobalIOList/GlobalIOLists.H delete mode 100644 src/OpenFOAM/db/IOobjects/IOMap/IOMap.C rename src/{OpenFOAM/db/IOobjects/IOMap/IOMapName.C => conversion/meshTables/dictionaryIOMap.C} (79%) diff --git a/applications/utilities/mesh/manipulation/createPatch/createPatch.C b/applications/utilities/mesh/manipulation/createPatch/createPatch.C index 0e9f979b24..e1d0442c8f 100644 --- a/applications/utilities/mesh/manipulation/createPatch/createPatch.C +++ b/applications/utilities/mesh/manipulation/createPatch/createPatch.C @@ -45,7 +45,6 @@ Description #include "OFstream.H" #include "meshTools.H" #include "faceSet.H" -#include "IOPtrList.H" #include "polyTopoChange.H" #include "polyModifyFace.H" #include "wordReList.H" @@ -55,11 +54,6 @@ using namespace Foam; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -namespace Foam -{ - defineTemplateTypeNameAndDebug(IOPtrList, 0); -} - void changePatchID ( const polyMesh& mesh, diff --git a/applications/utilities/parallelProcessing/decomposePar/lagrangianFieldDecomposer.H b/applications/utilities/parallelProcessing/decomposePar/lagrangianFieldDecomposer.H index f174d79348..09660a8f75 100644 --- a/applications/utilities/parallelProcessing/decomposePar/lagrangianFieldDecomposer.H +++ b/applications/utilities/parallelProcessing/decomposePar/lagrangianFieldDecomposer.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -102,10 +102,7 @@ public: ( const label cloudI, const IOobjectList& lagrangianObjects, - PtrList - < - PtrList, Type>> - >& lagrangianFields + PtrList>>>& lagrangianFields ); @@ -118,10 +115,10 @@ public: ) const; template - tmp, Type>> decomposeFieldField + tmp>> decomposeFieldField ( const word& cloudName, - const CompactIOField, Type>& field + const CompactIOField>& field ) const; diff --git a/applications/utilities/parallelProcessing/decomposePar/lagrangianFieldDecomposerDecomposeFields.C b/applications/utilities/parallelProcessing/decomposePar/lagrangianFieldDecomposerDecomposeFields.C index 5f643b709a..fdc0efa67d 100644 --- a/applications/utilities/parallelProcessing/decomposePar/lagrangianFieldDecomposerDecomposeFields.C +++ b/applications/utilities/parallelProcessing/decomposePar/lagrangianFieldDecomposerDecomposeFields.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -68,7 +68,7 @@ void Foam::lagrangianFieldDecomposer::readFieldFields ( const label cloudI, const IOobjectList& lagrangianObjects, - PtrList, Type>>>& lagrangianFields + PtrList>>>& lagrangianFields ) { // Search list of objects for lagrangian fields @@ -81,15 +81,14 @@ void Foam::lagrangianFieldDecomposer::readFieldFields ( lagrangianObjects.lookupClass ( - CompactIOField, - Type>::typeName + CompactIOField>::typeName ) ); lagrangianFields.set ( cloudI, - new PtrList, Type>> + new PtrList>> ( lagrangianTypeObjectsA.size() + lagrangianTypeObjectsB.size() ) @@ -102,7 +101,7 @@ void Foam::lagrangianFieldDecomposer::readFieldFields lagrangianFields[cloudI].set ( lagrangianFieldi++, - new CompactIOField, Type>(*iter()) + new CompactIOField>(*iter()) ); } @@ -111,7 +110,7 @@ void Foam::lagrangianFieldDecomposer::readFieldFields lagrangianFields[cloudI].set ( lagrangianFieldi++, - new CompactIOField, Type>(*iter()) + new CompactIOField>(*iter()) ); } } @@ -150,20 +149,20 @@ Foam::lagrangianFieldDecomposer::decomposeField template -Foam::tmp, Type>> +Foam::tmp>> Foam::lagrangianFieldDecomposer::decomposeFieldField ( const word& cloudName, - const CompactIOField, Type>& field + const CompactIOField>& field ) const { // Create and map the internal field values Field> procField(field, particleIndices_); // Create the field for the processor - return tmp, Type>> + return tmp>> ( - new CompactIOField, Type> + new CompactIOField> ( IOobject ( diff --git a/applications/utilities/parallelProcessing/reconstructPar/reconstructLagrangian.H b/applications/utilities/parallelProcessing/reconstructPar/reconstructLagrangian.H index 80626cf13a..4072dce2f7 100644 --- a/applications/utilities/parallelProcessing/reconstructPar/reconstructLagrangian.H +++ b/applications/utilities/parallelProcessing/reconstructPar/reconstructLagrangian.H @@ -69,7 +69,7 @@ tmp> reconstructLagrangianField template -tmp, Type>> reconstructLagrangianFieldField +tmp>> reconstructLagrangianFieldField ( const word& cloudName, const polyMesh& mesh, diff --git a/applications/utilities/parallelProcessing/reconstructPar/reconstructLagrangianFields.C b/applications/utilities/parallelProcessing/reconstructPar/reconstructLagrangianFields.C index 5adf9ab01a..a19f3f54c3 100644 --- a/applications/utilities/parallelProcessing/reconstructPar/reconstructLagrangianFields.C +++ b/applications/utilities/parallelProcessing/reconstructPar/reconstructLagrangianFields.C @@ -89,7 +89,7 @@ Foam::tmp> Foam::reconstructLagrangianField template -Foam::tmp, Type>> +Foam::tmp>> Foam::reconstructLagrangianFieldField ( const word& cloudName, @@ -99,9 +99,9 @@ Foam::reconstructLagrangianFieldField ) { // Construct empty field on mesh - tmp, Type >> tfield + tmp>> tfield ( - new CompactIOField, Type> + new CompactIOField> ( IOobject ( @@ -132,7 +132,7 @@ Foam::reconstructLagrangianFieldField if (localIOobject.headerOk()) { - CompactIOField, Type> fieldi(localIOobject); + CompactIOField> fieldi(localIOobject); label offset = field.size(); field.setSize(offset + fieldi.size()); @@ -203,7 +203,7 @@ void Foam::reconstructLagrangianFieldFields ) { { - const word fieldClassName(CompactIOField, Type>::typeName); + const word fieldClassName(CompactIOField>::typeName); IOobjectList fields = objects.lookupClass(fieldClassName); diff --git a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoam.H b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoam.H index fc9df306ff..2fe968e4a6 100644 --- a/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoam.H +++ b/applications/utilities/postProcessing/graphics/PVReaders/vtkPVFoam/vtkPVFoam.H @@ -97,9 +97,6 @@ class polyPatch; class faceSet; class pointSet; -template class IOField; -template class List; - /*---------------------------------------------------------------------------*\ Class vtkPVFoam Declaration \*---------------------------------------------------------------------------*/ diff --git a/applications/utilities/preProcessing/mapFields/MapLagrangianFields.H b/applications/utilities/preProcessing/mapFields/MapLagrangianFields.H index d92549a846..ec7a8bc533 100644 --- a/applications/utilities/preProcessing/mapFields/MapLagrangianFields.H +++ b/applications/utilities/preProcessing/mapFields/MapLagrangianFields.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -108,7 +108,7 @@ void MapLagrangianFields // Map - use CompactIOField to automatically write in // compact form for binary format. - CompactIOField, Type> fieldTarget + CompactIOField> fieldTarget ( IOobject ( @@ -135,7 +135,7 @@ void MapLagrangianFields { IOobjectList fieldFields = - objects.lookupClass(CompactIOField, Type>::typeName); + objects.lookupClass(CompactIOField>::typeName); forAllIter(IOobjectList, fieldFields, fieldIter) { @@ -143,10 +143,10 @@ void MapLagrangianFields << fieldIter()->name() << endl; // Read field (does not need mesh) - CompactIOField, Type> fieldSource(*fieldIter()); + CompactIOField> fieldSource(*fieldIter()); // Map - CompactIOField, Type> fieldTarget + CompactIOField> fieldTarget ( IOobject ( diff --git a/applications/utilities/preProcessing/mapFieldsPar/MapLagrangianFields.H b/applications/utilities/preProcessing/mapFieldsPar/MapLagrangianFields.H index 1001f281f6..21327e69b2 100644 --- a/applications/utilities/preProcessing/mapFieldsPar/MapLagrangianFields.H +++ b/applications/utilities/preProcessing/mapFieldsPar/MapLagrangianFields.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -108,7 +108,7 @@ void MapLagrangianFields // Map - use CompactIOField to automatically write in // compact form for binary format. - CompactIOField, Type> fieldTarget + CompactIOField> fieldTarget ( IOobject ( @@ -135,7 +135,7 @@ void MapLagrangianFields { IOobjectList fieldFields = - objects.lookupClass(CompactIOField, Type>::typeName); + objects.lookupClass(CompactIOField>::typeName); forAllIter(IOobjectList, fieldFields, fieldIter) { @@ -143,10 +143,10 @@ void MapLagrangianFields << fieldIter()->name() << endl; // Read field (does not need mesh) - CompactIOField, Type> fieldSource(*fieldIter()); + CompactIOField> fieldSource(*fieldIter()); // Map - CompactIOField, Type> fieldTarget + CompactIOField> fieldTarget ( IOobject ( diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index 3ed7092461..01f85aa58d 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -246,11 +246,7 @@ $(IOdictionary)/localIOdictionary.C $(IOdictionary)/timeIOdictionary.C $(IOdictionary)/systemDict.C -db/IOobjects/IOMap/IOMapName.C db/IOobjects/decomposedBlockData/decomposedBlockData.C -db/IOobjects/GlobalIOList/GlobalIOLists.C -db/IOobjects/GlobalIOField/GlobalIOFields.C - IOobject = db/IOobject $(IOobject)/IOobject.C diff --git a/src/OpenFOAM/db/IOobjects/CompactIOField/CompactIOField.C b/src/OpenFOAM/db/IOobjects/CompactIOField/CompactIOField.C deleted file mode 100644 index f1a9885330..0000000000 --- a/src/OpenFOAM/db/IOobjects/CompactIOField/CompactIOField.C +++ /dev/null @@ -1,340 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation - \\/ 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 . - -\*---------------------------------------------------------------------------*/ - -#include "CompactIOField.H" -#include "labelList.H" - -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -template -void Foam::CompactIOField::readFromStream(const bool read) -{ - Istream& is = readStream(word::null, read); - - if (read) - { - if (headerClassName() == IOField::typeName) - { - is >> static_cast&>(*this); - close(); - } - else if (headerClassName() == typeName) - { - is >> *this; - close(); - } - else - { - FatalIOErrorInFunction - ( - is - ) << "unexpected class name " << headerClassName() - << " expected " << typeName << " or " << IOField::typeName - << endl - << " while reading object " << name() - << exit(FatalIOError); - } - } -} - - -// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * // - -template -Foam::CompactIOField::CompactIOField(const IOobject& io) -: - regIOobject(io) -{ - if - ( - io.readOpt() == IOobject::MUST_READ - || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk()) - ) - { - readFromStream(); - } -} - - -template -Foam::CompactIOField::CompactIOField -( - const IOobject& io, - const bool read -) -: - regIOobject(io) -{ - if (io.readOpt() == IOobject::MUST_READ) - { - readFromStream(read); - } - else if (io.readOpt() == IOobject::READ_IF_PRESENT) - { - bool haveFile = headerOk(); - readFromStream(read && haveFile); - } -} - - -template -Foam::CompactIOField::CompactIOField -( - const IOobject& io, - const label size -) -: - regIOobject(io) -{ - if - ( - io.readOpt() == IOobject::MUST_READ - || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk()) - ) - { - readFromStream(); - } - else - { - Field::setSize(size); - } -} - - -template -Foam::CompactIOField::CompactIOField -( - const IOobject& io, - const Field& field -) -: - regIOobject(io) -{ - if - ( - io.readOpt() == IOobject::MUST_READ - || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk()) - ) - { - readFromStream(); - } - else - { - Field::operator=(field); - } -} - - -template -Foam::CompactIOField::CompactIOField -( - const IOobject& io, - Field&& field -) -: - regIOobject(io), - Field(move(field)) -{ - if - ( - io.readOpt() == IOobject::MUST_READ - || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk()) - ) - { - readFromStream(); - } -} - - -template -Foam::CompactIOField::CompactIOField -( - CompactIOField&& field -) -: - regIOobject(move(field)), - Field(move(field)) -{} - - -// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * // - -template -Foam::CompactIOField::~CompactIOField() -{} - - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -template -bool Foam::CompactIOField::writeObject -( - IOstream::streamFormat fmt, - IOstream::versionNumber ver, - IOstream::compressionType cmp, - const bool write -) const -{ - if (fmt == IOstream::ASCII) - { - // Change type to be non-compact format type - const word oldTypeName = typeName; - - const_cast(typeName) = IOField::typeName; - - bool good = regIOobject::writeObject(fmt, ver, cmp, write); - - // Change type back - const_cast(typeName) = oldTypeName; - - return good; - } - else - { - return regIOobject::writeObject(fmt, ver, cmp, write); - } -} - - -template -bool Foam::CompactIOField::writeData(Ostream& os) const -{ - return (os << *this).good(); -} - - -// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // - -template -void Foam::CompactIOField::operator= -( - const CompactIOField& rhs -) -{ - Field::operator=(rhs); -} - - -template -void Foam::CompactIOField::operator= -( - CompactIOField&& rhs -) -{ - Field::operator=(move(rhs)); -} - - -template -void Foam::CompactIOField::operator=(const Field& rhs) -{ - Field::operator=(rhs); -} - - -template -void Foam::CompactIOField::operator=(Field&& rhs) -{ - Field::operator=(move(rhs)); -} - - -// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // - -template -Foam::Istream& Foam::operator>> -( - Foam::Istream& is, - Foam::CompactIOField& L -) -{ - // Read compact - const labelList start(is); - const Field elems(is); - - // Convert - L.setSize(start.size()-1); - - forAll(L, i) - { - Type& subField = L[i]; - - label index = start[i]; - subField.setSize(start[i+1] - index); - - forAll(subField, j) - { - subField[j] = elems[index++]; - } - } - - return is; -} - - -template -Foam::Ostream& Foam::operator<< -( - Foam::Ostream& os, - const Foam::CompactIOField& L -) -{ - // Keep ascii writing same. - if (os.format() == IOstream::ASCII) - { - os << static_cast&>(L); - } - else - { - // Convert to compact format - labelList start(L.size()+1); - - start[0] = 0; - for (label i = 1; i < start.size(); i++) - { - start[i] = start[i-1]+L[i-1].size(); - } - - Field elems(start[start.size()-1]); - - label elemI = 0; - forAll(L, i) - { - const Type& subField = L[i]; - - forAll(subField, j) - { - elems[elemI++] = subField[j]; - } - } - os << start << elems; - } - - return os; -} - - -// ************************************************************************* // diff --git a/src/OpenFOAM/db/IOobjects/CompactIOField/CompactIOField.H b/src/OpenFOAM/db/IOobjects/CompactIOField/CompactIOField.H index 3590aded6c..db5ea92342 100644 --- a/src/OpenFOAM/db/IOobjects/CompactIOField/CompactIOField.H +++ b/src/OpenFOAM/db/IOobjects/CompactIOField/CompactIOField.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,58 +25,34 @@ Class Foam::CompactIOField Description - A Field of objects of type \ with automated input and output using + A Field of objects of type \ with automated input and output using a compact storage. Behaves like IOField except when binary output in case it writes a CompactListList. Useful for fields of small subfields e.g. in lagrangian -SourceFiles - CompactIOField.C - \*---------------------------------------------------------------------------*/ #ifndef CompactIOField_H #define CompactIOField_H +#include "CompactIOList.H" #include "IOField.H" -#include "regIOobject.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { -// Forward declaration of friend functions and operators -template class CompactIOField; - -template Istream& operator>> -( - Istream&, - CompactIOField& -); - -template Ostream& operator<< -( - Ostream&, - const CompactIOField& -); - /*---------------------------------------------------------------------------*\ Class CompactIOField Declaration \*---------------------------------------------------------------------------*/ -template +template class CompactIOField : - public regIOobject, - public Field + public CompactIOListBase { - // Private Member Functions - - //- Read according to header type - void readFromStream(const bool read = true); - public: //- Runtime type information @@ -85,50 +61,18 @@ public: // Constructors - //- Construct from IOobject - CompactIOField(const IOobject&); - - //- Construct from IOobject; does local processor require reading? - CompactIOField(const IOobject&, const bool read); - - //- Construct from IOobject and size - CompactIOField(const IOobject&, const label); - - //- Construct from IOobject and a Field - CompactIOField(const IOobject&, const Field&); - - //- Move construct by transferring the Field contents - CompactIOField(const IOobject&, Field&&); - - //- Move constructor - CompactIOField(CompactIOField&&); - - - // Destructor - - virtual ~CompactIOField(); - - - // Member Functions - - virtual bool writeObject - ( - IOstream::streamFormat, - IOstream::versionNumber, - IOstream::compressionType, - const bool write - ) const; - - virtual bool writeData(Ostream&) const; + //- Inherit constructors + using + CompactIOListBase:: + CompactIOListBase; // Member Operators - void operator=(const CompactIOField&); - void operator=(CompactIOField&&); - - void operator=(const Field&); - void operator=(Field&&); + //- Inherit assignment operators + using + CompactIOListBase:: + operator=; }; @@ -138,12 +82,6 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#ifdef NoRepository - #include "CompactIOField.C" -#endif - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - #endif // ************************************************************************* // diff --git a/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.C b/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.C index bbf28988f7..2e87011cc2 100644 --- a/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.C +++ b/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -28,39 +28,169 @@ License // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -template -void Foam::CompactIOList::readFromStream() +template +< + template class Container, + template class IOContainer, + template class CompactIOContainer, + class Type +> +bool +Foam::CompactIOListBase:: +overflows() const { - Istream& is = readStream(word::null); + label size = 0; - if (headerClassName() == IOList::typeName) + forAll(*this, i) { - is >> static_cast&>(*this); - close(); + label oldSize = size; + + size += this->operator[](i).size(); + + if (size < oldSize) + { + return true; + } } - else if (headerClassName() == typeName) + + return false; +} + + +template +< + template class Container, + template class IOContainer, + template class CompactIOContainer, + class Type +> +void +Foam::CompactIOListBase:: +convertToCompact +( + labelList& start, + List& elems +) const +{ + start.setSize(this->size() + 1); + + start[0] = 0; + + for (label i = 1; i < start.size(); i++) { - is >> *this; - close(); + const label prev = start[i-1]; + + start[i] = prev + this->operator[](i-1).size(); + + if (start[i] < prev) + { + FatalErrorInFunction + << "Overall number of elements " << start[i] + << " of CompactIOListBase of size " + << this->size() << " overflows the representation of a label" + << endl << "Please recompile with a larger representation" + << " for label" << exit(FatalError); + } } - else + + elems.setSize(start[start.size() - 1]); + + label elemi = 0; + + forAll(*this, i) { - FatalIOErrorInFunction - ( - is - ) << "unexpected class name " << headerClassName() - << " expected " << typeName << " or " << IOList::typeName - << endl - << " while reading object " << name() - << exit(FatalIOError); + const Type& subList = this->operator[](i); + + forAll(subList, j) + { + elems[elemi++] = subList[j]; + } + } +} + + +template +< + template class Container, + template class IOContainer, + template class CompactIOContainer, + class Type +> +void +Foam::CompactIOListBase:: +convertFromCompact +( + const labelList& start, + const List& elems +) +{ + this->setSize(start.size() - 1); + + forAll(*this, i) + { + Type& subList = this->operator[](i); + + label index = start[i]; + + subList.setSize(start[i+1] - index); + + forAll(subList, j) + { + subList[j] = elems[index++]; + } + } +} + + +template +< + template class Container, + template class IOContainer, + template class CompactIOContainer, + class Type +> +void +Foam::CompactIOListBase:: +readFromStream(const bool read) +{ + Istream& is = readStream(word::null, read); + + if (read) + { + if (headerClassName() == IOContainer::typeName) + { + is >> static_cast&>(*this); + close(); + } + else if (headerClassName() == CompactIOContainer::typeName) + { + is >> *this; + close(); + } + else + { + FatalIOErrorInFunction(is) + << "unexpected class name " << headerClassName() + << " expected " << CompactIOContainer::typeName << " or " + << IOContainer::typeName << endl + << " while reading object " << name() + << exit(FatalIOError); + } } } // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * // -template -Foam::CompactIOList::CompactIOList(const IOobject& io) +template +< + template class Container, + template class IOContainer, + template class CompactIOContainer, + class Type +> +Foam::CompactIOListBase:: +CompactIOListBase(const IOobject& io) : regIOobject(io) { @@ -75,8 +205,43 @@ Foam::CompactIOList::CompactIOList(const IOobject& io) } -template -Foam::CompactIOList::CompactIOList +template +< + template class Container, + template class IOContainer, + template class CompactIOContainer, + class Type +> +Foam::CompactIOListBase:: +CompactIOListBase +( + const IOobject& io, + const bool read +) +: + regIOobject(io) +{ + if (io.readOpt() == IOobject::MUST_READ) + { + readFromStream(read); + } + else if (io.readOpt() == IOobject::READ_IF_PRESENT) + { + bool haveFile = headerOk(); + readFromStream(read && haveFile); + } +} + + +template +< + template class Container, + template class IOContainer, + template class CompactIOContainer, + class Type +> +Foam::CompactIOListBase:: +CompactIOListBase ( const IOobject& io, const label size @@ -99,39 +264,22 @@ Foam::CompactIOList::CompactIOList } -template -Foam::CompactIOList::CompactIOList +template +< + template class Container, + template class IOContainer, + template class CompactIOContainer, + class Type +> +Foam::CompactIOListBase:: +CompactIOListBase ( const IOobject& io, - const List& list -) -: - regIOobject(io) -{ - if - ( - io.readOpt() == IOobject::MUST_READ - || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk()) - ) - { - readFromStream(); - } - else - { - ListCompactIO::operator=(list); - } -} - - -template -Foam::CompactIOList::CompactIOList -( - const IOobject& io, - List&& list + const Container& l ) : regIOobject(io), - ListCompactIO(move(list)) + Container(l) { if ( @@ -144,29 +292,78 @@ Foam::CompactIOList::CompactIOList } -template -Foam::CompactIOList::CompactIOList +template +< + template class Container, + template class IOContainer, + template class CompactIOContainer, + class Type +> +Foam::CompactIOListBase:: +CompactIOListBase ( - CompactIOList&& list + const IOobject& io, + Container&& l ) : - regIOobject(move(list)), - List(move(list)) + regIOobject(io), + Container(move(l)) +{ + if + ( + io.readOpt() == IOobject::MUST_READ + || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk()) + ) + { + readFromStream(); + } +} + + +template +< + template class Container, + template class IOContainer, + template class CompactIOContainer, + class Type +> +Foam::CompactIOListBase:: +CompactIOListBase +( + CompactIOListBase&& l +) +: + regIOobject(move(l)), + Container(move(l)) {} // * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * // -template -Foam::CompactIOList::~CompactIOList() +template +< + template class Container, + template class IOContainer, + template class CompactIOContainer, + class Type +> +Foam::CompactIOListBase:: +~CompactIOListBase() {} - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -template -bool Foam::CompactIOList::writeObject +template +< + template class Container, + template class IOContainer, + template class CompactIOContainer, + class Type +> +bool +Foam::CompactIOListBase:: +writeObject ( IOstream::streamFormat fmt, IOstream::versionNumber ver, @@ -177,33 +374,35 @@ bool Foam::CompactIOList::writeObject if (fmt == IOstream::ASCII) { // Change type to be non-compact format type - const word oldTypeName = typeName; + const word oldTypeName = CompactIOContainer::typeName; - const_cast(typeName) = IOList::typeName; + const_cast(CompactIOContainer::typeName) = + IOContainer::typeName; bool good = regIOobject::writeObject(fmt, ver, cmp, write); // Change type back - const_cast(typeName) = oldTypeName; + const_cast(CompactIOContainer::typeName) = oldTypeName; return good; } else if (this->overflows()) { WarningInFunction - << "Overall number of elements of CompactIOList of size " + << "Overall number of elements of CompactIOListBase of size " << this->size() << " overflows the representation of a label" << endl << " Switching to ascii writing" << endl; // Change type to be non-compact format type - const word oldTypeName = typeName; + const word oldTypeName = CompactIOContainer::typeName; - const_cast(typeName) = IOList::typeName; + const_cast(CompactIOContainer::typeName) = + IOContainer::typeName; bool good = regIOobject::writeObject(IOstream::ASCII, ver, cmp, write); // Change type back - const_cast(typeName) = oldTypeName; + const_cast(CompactIOContainer::typeName) = oldTypeName; return good; } @@ -214,8 +413,16 @@ bool Foam::CompactIOList::writeObject } -template -bool Foam::CompactIOList::writeData(Ostream& os) const +template +< + template class Container, + template class IOContainer, + template class CompactIOContainer, + class Type +> +bool +Foam::CompactIOListBase:: +writeData(Ostream& os) const { return (os << *this).good(); } @@ -223,43 +430,120 @@ bool Foam::CompactIOList::writeData(Ostream& os) const // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // -template -void Foam::CompactIOList::operator= +template +< + template class Container, + template class IOContainer, + template class CompactIOContainer, + class Type +> +void +Foam::CompactIOListBase:: +operator= ( - const CompactIOList& rhs + const CompactIOListBase& + rhs ) { - ListCompactIO::operator=(rhs); + Container::operator=(rhs); } -template -void Foam::CompactIOList::operator= +template +< + template class Container, + template class IOContainer, + template class CompactIOContainer, + class Type +> +void +Foam::CompactIOListBase:: +operator= ( - CompactIOList&& rhs + CompactIOListBase&& rhs ) { - ListCompactIO::operator=(move(rhs)); + Container::operator=(move(rhs)); } -template -void Foam::CompactIOList::operator= +// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * // + +template +< + template class Container, + template class IOContainer, + template class CompactIOContainer, + class Type +> +void Foam::writeEntry ( - const List& rhs + Ostream& os, + const CompactIOListBase& l ) { - ListCompactIO::operator=(rhs); + os << l; } -template -void Foam::CompactIOList::operator= +// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // + +template +< + template class Container, + template class IOContainer, + template class CompactIOContainer, + class Type +> +Foam::Istream& Foam::operator>> ( - List&& rhs + Istream& is, + CompactIOListBase& l ) { - ListCompactIO::operator=(move(rhs)); + // ASCII is not compacted + if (is.format() == IOstream::ASCII) + { + is >> static_cast&>(l); + } + else + { + labelList start(is); + List elems(is); + l.convertFromCompact(start, elems); + } + + return is; +} + + +template +< + template class Container, + template class IOContainer, + template class CompactIOContainer, + class Type +> +Foam::Ostream& Foam::operator<< +( + Ostream& os, + const CompactIOListBase& l +) +{ + // ASCII is not compacted + if (os.format() == IOstream::ASCII) + { + os << static_cast&>(l); + } + else + { + labelList start; + List elems; + l.convertToCompact(start, elems); + os << start << elems; + } + + return os; } diff --git a/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.H b/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.H index b632a6cb1d..9ad389d645 100644 --- a/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.H +++ b/src/OpenFOAM/db/IOobjects/CompactIOList/CompactIOList.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,7 +25,7 @@ Class Foam::CompactIOList Description - A List of objects of type \ with automated input and output using + A List of objects of type \ with automated input and output using a compact storage. Behaves like IOList except when binary output in case it writes a CompactListList. @@ -39,7 +39,7 @@ SourceFiles #ifndef CompactIOList_H #define CompactIOList_H -#include "ListCompactIO.H" +#include "IOList.H" #include "regIOobject.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -47,52 +47,136 @@ SourceFiles namespace Foam { +// Forward declaration of friend functions and operators +template +< + template class Container, + template class IOContainer, + template class CompactIOContainer, + class Type +> +class CompactIOListBase; + +template +< + template class Container, + template class IOContainer, + template class CompactIOContainer, + class Type +> +void writeEntry +( + Ostream&, + const CompactIOListBase& +); + +template +< + template class Container, + template class IOContainer, + template class CompactIOContainer, + class Type +> +Istream& operator>> +( + Istream&, + CompactIOListBase& +); + +template +< + template class Container, + template class IOContainer, + template class CompactIOContainer, + class Type +> +Ostream& operator<< +( + Ostream&, + const CompactIOListBase& +); + + /*---------------------------------------------------------------------------*\ - Class CompactIOList Declaration + Class CompactIOListBase Declaration \*---------------------------------------------------------------------------*/ -template -class CompactIOList +template +< + template class Container, + template class IOContainer, + template class CompactIOContainer, + class Type +> +class CompactIOListBase : public regIOobject, - public ListCompactIO + public Container { // Private Member Functions + //- Does the container have too many elements to represent with the + // current integer size type? + bool overflows() const; + + //- Convert the data to a compact representation + void convertToCompact + ( + labelList& start, + List& elems + ) const; + + //- Convert the data from a compact representation + void convertFromCompact + ( + const labelList& start, + const List& elems + ); + //- Read according to header type - void readFromStream(); + void readFromStream(const bool read = true); + public: - //- Runtime type information - TypeName("CompactList"); - - // Constructors //- Construct from IOobject - CompactIOList(const IOobject&); + CompactIOListBase(const IOobject&); - //- Construct from IOobject and size of CompactIOList - CompactIOList(const IOobject&, const label); + //- Construct from IOobject; does local processor require reading? + CompactIOListBase(const IOobject&, const bool read); - //- Construct from IOobject and a List - CompactIOList(const IOobject&, const List&); + //- Construct from IOobject and size of CompactIOListBase + CompactIOListBase(const IOobject&, const label); - //- Move construct by transferring the List contents - CompactIOList(const IOobject&, List&&); + //- Construct from IOobject and a Container + CompactIOListBase(const IOobject&, const Container&); + + //- Move construct by transferring the Container contents + CompactIOListBase(const IOobject&, Container&&); //- Move constructor - CompactIOList(CompactIOList&&); + CompactIOListBase + ( + CompactIOListBase + < + Container, + IOContainer, + CompactIOContainer, + Type + >&& + ); - // Destructor - - virtual ~CompactIOList(); + //- Destructor + virtual ~CompactIOListBase(); // Member Functions + //- WriteObject function. Changes the write type depending on whether + // the output is compact or not. virtual bool writeObject ( IOstream::streamFormat, @@ -101,16 +185,134 @@ public: const bool write ) const; + //- WriteData function required for regIOobject write operation virtual bool writeData(Ostream&) const; // Member Operators - void operator=(const CompactIOList&); - void operator=(CompactIOList&&); + //- Inherit assignment operators + using Container::operator=; - void operator=(const List&); - void operator=(List&&); + //- Assign to another CompactIOList + void operator= + ( + const CompactIOListBase + < + Container, + IOContainer, + CompactIOContainer, + Type + >& + ); + + //- Move-assign to another CompactIOList + void operator= + ( + CompactIOListBase + < + Container, + IOContainer, + CompactIOContainer, + Type + >&& + ); + + + // IOstream functions + + //- Write list to Ostream + friend void writeEntry + < + Container, + IOContainer, + CompactIOContainer, + Type + > + ( + Ostream&, + const CompactIOListBase + < + Container, + IOContainer, + CompactIOContainer, + Type + >& + ); + + + // IOstream Operators + + //- Read list from Istream + friend Istream& operator>> + < + Container, + IOContainer, + CompactIOContainer, + Type + > + ( + Istream&, + CompactIOListBase + < + Container, + IOContainer, + CompactIOContainer, + Type + >& + ); + + // Write list to Ostream + friend Ostream& operator<< + < + Container, + IOContainer, + CompactIOContainer, + Type + > + ( + Ostream&, + const CompactIOListBase + < + Container, + IOContainer, + CompactIOContainer, + Type + >& + ); +}; + + +/*---------------------------------------------------------------------------*\ + Class CompactIOList Declaration +\*---------------------------------------------------------------------------*/ + +template +class CompactIOList +: + public CompactIOListBase +{ + +public: + + //- Runtime type information + TypeName("ListList"); + + + // Constructors + + //- Inherit constructors + using + CompactIOListBase:: + CompactIOListBase; + + + // Member Operators + + //- Inherit assignment operators + using + CompactIOListBase:: + operator=; }; diff --git a/src/OpenFOAM/db/IOobjects/CompactIOList/ListCompactIO.C b/src/OpenFOAM/db/IOobjects/CompactIOList/ListCompactIO.C deleted file mode 100644 index eb5d4f8dd9..0000000000 --- a/src/OpenFOAM/db/IOobjects/CompactIOList/ListCompactIO.C +++ /dev/null @@ -1,262 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2019 OpenFOAM Foundation - \\/ 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 . - -\*---------------------------------------------------------------------------*/ - -#include "ListCompactIO.H" - -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -template -bool Foam::ListCompactIO::overflows() const -{ - label size = 0; - forAll(*this, i) - { - label oldSize = size; - size += this->operator[](i).size(); - if (size < oldSize) - { - return true; - } - } - return false; -} - - -template -void Foam::ListCompactIO::convertToCompact -( - labelList& start, - List& elems -) const -{ - start.setSize(this->size() + 1); - - start[0] = 0; - for (label i = 1; i < start.size(); i++) - { - label prev = start[i-1]; - start[i] = prev + this->operator[](i-1).size(); - - if (start[i] < prev) - { - FatalErrorInFunction - << "Overall number of elements " << start[i] - << " of ListCompactIO of size " - << this->size() << " overflows the representation of a label" - << endl << "Please recompile with a larger representation" - << " for label" << exit(FatalError); - } - } - - elems.setSize(start[start.size() - 1]); - - label elemi = 0; - forAll(*this, i) - { - const T& subList = this->operator[](i); - - forAll(subList, j) - { - elems[elemi++] = subList[j]; - } - } -} - - -template -void Foam::ListCompactIO::convertFromCompact -( - const labelList& start, - const List& elems -) -{ - this->setSize(start.size() - 1); - - forAll(*this, i) - { - T& subList = this->operator[](i); - - label index = start[i]; - subList.setSize(start[i+1] - index); - - forAll(subList, j) - { - subList[j] = elems[index++]; - } - } -} - - -// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * // - -template -Foam::ListCompactIO::ListCompactIO() -{} - - -template -Foam::ListCompactIO::ListCompactIO(const UList& l) -: - List(l) -{} - - -template -Foam::ListCompactIO::ListCompactIO(Istream& is) -{ - is >> *this; -} - - -template -Foam::ListCompactIO::ListCompactIO -( - const ListCompactIO& l -) -: - List(l) -{} - - -template -Foam::ListCompactIO::ListCompactIO(ListCompactIO&& l) -: - List(move(l)) -{} - - -template -Foam::ListCompactIO::ListCompactIO(List&& l) -: - List(move(l)) -{} - - -// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // - -template -void Foam::ListCompactIO::operator= -( - const ListCompactIO& rhs -) -{ - List::operator=(rhs); -} - - -template -void Foam::ListCompactIO::operator= -( - ListCompactIO&& rhs -) -{ - List::operator=(move(rhs)); -} - - -template -void Foam::ListCompactIO::operator=(const List& rhs) -{ - List::operator=(rhs); -} - - -template -void Foam::ListCompactIO::operator=(List&& rhs) -{ - List::operator=(move(rhs)); -} - - -// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * // - -template -void Foam::writeEntry(Ostream& os, const ListCompactIO& l) -{ - // Keep ascii writing same. - if (os.format() == IOstream::ASCII) - { - os << static_cast&>(l); - } - else - { - labelList start; - List elems; - l.convertToCompact(start, elems); - writeEntry(os, start); - writeEntry(os, elems); - } -} - - -// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // - -template -Foam::Istream& Foam::operator>> -( - Foam::Istream& is, - Foam::ListCompactIO& L -) -{ - if (is.format() == IOstream::ASCII) - { - is >> static_cast&>(L); - } - else - { - labelList start(is); - List elems(is); - L.convertFromCompact(start, elems); - } - - return is; -} - - -template -Foam::Ostream& Foam::operator<< -( - Foam::Ostream& os, - const Foam::ListCompactIO& L -) -{ - // Keep ascii writing same. - if (os.format() == IOstream::ASCII) - { - os << static_cast&>(L); - } - else - { - labelList start; - List elems; - L.convertToCompact(start, elems); - os << start << elems; - } - - return os; -} - - -// ************************************************************************* // diff --git a/src/OpenFOAM/db/IOobjects/CompactIOList/ListCompactIO.H b/src/OpenFOAM/db/IOobjects/CompactIOList/ListCompactIO.H deleted file mode 100644 index 852d80ba5e..0000000000 --- a/src/OpenFOAM/db/IOobjects/CompactIOList/ListCompactIO.H +++ /dev/null @@ -1,173 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2019-2020 OpenFOAM Foundation - \\/ 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 . - -Class - Foam::ListCompactIO - -Description - A List of objects of type \ with input and output using - a compact storage. Behaves like List except when binary output in - case it writes a CompactListList. - - Useful for lists of small sublists e.g. faceList, cellList. - -SourceFiles - ListCompactIO.C - -\*---------------------------------------------------------------------------*/ - -#ifndef ListCompactIO_H -#define ListCompactIO_H - -#include "labelList.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - -class Istream; -class Ostream; - -// Forward declaration of friend functions and operators -template class ListCompactIO; - -template -void writeEntry(Ostream& os, const ListCompactIO& l); - -template Istream& operator>> -( - Istream&, - ListCompactIO& -); - -template Ostream& operator<< -( - Ostream&, - const ListCompactIO& -); - - -/*---------------------------------------------------------------------------*\ - Class ListCompactIO Declaration -\*---------------------------------------------------------------------------*/ - -template -class ListCompactIO -: - public List -{ -protected: - - // Protected Member Functions - - //- Has too many elements in it? - bool overflows() const; - - void convertToCompact - ( - labelList& start, - List& elems - ) const; - - void convertFromCompact - ( - const labelList& start, - const List& elems - ); - - -public: - - // Constructors - - //- Construct null - ListCompactIO(); - - //- Construct from UList - ListCompactIO(const UList&); - - //- Construct from Istream - ListCompactIO(Istream&); - - //- Copy constructor - ListCompactIO(const ListCompactIO&); - - //- Move constructor - ListCompactIO(ListCompactIO&&); - - //- Move constructor from List - ListCompactIO(List&&); - - - // Member Operators - - void operator=(const ListCompactIO&); - void operator=(ListCompactIO&&); - - void operator=(const List&); - void operator=(List&&); - - - // IOstream functions - - friend void writeEntry - ( - Ostream& os, - const ListCompactIO& l - ); - - - // IOstream Operators - - //- Read List from Istream, discarding contents of existing List. - friend Istream& operator>> - ( - Istream&, - ListCompactIO& - ); - - // Write List to Ostream. - friend Ostream& operator<< - ( - Ostream&, - const ListCompactIO& - ); -}; - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#ifdef NoRepository - #include "ListCompactIO.C" -#endif - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/src/OpenFOAM/db/IOobjects/GlobalIOField/GlobalIOField.C b/src/OpenFOAM/db/IOobjects/GlobalIOField/GlobalIOField.C deleted file mode 100644 index 42c1ed06bd..0000000000 --- a/src/OpenFOAM/db/IOobjects/GlobalIOField/GlobalIOField.C +++ /dev/null @@ -1,170 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2015-2019 OpenFOAM Foundation - \\/ 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 . - -\*---------------------------------------------------------------------------*/ - -#include "GlobalIOField.H" - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -template -Foam::GlobalIOField::GlobalIOField(const IOobject& io) -: - regIOobject(io) -{ - // Check for MUST_READ_IF_MODIFIED - warnNoRereading>(); - - readHeaderOk(IOstream::BINARY, typeName); -} - - -template -Foam::GlobalIOField::GlobalIOField(const IOobject& io, const label size) -: - regIOobject(io) -{ - // Check for MUST_READ_IF_MODIFIED - warnNoRereading>(); - - if (!readHeaderOk(IOstream::BINARY, typeName)) - { - Field::setSize(size); - } -} - - -template -Foam::GlobalIOField::GlobalIOField -( - const IOobject& io, - const Field& f -) -: - regIOobject(io) -{ - // Check for MUST_READ_IF_MODIFIED - warnNoRereading>(); - - if (!readHeaderOk(IOstream::BINARY, typeName)) - { - Field::operator=(f); - } -} - - -template -Foam::GlobalIOField::GlobalIOField -( - const IOobject& io, - Field&& f -) -: - regIOobject(io), - Field(move(f)) - -{ - // Check for MUST_READ_IF_MODIFIED - warnNoRereading>(); - - readHeaderOk(IOstream::BINARY, typeName); -} - - -template -Foam::GlobalIOField::GlobalIOField -( - const GlobalIOField& field -) -: - regIOobject(field), - Field(field) -{} - - -template -Foam::GlobalIOField::GlobalIOField -( - GlobalIOField&& field -) -: - regIOobject(move(field)), - Field(move(field)) -{} - - -// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * // - -template -Foam::GlobalIOField::~GlobalIOField() -{} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -template -bool Foam::GlobalIOField::readData(Istream& is) -{ - is >> *this; - return is.good(); -} - - -template -bool Foam::GlobalIOField::writeData(Ostream& os) const -{ - return (os << static_cast&>(*this)).good(); -} - - -// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // - -template -void Foam::GlobalIOField::operator=(const GlobalIOField& rhs) -{ - Field::operator=(rhs); -} - - -template -void Foam::GlobalIOField::operator=(GlobalIOField&& rhs) -{ - Field::operator=(move(rhs)); -} - - -template -void Foam::GlobalIOField::operator=(const Field& rhs) -{ - Field::operator=(rhs); -} - - -template -void Foam::GlobalIOField::operator=(Field&& rhs) -{ - Field::operator=(move(rhs)); -} - - -// ************************************************************************* // diff --git a/src/OpenFOAM/db/IOobjects/GlobalIOField/GlobalIOField.H b/src/OpenFOAM/db/IOobjects/GlobalIOField/GlobalIOField.H index 7bf1b36158..fcbefe312b 100644 --- a/src/OpenFOAM/db/IOobjects/GlobalIOField/GlobalIOField.H +++ b/src/OpenFOAM/db/IOobjects/GlobalIOField/GlobalIOField.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2015-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,17 +25,14 @@ Class Foam::GlobalIOField Description - IOField with global data (so optionally read from master) - -SourceFiles - GlobalIOField.C + A primitive field of type \ with automated input and output. \*---------------------------------------------------------------------------*/ #ifndef GlobalIOField_H #define GlobalIOField_H -#include "regIOobject.H" +#include "GlobalIOList.H" #include "Field.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -44,68 +41,31 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class GlobalIOField Declaration + Class GlobalIOField Declaration \*---------------------------------------------------------------------------*/ template class GlobalIOField : - public regIOobject, - public Field + public GlobalIOListBase { public: + //- Runtime type information TypeName("Field"); // Constructors - //- Construct from IOobject - GlobalIOField(const IOobject&); - - //- Construct from IOobject and size (does not set values) - GlobalIOField(const IOobject&, const label size); - - //- Construct from components - GlobalIOField(const IOobject&, const Field&); - - //- Move construct by transferring the Field contents - GlobalIOField(const IOobject&, Field&&); - - //- Copy constructor - GlobalIOField(const GlobalIOField&); - - //- Move constructor - GlobalIOField(GlobalIOField&&); - - - //- Destructor - virtual ~GlobalIOField(); - - - // Member Functions - - //- Is object global - virtual bool global() const - { - return true; - } - - //- ReadData function required for regIOobject read operation - virtual bool readData(Istream&); - - //- WriteData function required for regIOobject write operation - bool writeData(Ostream&) const; + //- Inherit constructors + using GlobalIOListBase::GlobalIOListBase; // Member Operators - void operator=(const GlobalIOField&); - void operator=(GlobalIOField&&); - - void operator=(const Field&); - void operator=(Field&&); + //- Inherit assignment operators + using GlobalIOListBase::operator=; }; @@ -115,12 +75,6 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#ifdef NoRepository -# include "GlobalIOField.C" -#endif - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - #endif // ************************************************************************* // diff --git a/src/OpenFOAM/db/IOobjects/GlobalIOField/GlobalIOFields.C b/src/OpenFOAM/db/IOobjects/GlobalIOField/GlobalIOFields.C deleted file mode 100644 index 731df82c3e..0000000000 --- a/src/OpenFOAM/db/IOobjects/GlobalIOField/GlobalIOFields.C +++ /dev/null @@ -1,45 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2017-2020 OpenFOAM Foundation - \\/ 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 . - -\*---------------------------------------------------------------------------*/ - -#include "GlobalIOFields.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - defineTemplateTypeNameWithName(labelGlobalIOField, "labelField"); - defineTemplateTypeNameWithName(scalarGlobalIOField, "scalarField"); - defineTemplateTypeNameWithName(vectorGlobalIOField, "vectorField"); - defineTemplateTypeNameWithName - ( - sphericalTensorGlobalIOField, - "sphericalTensorField" - ); - defineTemplateTypeNameWithName(symmTensorGlobalIOField, "symmTensorField"); - defineTemplateTypeNameWithName(tensorGlobalIOField, "tensorField"); -} - - -// ************************************************************************* // diff --git a/src/OpenFOAM/db/IOobjects/GlobalIOField/GlobalIOFields.H b/src/OpenFOAM/db/IOobjects/GlobalIOField/GlobalIOFields.H deleted file mode 100644 index 7ebb5ab13a..0000000000 --- a/src/OpenFOAM/db/IOobjects/GlobalIOField/GlobalIOFields.H +++ /dev/null @@ -1,74 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2020 OpenFOAM Foundation - \\/ 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 . - -\*---------------------------------------------------------------------------*/ - -#include "primitiveFields.H" -#include "GlobalIOField.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - typedef GlobalIOField