From 5d5a94cfd061599aa5e9bd8cc09234abca1fd462 Mon Sep 17 00:00:00 2001 From: andy Date: Tue, 13 Dec 2011 15:12:04 +0000 Subject: [PATCH] ENH: Added new processorField function object - outputs field of procesor ID --- .../functionObjects/field/Make/files | 3 + .../field/processorField/IOprocessorField.H | 49 ++++++ .../field/processorField/postProcessingDict | 35 ++++ .../field/processorField/processorField.C | 120 +++++++++++++ .../field/processorField/processorField.H | 146 ++++++++++++++++ .../processorFieldFunctionObject.C | 42 +++++ .../processorFieldFunctionObject.H | 54 ++++++ .../processorField/processorFieldTemplates.C | 158 ++++++++++++++++++ 8 files changed, 607 insertions(+) create mode 100644 src/postProcessing/functionObjects/field/processorField/IOprocessorField.H create mode 100644 src/postProcessing/functionObjects/field/processorField/postProcessingDict create mode 100644 src/postProcessing/functionObjects/field/processorField/processorField.C create mode 100644 src/postProcessing/functionObjects/field/processorField/processorField.H create mode 100644 src/postProcessing/functionObjects/field/processorField/processorFieldFunctionObject.C create mode 100644 src/postProcessing/functionObjects/field/processorField/processorFieldFunctionObject.H create mode 100644 src/postProcessing/functionObjects/field/processorField/processorFieldTemplates.C diff --git a/src/postProcessing/functionObjects/field/Make/files b/src/postProcessing/functionObjects/field/Make/files index 9d465d2663..1ea75cf3ff 100644 --- a/src/postProcessing/functionObjects/field/Make/files +++ b/src/postProcessing/functionObjects/field/Make/files @@ -18,6 +18,9 @@ fieldValues/cellSource/cellSourceFunctionObject.C nearWallFields/nearWallFields.C nearWallFields/nearWallFieldsFunctionObject.C +processorField/processorField.C +processorField/processorFieldFunctionObject.C + readFields/readFields.C readFields/readFieldsFunctionObject.C diff --git a/src/postProcessing/functionObjects/field/processorField/IOprocessorField.H b/src/postProcessing/functionObjects/field/processorField/IOprocessorField.H new file mode 100644 index 0000000000..4c3e423972 --- /dev/null +++ b/src/postProcessing/functionObjects/field/processorField/IOprocessorField.H @@ -0,0 +1,49 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\/ 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::IOprocessorField + +Description + Instance of the generic IOOutputFilter for processorField. + +\*---------------------------------------------------------------------------*/ + +#ifndef IOprocessorField_H +#define IOprocessorField_H + +#include "processorField.H" +#include "IOOutputFilter.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + typedef IOOutputFilter IOprocessorField; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/field/processorField/postProcessingDict b/src/postProcessing/functionObjects/field/processorField/postProcessingDict new file mode 100644 index 0000000000..683e70c493 --- /dev/null +++ b/src/postProcessing/functionObjects/field/processorField/postProcessingDict @@ -0,0 +1,35 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: dev | +| \\ / A nd | Web: www.OpenFOAM.org | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object postProcessingDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +functions +{ + processorField1 + { + // Type of functionObject + type processorField; + + // Where to load it from (if not already in solver) + functionObjectLibs ("libfieldFunctionObjects.so"); + + // Function object enabled flag + enabled true; + + // When to output the average fields + outputControl outputTime; + } +} + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/field/processorField/processorField.C b/src/postProcessing/functionObjects/field/processorField/processorField.C new file mode 100644 index 0000000000..87794ba92e --- /dev/null +++ b/src/postProcessing/functionObjects/field/processorField/processorField.C @@ -0,0 +1,120 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\/ 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 "processorField.H" +#include "dictionary.H" +#include "Pstream.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +defineTypeNameAndDebug(Foam::processorField, 0); + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::processorField::processorField +( + const word& name, + const objectRegistry& obr, + const dictionary& dict, + const bool loadFromFiles +) +: + name_(name), + obr_(obr), + active_(true) +{ + // Check if the available mesh is an fvMesh otherise deactivate + if (!isA(obr_)) + { + active_ = false; + WarningIn + ( + "processorField::processorField" + "(" + "const word&, " + "const objectRegistry&, " + "const dictionary&, " + "const bool" + ")" + ) << "No fvMesh available, deactivating." + << endl; + } + + read(dict); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::processorField::~processorField() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::processorField::read(const dictionary& dict) +{ + // do nothing +} + + +void Foam::processorField::execute() +{ + // Do nothing +} + + +void Foam::processorField::end() +{ + // Do nothing +} + + +void Foam::processorField::write() +{ + if (active_) + { + const fvMesh& mesh = refCast(obr_); + volScalarField procField + ( + IOobject + ( + "processorID", + mesh.time().timeName(), + mesh, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + mesh, + dimensionedScalar("procI", dimless, Pstream::myProcNo()) + ); + + procField.write(); + } +} + + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/field/processorField/processorField.H b/src/postProcessing/functionObjects/field/processorField/processorField.H new file mode 100644 index 0000000000..a51b17f969 --- /dev/null +++ b/src/postProcessing/functionObjects/field/processorField/processorField.H @@ -0,0 +1,146 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\/ 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::processorField + +Description + Writes a scalar field whose value is the local processor ID. Output + field name is processorID. + +SourceFiles + processorField.C + IOprocessorField.H + +\*---------------------------------------------------------------------------*/ + +#ifndef processorField_H +#define processorField_H + +#include "OFstream.H" +#include "pointFieldFwd.H" +#include "volFields.H" +#include "surfaceFields.H" +#include "coordinateSystem.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward declaration of classes +class objectRegistry; +class dictionary; +class mapPolyMesh; + +/*---------------------------------------------------------------------------*\ + Class processorField Declaration +\*---------------------------------------------------------------------------*/ + +class processorField +{ +protected: + + // Protected data + + //- Name of this set of nearWallFields object + word name_; + + //- Reference to the database + const objectRegistry& obr_; + + //- on/off switch + bool active_; + + + // Protected Member Functions + + //- Disallow default bitwise copy construct + processorField(const processorField&); + + //- Disallow default bitwise assignment + void operator=(const processorField&); + + +public: + + //- Runtime type information + TypeName("processorField"); + + + // Constructors + + //- Construct for given objectRegistry and dictionary. + // Allow the possibility to load fields from files + processorField + ( + const word& name, + const objectRegistry&, + const dictionary&, + const bool loadFromFiles = false + ); + + + //- Destructor + virtual ~processorField(); + + + // Member Functions + + //- Return name of the processorField object + virtual const word& name() const + { + return name_; + } + + //- Read the input 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 + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/field/processorField/processorFieldFunctionObject.C b/src/postProcessing/functionObjects/field/processorField/processorFieldFunctionObject.C new file mode 100644 index 0000000000..52fb9eafce --- /dev/null +++ b/src/postProcessing/functionObjects/field/processorField/processorFieldFunctionObject.C @@ -0,0 +1,42 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\/ 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 "processorFieldFunctionObject.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineNamedTemplateTypeNameAndDebug(processorFieldFunctionObject, 0); + + addToRunTimeSelectionTable + ( + functionObject, + processorFieldFunctionObject, + dictionary + ); +} + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/field/processorField/processorFieldFunctionObject.H b/src/postProcessing/functionObjects/field/processorField/processorFieldFunctionObject.H new file mode 100644 index 0000000000..29b9b29c5b --- /dev/null +++ b/src/postProcessing/functionObjects/field/processorField/processorFieldFunctionObject.H @@ -0,0 +1,54 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\/ 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::processorFieldFunctionObject + +Description + FunctionObject wrapper around processorField to allow + them to be created via the functions entry within controlDict. + +SourceFiles + processorFieldFunctionObject.C + +\*---------------------------------------------------------------------------*/ + +#ifndef processorFieldFunctionObject_H +#define processorFieldFunctionObject_H + +#include "processorField.H" +#include "OutputFilterFunctionObject.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + typedef OutputFilterFunctionObject + processorFieldFunctionObject; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/postProcessing/functionObjects/field/processorField/processorFieldTemplates.C b/src/postProcessing/functionObjects/field/processorField/processorFieldTemplates.C new file mode 100644 index 0000000000..ac190e298b --- /dev/null +++ b/src/postProcessing/functionObjects/field/processorField/processorFieldTemplates.C @@ -0,0 +1,158 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\/ 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 "processorField.H" +#include "volFields.H" +#include "surfaceFields.H" +#include "Time.H" +#include "transformGeometricField.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +void Foam::processorField::transformField +( + const Type& field +) const +{ + const word& fieldName = field.name() + "Transformed"; + + dimensionedTensor R("R", field.dimensions(), coordSys_.R()); + + if (obr_.foundObject(fieldName)) + { + Type& transField = + const_cast(obr_.lookupObject(fieldName)); + + transField == field; + + forAll(field, i) + { + Foam::transform(transField, R, transField); + } + + transField.write(); + } + else + { + Type& transField = obr_.store + ( + new Type + ( + IOobject + ( + fieldName, + obr_.time().timeName(), + obr_, + IOobject::READ_IF_PRESENT, + IOobject::NO_WRITE + ), + field + ) + ); + + forAll(field, i) + { + Foam::transform(transField, R, transField); + } + + transField.write(); + } +} + + +template +void Foam::processorField::transform +( + const word& fieldName +) const +{ + typedef GeometricField vfType; + typedef GeometricField sfType; + + if (obr_.foundObject(fieldName)) + { + if (debug) + { + Info<< type() << ": Field " << fieldName << " already in database" + << endl; + } + + transformField(obr_.lookupObject(fieldName)); + } + else if (obr_.foundObject(fieldName)) + { + if (debug) + { + Info<< type() << ": Field " << fieldName << " already in database" + << endl; + } + + transformField(obr_.lookupObject(fieldName)); + } + else + { + IOobject fieldHeader + ( + fieldName, + obr_.time().timeName(), + obr_, + IOobject::MUST_READ, + IOobject::NO_WRITE + ); + + if + ( + fieldHeader.headerOk() + && fieldHeader.headerClassName() == vfType::typeName + ) + { + if (debug) + { + Info<< type() << ": Field " << fieldName << " read from file" + << endl; + } + + transformField(obr_.lookupObject(fieldName)); + } + else if + ( + fieldHeader.headerOk() + && fieldHeader.headerClassName() == sfType::typeName + ) + { + if (debug) + { + Info<< type() << ": Field " << fieldName << " read from file" + << endl; + } + + transformField(obr_.lookupObject(fieldName)); + } + } +} + + +// ************************************************************************* //