From a7524700f15efb6c169327afceacccc22e140e52 Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Thu, 11 Apr 2019 18:01:55 +0100
Subject: [PATCH] ENH: overset: overlap communications

---
 .../oversetPolyPatch/oversetFvPatchField.C    | 63 ++++++++++++++++++-
 .../oversetPolyPatch/oversetFvPatchField.H    | 20 ++++++
 2 files changed, 80 insertions(+), 3 deletions(-)

diff --git a/src/overset/oversetPolyPatch/oversetFvPatchField.C b/src/overset/oversetPolyPatch/oversetFvPatchField.C
index b0698afc32e..2a72d57e20f 100644
--- a/src/overset/oversetPolyPatch/oversetFvPatchField.C
+++ b/src/overset/oversetPolyPatch/oversetFvPatchField.C
@@ -211,6 +211,59 @@ void Foam::oversetFvPatchField<Type>::initEvaluate
 }
 
 
+template<class Type>
+void Foam::oversetFvPatchField<Type>::initInterfaceMatrixUpdate
+(
+    scalarField&,
+    const bool add,
+    const scalarField& psiInternal,
+    const scalarField&,
+    const direction,
+    const Pstream::commsTypes commsType
+) const
+{
+    // Add remote values
+
+    const oversetFvPatch& ovp = this->oversetPatch_;
+
+    if (ovp.master())
+    {
+        const fvMesh& mesh = this->patch().boundaryMesh().mesh();
+
+        // Try to find out if the solve routine comes from the mesh
+        // TBD. This should be cleaner.
+        if (&mesh.lduAddr() == &mesh.fvMesh::lduAddr())
+        {
+            return;
+        }
+
+        const mapDistribute& map = ovp.cellInterpolationMap();
+
+        // Transfer the current state (similar to processorFvPatchField). Note
+        // use of separate tag to avoid clashes with any outstanding processor
+        // exchanges
+        if (this->pBufs_.valid())
+        {
+            this->pBufs_().clear();
+        }
+        else
+        {
+            this->pBufs_.set
+            (
+                new PstreamBuffers
+                (
+                    Pstream::commsTypes::nonBlocking,
+                    UPstream::msgType()+1
+                )
+            );
+        }
+
+        // Start sending
+        map.mapDistributeBase::send(this->pBufs_(), psiInternal);
+    }
+}
+
+
 template<class Type>
 void Foam::oversetFvPatchField<Type>::updateInterfaceMatrix
 (
@@ -251,11 +304,14 @@ void Foam::oversetFvPatchField<Type>::updateInterfaceMatrix
         const scalarList& factor = ovp.cellInterpolationWeight();
         const scalarField& normalisation = ovp.normalisation();
 
-
         // Since we're inside initEvaluate/evaluate there might be processor
         // comms underway. Change the tag we use.
-        scalarField work(psiInternal);
-        map.mapDistributeBase::distribute(work, UPstream::msgType()+1);
+        //scalarField work(psiInternal);
+        //map.mapDistributeBase::distribute(work, UPstream::msgType()+1);
+
+        // Receive the outstanding data
+        scalarField work;
+        map.receive(this->pBufs_(), work);
 
         forAll(cellIDs, i)
         {
@@ -263,6 +319,7 @@ void Foam::oversetFvPatchField<Type>::updateInterfaceMatrix
 
             const scalarList& w = wghts[celli];
             const labelList& nbrs = stencil[celli];
+
             scalar f = factor[celli];
             const scalar norm = normalisation[celli];
 
diff --git a/src/overset/oversetPolyPatch/oversetFvPatchField.H b/src/overset/oversetPolyPatch/oversetFvPatchField.H
index 9cae63dc43c..9ed9aa99c07 100644
--- a/src/overset/oversetPolyPatch/oversetFvPatchField.H
+++ b/src/overset/oversetPolyPatch/oversetFvPatchField.H
@@ -56,6 +56,14 @@ class oversetFvPatchField
 :
     public semiImplicitOversetFvPatchField<Type>
 {
+protected:
+
+    // Protected data
+
+        //- Send/receive buffer
+        mutable autoPtr<PstreamBuffers> pBufs_;
+
+
 public:
 
     //- Runtime type information
@@ -127,6 +135,18 @@ public:
             //- Initialise the evaluation of the patch field
             virtual void initEvaluate(const Pstream::commsTypes commsType);
 
+            //- Initialise neighbour matrix update. Add
+            //  or subtract coupled contributions to matrix
+            virtual void initInterfaceMatrixUpdate
+            (
+                scalarField&,
+                const bool add,
+                const scalarField&,
+                const scalarField&,
+                const direction,
+                const Pstream::commsTypes commsType
+            ) const;
+
             //- Update result field based on interface functionality
             virtual void updateInterfaceMatrix
             (
-- 
GitLab