From 5bc846553c98fce57f77870f571a2d044377af0b Mon Sep 17 00:00:00 2001
From: Sergio Ferraris <s.ferraris@opencfd.co.uk>
Date: Fri, 28 Aug 2020 08:45:33 -0700
Subject: [PATCH] ENH: Updates to MPPIC sub-models. Instantiation for kinematic
 clouds

---
 .../AveragingMethod/AveragingMethod.C         |  7 +++-
 .../DampingModels/DampingModel/DampingModel.C |  7 +++-
 .../DampingModels/DampingModel/DampingModel.H | 36 +++++++++++++++++-
 .../IsotropyModel/IsotropyModel.C             |  7 +++-
 .../IsotropyModel/IsotropyModel.H             | 38 +++++++++++++++++--
 .../MPPIC/PackingModels/Explicit/Explicit.C   |  5 ++-
 .../PackingModels/PackingModel/PackingModel.C |  8 ++--
 .../PackingModels/PackingModel/PackingModel.H | 37 +++++++++++++++++-
 8 files changed, 128 insertions(+), 17 deletions(-)

diff --git a/src/lagrangian/intermediate/submodels/MPPIC/AveragingMethods/AveragingMethod/AveragingMethod.C b/src/lagrangian/intermediate/submodels/MPPIC/AveragingMethods/AveragingMethod/AveragingMethod.C
index 0c1516c53ed..53d5f233abb 100644
--- a/src/lagrangian/intermediate/submodels/MPPIC/AveragingMethods/AveragingMethod/AveragingMethod.C
+++ b/src/lagrangian/intermediate/submodels/MPPIC/AveragingMethods/AveragingMethod/AveragingMethod.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2013-2017 OpenFOAM Foundation
-    Copyright (C) 2019 OpenCFD Ltd.
+    Copyright (C) 2019-2020 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -87,7 +87,10 @@ Foam::AveragingMethod<Type>::New
     const fvMesh& mesh
 )
 {
-    const word modelType(dict.get<word>(typeName));
+    const word modelType
+    (
+        dict.template getOrDefault<word>(typeName, "basic")
+    );
 
     //Info<< "Selecting averaging method " << modelType << endl;
 
diff --git a/src/lagrangian/intermediate/submodels/MPPIC/DampingModels/DampingModel/DampingModel.C b/src/lagrangian/intermediate/submodels/MPPIC/DampingModels/DampingModel/DampingModel.C
index eb1e5bea6b4..8c09c223251 100644
--- a/src/lagrangian/intermediate/submodels/MPPIC/DampingModels/DampingModel/DampingModel.C
+++ b/src/lagrangian/intermediate/submodels/MPPIC/DampingModels/DampingModel/DampingModel.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2013-2016 OpenFOAM Foundation
-    Copyright (C) 2019 OpenCFD Ltd.
+    Copyright (C) 2019-2020 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -83,7 +83,10 @@ Foam::DampingModel<CloudType>::New
     CloudType& owner
 )
 {
-    const word modelType(dict.get<word>(typeName));
+    const word modelType
+    (
+        dict.template getOrDefault<word>(typeName, "none")
+    );
 
     Info<< "Selecting damping model " << modelType << endl;
 
diff --git a/src/lagrangian/intermediate/submodels/MPPIC/DampingModels/DampingModel/DampingModel.H b/src/lagrangian/intermediate/submodels/MPPIC/DampingModels/DampingModel/DampingModel.H
index 9bf1ed3d1e3..c943d7110f4 100644
--- a/src/lagrangian/intermediate/submodels/MPPIC/DampingModels/DampingModel/DampingModel.H
+++ b/src/lagrangian/intermediate/submodels/MPPIC/DampingModels/DampingModel/DampingModel.H
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2013-2016 OpenFOAM Foundation
+    Copyright (C) 2020 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -142,6 +143,39 @@ public:
 
 #define makeDampingModel(CloudType)                                            \
                                                                                \
+    typedef Foam::CloudType::kinematicCloudType kinematicCloudType;            \
+    defineNamedTemplateTypeNameAndDebug                                        \
+    (                                                                          \
+        Foam::DampingModel<kinematicCloudType>,                                \
+        0                                                                      \
+    );                                                                         \
+                                                                               \
+    namespace Foam                                                             \
+    {                                                                          \
+        defineTemplateRunTimeSelectionTable                                    \
+        (                                                                      \
+            DampingModel<kinematicCloudType>,                                  \
+            dictionary                                                         \
+        );                                                                     \
+    }
+
+
+#define makeDampingModelType(SS, CloudType)                                    \
+                                                                               \
+    typedef Foam::CloudType::kinematicCloudType kinematicCloudType;            \
+    defineNamedTemplateTypeNameAndDebug                                        \
+        (Foam::DampingModels::SS<kinematicCloudType>, 0);                      \
+                                                                               \
+    Foam::DampingModel<kinematicCloudType>::                                   \
+        adddictionaryConstructorToTable                                        \
+        <Foam::DampingModels::SS<kinematicCloudType>>                          \
+            add##SS##CloudType##kinematicCloudType##ConstructorToTable_;
+
+
+// These are used to defined models in MPPIC cloud specifically
+
+#define makeDampingModelMPPIC(CloudType)                                       \
+                                                                               \
     typedef Foam::CloudType::MPPICCloudType MPPICCloudType;                    \
     defineNamedTemplateTypeNameAndDebug                                        \
     (                                                                          \
@@ -159,7 +193,7 @@ public:
     }
 
 
-#define makeDampingModelType(SS, CloudType)                                    \
+#define makeDampingModelTypeMPPIC(SS, CloudType)                               \
                                                                                \
     typedef Foam::CloudType::MPPICCloudType MPPICCloudType;                    \
     defineNamedTemplateTypeNameAndDebug                                        \
diff --git a/src/lagrangian/intermediate/submodels/MPPIC/IsotropyModels/IsotropyModel/IsotropyModel.C b/src/lagrangian/intermediate/submodels/MPPIC/IsotropyModels/IsotropyModel/IsotropyModel.C
index a1d70f85563..1178e63947e 100644
--- a/src/lagrangian/intermediate/submodels/MPPIC/IsotropyModels/IsotropyModel/IsotropyModel.C
+++ b/src/lagrangian/intermediate/submodels/MPPIC/IsotropyModels/IsotropyModel/IsotropyModel.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2013-2016 OpenFOAM Foundation
-    Copyright (C) 2019 OpenCFD Ltd.
+    Copyright (C) 2019-2020 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -86,7 +86,10 @@ Foam::IsotropyModel<CloudType>::New
     CloudType& owner
 )
 {
-    const word modelType(dict.get<word>(typeName));
+    const word modelType
+    (
+        dict.template getOrDefault<word>(typeName, "none")
+    );
 
     Info<< "Selecting isotropy model " << modelType << endl;
 
diff --git a/src/lagrangian/intermediate/submodels/MPPIC/IsotropyModels/IsotropyModel/IsotropyModel.H b/src/lagrangian/intermediate/submodels/MPPIC/IsotropyModels/IsotropyModel/IsotropyModel.H
index c7ec30ca15a..023f6e28c03 100644
--- a/src/lagrangian/intermediate/submodels/MPPIC/IsotropyModels/IsotropyModel/IsotropyModel.H
+++ b/src/lagrangian/intermediate/submodels/MPPIC/IsotropyModels/IsotropyModel/IsotropyModel.H
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2013-2016 OpenFOAM Foundation
+    Copyright (C) 2020 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -136,10 +137,10 @@ public:
 
 #define makeIsotropyModel(CloudType)                                           \
                                                                                \
-    typedef Foam::CloudType::MPPICCloudType MPPICCloudType;                    \
+    typedef Foam::CloudType::kinematicCloudType kinematicCloudType;            \
     defineNamedTemplateTypeNameAndDebug                                        \
     (                                                                          \
-        Foam::IsotropyModel<MPPICCloudType>,                                   \
+        Foam::IsotropyModel<kinematicCloudType>,                               \
         0                                                                      \
     );                                                                         \
                                                                                \
@@ -147,7 +148,7 @@ public:
     {                                                                          \
         defineTemplateRunTimeSelectionTable                                    \
         (                                                                      \
-            IsotropyModel<MPPICCloudType>,                                     \
+            IsotropyModel<kinematicCloudType>,                                 \
             dictionary                                                         \
         );                                                                     \
     }
@@ -155,6 +156,36 @@ public:
 
 #define makeIsotropyModelType(SS, CloudType)                                   \
                                                                                \
+    typedef Foam::CloudType::kinematicCloudType kinematicCloudType;            \
+    defineNamedTemplateTypeNameAndDebug                                        \
+        (Foam::IsotropyModels::SS<kinematicCloudType>, 0);                     \
+                                                                               \
+    Foam::IsotropyModel<kinematicCloudType>::                                  \
+        adddictionaryConstructorToTable                                        \
+        <Foam::IsotropyModels::SS<kinematicCloudType>>                         \
+            add##SS##CloudType##kinematicCloudType##ConstructorToTable_;
+
+
+// These are used to defined models in MPPIC cloud specifically
+
+#define makeIsotropyModelMPPIC(CloudType)                                  \
+                                                                               \
+    typedef Foam::CloudType::MPPICCloudType MPPICCloudType;                    \
+    defineNamedTemplateTypeNameAndDebug                                        \
+        (Foam::IsotropyModel<MPPICCloudType>, 0);                              \
+                                                                               \
+    namespace Foam                                                             \
+    {                                                                          \
+        defineTemplateRunTimeSelectionTable                                    \
+        (                                                                      \
+            IsotropyModel<MPPICCloudType>,                                     \
+            dictionary                                                         \
+        );                                                                     \
+    }
+
+
+#define makeIsotropyModelTypeMPPIC(SS, CloudType)                              \
+                                                                               \
     typedef Foam::CloudType::MPPICCloudType MPPICCloudType;                    \
     defineNamedTemplateTypeNameAndDebug                                        \
         (Foam::IsotropyModels::SS<MPPICCloudType>, 0);                         \
@@ -164,7 +195,6 @@ public:
         <Foam::IsotropyModels::SS<MPPICCloudType>>                             \
             add##SS##CloudType##MPPICCloudType##ConstructorToTable_;
 
-
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 #ifdef NoRepository
diff --git a/src/lagrangian/intermediate/submodels/MPPIC/PackingModels/Explicit/Explicit.C b/src/lagrangian/intermediate/submodels/MPPIC/PackingModels/Explicit/Explicit.C
index 3689a4ff38c..49ea02277de 100644
--- a/src/lagrangian/intermediate/submodels/MPPIC/PackingModels/Explicit/Explicit.C
+++ b/src/lagrangian/intermediate/submodels/MPPIC/PackingModels/Explicit/Explicit.C
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2013-2017 OpenFOAM Foundation
+    Copyright (C) 2020 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -150,8 +151,10 @@ Foam::vector Foam::PackingModels::Explicit<CloudType>::velocityCorrection
     // interpolated quantities
     const scalar alpha =
         this->volumeAverage_->interpolate(p.coordinates(), tetIs);
+
     const vector alphaGrad =
         this->volumeAverage_->interpolateGrad(p.coordinates(), tetIs);
+
     const vector uMean =
         this->uAverage_->interpolate(p.coordinates(), tetIs);
 
@@ -175,7 +178,7 @@ Foam::vector Foam::PackingModels::Explicit<CloudType>::velocityCorrection
     // correction velocity
     if ((uRelative & alphaGrad) > 0)
     {
-        dU = - deltaT*tauGrad/(p.rho()*alpha/* + deltaT*F.Sp()*/);
+        dU = - deltaT*tauGrad/(p.rho()*(alpha + SMALL)/* + deltaT*F.Sp()*/);
     }
 
     // apply the velocity limiters
diff --git a/src/lagrangian/intermediate/submodels/MPPIC/PackingModels/PackingModel/PackingModel.C b/src/lagrangian/intermediate/submodels/MPPIC/PackingModels/PackingModel/PackingModel.C
index 017008f26b4..d6df6f22f73 100644
--- a/src/lagrangian/intermediate/submodels/MPPIC/PackingModels/PackingModel/PackingModel.C
+++ b/src/lagrangian/intermediate/submodels/MPPIC/PackingModels/PackingModel/PackingModel.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2013-2016 OpenFOAM Foundation
-    Copyright (C) 2019 OpenCFD Ltd.
+    Copyright (C) 2019-2020 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -85,8 +85,10 @@ Foam::PackingModel<CloudType>::New
     CloudType& owner
 )
 {
-    const word modelType(dict.get<word>(typeName));
-
+    const word modelType
+    (
+        dict.template getOrDefault<word>(typeName, "none")
+    );
     Info<< "Selecting packing model " << modelType << endl;
 
     auto cstrIter = dictionaryConstructorTablePtr_->cfind(modelType);
diff --git a/src/lagrangian/intermediate/submodels/MPPIC/PackingModels/PackingModel/PackingModel.H b/src/lagrangian/intermediate/submodels/MPPIC/PackingModels/PackingModel/PackingModel.H
index 4b22670d650..9d57353e217 100644
--- a/src/lagrangian/intermediate/submodels/MPPIC/PackingModels/PackingModel/PackingModel.H
+++ b/src/lagrangian/intermediate/submodels/MPPIC/PackingModels/PackingModel/PackingModel.H
@@ -6,6 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2013-2016 OpenFOAM Foundation
+    Copyright (C) 2020 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -147,6 +148,39 @@ public:
 
 #define makePackingModel(CloudType)                                            \
                                                                                \
+    typedef Foam::CloudType::kinematicCloudType kinematicCloudType;            \
+    defineNamedTemplateTypeNameAndDebug                                        \
+    (                                                                          \
+        Foam::PackingModel<kinematicCloudType>,                                \
+        0                                                                      \
+    );                                                                         \
+                                                                               \
+    namespace Foam                                                             \
+    {                                                                          \
+        defineTemplateRunTimeSelectionTable                                    \
+        (                                                                      \
+            PackingModel<kinematicCloudType>,                                  \
+            dictionary                                                         \
+        );                                                                     \
+    }
+
+
+#define makePackingModelType(SS, CloudType)                                    \
+                                                                               \
+    typedef Foam::CloudType::kinematicCloudType kinematicCloudType;            \
+    defineNamedTemplateTypeNameAndDebug                                        \
+        (Foam::PackingModels::SS<kinematicCloudType>, 0);                      \
+                                                                               \
+    Foam::PackingModel<kinematicCloudType>::                                   \
+        adddictionaryConstructorToTable                                        \
+        <Foam::PackingModels::SS<kinematicCloudType>>                          \
+            add##SS##CloudType##kinematicCloudType##ConstructorToTable_;
+
+
+// These are used to defined models in MPPIC cloud specifically
+
+#define makePackingModelMPPIC(CloudType)                                   \
+                                                                               \
     typedef Foam::CloudType::MPPICCloudType MPPICCloudType;                    \
     defineNamedTemplateTypeNameAndDebug                                        \
     (                                                                          \
@@ -164,7 +198,7 @@ public:
     }
 
 
-#define makePackingModelType(SS, CloudType)                                    \
+#define makePackingModelTypeMPPIC(SS, CloudType)                               \
                                                                                \
     typedef Foam::CloudType::MPPICCloudType MPPICCloudType;                    \
     defineNamedTemplateTypeNameAndDebug                                        \
@@ -175,7 +209,6 @@ public:
         <Foam::PackingModels::SS<MPPICCloudType>>                              \
             add##SS##CloudType##MPPICCloudType##ConstructorToTable_;
 
-
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 #ifdef NoRepository
-- 
GitLab