From 114c9851ca2556295945f84d7f342b06048d91c5 Mon Sep 17 00:00:00 2001
From: andy <andy>
Date: Tue, 31 Jul 2012 15:03:26 +0100
Subject: [PATCH] ENH: Enabled writing of mass stick/escape for particle
 localInteraction model

---
 .../LocalInteraction/LocalInteraction.C       | 110 ++++++++++++++++--
 .../LocalInteraction/LocalInteraction.H       |  17 +++
 2 files changed, 119 insertions(+), 8 deletions(-)

diff --git a/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/LocalInteraction/LocalInteraction.C b/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/LocalInteraction/LocalInteraction.C
index c1ce95e215c..2350ee62f88 100644
--- a/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/LocalInteraction/LocalInteraction.C
+++ b/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/LocalInteraction/LocalInteraction.C
@@ -39,8 +39,26 @@ Foam::LocalInteraction<CloudType>::LocalInteraction
     nEscape_(patchData_.size(), 0),
     massEscape_(patchData_.size(), 0.0),
     nStick_(patchData_.size(), 0),
-    massStick_(patchData_.size(), 0.0)
+    massStick_(patchData_.size(), 0.0),
+    writeFields_(this->coeffDict().lookupOrDefault("writeFields", false)),
+    massEscapePtr_(NULL),
+    massStickPtr_(NULL)
 {
+    if (writeFields_)
+    {
+        word massEscapeName(this->owner().name() + "::massEscape");
+        word massStickName(this->owner().name() + "::massStick");
+        Info<< "    Interaction fields will be written to " << massEscapeName
+            << " and " << massStickName << endl;
+
+        (void)massEscape();
+        (void)massStick();
+    }
+    else
+    {
+        Info<< "    Interaction fields will not be written" << endl;
+    }
+
     // check that interactions are valid/specified
     forAll(patchData_, patchI)
     {
@@ -74,7 +92,10 @@ Foam::LocalInteraction<CloudType>::LocalInteraction
     nEscape_(pim.nEscape_),
     massEscape_(pim.massEscape_),
     nStick_(pim.nStick_),
-    massStick_(pim.massStick_)
+    massStick_(pim.massStick_),
+    writeFields_(pim.writeFields_),
+    massEscapePtr_(NULL),
+    massStickPtr_(NULL)
 {}
 
 
@@ -87,6 +108,64 @@ Foam::LocalInteraction<CloudType>::~LocalInteraction()
 
 // * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
 
+template<class CloudType>
+Foam::volScalarField& Foam::LocalInteraction<CloudType>::massEscape()
+{
+    if (!massEscapePtr_.valid())
+    {
+        const fvMesh& mesh = this->owner().mesh();
+
+        massEscapePtr_.reset
+        (
+            new volScalarField
+            (
+                IOobject
+                (
+                    this->owner().name() + "::massEscape",
+                    mesh.time().timeName(),
+                    mesh,
+                    IOobject::READ_IF_PRESENT,
+                    IOobject::AUTO_WRITE
+                ),
+                mesh,
+                dimensionedScalar("zero", dimMass, 0.0)
+            )
+        );
+    }
+
+    return massEscapePtr_();
+}
+
+
+template<class CloudType>
+Foam::volScalarField& Foam::LocalInteraction<CloudType>::massStick()
+{
+    if (!massStickPtr_.valid())
+    {
+        const fvMesh& mesh = this->owner().mesh();
+
+        massStickPtr_.reset
+        (
+            new volScalarField
+            (
+                IOobject
+                (
+                    this->owner().name() + "::massStick",
+                    mesh.time().timeName(),
+                    mesh,
+                    IOobject::READ_IF_PRESENT,
+                    IOobject::AUTO_WRITE
+                ),
+                mesh,
+                dimensionedScalar("zero", dimMass, 0.0)
+            )
+        );
+    }
+
+    return massStickPtr_();
+}
+
+
 template<class CloudType>
 bool Foam::LocalInteraction<CloudType>::correct
 (
@@ -97,14 +176,13 @@ bool Foam::LocalInteraction<CloudType>::correct
     const tetIndices& tetIs
 )
 {
-    vector& U = p.U();
-
-    bool& active = p.active();
-
     label patchI = patchData_.applyToPatch(pp.index());
 
     if (patchI >= 0)
     {
+        vector& U = p.U();
+        bool& active = p.active();
+
         typename PatchInteractionModel<CloudType>::interactionType it =
             this->wordToInteractionType
             (
@@ -115,20 +193,36 @@ bool Foam::LocalInteraction<CloudType>::correct
         {
             case PatchInteractionModel<CloudType>::itEscape:
             {
+                scalar dm = p.mass()*p.nParticle();
+
                 keepParticle = false;
                 active = false;
                 U = vector::zero;
                 nEscape_[patchI]++;
-                massEscape_[patchI] += p.mass()*p.nParticle();
+                massEscape_[patchI] += dm;
+                if (writeFields_)
+                {
+                    label pI = pp.index();
+                    label fI = pp.whichFace(p.face());
+                    massEscape().boundaryField()[pI][fI] += dm;
+                }
                 break;
             }
             case PatchInteractionModel<CloudType>::itStick:
             {
+                scalar dm = p.mass()*p.nParticle();
+
                 keepParticle = true;
                 active = false;
                 U = vector::zero;
                 nStick_[patchI]++;
-                massStick_[patchI] += p.mass()*p.nParticle();
+                massStick_[patchI] += dm;
+                if (writeFields_)
+                {
+                    label pI = pp.index();
+                    label fI = pp.whichFace(p.face());
+                    massStick().boundaryField()[pI][fI] += dm;
+                }
                 break;
             }
             case PatchInteractionModel<CloudType>::itRebound:
diff --git a/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/LocalInteraction/LocalInteraction.H b/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/LocalInteraction/LocalInteraction.H
index a3a28121f0f..3a8c7767763 100644
--- a/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/LocalInteraction/LocalInteraction.H
+++ b/src/lagrangian/intermediate/submodels/Kinematic/PatchInteractionModel/LocalInteraction/LocalInteraction.H
@@ -34,6 +34,7 @@ Description
 
 #include "PatchInteractionModel.H"
 #include "patchInteractionDataList.H"
+#include "Switch.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -69,6 +70,16 @@ class LocalInteraction
             List<scalar> massStick_;
 
 
+        //- Flag to output data as fields
+        Switch writeFields_;
+
+        //- Mass escape field
+        autoPtr<volScalarField> massEscapePtr_;
+
+        //- Mass stick field
+        autoPtr<volScalarField> massStickPtr_;
+
+
 public:
 
     //- Runtime type information
@@ -99,6 +110,12 @@ public:
 
     // Member Functions
 
+        //- Return access to the massEscape field
+        volScalarField& massEscape();
+
+        //- Return access to the massStick field
+        volScalarField& massStick();
+
         //- Apply velocity correction
         //  Returns true if particle remains in same cell
         virtual bool correct
-- 
GitLab