From 93e2226595af6dd4c2b51fe8f2f865ff6bebf727 Mon Sep 17 00:00:00 2001
From: sergio <sergio>
Date: Wed, 8 Feb 2012 10:18:44 +0000
Subject: [PATCH] ENH: check of valid Ptr before using it

---
 .../interRegionHeatTransferModel.C            | 147 +++++++++---------
 1 file changed, 75 insertions(+), 72 deletions(-)

diff --git a/src/fieldSources/basicSource/interRegionHeatTransferModel/interRegionHeatTransferModel/interRegionHeatTransferModel.C b/src/fieldSources/basicSource/interRegionHeatTransferModel/interRegionHeatTransferModel/interRegionHeatTransferModel.C
index 24c0f612dd0..772f26094a7 100644
--- a/src/fieldSources/basicSource/interRegionHeatTransferModel/interRegionHeatTransferModel/interRegionHeatTransferModel.C
+++ b/src/fieldSources/basicSource/interRegionHeatTransferModel/interRegionHeatTransferModel/interRegionHeatTransferModel.C
@@ -137,100 +137,103 @@ void Foam::interRegionHeatTransferModel::addSup
     const label fieldI
 )
 {
-    if (firstIter_)
+    if (secondaryToPrimaryInterpPtr_.valid())
     {
-        check();
-        firstIter_ = false;
-    }
+        if (firstIter_)
+        {
+            check();
+            firstIter_ = false;
+        }
 
-    const volScalarField& h = eEqn.psi();
+        const volScalarField& h = eEqn.psi();
 
-    tmp<volScalarField> tTmapped
-    (
-        new volScalarField
+        tmp<volScalarField> tTmapped
         (
-            IOobject
+            new volScalarField
             (
-                "Tmapped" + mesh_.name(),
-                mesh_.time().timeName(),
+                IOobject
+                (
+                    "Tmapped" + mesh_.name(),
+                    mesh_.time().timeName(),
+                    mesh_,
+                    IOobject::NO_READ,
+                    IOobject::NO_WRITE
+                ),
                 mesh_,
-                IOobject::NO_READ,
-                IOobject::NO_WRITE
-            ),
-            mesh_,
-            dimensionedScalar("T", dimTemperature, 0.0)
-        )
-    );
-
-    volScalarField& Tmapped = tTmapped();
+                dimensionedScalar("T", dimTemperature, 0.0)
+            )
+        );
 
-    const fvMesh& secondaryMesh =
-        mesh_.time().lookupObject<fvMesh>(mapRegionName_);
+        volScalarField& Tmapped = tTmapped();
 
-    const volScalarField& Tsecondary =
-        secondaryMesh.lookupObject<volScalarField>("T");
+        const fvMesh& secondaryMesh =
+            mesh_.time().lookupObject<fvMesh>(mapRegionName_);
 
-    secondaryToPrimaryInterpPtr_->interpolateInternalField
-    (
-        Tmapped,
-        Tsecondary,
-        meshToMesh::MAP,
-        eqOp<scalar>()
-    );
+        const volScalarField& Tsecondary =
+            secondaryMesh.lookupObject<volScalarField>("T");
 
-    if (!master_)
-    {
         secondaryToPrimaryInterpPtr_->interpolateInternalField
         (
-            htc_,
-            secIrht_->calculateHtc(),
-            meshToMesh::CELL_VOLUME_WEIGHT,
+            Tmapped,
+            Tsecondary,
+            meshToMesh::MAP,
             eqOp<scalar>()
         );
-    }
-
-    if (debug)
-    {
-        Info<< " Volumetric integral of htc : "
-            << fvc::domainIntegrate(htc_).value()
-            << endl;
-    }
-
-    //SAF: temporarily output
-    if (mesh_.time().outputTime())
-    {
-        Tmapped.write();
-        htc_.write();
-    }
-
-    if (h.dimensions() == dimEnergy/dimMass)
-    {
-        const basicThermo& primaryThermo =
-            mesh_.lookupObject<basicThermo>("thermophysicalProperties");
 
-        eEqn += htc_*Tmapped - fvm::Sp(htc_/primaryThermo.Cp(), h);
+        if (!master_)
+        {
+            secondaryToPrimaryInterpPtr_->interpolateInternalField
+            (
+                htc_,
+                secIrht_->calculateHtc(),
+                meshToMesh::CELL_VOLUME_WEIGHT,
+                eqOp<scalar>()
+            );
+        }
 
         if (debug)
         {
-            Info<< " Energy exchange from region " << secondaryMesh.name()
-                << " To " << mesh_.name() << " : "
-                <<  fvc::domainIntegrate
-                    (
-                        htc_*(h/primaryThermo.Cp() - Tmapped)
-                    ).value()
+            Info<< " Volumetric integral of htc : "
+                << fvc::domainIntegrate(htc_).value()
                 << endl;
         }
-    }
-    else if(h.dimensions() == dimTemperature)
-    {
-        eEqn += htc_*Tmapped - fvm::Sp(htc_, h);
 
-        if (debug)
+        //SAF: temporarily output
+        if (mesh_.time().outputTime())
         {
-            Info<< " Enegy exchange from region " << secondaryMesh.name()
-                << " To " << mesh_.name() << " : "
-                <<  fvc::domainIntegrate(htc_*(h - Tmapped)).value()
-                << endl;
+            Tmapped.write();
+            htc_.write();
+        }
+
+        if (h.dimensions() == dimEnergy/dimMass)
+        {
+            const basicThermo& primaryThermo =
+                mesh_.lookupObject<basicThermo>("thermophysicalProperties");
+
+            eEqn += htc_*Tmapped - fvm::Sp(htc_/primaryThermo.Cp(), h);
+
+            if (debug)
+            {
+                Info<< " Energy exchange from region " << secondaryMesh.name()
+                    << " To " << mesh_.name() << " : "
+                    <<  fvc::domainIntegrate
+                        (
+                            htc_*(h/primaryThermo.Cp() - Tmapped)
+                        ).value()
+                    << endl;
+            }
+        }
+        else if(h.dimensions() == dimTemperature)
+        {
+            eEqn += htc_*Tmapped - fvm::Sp(htc_, h);
+
+            if (debug)
+            {
+                Info<< " Enegy exchange from region " << secondaryMesh.name()
+                    << " To " << mesh_.name() << " : "
+                    <<  fvc::domainIntegrate(htc_*(h - Tmapped)).value()
+                    << endl;
+            }
         }
     }
 }
-- 
GitLab