diff --git a/src/lagrangian/basic/Cloud/Cloud.H b/src/lagrangian/basic/Cloud/Cloud.H index 2fdb8fecf4..06b5d9a926 100644 --- a/src/lagrangian/basic/Cloud/Cloud.H +++ b/src/lagrangian/basic/Cloud/Cloud.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -45,6 +45,7 @@ SourceFiles #include "CompactIOField.H" #include "polyMesh.H" #include "bitSet.H" +#include "wordRes.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -240,6 +241,21 @@ public: const CompactIOField, DataType>& data ) const; + //- Helper function to store a cloud field on its registry + template + bool readStoreFile + ( + const IOobject& io, + const IOobject& ioNew + ) const; + + //- Read from files into objectRegistry + void readFromFiles + ( + objectRegistry& obr, + const wordRes& selectFields + ) const; + // Write diff --git a/src/lagrangian/basic/Cloud/CloudIO.C b/src/lagrangian/basic/Cloud/CloudIO.C index 858565aff7..5a34a2891e 100644 --- a/src/lagrangian/basic/Cloud/CloudIO.C +++ b/src/lagrangian/basic/Cloud/CloudIO.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017, 2020 OpenFOAM Foundation - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -30,6 +30,7 @@ License #include "Time.H" #include "IOPosition.H" #include "IOdictionary.H" +#include "IOobjectList.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -243,6 +244,80 @@ void Foam::Cloud::checkFieldFieldIOobject } +template +template +bool Foam::Cloud::readStoreFile +( + const IOobject& io, + const IOobject& ioNew +) const +{ + if (io.headerClassName() == IOField::typeName) + { + IOField fld(io); + auto* fldNewPtr = new IOField(ioNew, std::move(fld)); + return fldNewPtr->store(); + } + + return false; +} + + +template +void Foam::Cloud::readFromFiles +( + objectRegistry& obr, + const wordRes& selectFields +) const +{ + IOobjectList cloudObjects + ( + *this, + time().timeName(), + "", + IOobject::MUST_READ, + IOobject::NO_WRITE, + false + ); + + forAllIters(cloudObjects, iter) + { + if (selectFields.size() && !selectFields.match(iter()->name())) + { + continue; + } + + IOobject ioNew + ( + iter()->name(), + time().timeName(), + obr, + IOobject::NO_READ, + IOobject::NO_WRITE + ); + + auto& object = *iter(); + + const bool stored + ( + readStoreFile