From 5d0c0287cafb2faac7aad57c98810aef4686be4b Mon Sep 17 00:00:00 2001
From: andy <andy>
Date: Tue, 12 Nov 2013 11:52:30 +0000
Subject: [PATCH] ENH: lagrangian - caches cell length scale on the cloud

---
 .../clouds/Templates/KinematicCloud/KinematicCloud.C      | 5 +++++
 .../clouds/Templates/KinematicCloud/KinematicCloud.H      | 6 ++++++
 .../clouds/Templates/KinematicCloud/KinematicCloudI.H     | 8 ++++++++
 .../parcels/Templates/KinematicParcel/KinematicParcel.C   | 4 ++--
 4 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloud.C b/src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloud.C
index dc42e0f9db6..42cced76589 100644
--- a/src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloud.C
+++ b/src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloud.C
@@ -321,6 +321,7 @@ Foam::KinematicCloud<CloudType>::KinematicCloud
       : -1
     ),
     cellOccupancyPtr_(),
+    cellLengthScale_(cbrt(mesh_.V())),
     rho_(rho),
     U_(U),
     mu_(mu),
@@ -421,6 +422,7 @@ Foam::KinematicCloud<CloudType>::KinematicCloud
     subModelProperties_(c.subModelProperties_),
     rndGen_(c.rndGen_, true),
     cellOccupancyPtr_(NULL),
+    cellLengthScale_(c.cellLengthScale_),
     rho_(c.rho_),
     U_(c.U_),
     mu_(c.mu_),
@@ -511,6 +513,7 @@ Foam::KinematicCloud<CloudType>::KinematicCloud
     subModelProperties_(dictionary::null),
     rndGen_(0, 0),
     cellOccupancyPtr_(NULL),
+    cellLengthScale_(c.cellLengthScale_),
     rho_(c.rho_),
     U_(c.U_),
     mu_(c.mu_),
@@ -842,7 +845,9 @@ void Foam::KinematicCloud<CloudType>::patchData
 template<class CloudType>
 void Foam::KinematicCloud<CloudType>::updateMesh()
 {
+    updateCellOccupancy();
     injectors_.updateMesh();
+    cellLengthScale_ = cbrt(mesh_.V());
 }
 
 
diff --git a/src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloud.H b/src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloud.H
index e32a3bdf4ff..9c2a75157b9 100644
--- a/src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloud.H
+++ b/src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloud.H
@@ -165,6 +165,9 @@ protected:
         //- Cell occupancy information for each parcel, (demand driven)
         autoPtr<List<DynamicList<parcelType*> > > cellOccupancyPtr_;
 
+        //- Cell length scale
+        scalarField cellLengthScale_;
+
 
         // References to the carrier gas fields
 
@@ -368,6 +371,9 @@ public:
                 //  if particles are removed or created.
                 inline List<DynamicList<parcelType*> >& cellOccupancy();
 
+                //- Return the cell length scale
+                inline const scalarField& cellLengthScale() const;
+
 
             // References to the carrier gas fields
 
diff --git a/src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloudI.H b/src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloudI.H
index 1bbf47b41a5..ed0f74793f4 100644
--- a/src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloudI.H
+++ b/src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloudI.H
@@ -517,6 +517,14 @@ Foam::KinematicCloud<CloudType>::cellOccupancy()
 }
 
 
+template<class CloudType>
+inline const Foam::scalarField&
+Foam::KinematicCloud<CloudType>::cellLengthScale() const
+{
+    return cellLengthScale_;
+}
+
+
 template<class CloudType>
 inline Foam::DimensionedField<Foam::vector, Foam::volMesh>&
 Foam::KinematicCloud<CloudType>::UTrans()
diff --git a/src/lagrangian/intermediate/parcels/Templates/KinematicParcel/KinematicParcel.C b/src/lagrangian/intermediate/parcels/Templates/KinematicParcel/KinematicParcel.C
index b8339628257..22e01b9a98c 100644
--- a/src/lagrangian/intermediate/parcels/Templates/KinematicParcel/KinematicParcel.C
+++ b/src/lagrangian/intermediate/parcels/Templates/KinematicParcel/KinematicParcel.C
@@ -265,7 +265,7 @@ bool Foam::KinematicParcel<ParcelType>::move
 
     const polyMesh& mesh = td.cloud().pMesh();
     const polyBoundaryMesh& pbMesh = mesh.boundaryMesh();
-    const scalarField& V = mesh.cellVolumes();
+    const scalarField& cellLengthScale = td.cloud().cellLengthScale();
     const scalar maxCo = td.cloud().solution().maxCo();
 
     scalar tEnd = (1.0 - p.stepFraction())*trackTime;
@@ -290,7 +290,7 @@ bool Foam::KinematicParcel<ParcelType>::move
         if (p.active() && moving && (magU > ROOTVSMALL))
         {
             const scalar d = dt*magU;
-            const scalar dCorr = min(d, maxCo*cbrt(V[cellI]));
+            const scalar dCorr = min(d, maxCo*cellLengthScale[cellI]);
             dt *=
                 dCorr/d
                *p.trackToFace(p.position() + dCorr*U_/magU, td);
-- 
GitLab