From 8aa7b1353f38216022bccf032a9e3712b944e599 Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Thu, 26 Jul 2018 16:55:49 +0100
Subject: [PATCH] ENH: refCast: give better error messages. Fixes #953.

---
 src/OpenFOAM/db/typeInfo/typeInfo.H           | 42 +++++++++++++++++++
 .../constraint/cyclic/cyclicPointPatchField.C |  2 +-
 .../processor/processorPointPatchField.C      |  2 +-
 .../processorCyclicPointPatchField.C          |  2 +-
 .../symmetryPlanePointPatchField.C            |  2 +-
 .../basic/coupled/coupledFaPatchField.C       |  2 +-
 .../constraint/cyclic/cyclicFaPatchField.C    |  2 +-
 .../processor/processorFaPatchField.C         |  2 +-
 .../constraint/cyclic/cyclicFaePatchField.C   |  2 +-
 .../processor/processorFaePatchField.C        |  2 +-
 .../basic/coupled/coupledFvPatchField.C       |  2 +-
 .../constraint/cyclic/cyclicFvPatchField.C    |  2 +-
 .../cyclicACMI/cyclicACMIFvPatchField.C       |  2 +-
 .../cyclicAMI/cyclicAMIFvPatchField.C         |  2 +-
 .../processor/processorFvPatchField.C         |  2 +-
 .../processorCyclicFvPatchField.C             |  2 +-
 .../symmetryPlane/symmetryPlaneFvPatchField.C |  2 +-
 .../activeBaffleVelocityFvPatchVectorField.C  |  3 +-
 ...ureForceBaffleVelocityFvPatchVectorField.C |  3 +-
 ...mappedVelocityFluxFixedValueFvPatchField.C |  3 +-
 .../constraint/cyclic/cyclicFvsPatchField.C   |  2 +-
 .../cyclicACMI/cyclicACMIFvsPatchField.C      |  2 +-
 .../cyclicAMI/cyclicAMIFvsPatchField.C        |  2 +-
 .../processor/processorFvsPatchField.C        |  2 +-
 .../processorCyclicFvsPatchField.C            |  2 +-
 .../cyclicACMIPointPatchField.C               |  2 +-
 .../cyclicAMIPointPatchField.C                |  2 +-
 .../energyRegionCoupledFvPatchScalarField.C   |  2 +-
 .../thermalBaffleFvPatchScalarField.C         |  2 +-
 29 files changed, 73 insertions(+), 28 deletions(-)

diff --git a/src/OpenFOAM/db/typeInfo/typeInfo.H b/src/OpenFOAM/db/typeInfo/typeInfo.H
index c29d7713c93..f0b1af2965a 100644
--- a/src/OpenFOAM/db/typeInfo/typeInfo.H
+++ b/src/OpenFOAM/db/typeInfo/typeInfo.H
@@ -100,6 +100,27 @@ inline To& dynamicCast(From& r)
 }
 
 
+//- Reference type cast template function,
+//  wraps dynamic_cast to handle bad_cast exception and generate a FatalError.
+template<class To, class From>
+inline To& dynamicCast(From& r, const dictionary& d)
+{
+    try
+    {
+        return dynamic_cast<To&>(r);
+    }
+    catch (std::bad_cast&)
+    {
+        FatalIOErrorInFunction(d)
+            << "Attempt to cast type " << typeid(r).name()
+            << " to type " << typeid(To).name()
+            << abort(FatalIOError);
+
+        return dynamic_cast<To&>(r);
+    }
+}
+
+
 //- Reference type cast template function.
 //  As per dynamicCast, but handles type names via the virtual type() method.
 template<class To, class From>
@@ -121,6 +142,27 @@ inline To& refCast(From& r)
 }
 
 
+//- Reference type cast template function.
+//  As per dynamicCast, but handles type names via the virtual type() method.
+template<class To, class From>
+inline To& refCast(From& r, const dictionary& d)
+{
+    try
+    {
+        return dynamic_cast<To&>(r);
+    }
+    catch (std::bad_cast&)
+    {
+        FatalIOErrorInFunction(d)
+            << "Attempt to cast type " << r.type()
+            << " to type " << To::typeName
+            << abort(FatalIOError);
+
+        return dynamic_cast<To&>(r);
+    }
+}
+
+
 //- Check the typeid
 template<class TestType, class Type>
 inline bool isType(const Type& t)
diff --git a/src/OpenFOAM/fields/pointPatchFields/constraint/cyclic/cyclicPointPatchField.C b/src/OpenFOAM/fields/pointPatchFields/constraint/cyclic/cyclicPointPatchField.C
index 02e66ce22ef..2ce727f3f57 100644
--- a/src/OpenFOAM/fields/pointPatchFields/constraint/cyclic/cyclicPointPatchField.C
+++ b/src/OpenFOAM/fields/pointPatchFields/constraint/cyclic/cyclicPointPatchField.C
@@ -51,7 +51,7 @@ Foam::cyclicPointPatchField<Type>::cyclicPointPatchField
 )
 :
     coupledPointPatchField<Type>(p, iF, dict),
-    cyclicPatch_(refCast<const cyclicPointPatch>(p))
+    cyclicPatch_(refCast<const cyclicPointPatch>(p, dict))
 {
     if (!isType<cyclicPointPatch>(p))
     {
diff --git a/src/OpenFOAM/fields/pointPatchFields/constraint/processor/processorPointPatchField.C b/src/OpenFOAM/fields/pointPatchFields/constraint/processor/processorPointPatchField.C
index 011129adc8d..1be4e558cc8 100644
--- a/src/OpenFOAM/fields/pointPatchFields/constraint/processor/processorPointPatchField.C
+++ b/src/OpenFOAM/fields/pointPatchFields/constraint/processor/processorPointPatchField.C
@@ -49,7 +49,7 @@ Foam::processorPointPatchField<Type>::processorPointPatchField
 )
 :
     coupledPointPatchField<Type>(p, iF, dict),
-    procPatch_(refCast<const processorPointPatch>(p))
+    procPatch_(refCast<const processorPointPatch>(p, dict))
 {}
 
 
diff --git a/src/OpenFOAM/fields/pointPatchFields/constraint/processorCyclic/processorCyclicPointPatchField.C b/src/OpenFOAM/fields/pointPatchFields/constraint/processorCyclic/processorCyclicPointPatchField.C
index aac70da39ff..01986e6af19 100644
--- a/src/OpenFOAM/fields/pointPatchFields/constraint/processorCyclic/processorCyclicPointPatchField.C
+++ b/src/OpenFOAM/fields/pointPatchFields/constraint/processorCyclic/processorCyclicPointPatchField.C
@@ -52,7 +52,7 @@ Foam::processorCyclicPointPatchField<Type>::processorCyclicPointPatchField
 )
 :
     coupledPointPatchField<Type>(p, iF, dict),
-    procPatch_(refCast<const processorCyclicPointPatch>(p)),
+    procPatch_(refCast<const processorCyclicPointPatch>(p, dict)),
     receiveBuf_(0)
 {}
 
diff --git a/src/OpenFOAM/fields/pointPatchFields/constraint/symmetryPlane/symmetryPlanePointPatchField.C b/src/OpenFOAM/fields/pointPatchFields/constraint/symmetryPlane/symmetryPlanePointPatchField.C
index 9351dac4bd8..ace223aaa63 100644
--- a/src/OpenFOAM/fields/pointPatchFields/constraint/symmetryPlane/symmetryPlanePointPatchField.C
+++ b/src/OpenFOAM/fields/pointPatchFields/constraint/symmetryPlane/symmetryPlanePointPatchField.C
@@ -48,7 +48,7 @@ Foam::symmetryPlanePointPatchField<Type>::symmetryPlanePointPatchField
 )
 :
     basicSymmetryPointPatchField<Type>(p, iF, dict),
-    symmetryPlanePatch_(refCast<const symmetryPlanePointPatch>(p))
+    symmetryPlanePatch_(refCast<const symmetryPlanePointPatch>(p, dict))
 {
     if (!isType<symmetryPlanePointPatch>(p))
     {
diff --git a/src/finiteArea/fields/faPatchFields/basic/coupled/coupledFaPatchField.C b/src/finiteArea/fields/faPatchFields/basic/coupled/coupledFaPatchField.C
index 4ef17cc1c29..0fd8e445fc3 100644
--- a/src/finiteArea/fields/faPatchFields/basic/coupled/coupledFaPatchField.C
+++ b/src/finiteArea/fields/faPatchFields/basic/coupled/coupledFaPatchField.C
@@ -76,7 +76,7 @@ Foam::coupledFaPatchField<Type>::coupledFaPatchField
     const dictionary& dict
 )
 :
-    lduInterfaceField(refCast<const lduInterface>(p)),
+    lduInterfaceField(refCast<const lduInterface>(p, dict)),
     faPatchField<Type>(p, iF, dict)
 {}
 
diff --git a/src/finiteArea/fields/faPatchFields/constraint/cyclic/cyclicFaPatchField.C b/src/finiteArea/fields/faPatchFields/constraint/cyclic/cyclicFaPatchField.C
index f192714258d..14fa7dcd3c3 100644
--- a/src/finiteArea/fields/faPatchFields/constraint/cyclic/cyclicFaPatchField.C
+++ b/src/finiteArea/fields/faPatchFields/constraint/cyclic/cyclicFaPatchField.C
@@ -75,7 +75,7 @@ Foam::cyclicFaPatchField<Type>::cyclicFaPatchField
 )
 :
     coupledFaPatchField<Type>(p, iF, dict),
-    cyclicPatch_(refCast<const cyclicFaPatch>(p))
+    cyclicPatch_(refCast<const cyclicFaPatch>(p, dict))
 {
     if (!isA<cyclicFaPatch>(p))
     {
diff --git a/src/finiteArea/fields/faPatchFields/constraint/processor/processorFaPatchField.C b/src/finiteArea/fields/faPatchFields/constraint/processor/processorFaPatchField.C
index b9bfdb2f1a7..9db7f49ac5d 100644
--- a/src/finiteArea/fields/faPatchFields/constraint/processor/processorFaPatchField.C
+++ b/src/finiteArea/fields/faPatchFields/constraint/processor/processorFaPatchField.C
@@ -92,7 +92,7 @@ Foam::processorFaPatchField<Type>::processorFaPatchField
 )
 :
     coupledFaPatchField<Type>(p, iF, dict),
-    procPatch_(refCast<const processorFaPatch>(p))
+    procPatch_(refCast<const processorFaPatch>(p, dict))
 {
     if (!isType<processorFaPatch>(p))
     {
diff --git a/src/finiteArea/fields/faePatchFields/constraint/cyclic/cyclicFaePatchField.C b/src/finiteArea/fields/faePatchFields/constraint/cyclic/cyclicFaePatchField.C
index a7f112f2b2c..0692c6a82d0 100644
--- a/src/finiteArea/fields/faePatchFields/constraint/cyclic/cyclicFaePatchField.C
+++ b/src/finiteArea/fields/faePatchFields/constraint/cyclic/cyclicFaePatchField.C
@@ -74,7 +74,7 @@ Foam::cyclicFaePatchField<Type>::cyclicFaePatchField
 )
 :
     coupledFaePatchField<Type>(p, iF, dict),
-    cyclicPatch_(refCast<const cyclicFaPatch>(p))
+    cyclicPatch_(refCast<const cyclicFaPatch>(p, dict))
 {
     if (!isType<cyclicFaPatch>(p))
     {
diff --git a/src/finiteArea/fields/faePatchFields/constraint/processor/processorFaePatchField.C b/src/finiteArea/fields/faePatchFields/constraint/processor/processorFaePatchField.C
index d2be94d30a8..fe3c5d7edc8 100644
--- a/src/finiteArea/fields/faePatchFields/constraint/processor/processorFaePatchField.C
+++ b/src/finiteArea/fields/faePatchFields/constraint/processor/processorFaePatchField.C
@@ -87,7 +87,7 @@ Foam::processorFaePatchField<Type>::processorFaePatchField
 )
 :
     coupledFaePatchField<Type>(p, iF, dict),
-    procPatch_(refCast<const processorFaPatch>(p))
+    procPatch_(refCast<const processorFaPatch>(p, dict))
 {
     if (!isType<processorFaPatch>(p))
     {
diff --git a/src/finiteVolume/fields/fvPatchFields/basic/coupled/coupledFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/basic/coupled/coupledFvPatchField.C
index d53c2505657..fb0454bdc29 100644
--- a/src/finiteVolume/fields/fvPatchFields/basic/coupled/coupledFvPatchField.C
+++ b/src/finiteVolume/fields/fvPatchFields/basic/coupled/coupledFvPatchField.C
@@ -75,7 +75,7 @@ Foam::coupledFvPatchField<Type>::coupledFvPatchField
     const bool valueRequired
 )
 :
-    LduInterfaceField<Type>(refCast<const lduInterface>(p)),
+    LduInterfaceField<Type>(refCast<const lduInterface>(p, dict)),
     fvPatchField<Type>(p, iF, dict, valueRequired)
 {}
 
diff --git a/src/finiteVolume/fields/fvPatchFields/constraint/cyclic/cyclicFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/constraint/cyclic/cyclicFvPatchField.C
index 9a6dc99faac..718fc5ca40c 100644
--- a/src/finiteVolume/fields/fvPatchFields/constraint/cyclic/cyclicFvPatchField.C
+++ b/src/finiteVolume/fields/fvPatchFields/constraint/cyclic/cyclicFvPatchField.C
@@ -49,7 +49,7 @@ Foam::cyclicFvPatchField<Type>::cyclicFvPatchField
 )
 :
     coupledFvPatchField<Type>(p, iF, dict, false),
-    cyclicPatch_(refCast<const cyclicFvPatch>(p))
+    cyclicPatch_(refCast<const cyclicFvPatch>(p, dict))
 {
     if (!isA<cyclicFvPatch>(p))
     {
diff --git a/src/finiteVolume/fields/fvPatchFields/constraint/cyclicACMI/cyclicACMIFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/constraint/cyclicACMI/cyclicACMIFvPatchField.C
index 912c44173d7..579faf41bf8 100644
--- a/src/finiteVolume/fields/fvPatchFields/constraint/cyclicACMI/cyclicACMIFvPatchField.C
+++ b/src/finiteVolume/fields/fvPatchFields/constraint/cyclicACMI/cyclicACMIFvPatchField.C
@@ -51,7 +51,7 @@ Foam::cyclicACMIFvPatchField<Type>::cyclicACMIFvPatchField
 :
     cyclicACMILduInterfaceField(),
     coupledFvPatchField<Type>(p, iF, dict, dict.found("value")),
-    cyclicACMIPatch_(refCast<const cyclicACMIFvPatch>(p))
+    cyclicACMIPatch_(refCast<const cyclicACMIFvPatch>(p, dict))
 {
     if (!isA<cyclicACMIFvPatch>(p))
     {
diff --git a/src/finiteVolume/fields/fvPatchFields/constraint/cyclicAMI/cyclicAMIFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/constraint/cyclicAMI/cyclicAMIFvPatchField.C
index 5bbce362be8..2888814b166 100644
--- a/src/finiteVolume/fields/fvPatchFields/constraint/cyclicAMI/cyclicAMIFvPatchField.C
+++ b/src/finiteVolume/fields/fvPatchFields/constraint/cyclicAMI/cyclicAMIFvPatchField.C
@@ -48,7 +48,7 @@ Foam::cyclicAMIFvPatchField<Type>::cyclicAMIFvPatchField
 :
     cyclicAMILduInterfaceField(),
     coupledFvPatchField<Type>(p, iF, dict, dict.found("value")),
-    cyclicAMIPatch_(refCast<const cyclicAMIFvPatch>(p))
+    cyclicAMIPatch_(refCast<const cyclicAMIFvPatch>(p, dict))
 {
     if (!isA<cyclicAMIFvPatch>(p))
     {
diff --git a/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchField.C
index 84405f38323..a9573c596fc 100644
--- a/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchField.C
+++ b/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchField.C
@@ -76,7 +76,7 @@ Foam::processorFvPatchField<Type>::processorFvPatchField
 )
 :
     coupledFvPatchField<Type>(p, iF, dict, dict.found("value")),
-    procPatch_(refCast<const processorFvPatch>(p)),
+    procPatch_(refCast<const processorFvPatch>(p, dict)),
     sendBuf_(0),
     receiveBuf_(0),
     outstandingSendRequest_(-1),
diff --git a/src/finiteVolume/fields/fvPatchFields/constraint/processorCyclic/processorCyclicFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/constraint/processorCyclic/processorCyclicFvPatchField.C
index 4cc2a4d53c5..be958aaacf9 100644
--- a/src/finiteVolume/fields/fvPatchFields/constraint/processorCyclic/processorCyclicFvPatchField.C
+++ b/src/finiteVolume/fields/fvPatchFields/constraint/processorCyclic/processorCyclicFvPatchField.C
@@ -51,7 +51,7 @@ Foam::processorCyclicFvPatchField<Type>::processorCyclicFvPatchField
 )
 :
     processorFvPatchField<Type>(p, iF, dict),
-    procPatch_(refCast<const processorCyclicFvPatch>(p))
+    procPatch_(refCast<const processorCyclicFvPatch>(p, dict))
 {
     if (!isType<processorCyclicFvPatch>(p))
     {
diff --git a/src/finiteVolume/fields/fvPatchFields/constraint/symmetryPlane/symmetryPlaneFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/constraint/symmetryPlane/symmetryPlaneFvPatchField.C
index 57d21f8f942..f8a8d0e71cc 100644
--- a/src/finiteVolume/fields/fvPatchFields/constraint/symmetryPlane/symmetryPlaneFvPatchField.C
+++ b/src/finiteVolume/fields/fvPatchFields/constraint/symmetryPlane/symmetryPlaneFvPatchField.C
@@ -73,7 +73,7 @@ Foam::symmetryPlaneFvPatchField<Type>::symmetryPlaneFvPatchField
 )
 :
     basicSymmetryFvPatchField<Type>(p, iF, dict),
-    symmetryPlanePatch_(refCast<const symmetryPlaneFvPatch>(p))
+    symmetryPlanePatch_(refCast<const symmetryPlaneFvPatch>(p, dict))
 {
     if (!isType<symmetryPlaneFvPatch>(p))
     {
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/activeBaffleVelocity/activeBaffleVelocityFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/activeBaffleVelocity/activeBaffleVelocityFvPatchVectorField.C
index 4761e61da7e..7b5a5910638 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/activeBaffleVelocity/activeBaffleVelocityFvPatchVectorField.C
+++ b/src/finiteVolume/fields/fvPatchFields/derived/activeBaffleVelocity/activeBaffleVelocityFvPatchVectorField.C
@@ -96,7 +96,8 @@ activeBaffleVelocityFvPatchVectorField
     (
         refCast<const cyclicFvPatch>
         (
-            p.boundaryMesh()[cyclicPatchLabel_]
+            p.boundaryMesh()[cyclicPatchLabel_],
+            dict
         ).neighbFvPatch().Sf()
     ),
     openFraction_(readScalar(dict.lookup("openFraction"))),
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/activePressureForceBaffleVelocity/activePressureForceBaffleVelocityFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/activePressureForceBaffleVelocity/activePressureForceBaffleVelocityFvPatchVectorField.C
index a0f66f5739c..575490bac42 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/activePressureForceBaffleVelocity/activePressureForceBaffleVelocityFvPatchVectorField.C
+++ b/src/finiteVolume/fields/fvPatchFields/derived/activePressureForceBaffleVelocity/activePressureForceBaffleVelocityFvPatchVectorField.C
@@ -115,7 +115,8 @@ activePressureForceBaffleVelocityFvPatchVectorField
         initCyclicSf_ = p.boundaryMesh()[cyclicPatchLabel_].Sf();
         nbrCyclicSf_ =  refCast<const cyclicFvPatch>
         (
-            p.boundaryMesh()[cyclicPatchLabel_]
+            p.boundaryMesh()[cyclicPatchLabel_],
+            dict
         ).neighbFvPatch().Sf();
     }
 
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedVelocityFluxFixedValue/mappedVelocityFluxFixedValueFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/mappedVelocityFluxFixedValue/mappedVelocityFluxFixedValueFvPatchField.C
index e35b556c480..7c9154c0a00 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/mappedVelocityFluxFixedValue/mappedVelocityFluxFixedValueFvPatchField.C
+++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedVelocityFluxFixedValue/mappedVelocityFluxFixedValueFvPatchField.C
@@ -94,7 +94,8 @@ mappedVelocityFluxFixedValueFvPatchField
 
     const mappedPatchBase& mpp = refCast<const mappedPatchBase>
     (
-        this->patch().patch()
+        this->patch().patch(),
+        dict
     );
     if (mpp.mode() == mappedPolyPatch::NEARESTCELL)
     {
diff --git a/src/finiteVolume/fields/fvsPatchFields/constraint/cyclic/cyclicFvsPatchField.C b/src/finiteVolume/fields/fvsPatchFields/constraint/cyclic/cyclicFvsPatchField.C
index 15fe2d9df7c..dab94137f15 100644
--- a/src/finiteVolume/fields/fvsPatchFields/constraint/cyclic/cyclicFvsPatchField.C
+++ b/src/finiteVolume/fields/fvsPatchFields/constraint/cyclic/cyclicFvsPatchField.C
@@ -48,7 +48,7 @@ Foam::cyclicFvsPatchField<Type>::cyclicFvsPatchField
 )
 :
     coupledFvsPatchField<Type>(p, iF, dict),
-    cyclicPatch_(refCast<const cyclicFvPatch>(p))
+    cyclicPatch_(refCast<const cyclicFvPatch>(p, dict))
 {
     if (!isA<cyclicFvPatch>(p))
     {
diff --git a/src/finiteVolume/fields/fvsPatchFields/constraint/cyclicACMI/cyclicACMIFvsPatchField.C b/src/finiteVolume/fields/fvsPatchFields/constraint/cyclicACMI/cyclicACMIFvsPatchField.C
index d230e64d5a5..86cfbabbf14 100644
--- a/src/finiteVolume/fields/fvsPatchFields/constraint/cyclicACMI/cyclicACMIFvsPatchField.C
+++ b/src/finiteVolume/fields/fvsPatchFields/constraint/cyclicACMI/cyclicACMIFvsPatchField.C
@@ -72,7 +72,7 @@ Foam::cyclicACMIFvsPatchField<Type>::cyclicACMIFvsPatchField
 )
 :
     coupledFvsPatchField<Type>(p, iF, dict),
-    cyclicACMIPatch_(refCast<const cyclicACMIFvPatch>(p))
+    cyclicACMIPatch_(refCast<const cyclicACMIFvPatch>(p, dict))
 {
     if (!isA<cyclicACMIFvPatch>(p))
     {
diff --git a/src/finiteVolume/fields/fvsPatchFields/constraint/cyclicAMI/cyclicAMIFvsPatchField.C b/src/finiteVolume/fields/fvsPatchFields/constraint/cyclicAMI/cyclicAMIFvsPatchField.C
index 4b92ffe8938..1862467aac6 100644
--- a/src/finiteVolume/fields/fvsPatchFields/constraint/cyclicAMI/cyclicAMIFvsPatchField.C
+++ b/src/finiteVolume/fields/fvsPatchFields/constraint/cyclicAMI/cyclicAMIFvsPatchField.C
@@ -72,7 +72,7 @@ Foam::cyclicAMIFvsPatchField<Type>::cyclicAMIFvsPatchField
 )
 :
     coupledFvsPatchField<Type>(p, iF, dict),
-    cyclicAMIPatch_(refCast<const cyclicAMIFvPatch>(p))
+    cyclicAMIPatch_(refCast<const cyclicAMIFvPatch>(p, dict))
 {
     if (!isA<cyclicAMIFvPatch>(p))
     {
diff --git a/src/finiteVolume/fields/fvsPatchFields/constraint/processor/processorFvsPatchField.C b/src/finiteVolume/fields/fvsPatchFields/constraint/processor/processorFvsPatchField.C
index a6fa1617905..a9f6bd3ca0c 100644
--- a/src/finiteVolume/fields/fvsPatchFields/constraint/processor/processorFvsPatchField.C
+++ b/src/finiteVolume/fields/fvsPatchFields/constraint/processor/processorFvsPatchField.C
@@ -61,7 +61,7 @@ Foam::processorFvsPatchField<Type>::processorFvsPatchField
 )
 :
     coupledFvsPatchField<Type>(p, iF, dict),
-    procPatch_(refCast<const processorFvPatch>(p))
+    procPatch_(refCast<const processorFvPatch>(p, dict))
 {
     if (!isType<processorFvPatch>(p))
     {
diff --git a/src/finiteVolume/fields/fvsPatchFields/constraint/processorCyclic/processorCyclicFvsPatchField.C b/src/finiteVolume/fields/fvsPatchFields/constraint/processorCyclic/processorCyclicFvsPatchField.C
index 0cfa469404a..6f5d10d4cef 100644
--- a/src/finiteVolume/fields/fvsPatchFields/constraint/processorCyclic/processorCyclicFvsPatchField.C
+++ b/src/finiteVolume/fields/fvsPatchFields/constraint/processorCyclic/processorCyclicFvsPatchField.C
@@ -61,7 +61,7 @@ Foam::processorCyclicFvsPatchField<Type>::processorCyclicFvsPatchField
 )
 :
     coupledFvsPatchField<Type>(p, iF, dict),
-    procPatch_(refCast<const processorCyclicFvPatch>(p))
+    procPatch_(refCast<const processorCyclicFvPatch>(p, dict))
 {
     if (!isType<processorCyclicFvPatch>(p))
     {
diff --git a/src/meshTools/AMIInterpolation/patches/cyclicACMI/cyclicACMIPointPatchField/cyclicACMIPointPatchField.C b/src/meshTools/AMIInterpolation/patches/cyclicACMI/cyclicACMIPointPatchField/cyclicACMIPointPatchField.C
index cd4eae9048b..434489fed1d 100644
--- a/src/meshTools/AMIInterpolation/patches/cyclicACMI/cyclicACMIPointPatchField/cyclicACMIPointPatchField.C
+++ b/src/meshTools/AMIInterpolation/patches/cyclicACMI/cyclicACMIPointPatchField/cyclicACMIPointPatchField.C
@@ -53,7 +53,7 @@ Foam::cyclicACMIPointPatchField<Type>::cyclicACMIPointPatchField
 )
 :
     coupledPointPatchField<Type>(p, iF, dict),
-    cyclicACMIPatch_(refCast<const cyclicACMIPointPatch>(p)),
+    cyclicACMIPatch_(refCast<const cyclicACMIPointPatch>(p, dict)),
     ppiPtr_(nullptr),
     nbrPpiPtr_(nullptr)
 {
diff --git a/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPointPatchField/cyclicAMIPointPatchField.C b/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPointPatchField/cyclicAMIPointPatchField.C
index 2d2d6c524db..64650ab876a 100644
--- a/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPointPatchField/cyclicAMIPointPatchField.C
+++ b/src/meshTools/AMIInterpolation/patches/cyclicAMI/cyclicAMIPointPatchField/cyclicAMIPointPatchField.C
@@ -53,7 +53,7 @@ Foam::cyclicAMIPointPatchField<Type>::cyclicAMIPointPatchField
 )
 :
     coupledPointPatchField<Type>(p, iF, dict),
-    cyclicAMIPatch_(refCast<const cyclicAMIPointPatch>(p)),
+    cyclicAMIPatch_(refCast<const cyclicAMIPointPatch>(p, dict)),
     ppiPtr_(nullptr),
     nbrPpiPtr_(nullptr)
 {
diff --git a/src/regionCoupled/derivedFvPatchFields/energyRegionCoupled/energyRegionCoupledFvPatchScalarField.C b/src/regionCoupled/derivedFvPatchFields/energyRegionCoupled/energyRegionCoupledFvPatchScalarField.C
index b372995659d..53ba2236c51 100644
--- a/src/regionCoupled/derivedFvPatchFields/energyRegionCoupled/energyRegionCoupledFvPatchScalarField.C
+++ b/src/regionCoupled/derivedFvPatchFields/energyRegionCoupled/energyRegionCoupledFvPatchScalarField.C
@@ -236,7 +236,7 @@ energyRegionCoupledFvPatchScalarField
 )
 :
     coupledFvPatchField<scalar>(p, iF, dict),
-    regionCoupledPatch_(refCast<const regionCoupledBaseFvPatch>(p)),
+    regionCoupledPatch_(refCast<const regionCoupledBaseFvPatch>(p, dict)),
     method_(UNDEFINED),
     nbrThermoPtr_(nullptr),
     thermoPtr_(nullptr)
diff --git a/src/regionModels/thermalBaffleModels/derivedFvPatchFields/thermalBaffle/thermalBaffleFvPatchScalarField.C b/src/regionModels/thermalBaffleModels/derivedFvPatchFields/thermalBaffle/thermalBaffleFvPatchScalarField.C
index 9895f146bc1..23620a89421 100644
--- a/src/regionModels/thermalBaffleModels/derivedFvPatchFields/thermalBaffle/thermalBaffleFvPatchScalarField.C
+++ b/src/regionModels/thermalBaffleModels/derivedFvPatchFields/thermalBaffle/thermalBaffleFvPatchScalarField.C
@@ -180,7 +180,7 @@ void thermalBaffleFvPatchScalarField::createPatchMesh()
     }
 
     const mappedPatchBase& mpp =
-        refCast<const mappedPatchBase>(patch().patch());
+        refCast<const mappedPatchBase>(patch().patch(), dict_);
 
     const word coupleGroup(mpp.coupleGroup());
 
-- 
GitLab