diff --git a/src/lagrangian/basic/Cloud/Cloud.H b/src/lagrangian/basic/Cloud/Cloud.H index 2fdb8fecf41f7855a0763cdf9db0f268a7cbdfb8..06b5d9a926972114873b0f85556d755ff9277a07 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<Field<DataType>, DataType>& data ) const; + //- Helper function to store a cloud field on its registry + template<class Type> + 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 858565aff7b348c670fb4d695e6cf9a18706ef3a..5a34a2891ee1d9584db3e2a3e67ff7eae82ee63c 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<ParticleType>::checkFieldFieldIOobject } +template<class ParticleType> +template<class Type> +bool Foam::Cloud<ParticleType>::readStoreFile +( + const IOobject& io, + const IOobject& ioNew +) const +{ + if (io.headerClassName() == IOField<Type>::typeName) + { + IOField<Type> fld(io); + auto* fldNewPtr = new IOField<Type>(ioNew, std::move(fld)); + return fldNewPtr->store(); + } + + return false; +} + + +template<class ParticleType> +void Foam::Cloud<ParticleType>::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<label>(object, ioNew) + || readStoreFile<scalar>(object, ioNew) + || readStoreFile<vector>(object, ioNew) + || readStoreFile<sphericalTensor>(object, ioNew) + || readStoreFile<symmTensor>(object, ioNew) + || readStoreFile<tensor>(object, ioNew) + ); + + if (!stored) + { + DebugInfo + << "Unhandled field type " << iter()->headerClassName() + << endl; + } + } +} + + template<class ParticleType> void Foam::Cloud<ParticleType>::writeFields() const {