Skip to content
Snippets Groups Projects
Commit 4a0c74d2 authored by Andrew Heather's avatar Andrew Heather
Browse files

ENH: readFields function object - read fields on construction

parent d13b2aac
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -30,7 +30,7 @@ License
namespace Foam
{
defineTypeNameAndDebug(readFields, 0);
defineTypeNameAndDebug(readFields, 0);
}
......@@ -54,6 +54,9 @@ Foam::readFields::readFields
if (isA<fvMesh>(obr_))
{
read(dict);
// Fields should all be present from start time so read on construction
execute();
}
else
{
......@@ -87,16 +90,28 @@ void Foam::readFields::execute()
{
if (active_)
{
if (log_) Info << type() << " " << name_ << ":" << nl;
bool loaded = false;
forAll(fieldSet_, fieldI)
{
const word& fieldName = fieldSet_[fieldI];
// If necessary load field
loadField<scalar>(fieldName);
loadField<vector>(fieldName);
loadField<sphericalTensor>(fieldName);
loadField<symmTensor>(fieldName);
loadField<tensor>(fieldName);
// Load field if necessary
loaded = loadField<scalar>(fieldName) || loaded;
loaded = loadField<vector>(fieldName) || loaded;
loaded = loadField<sphericalTensor>(fieldName) || loaded;
loaded = loadField<symmTensor>(fieldName) || loaded;
loaded = loadField<tensor>(fieldName) || loaded;
}
if (log_)
{
if (!loaded)
{
Info<< " no fields loaded" << endl;
}
Info<< endl;
}
}
}
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -106,7 +106,7 @@ protected:
// Protected Member Functions
template<class Type>
void loadField(const word&) const;
bool loadField(const word&) const;
private:
......
......@@ -31,7 +31,7 @@ License
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
void Foam::readFields::loadField(const word& fieldName) const
bool Foam::readFields::loadField(const word& fieldName) const
{
typedef GeometricField<Type, fvPatchField, volMesh> vfType;
typedef GeometricField<Type, fvsPatchField, surfaceMesh> sfType;
......@@ -77,6 +77,7 @@ void Foam::readFields::loadField(const word& fieldName) const
if (log_) Info<< " Reading " << fieldName << endl;
vfType* vfPtr = new vfType(fieldHeader, mesh);
mesh.objectRegistry::store(vfPtr);
return true;
}
else if
(
......@@ -88,8 +89,11 @@ void Foam::readFields::loadField(const word& fieldName) const
if (log_) Info<< " Reading " << fieldName << endl;
sfType* sfPtr = new sfType(fieldHeader, mesh);
mesh.objectRegistry::store(sfPtr);
return true;
}
}
return false;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment