From 6b2fb4664cfe413613ed8878b71d33f76e7056c9 Mon Sep 17 00:00:00 2001
From: Henry <Henry>
Date: Fri, 8 May 2015 09:51:36 +0100
Subject: [PATCH] twoPhaseEulerFoam: Update only the fixed-value phi patch
 fields before constructing the pressure eqn Avoids small continuity error in
 parallel

---
 .../multiphase/twoPhaseEulerFoam/pU/pEqn.H    | 35 ++++++++++++-------
 .../multiphase/twoPhaseEulerFoam/pUf/pEqn.H   | 26 +++++++++++---
 .../twoPhaseSystem/phaseModel/phaseModel.C    |  3 +-
 3 files changed, 46 insertions(+), 18 deletions(-)

diff --git a/applications/solvers/multiphase/twoPhaseEulerFoam/pU/pEqn.H b/applications/solvers/multiphase/twoPhaseEulerFoam/pU/pEqn.H
index 819e4ed4294..e9567bf7e22 100644
--- a/applications/solvers/multiphase/twoPhaseEulerFoam/pU/pEqn.H
+++ b/applications/solvers/multiphase/twoPhaseEulerFoam/pU/pEqn.H
@@ -22,8 +22,6 @@ volScalarField rAU2
     )
 );
 
-//surfaceScalarField alpharAUf1(fvc::interpolate(alpha1*rAU1));
-//surfaceScalarField alpharAUf2(fvc::interpolate(alpha2*rAU2));
 surfaceScalarField alpharAUf1
 (
     fvc::interpolate(max(alpha1, fluid.residualAlpha(phase1))*rAU1)
@@ -94,10 +92,26 @@ while (pimple.correct())
     #include "correctContErrs.H"
 
     // Correct flux BCs to be consistent with the velocity BCs
-    phi1.boundaryField() ==
-        mrfZones.relative(mesh.Sf().boundaryField() & U1.boundaryField());
-    phi2.boundaryField() ==
-        mrfZones.relative(mesh.Sf().boundaryField() & U2.boundaryField());
+    forAll(mesh.boundary(), patchi)
+    {
+        if (isA<fixedValueFvsPatchScalarField>(phi1.boundaryField()[patchi]))
+        {
+            phi1.boundaryField()[patchi] ==
+                mrfZones.relative
+                (
+                    mesh.Sf().boundaryField() & U1.boundaryField()
+                )()[patchi];
+        }
+
+        if (isA<fixedValueFvsPatchScalarField>(phi2.boundaryField()[patchi]))
+        {
+            phi2.boundaryField()[patchi] ==
+                mrfZones.relative
+                (
+                    mesh.Sf().boundaryField() & U2.boundaryField()
+                )()[patchi];
+        }
+    }
 
     volVectorField HbyA1
     (
@@ -227,12 +241,9 @@ while (pimple.correct())
         p_rgh.boundaryField(),
         (
             phiHbyA.boundaryField()
-          - mrfZones.relative
-            (
-                alphaf1.boundaryField()
-               *(mesh.Sf().boundaryField() & U1.boundaryField())
-              + alphaf2.boundaryField()
-               *(mesh.Sf().boundaryField() & U2.boundaryField())
+          - (
+                alphaf1.boundaryField()*phi1.boundaryField()
+              + alphaf2.boundaryField()*phi2.boundaryField()
             )
         )/(mesh.magSf().boundaryField()*rAUf.boundaryField())
     );
diff --git a/applications/solvers/multiphase/twoPhaseEulerFoam/pUf/pEqn.H b/applications/solvers/multiphase/twoPhaseEulerFoam/pUf/pEqn.H
index 5d39ce0d7c6..5f508913110 100644
--- a/applications/solvers/multiphase/twoPhaseEulerFoam/pUf/pEqn.H
+++ b/applications/solvers/multiphase/twoPhaseEulerFoam/pUf/pEqn.H
@@ -98,11 +98,27 @@ while (pimple.correct())
     surfaceScalarField rhof1(fvc::interpolate(rho1));
     surfaceScalarField rhof2(fvc::interpolate(rho2));
 
-    // Correct flux BCs to be consistent with the velocity BCs
-    phi1.boundaryField() ==
-        mrfZones.relative(mesh.Sf().boundaryField() & U1.boundaryField());
-    phi2.boundaryField() ==
-        mrfZones.relative(mesh.Sf().boundaryField() & U2.boundaryField());
+    // Correct fixed-flux BCs to be consistent with the velocity BCs
+    forAll(mesh.boundary(), patchi)
+    {
+        if (isA<fixedValueFvsPatchScalarField>(phi1.boundaryField()[patchi]))
+        {
+            phi1.boundaryField()[patchi] ==
+                mrfZones.relative
+                (
+                    mesh.Sf().boundaryField() & U1.boundaryField()
+                )()[patchi];
+        }
+
+        if (isA<fixedValueFvsPatchScalarField>(phi2.boundaryField()[patchi]))
+        {
+            phi2.boundaryField()[patchi] ==
+                mrfZones.relative
+                (
+                    mesh.Sf().boundaryField() & U2.boundaryField()
+                )()[patchi];
+        }
+    }
 
     surfaceScalarField alpharAUf1
     (
diff --git a/applications/solvers/multiphase/twoPhaseEulerFoam/twoPhaseSystem/phaseModel/phaseModel.C b/applications/solvers/multiphase/twoPhaseEulerFoam/twoPhaseSystem/phaseModel/phaseModel.C
index 2b99be00b8c..5a861911f97 100644
--- a/applications/solvers/multiphase/twoPhaseEulerFoam/twoPhaseSystem/phaseModel/phaseModel.C
+++ b/applications/solvers/multiphase/twoPhaseEulerFoam/twoPhaseSystem/phaseModel/phaseModel.C
@@ -30,6 +30,7 @@ License
 #include "PhaseCompressibleTurbulenceModel.H"
 #include "dragModel.H"
 #include "heatTransferModel.H"
+#include "fixedValueFvsPatchFields.H"
 #include "fixedValueFvPatchFields.H"
 #include "slipFvPatchFields.H"
 #include "partialSlipFvPatchFields.H"
@@ -151,7 +152,7 @@ Foam::phaseModel::phaseModel
              || isA<partialSlipFvPatchVectorField>(U_.boundaryField()[i])
             )
             {
-                phiTypes[i] = fixedValueFvPatchScalarField::typeName;
+                phiTypes[i] = fixedValueFvsPatchScalarField::typeName;
             }
         }
 
-- 
GitLab