ENH: support cylindrical coordinates in fieldCoordinateSystemTransform (#1076)

This commit is contained in:
Mark Olesen
2018-11-16 15:12:19 +01:00
parent 4a53835f4b
commit f269371dbc
5 changed files with 234 additions and 27 deletions

View File

@ -64,7 +64,8 @@ fieldCoordinateSystemTransform
read(dict);
Info<< type() << " " << name << ":" << nl
<< " Applying uniform transformation from global Cartesian to local "
<< " Applying " << (csysPtr_->uniform() ? "" : "non-")
<< "uniform transformation from global Cartesian to local "
<< *csysPtr_ << nl << endl;
}
@ -81,6 +82,96 @@ Foam::functionObjects::fieldCoordinateSystemTransform::transformFieldName
}
const Foam::surfaceTensorField&
Foam::functionObjects::fieldCoordinateSystemTransform::srotTensor() const
{
typedef surfaceTensorField FieldType;
typedef surfaceTensorField::Boundary BoundaryType;
if (!rotTensorSurface_.valid())
{
tensorField rotations(csysPtr_->R(mesh_.faceCentres()));
rotTensorSurface_.reset
(
new FieldType
(
IOobject
(
"surfRotation",
mesh_.objectRegistry::instance(),
mesh_.objectRegistry::db(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false // no register
),
mesh_,
dimless,
std::move(rotations)
// calculatedType
)
);
auto& rot = *rotTensorSurface_;
// Boundaries
BoundaryType& bf = const_cast<BoundaryType&>(rot.boundaryField());
forAll(bf, patchi)
{
bf[patchi] = csysPtr_->R(bf[patchi].patch().patch().faceCentres());
}
}
return *rotTensorSurface_;
}
const Foam::volTensorField&
Foam::functionObjects::fieldCoordinateSystemTransform::vrotTensor() const
{
typedef volTensorField FieldType;
typedef volTensorField::Boundary BoundaryType;
if (!rotTensorVolume_.valid())
{
tensorField rotations(csysPtr_->R(mesh_.cellCentres()));
rotTensorVolume_.reset
(
new FieldType
(
IOobject
(
"volRotation",
mesh_.objectRegistry::instance(),
mesh_.objectRegistry::db(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false // no register
),
mesh_,
dimless,
std::move(rotations)
// calculatedType
)
);
auto& rot = *rotTensorVolume_;
// Boundaries
BoundaryType& bf = const_cast<BoundaryType&>(rot.boundaryField());
forAll(bf, patchi)
{
bf[patchi] = csysPtr_->R(bf[patchi].patch().patch().faceCentres());
}
}
return *rotTensorVolume_;
}
bool Foam::functionObjects::fieldCoordinateSystemTransform::read
(
const dictionary& dict
@ -109,6 +200,10 @@ bool Foam::functionObjects::fieldCoordinateSystemTransform::execute()
transform<tensor>(fieldName);
}
// Finished with these
rotTensorSurface_.clear();
rotTensorVolume_.clear();
return true;
}

View File

@ -29,7 +29,7 @@ Group
Description
Transforms a user-specified selection of fields from global Cartesian
coordinates to a local Cartesian coordinate system.
coordinates to a local coordinate system.
The fields are run-time modifiable.
Usage
@ -40,12 +40,7 @@ Usage
type fieldCoordinateSystemTransform;
libs ("libfieldFunctionObjects.so");
...
fields
(
U
UMean
UPrime2Mean
);
fields ( U UMean UPrime2Mean );
coordinateSystem
{
@ -102,7 +97,7 @@ class fieldCoordinateSystemTransform
{
protected:
// Protected data
// Protected Data
//- Fields to transform
volFieldSelection fieldSet_;
@ -110,16 +105,39 @@ protected:
//- Coordinate system to transform to
autoPtr<coordinateSystem> csysPtr_;
//- Demand-driven non-uniform rotation field (surface fields)
// Eg, for cylindrical coordinates
mutable autoPtr<surfaceTensorField> rotTensorSurface_;
//- Demand-driven non-uniform rotation field (volume fields)
// Eg, for cylindrical coordinates
mutable autoPtr<volTensorField> rotTensorVolume_;
// Protected Member Functions
//- Return the name of the transformed field
word transformFieldName(const word& fieldName) const;
//- Demand-driven non-uniform rotation field for surface fields
const surfaceTensorField& srotTensor() const;
//- Demand-driven non-uniform rotation field for volume fields
const volTensorField& vrotTensor() const;
//- Transform the given field
template<class FieldType>
void transformField(const FieldType& field);
//- Transform the given field
template<class FieldType, class RotationFieldType>
void transformField
(
const RotationFieldType& rot,
const FieldType& field
);
//- Transform the given field if has the specified element type
template<class Type>
void transform(const word& fieldName);

View File

@ -46,6 +46,23 @@ void Foam::functionObjects::fieldCoordinateSystemTransform::transformField
}
template<class FieldType, class RotationFieldType>
void Foam::functionObjects::fieldCoordinateSystemTransform::transformField
(
const RotationFieldType& rot,
const FieldType& field
)
{
word transFieldName(transformFieldName(field.name()));
store
(
transFieldName,
Foam::invTransform(rot, field)
);
}
template<class Type>
void Foam::functionObjects::fieldCoordinateSystemTransform::transform
(
@ -55,29 +72,55 @@ void Foam::functionObjects::fieldCoordinateSystemTransform::transform
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
// Scalar quantities (bool, label, scalar) and sphericalTensor quantities
// are transform invariant. Use (pTraits<Type>::nComponents == 1) to avoid
// avoid generating a tensor field for a non-uniform transformation.
if (foundObject<VolFieldType>(fieldName))
{
DebugInfo
<< type() << ": Field " << fieldName << " already in database"
<< endl;
if (csysPtr_->uniform() || pTraits<Type>::nComponents == 1)
{
transformField<VolFieldType>
(
lookupObject<VolFieldType>(fieldName)
);
}
else
{
transformField<VolFieldType>
(
vrotTensor(),
lookupObject<VolFieldType>(fieldName)
);
}
}
else if (foundObject<SurfaceFieldType>(fieldName))
{
DebugInfo
<< type() << ": Field " << fieldName << " already in database"
<< endl;
if (csysPtr_->uniform() || pTraits<Type>::nComponents == 1)
{
transformField<SurfaceFieldType>
(
lookupObject<SurfaceFieldType>(fieldName)
);
}
else
{
transformField<SurfaceFieldType>
(
srotTensor(),
lookupObject<SurfaceFieldType>(fieldName)
);
}
}
else
{
IOobject fieldHeader
(
@ -94,22 +137,44 @@ void Foam::functionObjects::fieldCoordinateSystemTransform::transform
<< type() << ": Field " << fieldName << " read from file"
<< endl;
if (csysPtr_->uniform() || pTraits<Type>::nComponents == 1)
{
transformField<VolFieldType>
(
lookupObject<VolFieldType>(fieldName)
);
}
else
{
transformField<VolFieldType>
(
vrotTensor(),
lookupObject<VolFieldType>(fieldName)
);
}
}
else if (fieldHeader.typeHeaderOk<SurfaceFieldType>(true, true, false))
{
DebugInfo
<< type() << ": Field " << fieldName << " read from file"
<< endl;
if (csysPtr_->uniform() || pTraits<Type>::nComponents == 1)
{
transformField<SurfaceFieldType>
(
lookupObject<SurfaceFieldType>(fieldName)
);
}
else
{
transformField<SurfaceFieldType>
(
srotTensor(),
lookupObject<SurfaceFieldType>(fieldName)
);
}
}
}
}

View File

@ -45,5 +45,10 @@ timePrecision 6;
runTimeModifiable true;
functions
{
#include "coordinateTransform"
}
// ************************************************************************* //

View File

@ -0,0 +1,24 @@
/// -*- C++ -*-
coordinateTransform
{
type fieldCoordinateSystemTransform;
libs ("libfieldFunctionObjects.so");
log true;
fields ( U );
writeControl writeTime;
coordinateSystem
{
type cylindrical;
origin (0 0 0);
rotation
{
type cylindrical;
axis (1 0 0); //< local Z
}
}
}
// ************************************************************************* //