From 385248c5bf57065bbaa0d19e61a811f3f6273660 Mon Sep 17 00:00:00 2001
From: andy <andy>
Date: Fri, 7 Oct 2011 10:21:02 +0100
Subject: [PATCH] ENH: Propogated binary op for inter-region comms to region
 model

---
 .../regionModel/regionModel/regionModel.H     | 18 +++++
 .../regionModel/regionModelTemplates.C        | 65 +++++++++++++++++++
 2 files changed, 83 insertions(+)

diff --git a/src/regionModels/regionModel/regionModel/regionModel.H b/src/regionModels/regionModel/regionModel/regionModel.H
index 2af98421d10..49f708bcd81 100644
--- a/src/regionModels/regionModel/regionModel/regionModel.H
+++ b/src/regionModels/regionModel/regionModel/regionModel.H
@@ -231,6 +231,24 @@ public:
                 List<Type>& primaryFieldField
             ) const;
 
+            //- Convert a local region field to the primary region with op
+            template<class Type, class BinaryOp>
+            void toPrimary
+            (
+                const label regionPatchI,
+                List<Type>& regionField,
+                const BinaryOp& bop
+            ) const;
+
+            //- Convert a primary region field to the local region with op
+            template<class Type, class BinaryOp>
+            void toRegion
+            (
+                const label regionPatchI,
+                List<Type>& primaryFieldField,
+                const BinaryOp& bop
+            ) const;
+
 
         // Evolution
 
diff --git a/src/regionModels/regionModel/regionModel/regionModelTemplates.C b/src/regionModels/regionModel/regionModel/regionModelTemplates.C
index 977da7dd816..ab013ad8e08 100644
--- a/src/regionModels/regionModel/regionModel/regionModelTemplates.C
+++ b/src/regionModels/regionModel/regionModel/regionModelTemplates.C
@@ -77,4 +77,69 @@ void Foam::regionModels::regionModel::toRegion
 }
 
 
+template<class Type, class BinaryOp>
+void Foam::regionModels::regionModel::toPrimary
+(
+    const label regionPatchI,
+    List<Type>& regionField,
+    const BinaryOp& bop
+) const
+{
+    forAll(intCoupledPatchIDs_, i)
+    {
+        if (intCoupledPatchIDs_[i] == regionPatchI)
+        {
+            const mappedPatchBase& mpb =
+                refCast<const mappedPatchBase>
+                (
+                    regionMesh().boundaryMesh()[regionPatchI]
+                );
+            mpb.reverseDistribute(regionField, bop);
+            return;
+        }
+    }
+
+    FatalErrorIn
+    (
+        "const void toPrimary"
+        "("
+            "const label, "
+            "List<Type>&, "
+            "const BinaryOp&"
+        ") const"
+    )   << "Region patch ID " << regionPatchI << " not found in region mesh"
+        << abort(FatalError);
+}
+
+
+template<class Type, class BinaryOp>
+void Foam::regionModels::regionModel::toRegion
+(
+    const label regionPatchI,
+    List<Type>& primaryField,
+    const BinaryOp& bop
+) const
+{
+    forAll(intCoupledPatchIDs_, i)
+    {
+        if (intCoupledPatchIDs_[i] == regionPatchI)
+        {
+            const mappedPatchBase& mpb =
+                refCast<const mappedPatchBase>
+                (
+                    regionMesh().boundaryMesh()[regionPatchI]
+                );
+            mpb.distribute(primaryField, bop);
+            return;
+        }
+    }
+
+    FatalErrorIn
+    (
+        "const void toRegion(const label, List<Type>&, const BinaryOp&) const"
+    )   << "Region patch ID " << regionPatchI << " not found in region mesh"
+        << abort(FatalError);
+}
+
+
 // ************************************************************************* //
-- 
GitLab