transformer: Generalised to permit scaling and improved abstraction
Transformer now supports scaling matrices. The number of ways in which transformer can be constructed has also been reduced to null (i.e., identity), pure translation, pure scaling and pure rotation. Compound translations must be constructed by combining transformers with the dot-product (&) operator. In this way, the details of in what order the different parts of the transformation are applied have been abstracted.
This commit is contained in:
@ -50,7 +50,7 @@ void Foam::cyclicLduInterfaceField::transformCoupleField
|
||||
{
|
||||
if (transforms())
|
||||
{
|
||||
f *= pow(diag(transform().R()).component(cmpt), rank());
|
||||
f *= pow(diag(transform().T()).component(cmpt), rank());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -78,7 +78,7 @@ public:
|
||||
//- Is the transform required
|
||||
bool transforms() const
|
||||
{
|
||||
return transform().rotates() && rank() != 0;
|
||||
return transform().transforms() && rank() != 0;
|
||||
}
|
||||
|
||||
//- Return rank of component for transform
|
||||
|
||||
@ -50,7 +50,7 @@ void Foam::processorLduInterfaceField::transformCoupleField
|
||||
{
|
||||
if (transforms())
|
||||
{
|
||||
f *= pow(diag(transform().R()).component(cmpt), rank());
|
||||
f *= pow(diag(transform().T()).component(cmpt), rank());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -90,7 +90,7 @@ public:
|
||||
//- Is the transform required
|
||||
bool transforms() const
|
||||
{
|
||||
return transform().rotates() && rank() != 0;
|
||||
return transform().transforms() && rank() != 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -77,13 +77,14 @@ void Foam::cyclicTransform::update()
|
||||
|
||||
if (mag(rotationCentre_) == 0)
|
||||
{
|
||||
transform_ = transformer(R);
|
||||
transform_ = transformer::rotation(R);
|
||||
}
|
||||
else
|
||||
{
|
||||
const vector t = rotationCentre_ - (R & rotationCentre_);
|
||||
|
||||
transform_ = transformer(t, R);
|
||||
transform_ =
|
||||
transformer::translation(rotationCentre_)
|
||||
& transformer::rotation(R)
|
||||
& transformer::translation(- rotationCentre_);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -95,7 +96,7 @@ void Foam::cyclicTransform::update()
|
||||
}
|
||||
else
|
||||
{
|
||||
transform_ = transformer(separation_);
|
||||
transform_ = transformer::translation(separation_);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -260,7 +261,7 @@ Foam::cyclicTransform::cyclicTransform
|
||||
&& (dict.found("separation") || dict.found("separationVector"))
|
||||
)
|
||||
),
|
||||
transform_(vector::uniform(NaN), tensor::uniform(NaN))
|
||||
transform_()
|
||||
{
|
||||
if (transformComplete_)
|
||||
{
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration | Website: https://openfoam.org
|
||||
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -54,6 +54,9 @@ namespace Foam
|
||||
template<class Cmpt>
|
||||
class SymmTensor;
|
||||
|
||||
template<class Cmpt>
|
||||
class DiagTensor;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class Tensor Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
@ -107,6 +110,9 @@ public:
|
||||
//- Construct given SymmTensor
|
||||
inline Tensor(const SymmTensor<Cmpt>&);
|
||||
|
||||
//- Construct given DiagTensor
|
||||
inline Tensor(const DiagTensor<Cmpt>&);
|
||||
|
||||
//- Construct given triad
|
||||
inline Tensor(const Vector<Vector<Cmpt>>&);
|
||||
|
||||
@ -198,6 +204,9 @@ public:
|
||||
//- Assign to a SymmTensor
|
||||
inline void operator=(const SymmTensor<Cmpt>&);
|
||||
|
||||
//- Assign to a DiagTensor
|
||||
inline void operator=(const DiagTensor<Cmpt>&);
|
||||
|
||||
//- Assign to a triad
|
||||
inline void operator=(const Vector<Vector<Cmpt>>&);
|
||||
};
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration | Website: https://openfoam.org
|
||||
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -24,6 +24,7 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "SymmTensor.H"
|
||||
#include "DiagTensor.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
@ -79,6 +80,15 @@ inline Foam::Tensor<Cmpt>::Tensor(const SymmTensor<Cmpt>& st)
|
||||
}
|
||||
|
||||
|
||||
template<class Cmpt>
|
||||
inline Foam::Tensor<Cmpt>::Tensor(const DiagTensor<Cmpt>& st)
|
||||
{
|
||||
this->v_[XX] = st.xx(); this->v_[XY] = 0; this->v_[XZ] = 0;
|
||||
this->v_[YX] = 0; this->v_[YY] = st.yy(); this->v_[YZ] = 0;
|
||||
this->v_[ZX] = 0; this->v_[ZY] = 0; this->v_[ZZ] = st.zz();
|
||||
}
|
||||
|
||||
|
||||
template<class Cmpt>
|
||||
inline Foam::Tensor<Cmpt>::Tensor(const Vector<Vector<Cmpt>>& tr)
|
||||
{
|
||||
|
||||
@ -74,10 +74,10 @@ Foam::label Foam::globalIndexAndTransform::matchTransform
|
||||
|
||||
scalar tensorDiff = 0;
|
||||
|
||||
if (refTransform.rotates() || testTransform.rotates())
|
||||
if (refTransform.transforms() || testTransform.transforms())
|
||||
{
|
||||
tensorDiff =
|
||||
mag(refTransform.R() - testTransform.R())
|
||||
mag(refTransform.T() - testTransform.T())
|
||||
/sqrt(3.0)
|
||||
/tolerance;
|
||||
}
|
||||
@ -103,10 +103,10 @@ Foam::label Foam::globalIndexAndTransform::matchTransform
|
||||
|
||||
tensorDiff = 0;
|
||||
|
||||
if (refTransform.rotates() || testTransform.rotates())
|
||||
if (refTransform.transforms() || testTransform.transforms())
|
||||
{
|
||||
tensorDiff =
|
||||
mag(refTransform.R() - testTransform.R().T())
|
||||
mag(refTransform.T() - testTransform.T().T())
|
||||
/sqrt(3.0)
|
||||
/tolerance;
|
||||
}
|
||||
@ -360,15 +360,7 @@ Foam::globalIndexAndTransform::globalIndexAndTransform(const polyMesh& mesh)
|
||||
{
|
||||
Info<< '\t' << i << '\t';
|
||||
const transformer& trafo = transforms_[i];
|
||||
if (trafo.rotates())
|
||||
{
|
||||
Info<< trafo.t() << '\t' << trafo.R();
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< trafo.t() << '\t' << "---";
|
||||
}
|
||||
Info<< endl;
|
||||
Info<< trafo.t() << '\t' << trafo.T() << endl;
|
||||
}
|
||||
Info<< endl;
|
||||
|
||||
@ -393,15 +385,7 @@ Foam::globalIndexAndTransform::globalIndexAndTransform(const polyMesh& mesh)
|
||||
{
|
||||
Info<< '\t' << i << '\t';
|
||||
const transformer& trafo = transformPermutations_[i];
|
||||
if (trafo.rotates())
|
||||
{
|
||||
Info<< trafo.t() << '\t' << trafo.R();
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< trafo.t() << '\t' << "---";
|
||||
}
|
||||
Info<< endl;
|
||||
Info<< trafo.t() << '\t' << trafo.T() << endl;
|
||||
}
|
||||
Info<< "nullTransformIndex:" << nullTransformIndex() << endl
|
||||
<< endl;
|
||||
|
||||
@ -188,11 +188,11 @@ Foam::label Foam::globalIndexAndTransform::addToTransformIndex
|
||||
bool antiCyclic = false;
|
||||
|
||||
const transformer& vt = transforms_[matchTransI];
|
||||
if (!vt.translates() && vt.rotates())
|
||||
if (vt.transforms())
|
||||
{
|
||||
const tensor& R = vt.R();
|
||||
scalar sumDiag = tr(R);
|
||||
scalar sumMagDiag = mag(R.xx()) + mag(R.yy())+mag(R.zz());
|
||||
const tensor& T = vt.T();
|
||||
scalar sumDiag = tr(T);
|
||||
scalar sumMagDiag = mag(T.xx()) + mag(T.yy()) + mag(T.zz());
|
||||
|
||||
if (mag(sumMagDiag-3) < tol && mag(sumDiag+1) < tol)
|
||||
{
|
||||
|
||||
@ -37,6 +37,7 @@ const Foam::transformer Foam::transformer::zero
|
||||
Zero,
|
||||
false,
|
||||
Zero,
|
||||
false,
|
||||
false
|
||||
);
|
||||
|
||||
@ -45,6 +46,7 @@ const Foam::transformer Foam::transformer::I
|
||||
Zero,
|
||||
false,
|
||||
tensor::I,
|
||||
false,
|
||||
false
|
||||
);
|
||||
|
||||
@ -65,7 +67,7 @@ Foam::word Foam::name(const transformer& s)
|
||||
{
|
||||
OStringStream buf;
|
||||
|
||||
buf << '(' << s.t() << ',' << s.R() << ')';
|
||||
buf << '(' << s.t() << ',' << s.T() << ')';
|
||||
|
||||
return buf.str();
|
||||
}
|
||||
@ -77,17 +79,17 @@ void Foam::transformer::transformPosition
|
||||
const pointField& pts
|
||||
) const
|
||||
{
|
||||
if (translates_ && !rotates_)
|
||||
if (translates_ && !transforms())
|
||||
{
|
||||
res = pts + t();
|
||||
}
|
||||
else if (!translates_ && rotates_)
|
||||
else if (!translates_ && transforms())
|
||||
{
|
||||
res = R() & pts;
|
||||
res = T() & pts;
|
||||
}
|
||||
else if (translates_ && rotates_)
|
||||
else if (translates_ && transforms())
|
||||
{
|
||||
res = (R() & pts) + t();
|
||||
res = (T() & pts) + t();
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,17 +99,17 @@ Foam::tmp<Foam::pointField> Foam::transformer::transformPosition
|
||||
const pointField& pts
|
||||
) const
|
||||
{
|
||||
if (translates_ && !rotates_)
|
||||
if (translates_ && !transforms())
|
||||
{
|
||||
return pts + t();
|
||||
}
|
||||
else if (!translates_ && rotates_)
|
||||
else if (!translates_ && transforms())
|
||||
{
|
||||
return R() & pts;
|
||||
return T() & pts;
|
||||
}
|
||||
else if (translates_ && rotates_)
|
||||
else if (translates_ && transforms())
|
||||
{
|
||||
return (R() & pts) + t();
|
||||
return (T() & pts) + t();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -121,17 +123,17 @@ Foam::tmp<Foam::pointField> Foam::transformer::invTransformPosition
|
||||
const pointField& pts
|
||||
) const
|
||||
{
|
||||
if (translates_ && !rotates_)
|
||||
if (translates_ && !transforms())
|
||||
{
|
||||
return pts - t();
|
||||
}
|
||||
else if (!translates_ && rotates_)
|
||||
else if (!translates_ && transforms())
|
||||
{
|
||||
return R().T() & pts;
|
||||
return T().T() & pts;
|
||||
}
|
||||
else if (translates_ && rotates_)
|
||||
else if (translates_ && transforms())
|
||||
{
|
||||
return (R().T() & (pts - t()));
|
||||
return (T().T() & (pts - t()));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -146,17 +148,17 @@ void Foam::transformer::invTransformPosition
|
||||
const pointField& pts
|
||||
) const
|
||||
{
|
||||
if (translates_ && !rotates_)
|
||||
if (translates_ && !transforms())
|
||||
{
|
||||
res = pts - t();
|
||||
}
|
||||
else if (!translates_ && rotates_)
|
||||
else if (!translates_ && transforms())
|
||||
{
|
||||
res = R().T() & pts;
|
||||
res = T().T() & pts;
|
||||
}
|
||||
else if (translates_ && rotates_)
|
||||
else if (translates_ && transforms())
|
||||
{
|
||||
res = (R().T() & (pts - t()));
|
||||
res = (T().T() & (pts - t()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -228,7 +230,7 @@ Foam::Istream& Foam::operator>>(Istream& is, transformer& tr)
|
||||
// Read beginning of transformer
|
||||
is.readBegin("transformer");
|
||||
|
||||
is >> tr.translates_ >> tr.t_ >> tr.rotates_ >> tr.R_;
|
||||
is >> tr.translates_ >> tr.t_ >> tr.scales_ >> tr.rotates_ >> tr.T_;
|
||||
|
||||
// Read end of transformer
|
||||
is.readEnd("transformer");
|
||||
@ -244,7 +246,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const transformer& tr)
|
||||
{
|
||||
os << token::BEGIN_LIST
|
||||
<< tr.translates_ << token::SPACE << tr.t_ << token::SPACE
|
||||
<< tr.rotates_ << token::SPACE << tr.R_
|
||||
<< tr.scales_ << token::SPACE << tr.rotates_ << token::SPACE << tr.T_
|
||||
<< token::END_LIST;
|
||||
|
||||
return os;
|
||||
|
||||
@ -83,7 +83,7 @@ inline transformer operator&(const transformer& tr1, const transformer& tr2);
|
||||
|
||||
class transformer
|
||||
{
|
||||
// private data
|
||||
// Private data
|
||||
|
||||
//- Translation vector
|
||||
vector t_;
|
||||
@ -91,13 +91,30 @@ class transformer
|
||||
//- True if the translation vector is non-zero
|
||||
bool translates_;
|
||||
|
||||
//- Rotation tensor
|
||||
tensor R_;
|
||||
//- Transformation tensor
|
||||
tensor T_;
|
||||
|
||||
//- True if the rotation tensor is non-I
|
||||
//- True if the transformation tensor has component vectors of
|
||||
// differing magnitudes
|
||||
bool scales_;
|
||||
|
||||
//- True if the transformation tensor has off-diagonal terms
|
||||
bool rotates_;
|
||||
|
||||
|
||||
// Private constructors
|
||||
|
||||
//- Construct given a translation vector and transformation tensor
|
||||
inline transformer
|
||||
(
|
||||
const vector& t,
|
||||
const bool translates,
|
||||
const tensor& T,
|
||||
const bool scales,
|
||||
const bool rotates
|
||||
);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Static Data Members
|
||||
@ -112,31 +129,23 @@ public:
|
||||
static const transformer null;
|
||||
|
||||
|
||||
// Static Member Functions
|
||||
|
||||
//- Construct a pure translation transformer
|
||||
inline static transformer translation(const vector& t);
|
||||
|
||||
//- Construct a pure scaling transformer
|
||||
inline static transformer scaling(const tensor& T);
|
||||
|
||||
//- Construct a pure rotation transformer
|
||||
inline static transformer rotation(const tensor& T);
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
//- Construct null (i.e., no transformation)
|
||||
inline transformer();
|
||||
|
||||
//- Construct a pure translation transformer given a
|
||||
// translation vector
|
||||
inline explicit transformer(const vector& t);
|
||||
|
||||
//- Construct a pure rotation transformer given a
|
||||
// rotation tensor
|
||||
inline explicit transformer(const tensor& R);
|
||||
|
||||
//- Construct given a translation vector and rotation tensor
|
||||
inline transformer(const vector& t, const tensor& R);
|
||||
|
||||
//- Construct given a translation vector and rotation tensor
|
||||
inline transformer
|
||||
(
|
||||
const vector& t,
|
||||
const bool translates,
|
||||
const tensor& R,
|
||||
const bool rotates
|
||||
);
|
||||
|
||||
//- Construct from Istream
|
||||
transformer(Istream&);
|
||||
|
||||
@ -145,43 +154,42 @@ public:
|
||||
|
||||
// Access
|
||||
|
||||
//- Return true if the transformer performs pure translation
|
||||
// i.e. the translation vector is non-zero and the rotation tensor
|
||||
// is I
|
||||
inline bool translates() const;
|
||||
|
||||
//- Return the translation vector
|
||||
inline const vector& t() const;
|
||||
|
||||
//- Return true if the rotation tensor is non-I
|
||||
//- Return true if the transformer performs pure translation
|
||||
// (i.e. the translation vector is non-zero and the transformation
|
||||
// tensor is I)
|
||||
inline bool translates() const;
|
||||
|
||||
//- Return the transformation tensor
|
||||
inline const tensor& T() const;
|
||||
|
||||
//- Return the inverse transformation tensor
|
||||
inline tensor invT() const;
|
||||
|
||||
//- Return true if the transformer performs pure scaling
|
||||
// (i.e. the transformation tensor is diagonal)
|
||||
inline bool scales() const;
|
||||
|
||||
//- Return true if the transformer performs pure rotation
|
||||
// (i.e. the transformation tensor is orthogonal)
|
||||
inline bool rotates() const;
|
||||
|
||||
//- Return the rotation tensor
|
||||
inline const tensor& R() const;
|
||||
|
||||
//- Return true if the transformer transforms a type
|
||||
// (i.e. rotates)
|
||||
// (i.e. scales or rotates)
|
||||
inline bool transforms() const;
|
||||
|
||||
//- Return true if the transformer transforms the given type
|
||||
// (i.e. rotates)
|
||||
// (i.e. scales or rotates)
|
||||
template<typename Type>
|
||||
inline bool transforms() const;
|
||||
|
||||
//- Return true if the transformer transforms a point
|
||||
// (i.e. translates or rotates)
|
||||
// (i.e. translates or scales or rotates)
|
||||
inline bool transformsPosition() const;
|
||||
|
||||
|
||||
// Edit
|
||||
|
||||
//- Return non-const access to the translation vector
|
||||
inline vector& t();
|
||||
|
||||
//- Return non-const access to the rotation tensor
|
||||
inline tensor& R();
|
||||
|
||||
|
||||
// Transform
|
||||
|
||||
//- Transform the given position
|
||||
@ -247,13 +255,6 @@ public:
|
||||
|
||||
inline void operator&=(const transformer&);
|
||||
|
||||
inline void operator=(const vector&);
|
||||
inline void operator+=(const vector&);
|
||||
inline void operator-=(const vector&);
|
||||
|
||||
inline void operator=(const tensor&);
|
||||
inline void operator&=(const tensor&);
|
||||
|
||||
|
||||
// Global Functions
|
||||
|
||||
@ -275,24 +276,6 @@ public:
|
||||
const transformer& tr2
|
||||
);
|
||||
|
||||
friend inline transformer operator+
|
||||
(
|
||||
const transformer& tr,
|
||||
const vector& t
|
||||
);
|
||||
|
||||
friend inline transformer operator+
|
||||
(
|
||||
const vector& t,
|
||||
const transformer& tr
|
||||
);
|
||||
|
||||
friend inline transformer operator-
|
||||
(
|
||||
const transformer& tr,
|
||||
const vector& t
|
||||
);
|
||||
|
||||
friend inline transformer operator&
|
||||
(
|
||||
const transformer& tr1,
|
||||
|
||||
@ -23,119 +23,129 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "transformer.H"
|
||||
#include "diagTensor.H"
|
||||
|
||||
// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
inline Foam::transformer Foam::transformer::translation(const vector& t)
|
||||
{
|
||||
return transformer(t, true, tensor::I, false, false);
|
||||
}
|
||||
|
||||
|
||||
inline Foam::transformer Foam::transformer::scaling(const tensor& T)
|
||||
{
|
||||
return transformer(vector::zero, false, T, true, false);
|
||||
}
|
||||
|
||||
|
||||
inline Foam::transformer Foam::transformer::rotation(const tensor& T)
|
||||
{
|
||||
return transformer(vector::zero, false, T, false, true);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Private Constructors * * * * * * * * * * * * //
|
||||
|
||||
inline Foam::transformer::transformer
|
||||
(
|
||||
const vector& t,
|
||||
const bool translates,
|
||||
const tensor& T,
|
||||
const bool scales,
|
||||
const bool rotates
|
||||
)
|
||||
:
|
||||
t_(t),
|
||||
translates_(translates),
|
||||
T_(T),
|
||||
scales_(scales),
|
||||
rotates_(rotates)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
inline Foam::transformer::transformer()
|
||||
:
|
||||
t_(Zero),
|
||||
translates_(false),
|
||||
R_(tensor::I),
|
||||
T_(tensor::I),
|
||||
scales_(false),
|
||||
rotates_(false)
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::transformer::transformer(const vector& t)
|
||||
:
|
||||
t_(t),
|
||||
translates_(true),
|
||||
R_(tensor::I),
|
||||
rotates_(false)
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::transformer::transformer(const tensor& R)
|
||||
:
|
||||
t_(Zero),
|
||||
translates_(false),
|
||||
R_(R),
|
||||
rotates_(true)
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::transformer::transformer(const vector& t, const tensor& R)
|
||||
:
|
||||
t_(t),
|
||||
translates_(true),
|
||||
R_(R),
|
||||
rotates_(true)
|
||||
{}
|
||||
|
||||
|
||||
inline Foam::transformer::transformer
|
||||
(
|
||||
const vector& t,
|
||||
const bool translates,
|
||||
const tensor& R,
|
||||
const bool rotates
|
||||
)
|
||||
:
|
||||
t_(t),
|
||||
translates_(translates),
|
||||
R_(R),
|
||||
rotates_(rotates)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
inline bool Foam::transformer::translates() const
|
||||
{
|
||||
return translates_ && !rotates_;
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::vector& Foam::transformer::t() const
|
||||
{
|
||||
return t_;
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::transformer::rotates() const
|
||||
inline bool Foam::transformer::translates() const
|
||||
{
|
||||
return rotates_;
|
||||
return translates_ && !transforms();
|
||||
}
|
||||
|
||||
|
||||
inline const Foam::tensor& Foam::transformer::R() const
|
||||
inline const Foam::tensor& Foam::transformer::T() const
|
||||
{
|
||||
return R_;
|
||||
return T_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::tensor Foam::transformer::invT() const
|
||||
{
|
||||
if (scales_ && rotates_)
|
||||
{
|
||||
return inv(T());
|
||||
}
|
||||
else if (scales_)
|
||||
{
|
||||
return inv(diag(T()));
|
||||
}
|
||||
else if (rotates_)
|
||||
{
|
||||
return T().T();
|
||||
}
|
||||
else
|
||||
{
|
||||
return tensor::I;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::transformer::scales() const
|
||||
{
|
||||
return scales_ && !rotates_;
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::transformer::rotates() const
|
||||
{
|
||||
return !scales_ && rotates_;
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::transformer::transforms() const
|
||||
{
|
||||
return rotates_;
|
||||
return scales_ || rotates_;
|
||||
}
|
||||
|
||||
|
||||
template<typename Type>
|
||||
inline bool Foam::transformer::transforms() const
|
||||
{
|
||||
return pTraits<Type>::rank != 0 && rotates_;
|
||||
return pTraits<Type>::rank != 0 && transforms();
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::transformer::transformsPosition() const
|
||||
{
|
||||
return translates_ || rotates_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::vector& Foam::transformer::t()
|
||||
{
|
||||
// Assume that non-const access to t changes it from zero
|
||||
translates_ = true;
|
||||
|
||||
return t_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::tensor& Foam::transformer::R()
|
||||
{
|
||||
// Assume that non-const access to R changes it from I
|
||||
rotates_ = true;
|
||||
|
||||
return R_;
|
||||
return translates_ || transforms();
|
||||
}
|
||||
|
||||
|
||||
@ -144,17 +154,17 @@ inline Foam::vector Foam::transformer::transformPosition
|
||||
const vector& p
|
||||
) const
|
||||
{
|
||||
if (translates_ && !rotates_)
|
||||
if (translates_ && !transforms())
|
||||
{
|
||||
return p + t();
|
||||
}
|
||||
else if (!translates_ && rotates_)
|
||||
else if (!translates_ && transforms())
|
||||
{
|
||||
return R() & p;
|
||||
return T() & p;
|
||||
}
|
||||
else if (translates_ && rotates_)
|
||||
else if (translates_ && transforms())
|
||||
{
|
||||
return (R() & p) + t();
|
||||
return (T() & p) + t();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -168,17 +178,17 @@ inline Foam::vector Foam::transformer::invTransformPosition
|
||||
const vector& p
|
||||
) const
|
||||
{
|
||||
if (translates_ && !rotates_)
|
||||
if (translates_ && !transforms())
|
||||
{
|
||||
return p - t();
|
||||
}
|
||||
else if (!translates_ && rotates_)
|
||||
else if (!translates_ && transforms())
|
||||
{
|
||||
return R().T() & p;
|
||||
return invT() & p;
|
||||
}
|
||||
else if (translates_ && rotates_)
|
||||
else if (translates_ && transforms())
|
||||
{
|
||||
return (R().T() & (p - t()));
|
||||
return invT() & (p - t());
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -197,54 +207,13 @@ inline void Foam::transformer::operator&=
|
||||
// If either of the two objects has translates_ as true, then inherit
|
||||
// it, otherwise, these should both be zero vectors.
|
||||
translates_ = tr.translates_ || translates_;
|
||||
t_ = (tr.R_ & t_) + tr.t_;
|
||||
t_ = (tr.T_ & t_) + tr.t_;
|
||||
|
||||
// If either of the two objects has rotates_ as true, then inherit
|
||||
// it, otherwise, these should both be I tensors.
|
||||
// If either of the two objects has scales_ or rotates_ as true, then
|
||||
// inherit it, otherwise, these should both be I tensors.
|
||||
scales_ = tr.scales_ || scales_;
|
||||
rotates_ = tr.rotates_ || rotates_;
|
||||
R_ = tr.R_ & R_;
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::transformer::operator=(const vector& t)
|
||||
{
|
||||
translates_ = true;
|
||||
t_ = t;
|
||||
|
||||
rotates_ = false;
|
||||
R_ = tensor::I;
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::transformer::operator+=(const vector& t)
|
||||
{
|
||||
translates_ = true;
|
||||
t_ += t;
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::transformer::operator-=(const vector& t)
|
||||
{
|
||||
translates_ = true;
|
||||
t_ -= t;
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::transformer::operator=(const tensor& R)
|
||||
{
|
||||
translates_ = false;
|
||||
t_ = Zero;
|
||||
|
||||
rotates_ = true;
|
||||
R_ = R;
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::transformer::operator&=(const tensor& R)
|
||||
{
|
||||
rotates_ = true;
|
||||
t_ = R & t_;
|
||||
R_ = R & R_;
|
||||
T_ = tr.T_ & T_;
|
||||
}
|
||||
|
||||
|
||||
@ -252,22 +221,14 @@ inline void Foam::transformer::operator&=(const tensor& R)
|
||||
|
||||
inline Foam::transformer Foam::inv(const transformer& tr)
|
||||
{
|
||||
if (tr.translates_ && !tr.rotates_)
|
||||
{
|
||||
return transformer(-tr.t());
|
||||
}
|
||||
else if (!tr.translates_ && tr.rotates_)
|
||||
{
|
||||
return transformer(tr.R().T());
|
||||
}
|
||||
else if (tr.translates_ && tr.rotates_)
|
||||
{
|
||||
return transformer(tr.R().T() & (-tr.t()), tr.R().T());
|
||||
}
|
||||
else
|
||||
{
|
||||
return transformer();
|
||||
}
|
||||
return transformer
|
||||
(
|
||||
tr.invT() & (-tr.t()),
|
||||
tr.translates_,
|
||||
tr.invT(),
|
||||
tr.scales_,
|
||||
tr.rotates_
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -275,7 +236,7 @@ inline Foam::transformer Foam::inv(const transformer& tr)
|
||||
|
||||
inline bool Foam::operator==(const transformer& tr1, const transformer& tr2)
|
||||
{
|
||||
return (tr1.t() == tr2.t() && tr1.R() == tr2.R());
|
||||
return (tr1.t() == tr2.t() && tr1.T() == tr2.T());
|
||||
}
|
||||
|
||||
|
||||
@ -285,24 +246,6 @@ inline bool Foam::operator!=(const transformer& tr1, const transformer& tr2)
|
||||
}
|
||||
|
||||
|
||||
inline Foam::transformer Foam::operator+(const transformer& tr, const vector& t)
|
||||
{
|
||||
return transformer(tr.t() + t, true, tr.R(), tr.rotates_);
|
||||
}
|
||||
|
||||
|
||||
inline Foam::transformer Foam::operator+(const vector& t, const transformer& tr)
|
||||
{
|
||||
return transformer(t + tr.t(), true, tr.R(), tr.rotates_);
|
||||
}
|
||||
|
||||
|
||||
inline Foam::transformer Foam::operator-(const transformer& tr, const vector& t)
|
||||
{
|
||||
return transformer(tr.t() - t, true, tr.R(), tr.rotates_);
|
||||
}
|
||||
|
||||
|
||||
inline Foam::transformer Foam::operator&
|
||||
(
|
||||
const transformer& tr1,
|
||||
@ -311,9 +254,10 @@ inline Foam::transformer Foam::operator&
|
||||
{
|
||||
return transformer
|
||||
(
|
||||
(tr1.R() & tr2.t()) + tr1.t(),
|
||||
(tr1.T() & tr2.t()) + tr1.t(),
|
||||
tr1.translates_ || tr2.translates_,
|
||||
tr1.R() & tr2.R(),
|
||||
tr1.T() & tr2.T(),
|
||||
tr1.scales_ || tr2.scales_,
|
||||
tr1.rotates_ || tr2.rotates_
|
||||
);
|
||||
}
|
||||
|
||||
@ -28,9 +28,9 @@ License
|
||||
template<class Type>
|
||||
Type Foam::transformer::transform(const Type& x) const
|
||||
{
|
||||
if (rotates_)
|
||||
if (transforms())
|
||||
{
|
||||
return Foam::transform(R(), x);
|
||||
return Foam::transform(T(), x);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -46,9 +46,9 @@ void Foam::transformer::transform
|
||||
const Field<Type>& fld
|
||||
) const
|
||||
{
|
||||
if (rotates_)
|
||||
if (transforms())
|
||||
{
|
||||
return Foam::transform(res, R(), fld);
|
||||
return Foam::transform(res, T(), fld);
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,9 +59,9 @@ Foam::tmp<Foam::Field<Type>> Foam::transformer::transform
|
||||
const Field<Type>& fld
|
||||
) const
|
||||
{
|
||||
if (rotates_)
|
||||
if (transforms())
|
||||
{
|
||||
return Foam::transform(R(), fld);
|
||||
return Foam::transform(T(), fld);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -76,9 +76,9 @@ Foam::tmp<Foam::Field<Type>> Foam::transformer::transform
|
||||
const tmp<Field<Type>>& tfld
|
||||
) const
|
||||
{
|
||||
if (rotates_)
|
||||
if (transforms())
|
||||
{
|
||||
return Foam::transform(R(), tfld);
|
||||
return Foam::transform(T(), tfld);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -90,11 +90,11 @@ Foam::tmp<Foam::Field<Type>> Foam::transformer::transform
|
||||
template<class Type, template<class> class Container>
|
||||
void Foam::transformer::transformList(Container<Type>& l) const
|
||||
{
|
||||
if (rotates_)
|
||||
if (transforms())
|
||||
{
|
||||
forAllIter(typename Container<Type>, l, iter)
|
||||
{
|
||||
*iter = Foam::transform(R(), *iter);
|
||||
*iter = Foam::transform(T(), *iter);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -103,9 +103,9 @@ void Foam::transformer::transformList(Container<Type>& l) const
|
||||
template<class Type>
|
||||
Type Foam::transformer::invTransform(const Type& x) const
|
||||
{
|
||||
if (rotates_)
|
||||
if (transforms())
|
||||
{
|
||||
return Foam::transform(R().T(), x);
|
||||
return Foam::transform(invT(), x);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -121,9 +121,9 @@ void Foam::transformer::invTransform
|
||||
const Field<Type>& fld
|
||||
) const
|
||||
{
|
||||
if (rotates_)
|
||||
if (transforms())
|
||||
{
|
||||
Foam::transform(res, R().T(), fld);
|
||||
Foam::transform(res, invT(), fld);
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,9 +134,9 @@ Foam::tmp<Foam::Field<Type>> Foam::transformer::invTransform
|
||||
const Field<Type>& fld
|
||||
) const
|
||||
{
|
||||
if (rotates_)
|
||||
if (transforms())
|
||||
{
|
||||
return Foam::transform(R().T(), fld);
|
||||
return Foam::transform(invT(), fld);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -151,9 +151,9 @@ Foam::tmp<Foam::Field<Type>> Foam::transformer::invTransform
|
||||
const tmp<Field<Type>>& tfld
|
||||
) const
|
||||
{
|
||||
if (rotates_)
|
||||
if (transforms())
|
||||
{
|
||||
return Foam::transform(R().T(), tfld);
|
||||
return Foam::transform(invT(), tfld);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -165,11 +165,13 @@ Foam::tmp<Foam::Field<Type>> Foam::transformer::invTransform
|
||||
template<class Type, template<class> class Container>
|
||||
void Foam::transformer::invTransformList(Container<Type>& l) const
|
||||
{
|
||||
if (rotates_)
|
||||
if (transforms())
|
||||
{
|
||||
tensor invT = this->invT();
|
||||
|
||||
forAllIter(typename Container<Type>, l, iter)
|
||||
{
|
||||
*iter = Foam::transform(R().T(), *iter);
|
||||
*iter = Foam::transform(invT, *iter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,7 +80,7 @@ Foam::tmp<Foam::vectorField> Foam::cyclicFvPatch::delta() const
|
||||
vectorField& pdv = tpdv.ref();
|
||||
|
||||
// To the transformation if necessary
|
||||
if (transform().rotates())
|
||||
if (transform().transforms())
|
||||
{
|
||||
forAll(patchD, facei)
|
||||
{
|
||||
|
||||
@ -139,7 +139,7 @@ Foam::tmp<Foam::vectorField> Foam::cyclicAMIFvPatch::delta() const
|
||||
vectorField& pdv = tpdv.ref();
|
||||
|
||||
// do the transformation if necessary
|
||||
if (transform().rotates())
|
||||
if (transform().transforms())
|
||||
{
|
||||
forAll(patchD, facei)
|
||||
{
|
||||
|
||||
@ -93,7 +93,7 @@ Foam::tmp<Foam::vectorField> Foam::processorFvPatch::delta() const
|
||||
if (Pstream::parRun())
|
||||
{
|
||||
// To the transformation if necessary
|
||||
if (transform().rotates())
|
||||
if (transform().transforms())
|
||||
{
|
||||
return
|
||||
coupledFvPatch::delta()
|
||||
|
||||
@ -256,7 +256,7 @@ template<class TrackCloudType>
|
||||
void Foam::particle::hitSymmetryPatch(TrackCloudType&, trackingData&)
|
||||
{
|
||||
const vector nf = normal();
|
||||
transformProperties(transformer(I - 2.0*nf*nf));
|
||||
transformProperties(transformer::rotation(I - 2.0*nf*nf));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -190,7 +190,7 @@ void Foam::molecule::transformProperties(const transformer& transform)
|
||||
{
|
||||
particle::transformProperties(transform);
|
||||
|
||||
Q_ = transform.R() & Q_;
|
||||
Q_ = transform.T() & Q_;
|
||||
|
||||
v_ = transform.transform(v_);
|
||||
|
||||
|
||||
@ -134,7 +134,7 @@ Foam::PtrList<Foam::dictionary> Foam::blockMesh::patchDicts() const
|
||||
if (isA<cyclicTransform>(ppPtr()))
|
||||
{
|
||||
refCast<cyclicTransform>(ppPtr()) =
|
||||
transformer(scaleFactor_*tensor::I)
|
||||
transformer::scaling(scaleFactor_*tensor::I)
|
||||
& refCast<cyclicTransform>(ppPtr());
|
||||
}
|
||||
|
||||
|
||||
@ -113,7 +113,7 @@ void Foam::cyclicAMIGAMGInterfaceField::updateInterfaceMatrix
|
||||
const scalar r =
|
||||
pow
|
||||
(
|
||||
inv(thisInterface.AMITransforms()[i]).R()(cmpt, cmpt),
|
||||
inv(thisInterface.AMITransforms()[i]).T()(cmpt, cmpt),
|
||||
rank()
|
||||
);
|
||||
|
||||
@ -127,7 +127,7 @@ void Foam::cyclicAMIGAMGInterfaceField::updateInterfaceMatrix
|
||||
const scalar r =
|
||||
pow
|
||||
(
|
||||
neiInterface.AMITransforms()[i].R()(cmpt, cmpt),
|
||||
neiInterface.AMITransforms()[i].T()(cmpt, cmpt),
|
||||
rank()
|
||||
);
|
||||
|
||||
|
||||
@ -50,7 +50,7 @@ void Foam::cyclicAMILduInterfaceField::transformCoupleField
|
||||
{
|
||||
if (transforms())
|
||||
{
|
||||
f *= pow(diag(transform().R()).component(cmpt), rank());
|
||||
f *= pow(diag(transform().T()).component(cmpt), rank());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -80,7 +80,7 @@ public:
|
||||
//- Is the transform required
|
||||
bool transforms() const
|
||||
{
|
||||
return transform().rotates() && rank() != 0;
|
||||
return transform().transforms() && rank() != 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -553,7 +553,7 @@ Foam::tmp<Foam::scalarField> Foam::cyclicAMIPolyPatch::interpolate
|
||||
forAll(AMIs(), i)
|
||||
{
|
||||
const scalar r =
|
||||
pow(inv(AMITransforms()[i]).R()(cmpt, cmpt), rank);
|
||||
pow(inv(AMITransforms()[i]).T()(cmpt, cmpt), rank);
|
||||
|
||||
result.ref() +=
|
||||
AMIs()[i].interpolateToSource(r*fld, defaultValues);
|
||||
@ -564,7 +564,7 @@ Foam::tmp<Foam::scalarField> Foam::cyclicAMIPolyPatch::interpolate
|
||||
forAll(nei.AMIs(), i)
|
||||
{
|
||||
const scalar r =
|
||||
pow(nei.AMITransforms()[i].R()(cmpt, cmpt), rank);
|
||||
pow(nei.AMITransforms()[i].T()(cmpt, cmpt), rank);
|
||||
|
||||
result.ref() +=
|
||||
nei.AMIs()[i].interpolateToTarget(r*fld, defaultValues);
|
||||
|
||||
@ -479,11 +479,11 @@ void Foam::FaceCellWave<Type, TrackingData>::transform
|
||||
{
|
||||
// Transform. Implementation referred to Type
|
||||
|
||||
if (trans.rotates())
|
||||
if (trans.transforms())
|
||||
{
|
||||
for (label facei = 0; facei < nFaces; facei++)
|
||||
{
|
||||
faceInfo[facei].transform(mesh_, trans.R(), td_);
|
||||
faceInfo[facei].transform(mesh_, trans.T(), td_);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -597,11 +597,11 @@ void Foam::FaceCellWave<Type, TrackingData>::handleProcPatches()
|
||||
}
|
||||
|
||||
// Apply transform to received data for non-parallel planes
|
||||
if (procPatch.transform().rotates())
|
||||
if (procPatch.transform().transforms())
|
||||
{
|
||||
transform
|
||||
(
|
||||
procPatch.transform().R(),
|
||||
procPatch.transform().T(),
|
||||
receiveFaces.size(),
|
||||
receiveFacesInfo
|
||||
);
|
||||
@ -669,12 +669,12 @@ void Foam::FaceCellWave<Type, TrackingData>::handleCyclicPatches()
|
||||
const cyclicPolyPatch& cycPatch =
|
||||
refCast<const cyclicPolyPatch>(patch);
|
||||
|
||||
if (cycPatch.transform().rotates())
|
||||
if (cycPatch.transform().transforms())
|
||||
{
|
||||
// received data from other half
|
||||
transform
|
||||
(
|
||||
cycPatch.transform().R(),
|
||||
cycPatch.transform().T(),
|
||||
nReceiveFaces,
|
||||
receiveFacesInfo
|
||||
);
|
||||
@ -805,11 +805,11 @@ void Foam::FaceCellWave<Type, TrackingData>::handleAMICyclicPatches()
|
||||
}
|
||||
|
||||
// Apply transform to received data for non-parallel planes
|
||||
if (cycPatch.transform().rotates())
|
||||
if (cycPatch.transform().transforms())
|
||||
{
|
||||
transform
|
||||
(
|
||||
cycPatch.transform().R(),
|
||||
cycPatch.transform().T(),
|
||||
receiveInfo.size(),
|
||||
receiveInfo
|
||||
);
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration | Website: https://openfoam.org
|
||||
\\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -342,14 +342,14 @@ public:
|
||||
{
|
||||
forAll(fld, i)
|
||||
{
|
||||
fld[i].transform(mesh_, patch_, vt.R(), tol_, td_);
|
||||
fld[i].transform(mesh_, patch_, vt.T(), tol_, td_);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
forAll(fld, i)
|
||||
{
|
||||
fld[i].transform(mesh_, patch_, vt.R().T(), tol_, td_);
|
||||
fld[i].transform(mesh_, patch_, vt.T().T(), tol_, td_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -368,9 +368,9 @@ void Foam::PointEdgeWave<Type, TrackingData>::handleProcPatches()
|
||||
//}
|
||||
|
||||
// Apply transform to received data for non-parallel planes
|
||||
if (procPatch.transform().rotates())
|
||||
if (procPatch.transform().transforms())
|
||||
{
|
||||
transform(procPatch, procPatch.transform().R(), patchInfo);
|
||||
transform(procPatch, procPatch.transform().T(), patchInfo);
|
||||
}
|
||||
|
||||
// Adapt for entering domain
|
||||
@ -453,10 +453,10 @@ void Foam::PointEdgeWave<Type, TrackingData>::handleCyclicPatches()
|
||||
|
||||
// Apply rotation for non-parallel planes
|
||||
|
||||
if (cycPatch.transform().rotates())
|
||||
if (cycPatch.transform().transforms())
|
||||
{
|
||||
// received data from half1
|
||||
transform(cycPatch, cycPatch.transform().R(), nbrInfo);
|
||||
transform(cycPatch, cycPatch.transform().T(), nbrInfo);
|
||||
}
|
||||
|
||||
// if (debug)
|
||||
|
||||
Reference in New Issue
Block a user