From c7ded8226ed3f333e9a482835ecb80e271f05d20 Mon Sep 17 00:00:00 2001
From: andy <andy>
Date: Tue, 8 Jan 2013 17:52:51 +0000
Subject: [PATCH] ENH: Added calculation of overlap volume to meshToMesh
 interpolation

---
 .../meshToMesh/calculateMeshToMeshWeights.C   | 27 ++++++++++++++++++-
 .../meshToMesh/meshToMesh.C                   |  8 +++---
 .../meshToMesh/meshToMesh.H                   | 14 ++++++++--
 3 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/src/sampling/meshToMeshInterpolation/meshToMesh/calculateMeshToMeshWeights.C b/src/sampling/meshToMeshInterpolation/meshToMesh/calculateMeshToMeshWeights.C
index 5ffd6de0e14..b967f5a338b 100644
--- a/src/sampling/meshToMeshInterpolation/meshToMesh/calculateMeshToMeshWeights.C
+++ b/src/sampling/meshToMeshInterpolation/meshToMesh/calculateMeshToMeshWeights.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011-2012 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2013 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -43,6 +43,9 @@ void Foam::meshToMesh::calculateInverseDistanceWeights() const
             << exit(FatalError);
     }
 
+    //- Initialise overlap volume to zero
+    V_ = 0.0;
+
     inverseDistanceWeightsPtr_ = new scalarListList(toMesh_.nCells());
     scalarListList& invDistCoeffs = *inverseDistanceWeightsPtr_;
 
@@ -70,6 +73,7 @@ void Foam::meshToMesh::calculateInverseDistanceWeights() const
             {
                 invDistCoeffs[celli].setSize(1);
                 invDistCoeffs[celli][0] = 1.0;
+                V_ += fromMesh_.V()[cellAddressing_[celli]];
             }
             else
             {
@@ -94,6 +98,16 @@ void Foam::meshToMesh::calculateInverseDistanceWeights() const
                 {
                     invDistCoeffs[celli][i] /= sumInvDist;
                 }
+
+
+                V_ +=
+                    invDistCoeffs[celli][0]
+                   *fromMesh_.V()[cellAddressing_[celli]];
+                for (label i = 1; i < invDistCoeffs[celli].size(); i++)
+                {
+                    V_ +=
+                        invDistCoeffs[celli][i]*fromMesh_.V()[neighbours[i-1]];
+                }
             }
         }
     }
@@ -115,6 +129,9 @@ void Foam::meshToMesh::calculateInverseVolumeWeights() const
             << exit(FatalError);
     }
 
+    //- Initialise overlap volume to zero
+    V_ = 0.0;
+
     inverseVolumeWeightsPtr_ = new scalarListList(toMesh_.nCells());
     scalarListList& invVolCoeffs = *inverseVolumeWeightsPtr_;
 
@@ -152,6 +169,8 @@ void Foam::meshToMesh::calculateInverseVolumeWeights() const
                     bbFromMesh
                 );
                 invVolCoeffs[celli][j] = v/toMesh_.V()[celli];
+
+                V_ += v;
             }
         }
     }
@@ -173,6 +192,9 @@ void Foam::meshToMesh::calculateCellToCellAddressing() const
             << exit(FatalError);
     }
 
+    //- Initialise overlap volume to zero
+    V_ = 0.0;
+
     tetOverlapVolume overlapEngine;
 
     cellToCellAddressingPtr_ = new labelListList(toMesh_.nCells());
@@ -192,6 +214,7 @@ void Foam::meshToMesh::calculateCellToCellAddressing() const
             forAll(overLapCells, j)
             {
                 cellToCell[iTo][j] = overLapCells[j];
+                V_ += fromMesh_.V()[overLapCells[j]];
             }
         }
     }
@@ -220,6 +243,7 @@ const Foam::scalarListList& Foam::meshToMesh::inverseVolumeWeights() const
     return *inverseVolumeWeightsPtr_;
 }
 
+
 const Foam::labelListList& Foam::meshToMesh::cellToCellAddressing() const
 {
     if (!cellToCellAddressingPtr_)
@@ -230,4 +254,5 @@ const Foam::labelListList& Foam::meshToMesh::cellToCellAddressing() const
     return *cellToCellAddressingPtr_;
 }
 
+
 // ************************************************************************* //
diff --git a/src/sampling/meshToMeshInterpolation/meshToMesh/meshToMesh.C b/src/sampling/meshToMeshInterpolation/meshToMesh/meshToMesh.C
index 3cbd5fd02f3..cbd1aafc294 100644
--- a/src/sampling/meshToMeshInterpolation/meshToMesh/meshToMesh.C
+++ b/src/sampling/meshToMeshInterpolation/meshToMesh/meshToMesh.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011-2012 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2013 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -54,7 +54,8 @@ Foam::meshToMesh::meshToMesh
     boundaryAddressing_(toMesh_.boundaryMesh().size()),
     inverseDistanceWeightsPtr_(NULL),
     inverseVolumeWeightsPtr_(NULL),
-    cellToCellAddressingPtr_(NULL)
+    cellToCellAddressingPtr_(NULL),
+    V_(0.0)
 {
     forAll(fromMesh_.boundaryMesh(), patchi)
     {
@@ -126,7 +127,8 @@ Foam::meshToMesh::meshToMesh
     boundaryAddressing_(toMesh_.boundaryMesh().size()),
     inverseDistanceWeightsPtr_(NULL),
     inverseVolumeWeightsPtr_(NULL),
-    cellToCellAddressingPtr_(NULL)
+    cellToCellAddressingPtr_(NULL),
+    V_(0.0)
 {
     // check whether both meshes have got the same number
     // of boundary patches
diff --git a/src/sampling/meshToMeshInterpolation/meshToMesh/meshToMesh.H b/src/sampling/meshToMeshInterpolation/meshToMesh/meshToMesh.H
index e60871be259..9344f75ba0e 100644
--- a/src/sampling/meshToMeshInterpolation/meshToMesh/meshToMesh.H
+++ b/src/sampling/meshToMeshInterpolation/meshToMesh/meshToMesh.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2013 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -94,6 +94,9 @@ class meshToMesh
         //- Cell to cell overlap addressing
         mutable labelListList* cellToCellAddressingPtr_;
 
+        //- Overlap volume
+        mutable scalar V_;
+
 
     // Private Member Functions
 
@@ -231,6 +234,13 @@ public:
                 return cellAddressing_;
             }
 
+            //- Overlap volume
+            scalar V() const
+            {
+                return V_;
+            }
+
+
         // Interpolation
 
             //- Map field
@@ -275,7 +285,7 @@ public:
                 const labelList& adr,
                 const vectorField& centres,
                 const CombineOp& cop
-            ) const;
+            )const;
 
 
             //- Interpolate internal volume field
-- 
GitLab