From a96fb65963b5781614ef086338ce36f11f3b16fe Mon Sep 17 00:00:00 2001 From: Martin Beaudoin Date: Sun, 1 Apr 2012 16:28:33 -0400 Subject: [PATCH] Add a componentsTurbo option to foamCalc. Will compute radial, tangential and z components from a vector/velocity field --- .../foamCalcFunctions/Make/files | 1 + .../field/componentsTurbo/componentsTurbo.C | 122 +++++++++++++++ .../field/componentsTurbo/componentsTurbo.H | 146 ++++++++++++++++++ .../writeComponentTurboFields.C | 121 +++++++++++++++ 4 files changed, 390 insertions(+) create mode 100644 src/postProcessing/foamCalcFunctions/field/componentsTurbo/componentsTurbo.C create mode 100644 src/postProcessing/foamCalcFunctions/field/componentsTurbo/componentsTurbo.H create mode 100644 src/postProcessing/foamCalcFunctions/field/componentsTurbo/writeComponentTurboFields.C diff --git a/src/postProcessing/foamCalcFunctions/Make/files b/src/postProcessing/foamCalcFunctions/Make/files index 55297ca8c..085fa12fc 100644 --- a/src/postProcessing/foamCalcFunctions/Make/files +++ b/src/postProcessing/foamCalcFunctions/Make/files @@ -2,6 +2,7 @@ calcType/calcType.C calcType/newCalcType.C field/components/components.C +field/componentsTurbo/componentsTurbo.C field/mag/mag.C field/magSqr/magSqr.C field/magGrad/magGrad.C diff --git a/src/postProcessing/foamCalcFunctions/field/componentsTurbo/componentsTurbo.C b/src/postProcessing/foamCalcFunctions/field/componentsTurbo/componentsTurbo.C new file mode 100644 index 000000000..6fb84da65 --- /dev/null +++ b/src/postProcessing/foamCalcFunctions/field/componentsTurbo/componentsTurbo.C @@ -0,0 +1,122 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Author + Martin Beaudoin, Hydro-Quebec, 2012. All rights reserved + +\*---------------------------------------------------------------------------*/ + +#include "componentsTurbo.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + namespace calcTypes + { + defineTypeNameAndDebug(componentsTurbo, 0); + addToRunTimeSelectionTable(calcType, componentsTurbo, dictionary); + } +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::calcTypes::componentsTurbo::componentsTurbo() +: + calcType() +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::calcTypes::componentsTurbo::~componentsTurbo() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::calcTypes::componentsTurbo::init() +{ + argList::validArgs.append("componentsTurbo"); + argList::validArgs.append("fieldName"); + //argList::validOptions.insert("rotationAxis", "rotation axis"); + //argList::validOptions.insert("rotationAxisOrigin", "rotation axis origin"); +} + + +void Foam::calcTypes::componentsTurbo::preCalc +( + const argList& args, + const Time& runTime, + const fvMesh& mesh +) +{} + + +void Foam::calcTypes::componentsTurbo::calc +( + const argList& args, + const Time& runTime, + const fvMesh& mesh +) +{ + const word& fieldName = args.additionalArgs()[1]; + + IOobject fieldHeader + ( + fieldName, + runTime.timeName(), + mesh, + IOobject::MUST_READ + ); + + // Check field exists + if (fieldHeader.headerOk()) + { + bool processed = false; + + writeComponentFields(fieldHeader, mesh, processed); + //writeComponentFields(fieldHeader, mesh, processed); + //writeComponentFields(fieldHeader, mesh, processed); + //writeComponentFields(fieldHeader, mesh, processed); + + if (!processed) + { + FatalError + << "Unable to process " << fieldName << nl + << "No call to componentsTurbo for fields of type " + << fieldHeader.headerClassName() << nl << nl + << exit(FatalError); + } + } + else + { + Info<< " No " << fieldName << endl; + } +} + + +// ************************************************************************* // diff --git a/src/postProcessing/foamCalcFunctions/field/componentsTurbo/componentsTurbo.H b/src/postProcessing/foamCalcFunctions/field/componentsTurbo/componentsTurbo.H new file mode 100644 index 000000000..e0e9ba5f5 --- /dev/null +++ b/src/postProcessing/foamCalcFunctions/field/componentsTurbo/componentsTurbo.H @@ -0,0 +1,146 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::calcTypes::componentsTurbo + +Description + Writes turbo scalar fields corresponding to radial, tangential and z + components of the supplied vector field (name) (usually a velocity field) + for each time. + + Caveat: the current implementation expect the vector field to be centered + around the z-axis. + +Author + Martin Beaudoin, Hydro-Quebec, 2012. All rights reserved + +SourceFiles + componentsTurbo.C + +\*---------------------------------------------------------------------------*/ + +#ifndef componentsTurbo_H +#define componentsTurbo_H + +#include "calcType.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +namespace calcTypes +{ + +/*---------------------------------------------------------------------------*\ + Class componentsTurbo Declaration +\*---------------------------------------------------------------------------*/ + +class componentsTurbo +: + public calcType +{ + // Private Member Functions + + //- Disallow default bitwise copy construct + componentsTurbo(const componentsTurbo&); + + //- Disallow default bitwise assignment + void operator=(const componentsTurbo&); + + +protected: + + // Member Functions + + // Calculation routines + + //- Initialise - typically setting static variables, + // e.g. command line arguments + virtual void init(); + + //- Pre-time loop calculations + virtual void preCalc + ( + const argList& args, + const Time& runTime, + const fvMesh& mesh + ); + + //- Time loop calculations + virtual void calc + ( + const argList& args, + const Time& runTime, + const fvMesh& mesh + ); + + + // I-O + + //- Write component fields + template + void writeComponentFields + ( + const IOobject& header, + const fvMesh& mesh, + bool& processed + ); + + +public: + + //- Runtime type information + TypeName("componentsTurbo"); + + + // Constructors + + //- Construct null + componentsTurbo(); + + + // Destructor + + virtual ~componentsTurbo(); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace calcTypes +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "writeComponentTurboFields.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/postProcessing/foamCalcFunctions/field/componentsTurbo/writeComponentTurboFields.C b/src/postProcessing/foamCalcFunctions/field/componentsTurbo/writeComponentTurboFields.C new file mode 100644 index 000000000..2899e75c4 --- /dev/null +++ b/src/postProcessing/foamCalcFunctions/field/componentsTurbo/writeComponentTurboFields.C @@ -0,0 +1,121 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +template +void Foam::calcTypes::componentsTurbo::writeComponentFields +( + const IOobject& header, + const fvMesh& mesh, + bool& processed +) +{ + typedef GeometricField fieldType; + + if (header.headerClassName() == fieldType::typeName) + { + const char* turboComponentNames[] = {"radial", "tangential", "z"}; + + Info<< " Reading " << header.name() << endl; + fieldType field(header, mesh); + fieldType turboField(field); + + vectorField cellCentres(mesh.cellCentres()); + cellCentres.replace(vector::Z, scalar(0)); + + const scalarField r = mag(cellCentres); + + forAll(turboField, fI) + { + turboField[fI].replace(vector::X, + ( + cellCentres[fI].component(vector::X)*field[fI].component(vector::X) + + cellCentres[fI].component(vector::Y)*field[fI].component(vector::Y) + ) / r[fI] + ); + + turboField[fI].replace(vector::Y, + ( + -cellCentres[fI].component(vector::Y)*field[fI].component(vector::X) + + cellCentres[fI].component(vector::X)*field[fI].component(vector::Y) + ) / r[fI] + ); + } + + // Convert boundary fields + forAll(turboField.boundaryField(), patchI) + { + fvPatchField& bf = field.boundaryField()[patchI]; + fvPatchField& tbf = turboField.boundaryField()[patchI]; + + vectorField faceCentres(tbf.patch().Cf()); + + faceCentres.replace(vector::Z, scalar(0)); + + const scalarField r = mag(faceCentres); + + forAll(tbf, tbfI) + { + tbf[tbfI].replace(vector::X, + ( + faceCentres[tbfI].component(vector::X)*bf[tbfI].component(vector::X) + + faceCentres[tbfI].component(vector::Y)*bf[tbfI].component(vector::Y) + ) / r[tbfI] + ); + + tbf[tbfI].replace(vector::Y, + ( + -faceCentres[tbfI].component(vector::Y)*bf[tbfI].component(vector::X) + + faceCentres[tbfI].component(vector::X)*bf[tbfI].component(vector::Y) + ) / r[tbfI] + ); + } + } + + for (direction i=0; i