From d58d7a981410fab5cd0e91c2235d9035c425f8c0 Mon Sep 17 00:00:00 2001
From: andy <andy>
Date: Tue, 13 May 2014 16:17:06 +0100
Subject: [PATCH] ENH: localAxesRotation - added new consructor to operate on a
 list of cells

---
 .../coordinateRotation/localAxesRotation.C    | 179 ++++++++++++------
 .../coordinateRotation/localAxesRotation.H    |  42 ++--
 2 files changed, 147 insertions(+), 74 deletions(-)

diff --git a/src/meshTools/coordinateSystems/coordinateRotation/localAxesRotation.C b/src/meshTools/coordinateSystems/coordinateRotation/localAxesRotation.C
index 132c1f10d0f..53c18f9fb94 100644
--- a/src/meshTools/coordinateSystems/coordinateRotation/localAxesRotation.C
+++ b/src/meshTools/coordinateSystems/coordinateRotation/localAxesRotation.C
@@ -51,20 +51,41 @@ namespace Foam
 
 // * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * * //
 
-void Foam::localAxesRotation::init(const objectRegistry& obr)
+void Foam::localAxesRotation::init
+(
+    const objectRegistry& obr,
+    const List<label>& cells
+)
 {
     const polyMesh& mesh = refCast<const polyMesh>(obr);
     const vectorField& cc = mesh.cellCentres();
 
-    tensorField& R = Rptr_();
-    forAll(cc, cellI)
+    if (cells.size())
     {
-        vector dir = cc[cellI] - origin_;
-        dir /= mag(dir) + VSMALL;
+        Rptr_.reset(new tensorField(cells.size()));
 
-        const axesRotation ar(e3_, dir);
+        tensorField& R = Rptr_();
+        forAll(cells, i)
+        {
+            label cellI = cells[i];
+            vector dir = cc[cellI] - origin_;
+            dir /= mag(dir) + VSMALL;
 
-        R[cellI] = ar.R();
+            R[i] = axesRotation(e3_, dir).R();
+        }
+    }
+    else
+    {
+        Rptr_.reset(new tensorField(mesh.nCells()));
+
+        tensorField& R = Rptr_();
+        forAll(cc, cellI)
+        {
+            vector dir = cc[cellI] - origin_;
+            dir /= mag(dir) + VSMALL;
+
+            R[cellI] = axesRotation(e3_, dir).R();
+        }
     }
 }
 
@@ -90,26 +111,22 @@ Foam::localAxesRotation::localAxesRotation
     // rotation axis
     dict.lookup("e3") >> e3_;
 
-    const polyMesh& mesh = refCast<const polyMesh>(obr);
-
-    Rptr_.reset(new tensorField(mesh.nCells()));
     init(obr);
 }
 
 
-Foam::localAxesRotation::localAxesRotation(const dictionary& dict)
+Foam::localAxesRotation::localAxesRotation
+(
+    const objectRegistry& obr,
+    const vector& axis,
+    const point& origin
+)
 :
     Rptr_(),
-    origin_(),
-    e3_()
+    origin_(origin),
+    e3_(axis)
 {
-    FatalErrorIn("localAxesRotation(const dictionary&)")
-        << " localAxesRotation can not be constructed from dictionary "
-        << " use the construtctor : "
-           "("
-           "    const dictionary&, const objectRegistry&"
-           ")"
-        << exit(FatalIOError);
+    init(obr);
 }
 
 
@@ -117,19 +134,34 @@ Foam::localAxesRotation::localAxesRotation
 (
     const objectRegistry& obr,
     const vector& axis,
-    const point& origin
+    const point& origin,
+    const List<label>& cells
 )
 :
     Rptr_(),
     origin_(origin),
     e3_(axis)
 {
-    const polyMesh& mesh = refCast<const polyMesh>(obr);
+    init(obr, cells);
+}
 
-    Rptr_.reset(new tensorField(mesh.nCells()));
-    init(obr);
+
+Foam::localAxesRotation::localAxesRotation(const dictionary& dict)
+:
+    Rptr_(),
+    origin_(),
+    e3_()
+{
+    FatalErrorIn("localAxesRotation(const dictionary&)")
+        << " localAxesRotation can not be constructed from dictionary "
+        << " use the construtctor : "
+           "("
+           "    const dictionary&, const objectRegistry&"
+           ")"
+        << exit(FatalIOError);
 }
 
+
 Foam::localAxesRotation::localAxesRotation(const tensorField& R)
 :
     Rptr_(),
@@ -157,18 +189,40 @@ void Foam::localAxesRotation::updateCells
     const labelList& cells
 )
 {
+    const vectorField& cc = mesh.cellCentres();
+    tensorField& R = Rptr_();
+
     forAll(cells, i)
     {
         label cellI = cells[i];
-        vector dir = mesh.cellCentres()[cellI] - origin_;
+        vector dir = cc[cellI] - origin_;
         dir /= mag(dir) + VSMALL;
 
-        Rptr_()[cellI] = axesRotation(e3_, dir).R();
+        R[cellI] = axesRotation(e3_, dir).R();
     }
 }
 
 
-Foam::vector Foam::localAxesRotation::transform(const vector& st) const
+Foam::tmp<Foam::vectorField> Foam::localAxesRotation::transform
+(
+    const vectorField& vf
+) const
+{
+    if (Rptr_->size() != vf.size())
+    {
+        FatalErrorIn
+        (
+            "tmp<vectorField> localAxesRotation::transform(const vectorField&)"
+        )
+            << "vectorField st has different size to tensorField "
+            << abort(FatalError);
+    }
+
+    return (Rptr_() & vf);
+}
+
+
+Foam::vector Foam::localAxesRotation::transform(const vector& v) const
 {
     notImplemented
     (
@@ -178,50 +232,51 @@ Foam::vector Foam::localAxesRotation::transform(const vector& st) const
 }
 
 
-Foam::vector Foam::localAxesRotation::invTransform(const vector& st) const
+Foam::vector Foam::localAxesRotation::transform
+(
+    const vector& v,
+    const label cmptI
+) const
 {
-    notImplemented
-    (
-        "vector localAxesRotation::invTransform(const vector&) const"
-    );
-    return vector::zero;
+    return (Rptr_()[cmptI] & v);
 }
 
 
-Foam::tmp<Foam::vectorField> Foam::localAxesRotation::transform
+Foam::tmp<Foam::vectorField> Foam::localAxesRotation::invTransform
 (
-    const vectorField& st
+    const vectorField& vf
 ) const
 {
-    if (Rptr_->size() != st.size())
-    {
-        FatalErrorIn
-        (
-            "tmp<vectorField> localAxesRotation::transform(const vectorField&)"
-        )
-            << "vectorField st has different size to tensorField "
-            << abort(FatalError);
-    }
+    return (Rptr_().T() & vf);
+}
+
 
-    return (Rptr_() & st);
+Foam::vector Foam::localAxesRotation::invTransform(const vector& v) const
+{
+    notImplemented
+    (
+        "vector localAxesRotation::invTransform(const vector&) const"
+    );
+    return vector::zero;
 }
 
 
-Foam::tmp<Foam::vectorField> Foam::localAxesRotation::invTransform
+Foam::vector Foam::localAxesRotation::invTransform
 (
-    const vectorField& st
+    const vector& v,
+    const label cmptI
 ) const
 {
-    return (Rptr_().T() & st);
+    return (Rptr_()[cmptI].T() & v);
 }
 
 
 Foam::tmp<Foam::tensorField> Foam::localAxesRotation::transformTensor
 (
-    const tensorField& st
+    const tensorField& tf
 ) const
 {
-    if (Rptr_->size() != st.size())
+    if (Rptr_->size() != tf.size())
     {
         FatalErrorIn
         (
@@ -233,13 +288,13 @@ Foam::tmp<Foam::tensorField> Foam::localAxesRotation::transformTensor
             << "tensorField st has different size to tensorField Tr"
             << abort(FatalError);
     }
-    return (Rptr_() & st & Rptr_().T());
+    return (Rptr_() & tf & Rptr_().T());
 }
 
 
 Foam::tensor Foam::localAxesRotation::transformTensor
 (
-    const tensor& st
+    const tensor& t
 ) const
 {
     notImplemented
@@ -253,21 +308,21 @@ Foam::tensor Foam::localAxesRotation::transformTensor
 
 Foam::tmp<Foam::tensorField> Foam::localAxesRotation::transformTensor
 (
-    const tensorField& st,
+    const tensorField& tf,
     const labelList& cellMap
 ) const
 {
-    if (cellMap.size() != st.size())
+    if (cellMap.size() != tf.size())
     {
         FatalErrorIn
         (
             "tmp<tensorField> localAxesRotation::transformTensor"
             "("
-                "const tensorField&"
+                "const tensorField&, "
                 "const labelList&"
             ")"
         )
-            << "tensorField st has different size to tensorField Tr"
+            << "tensorField tf has different size to tensorField Tr"
             << abort(FatalError);
     }
 
@@ -278,7 +333,7 @@ Foam::tmp<Foam::tensorField> Foam::localAxesRotation::transformTensor
     forAll(cellMap, i)
     {
         const label cellI = cellMap[i];
-        t[i] = R[cellI] & st[i] & Rtr[cellI];
+        t[i] = R[cellI] & tf[i] & Rtr[cellI];
     }
 
     return tt;
@@ -287,13 +342,13 @@ Foam::tmp<Foam::tensorField> Foam::localAxesRotation::transformTensor
 
 Foam::tmp<Foam::symmTensorField> Foam::localAxesRotation::transformVector
 (
-    const vectorField& st
+    const vectorField& vf
 ) const
 {
-    if (Rptr_->size() != st.size())
+    if (Rptr_->size() != vf.size())
     {
         FatalErrorIn("localAxesRotation::transformVector(const vectorField&)")
-            << "tensorField st has different size to tensorField Tr"
+            << "tensorField vf has different size to tensorField Tr"
             << abort(FatalError);
     }
 
@@ -303,7 +358,7 @@ Foam::tmp<Foam::symmTensorField> Foam::localAxesRotation::transformVector
     const tensorField& R = Rptr_();
     forAll(fld, i)
     {
-        fld[i] = transformPrincipal(R[i], st[i]);
+        fld[i] = transformPrincipal(R[i], vf[i]);
     }
     return tfld;
 }
@@ -311,7 +366,7 @@ Foam::tmp<Foam::symmTensorField> Foam::localAxesRotation::transformVector
 
 Foam::symmTensor Foam::localAxesRotation::transformVector
 (
-    const vector& st
+    const vector& v
 ) const
 {
     notImplemented
diff --git a/src/meshTools/coordinateSystems/coordinateRotation/localAxesRotation.H b/src/meshTools/coordinateSystems/coordinateRotation/localAxesRotation.H
index 444898c7f0a..41a12f459bd 100644
--- a/src/meshTools/coordinateSystems/coordinateRotation/localAxesRotation.H
+++ b/src/meshTools/coordinateSystems/coordinateRotation/localAxesRotation.H
@@ -80,7 +80,11 @@ class localAxesRotation
     // Private members
 
         //- Init transformation tensor field
-        void init(const objectRegistry& obr);
+        void init
+        (
+            const objectRegistry& obr,
+            const List<label>& cells = List<label>()
+        );
 
 
 public:
@@ -93,7 +97,7 @@ public:
         //- Construct from dictionary and objectRegistry
         localAxesRotation(const dictionary&, const objectRegistry&);
 
-         //- Construct from dictionary and objectRegistry
+        //- Construct from components for all cells
         localAxesRotation
         (
             const objectRegistry&,
@@ -101,6 +105,15 @@ public:
             const point& origin
         );
 
+        //- Construct from components for list of cells
+        localAxesRotation
+        (
+            const objectRegistry&,
+            const vector& axis,
+            const point& origin,
+            const List<label>& cells
+        );
+
         //- Construct from dictionary
         localAxesRotation(const dictionary&);
 
@@ -167,16 +180,22 @@ public:
         }
 
         //- Transform vectorField using transformation tensor field
-        virtual tmp<vectorField> transform(const vectorField& st) const;
+        virtual tmp<vectorField> transform(const vectorField& tf) const;
 
         //- Transform vector using transformation tensor
-        virtual vector transform(const vector& st) const;
+        virtual vector transform(const vector& v) const;
+
+        //- Transform vector using transformation tensor for component
+        virtual vector transform(const vector& v, const label cmptI) const;
 
         //- Inverse transform vectorField using transformation tensor field
-        virtual tmp<vectorField> invTransform(const vectorField& st) const;
+        virtual tmp<vectorField> invTransform(const vectorField& vf) const;
 
         //- Inverse transform vector using transformation tensor
-        virtual vector invTransform(const vector& st) const;
+        virtual vector invTransform(const vector& v) const;
+
+        //- Inverse transform vector using transformation tensor for component
+        virtual vector invTransform(const vector& v, const label cmptI) const;
 
         //- Return if the rotation is uniform
         virtual bool uniform() const
@@ -185,15 +204,15 @@ public:
         }
 
         //- Transform tensor field using transformation tensorField
-        virtual tmp<tensorField> transformTensor(const tensorField& st) const;
+        virtual tmp<tensorField> transformTensor(const tensorField& tf) const;
 
         //- Transform tensor using transformation tensorField
-        virtual tensor transformTensor(const tensor& st) const;
+        virtual tensor transformTensor(const tensor& t) const;
 
         //- Transform tensor sub-field using transformation tensorField
         virtual tmp<tensorField> transformTensor
         (
-            const tensorField& st,
+            const tensorField& tf,
             const labelList& cellMap
         ) const;
 
@@ -201,19 +220,18 @@ public:
         // symmetrical tensorField
         virtual tmp<symmTensorField> transformVector
         (
-            const vectorField& st
+            const vectorField& vf
         ) const;
 
         //- Transform vector using transformation tensor and return
         // symmetrical tensor (R & st & R.T())
-        virtual symmTensor transformVector(const vector& st) const;
+        virtual symmTensor transformVector(const vector& v) const;
 
 
     // Write
 
         //- Write
         virtual void write(Ostream&) const;
-
 };
 
 
-- 
GitLab