From 0dbdea47813d319cee0743992af2b90e2a281130 Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Tue, 7 Feb 2012 11:35:18 +0000
Subject: [PATCH] ENH: wallBoundedStreamLine: -store one value per location
 -optional tracklength specification

---
 .../field/streamLine/controlDict              | 11 ++-
 .../field/wallBoundedStreamLine/controlDict   |  4 +
 .../wallBoundedStreamLine.C                   |  9 ++
 .../wallBoundedStreamLine.H                   |  3 +
 .../wallBoundedStreamLineParticle.C           | 86 +++++++++++++------
 .../wallBoundedStreamLineParticle.H           |  3 +
 .../sampledSet/patchSeed/patchSeedSet.C       |  2 +-
 7 files changed, 87 insertions(+), 31 deletions(-)

diff --git a/src/postProcessing/functionObjects/field/streamLine/controlDict b/src/postProcessing/functionObjects/field/streamLine/controlDict
index 63b6d1d1d2b..06b3235d845 100644
--- a/src/postProcessing/functionObjects/field/streamLine/controlDict
+++ b/src/postProcessing/functionObjects/field/streamLine/controlDict
@@ -74,8 +74,15 @@ functions
         // Steps particles can travel before being removed
         lifeTime        10000;
 
-        // Number of steps per cell (estimate). Set to 1 to disable subcycling.
-        nSubCycle 5;
+        //- Specify either absolute length of steps (trackLength) or a number
+        //  of subcycling steps per cell (nSubCycle)
+
+            // Size of single track segment [m]
+            //trackLength 1e-3;
+
+            // Number of steps per cell (estimate). Set to 1 to disable
+            // subcycling.
+            nSubCycle 5;
 
         // Cloud name to use
         cloudName       particleTracks;
diff --git a/src/postProcessing/functionObjects/field/wallBoundedStreamLine/controlDict b/src/postProcessing/functionObjects/field/wallBoundedStreamLine/controlDict
index 4a3f4fe29c4..e7366e4445a 100644
--- a/src/postProcessing/functionObjects/field/wallBoundedStreamLine/controlDict
+++ b/src/postProcessing/functionObjects/field/wallBoundedStreamLine/controlDict
@@ -108,6 +108,10 @@ functions
         // Steps particles can travel before being removed
         lifeTime        100;
 
+        // Optional absolute length of steps (trackLength)
+        // Size of single track segment [m]
+        //trackLength 1e-3;
+
         // Cloud name to use
         cloudName       particleTracks;
 
diff --git a/src/postProcessing/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLine.C b/src/postProcessing/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLine.C
index 9089749eefe..822465edff3 100644
--- a/src/postProcessing/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLine.C
+++ b/src/postProcessing/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLine.C
@@ -408,6 +408,7 @@ void Foam::wallBoundedStreamLine::track()
         vvInterp,
         UIndex,         // index of U in vvInterp
         trackForward_,  // track in +u direction?
+        trackLength_,   // fixed track length
         isWallPatch,    // which faces are to follow
 
         allTracks_,
@@ -518,6 +519,14 @@ void Foam::wallBoundedStreamLine::read(const dictionary& dict)
                 << "Illegal value " << lifeTime_ << " for lifeTime"
                 << exit(FatalError);
         }
+        trackLength_ = VGREAT;
+        if (dict.found("trackLength"))
+        {
+            dict.lookup("trackLength") >> trackLength_;
+
+            Info<< type() << " : fixed track length specified : "
+                << trackLength_ << nl << endl;
+        }
 
 
         interpolationScheme_ = dict.lookupOrDefault
diff --git a/src/postProcessing/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLine.H b/src/postProcessing/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLine.H
index 6a39d25b37d..bb130b985d8 100644
--- a/src/postProcessing/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLine.H
+++ b/src/postProcessing/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLine.H
@@ -98,6 +98,9 @@ class wallBoundedStreamLine
         //- Maximum lifetime (= number of cells) of particle
         label lifeTime_;
 
+        //- Track length
+        scalar trackLength_;
+
         //- Optional specified name of particles
         word cloudName_;
 
diff --git a/src/postProcessing/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLineParticle.C b/src/postProcessing/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLineParticle.C
index cd7605a56ed..0cdb3664f9c 100644
--- a/src/postProcessing/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLineParticle.C
+++ b/src/postProcessing/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLineParticle.C
@@ -651,6 +651,8 @@ Foam::scalar Foam::wallBoundedStreamLineParticle::trackToEdge
             {
                 // Reached endpoint
                 //checkInside();
+                diagEdge_ = -1;
+                meshEdgeStart_ = -1;
                 return trackFraction;
             }
 
@@ -797,38 +799,61 @@ Foam::vector Foam::wallBoundedStreamLineParticle::interpolateFields
 
     const tetIndices ti = currentTetIndices();
 
+    const vector U = td.vvInterp_[td.UIndex_].interpolate
+    (
+        position,
+        ti,     //cellI,
+        faceI
+    );
 
-    sampledScalars_.setSize(td.vsInterp_.size());
-    forAll(td.vsInterp_, scalarI)
+    // Check if at different position
+    if
+    (
+       !sampledPositions_.size()
+     || magSqr(sampledPositions_.last()-position) > Foam::sqr(SMALL)
+    )
     {
-        sampledScalars_[scalarI].append
-        (
-            td.vsInterp_[scalarI].interpolate
-            (
-                position,
-                ti,     //cellI,
-                faceI
-            )
-        );
-    }
+        // Store the location
+        sampledPositions_.append(position);
 
-    sampledVectors_.setSize(td.vvInterp_.size());
-    forAll(td.vvInterp_, vectorI)
-    {
-        sampledVectors_[vectorI].append
-        (
-            td.vvInterp_[vectorI].interpolate
+        // Store the scalar fields
+        sampledScalars_.setSize(td.vsInterp_.size());
+        forAll(td.vsInterp_, scalarI)
+        {
+            sampledScalars_[scalarI].append
             (
-                position,
-                ti,     //cellI,
-                faceI
-            )
-        );
-    }
+                td.vsInterp_[scalarI].interpolate
+                (
+                    position,
+                    ti,     //cellI,
+                    faceI
+                )
+            );
+        }
 
-    const DynamicList<vector>& U = sampledVectors_[td.UIndex_];
+        // Store the vector fields
+        sampledVectors_.setSize(td.vvInterp_.size());
+        forAll(td.vvInterp_, vectorI)
+        {
+            vector positionU;
+            if (vectorI == td.UIndex_)
+            {
+                positionU = U;
+            }
+            else
+            {
+                positionU = td.vvInterp_[vectorI].interpolate
+                (
+                    position,
+                    ti,     //cellI,
+                    faceI
+                );
+            }
+            sampledVectors_[vectorI].append(positionU);
+        }
+    }
 
-    return U.last();
+    return U;
 }
 
 
@@ -837,7 +862,6 @@ Foam::vector Foam::wallBoundedStreamLineParticle::sample
     trackingData& td
 )
 {
-    sampledPositions_.append(position());
     vector U = interpolateFields(td, position(), cell(), tetFace());
 
     if (!td.trackForward_)
@@ -979,7 +1003,7 @@ bool Foam::wallBoundedStreamLineParticle::move
 
         --lifeTime_;
 
-        // Update sampled velocity and fields if position changed
+        // Get sampled velocity and fields. Store if position changed.
         vector U = sample(td);
 
         // !user parameter!
@@ -991,6 +1015,12 @@ bool Foam::wallBoundedStreamLineParticle::move
         }
 
 
+        if (td.trackLength_ < GREAT)
+        {
+            dt = td.trackLength_;
+        }
+
+
         scalar fraction = trackToEdge(td, position() + dt*U);
         dt *= fraction;
 
diff --git a/src/postProcessing/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLineParticle.H b/src/postProcessing/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLineParticle.H
index c0e19dd090a..a70311c4cfc 100644
--- a/src/postProcessing/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLineParticle.H
+++ b/src/postProcessing/functionObjects/field/wallBoundedStreamLine/wallBoundedStreamLineParticle.H
@@ -73,6 +73,7 @@ public:
         const PtrList<interpolation<vector> >& vvInterp_;
         const label UIndex_;
         const bool trackForward_;
+        const scalar trackLength_;
 
         const PackedBoolList& isWallPatch_;
 
@@ -90,6 +91,7 @@ public:
                 const PtrList<interpolation<vector> >& vvInterp,
                 const label UIndex,
                 const bool trackForward,
+                const scalar trackLength,
                 const PackedBoolList& isWallPatch,
 
                 DynamicList<List<point> >& allPositions,
@@ -105,6 +107,7 @@ public:
                 vvInterp_(vvInterp),
                 UIndex_(UIndex),
                 trackForward_(trackForward),
+                trackLength_(trackLength),
                 isWallPatch_(isWallPatch),
 
                 allPositions_(allPositions),
diff --git a/src/sampling/sampledSet/patchSeed/patchSeedSet.C b/src/sampling/sampledSet/patchSeed/patchSeedSet.C
index bbd8cf0a3c1..0393b5a85a9 100644
--- a/src/sampling/sampledSet/patchSeed/patchSeedSet.C
+++ b/src/sampling/sampledSet/patchSeed/patchSeedSet.C
@@ -114,7 +114,7 @@ void Foam::patchSeedSet::calcSamples
 
         if (debug)
         {
-            Pout<< "In random mode : selected " << patchFaces
+            Pout<< "In random mode : selected " << patchFaces.size()
                 << " faces out of " << sz << endl;
         }
     }
-- 
GitLab