From 149a190e22b99aaebf09c1a85b2f64e676762477 Mon Sep 17 00:00:00 2001 From: andy Date: Wed, 7 Apr 2010 11:40:57 +0100 Subject: [PATCH] ENH: Added readFields function object - function object to read fields and register them on the mesh database for further post-processing --- .../functionObjects/field/Make/files | 3 + .../field/readFields/IOreadFields.H | 49 ++++++ .../field/readFields/postProcessingDict | 52 ++++++ .../field/readFields/readFields.C | 116 +++++++++++++ .../field/readFields/readFields.H | 154 ++++++++++++++++++ .../readFields/readFieldsFunctionObject.C | 42 +++++ .../readFields/readFieldsFunctionObject.H | 54 ++++++ .../field/readFields/readFieldsTemplates.C | 94 +++++++++++ 8 files changed, 564 insertions(+) create mode 100644 src/postProcessing/functionObjects/field/readFields/IOreadFields.H create mode 100644 src/postProcessing/functionObjects/field/readFields/postProcessingDict create mode 100644 src/postProcessing/functionObjects/field/readFields/readFields.C create mode 100644 src/postProcessing/functionObjects/field/readFields/readFields.H create mode 100644 src/postProcessing/functionObjects/field/readFields/readFieldsFunctionObject.C create mode 100644 src/postProcessing/functionObjects/field/readFields/readFieldsFunctionObject.H create mode 100644 src/postProcessing/functionObjects/field/readFields/readFieldsTemplates.C diff --git a/src/postProcessing/functionObjects/field/Make/files b/src/postProcessing/functionObjects/field/Make/files index 6195b98a41..bfed281015 100644 --- a/src/postProcessing/functionObjects/field/Make/files +++ b/src/postProcessing/functionObjects/field/Make/files @@ -12,6 +12,9 @@ fieldValues/faceSource/faceSourceFunctionObject.C fieldValues/cellSource/cellSource.C fieldValues/cellSource/cellSourceFunctionObject.C +readFields/readFields.C +readFields/readFieldsFunctionObject.C + streamLine/streamLine.C streamLine/streamLineParticle.C streamLine/streamLineParticleCloud.C diff --git a/src/postProcessing/functionObjects/field/readFields/IOreadFields.H b/src/postProcessing/functionObjects/field/readFields/IOreadFields.H new file mode 100644 index 0000000000..b3bdfa521e --- /dev/null +++ b/src/postProcessing/functionObjects/field/readFields/IOreadFields.H @@ -0,0 +1,49 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd. + \\/ 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 . + +Typedef + Foam::IOreadFields + +Description + Instance of the generic IOOutputFilter for readFields. + +\*---------------------------------------------------------------------------*/ + +#ifndef IOreadFields_H +#define IOreadFields_H + +#include "readFields.H" +#include "IOOutputFilter.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + typedef IOOutputFilter IOreadFields; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/field/readFields/postProcessingDict b/src/postProcessing/functionObjects/field/readFields/postProcessingDict new file mode 100644 index 0000000000..aa304a259f --- /dev/null +++ b/src/postProcessing/functionObjects/field/readFields/postProcessingDict @@ -0,0 +1,52 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: 1.6 | +| \\ / A nd | Web: www.OpenFOAM.org | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + location "system"; + object postProcessingDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +functions +( + readFields1 + { + type readFields; + functionObjectLibs ("libfieldFunctionObjects.so"); + enabled true; + outputControl timeStep; + outputInterval 1; + fields + ( + interpolateU + ); + } + faceObj2 + { + type faceSource; + functionObjectLibs ("libfieldFunctionObjects.so"); + enabled true; + outputControl timeStep; + outputInterval 1; + log true; + valueOutput true; + source faceZone; + sourceName f0; + operation areaAverage; + fields + ( + interpolateU + ); + } +); + + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/field/readFields/readFields.C b/src/postProcessing/functionObjects/field/readFields/readFields.C new file mode 100644 index 0000000000..17b46f1a52 --- /dev/null +++ b/src/postProcessing/functionObjects/field/readFields/readFields.C @@ -0,0 +1,116 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd. + \\/ 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 "readFields.H" +#include "dictionary.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(readFields, 0); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::readFields::readFields +( + const word& name, + const objectRegistry& obr, + const dictionary& dict, + const bool loadFromFiles +) +: + name_(name), + obr_(obr), + active_(true), + fieldSet_() +{ + // Check if the available mesh is an fvMesh otherise deactivate + if (!isA(obr_)) + { + active_ = false; + WarningIn + ( + "readFields::readFields" + "(" + "const word&, " + "const objectRegistry&, " + "const dictionary&, " + "const bool" + ")" + ) << "No fvMesh available, deactivating." + << endl; + } + + read(dict); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::readFields::~readFields() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::readFields::read(const dictionary& dict) +{ + if (active_) + { + dict.lookup("fields") >> fieldSet_; + } +} + + +void Foam::readFields::execute() +{ + Info<< type() << " " << name_ << ":" << nl; + forAll(fieldSet_, fieldI) + { + setField(fieldSet_[fieldI]); + setField(fieldSet_[fieldI]); + setField(fieldSet_[fieldI]); + setField(fieldSet_[fieldI]); + setField(fieldSet_[fieldI]); + } +} + + +void Foam::readFields::end() +{ + // Do nothing +} + + +void Foam::readFields::write() +{ + // Do nothing +} + + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/field/readFields/readFields.H b/src/postProcessing/functionObjects/field/readFields/readFields.H new file mode 100644 index 0000000000..52ee6a47ae --- /dev/null +++ b/src/postProcessing/functionObjects/field/readFields/readFields.H @@ -0,0 +1,154 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd. + \\/ 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::readFields + +Description + Reads fields from the time folders and adds them to the mesh database + for further post-processing. + +SourceFiles + readFields.C + IOreadFields.H + +\*---------------------------------------------------------------------------*/ + +#ifndef readFields_H +#define readFields_H + +#include "OFstream.H" +#include "pointFieldFwd.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward declaration of classes +class objectRegistry; +class dictionary; +class mapPolyMesh; + +/*---------------------------------------------------------------------------*\ + Class readFields Declaration +\*---------------------------------------------------------------------------*/ + +class readFields +{ +protected: + + // Protected data + + //- Name of this set of readFields object + word name_; + + const objectRegistry& obr_; + + //- on/off switch + bool active_; + + //- Fields to assess min/max + wordList fieldSet_; + + + // Protected Member Functions + + //- Disallow default bitwise copy construct + readFields(const readFields&); + + //- Disallow default bitwise assignment + void operator=(const readFields&); + + template + void setField(const word& fieldName); + + +public: + + //- Runtime type information + TypeName("readFields"); + + + // Constructors + + //- Construct for given objectRegistry and dictionary. + // Allow the possibility to load fields from files + readFields + ( + const word& name, + const objectRegistry&, + const dictionary&, + const bool loadFromFiles = false + ); + + + //- Destructor + virtual ~readFields(); + + + // Member Functions + + //- Return name of the readFields object + virtual const word& name() const + { + return name_; + } + + //- Read the field min/max data + virtual void read(const dictionary&); + + //- Execute, currently does nothing + virtual void execute(); + + //- Execute at the final time-loop, currently does nothing + virtual void end(); + + //- Write + virtual void write(); + + //- Update for changes of mesh + virtual void updateMesh(const mapPolyMesh&) + {} + + //- Update for changes of mesh + virtual void movePoints(const pointField&) + {} +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "readFieldsTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/field/readFields/readFieldsFunctionObject.C b/src/postProcessing/functionObjects/field/readFields/readFieldsFunctionObject.C new file mode 100644 index 0000000000..970dfe24c2 --- /dev/null +++ b/src/postProcessing/functionObjects/field/readFields/readFieldsFunctionObject.C @@ -0,0 +1,42 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd. + \\/ 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 "readFieldsFunctionObject.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineNamedTemplateTypeNameAndDebug(readFieldsFunctionObject, 0); + + addToRunTimeSelectionTable + ( + functionObject, + readFieldsFunctionObject, + dictionary + ); +} + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/field/readFields/readFieldsFunctionObject.H b/src/postProcessing/functionObjects/field/readFields/readFieldsFunctionObject.H new file mode 100644 index 0000000000..9ddca2a65d --- /dev/null +++ b/src/postProcessing/functionObjects/field/readFields/readFieldsFunctionObject.H @@ -0,0 +1,54 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd. + \\/ 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 . + +Typedef + Foam::readFieldsFunctionObject + +Description + FunctionObject wrapper around readFields to allow them to be created via + the functions entry within controlDict. + +SourceFiles + readFieldsFunctionObject.C + +\*---------------------------------------------------------------------------*/ + +#ifndef readFieldsFunctionObject_H +#define readFieldsFunctionObject_H + +#include "readFields.H" +#include "OutputFilterFunctionObject.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + typedef OutputFilterFunctionObject + readFieldsFunctionObject; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/field/readFields/readFieldsTemplates.C b/src/postProcessing/functionObjects/field/readFields/readFieldsTemplates.C new file mode 100644 index 0000000000..f78859d769 --- /dev/null +++ b/src/postProcessing/functionObjects/field/readFields/readFieldsTemplates.C @@ -0,0 +1,94 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd. + \\/ 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 "readFields.H" +#include "volFields.H" +#include "surfaceFields.H" +#include "Time.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +void Foam::readFields::setField(const word& fieldName) +{ + typedef GeometricField vfType; + typedef GeometricField sfType; + + if (obr_.foundObject(fieldName)) + { + if (debug) + { + Info<< "Field " << fieldName << " already in database" << endl; + } + + vfType& vf = const_cast(obr_.lookupObject(fieldName)); + vf.checkOut(); + } + if (obr_.foundObject(fieldName)) + { + if (debug) + { + Info<< "Field " << fieldName << " already in database" << endl; + } + + sfType& sf = const_cast(obr_.lookupObject(fieldName)); + sf.checkOut(); + } + + const fvMesh& mesh = refCast(obr_); + + IOobject fieldHeader + ( + fieldName, + mesh.time().timeName(), + mesh, + IOobject::MUST_READ, + IOobject::NO_WRITE + ); + + if + ( + fieldHeader.headerOk() + && fieldHeader.headerClassName() == vfType::typeName + ) + { + // store field on the mesh database + Info<< " Reading " << fieldName << endl; + obr_.store(new vfType(fieldHeader, mesh)); + } + else if + ( + fieldHeader.headerOk() + && fieldHeader.headerClassName() == sfType::typeName + ) + { + // store field on the mesh database + Info<< " Reading " << fieldName << endl; + obr_.store(new sfType(fieldHeader, mesh)); + } +} + + +// ************************************************************************* //