mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: support cylindrical coordinates in fieldCoordinateSystemTransform (#1076)
This commit is contained in:
@ -64,7 +64,8 @@ fieldCoordinateSystemTransform
|
|||||||
read(dict);
|
read(dict);
|
||||||
|
|
||||||
Info<< type() << " " << name << ":" << nl
|
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;
|
<< *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
|
bool Foam::functionObjects::fieldCoordinateSystemTransform::read
|
||||||
(
|
(
|
||||||
const dictionary& dict
|
const dictionary& dict
|
||||||
@ -109,6 +200,10 @@ bool Foam::functionObjects::fieldCoordinateSystemTransform::execute()
|
|||||||
transform<tensor>(fieldName);
|
transform<tensor>(fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Finished with these
|
||||||
|
rotTensorSurface_.clear();
|
||||||
|
rotTensorVolume_.clear();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -29,7 +29,7 @@ Group
|
|||||||
|
|
||||||
Description
|
Description
|
||||||
Transforms a user-specified selection of fields from global Cartesian
|
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.
|
The fields are run-time modifiable.
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
@ -40,12 +40,7 @@ Usage
|
|||||||
type fieldCoordinateSystemTransform;
|
type fieldCoordinateSystemTransform;
|
||||||
libs ("libfieldFunctionObjects.so");
|
libs ("libfieldFunctionObjects.so");
|
||||||
...
|
...
|
||||||
fields
|
fields ( U UMean UPrime2Mean );
|
||||||
(
|
|
||||||
U
|
|
||||||
UMean
|
|
||||||
UPrime2Mean
|
|
||||||
);
|
|
||||||
|
|
||||||
coordinateSystem
|
coordinateSystem
|
||||||
{
|
{
|
||||||
@ -102,7 +97,7 @@ class fieldCoordinateSystemTransform
|
|||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// Protected data
|
// Protected Data
|
||||||
|
|
||||||
//- Fields to transform
|
//- Fields to transform
|
||||||
volFieldSelection fieldSet_;
|
volFieldSelection fieldSet_;
|
||||||
@ -110,16 +105,39 @@ protected:
|
|||||||
//- Coordinate system to transform to
|
//- Coordinate system to transform to
|
||||||
autoPtr<coordinateSystem> csysPtr_;
|
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
|
// Protected Member Functions
|
||||||
|
|
||||||
//- Return the name of the transformed field
|
//- Return the name of the transformed field
|
||||||
word transformFieldName(const word& fieldName) const;
|
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
|
//- Transform the given field
|
||||||
template<class FieldType>
|
template<class FieldType>
|
||||||
void transformField(const FieldType& field);
|
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
|
//- Transform the given field if has the specified element type
|
||||||
template<class Type>
|
template<class Type>
|
||||||
void transform(const word& fieldName);
|
void transform(const word& fieldName);
|
||||||
|
|||||||
@ -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>
|
template<class Type>
|
||||||
void Foam::functionObjects::fieldCoordinateSystemTransform::transform
|
void Foam::functionObjects::fieldCoordinateSystemTransform::transform
|
||||||
(
|
(
|
||||||
@ -55,29 +72,55 @@ void Foam::functionObjects::fieldCoordinateSystemTransform::transform
|
|||||||
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
|
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
|
||||||
typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
|
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))
|
if (foundObject<VolFieldType>(fieldName))
|
||||||
{
|
{
|
||||||
DebugInfo
|
DebugInfo
|
||||||
<< type() << ": Field " << fieldName << " already in database"
|
<< type() << ": Field " << fieldName << " already in database"
|
||||||
<< endl;
|
<< endl;
|
||||||
|
|
||||||
|
if (csysPtr_->uniform() || pTraits<Type>::nComponents == 1)
|
||||||
|
{
|
||||||
transformField<VolFieldType>
|
transformField<VolFieldType>
|
||||||
(
|
(
|
||||||
lookupObject<VolFieldType>(fieldName)
|
lookupObject<VolFieldType>(fieldName)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
transformField<VolFieldType>
|
||||||
|
(
|
||||||
|
vrotTensor(),
|
||||||
|
lookupObject<VolFieldType>(fieldName)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (foundObject<SurfaceFieldType>(fieldName))
|
else if (foundObject<SurfaceFieldType>(fieldName))
|
||||||
{
|
{
|
||||||
DebugInfo
|
DebugInfo
|
||||||
<< type() << ": Field " << fieldName << " already in database"
|
<< type() << ": Field " << fieldName << " already in database"
|
||||||
<< endl;
|
<< endl;
|
||||||
|
|
||||||
|
if (csysPtr_->uniform() || pTraits<Type>::nComponents == 1)
|
||||||
|
{
|
||||||
transformField<SurfaceFieldType>
|
transformField<SurfaceFieldType>
|
||||||
(
|
(
|
||||||
lookupObject<SurfaceFieldType>(fieldName)
|
lookupObject<SurfaceFieldType>(fieldName)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
transformField<SurfaceFieldType>
|
||||||
|
(
|
||||||
|
srotTensor(),
|
||||||
|
lookupObject<SurfaceFieldType>(fieldName)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
IOobject fieldHeader
|
IOobject fieldHeader
|
||||||
(
|
(
|
||||||
@ -94,22 +137,44 @@ void Foam::functionObjects::fieldCoordinateSystemTransform::transform
|
|||||||
<< type() << ": Field " << fieldName << " read from file"
|
<< type() << ": Field " << fieldName << " read from file"
|
||||||
<< endl;
|
<< endl;
|
||||||
|
|
||||||
|
if (csysPtr_->uniform() || pTraits<Type>::nComponents == 1)
|
||||||
|
{
|
||||||
transformField<VolFieldType>
|
transformField<VolFieldType>
|
||||||
(
|
(
|
||||||
lookupObject<VolFieldType>(fieldName)
|
lookupObject<VolFieldType>(fieldName)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
transformField<VolFieldType>
|
||||||
|
(
|
||||||
|
vrotTensor(),
|
||||||
|
lookupObject<VolFieldType>(fieldName)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (fieldHeader.typeHeaderOk<SurfaceFieldType>(true, true, false))
|
else if (fieldHeader.typeHeaderOk<SurfaceFieldType>(true, true, false))
|
||||||
{
|
{
|
||||||
DebugInfo
|
DebugInfo
|
||||||
<< type() << ": Field " << fieldName << " read from file"
|
<< type() << ": Field " << fieldName << " read from file"
|
||||||
<< endl;
|
<< endl;
|
||||||
|
|
||||||
|
if (csysPtr_->uniform() || pTraits<Type>::nComponents == 1)
|
||||||
|
{
|
||||||
transformField<SurfaceFieldType>
|
transformField<SurfaceFieldType>
|
||||||
(
|
(
|
||||||
lookupObject<SurfaceFieldType>(fieldName)
|
lookupObject<SurfaceFieldType>(fieldName)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
transformField<SurfaceFieldType>
|
||||||
|
(
|
||||||
|
srotTensor(),
|
||||||
|
lookupObject<SurfaceFieldType>(fieldName)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -45,5 +45,10 @@ timePrecision 6;
|
|||||||
|
|
||||||
runTimeModifiable true;
|
runTimeModifiable true;
|
||||||
|
|
||||||
|
functions
|
||||||
|
{
|
||||||
|
#include "coordinateTransform"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
// ************************************************************************* //
|
||||||
|
|||||||
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
Reference in New Issue
Block a user