ENH: simplify coordinate rotation specification (#2505)

- can specify rotations that are not "axes" in a compact form:

      transform
      {
          origin  (0 0 0);
          rotation none;
      }

      transform
      {
          origin  (0 0 0);
          rotation axisAngle;
          axis    (0 0 1);
          angle   45;
      }

   An expanded dictionary form also remains possible:

      transform
      {
          origin  (0 0 0);
          rotation
          {
              type  axisAngle;
              axis  (0 0 1);
              angle 45;
          }
      }

STYLE: verbose deprecation for "coordinateRotation" keyword

- the "coordinateRotation" keyword was replaced by the "rotation"
  keyword (OpenFOAM-v1812 and later) but was handled silently.
  Now elevated to non-silent.

STYLE: alias lookups "axesRotation", "EulerRotation", "STARCDRotation"

- these warn and report the equivalent short form, which aids in
  upgrading. Previously had silent lookups.
This commit is contained in:
Mark Olesen 2022-06-07 16:49:14 +02:00
parent 460b29b8c7
commit 7184de50df
26 changed files with 217 additions and 192 deletions

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / O peration | Version: v2206 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -174,24 +174,16 @@ surfaces
interpolatedPlane
{
type plane; // always triangulated
basePoint (0 0 0);
normalVector (0.1 0.1 1);
interpolate true;
// Make plane relative to the coordinateSystem (Cartesian)
coordinateSystem
{
origin (0.0501 0.0501 0.005);
// Add a coordinate rotation
// (required, so here one that doesn't change anything)
coordinateRotation
{
type axesRotation;
e1 (1 0 0);
e2 (0 1 0);
}
rotation none;
}
basePoint (0 0 0);
normalVector (0.1 0.1 1);
interpolate true;
}
walls_constant

View File

@ -48,13 +48,15 @@ namespace coordinateRotations
euler
);
// Longer name - Compat 1806
addNamedToRunTimeSelectionTable
// Long name - Compat 1806
addAliasToRunTimeSelectionTable
(
coordinateRotation,
euler,
dictionary,
EulerRotation
euler,
EulerRotation,
1806
);
} // End namespace coordinateRotations

View File

@ -48,7 +48,7 @@ Description
\heading Dictionary entries
\table
Property | Description | Reqd | Default
type | Type name: euler (or EulerRotation) | yes |
type | Type name: euler | yes |
angles | Rotation angles (usually z-x-z order) | yes |
degrees | Angles are in degrees | no | true
order | Rotation order | no | zxz
@ -57,6 +57,7 @@ Description
Note
The rotation order is usually z-x-z, but can also be something like
"rollPitchYaw" etc.
Also accepts "EulerRotation" (OpenFOAM-v1806) for the type.
SourceFiles
EulerCoordinateRotation.C

View File

@ -48,13 +48,15 @@ namespace coordinateRotations
starcd
);
// Longer name - Compat 1806
addNamedToRunTimeSelectionTable
// Long name - Compat 1806
addAliasToRunTimeSelectionTable
(
coordinateRotation,
starcd,
dictionary,
STARCDRotation
starcd,
STARCDRotation,
1806
);
} // End namespace coordinateRotation

View File

@ -46,12 +46,15 @@ Description
\heading Dictionary entries
\table
Property | Description | Required | Default
type | Type name: starcd (or STARCDRotation) | yes |
angles | The z-x-y rotation angles | yes |
degrees | Angles are in degrees | no | true
Property | Description | Reqd | Default
type | Type name: starcd | yes |
angles | The z-x-y rotation angles | yes |
degrees | Angles are in degrees | no | true
\endtable
Note
Also accepts "STARCDRotation" (OpenFOAM-v1806) for the type.
SourceFiles
STARCDCoordinateRotation.C

View File

@ -48,13 +48,15 @@ namespace coordinateRotations
axes
);
// Longer name - Compat 1806
addNamedToRunTimeSelectionTable
// Long name - Compat 1806
addAliasToRunTimeSelectionTable
(
coordinateRotation,
axes,
dictionary,
axesRotation
axes,
axesRotation,
1806
);
} // End namespace coordinateRotations

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2017-2021 OpenCFD Ltd.
Copyright (C) 2017-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -44,17 +44,18 @@ Description
\heading Dictionary entries
\table
Property | Description | Required | Default
type | type name: axes (previously axesRotation) | yes |
e1 | local x-axis | partly |
e2 | local y-axis | partly |
e3 | local z-axis | partly |
Property | Description | Reqd | Default
type | Type name: axes | yes |
e1 | local x-axis | partly |
e2 | local y-axis | partly |
e3 | local z-axis | partly |
\endtable
Note
It is also possible to specify in terms of \c axis and \c direction.
For cylindrical coordinates, the \c axis would correspond to the
\a z-axis and the \c direction to the \a r-axis.
Also accepts "axesRotation" (OpenFOAM-v1806) for the type.
SourceFiles
axesRotation.C

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2013 OpenFOAM Foundation
Copyright (C) 2017-2021 OpenCFD Ltd.
Copyright (C) 2017-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -27,6 +27,7 @@ License
\*---------------------------------------------------------------------------*/
#include "coordinateRotation.H"
#include "axesRotation.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -45,7 +46,7 @@ Foam::vector Foam::coordinateRotation::findOrthogonal(const vector& axis)
direction maxCmpt = 0;
scalar maxVal = mag(axis[maxCmpt]);
for (direction cmpt=1; cmpt < vector::nComponents; ++cmpt)
for (direction cmpt = 1; cmpt < vector::nComponents; ++cmpt)
{
const scalar val = mag(axis[cmpt]);
@ -69,10 +70,14 @@ Foam::vector Foam::coordinateRotation::findOrthogonal(const vector& axis)
Foam::autoPtr<Foam::coordinateRotation> Foam::coordinateRotation::New
(
word modelType,
const dictionary& dict
)
{
const word modelType(dict.get<word>("type"));
if (modelType.empty())
{
modelType = coordinateRotations::axes::typeName_();
}
auto* ctorPtr = dictionaryConstructorTable(modelType);
@ -81,7 +86,7 @@ Foam::autoPtr<Foam::coordinateRotation> Foam::coordinateRotation::New
FatalIOErrorInLookup
(
dict,
"coordinateRotation",
"rotation",
modelType,
*dictionaryConstructorTablePtr_
) << exit(FatalIOError);
@ -91,4 +96,13 @@ Foam::autoPtr<Foam::coordinateRotation> Foam::coordinateRotation::New
}
Foam::autoPtr<Foam::coordinateRotation> Foam::coordinateRotation::New
(
const dictionary& dict
)
{
return coordinateRotation::New(dict.get<word>("type"), dict);
}
// ************************************************************************* //

View File

@ -114,7 +114,16 @@ public:
// Selectors
//- Select constructed from dictionary
//- Select construct the specified coordinate rotation type
//
// An empty modelType will be treated as "axes" (eg, e1/e3)
static autoPtr<coordinateRotation> New
(
word modelType,
const dictionary& dict
);
//- Select construct from dictionary (requires the "type" entry)
static autoPtr<coordinateRotation> New(const dictionary& dict);

View File

@ -41,8 +41,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef cartesianCS_H
#define cartesianCS_H
#ifndef Foam_cartesianCS_H
#define Foam_cartesianCS_H
#include "coordinateSystem.H"

View File

@ -74,23 +74,25 @@ void Foam::coordinateSystem::assign(const dictionary& dict)
note_.clear();
dict.readIfPresent("note", note_);
// Non-recursive, no pattern search for "rotation"
// or "coordinateRotation" (older) sub-dictionary.
// Don't warn about older naming for now (OCT-2018)
const auto finder = dict.csearchCompat
(
"rotation", {{"coordinateRotation", -1806}},
"rotation", {{"coordinateRotation", 1806}},
keyType::LITERAL
);
if (finder.isDict())
if (finder.good())
{
spec_ = coordinateRotation::New(finder.dict());
}
else if (finder.good() && (finder->stream().peek().isWord("none")))
{
spec_.reset(new coordinateRotations::identity());
if (finder.isDict())
{
// Use the sub-dict, which is expected to contain "type"
spec_ = coordinateRotation::New(finder.dict());
}
else
{
// Use current dict. Type specified by "rotation" entry itself.
const word rotationType(finder->get<word>());
spec_.reset(coordinateRotation::New(rotationType, dict));
}
}
else
{
@ -106,7 +108,7 @@ void Foam::coordinateSystem::assign(const dictionary& dict)
Foam::coordinateSystem::coordinateSystem(std::nullptr_t)
:
spec_(),
spec_(nullptr),
origin_(Zero),
rot_(sphericalTensor::I),
name_(),
@ -258,8 +260,10 @@ Foam::coordinateSystem::coordinateSystem
Foam::coordinateSystem::coordinateSystem(const dictionary& dict)
:
coordinateSystem(word::null, dict)
{}
coordinateSystem(nullptr)
{
assign(dict);
}
Foam::coordinateSystem::coordinateSystem

View File

@ -52,7 +52,8 @@ Description
}
\endverbatim
The same, but in more verbose format:
However, a more verbose format with rotation provided as a dictionary entry
is possible:
\verbatim
coordinateSystem
{
@ -67,9 +68,20 @@ Description
}
\endverbatim
For an identity rotation, can use a slightly more compact format:
It also also possible to use the compact (single-dictionary) form
and specific a different type of rotation:
\verbatim
coordinateSystem
{
type cartesian;
origin (0 0 0);
rotation euler;
angles (90 0 0);
}
\endverbatim
This last form can be particularly readable for an identity rotation:
coordinateSystem
{
type cartesian;
origin (0 0 0);
@ -132,12 +144,6 @@ class indirect;
class coordinateSystem
{
// Private Member Functions
//- Use 'coordinateSystem' sub-dictionary if present
static const dictionary* subDictCompat(const dictionary* dictPtr);
protected:
//- Friendship with indirect for dispatching to its underlying system
@ -434,9 +440,9 @@ public:
// Member Functions
// Access
// Characteristics
//- Considered valid if it has a specification
//- Consider valid if it has a specification
virtual bool valid() const
{
return bool(spec_);
@ -448,6 +454,15 @@ public:
return true;
}
// Access
//- Return origin
virtual const point& origin() const
{
return origin_;
}
//- The rotation specification
virtual const coordinateRotation& rotation() const
{
@ -466,12 +481,6 @@ public:
return note_;
}
//- Return origin
virtual const point& origin() const
{
return origin_;
}
//- Return const reference to the rotation tensor
virtual const tensor& R() const
{

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2018-2021 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -30,28 +30,34 @@ License
#include "cartesianCS.H"
#include "indirectCS.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
namespace Foam
{
//- Handle a 'coordinateSystem' sub-dictionary
// Handle a 'coordinateSystem' sub-dictionary
// In 1806 and earlier, this was handled (rather poorly) in the
// coordinateSystem constructor itself.
const Foam::dictionary* Foam::coordinateSystem::subDictCompat
static const dictionary* subDictCompat
(
const word& entryName,
const dictionary* dictPtr
)
{
if (dictPtr)
if (entryName.empty() || !dictPtr)
{
// Non-recursive, no pattern matching in the search
const auto finder =
dictPtr->csearch(coordinateSystem::typeName_(), keyType::LITERAL);
return nullptr;
}
const auto finder = dictPtr->csearch(entryName, keyType::LITERAL);
if (finder.good())
{
if (finder.isDict())
{
return finder.dictPtr();
}
else if (finder.found())
else
{
const word csName(finder.ref().stream());
@ -60,7 +66,7 @@ const Foam::dictionary* Foam::coordinateSystem::subDictCompat
{
std::cerr
<< "--> FOAM IOWarning :" << nl
<< " Ignoring 'coordinateSystem' as a keyword."
<< " Ignoring '" << entryName << "' as a keyword."
" Perhaps you meant this instead?" << nl
<< '{' << nl
<< " type " << coordSystem::indirect::typeName_()
@ -77,6 +83,8 @@ const Foam::dictionary* Foam::coordinateSystem::subDictCompat
return dictPtr;
}
} // End namespace Foam
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -162,8 +170,8 @@ Foam::autoPtr<Foam::coordinateSystem> Foam::coordinateSystem::New
}
else
{
// Use 'coordinateSystem' subDict if present
dictPtr = coordinateSystem::subDictCompat(dictPtr);
// Fallback: 'coordinateSystem' subDict if present
dictPtr = subDictCompat(coordinateSystem::typeName_(), dictPtr);
}
word modelType = dictPtr->getOrDefault<word>
@ -190,8 +198,8 @@ Foam::autoPtr<Foam::coordinateSystem> Foam::coordinateSystem::New
}
else
{
// Use 'coordinateSystem' subDict if present
dictPtr = coordinateSystem::subDictCompat(dictPtr);
// Fallback: 'coordinateSystem' subDict if present
dictPtr = subDictCompat(coordinateSystem::typeName_(), dictPtr);
}
const word modelType = dictPtr->getOrDefault<word>

View File

@ -43,8 +43,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef cylindricalCS_H
#define cylindricalCS_H
#ifndef Foam_cylindricalCS_H
#define Foam_cylindricalCS_H
#include "coordinateSystem.H"

View File

@ -68,15 +68,9 @@ class indirect
const coordinateSystem* backend_;
// Private Member Functions
//- Construct null is disallowed
indirect() = delete;
protected:
// Protected Member Functions
// Protected Member Functions
//- Convert from local coordinate system to the global Cartesian system
//- with optional translation for the origin
@ -131,6 +125,9 @@ public:
// Constructors
//- Default construct is disallowed
indirect() = delete;
//- Copy construct
indirect(const indirect& csys);
@ -156,15 +153,9 @@ public:
// Member Functions
// Access
// Characteristics
//- Reference to the underlying coordinate system
virtual const coordinateSystem& cs() const
{
return *backend_;
}
//- Is the coordinate system valid?
//- Is coordinate system valid?
virtual bool valid() const
{
return backend_ && backend_->valid();
@ -176,6 +167,21 @@ public:
return backend_->uniform();
}
// Access
//- Reference to the underlying coordinate system
virtual const coordinateSystem& cs() const
{
return *backend_;
}
//- Return origin
virtual const point& origin() const
{
return backend_->origin();
}
//- The rotation specification
virtual const coordinateRotation& rotation() const
{
@ -194,12 +200,6 @@ public:
return backend_->note();
}
//- Return origin
virtual const point& origin() const
{
return backend_->origin();
}
//- Return const reference to the rotation tensor
virtual const tensor& R() const
{

View File

@ -207,23 +207,33 @@ Foam::searchableSurfaceCollection::searchableSurfaceCollection
sDict.readEntry("scale", scale_[surfI]);
const dictionary& coordDict = sDict.subDict("transform");
if (coordDict.found("coordinateSystem"))
{
// Backwards compatibility: use coordinateSystem subdictionary
transform_.set
const dictionary* compatDict =
coordDict.findDict
(
surfI,
new coordSystem::cartesian(coordDict, "coordinateSystem")
coordinateSystem::typeName_(),
keyType::LITERAL
);
if (compatDict)
{
// Deprecated form
if (error::master())
{
std::cerr
<< "--> FOAM IOWarning :" << nl
<< " Found [v1806] '"
<< coordinateSystem::typeName_()
<< "' entry within transform dictionary" << nl
<< std::endl;
error::warnAboutAge("sub-dictionary", 1806);
}
transform_.set(surfI, new coordSystem::cartesian(*compatDict));
}
else
{
// New form: directly set from dictionary
transform_.set
(
surfI,
new coordSystem::cartesian(sDict, "transform")
);
transform_.set(surfI, new coordSystem::cartesian(coordDict));
}
const word subGeomName(sDict.get<word>("surface"));

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / O peration | Version: v2206 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -21,12 +21,9 @@ scale 0.001;
transform
{
origin (0 0 0);
rotation
{
type axisAngle;
axis (0 0 1);
angle 45;
}
rotation axisAngle;
axis (0 0 1);
angle 45;
}
// Geometric parameters

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / O peration | Version: v2206 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -26,15 +26,12 @@ coeffs
transform
{
origin (-0.15 0.15 0);
rotation
{
type axisAngle;
axis (0 0 1);
angle 44.5;
rotation axisAngle;
// Or disabled
//rotation none;
// Or disabled
//type none;
}
axis (0 0 1);
angle 44.5;
}
}

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / O peration | Version: v2206 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -20,13 +20,10 @@ scale 0.001;
transform
{
origin (0 0 0);
rotation
{
type axisAngle;
axis (0 0 1);
angle 45;
}
origin (0 0 0);
rotation axisAngle;
axis (0 0 1);
angle 45;
}
// Geometric parameters

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / O peration | Version: v2206 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -32,11 +32,7 @@ porosity1
coordinateSystem
{
origin (0 0 0);
rotation
{
type none;
}
rotation none;
}
}
}

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / O peration | Version: v2206 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -20,13 +20,10 @@ scale 0.001;
transform
{
origin (0 0 0);
rotation
{
type axisAngle;
axis (0 0 1);
angle 45;
}
origin (0 0 0);
rotation axisAngle;
axis (0 0 1);
angle 45;
}
// Geometric parameters

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / O peration | Version: v2206 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -21,12 +21,9 @@ scale 0.001;
transform
{
origin (0 0 0);
rotation
{
type axisAngle;
axis (0 0 1);
angle 45;
}
rotation axisAngle;
axis (0 0 1);
angle 45;
}
// Geometric parameters

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / O peration | Version: v2206 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -37,11 +37,7 @@ porosity1
coordinateSystem
{
origin (0 0 0);
rotation
{
type none;
}
rotation none;
}
}
}

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / O peration | Version: v2206 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -21,12 +21,9 @@ scale 0.001;
transform
{
origin (0 0 0);
rotation
{
type axisAngle;
axis (0 0 1);
angle 45;
}
rotation axisAngle;
axis (0 0 1);
angle 45;
}
// Geometric parameters

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / O peration | Version: v2206 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -20,12 +20,9 @@ prescale (1.25 1 1);
transform
{
origin (0 0 0);
rotation
{
type axisAngle;
axis (1 0 0);
angle 45;
}
rotation axisAngle;
axis (1 0 0);
angle 45;
}
geometry

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / O peration | Version: v2206 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
@ -20,13 +20,10 @@ scale 0.001;
transform
{
origin (0 0 0);
rotation
{
type axisAngle;
axis (0 0 1);
angle 45;
}
origin (0 0 0);
rotation axisAngle;
axis (0 0 1);
angle 45;
}
// Geometric parameters