From ca540320dfa9c687312853af2672a41d92800e79 Mon Sep 17 00:00:00 2001
From: sergio <s.ferraris@opencfd.co.uk>
Date: Tue, 23 Jun 2020 08:13:33 -0700
Subject: [PATCH] BUG: Correcting htc definition to avoid negative values

---
 ...ernalCoupledTemperatureMixedFvPatchScalarField.C | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/functionObjects/field/externalCoupled/externalCoupledTemperatureMixed/externalCoupledTemperatureMixedFvPatchScalarField.C b/src/functionObjects/field/externalCoupled/externalCoupledTemperatureMixed/externalCoupledTemperatureMixedFvPatchScalarField.C
index 2db768229d1..2d5209d7b1a 100644
--- a/src/functionObjects/field/externalCoupled/externalCoupledTemperatureMixed/externalCoupledTemperatureMixedFvPatchScalarField.C
+++ b/src/functionObjects/field/externalCoupled/externalCoupledTemperatureMixed/externalCoupledTemperatureMixedFvPatchScalarField.C
@@ -283,9 +283,18 @@ void Foam::externalCoupledTemperatureMixedFvPatchScalarField::writeData
 
     const scalarField Tfluid(tfluid);
 
-
     // Heat transfer coefficient [W/m2/K]
-    const scalarField htc(qDot/(max(Twall - Tfluid), 1e-3));
+    // This htc needs to be always larger or equal to zero
+    //const scalarField htc(qDot/max(Twall - Tfluid, 1e-3));
+    scalarField htc(qDot.size(), 0);
+    forAll (qDot, i)
+    {
+        scalar deltaT = mag(Twall[i] - Tfluid[i]);
+        if (deltaT > 1e-3)
+        {
+            htc[i] = sign(qDot[i])*qDot[i]/deltaT;
+        }
+    }
 
     const Field<scalar>& magSf = this->patch().magSf();
 
-- 
GitLab