From df5955a8fe9c91ccee69b14fb2c1fbb52d3784ce Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Sun, 22 May 2016 14:26:40 +0100 Subject: [PATCH] functionObjects/field/fieldCoordinateSystemTransform: simplified, standardized, rationalized --- .../fieldCoordinateSystemTransform.C | 44 +++------- .../fieldCoordinateSystemTransform.H | 34 +++----- .../fieldCoordinateSystemTransformTemplates.C | 83 ++++++++----------- 3 files changed, 59 insertions(+), 102 deletions(-) diff --git a/src/postProcessing/functionObjects/field/fieldCoordinateSystemTransform/fieldCoordinateSystemTransform.C b/src/postProcessing/functionObjects/field/fieldCoordinateSystemTransform/fieldCoordinateSystemTransform.C index 702d77983..4f1ae748d 100644 --- a/src/postProcessing/functionObjects/field/fieldCoordinateSystemTransform/fieldCoordinateSystemTransform.C +++ b/src/postProcessing/functionObjects/field/fieldCoordinateSystemTransform/fieldCoordinateSystemTransform.C @@ -24,7 +24,6 @@ License \*---------------------------------------------------------------------------*/ #include "fieldCoordinateSystemTransform.H" -#include "dictionary.H" #include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -55,23 +54,10 @@ fieldCoordinateSystemTransform const dictionary& dict ) : - functionObject(name), - obr_ - ( - runTime.lookupObject - ( - dict.lookupOrDefault("region", polyMesh::defaultRegion) - ) - ), + fvMeshFunctionObject(name, runTime, dict), fieldSet_(), - coordSys_(obr_, dict) + coordSys_(mesh_, dict) { - if (!isA(obr_)) - { - FatalErrorInFunction - << "objectRegistry is not an fvMesh" << exit(FatalError); - } - read(dict); Info<< type() << " " << name << ":" << nl @@ -89,6 +75,16 @@ Foam::functionObjects::fieldCoordinateSystemTransform:: // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +Foam::word +Foam::functionObjects::fieldCoordinateSystemTransform::transformFieldName +( + const word& fieldName +) const +{ + return fieldName + ":Transformed"; +} + + bool Foam::functionObjects::fieldCoordinateSystemTransform::read ( const dictionary& dict @@ -105,11 +101,8 @@ bool Foam::functionObjects::fieldCoordinateSystemTransform::execute const bool postProcess ) { - Info<< type() << " " << name() << " output:" << nl; - forAll(fieldSet_, fieldi) { - // If necessary load field transform(fieldSet_[fieldi]); transform(fieldSet_[fieldi]); transform(fieldSet_[fieldi]); @@ -126,22 +119,11 @@ bool Foam::functionObjects::fieldCoordinateSystemTransform::write const bool postProcess ) { - Info<< type() << " " << name() << " output:" << nl; - forAll(fieldSet_, fieldi) { - const word fieldName = fieldSet_[fieldi] + ":Transformed"; - - const regIOobject& field = - obr_.lookupObject(fieldName); - - Info<< " writing field " << field.name() << nl; - - field.write(); + fvMeshFunctionObject::write(transformFieldName(fieldSet_[fieldi])); } - Info<< endl; - return true; } diff --git a/src/postProcessing/functionObjects/field/fieldCoordinateSystemTransform/fieldCoordinateSystemTransform.H b/src/postProcessing/functionObjects/field/fieldCoordinateSystemTransform/fieldCoordinateSystemTransform.H index 7987f1382..d22b461c9 100644 --- a/src/postProcessing/functionObjects/field/fieldCoordinateSystemTransform/fieldCoordinateSystemTransform.H +++ b/src/postProcessing/functionObjects/field/fieldCoordinateSystemTransform/fieldCoordinateSystemTransform.H @@ -63,7 +63,7 @@ Description \endtable SeeAlso - Foam::functionObject + Foam::functionObjects::fvMeshFunctionObject Foam::coordinateSystem SourceFiles @@ -75,8 +75,7 @@ SourceFiles #ifndef functionObjects_fieldCoordinateSystemTransform_H #define functionObjects_fieldCoordinateSystemTransform_H -#include "functionObject.H" -#include "volFieldsFwd.H" +#include "fvMeshFunctionObject.H" #include "coordinateSystem.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -96,15 +95,12 @@ namespace functionObjects class fieldCoordinateSystemTransform : - public functionObject + public fvMeshFunctionObject { protected: // Protected data - //- Reference to the objectRegistry - const objectRegistry& obr_; - //- Fields to transform wordList fieldSet_; @@ -114,22 +110,16 @@ protected: // Protected Member Functions + //- Return the name of the transformed field + word transformFieldName(const word& fieldName) const; + + //- Transform the given field + template + void transformField(const FieldType& field); + + //- Transform the given field if has the specified element type template - void transform(const word& fieldName) const; - - template - void transformField(const Type& field) const; - - -private: - - // Private member functions - - //- Disallow default bitwise copy construct - fieldCoordinateSystemTransform(const fieldCoordinateSystemTransform&); - - //- Disallow default bitwise assignment - void operator=(const fieldCoordinateSystemTransform&); + void transform(const word& fieldName); public: diff --git a/src/postProcessing/functionObjects/field/fieldCoordinateSystemTransform/fieldCoordinateSystemTransformTemplates.C b/src/postProcessing/functionObjects/field/fieldCoordinateSystemTransform/fieldCoordinateSystemTransformTemplates.C index 334d9d628..72c01ddc2 100644 --- a/src/postProcessing/functionObjects/field/fieldCoordinateSystemTransform/fieldCoordinateSystemTransformTemplates.C +++ b/src/postProcessing/functionObjects/field/fieldCoordinateSystemTransform/fieldCoordinateSystemTransformTemplates.C @@ -26,50 +26,23 @@ License #include "fieldCoordinateSystemTransform.H" #include "volFields.H" #include "surfaceFields.H" -#include "Time.H" #include "transformGeometricField.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -template +template void Foam::functionObjects::fieldCoordinateSystemTransform::transformField ( - const Type& field -) const + const FieldType& field +) { - const word& fieldName = field.name() + ":Transformed"; + word transFieldName(transformFieldName(field.name())); - if (!obr_.foundObject(fieldName)) - { - obr_.store - ( - new Type - ( - IOobject - ( - fieldName, - obr_.time().timeName(), - obr_, - IOobject::READ_IF_PRESENT, - IOobject::NO_WRITE - ), - field - ) - ); - } - - Type& transField = - const_cast(obr_.lookupObject(fieldName)); - - transField == field; - - dimensionedTensor R("R", field.dimensions(), coordSys_.R().R()); - - Foam::transform(transField, R, transField); - - Info<< " writing field " << transField.name() << nl << endl; - - transField.write(); + store + ( + transFieldName, + Foam::transform(dimensionedTensor(coordSys_.R().R()), field) + ); } @@ -77,12 +50,12 @@ template void Foam::functionObjects::fieldCoordinateSystemTransform::transform ( const word& fieldName -) const +) { - typedef GeometricField vfType; - typedef GeometricField sfType; + typedef GeometricField VolFieldType; + typedef GeometricField SurfaceFieldType; - if (obr_.foundObject(fieldName)) + if (mesh_.foundObject(fieldName)) { if (debug) { @@ -90,9 +63,12 @@ void Foam::functionObjects::fieldCoordinateSystemTransform::transform << endl; } - transformField(obr_.lookupObject(fieldName)); + transformField + ( + mesh_.lookupObject(fieldName) + ); } - else if (obr_.foundObject(fieldName)) + else if (mesh_.foundObject(fieldName)) { if (debug) { @@ -100,15 +76,18 @@ void Foam::functionObjects::fieldCoordinateSystemTransform::transform << endl; } - transformField(obr_.lookupObject(fieldName)); + transformField + ( + mesh_.lookupObject(fieldName) + ); } else { IOobject fieldHeader ( fieldName, - obr_.time().timeName(), - obr_, + mesh_.time().timeName(), + mesh_, IOobject::MUST_READ, IOobject::NO_WRITE ); @@ -116,7 +95,7 @@ void Foam::functionObjects::fieldCoordinateSystemTransform::transform if ( fieldHeader.headerOk() - && fieldHeader.headerClassName() == vfType::typeName + && fieldHeader.headerClassName() == VolFieldType::typeName ) { if (debug) @@ -125,12 +104,15 @@ void Foam::functionObjects::fieldCoordinateSystemTransform::transform << endl; } - transformField(obr_.lookupObject(fieldName)); + transformField + ( + mesh_.lookupObject(fieldName) + ); } else if ( fieldHeader.headerOk() - && fieldHeader.headerClassName() == sfType::typeName + && fieldHeader.headerClassName() == SurfaceFieldType::typeName ) { if (debug) @@ -139,7 +121,10 @@ void Foam::functionObjects::fieldCoordinateSystemTransform::transform << endl; } - transformField(obr_.lookupObject(fieldName)); + transformField + ( + mesh_.lookupObject(fieldName) + ); } } }