Commit db0178b8 authored by Mark OLESEN's avatar Mark OLESEN
Browse files

ENH: additional constructor and methods for axesRotation

- provide single parameter constructor for which the rotation direction
  is determined based on the size/sign of the axis components.
  The direction is aligned with one of the global axes.

- expose setTransform as a public method to allow the user to reset
  the axesRotation if desired.
parent 5cb1dab8
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -195,7 +195,17 @@ void Foam::EulerCoordinateRotation::calcTransform
Foam::EulerCoordinateRotation::EulerCoordinateRotation()
:
R_(sphericalTensor::I),
Rtr_(R_)
Rtr_(sphericalTensor::I)
{}
Foam::EulerCoordinateRotation::EulerCoordinateRotation
(
const EulerCoordinateRotation& r
)
:
R_(r.R_),
Rtr_(r.Rtr_)
{}
......@@ -206,7 +216,7 @@ Foam::EulerCoordinateRotation::EulerCoordinateRotation
)
:
R_(sphericalTensor::I),
Rtr_(R_)
Rtr_(sphericalTensor::I)
{
calcTransform
(
......@@ -227,7 +237,7 @@ Foam::EulerCoordinateRotation::EulerCoordinateRotation
)
:
R_(sphericalTensor::I),
Rtr_(R_)
Rtr_(sphericalTensor::I)
{
calcTransform(phiAngle, thetaAngle, psiAngle, inDegrees);
}
......@@ -239,9 +249,9 @@ Foam::EulerCoordinateRotation::EulerCoordinateRotation
)
:
R_(sphericalTensor::I),
Rtr_(R_)
Rtr_(sphericalTensor::I)
{
vector rotation(dict.lookup("rotation"));
const vector rotation(dict.lookup("rotation"));
calcTransform
(
......@@ -259,36 +269,8 @@ Foam::EulerCoordinateRotation::EulerCoordinateRotation
const objectRegistry&
)
:
R_(sphericalTensor::I),
Rtr_(R_)
{
vector rotation(dict.lookup("rotation"));
calcTransform
(
rotation.component(vector::X),
rotation.component(vector::Y),
rotation.component(vector::Z),
dict.lookupOrDefault("degrees", true)
);
}
Foam::EulerCoordinateRotation::EulerCoordinateRotation
(
const EulerCoordinateRotation& r
)
:
R_(r.R_),
Rtr_(r.Rtr_)
EulerCoordinateRotation(dict)
{}
void Foam::EulerCoordinateRotation::write(Ostream& os) const
{
os.writeKeyword("e1") << e1() << token::END_STATEMENT << nl;
os.writeKeyword("e2") << e2() << token::END_STATEMENT << nl;
os.writeKeyword("e3") << e3() << token::END_STATEMENT << nl;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -91,7 +91,7 @@ class EulerCoordinateRotation
const scalar phiAngle,
const scalar thetaAngle,
const scalar psiAngle,
const bool inDegrees=true
const bool inDegrees
);
......@@ -106,11 +106,14 @@ public:
//- Construct null
EulerCoordinateRotation();
//- Construct as copy
EulerCoordinateRotation(const EulerCoordinateRotation& r);
//- Construct from rotation vector
EulerCoordinateRotation
(
const vector& phiThetaPsi,
const bool inDegrees=true
const bool inDegrees
);
//- Construct from components of rotation vector
......@@ -119,17 +122,18 @@ public:
const scalar phiAngle,
const scalar thetaAngle,
const scalar psiAngle,
const bool inDegrees=true
const bool inDegrees
);
//- Construct from dictionary
EulerCoordinateRotation(const dictionary&);
//- Construct from dictionary and mesh
EulerCoordinateRotation(const dictionary&, const objectRegistry&);
explicit EulerCoordinateRotation(const dictionary& dict);
//- Construct as copy
EulerCoordinateRotation(const EulerCoordinateRotation&);
//- Construct from dictionary and a registry (typically a mesh)
EulerCoordinateRotation
(
const dictionary& dict,
const objectRegistry& unused
);
//- Return clone
autoPtr<coordinateRotation> clone() const
......@@ -226,11 +230,6 @@ public:
// symmetrical tensor
virtual symmTensor transformVector(const vector& st) const;
// Write
//- Write
virtual void write(Ostream&) const;
};
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -147,6 +147,7 @@ Foam::symmTensor Foam::STARCDCoordinateRotation::transformVector
return transformPrincipal(R_, st);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::STARCDCoordinateRotation::calcTransform
......@@ -195,7 +196,17 @@ void Foam::STARCDCoordinateRotation::calcTransform
Foam::STARCDCoordinateRotation::STARCDCoordinateRotation()
:
R_(sphericalTensor::I),
Rtr_(R_)
Rtr_(sphericalTensor::I)
{}
Foam::STARCDCoordinateRotation::STARCDCoordinateRotation
(
const STARCDCoordinateRotation& r
)
:
R_(r.R_),
Rtr_(r.Rtr_)
{}
......@@ -206,7 +217,7 @@ Foam::STARCDCoordinateRotation::STARCDCoordinateRotation
)
:
R_(sphericalTensor::I),
Rtr_(R_)
Rtr_(sphericalTensor::I)
{
calcTransform
(
......@@ -227,7 +238,7 @@ Foam::STARCDCoordinateRotation::STARCDCoordinateRotation
)
:
R_(sphericalTensor::I),
Rtr_(R_)
Rtr_(sphericalTensor::I)
{
calcTransform(rotZ, rotX, rotY, inDegrees);
}
......@@ -239,9 +250,9 @@ Foam::STARCDCoordinateRotation::STARCDCoordinateRotation
)
:
R_(sphericalTensor::I),
Rtr_(R_)
Rtr_(sphericalTensor::I)
{
vector rotation(dict.lookup("rotation"));
const vector rotation(dict.lookup("rotation"));
calcTransform
(
......@@ -258,34 +269,9 @@ Foam::STARCDCoordinateRotation::STARCDCoordinateRotation
const dictionary& dict,
const objectRegistry&
)
{
vector rotation(dict.lookup("rotation"));
calcTransform
(
rotation.component(vector::X),
rotation.component(vector::Y),
rotation.component(vector::Z),
dict.lookupOrDefault("degrees", true)
);
}
Foam::STARCDCoordinateRotation::STARCDCoordinateRotation
(
const STARCDCoordinateRotation& r
)
:
R_(r.R_),
Rtr_(r.Rtr_)
STARCDCoordinateRotation(dict)
{}
void Foam::STARCDCoordinateRotation::write(Ostream& os) const
{
os.writeKeyword("e1") << e1() << token::END_STATEMENT << nl;
os.writeKeyword("e2") << e2() << token::END_STATEMENT << nl;
os.writeKeyword("e3") << e3() << token::END_STATEMENT << nl;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -83,7 +83,7 @@ class STARCDCoordinateRotation
const scalar rotZ,
const scalar rotX,
const scalar rotY,
const bool inDegrees=true
const bool inDegrees
);
......@@ -98,11 +98,14 @@ public:
//- Construct null
STARCDCoordinateRotation();
//- Construct as copy
STARCDCoordinateRotation(const STARCDCoordinateRotation& r);
//- Construct from rotation vector
STARCDCoordinateRotation
(
const vector& rotZrotXrotY,
const bool inDegrees=true
const bool inDegrees
);
//- Construct from components of rotation vector
......@@ -111,17 +114,19 @@ public:
const scalar rotZ,
const scalar rotX,
const scalar rotY,
const bool inDegrees=true
const bool inDegrees
);
//- Construct from dictionary
STARCDCoordinateRotation(const dictionary&);
explicit STARCDCoordinateRotation(const dictionary& dict);
//- Construct from dictionary and mesh
STARCDCoordinateRotation(const dictionary&, const objectRegistry&);
//- Construct from dictionary and a registry (typically a mesh)
STARCDCoordinateRotation
(
const dictionary& dict,
const objectRegistry& unused
);
//- Construct as copy
STARCDCoordinateRotation(const STARCDCoordinateRotation&);
//- Return clone
autoPtr<coordinateRotation> clone() const
......@@ -218,11 +223,6 @@ public:
// symmetrical tensor
virtual symmTensor transformVector(const vector& st) const;
// Write
//- Write
virtual void write(Ostream&) const;
};
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -32,7 +32,12 @@ License
namespace Foam
{
defineTypeNameAndDebug(axesRotation, 0);
addToRunTimeSelectionTable(coordinateRotation, axesRotation, dictionary);
addToRunTimeSelectionTable
(
coordinateRotation,
axesRotation,
dictionary
);
addToRunTimeSelectionTable
(
coordinateRotation,
......@@ -41,131 +46,161 @@ namespace Foam
);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::axesRotation::calcTransform
(
const vector& axis1,
const vector& axis2,
const axisOrder& order
)
{
vector a = axis1/mag(axis1);
vector b = axis2;
b = b - (b & a)*a;
if (mag(b) < SMALL)
{
FatalErrorInFunction
<< "axis1, axis2 appear co-linear: "
<< axis1 << ", " << axis2 << endl
<< abort(FatalError);
}
b = b/mag(b);
vector c = a^b;
tensor Rtr;
switch (order)
{
case e1e2:
{
Rtr = tensor(a, b, c);
break;
}
case e2e3:
{
Rtr = tensor(c, a, b);
break;
}
case e3e1:
{
Rtr = tensor(b, c, a);
break;
}
default:
{
FatalErrorInFunction
<< "Unhandled axes specifictation" << endl
<< abort(FatalError);
Rtr = Zero;
break;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Global->local transformation
Rtr_ = Rtr;
Foam::axesRotation::axesRotation()
:
R_(sphericalTensor::I),
Rtr_(sphericalTensor::I)
{}
// Local->global transformation
R_ = Rtr.T();
}
Foam::axesRotation::axesRotation(const axesRotation& r)
:
R_(r.R_),
Rtr_(r.Rtr_)
{}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::axesRotation::axesRotation()
Foam::axesRotation::axesRotation(const tensor& R)
:
R_(sphericalTensor::I),
Rtr_(R_)
R_(R),
Rtr_(R_.T())
{}
Foam::axesRotation::axesRotation
(
const vector& axis,
const vector& dir
const vector& dir,
const axisOrder& order
)
:
R_(sphericalTensor::I),
Rtr_(R_)
Rtr_(sphericalTensor::I)
{
calcTransform(axis, dir, e3e1);
setTransform(axis, dir, order);
}
Foam::axesRotation::axesRotation
(
const dictionary& dict
const vector& axis
)
:
R_(sphericalTensor::I),
Rtr_(R_)
Rtr_(sphericalTensor::I)
{
operator=(dict);
direction maxCmpt = 0, dirCmpt = 1;
scalar maxVal = mag(axis[maxCmpt]);
bool negative = (axis[maxCmpt] < 0);
for (direction cmpt = 1; cmpt < vector::nComponents; ++cmpt)
{
const scalar val = mag(axis[cmpt]);
if (maxVal < val)
{
maxVal = val;
maxCmpt = cmpt;
dirCmpt = maxCmpt+1;
negative = (axis[cmpt] < 0);
if (dirCmpt >= vector::nComponents)
{
dirCmpt = 0;
}
}
}
vector dir = Zero;
dir.component(dirCmpt) = (negative ? -1 : 1);
setTransform(axis, dir, E3_E1);
}
Foam::axesRotation::axesRotation
(
const dictionary& dict,
const objectRegistry& obr
const dictionary& dict
)
:
R_(sphericalTensor::I),
Rtr_(R_)
Rtr_(sphericalTensor::I)
{
operator=(dict);
}
Foam::axesRotation::axesRotation(const tensor& R)
Foam::axesRotation::axesRotation
(
const dictionary& dict,
const objectRegistry&
)
:
R_(R),
Rtr_(R_.T())
axesRotation(dict)
{}
Foam::axesRotation::axesRotation(const axesRotation& r)
:
R_(r.R_),
Rtr_(r.Rtr_)
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
void Foam::axesRotation::setTransform
(
const vector& axis1,
const vector& axis2,
const axisOrder& order
)
{
const vector a = axis1/mag(axis1);
vector b = axis2;
b = b - (b & a)*a;
if (mag(b) < SMALL)
{
FatalErrorInFunction
<< "axis1, axis2 appear to be co-linear: "
<< axis1 << ", " << axis2 << endl
<< abort(FatalError);
}
b = b/mag(b);
const vector c = a^b;
// Global->local transformation
switch (order)
{
case E1_E2:
{
Rtr_ = tensor(a, b, c);
break;
}
case E2_E3:
{
Rtr_ = tensor(c, a, b);
break;
}
case E3_E1:
{
Rtr_ = tensor(b, c, a);
break;
}
default:
{
FatalErrorInFunction
<< "Unhandled axes specification" << endl
<< abort(FatalError);
break;
}
}
// Local->global transformation
R_ = Rtr_.T();
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
const Foam::tensorField& Foam::axesRotation::Tr() const
{
......@@ -263,34 +298,28 @@ Foam::symmTensor Foam::axesRotation::transformVector
void Foam::axesRotation::operator=(const dictionary& dict)