From a54aefff4f5b80347d07e39668cdb6ebfd857ee9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Jasi=C5=84ski?= <daniel.jasinski@gmail.com>
Date: Thu, 29 Oct 2015 15:08:43 +0100
Subject: [PATCH] basicThermo API for optional read

---
 .../basic/basicThermo/basicThermo.C                | 38 ++++++++++++++++++++++
 .../basic/basicThermo/basicThermo.H                | 12 ++++++-
 .../basic/basicThermo/basicThermoTemplates.C       |  9 +++--
 3 files changed, 55 insertions(+), 4 deletions(-)

diff --git a/src/thermophysicalModels/basic/basicThermo/basicThermo.C b/src/thermophysicalModels/basic/basicThermo/basicThermo.C
index e7264b0..e780379 100644
--- a/src/thermophysicalModels/basic/basicThermo/basicThermo.C
+++ b/src/thermophysicalModels/basic/basicThermo/basicThermo.C
@@ -276,6 +276,44 @@ Foam::autoPtr<Foam::basicThermo> Foam::basicThermo::New
     return New<basicThermo>(mesh, phaseName);
 }
 
+Foam::autoPtr<Foam::basicThermo> Foam::basicThermo::NewIfPresent
+(
+    const fvMesh& mesh,
+    const word& phaseName,
+    bool printInfo
+)
+{
+    IOobject thermoIO
+    (
+        phasePropertyName(dictName, phaseName),
+        mesh.time().constant(),
+        mesh,
+        IOobject::MUST_READ_IF_MODIFIED,
+        IOobject::NO_WRITE,
+        false
+    );
+
+    if(!thermoIO.headerOk())
+    {
+        return autoPtr<basicThermo>();
+    }
+
+    IOdictionary thermoDict
+    (
+        thermoIO
+    );
+
+    basicThermo::fvMeshConstructorTable::iterator cstrIter =
+        lookupThermo<basicThermo, basicThermo::fvMeshConstructorTable>
+        (
+            thermoDict,
+            basicThermo::fvMeshConstructorTablePtr_,
+            printInfo
+        );
+
+    return autoPtr<basicThermo>(cstrIter()(mesh, phaseName));
+}
+
 
 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
 
diff --git a/src/thermophysicalModels/basic/basicThermo/basicThermo.H b/src/thermophysicalModels/basic/basicThermo/basicThermo.H
index 9d4fc58..600e295 100644
--- a/src/thermophysicalModels/basic/basicThermo/basicThermo.H
+++ b/src/thermophysicalModels/basic/basicThermo/basicThermo.H
@@ -140,7 +140,8 @@ public:
         static typename Table::iterator lookupThermo
         (
             const dictionary& thermoDict,
-            Table* tablePtr
+            Table* tablePtr,
+            bool printInfo=true
         );
 
         //- Generic New for each of the related thermodynamics packages
@@ -167,6 +168,15 @@ public:
             const word& phaseName=word::null
         );
 
+        //- Specialisation of the Generic New for basicThermo
+        //- Returns empty pointer if dictionary not available
+        static autoPtr<basicThermo> NewIfPresent
+        (
+            const fvMesh&,
+            const word& phaseName=word::null,
+            bool printInfo=true
+        );
+
 
     //- Destructor
     virtual ~basicThermo();
diff --git a/src/thermophysicalModels/basic/basicThermo/basicThermoTemplates.C b/src/thermophysicalModels/basic/basicThermo/basicThermoTemplates.C
index 4521750..334ee89 100644
--- a/src/thermophysicalModels/basic/basicThermo/basicThermoTemplates.C
+++ b/src/thermophysicalModels/basic/basicThermo/basicThermoTemplates.C
@@ -31,7 +31,8 @@ template<class Thermo, class Table>
 typename Table::iterator Foam::basicThermo::lookupThermo
 (
     const dictionary& thermoDict,
-    Table* tablePtr
+    Table* tablePtr,
+    bool printInfo
 )
 {
     word thermoTypeName;
@@ -40,7 +41,8 @@ typename Table::iterator Foam::basicThermo::lookupThermo
     {
         const dictionary& thermoTypeDict(thermoDict.subDict("thermoType"));
 
-        Info<< "Selecting thermodynamics package " << thermoTypeDict << endl;
+        if(printInfo)
+            Info<< "Selecting thermodynamics package " << thermoTypeDict << endl;
 
         const int nCmpt = 7;
         const char* cmptNames[nCmpt] =
@@ -114,7 +116,8 @@ typename Table::iterator Foam::basicThermo::lookupThermo
     {
         thermoTypeName = word(thermoDict.lookup("thermoType"));
 
-        Info<< "Selecting thermodynamics package " << thermoTypeName << endl;
+        if(printInfo)
+            Info<< "Selecting thermodynamics package " << thermoTypeName << endl;
 
         typename Table::iterator cstrIter = tablePtr->find(thermoTypeName);
 
-- 
1.9.1

