Skip to content
Snippets Groups Projects
Commit 79fafda2 authored by Andrew Heather's avatar Andrew Heather Committed by Mark OLESEN
Browse files

ENH: Cloud - added function to read cloud fields from disk to obr

parent f5f93e81
Branches
Tags
1 merge request!503sampledSets - enable writer construction from dictionary; glTF export
......@@ -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
......
......@@ -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
{
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment