diff --git a/src/OpenFOAM/primitives/globalIndexAndTransform/globalIndexAndTransform.C b/src/OpenFOAM/primitives/globalIndexAndTransform/globalIndexAndTransform.C index 10db88b933..fab2e74eb7 100644 --- a/src/OpenFOAM/primitives/globalIndexAndTransform/globalIndexAndTransform.C +++ b/src/OpenFOAM/primitives/globalIndexAndTransform/globalIndexAndTransform.C @@ -53,7 +53,7 @@ Foam::label Foam::globalIndexAndTransform::matchTransform { const transformer& refTransform = refTransforms[i]; - scalar maxVectorMag = sqrt + const scalar maxVectorMag = sqrt ( max(magSqr(testTransform.t()), magSqr(refTransform.t())) ); @@ -74,7 +74,7 @@ Foam::label Foam::globalIndexAndTransform::matchTransform scalar tensorDiff = 0; - if (refTransform.hasR() || testTransform.hasR()) + if (refTransform.rotates() || testTransform.rotates()) { tensorDiff = mag(refTransform.R() - testTransform.R()) @@ -103,7 +103,7 @@ Foam::label Foam::globalIndexAndTransform::matchTransform tensorDiff = 0; - if (refTransform.hasR() || testTransform.hasR()) + if (refTransform.rotates() || testTransform.rotates()) { tensorDiff = mag(refTransform.R() - testTransform.R().T()) @@ -234,7 +234,7 @@ void Foam::globalIndexAndTransform::determineTransforms() { const transformer& transform = procTransVecs[pSVI]; - if (mag(transform.t()) > small || transform.hasR()) + if (transform.translates() || transform.rotates()) { if ( @@ -448,7 +448,7 @@ Foam::globalIndexAndTransform::globalIndexAndTransform(const polyMesh& mesh) { Info<< '\t' << i << '\t'; const transformer& trafo = transforms_[i]; - if (trafo.hasR()) + if (trafo.rotates()) { Info<< trafo.t() << '\t' << trafo.R(); } @@ -481,7 +481,7 @@ Foam::globalIndexAndTransform::globalIndexAndTransform(const polyMesh& mesh) { Info<< '\t' << i << '\t'; const transformer& trafo = transformPermutations_[i]; - if (trafo.hasR()) + if (trafo.rotates()) { Info<< trafo.t() << '\t' << trafo.R(); } diff --git a/src/OpenFOAM/primitives/globalIndexAndTransform/globalIndexAndTransformI.H b/src/OpenFOAM/primitives/globalIndexAndTransform/globalIndexAndTransformI.H index ee11d58f0a..6815ac3c86 100644 --- a/src/OpenFOAM/primitives/globalIndexAndTransform/globalIndexAndTransformI.H +++ b/src/OpenFOAM/primitives/globalIndexAndTransform/globalIndexAndTransformI.H @@ -188,7 +188,7 @@ Foam::label Foam::globalIndexAndTransform::addToTransformIndex bool antiCyclic = false; const transformer& vt = transforms_[matchTransI]; - if (mag(vt.t()) < small && vt.hasR()) + if (!vt.translates() && vt.rotates()) { const tensor& R = vt.R(); scalar sumDiag = tr(R); diff --git a/src/OpenFOAM/primitives/transform/transformer/transformer.C b/src/OpenFOAM/primitives/transform/transformer/transformer.C index 55912ff71b..efcfb213f2 100644 --- a/src/OpenFOAM/primitives/transform/transformer/transformer.C +++ b/src/OpenFOAM/primitives/transform/transformer/transformer.C @@ -35,15 +35,16 @@ const char* const Foam::transformer::typeName = const Foam::transformer Foam::transformer::zero ( Zero, + false, Zero, false ); - const Foam::transformer Foam::transformer::I ( Zero, - sphericalTensor::I, + false, + tensor::I, false ); @@ -76,6 +77,18 @@ Foam::tmp> Foam::transformer::transform { return fld; } + + +template<> +Foam::tmp> Foam::transformer::transform +( + const tmp>& tfld +) const +{ + return tfld; +} + + template<> Foam::tmp> Foam::transformer::transform ( @@ -84,6 +97,18 @@ Foam::tmp> Foam::transformer::transform { return fld; } + + +template<> +Foam::tmp> Foam::transformer::transform +( + const tmp>& tfld +) const +{ + return tfld; +} + + template<> Foam::tmp> Foam::transformer::transform ( @@ -94,6 +119,16 @@ Foam::tmp> Foam::transformer::transform } +template<> +Foam::tmp> Foam::transformer::transform +( + const tmp>& tfld +) const +{ + return tfld; +} + + // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // Foam::Istream& Foam::operator>>(Istream& is, transformer& tr) @@ -101,7 +136,7 @@ Foam::Istream& Foam::operator>>(Istream& is, transformer& tr) // Read beginning of transformer is.readBegin("transformer"); - is >> tr.t_ >> tr.R_ >> tr.hasR_; + is >> tr.t_ >> tr.R_ >> tr.rotates_; // Read end of transformer is.readEnd("transformer"); @@ -116,7 +151,7 @@ Foam::Istream& Foam::operator>>(Istream& is, transformer& tr) Foam::Ostream& Foam::operator<<(Ostream& os, const transformer& tr) { os << token::BEGIN_LIST - << tr.t() << token::SPACE << tr.R() << token::SPACE << tr.hasR() + << tr.t() << token::SPACE << tr.R() << token::SPACE << tr.rotates() << token::END_LIST; return os; diff --git a/src/OpenFOAM/primitives/transform/transformer/transformer.H b/src/OpenFOAM/primitives/transform/transformer/transformer.H index f47602e339..8089b60f37 100644 --- a/src/OpenFOAM/primitives/transform/transformer/transformer.H +++ b/src/OpenFOAM/primitives/transform/transformer/transformer.H @@ -67,13 +67,14 @@ class transformer //- Translation vector vector t_; + //- True if the translation vector is non-zero + bool translates_; + //- Rotation tensor tensor R_; - //- Recording if the transform has non-identity transform to - // allow its calculation to be skipped, which is the majority - // of the expected cases - bool hasR_; + //- True if the rotation tensor is non-I + bool rotates_; public: @@ -92,15 +93,6 @@ public: //- Construct null inline transformer(); - //- Construct given a translation vector, rotation tensor and - // hasR bool - inline transformer - ( - const vector& t, - const tensor& R, - bool hasR = true - ); - //- Construct a pure translation transformer given a // translation vector inline explicit transformer(const vector& t); @@ -109,6 +101,18 @@ public: // 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&); @@ -117,17 +121,28 @@ public: // Access + //- Return the translation vector inline const vector& t() const; + //- Return true is the translation vector is non-zero + inline bool translates() const; + + //- Return the rotation tensor inline const tensor& R() const; - inline bool hasR() const; + //- Return true if the rotation tensor is non-I + inline bool rotates() const; + + //- Return true if the transformer either translates or rotates + inline bool transforms() const; // Edit + //- Return non-const access to the translation vector inline vector& t(); + //- Return non-const access to the rotation tensor inline tensor& R(); @@ -137,13 +152,19 @@ public: inline vector transformPosition(const vector& v) const; //- Transform the given pointField - inline pointField transformPosition(const pointField& pts) const; + inline tmp transformPosition + ( + const pointField& pts + ) const; //- Inverse transform the given position inline vector invTransformPosition(const vector& v) const; //- Inverse transform the given pointField - inline pointField invTransformPosition(const pointField& pts) const; + inline tmp invTransformPosition + ( + const pointField& pts + ) const; //- Transform the given type template @@ -153,6 +174,10 @@ public: template tmp> transform(const Field&) const; + //- Transform the given field + template + tmp> transform(const tmp>&) const; + //- Inverse transform the given type template Type invTransform(const Type&) const; @@ -161,6 +186,10 @@ public: template tmp> invTransform(const Field&) const; + //- Inverse transform the given field + template + tmp> invTransform(const tmp>&) const; + // Member Operators @@ -187,68 +216,49 @@ public: //- Return the inverse of the given transformer inline transformer inv(const transformer& tr); - //- Return a string representation of a transformer word name(const transformer&); - //- Data associated with transformer type are contiguous template<> inline bool contiguous() {return true;} -//- Template specialisations +// Template specialisations + template<> tmp> transformer::transform(const Field&) const; + +template<> +tmp> transformer::transform(const tmp>&) const; + template<> tmp> transformer::transform(const Field