functionObjects/field/fieldCoordinateSystemTransform: simplified, standardized, rationalized

This commit is contained in:
Henry Weller
2016-05-22 14:26:40 +01:00
parent d67f296265
commit df5955a8fe
3 changed files with 59 additions and 102 deletions

View File

@ -24,7 +24,6 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "fieldCoordinateSystemTransform.H" #include "fieldCoordinateSystemTransform.H"
#include "dictionary.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -55,23 +54,10 @@ fieldCoordinateSystemTransform
const dictionary& dict const dictionary& dict
) )
: :
functionObject(name), fvMeshFunctionObject(name, runTime, dict),
obr_
(
runTime.lookupObject<objectRegistry>
(
dict.lookupOrDefault("region", polyMesh::defaultRegion)
)
),
fieldSet_(), fieldSet_(),
coordSys_(obr_, dict) coordSys_(mesh_, dict)
{ {
if (!isA<fvMesh>(obr_))
{
FatalErrorInFunction
<< "objectRegistry is not an fvMesh" << exit(FatalError);
}
read(dict); read(dict);
Info<< type() << " " << name << ":" << nl Info<< type() << " " << name << ":" << nl
@ -89,6 +75,16 @@ Foam::functionObjects::fieldCoordinateSystemTransform::
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::word
Foam::functionObjects::fieldCoordinateSystemTransform::transformFieldName
(
const word& fieldName
) const
{
return fieldName + ":Transformed";
}
bool Foam::functionObjects::fieldCoordinateSystemTransform::read bool Foam::functionObjects::fieldCoordinateSystemTransform::read
( (
const dictionary& dict const dictionary& dict
@ -105,11 +101,8 @@ bool Foam::functionObjects::fieldCoordinateSystemTransform::execute
const bool postProcess const bool postProcess
) )
{ {
Info<< type() << " " << name() << " output:" << nl;
forAll(fieldSet_, fieldi) forAll(fieldSet_, fieldi)
{ {
// If necessary load field
transform<scalar>(fieldSet_[fieldi]); transform<scalar>(fieldSet_[fieldi]);
transform<vector>(fieldSet_[fieldi]); transform<vector>(fieldSet_[fieldi]);
transform<sphericalTensor>(fieldSet_[fieldi]); transform<sphericalTensor>(fieldSet_[fieldi]);
@ -126,22 +119,11 @@ bool Foam::functionObjects::fieldCoordinateSystemTransform::write
const bool postProcess const bool postProcess
) )
{ {
Info<< type() << " " << name() << " output:" << nl;
forAll(fieldSet_, fieldi) forAll(fieldSet_, fieldi)
{ {
const word fieldName = fieldSet_[fieldi] + ":Transformed"; fvMeshFunctionObject::write(transformFieldName(fieldSet_[fieldi]));
const regIOobject& field =
obr_.lookupObject<regIOobject>(fieldName);
Info<< " writing field " << field.name() << nl;
field.write();
} }
Info<< endl;
return true; return true;
} }

View File

@ -63,7 +63,7 @@ Description
\endtable \endtable
SeeAlso SeeAlso
Foam::functionObject Foam::functionObjects::fvMeshFunctionObject
Foam::coordinateSystem Foam::coordinateSystem
SourceFiles SourceFiles
@ -75,8 +75,7 @@ SourceFiles
#ifndef functionObjects_fieldCoordinateSystemTransform_H #ifndef functionObjects_fieldCoordinateSystemTransform_H
#define functionObjects_fieldCoordinateSystemTransform_H #define functionObjects_fieldCoordinateSystemTransform_H
#include "functionObject.H" #include "fvMeshFunctionObject.H"
#include "volFieldsFwd.H"
#include "coordinateSystem.H" #include "coordinateSystem.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -96,15 +95,12 @@ namespace functionObjects
class fieldCoordinateSystemTransform class fieldCoordinateSystemTransform
: :
public functionObject public fvMeshFunctionObject
{ {
protected: protected:
// Protected data // Protected data
//- Reference to the objectRegistry
const objectRegistry& obr_;
//- Fields to transform //- Fields to transform
wordList fieldSet_; wordList fieldSet_;
@ -114,22 +110,16 @@ protected:
// Protected Member Functions // Protected Member Functions
//- Return the name of the transformed field
word transformFieldName(const word& fieldName) const;
//- Transform the given field
template<class FieldType>
void transformField(const FieldType& field);
//- Transform the given field if has the specified element type
template<class Type> template<class Type>
void transform(const word& fieldName) const; void transform(const word& fieldName);
template<class Type>
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&);
public: public:

View File

@ -26,50 +26,23 @@ License
#include "fieldCoordinateSystemTransform.H" #include "fieldCoordinateSystemTransform.H"
#include "volFields.H" #include "volFields.H"
#include "surfaceFields.H" #include "surfaceFields.H"
#include "Time.H"
#include "transformGeometricField.H" #include "transformGeometricField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type> template<class FieldType>
void Foam::functionObjects::fieldCoordinateSystemTransform::transformField void Foam::functionObjects::fieldCoordinateSystemTransform::transformField
( (
const Type& field const FieldType& field
) const )
{ {
const word& fieldName = field.name() + ":Transformed"; word transFieldName(transformFieldName(field.name()));
if (!obr_.foundObject<Type>(fieldName)) store
{ (
obr_.store transFieldName,
( Foam::transform(dimensionedTensor(coordSys_.R().R()), field)
new Type );
(
IOobject
(
fieldName,
obr_.time().timeName(),
obr_,
IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE
),
field
)
);
}
Type& transField =
const_cast<Type&>(obr_.lookupObject<Type>(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();
} }
@ -77,12 +50,12 @@ template<class Type>
void Foam::functionObjects::fieldCoordinateSystemTransform::transform void Foam::functionObjects::fieldCoordinateSystemTransform::transform
( (
const word& fieldName const word& fieldName
) const )
{ {
typedef GeometricField<Type, fvPatchField, volMesh> vfType; typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
typedef GeometricField<Type, fvsPatchField, surfaceMesh> sfType; typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
if (obr_.foundObject<vfType>(fieldName)) if (mesh_.foundObject<VolFieldType>(fieldName))
{ {
if (debug) if (debug)
{ {
@ -90,9 +63,12 @@ void Foam::functionObjects::fieldCoordinateSystemTransform::transform
<< endl; << endl;
} }
transformField<vfType>(obr_.lookupObject<vfType>(fieldName)); transformField<VolFieldType>
(
mesh_.lookupObject<VolFieldType>(fieldName)
);
} }
else if (obr_.foundObject<sfType>(fieldName)) else if (mesh_.foundObject<SurfaceFieldType>(fieldName))
{ {
if (debug) if (debug)
{ {
@ -100,15 +76,18 @@ void Foam::functionObjects::fieldCoordinateSystemTransform::transform
<< endl; << endl;
} }
transformField<sfType>(obr_.lookupObject<sfType>(fieldName)); transformField<SurfaceFieldType>
(
mesh_.lookupObject<SurfaceFieldType>(fieldName)
);
} }
else else
{ {
IOobject fieldHeader IOobject fieldHeader
( (
fieldName, fieldName,
obr_.time().timeName(), mesh_.time().timeName(),
obr_, mesh_,
IOobject::MUST_READ, IOobject::MUST_READ,
IOobject::NO_WRITE IOobject::NO_WRITE
); );
@ -116,7 +95,7 @@ void Foam::functionObjects::fieldCoordinateSystemTransform::transform
if if
( (
fieldHeader.headerOk() fieldHeader.headerOk()
&& fieldHeader.headerClassName() == vfType::typeName && fieldHeader.headerClassName() == VolFieldType::typeName
) )
{ {
if (debug) if (debug)
@ -125,12 +104,15 @@ void Foam::functionObjects::fieldCoordinateSystemTransform::transform
<< endl; << endl;
} }
transformField<vfType>(obr_.lookupObject<vfType>(fieldName)); transformField<VolFieldType>
(
mesh_.lookupObject<VolFieldType>(fieldName)
);
} }
else if else if
( (
fieldHeader.headerOk() fieldHeader.headerOk()
&& fieldHeader.headerClassName() == sfType::typeName && fieldHeader.headerClassName() == SurfaceFieldType::typeName
) )
{ {
if (debug) if (debug)
@ -139,7 +121,10 @@ void Foam::functionObjects::fieldCoordinateSystemTransform::transform
<< endl; << endl;
} }
transformField<sfType>(obr_.lookupObject<sfType>(fieldName)); transformField<SurfaceFieldType>
(
mesh_.lookupObject<SurfaceFieldType>(fieldName)
);
} }
} }
} }