diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/Make/files b/applications/solvers/heatTransfer/chtMultiRegionFoam/Make/files
index e924e9de680bcbe388c230a109aa2d01c14b9adf..3ee71c0ea6ad8cd2afeb422b1b7efd4bfbfe7991 100644
--- a/applications/solvers/heatTransfer/chtMultiRegionFoam/Make/files
+++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/Make/files
@@ -5,7 +5,7 @@ coupleManager/coupleManager.C
 derivedFvPatchFields/solidWallHeatFluxTemperature/solidWallHeatFluxTemperatureFvPatchScalarField.C
 derivedFvPatchFields/solidWallHeatFluxTemperatureCoupled/solidWallHeatFluxTemperatureCoupledFvPatchScalarField.C
 derivedFvPatchFields/solidWallTemperatureCoupled/solidWallTemperatureCoupledFvPatchScalarField.C
-
+derivedFvPatchFields/solidWallMixedTemperatureCoupled/solidWallMixedTemperatureCoupledFvPatchScalarField.C
 
 chtMultiRegionFoam.C
 
diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/coupleManager/coupleManager.C b/applications/solvers/heatTransfer/chtMultiRegionFoam/coupleManager/coupleManager.C
index dbe38fce9c9efc071bb87b6df4ec94e2b9f1ca02..1668e1144c46f13024e37813296b96642fbcbc92 100644
--- a/applications/solvers/heatTransfer/chtMultiRegionFoam/coupleManager/coupleManager.C
+++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/coupleManager/coupleManager.C
@@ -26,6 +26,7 @@ License
 
 #include "coupleManager.H"
 #include "OFstream.H"
+#include "regionProperties.H"
 
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
@@ -74,6 +75,51 @@ Foam::coupleManager::~coupleManager()
 
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
+bool Foam::coupleManager::regionOwner() const
+{
+    const fvMesh& nbrRegion = neighbourRegion();
+
+    const regionProperties& props =
+        localRegion_.objectRegistry::parent().lookupObject<regionProperties>
+        (
+            "regionProperties"
+        );
+
+    label myIndex = findIndex(props.fluidRegionNames(), localRegion_.name());
+    if (myIndex == -1)
+    {
+        label i = findIndex(props.solidRegionNames(), localRegion_.name());
+
+        if (i == -1)
+        {
+            FatalErrorIn("coupleManager::regionOwner() const")
+                << "Cannot find region " << localRegion_.name()
+                << " neither in fluids " << props.fluidRegionNames()
+                << " nor in solids " << props.solidRegionNames()
+                << exit(FatalError);
+        }
+        myIndex = props.fluidRegionNames().size() + i;
+    }
+    label nbrIndex = findIndex(props.fluidRegionNames(), nbrRegion.name());
+    if (nbrIndex == -1)
+    {
+        label i = findIndex(props.solidRegionNames(), nbrRegion.name());
+
+        if (i == -1)
+        {
+            FatalErrorIn("coupleManager::regionOwner() const")
+                << "Cannot find region " << nbrRegion.name()
+                << " neither in fluids " << props.fluidRegionNames()
+                << " nor in solids " << props.solidRegionNames()
+                << exit(FatalError);
+        }
+        nbrIndex = props.fluidRegionNames().size() + i;
+    }
+
+    return myIndex < nbrIndex;
+}
+
+
 void Foam::coupleManager::checkCouple() const
 {
     Info<< "neighbourRegionName_ = " << neighbourRegionName_ << endl;
diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/coupleManager/coupleManager.H b/applications/solvers/heatTransfer/chtMultiRegionFoam/coupleManager/coupleManager.H
index 95811bfd4f5d39daf3cb19b8d0e5c598252a2487..f1f73d23efe8505664cb5886dd3b37a5dc6727d2 100644
--- a/applications/solvers/heatTransfer/chtMultiRegionFoam/coupleManager/coupleManager.H
+++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/coupleManager/coupleManager.H
@@ -74,9 +74,6 @@ class coupleManager
 
     // Private Member Functions
 
-        //- Disallow default bitwise copy construct
-//        coupleManager(const coupleManager&);
-
         //- Disallow default bitwise assignment
         void operator=(const coupleManager&);
 
@@ -129,6 +126,9 @@ public:
             template<class Type>
             inline const fvPatchField<Type>& neighbourPatchField() const;
 
+            //- Am I owner (= first to evaluate) of this region interface? 
+            bool regionOwner() const;
+
             //- Check that the couple is valid
             void checkCouple() const;
 
diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallHeatFluxTemperatureCoupled/solidWallHeatFluxTemperatureCoupledFvPatchScalarField.C b/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallHeatFluxTemperatureCoupled/solidWallHeatFluxTemperatureCoupledFvPatchScalarField.C
index c56ce486d86db677a808d2b8b1613c00d87ecc5d..07bcac29a683edc4dcb95805f63df358f7613d77 100644
--- a/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallHeatFluxTemperatureCoupled/solidWallHeatFluxTemperatureCoupledFvPatchScalarField.C
+++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallHeatFluxTemperatureCoupled/solidWallHeatFluxTemperatureCoupledFvPatchScalarField.C
@@ -115,7 +115,7 @@ void Foam::solidWallHeatFluxTemperatureCoupledFvPatchScalarField::updateCoeffs()
     const fvPatchField<scalar>& K =
         patch().lookupPatchField<volScalarField, scalar>(KName_);
 
-    gradient() = refCast<const solidWallTemperatureCoupledFvPatchScalarField>
+    gradient() = -refCast<const solidWallTemperatureCoupledFvPatchScalarField>
         (neighbourField).flux()/K;
 
     fixedGradientFvPatchScalarField::updateCoeffs();
diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallMixedTemperatureCoupled/solidWallMixedTemperatureCoupledFvPatchScalarField.C b/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallMixedTemperatureCoupled/solidWallMixedTemperatureCoupledFvPatchScalarField.C
new file mode 100644
index 0000000000000000000000000000000000000000..ba2ee599d0cbf84d4bce1b5846ee0053fd060472
--- /dev/null
+++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallMixedTemperatureCoupled/solidWallMixedTemperatureCoupledFvPatchScalarField.C
@@ -0,0 +1,252 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM; if not, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+\*---------------------------------------------------------------------------*/
+
+#include "solidWallMixedTemperatureCoupledFvPatchScalarField.H"
+#include "addToRunTimeSelectionTable.H"
+#include "fvPatchFieldMapper.H"
+#include "volFields.H"
+#include "regionProperties.H"
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::solidWallMixedTemperatureCoupledFvPatchScalarField::
+solidWallMixedTemperatureCoupledFvPatchScalarField
+(
+    const fvPatch& p,
+    const DimensionedField<scalar, volMesh>& iF
+)
+:
+    mixedFvPatchScalarField(p, iF),
+    coupleManager_(p),
+    KName_("undefined-K")
+{
+    this->refValue() = 0.0;
+    this->refGrad() = 0.0;
+    this->valueFraction() = 1.0;
+    this->fixesValue_ = true;
+}
+
+
+Foam::solidWallMixedTemperatureCoupledFvPatchScalarField::
+solidWallMixedTemperatureCoupledFvPatchScalarField
+(
+    const solidWallMixedTemperatureCoupledFvPatchScalarField& ptf,
+    const fvPatch& p,
+    const DimensionedField<scalar, volMesh>& iF,
+    const fvPatchFieldMapper& mapper
+)
+:
+    mixedFvPatchScalarField(ptf, p, iF, mapper),
+    coupleManager_(ptf.coupleManager_),
+    KName_(ptf.KName_),
+    fixesValue_(ptf.fixesValue_)
+{}
+
+
+Foam::solidWallMixedTemperatureCoupledFvPatchScalarField::
+solidWallMixedTemperatureCoupledFvPatchScalarField
+(
+    const fvPatch& p,
+    const DimensionedField<scalar, volMesh>& iF,
+    const dictionary& dict
+)
+:
+    mixedFvPatchScalarField(p, iF),
+    coupleManager_(p, dict),
+    KName_(dict.lookup("K"))
+{
+    fvPatchScalarField::operator=(scalarField("value", dict, p.size()));
+    refValue() = static_cast<scalarField>(*this);
+    refGrad() = 0.0;
+    valueFraction() = 1.0;
+    fixesValue_ = true;
+}
+
+
+Foam::solidWallMixedTemperatureCoupledFvPatchScalarField::
+solidWallMixedTemperatureCoupledFvPatchScalarField
+(
+    const solidWallMixedTemperatureCoupledFvPatchScalarField& wtcsf,
+    const DimensionedField<scalar, volMesh>& iF
+)
+:
+    mixedFvPatchScalarField(wtcsf, iF),
+    coupleManager_(wtcsf.coupleManager_),
+    KName_(wtcsf.KName_),
+    fixesValue_(wtcsf.fixesValue_)
+{}
+
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+const Foam::fvPatchScalarField&
+Foam::solidWallMixedTemperatureCoupledFvPatchScalarField::K() const
+{
+    return this->patch().lookupPatchField<volScalarField, scalar>(KName_);
+}
+
+
+void Foam::solidWallMixedTemperatureCoupledFvPatchScalarField::updateCoeffs()
+{
+    if (updated())
+    {
+        return;
+    }
+
+    tmp<scalarField> intFld = patchInternalField();
+
+    label nFixed = 0;
+
+    // Like snGrad but bypass switching on refValue/refGrad.
+    tmp<scalarField> normalGradient =
+        (*this-intFld())
+      * patch().deltaCoeffs();
+
+    if (debug)
+    {
+        Info<< "solidWallMixedTemperatureCoupledFvPatchScalarField::"
+            << "updateCoeffs() :"
+            << " walltemperature "
+            << " min:" << gMin(*this)
+            << " max:" << gMax(*this)
+            << " avg:" << gAverage(*this)
+            << endl;
+    }
+
+    forAll(*this, i)
+    {
+        // if outgoing flux use fixed value.
+        if (intFld()[i] > operator[](i))
+        {
+            this->refValue()[i] = operator[](i);
+            this->refGrad()[i] = 0.0;   // not used
+            this->valueFraction()[i] = 1.0;
+            nFixed++;
+        }
+        else
+        {
+            this->refValue()[i] = 0.0;  // not used
+            this->refGrad()[i] = normalGradient()[i];
+            this->valueFraction()[i] = 0.0;
+        }
+    }
+
+    reduce(nFixed, sumOp<label>());
+
+    fixesValue_ = (nFixed > 0);
+
+    if (debug)
+    {
+        label nTotSize = returnReduce(this->size(), sumOp<label>());
+
+        Info<< "solidWallMixedTemperatureCoupledFvPatchScalarField::"
+            << "updateCoeffs() : Out of " << nTotSize
+            << " fixedBC:" << nFixed
+            << " gradient:" << nTotSize-nFixed << endl;
+    }
+
+    mixedFvPatchScalarField::updateCoeffs();
+}
+
+
+void Foam::solidWallMixedTemperatureCoupledFvPatchScalarField::evaluate
+(
+    const Pstream::commsTypes
+)
+{
+    if (!this->updated())
+    {
+        this->updateCoeffs();
+    }
+
+    if (!coupleManager_.regionOwner())
+    {
+        // I am the last one to evaluate.
+
+        tmp<scalarField> intFld = patchInternalField();
+
+        const fvPatch& nbrPatch = coupleManager_.neighbourPatch();
+
+        solidWallMixedTemperatureCoupledFvPatchScalarField& nbrField =
+        refCast<solidWallMixedTemperatureCoupledFvPatchScalarField>
+        (
+            const_cast<fvPatchField<scalar>&>
+            (
+                coupleManager_.neighbourPatchField<scalar>()
+            )
+        );
+        tmp<scalarField> nbrIntFld = nbrField.patchInternalField();
+        tmp<scalarField> myKDelta = K()*patch().deltaCoeffs();
+        tmp<scalarField> nbrKDelta = nbrField.K()*nbrPatch.deltaCoeffs();
+
+        // Calculate common wall temperature and assign to both sides
+        scalarField::operator=
+        (
+            (myKDelta()*intFld + nbrKDelta()*nbrIntFld)
+          / (myKDelta() + nbrKDelta())
+        );
+
+        nbrField.scalarField::operator=(*this);
+
+        if (debug)
+        {
+            Info<< "Setting master and slave to wall temperature "
+                << " min:" << gMin(*this)
+                << " max:" << gMax(*this)
+                << " avg:" << gAverage(*this)
+                << endl;
+        }
+    }
+
+    fvPatchScalarField::evaluate();
+}
+
+
+void Foam::solidWallMixedTemperatureCoupledFvPatchScalarField::write
+(
+    Ostream& os
+) const
+{
+    mixedFvPatchScalarField::write(os);
+    coupleManager_.writeEntries(os);
+    os.writeKeyword("K") << KName_ << token::END_STATEMENT << nl;
+}
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+makePatchTypeField
+(
+    fvPatchScalarField,
+    solidWallMixedTemperatureCoupledFvPatchScalarField
+);
+
+} // End namespace Foam
+
+// ************************************************************************* //
diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallMixedTemperatureCoupled/solidWallMixedTemperatureCoupledFvPatchScalarField.H b/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallMixedTemperatureCoupled/solidWallMixedTemperatureCoupledFvPatchScalarField.H
new file mode 100644
index 0000000000000000000000000000000000000000..b650ee226ea30cb23cd3988ba1af4ff867481799
--- /dev/null
+++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallMixedTemperatureCoupled/solidWallMixedTemperatureCoupledFvPatchScalarField.H
@@ -0,0 +1,184 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM; if not, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+Class
+    solidWallMixedTemperatureCoupledFvPatchScalarField
+
+Description
+    Mixed boundary condition for temperature, to be used by the
+    conjugate heat transfer solver.
+    If my temperature is T1, neighbour is T2:
+
+    T1 > T2: my side becomes fixedValue T2 bc, other side becomes fixedGradient.
+    
+
+    Example usage:
+        myInterfacePatchName
+        {
+            type                solidWallMixedTemperatureCoupled;
+            neighbourRegionName fluid;
+            neighbourPatchName  fluidSolidInterface;
+            neighbourFieldName  T;
+            K                   K;
+            value               uniform 300;
+        }
+
+SourceFiles
+    solidWallMixedTemperatureCoupledFvPatchScalarField.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef solidWallMixedTemperatureCoupledFvPatchScalarField_H
+#define solidWallMixedTemperatureCoupledFvPatchScalarField_H
+
+#include "fvPatchFields.H"
+#include "mixedFvPatchFields.H"
+#include "coupleManager.H"
+#include "fvPatch.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+/*---------------------------------------------------------------------------*\
+        Class solidWallMixedTemperatureCoupledFvPatchScalarField Declaration
+\*---------------------------------------------------------------------------*/
+
+class solidWallMixedTemperatureCoupledFvPatchScalarField
+:
+    public mixedFvPatchScalarField
+{
+    // Private data
+
+        //- Couple manager object
+        coupleManager coupleManager_;
+
+        //- Name of thermal conductivity field
+        word KName_;
+
+        bool fixesValue_;
+
+public:
+
+    //- Runtime type information
+    TypeName("solidWallMixedTemperatureCoupled");
+
+
+    // Constructors
+
+        //- Construct from patch and internal field
+        solidWallMixedTemperatureCoupledFvPatchScalarField
+        (
+            const fvPatch&,
+            const DimensionedField<scalar, volMesh>&
+        );
+
+        //- Construct from patch, internal field and dictionary
+        solidWallMixedTemperatureCoupledFvPatchScalarField
+        (
+            const fvPatch&,
+            const DimensionedField<scalar, volMesh>&,
+            const dictionary&
+        );
+
+        //- Construct by mapping given solidWallMixedTemperatureCoupledFvPatchScalarField
+        //  onto a new patch
+        solidWallMixedTemperatureCoupledFvPatchScalarField
+        (
+            const solidWallMixedTemperatureCoupledFvPatchScalarField&,
+            const fvPatch&,
+            const DimensionedField<scalar, volMesh>&,
+            const fvPatchFieldMapper&
+        );
+
+        //- Construct and return a clone
+        virtual tmp<fvPatchScalarField> clone() const
+        {
+            return tmp<fvPatchScalarField>
+            (
+                new solidWallMixedTemperatureCoupledFvPatchScalarField(*this)
+            );
+        }
+
+        //- Construct as copy setting internal field reference
+        solidWallMixedTemperatureCoupledFvPatchScalarField
+        (
+            const solidWallMixedTemperatureCoupledFvPatchScalarField&,
+            const DimensionedField<scalar, volMesh>&
+        );
+
+        //- Construct and return a clone setting internal field reference
+        virtual tmp<fvPatchScalarField> clone
+        (
+            const DimensionedField<scalar, volMesh>& iF
+        ) const
+        {
+            return tmp<fvPatchScalarField>
+            (
+                new solidWallMixedTemperatureCoupledFvPatchScalarField
+                (
+                    *this,
+                    iF
+                )
+            );
+        }
+
+
+    // Member functions
+
+        //- Get corresponding K field
+        const fvPatchScalarField& K() const;
+
+        //- Return true if this patch field fixes a value.
+        //  Needed to check if a level has to be specified while solving
+        //  Poissons equations.
+        virtual bool fixesValue() const
+        {
+            return fixesValue_;
+        }
+
+        //- Update the coefficients associated with the patch field
+        virtual void updateCoeffs();
+
+        //- Evaluate the patch field
+        virtual void evaluate
+        (
+            const Pstream::commsTypes commsType=Pstream::blocking
+        );
+
+        //- Write
+        virtual void write(Ostream&) const;
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallTemperatureCoupled/solidWallTemperatureCoupledFvPatchScalarField.C b/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallTemperatureCoupled/solidWallTemperatureCoupledFvPatchScalarField.C
index e32560806c4dfb22ed4f4626a01c6a70a69603bc..05bbdd1ba3fb75adce7642f1afd732f8c87d3c3d 100644
--- a/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallTemperatureCoupled/solidWallTemperatureCoupledFvPatchScalarField.C
+++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallTemperatureCoupled/solidWallTemperatureCoupledFvPatchScalarField.C
@@ -136,7 +136,7 @@ Foam::solidWallTemperatureCoupledFvPatchScalarField::flux() const
 
     const fvPatchScalarField& Tw = *this;
 
-    return Tw.snGrad()*patch().magSf()*Kw;
+    return Tw.snGrad()*Kw;
 }
 
 
diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallTemperatureCoupled/solidWallTemperatureCoupledFvPatchScalarField.H b/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallTemperatureCoupled/solidWallTemperatureCoupledFvPatchScalarField.H
index 78a6c5661c2a3ec76b84e1fcafa4c16e05ec4ada..22fd168175134eb812ac447caac3d397dee21df3 100644
--- a/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallTemperatureCoupled/solidWallTemperatureCoupledFvPatchScalarField.H
+++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/derivedFvPatchFields/solidWallTemperatureCoupled/solidWallTemperatureCoupledFvPatchScalarField.H
@@ -138,7 +138,7 @@ public:
 
     // Member functions
 
-        //- Flux
+        //- (intensive) flux
         tmp<scalarField> flux() const;
 
         //- Update the coefficients associated with the patch field
diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/createFluidFields.H b/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/createFluidFields.H
index 907a4b835269790082f0e2b92ef62edb253c995f..314b9d028a3fb16198e0f7842a19c98c2e859e2e 100644
--- a/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/createFluidFields.H
+++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/createFluidFields.H
@@ -82,7 +82,7 @@
                     IOobject::NO_READ,
                     IOobject::NO_WRITE
                 ),
-                thermof[i].rho()*thermof[i].Cp()*thermof[i].alpha()
+                thermof[i].Cp()*thermof[i].alpha()
             )
         );
 
diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/pEqn.H b/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/pEqn.H
index fd018d70962f8a8805c967abeda45cbbc92528e7..2b1f5fceb15b1cf8854cdedd9794142284360e61 100644
--- a/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/pEqn.H
+++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/pEqn.H
@@ -56,5 +56,5 @@
     }
 
     // Update thermal conductivity
-    Kf[i] = rhof[i]*thermof[i].Cp()*turb[i].alphaEff();
+    Kf[i] = thermof[i].Cp()*turb[i].alphaEff();
 }
diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/solid/solveSolid.H b/applications/solvers/heatTransfer/chtMultiRegionFoam/solid/solveSolid.H
index 40299e7b575315ebf474e119eefff142aec054a0..790d4ec9348d2b855f23a2dcb5ea33cf2094b620 100644
--- a/applications/solvers/heatTransfer/chtMultiRegionFoam/solid/solveSolid.H
+++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/solid/solveSolid.H
@@ -6,4 +6,7 @@
             fvm::ddt(rhosCps[i], Ts[i]) - fvm::laplacian(Ks[i], Ts[i])
         );
     }
+
+    Info<< "Min/max T:" << min(Ts[i]) << ' ' << max(Ts[i])
+        << endl;
 }
diff --git a/applications/solvers/incompressible/pisoFoam/pisoFoam.C b/applications/solvers/incompressible/pisoFoam/pisoFoam.C
index dcf1130288236c1a21e2477bd1b5883a4f3ded0d..8491d37ff7489e7c0901bfc478442906c9588f12 100644
--- a/applications/solvers/incompressible/pisoFoam/pisoFoam.C
+++ b/applications/solvers/incompressible/pisoFoam/pisoFoam.C
@@ -70,6 +70,8 @@ int main(int argc, char *argv[])
               + turbulence->divDevReff(U)
             );
 
+            UEqn.relax();
+
             if (momentumPredictor)
             {
                 solve(UEqn == -fvc::grad(p));
diff --git a/applications/solvers/multiphase/cavitatingFoam/pEqn.H b/applications/solvers/multiphase/cavitatingFoam/pEqn.H
index c9382dfc0fb95f3cb59f2d510cad407c4757d8c8..c22aa76479a0d503d22bc60af591a82a7733d850 100644
--- a/applications/solvers/multiphase/cavitatingFoam/pEqn.H
+++ b/applications/solvers/multiphase/cavitatingFoam/pEqn.H
@@ -1,7 +1,7 @@
 {
     if (nOuterCorr == 1)
     {
-        p = 
+        p =
         (
             rho
           - (1.0 - gamma)*rhol0
@@ -37,7 +37,14 @@
           - fvm::laplacian(rUAf, p)
         );
 
-        pEqn.solve();
+        if (corr == nCorr-1 && nonOrth == nNonOrthCorr)
+        {
+            pEqn.solve(mesh.solver(p.name() + "Final"));
+        }
+        else
+        {
+            pEqn.solve(mesh.solver(p.name()));
+        }
 
         if (nonOrth == nNonOrthCorr)
         {
diff --git a/applications/solvers/multiphase/compressibleInterDyMFoam/UEqn.H b/applications/solvers/multiphase/compressibleInterDyMFoam/UEqn.H
index 90033f9826fa037c0d626e2b7f9e4aa5b2fa0ba3..1576f6ba787b037d97c84368836912f0c7d129dd 100644
--- a/applications/solvers/multiphase/compressibleInterDyMFoam/UEqn.H
+++ b/applications/solvers/multiphase/compressibleInterDyMFoam/UEqn.H
@@ -1,13 +1,16 @@
-    surfaceScalarField muf =
+    surfaceScalarField muEff
+    (
+        "muEff",
         twoPhaseProperties.muf()
-      + fvc::interpolate(rho*turbulence->nut());
+      + fvc::interpolate(rho*turbulence->nut())
+    );
 
     fvVectorMatrix UEqn
     (
         fvm::ddt(rho, U)
       + fvm::div(rhoPhi, U)
-      - fvm::laplacian(muf, U)
-      - (fvc::grad(U) & fvc::grad(muf))
+      - fvm::laplacian(muEff, U)
+      - (fvc::grad(U) & fvc::grad(muEff))
     //- fvc::div(muf*(mesh.Sf() & fvc::interpolate(fvc::grad(U)().T())))
     );
 
diff --git a/applications/solvers/multiphase/compressibleInterDyMFoam/alphaEqnsSubCycle.H b/applications/solvers/multiphase/compressibleInterDyMFoam/alphaEqnsSubCycle.H
index e161a3cbe6b2ea9eb48eeca600982f0a4cc3492f..32a7163130ebe623fec24babb865c2a4f8bb9322 100644
--- a/applications/solvers/multiphase/compressibleInterDyMFoam/alphaEqnsSubCycle.H
+++ b/applications/solvers/multiphase/compressibleInterDyMFoam/alphaEqnsSubCycle.H
@@ -12,7 +12,9 @@
     surfaceScalarField phic = mag(phi/mesh.magSf());
     phic = min(interface.cAlpha()*phic, max(phic));
 
+    fvc::makeAbsolute(phi, U);
     volScalarField divU = fvc::div(phi);
+    fvc::makeRelative(phi, U);
 
     if (nAlphaSubCycles > 1)
     {
diff --git a/applications/solvers/multiphase/compressibleInterDyMFoam/pEqn.H b/applications/solvers/multiphase/compressibleInterDyMFoam/pEqn.H
index b0f3378408fb76da41887cee0724a55e77afea11..7e4b37061fdede3fccc625875cc38c447657a198 100644
--- a/applications/solvers/multiphase/compressibleInterDyMFoam/pEqn.H
+++ b/applications/solvers/multiphase/compressibleInterDyMFoam/pEqn.H
@@ -30,7 +30,7 @@
           - ghf*fvc::snGrad(rho)
         )*rUAf*mesh.magSf();
 
-    for(int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++)
+    for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++)
     {
         fvScalarMatrix pdEqnIncomp
         (
@@ -38,15 +38,36 @@
           - fvm::laplacian(rUAf, pd)
         );
 
-        solve
+        if
         (
+            oCorr == nOuterCorr-1
+            && corr == nCorr-1
+            && nonOrth == nNonOrthCorr
+        )
+        {
+            solve
             (
-                max(alpha1, scalar(0))*(psi1/rho1)
-              + max(alpha2, scalar(0))*(psi2/rho2)
-            )
-           *pdEqnComp()
-          + pdEqnIncomp
-        );
+                (
+                    max(alpha1, scalar(0))*(psi1/rho1)
+                  + max(alpha2, scalar(0))*(psi2/rho2)
+                )
+               *pdEqnComp()
+              + pdEqnIncomp,
+                mesh.solver(pd.name() + "Final")
+            );
+        }
+        else
+        {
+            solve
+            (
+                (
+                    max(alpha1, scalar(0))*(psi1/rho1)
+                  + max(alpha2, scalar(0))*(psi2/rho2)
+                )
+               *pdEqnComp()
+              + pdEqnIncomp
+            );
+        }
 
         if (nonOrth == nNonOrthCorr)
         {
@@ -62,7 +83,8 @@
 
     p = max
         (
-            (pd + gh*(alpha1*rho10 + alpha2*rho20))/(1.0 - gh*(alpha1*psi1 + alpha2*psi2)),
+            (pd + gh*(alpha1*rho10 + alpha2*rho20))
+           /(1.0 - gh*(alpha1*psi1 + alpha2*psi2)),
             pMin
         );
 
diff --git a/applications/solvers/multiphase/interPhaseChangeFoam/UEqn.H b/applications/solvers/multiphase/interPhaseChangeFoam/UEqn.H
index f020863077b7b9678a76af75d3249fe860280098..c59137c7b87a9be3c799e03567dc8209341798f5 100644
--- a/applications/solvers/multiphase/interPhaseChangeFoam/UEqn.H
+++ b/applications/solvers/multiphase/interPhaseChangeFoam/UEqn.H
@@ -1,15 +1,18 @@
-    surfaceScalarField muf =
+    surfaceScalarField muEff
+    (
+        "muEff",
         twoPhaseProperties->muf()
-      + fvc::interpolate(rho*turbulence->nut());
+      + fvc::interpolate(rho*turbulence->nut())
+    );
 
     fvVectorMatrix UEqn
     (
         fvm::ddt(rho, U)
       + fvm::div(rhoPhi, U)
       - fvm::Sp(fvc::ddt(rho) + fvc::div(rhoPhi), U)
-      - fvm::laplacian(muf, U)
-      - (fvc::grad(U) & fvc::grad(muf))
-    //- fvc::div(muf*(fvc::interpolate(dev2(fvc::grad(U))) & mesh.Sf()))
+      - fvm::laplacian(muEff, U)
+      - (fvc::grad(U) & fvc::grad(muEff))
+    //- fvc::div(muEff*(fvc::interpolate(dev2(fvc::grad(U))) & mesh.Sf()))
     );
 
     UEqn.relax();
diff --git a/applications/solvers/multiphase/twoPhaseEulerFoam/kineticTheoryModels/kineticTheoryModel/kineticTheoryModel.C b/applications/solvers/multiphase/twoPhaseEulerFoam/kineticTheoryModels/kineticTheoryModel/kineticTheoryModel.C
index c86572a366ede87e9e27203961aca5a3556cea30..5a6d4aa52d79c6a72fcf1e3b7fb0c0e04ae8a0f9 100644
--- a/applications/solvers/multiphase/twoPhaseEulerFoam/kineticTheoryModels/kineticTheoryModel/kineticTheoryModel.C
+++ b/applications/solvers/multiphase/twoPhaseEulerFoam/kineticTheoryModels/kineticTheoryModel/kineticTheoryModel.C
@@ -167,7 +167,7 @@ Foam::kineticTheoryModel::kineticTheoryModel
             IOobject::NO_WRITE
         ),
         Ua_.mesh(),
-        dimensionedScalar("zero", dimensionSet(0, 0, 0, 0, 0), 0.0)
+        dimensionedScalar("zero", dimensionSet(1, -1, -1, 0, 0), 0.0)
     ),
     gs0_
     (
diff --git a/applications/utilities/mesh/manipulation/setSet/writeFuns.C b/applications/utilities/mesh/manipulation/setSet/writeFuns.C
index 6c3d08dc76b2c96d2f8ba30f5f3a4e7a9c77057d..44bf3ecd81060d1a2469f61943acbcea7f0332bc 100644
--- a/applications/utilities/mesh/manipulation/setSet/writeFuns.C
+++ b/applications/utilities/mesh/manipulation/setSet/writeFuns.C
@@ -28,7 +28,7 @@ Description
 
 #include "writeFuns.H"
 
-#ifdef __mips
+#if defined(__mips) && !defined(__SICORTEX__)
 #include <standards.h>
 #include <sys/endian.h>
 #endif
diff --git a/applications/utilities/postProcessing/dataConversion/foamToVTK/writeFuns.C b/applications/utilities/postProcessing/dataConversion/foamToVTK/writeFuns.C
index fcf3c2bc37db8a88e85866323831b46e5b78c750..f699e1758885154c2300776b304b1823e9530470 100644
--- a/applications/utilities/postProcessing/dataConversion/foamToVTK/writeFuns.C
+++ b/applications/utilities/postProcessing/dataConversion/foamToVTK/writeFuns.C
@@ -27,7 +27,7 @@ License
 #include "writeFuns.H"
 #include "vtkTopo.H"
 
-#ifdef __mips
+#if defined(__mips) && !defined(__SICORTEX__)
 #include <standards.h>
 #include <sys/endian.h>
 #endif
diff --git a/applications/utilities/postProcessing/sampling/probeLocations/probeLocations.C b/applications/utilities/postProcessing/sampling/probeLocations/probeLocations.C
index 2efb1620052b3afa827971acc7e4f3d78849aec8..6e9ee2f228690de91729390ff9ab93eb500ce6cd 100644
--- a/applications/utilities/postProcessing/sampling/probeLocations/probeLocations.C
+++ b/applications/utilities/postProcessing/sampling/probeLocations/probeLocations.C
@@ -44,7 +44,14 @@ int main(int argc, char *argv[])
     instantList timeDirs = timeSelector::select0(runTime, args);
 #   include "createMesh.H"
 
-    IOprobes sniff(mesh, "probesDict", IOobject::MUST_READ, true);
+    IOprobes sniff
+    (
+        probes::typeName,
+        mesh,
+        "probesDict",
+        IOobject::MUST_READ,
+        true
+    );
 
     forAll(timeDirs, timeI)
     {
diff --git a/applications/utilities/postProcessing/sampling/sample/sample.C b/applications/utilities/postProcessing/sampling/sample/sample.C
index 8a12916a8eb2b257ffd5a055b4f485e5d69dab45..2735ed2dff0d1b07162d4ef36e8a8e52e869fce0 100644
--- a/applications/utilities/postProcessing/sampling/sample/sample.C
+++ b/applications/utilities/postProcessing/sampling/sample/sample.C
@@ -101,8 +101,23 @@ int main(int argc, char *argv[])
     instantList timeDirs = timeSelector::select0(runTime, args);
 #   include "createMesh.H"
 
-    IOsampledSets sSets(mesh, "sampleDict", IOobject::MUST_READ, true);
-    IOsampledSurfaces sSurfs(mesh, "sampleDict", IOobject::MUST_READ, true);
+    IOsampledSets sSets
+    (
+        sampledSets::typeName,
+        mesh,
+        "sampleDict",
+        IOobject::MUST_READ,
+        true
+    );
+
+    IOsampledSurfaces sSurfs
+    (
+        sampledSurfaces::typeName,
+        mesh,
+        "sampleDict",
+        IOobject::MUST_READ,
+        true
+    );
 
     forAll(timeDirs, timeI)
     {
diff --git a/bin/tools/CleanFunctions b/bin/tools/CleanFunctions
index 5072c9217cd17b9c343f1386b3a61d0f110ac9b6..c63b69c45fb8bb28fdba781ce0d8874fe5d9287d 100644
--- a/bin/tools/CleanFunctions
+++ b/bin/tools/CleanFunctions
@@ -88,7 +88,7 @@ removeCase ()
 
 cleanSamples ()
 {
-    rm -rf {samples,sampleSurfaces} > /dev/null 2>&1
+    rm -rf {sets,samples,sampleSurfaces} > /dev/null 2>&1
 }
 
 cleanUcomponents ()
diff --git a/etc/bashrc b/etc/bashrc
index a01cd281281de06b74c574c824b084b831ee675c..28028384c69d889b7c952631a6c8f68e3d27a217 100644
--- a/etc/bashrc
+++ b/etc/bashrc
@@ -142,6 +142,16 @@ Linux)
         WM_ARCH=linuxIA64
         export WM_COMPILER=I64
         ;;
+    mips64)
+        WM_ARCH=SiCortex64
+        export WM_COMPILER_LIB_ARCH=64
+        export WM_CC='gcc'
+        export WM_CXX='g++'
+        export WM_CFLAGS='-mabi=64 -fPIC'
+        export WM_CXXFLAGS='-mabi=64 -fPIC'
+        export WM_LDFLAGS='-mabi=64 -G0'
+        export WM_MPLIB=MPI
+        ;;
     *)
         echo Unknown processor type `uname -m` for Linux
         ;;
diff --git a/etc/cshrc b/etc/cshrc
index e17c76631ba178c70516b9d687e1e9340b73d2bb..c12ff2e6ba5ca97391824c32cf2249b6862ee05e 100644
--- a/etc/cshrc
+++ b/etc/cshrc
@@ -139,6 +139,16 @@ case Linux:
         setenv WM_ARCH linuxIA64
         setenv WM_COMPILER I64
         breaksw
+    mips64)
+        setenv WM_ARCH SiCortex64
+        setenv WM_COMPILER_LIB_ARCH 64
+        setenv WM_CC 'gcc'
+        setenv WM_CXX 'g++'
+        setenv WM_CFLAGS '-mabi=64 -fPIC'
+        setenv WM_CXXFLAGS '-mabi=64 -fPIC'
+        setenv WM_LDFLAGS '-mabi=64 -G0'
+        setenv WM_MPLIB MPI
+        ;;
     default:
         echo Unknown processor type `uname -m` for Linux
         breaksw
diff --git a/src/OSspecific/Unix/printStack.C b/src/OSspecific/Unix/printStack.C
index c27ad9e5ca30dec507b02832437d69e0243bf13b..f73c50073586faac2d4fe3451f702e5e5c87ee96 100644
--- a/src/OSspecific/Unix/printStack.C
+++ b/src/OSspecific/Unix/printStack.C
@@ -149,7 +149,7 @@ void getSymbolForRaw
     const word& address
 )
 {
-    if (filename[0] == '/')
+    if (filename.size() > 0 && filename[0] == '/')
     {
         string fcnt = pOpen
         (
@@ -220,6 +220,7 @@ void error::printStack(Ostream& os)
             if (lPos != string::npos && rPos != string::npos && lPos<rPos)
             {
                 address = msg.substr(lPos+1, rPos-lPos-1);
+                msg = msg.substr(0, lPos);
             }
 
             string::size_type bracketPos = msg.find('(');
diff --git a/src/OpenFOAM/db/IOobject/IOobjectI.H b/src/OpenFOAM/db/IOobject/IOobjectI.H
index 5d0546dc533a50e26512eec414b0c3d320755df7..2407507c86ae504348060c968c4a2df89653ef69 100644
--- a/src/OpenFOAM/db/IOobject/IOobjectI.H
+++ b/src/OpenFOAM/db/IOobject/IOobjectI.H
@@ -65,8 +65,8 @@ inline void Foam::IOobject::writeBanner(Stream& os, bool noHint)
         "| =========                 |                                                 |\n"
         "| \\\\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |\n"
         "|  \\\\    /   O peration     | Version:  " << FOAMversion << spaces << "|\n"
-        "|   \\\\  /    A nd           |                                                 |\n"
-        "|    \\\\/     M anipulation  |                                www.OpenFOAM.org |\n"
+        "|   \\\\  /    A nd           | Web:      www.OpenFOAM.org                      |\n"
+        "|    \\\\/     M anipulation  |                                                 |\n"
         "\\*---------------------------------------------------------------------------*/\n";
 }
 
diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.C b/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.C
index 0ee14360b9070739b0af2c63ff94c261dc6f4279..3d889af9615eebd56225102cf0353b9e73799d2b 100644
--- a/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.C
+++ b/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.C
@@ -45,15 +45,27 @@ inline void Foam::IPstream::checkEof()
 template<class T>
 inline void Foam::IPstream::readFromBuffer(T& t)
 {
+    const size_t align = sizeof(T);
+    bufPosition_ = align + ((bufPosition_ - 1) & ~(align - 1));
+
     t = reinterpret_cast<T&>(buf_[bufPosition_]);
     bufPosition_ += sizeof(T);
     checkEof();
-    // readFromBuffer(&t, sizeof(T));
 }
 
 
-inline void Foam::IPstream::readFromBuffer(void* data, size_t count)
+inline void Foam::IPstream::readFromBuffer
+(
+    void* data,
+    size_t count,
+    size_t align
+)
 {
+    if (align > 1)
+    {
+        bufPosition_ = align + ((bufPosition_ - 1) & ~(align - 1));
+    }
+
     register const char* bufPtr = &buf_[bufPosition_];
     register char* dataPtr = reinterpret_cast<char*>(data);
     register size_t i = count;
@@ -279,7 +291,7 @@ Foam::Istream& Foam::IPstream::read(char* data, std::streamsize count)
             << Foam::abort(FatalError);
     }
 
-    readFromBuffer(data, count);
+    readFromBuffer(data, count, 8);
     return *this;
 }
 
diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.H
index 3dcbdc3de73b227f3a01f72115409f5a47154bb9..09db5931b8fad4a53e01857ab9419fac17931bd0 100644
--- a/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.H
+++ b/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.H
@@ -70,7 +70,7 @@ class IPstream
         inline void readFromBuffer(T&);
 
         //- Read data from the transfer buffer
-        inline void readFromBuffer(void* data, size_t count);
+        inline void readFromBuffer(void* data, size_t count, size_t align);
 
 
 public:
diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.C b/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.C
index 4dbfc1badd387463afe42931be9b671a417251bd..bb4258af11e58f132a4dc4755814b7cbc74aa179 100644
--- a/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.C
+++ b/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.C
@@ -40,10 +40,7 @@ Description
 template<class T>
 inline void Foam::OPstream::writeToBuffer(const T& t)
 {
-    // (T&)(buf_[bufPosition_]) = t;
-    // bufPosition_ += sizeof(T);
-
-    writeToBuffer(&t, sizeof(T));
+    writeToBuffer(&t, sizeof(T), sizeof(T));
 }
 
 
@@ -59,11 +56,24 @@ inline void Foam::OPstream::writeToBuffer(const char& c)
 }
 
 
-inline void Foam::OPstream::writeToBuffer(const void* data, size_t count)
+inline void Foam::OPstream::writeToBuffer
+(
+    const void* data,
+    size_t count,
+    size_t align
+)
 {
+    label oldPos = bufPosition_;
+
+    if (align > 1)
+    {
+        // Align bufPosition. Pads bufPosition_ - oldPos characters.
+        bufPosition_ = align + ((bufPosition_ - 1) & ~(align - 1));
+    }
+
     if (size_t(buf_.size()) < bufPosition_ + count)
     {
-        enlargeBuffer(count);
+        enlargeBuffer(bufPosition_ - oldPos + count);
     }
 
     register char* bufPtr = &buf_[bufPosition_];
@@ -75,6 +85,7 @@ inline void Foam::OPstream::writeToBuffer(const void* data, size_t count)
 }
 
 
+
 // * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
 
 Foam::OPstream::OPstream
@@ -146,7 +157,7 @@ Foam::Ostream& Foam::OPstream::write(const word& str)
 
     size_t len = str.size();
     writeToBuffer(len);
-    writeToBuffer(str.c_str(), len + 1);
+    writeToBuffer(str.c_str(), len + 1, 1);
 
     return *this;
 }
@@ -158,7 +169,7 @@ Foam::Ostream& Foam::OPstream::write(const string& str)
 
     size_t len = str.size();
     writeToBuffer(len);
-    writeToBuffer(str.c_str(), len + 1);
+    writeToBuffer(str.c_str(), len + 1, 1);
 
     return *this;
 }
@@ -197,7 +208,8 @@ Foam::Ostream& Foam::OPstream::write(const char* data, std::streamsize count)
             << Foam::abort(FatalError);
     }
 
-    writeToBuffer(data, count);
+    writeToBuffer(data, count, 8);
+
     return *this;
 }
 
diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.H
index 7391b36741e87a440c6751c140db99b765fed878..075f7c557c4f174a1a1d85a9e1930b8504fbfde2 100644
--- a/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.H
+++ b/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.H
@@ -69,7 +69,7 @@ class OPstream
         inline void writeToBuffer(const char&);
 
         //- Write data to the transfer buffer
-        inline void writeToBuffer(const void* data, size_t count);
+        inline void writeToBuffer(const void* data, size_t count, size_t align);
 
 
 public:
diff --git a/src/OpenFOAM/db/Time/TimeIO.C b/src/OpenFOAM/db/Time/TimeIO.C
index 44d65fa862190f05fcd1e13593e77ba0c349e946..1f1df0507e9340410546d9fc5fb222d11740a0c7 100644
--- a/src/OpenFOAM/db/Time/TimeIO.C
+++ b/src/OpenFOAM/db/Time/TimeIO.C
@@ -67,7 +67,12 @@ void Foam::Time::readDict()
             case wcAdjustableRunTime:
                 // Recalculate outputTimeIndex_ to be in units of current
                 // writeInterval.
-                outputTimeIndex_ *= oldWriteInterval/writeInterval_;
+                outputTimeIndex_ = label
+                (
+                    outputTimeIndex_
+                  * oldWriteInterval
+                  / writeInterval_
+                );
             break;
 
             default:
diff --git a/src/OpenFOAM/global/global.Cver b/src/OpenFOAM/global/global.Cver
index 66886d59986ae83040561f2608283810fe4c0c41..8bcd7e7728a02947180594c1c7fac38fd100ebcf 100644
--- a/src/OpenFOAM/global/global.Cver
+++ b/src/OpenFOAM/global/global.Cver
@@ -37,6 +37,11 @@ Description
 
 const char* const Foam::FOAMversion = "WM_PROJECT_VERSION";
 
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+// Static initializers for string::null, word::null and fileName::null
+
+#include "stringsGlobals.C"
+
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 // Setup an error handler for the global new operator
 
diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.C b/src/OpenFOAM/primitives/strings/fileName/fileName.C
index 2f669a839ae6fd35f0b37c15d3c4a11960c8bc64..8545d03a95c79ef545ca80aeddc49fae085f573b 100644
--- a/src/OpenFOAM/primitives/strings/fileName/fileName.C
+++ b/src/OpenFOAM/primitives/strings/fileName/fileName.C
@@ -33,7 +33,6 @@ License
 
 const char* const Foam::fileName::typeName = "fileName";
 int Foam::fileName::debug(debug::debugSwitch(fileName::typeName, 0));
-const Foam::fileName Foam::fileName::null;
 
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
diff --git a/src/OpenFOAM/primitives/strings/string/string.C b/src/OpenFOAM/primitives/strings/string/string.C
index f9a863e10f99846a1c019ff1294d48e1fc6a2666..da918d09e1732354cbe4937b5ae3ab37ca9676ab 100644
--- a/src/OpenFOAM/primitives/strings/string/string.C
+++ b/src/OpenFOAM/primitives/strings/string/string.C
@@ -32,7 +32,6 @@ License
 
 const char* const Foam::string::typeName = "string";
 int Foam::string::debug(debug::debugSwitch(string::typeName, 0));
-const Foam::string Foam::string::null;
 
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
diff --git a/src/OpenFOAM/primitives/strings/stringsGlobals.C b/src/OpenFOAM/primitives/strings/stringsGlobals.C
new file mode 100644
index 0000000000000000000000000000000000000000..c81a032ee9b0c1a4f01bc3611ed9f2c55a516cc6
--- /dev/null
+++ b/src/OpenFOAM/primitives/strings/stringsGlobals.C
@@ -0,0 +1,45 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM; if not, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+Description
+    Static initializers for
+        Foam::string::null
+        Foam::word::null
+        Foam::fileName::null.
+    This file is included in global.Cver since these members are required by
+    debug.C.
+
+\*---------------------------------------------------------------------------*/
+
+#include "string.H"
+#include "word.H"
+#include "fileName.H"
+
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
+
+const Foam::string Foam::string::null;
+const Foam::word Foam::word::null;
+const Foam::fileName Foam::fileName::null;
+
+// ************************************************************************* //
diff --git a/src/OpenFOAM/primitives/strings/word/word.C b/src/OpenFOAM/primitives/strings/word/word.C
index d80966ebf045dee586eee26977e96aae6a313d48..c89004665729e2909b225789f973c0e741636896 100644
--- a/src/OpenFOAM/primitives/strings/word/word.C
+++ b/src/OpenFOAM/primitives/strings/word/word.C
@@ -31,6 +31,5 @@ License
 
 const char* const Foam::word::typeName = "word";
 int Foam::word::debug(Foam::debug::debugSwitch(word::typeName, 0));
-const Foam::word Foam::word::null;
 
 // ************************************************************************* //
diff --git a/src/OpenFOAM/primitives/uint/uintIO.C b/src/OpenFOAM/primitives/uint/uintIO.C
index f8eb5b1e59d912ce78ac8da850cb42b40b1f674d..7b976aa96feb7f9e4289fd51d3689255ab4b8b59 100644
--- a/src/OpenFOAM/primitives/uint/uintIO.C
+++ b/src/OpenFOAM/primitives/uint/uintIO.C
@@ -44,7 +44,6 @@ namespace Foam
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
-// Return a string representation of an uint
 word name(const unsigned int i)
 {
     std::ostringstream osBuffer;
@@ -66,7 +65,7 @@ Istream& operator>>(Istream& is, unsigned int& i)
 
     if (t.isLabel())
     {
-        i = uint(t.labelToken());
+        i = unsigned(t.labelToken());
     }
     else
     {
diff --git a/src/autoMesh/Make/files b/src/autoMesh/Make/files
index 96141445bea1ba3e2928715d3a50880f693d29b6..fecec5db5dbd2b8c85870cb0d0a7721397112cff 100644
--- a/src/autoMesh/Make/files
+++ b/src/autoMesh/Make/files
@@ -15,6 +15,7 @@ $(autoHexMeshDriver)/pointData/pointData.C
 $(autoHexMesh)/meshRefinement/meshRefinementBaffles.C
 $(autoHexMesh)/meshRefinement/meshRefinement.C
 $(autoHexMesh)/meshRefinement/meshRefinementMerge.C
+$(autoHexMesh)/meshRefinement/meshRefinementProblemCells.C
 $(autoHexMesh)/meshRefinement/meshRefinementRefine.C
 $(autoHexMesh)/refinementSurfaces/refinementSurfaces.C
 $(autoHexMesh)/shellSurfaces/shellSurfaces.C
diff --git a/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C b/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C
index 5fd329fe86d07cc6d83c9b2b1374b4ac445c70f2..93fa342507d5c3a9d95dad657e8c4d0215724731 100644
--- a/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C
+++ b/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C
@@ -518,7 +518,9 @@ void Foam::autoRefineDriver::baffleAndSplitMesh
     // be like boundary face from now on so not coupled anymore.
     meshRefiner_.baffleAndSplitMesh
     (
-        handleSnapProblems,
+        handleSnapProblems,             // detect&remove potential snap problem
+        false,                          // perpendicular edge connected cells
+        scalarField(0),                 // per region perpendicular angle
         !handleSnapProblems,            // merge free standing baffles?
         motionDict,
         const_cast<Time&>(mesh.time()),
@@ -592,10 +594,14 @@ void Foam::autoRefineDriver::splitAndMergeBaffles
         const_cast<Time&>(mesh.time())++;
     }
 
+    const scalarField& perpAngle = meshRefiner_.surfaces().perpendicularAngle();
+
     meshRefiner_.baffleAndSplitMesh
     (
         handleSnapProblems,
-        false,                  // merge free standing baffles?
+        handleSnapProblems,                 // remove perp edge connected cells
+        perpAngle,                          // perp angle
+        false,                              // merge free standing baffles?
         motionDict,
         const_cast<Time&>(mesh.time()),
         globalToPatch_,
diff --git a/src/autoMesh/autoHexMesh/meshRefinement/meshRefinement.H b/src/autoMesh/autoHexMesh/meshRefinement/meshRefinement.H
index 04901e6ba0d35ec5d652a5b1a7fd5e0389f9626f..c684fbaad4511e961fda77260301304fa2f8cdf2 100644
--- a/src/autoMesh/autoHexMesh/meshRefinement/meshRefinement.H
+++ b/src/autoMesh/autoHexMesh/meshRefinement/meshRefinement.H
@@ -36,6 +36,7 @@ SourceFiles
     meshRefinement.C
     meshRefinementBaffles.C
     meshRefinementMerge.C
+    meshRefinementProblemCells.C
     meshRefinementRefine.C
 
 \*---------------------------------------------------------------------------*/
@@ -51,6 +52,7 @@ SourceFiles
 #include "indirectPrimitivePatch.H"
 #include "pointFieldsFwd.H"
 #include "Tuple2.H"
+#include "pointIndexHit.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -345,6 +347,8 @@ private:
                 polyTopoChange& meshMod
             ) const;
 
+        // Problem cell handling
+
             //- Helper function to mark face as being on 'boundary'. Used by
             //  markFacesOnProblemCells
             void markBoundaryFace
@@ -355,15 +359,32 @@ private:
                 boolList& isBoundaryPoint
             ) const;
 
+            void findNearest
+            (
+                const labelList& meshFaces,
+                List<pointIndexHit>& nearestInfo,
+                labelList& nearestSurface,
+                labelList& nearestRegion,
+                vectorField& nearestNormal
+            ) const;
+
+            Map<label> findEdgeConnectedProblemCells
+            (
+                const scalarField& perpendicularAngle,
+                const labelList&
+            ) const;
+
             //- Returns list with for every internal face -1 or the patch
-            //  they should be baffled into.
+            //  they should be baffled into. If removeEdgeConnectedCells is set
+            //  removes cells based on perpendicularAngle.
             labelList markFacesOnProblemCells
             (
+                const bool removeEdgeConnectedCells,
+                const scalarField& perpendicularAngle,
                 const labelList& globalToPatch
             ) const;
 
-            //- Returns list with for every internal face -1 or the patch
-            //  they should be baffled into.
+            //- Initial test of marking faces using geometric information.
             labelList markFacesOnProblemCellsGeometric
             (
                 const dictionary& motionDict,
@@ -589,6 +610,8 @@ public:
             void baffleAndSplitMesh
             (
                 const bool handleSnapProblems,
+                const bool removeEdgeConnectedCells,
+                const scalarField& perpendicularAngle,
                 const bool mergeFreeStanding,
                 const dictionary& motionDict,
                 Time& runTime,
diff --git a/src/autoMesh/autoHexMesh/meshRefinement/meshRefinementBaffles.C b/src/autoMesh/autoHexMesh/meshRefinement/meshRefinementBaffles.C
index 486d86289ba223a16cd9e1f6c3455e79a5c16110..79d698bef6c276641b72ad79bfc38b684048cd06 100644
--- a/src/autoMesh/autoHexMesh/meshRefinement/meshRefinementBaffles.C
+++ b/src/autoMesh/autoHexMesh/meshRefinement/meshRefinementBaffles.C
@@ -44,10 +44,6 @@ License
 #include "OFstream.H"
 #include "regionSplit.H"
 #include "removeCells.H"
-#include "motionSmoother.H"
-#include "polyMeshGeometry.H"
-#include "IOmanip.H"
-#include "cellSet.H"
 
 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
 
@@ -230,7 +226,7 @@ void Foam::meshRefinement::getBafflePatches
     label vertI = 0;
     if (debug&OBJINTERSECTIONS)
     {
-        str.reset(new OFstream(mesh_.time().path()/"intersections.obj"));
+        str.reset(new OFstream(mesh_.time().timePath()/"intersections.obj"));
 
         Pout<< "getBafflePatches : Writing surface intersections to file "
             << str().name() << nl << endl;
@@ -510,642 +506,6 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::createBaffles
 }
 
 
-void Foam::meshRefinement::markBoundaryFace
-(
-    const label faceI,
-    boolList& isBoundaryFace,
-    boolList& isBoundaryEdge,
-    boolList& isBoundaryPoint
-) const
-{
-    isBoundaryFace[faceI] = true;
-
-    const labelList& fEdges = mesh_.faceEdges(faceI);
-
-    forAll(fEdges, fp)
-    {
-        isBoundaryEdge[fEdges[fp]] = true;
-    }
-
-    const face& f = mesh_.faces()[faceI];
-
-    forAll(f, fp)
-    {
-        isBoundaryPoint[f[fp]] = true;
-    }
-}
-
-
-// Returns list with for every internal face -1 or the patch they should
-// be baffled into. Gets run after createBaffles so all the surface
-// intersections have already been turned into baffles. Used to remove cells
-// by baffling all their faces and have the splitMeshRegions chuck away non
-// used regions.
-Foam::labelList Foam::meshRefinement::markFacesOnProblemCells
-(
-    const labelList& globalToPatch
-) const
-{
-    const labelList& cellLevel = meshCutter_.cellLevel();
-    const labelList& pointLevel = meshCutter_.pointLevel();
-    const polyBoundaryMesh& patches = mesh_.boundaryMesh();
-
-
-    // Per internal face (boundary faces not used) the patch that the
-    // baffle should get (or -1)
-    labelList facePatch(mesh_.nFaces(), -1);
-
-    // Mark all points and edges on baffle patches (so not on any inlets,
-    // outlets etc.)
-    boolList isBoundaryPoint(mesh_.nPoints(), false);
-    boolList isBoundaryEdge(mesh_.nEdges(), false);
-    boolList isBoundaryFace(mesh_.nFaces(), false);
-
-    // Fill boundary data. All elements on meshed patches get marked.
-    // Get the labels of added patches.
-    labelList adaptPatchIDs(meshRefinement::addedPatches(globalToPatch));
-
-    forAll(adaptPatchIDs, i)
-    {
-        label patchI = adaptPatchIDs[i];
-
-        const polyPatch& pp = patches[patchI];
-
-        label faceI = pp.start();
-
-        forAll(pp, j)
-        {
-            markBoundaryFace
-            (
-                faceI,
-                isBoundaryFace,
-                isBoundaryEdge,
-                isBoundaryPoint
-            );
-
-            faceI++;
-        }
-    }
-
-    syncTools::syncPointList
-    (
-        mesh_,
-        isBoundaryPoint,
-        orEqOp<bool>(),
-        false,              // null value
-        false               // no separation
-    );
-
-    syncTools::syncEdgeList
-    (
-        mesh_,
-        isBoundaryEdge,
-        orEqOp<bool>(),
-        false,              // null value
-        false               // no separation
-    );
-
-    syncTools::syncFaceList
-    (
-        mesh_,
-        isBoundaryFace,
-        orEqOp<bool>(),
-        false               // no separation
-    );
-
-
-    // For each cell count the number of anchor points that are on
-    // the boundary:
-    // 8 : check the number of (baffle) boundary faces. If 3 or more block
-    //     off the cell since the cell would get squeezed down to a diamond
-    //     (probably; if the 3 or more faces are unrefined (only use the
-    //      anchor points))
-    // 7 : store. Used to check later on whether there are points with
-    //     3 or more of these cells. (note that on a flat surface a boundary
-    //     point will only have 4 cells connected to it)
-
-    // Does cell have exactly 7 of its 8 anchor points on the boundary?
-    PackedList<1> hasSevenBoundaryAnchorPoints(mesh_.nCells(), 0u);
-    // If so what is the remaining non-boundary anchor point?
-    labelHashSet nonBoundaryAnchors(mesh_.nCells()/10000);
-
-    // On-the-fly addressing storage.
-    DynamicList<label> dynFEdges;
-    DynamicList<label> dynCPoints;
-
-    // Count of faces marked for baffling
-    label nBaffleFaces = 0;
-
-    forAll(cellLevel, cellI)
-    {
-        const labelList& cPoints = mesh_.cellPoints(cellI, dynCPoints);
-
-        // Get number of anchor points (pointLevel == cellLevel)
-
-        label nBoundaryAnchors = 0;
-        label nNonAnchorBoundary = 0;
-        label nonBoundaryAnchor = -1;
-
-        forAll(cPoints, i)
-        {
-            label pointI = cPoints[i];
-
-            if (pointLevel[pointI] <= cellLevel[cellI])
-            {
-                // Anchor point
-                if (isBoundaryPoint[pointI])
-                {
-                    nBoundaryAnchors++;
-                }
-                else
-                {
-                    // Anchor point which is not on the surface
-                    nonBoundaryAnchor = pointI;
-                }
-            }
-            else if (isBoundaryPoint[pointI])
-            {
-                nNonAnchorBoundary++;
-            }
-        }
-
-        if (nBoundaryAnchors == 8)
-        {
-            const cell& cFaces = mesh_.cells()[cellI];
-
-            // Count boundary faces.
-            label nBfaces = 0;
-
-            forAll(cFaces, cFaceI)
-            {
-                if (isBoundaryFace[cFaces[cFaceI]])
-                {
-                    nBfaces++;
-                }
-            }
-
-            // If nBfaces > 1 make all non-boundary non-baffle faces baffles.
-            // We assume that this situation is where there is a single
-            // cell sticking out which would get flattened.
-
-            // Eugene: delete cell no matter what.
-            //if (nBfaces > 1)
-            {
-                forAll(cFaces, cf)
-                {
-                    label faceI = cFaces[cf];
-
-                    if (facePatch[faceI] == -1 && mesh_.isInternalFace(faceI))
-                    {
-                        facePatch[faceI] = getBafflePatch(facePatch, faceI);
-                        nBaffleFaces++;
-
-                        // Mark face as a 'boundary'
-                        markBoundaryFace
-                        (
-                            faceI,
-                            isBoundaryFace,
-                            isBoundaryEdge,
-                            isBoundaryPoint
-                        );
-                    }
-                }
-            }
-        }
-        else if (nBoundaryAnchors == 7)
-        {
-            // Mark the cell. Store the (single!) non-boundary anchor point.
-            hasSevenBoundaryAnchorPoints.set(cellI, 1u);
-            nonBoundaryAnchors.insert(nonBoundaryAnchor);
-        }
-    }
-
-
-    // Loop over all points. If a point is connected to 4 or more cells
-    // with 7 anchor points on the boundary set those cell's non-boundary faces
-    // to baffles
-
-    DynamicList<label> dynPCells;
-
-    forAllConstIter(labelHashSet, nonBoundaryAnchors, iter)
-    {
-        label pointI = iter.key();
-
-        const labelList& pCells = mesh_.pointCells(pointI, dynPCells);
-
-        // Count number of 'hasSevenBoundaryAnchorPoints' cells.
-        label n = 0;
-
-        forAll(pCells, i)
-        {
-            if (hasSevenBoundaryAnchorPoints.get(pCells[i]) == 1u)
-            {
-                n++;
-            }
-        }
-
-        if (n > 3)
-        {
-            // Point in danger of being what? Remove all 7-cells.
-            forAll(pCells, i)
-            {
-                label cellI = pCells[i];
-
-                if (hasSevenBoundaryAnchorPoints.get(cellI) == 1u)
-                {
-                    const cell& cFaces = mesh_.cells()[cellI];
-
-                    forAll(cFaces, cf)
-                    {
-                        label faceI = cFaces[cf];
-
-                        if
-                        (
-                            facePatch[faceI] == -1
-                         && mesh_.isInternalFace(faceI)
-                        )
-                        {
-                            facePatch[faceI] = getBafflePatch(facePatch, faceI);
-                            nBaffleFaces++;
-
-                            // Mark face as a 'boundary'
-                            markBoundaryFace
-                            (
-                                faceI,
-                                isBoundaryFace,
-                                isBoundaryEdge,
-                                isBoundaryPoint
-                            );
-                        }
-                    }
-                }
-            }
-        }
-    }
-
-
-    // Sync all. (note that pointdata and facedata not used anymore but sync
-    // anyway)
-
-    syncTools::syncPointList
-    (
-        mesh_,
-        isBoundaryPoint,
-        orEqOp<bool>(),
-        false,              // null value
-        false               // no separation
-    );
-
-    syncTools::syncEdgeList
-    (
-        mesh_,
-        isBoundaryEdge,
-        orEqOp<bool>(),
-        false,              // null value
-        false               // no separation
-    );
-
-    syncTools::syncFaceList
-    (
-        mesh_,
-        isBoundaryFace,
-        orEqOp<bool>(),
-        false               // no separation
-    );
-
-
-    // Find faces with all edges on the boundary and make them baffles
-    for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
-    {
-        if (facePatch[faceI] == -1)
-        {
-            const labelList& fEdges = mesh_.faceEdges(faceI, dynFEdges);
-            label nFaceBoundaryEdges = 0;
-
-            forAll(fEdges, fe)
-            {
-                if (isBoundaryEdge[fEdges[fe]])
-                {
-                    nFaceBoundaryEdges++;
-                }
-            }
-
-            if (nFaceBoundaryEdges == fEdges.size())
-            {
-                facePatch[faceI] = getBafflePatch(facePatch, faceI);
-                nBaffleFaces++;
-
-                // Do NOT update boundary data since this would grow blocked
-                // faces across gaps.
-            }
-        }
-    }
-
-    forAll(patches, patchI)
-    {
-        const polyPatch& pp = patches[patchI];
-
-        if (pp.coupled())
-        {
-            label faceI = pp.start();
-
-            forAll(pp, i)
-            {
-                if (facePatch[faceI] == -1)
-                {
-                    const labelList& fEdges = mesh_.faceEdges(faceI, dynFEdges);
-                    label nFaceBoundaryEdges = 0;
-
-                    forAll(fEdges, fe)
-                    {
-                        if (isBoundaryEdge[fEdges[fe]])
-                        {
-                            nFaceBoundaryEdges++;
-                        }
-                    }
-
-                    if (nFaceBoundaryEdges == fEdges.size())
-                    {
-                        facePatch[faceI] = getBafflePatch(facePatch, faceI);
-                        nBaffleFaces++;
-
-                        // Do NOT update boundary data since this would grow
-                        // blocked faces across gaps.
-                    }
-                }
-
-                faceI++;
-            }
-        }
-    }
-
-    Info<< "markFacesOnProblemCells : marked "
-        << returnReduce(nBaffleFaces, sumOp<label>())
-        << " additional internal faces to be converted into baffles."
-        << endl;
-
-    return facePatch;
-}
-//XXXXXXXXXXXXXX
-// Mark faces to be baffled to prevent snapping problems. Does
-// test to find nearest surface and checks which faces would get squashed.
-Foam::labelList Foam::meshRefinement::markFacesOnProblemCellsGeometric
-(
-    const dictionary& motionDict,
-    const labelList& globalToPatch
-) const
-{
-    // Get the labels of added patches.
-    labelList adaptPatchIDs(meshRefinement::addedPatches(globalToPatch));
-
-    // Construct addressing engine.
-    autoPtr<indirectPrimitivePatch> ppPtr
-    (
-        meshRefinement::makePatch
-        (
-            mesh_,
-            adaptPatchIDs
-        )
-    );
-    const indirectPrimitivePatch& pp = ppPtr();
-    const pointField& localPoints = pp.localPoints();
-    const labelList& meshPoints = pp.meshPoints();
-
-    // Find nearest (non-baffle) surface
-    pointField newPoints(mesh_.points());
-    {
-        List<pointIndexHit> hitInfo;
-        labelList hitSurface;
-        surfaces_.findNearest
-        (
-            surfaces_.getUnnamedSurfaces(),
-            localPoints,
-            scalarField(localPoints.size(), sqr(GREAT)),    // sqr of attraction
-            hitSurface,
-            hitInfo
-        );
-    
-        forAll(hitInfo, i)
-        {
-            if (hitInfo[i].hit())
-            {
-                //label pointI = meshPoints[i];
-                //Pout<< "   " << pointI << " moved from "
-                //    << mesh_.points()[pointI] << " by "
-                //    << mag(hitInfo[i].hitPoint()-mesh_.points()[pointI])
-                //    << endl;
-                newPoints[meshPoints[i]] = hitInfo[i].hitPoint();
-            }
-        }
-    }
-
-    // Per face (internal or coupled!) the patch that the
-    // baffle should get (or -1).
-    labelList facePatch(mesh_.nFaces(), -1);
-    // Count of baffled faces
-    label nBaffleFaces = 0;
-
-
-//    // Sync position? Or not since same face on both side so just sync
-//    // result of baffle.
-//
-//    const scalar minArea(readScalar(motionDict.lookup("minArea")));
-//
-//    Pout<< "markFacesOnProblemCellsGeometric : Comparing to minArea:"
-//        << minArea << endl;
-//
-//    pointField facePoints;
-//    for (label faceI = mesh_.nInternalFaces(); faceI < mesh_.nFaces(); faceI++)
-//    {
-//        const face& f = mesh_.faces()[faceI];
-//
-//        bool usesPatchPoint = false;
-//
-//        facePoints.setSize(f.size());
-//        forAll(f, fp)
-//        {
-//            Map<label>::const_iterator iter = pp.meshPointMap().find(f[fp]);
-//
-//            if (iter != pp.meshPointMap().end())
-//            {
-//                facePoints[fp] = newPosition[iter()];
-//                usesPatchPoint = true;
-//            }
-//            else
-//            {
-//                facePoints[fp] = mesh_.points()[f[fp]];
-//            }
-//        }
-//
-//        if (usesPatchPoint)
-//        {
-//            // Check area of face wrt original area
-//            face identFace(identity(f.size()));
-//
-//            if (identFace.mag(facePoints) < minArea)
-//            {
-//                facePatch[faceI] = getBafflePatch(facePatch, faceI);
-//                nBaffleFaces++;
-//            }
-//        }
-//    }
-//
-//
-//    const polyBoundaryMesh& patches = mesh_.boundaryMesh();
-//    forAll(patches, patchI)
-//    {
-//        const polyPatch& pp = patches[patchI];
-//
-//        if (pp.coupled())
-//        {
-//            forAll(pp, i)
-//            {
-//                label faceI = pp.start()+i;
-//
-//                const face& f = mesh_.faces()[faceI];
-//
-//                bool usesPatchPoint = false;
-//
-//                facePoints.setSize(f.size());
-//                forAll(f, fp)
-//                {
-//                    Map<label>::const_iterator iter =
-//                        pp.meshPointMap().find(f[fp]);
-//
-//                    if (iter != pp.meshPointMap().end())
-//                    {
-//                        facePoints[fp] = newPosition[iter()];
-//                        usesPatchPoint = true;
-//                    }
-//                    else
-//                    {
-//                        facePoints[fp] = mesh_.points()[f[fp]];
-//                    }
-//                }
-//
-//                if (usesPatchPoint)
-//                {
-//                    // Check area of face wrt original area
-//                    face identFace(identity(f.size()));
-//
-//                    if (identFace.mag(facePoints) < minArea)
-//                    {
-//                        facePatch[faceI] = getBafflePatch(facePatch, faceI);
-//                        nBaffleFaces++;
-//                    }
-//                }
-//            }
-//        }
-//    }
-
-    {
-        pointField oldPoints(mesh_.points());
-        mesh_.movePoints(newPoints);
-        faceSet wrongFaces(mesh_, "wrongFaces", 100);
-        {
-            //motionSmoother::checkMesh(false, mesh_, motionDict, wrongFaces);
-
-            // Just check the errors from squashing
-            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-            const labelList allFaces(identity(mesh_.nFaces()));
-            label nWrongFaces = 0;
-
-            scalar minArea(readScalar(motionDict.lookup("minArea")));
-            if (minArea > -SMALL)
-            {
-                polyMeshGeometry::checkFaceArea
-                (
-                    false,
-                    minArea,
-                    mesh_,
-                    mesh_.faceAreas(),
-                    allFaces,
-                    &wrongFaces
-                );
-
-                label nNewWrongFaces = returnReduce
-                (
-                    wrongFaces.size(),
-                    sumOp<label>()
-                );
-
-                Info<< "    faces with area < "
-                    << setw(5) << minArea
-                    << " m^2                            : "
-                    << nNewWrongFaces-nWrongFaces << endl;
-
-                nWrongFaces = nNewWrongFaces;
-            }
-
-//            scalar minDet(readScalar(motionDict.lookup("minDeterminant")));
-            scalar minDet = 0.01;
-            if (minDet > -1)
-            {
-                polyMeshGeometry::checkCellDeterminant
-                (
-                    false,
-                    minDet,
-                    mesh_,
-                    mesh_.faceAreas(),
-                    allFaces,
-                    polyMeshGeometry::affectedCells(mesh_, allFaces),
-                    &wrongFaces
-                );
-
-                label nNewWrongFaces = returnReduce
-                (
-                    wrongFaces.size(),
-                    sumOp<label>()
-                );
-
-                Info<< "    faces on cells with determinant < "
-                    << setw(5) << minDet << "                : "
-                    << nNewWrongFaces-nWrongFaces << endl;
-
-                nWrongFaces = nNewWrongFaces;
-            }
-        }
-
-
-        forAllConstIter(faceSet, wrongFaces, iter)
-        {
-            label patchI = mesh_.boundaryMesh().whichPatch(iter.key());
-
-            if (patchI == -1 || mesh_.boundaryMesh()[patchI].coupled())
-            {
-                facePatch[iter.key()] = getBafflePatch(facePatch, iter.key());
-                nBaffleFaces++;
-
-                //Pout<< "    " << iter.key()
-                //    //<< " on patch " << mesh_.boundaryMesh()[patchI].name()
-                //    << " is destined for patch " << facePatch[iter.key()]
-                //    << endl;
-            }
-        }
-        // Restore points.
-        mesh_.movePoints(oldPoints);
-    }
-
-
-    Info<< "markFacesOnProblemCellsGeometric : marked "
-        << returnReduce(nBaffleFaces, sumOp<label>())
-        << " additional internal and coupled faces"
-        << " to be converted into baffles." << endl;
-
-    syncTools::syncFaceList
-    (
-        mesh_,
-        facePatch,
-        maxEqOp<label>(),
-        false               // no separation
-    );
-
-    return facePatch;
-}
-//XXXXXXXX
-
-
 // Return a list of coupled face pairs, i.e. faces that use the same vertices.
 // (this information is recalculated instead of maintained since would be too
 // hard across splitMeshRegions).
@@ -1855,13 +1215,13 @@ void Foam::meshRefinement::findCellZoneTopo
             break;
         }
 
-	// Synchronise regionToCellZone.
-	// Note:
-	// - region numbers are identical on all processors
-	// - keepRegion is identical ,,
-	// - cellZones are identical ,,
-	Pstream::listCombineGather(regionToCellZone, maxEqOp<label>());
-	Pstream::listCombineScatter(regionToCellZone);
+        // Synchronise regionToCellZone.
+        // Note:
+        // - region numbers are identical on all processors
+        // - keepRegion is identical ,,
+        // - cellZones are identical ,,
+        Pstream::listCombineGather(regionToCellZone, maxEqOp<label>());
+        Pstream::listCombineScatter(regionToCellZone);
     }
 
 
@@ -1904,6 +1264,8 @@ void Foam::meshRefinement::findCellZoneTopo
 void Foam::meshRefinement::baffleAndSplitMesh
 (
     const bool handleSnapProblems,
+    const bool removeEdgeConnectedCells,
+    const scalarField& perpendicularAngle,
     const bool mergeFreeStanding,
     const dictionary& motionDict,
     Time& runTime,
@@ -1981,6 +1343,8 @@ void Foam::meshRefinement::baffleAndSplitMesh
         (
             markFacesOnProblemCells
             (
+                removeEdgeConnectedCells,
+                perpendicularAngle,
                 globalToPatch
             )
             //markFacesOnProblemCellsGeometric
@@ -2024,6 +1388,8 @@ void Foam::meshRefinement::baffleAndSplitMesh
             (    
                 markFacesOnProblemCells
                 (
+                    removeEdgeConnectedCells,
+                    perpendicularAngle,
                     globalToPatch
                 )
             );
@@ -2099,7 +1465,7 @@ void Foam::meshRefinement::baffleAndSplitMesh
     {
         Pout<< "Writing subsetted mesh to time " << mesh_.time().timeName()
             << endl;
-        write(debug, runTime.path()/runTime.timeName());
+        write(debug, runTime.timePath());
         Pout<< "Dumped debug data in = "
             << runTime.cpuTimeIncrement() << " s\n" << nl << endl;
     }
diff --git a/src/autoMesh/autoHexMesh/meshRefinement/meshRefinementProblemCells.C b/src/autoMesh/autoHexMesh/meshRefinement/meshRefinementProblemCells.C
new file mode 100644
index 0000000000000000000000000000000000000000..8a027fa654b9de308e38fdd43f2c7f355b4c8c36
--- /dev/null
+++ b/src/autoMesh/autoHexMesh/meshRefinement/meshRefinementProblemCells.C
@@ -0,0 +1,952 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
+     \\/     M anipulation  |
+-------------------------------------------------------------------------------
+License
+    This file is part of OpenFOAM.
+
+    OpenFOAM is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 2 of the License, or (at your
+    option) any later version.
+
+    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+    for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OpenFOAM; if not, write to the Free Software Foundation,
+    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+\*----------------------------------------------------------------------------*/
+
+#include "meshRefinement.H"
+#include "fvMesh.H"
+#include "syncTools.H"
+#include "Time.H"
+#include "refinementSurfaces.H"
+#include "pointSet.H"
+#include "faceSet.H"
+#include "indirectPrimitivePatch.H"
+#include "OFstream.H"
+#include "cellSet.H"
+#include "searchableSurfaces.H"
+#include "polyMeshGeometry.H"
+#include "IOmanip.H"
+
+// * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
+
+void Foam::meshRefinement::markBoundaryFace
+(
+    const label faceI,
+    boolList& isBoundaryFace,
+    boolList& isBoundaryEdge,
+    boolList& isBoundaryPoint
+) const
+{
+    isBoundaryFace[faceI] = true;
+
+    const labelList& fEdges = mesh_.faceEdges(faceI);
+
+    forAll(fEdges, fp)
+    {
+        isBoundaryEdge[fEdges[fp]] = true;
+    }
+
+    const face& f = mesh_.faces()[faceI];
+
+    forAll(f, fp)
+    {
+        isBoundaryPoint[f[fp]] = true;
+    }
+}
+
+
+void Foam::meshRefinement::findNearest
+(
+    const labelList& meshFaces,
+    List<pointIndexHit>& nearestInfo,
+    labelList& nearestSurface,
+    labelList& nearestRegion,
+    vectorField& nearestNormal
+) const
+{
+    pointField fc(meshFaces.size());
+    forAll(meshFaces, i)
+    {
+        fc[i] = mesh_.faceCentres()[meshFaces[i]];
+    }
+
+    const labelList allSurfaces(identity(surfaces_.surfaces().size()));
+
+    surfaces_.findNearest
+    (
+        allSurfaces,
+        fc,
+        scalarField(fc.size(), sqr(GREAT)),    // sqr of attraction
+        nearestSurface,
+        nearestInfo
+    );
+
+    // Do normal testing per surface.
+    nearestNormal.setSize(nearestInfo.size());
+    nearestRegion.setSize(nearestInfo.size());
+
+    forAll(allSurfaces, surfI)
+    {
+        DynamicList<pointIndexHit> localHits;
+
+        forAll(nearestSurface, i)
+        {
+            if (nearestSurface[i] == surfI)
+            {
+                localHits.append(nearestInfo[i]);
+            }
+        }
+
+        label geomI = surfaces_.surfaces()[surfI];
+
+        pointField localNormals;
+        surfaces_.geometry()[geomI].getNormal(localHits, localNormals);
+
+        labelList localRegion;
+        surfaces_.geometry()[geomI].getRegion(localHits, localRegion);
+
+        label localI = 0;
+        forAll(nearestSurface, i)
+        {
+            if (nearestSurface[i] == surfI)
+            {
+                nearestNormal[i] = localNormals[localI];
+                nearestRegion[i] = localRegion[localI];
+                localI++;
+            }
+        }
+    }
+}
+
+
+Foam::Map<Foam::label> Foam::meshRefinement::findEdgeConnectedProblemCells
+(
+    const scalarField& perpendicularAngle,
+    const labelList& globalToPatch
+) const
+{
+    labelList adaptPatchIDs(meshRefinement::addedPatches(globalToPatch));
+
+    // Construct addressing engine.
+    autoPtr<indirectPrimitivePatch> ppPtr
+    (
+        meshRefinement::makePatch
+        (
+            mesh_,
+            adaptPatchIDs
+        )
+    );
+    const indirectPrimitivePatch& pp = ppPtr();
+
+
+    // 1. Collect faces to test
+    // ~~~~~~~~~~~~~~~~~~~~~~~~
+
+    DynamicList<label> candidateFaces(pp.size()/20);
+
+    const labelListList& edgeFaces = pp.edgeFaces();
+
+    const labelList& cellLevel = meshCutter_.cellLevel();
+
+    forAll(edgeFaces, edgeI)
+    {
+        const labelList& eFaces = edgeFaces[edgeI];
+
+        if (eFaces.size() == 2)
+        {
+            label face0 = pp.addressing()[eFaces[0]];
+            label face1 = pp.addressing()[eFaces[1]];
+
+            label cell0 = mesh_.faceOwner()[face0];
+            label cell1 = mesh_.faceOwner()[face1];
+
+            if (cellLevel[cell0] > cellLevel[cell1])
+            {
+                // cell0 smaller.
+                const vector& n0 = pp.faceNormals()[eFaces[0]];
+                const vector& n1 = pp.faceNormals()[eFaces[1]];
+
+                if (mag(n0 & n1) < 0.1)
+                {
+                    candidateFaces.append(face0);
+                }
+            }
+            else if (cellLevel[cell1] > cellLevel[cell0])
+            {
+                // cell1 smaller.
+                const vector& n0 = pp.faceNormals()[eFaces[0]];
+                const vector& n1 = pp.faceNormals()[eFaces[1]];
+
+                if (mag(n0 & n1) < 0.1)
+                {
+                    candidateFaces.append(face1);
+                }
+            }
+        }
+    }
+    candidateFaces.shrink();
+
+    Info<< "Testing " << returnReduce(candidateFaces.size(), sumOp<label>())
+        << " faces on edge-connected cells of differing level."
+        << endl;
+
+    if (debug)
+    {
+        faceSet fSet(mesh_, "edgeConnectedFaces", candidateFaces);
+        Pout<< "Writing " << fSet.size()
+            << " with problematic topology to faceSet "
+            << fSet.objectPath() << endl;
+        fSet.write();
+    }
+
+
+    // 2. Find nearest surface on candidate faces
+    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+    List<pointIndexHit> nearestInfo;
+    labelList nearestSurface;
+    labelList nearestRegion;
+    vectorField nearestNormal;
+    findNearest
+    (
+        candidateFaces,
+        nearestInfo,
+        nearestSurface,
+        nearestRegion,
+        nearestNormal
+    );
+
+
+    // 3. Test angle to surface
+    // ~~~~~~~~~~~~~~~~~~~~~~~~
+
+    Map<label> candidateCells(candidateFaces.size());
+
+    faceSet perpFaces(mesh_, "perpendicularFaces", pp.size()/100);
+
+    forAll(candidateFaces, i)
+    {
+        label faceI = candidateFaces[i];
+
+        vector n = mesh_.faceAreas()[faceI];
+        n /= mag(n);
+
+        label region = surfaces_.globalRegion
+        (
+            nearestSurface[i],
+            nearestRegion[i]
+        );
+
+        scalar angle =
+            perpendicularAngle[region]
+          / 180.0
+          * mathematicalConstant::pi;
+
+        if (angle >= 0)
+        {
+            if (mag(n & nearestNormal[i]) < Foam::sin(angle))
+            {
+                perpFaces.insert(faceI);
+                candidateCells.insert
+                (
+                    mesh_.faceOwner()[faceI],
+                    globalToPatch[region]
+                );
+            }
+        }
+    }
+
+    if (debug)
+    {
+        Pout<< "Writing " << perpFaces.size()
+            << " faces that are perpendicular to the surface to set "
+            << perpFaces.objectPath() << endl;
+        perpFaces.write();
+    }
+    return candidateCells;
+}
+
+
+// Returns list with for every internal face -1 or the patch they should
+// be baffled into. Gets run after createBaffles so all the surface
+// intersections have already been turned into baffles. Used to remove cells
+// by baffling all their faces and have the splitMeshRegions chuck away non
+// used regions.
+Foam::labelList Foam::meshRefinement::markFacesOnProblemCells
+(
+    const bool removeEdgeConnectedCells,
+    const scalarField& perpendicularAngle,
+    const labelList& globalToPatch
+) const
+{
+    const labelList& cellLevel = meshCutter_.cellLevel();
+    const labelList& pointLevel = meshCutter_.pointLevel();
+    const polyBoundaryMesh& patches = mesh_.boundaryMesh();
+
+
+    // Per internal face (boundary faces not used) the patch that the
+    // baffle should get (or -1)
+    labelList facePatch(mesh_.nFaces(), -1);
+
+    // Mark all points and edges on baffle patches (so not on any inlets,
+    // outlets etc.)
+    boolList isBoundaryPoint(mesh_.nPoints(), false);
+    boolList isBoundaryEdge(mesh_.nEdges(), false);
+    boolList isBoundaryFace(mesh_.nFaces(), false);
+
+    // Fill boundary data. All elements on meshed patches get marked.
+    // Get the labels of added patches.
+    labelList adaptPatchIDs(meshRefinement::addedPatches(globalToPatch));
+
+    forAll(adaptPatchIDs, i)
+    {
+        label patchI = adaptPatchIDs[i];
+
+        const polyPatch& pp = patches[patchI];
+
+        label faceI = pp.start();
+
+        forAll(pp, j)
+        {
+            markBoundaryFace
+            (
+                faceI,
+                isBoundaryFace,
+                isBoundaryEdge,
+                isBoundaryPoint
+            );
+
+            faceI++;
+        }
+    }
+
+    // Count of faces marked for baffling
+    label nBaffleFaces = 0;
+
+    if (removeEdgeConnectedCells && max(perpendicularAngle) >= 0)
+    {
+        Info<< "markFacesOnProblemCells :"
+            << " Checking for edge-connected cells of highly differing sizes."
+            << endl;
+
+        // Pick up the cells that need to be removed and (a guess for)
+        // the patch they should be patched with.
+        Map<label> problemCells
+        (
+            findEdgeConnectedProblemCells
+            (
+                perpendicularAngle,
+                globalToPatch
+            )
+        );
+
+        // Baffle all faces of cells that need to be removed
+        forAllConstIter(Map<label>, problemCells, iter)
+        {
+            const cell& cFaces = mesh_.cells()[iter.key()];
+
+            forAll(cFaces, i)
+            {
+                label faceI = cFaces[i];
+
+                if (facePatch[faceI] == -1 && mesh_.isInternalFace(faceI))
+                {
+                    facePatch[faceI] = getBafflePatch(facePatch, faceI);
+                    nBaffleFaces++;
+
+                    // Mark face as a 'boundary'
+                    markBoundaryFace
+                    (
+                        faceI,
+                        isBoundaryFace,
+                        isBoundaryEdge,
+                        isBoundaryPoint
+                    );
+                }
+            }
+        }
+        Info<< "markFacesOnProblemCells : Marked "
+            << returnReduce(nBaffleFaces, sumOp<label>())
+            << " additional internal faces to be converted into baffles"
+            << " due to "
+            << returnReduce(problemCells.size(), sumOp<label>())
+            << " cells edge-connected to lower level cells." << endl;
+
+        if (debug)
+        {
+            cellSet problemCellSet(mesh_, "problemCells", problemCells.toc());
+            Pout<< "Writing " << problemCellSet.size()
+                << " cells that are edge connected to coarser cell to set "
+                << problemCellSet.objectPath() << endl;
+            problemCellSet.write();
+        }
+    }
+
+    syncTools::syncPointList
+    (
+        mesh_,
+        isBoundaryPoint,
+        orEqOp<bool>(),
+        false,              // null value
+        false               // no separation
+    );
+
+    syncTools::syncEdgeList
+    (
+        mesh_,
+        isBoundaryEdge,
+        orEqOp<bool>(),
+        false,              // null value
+        false               // no separation
+    );
+
+    syncTools::syncFaceList
+    (
+        mesh_,
+        isBoundaryFace,
+        orEqOp<bool>(),
+        false               // no separation
+    );
+
+
+    // For each cell count the number of anchor points that are on
+    // the boundary:
+    // 8 : check the number of (baffle) boundary faces. If 3 or more block
+    //     off the cell since the cell would get squeezed down to a diamond
+    //     (probably; if the 3 or more faces are unrefined (only use the
+    //      anchor points))
+    // 7 : store. Used to check later on whether there are points with
+    //     3 or more of these cells. (note that on a flat surface a boundary
+    //     point will only have 4 cells connected to it)
+
+    // Does cell have exactly 7 of its 8 anchor points on the boundary?
+    PackedList<1> hasSevenBoundaryAnchorPoints(mesh_.nCells(), 0u);
+    // If so what is the remaining non-boundary anchor point?
+    labelHashSet nonBoundaryAnchors(mesh_.nCells()/10000);
+
+    // On-the-fly addressing storage.
+    DynamicList<label> dynFEdges;
+    DynamicList<label> dynCPoints;
+
+    forAll(cellLevel, cellI)
+    {
+        const labelList& cPoints = mesh_.cellPoints(cellI, dynCPoints);
+
+        // Get number of anchor points (pointLevel == cellLevel)
+
+        label nBoundaryAnchors = 0;
+        label nNonAnchorBoundary = 0;
+        label nonBoundaryAnchor = -1;
+
+        forAll(cPoints, i)
+        {
+            label pointI = cPoints[i];
+
+            if (pointLevel[pointI] <= cellLevel[cellI])
+            {
+                // Anchor point
+                if (isBoundaryPoint[pointI])
+                {
+                    nBoundaryAnchors++;
+                }
+                else
+                {
+                    // Anchor point which is not on the surface
+                    nonBoundaryAnchor = pointI;
+                }
+            }
+            else if (isBoundaryPoint[pointI])
+            {
+                nNonAnchorBoundary++;
+            }
+        }
+
+        if (nBoundaryAnchors == 8)
+        {
+            const cell& cFaces = mesh_.cells()[cellI];
+
+            // Count boundary faces.
+            label nBfaces = 0;
+
+            forAll(cFaces, cFaceI)
+            {
+                if (isBoundaryFace[cFaces[cFaceI]])
+                {
+                    nBfaces++;
+                }
+            }
+
+            // If nBfaces > 1 make all non-boundary non-baffle faces baffles.
+            // We assume that this situation is where there is a single
+            // cell sticking out which would get flattened.
+
+            // Eugene: delete cell no matter what.
+            //if (nBfaces > 1)
+            {
+                forAll(cFaces, cf)
+                {
+                    label faceI = cFaces[cf];
+
+                    if (facePatch[faceI] == -1 && mesh_.isInternalFace(faceI))
+                    {
+                        facePatch[faceI] = getBafflePatch(facePatch, faceI);
+                        nBaffleFaces++;
+
+                        // Mark face as a 'boundary'
+                        markBoundaryFace
+                        (
+                            faceI,
+                            isBoundaryFace,
+                            isBoundaryEdge,
+                            isBoundaryPoint
+                        );
+                    }
+                }
+            }
+        }
+        else if (nBoundaryAnchors == 7)
+        {
+            // Mark the cell. Store the (single!) non-boundary anchor point.
+            hasSevenBoundaryAnchorPoints.set(cellI, 1u);
+            nonBoundaryAnchors.insert(nonBoundaryAnchor);
+        }
+    }
+
+
+    // Loop over all points. If a point is connected to 4 or more cells
+    // with 7 anchor points on the boundary set those cell's non-boundary faces
+    // to baffles
+
+    DynamicList<label> dynPCells;
+
+    forAllConstIter(labelHashSet, nonBoundaryAnchors, iter)
+    {
+        label pointI = iter.key();
+
+        const labelList& pCells = mesh_.pointCells(pointI, dynPCells);
+
+        // Count number of 'hasSevenBoundaryAnchorPoints' cells.
+        label n = 0;
+
+        forAll(pCells, i)
+        {
+            if (hasSevenBoundaryAnchorPoints.get(pCells[i]) == 1u)
+            {
+                n++;
+            }
+        }
+
+        if (n > 3)
+        {
+            // Point in danger of being what? Remove all 7-cells.
+            forAll(pCells, i)
+            {
+                label cellI = pCells[i];
+
+                if (hasSevenBoundaryAnchorPoints.get(cellI) == 1u)
+                {
+                    const cell& cFaces = mesh_.cells()[cellI];
+
+                    forAll(cFaces, cf)
+                    {
+                        label faceI = cFaces[cf];
+
+                        if
+                        (
+                            facePatch[faceI] == -1
+                         && mesh_.isInternalFace(faceI)
+                        )
+                        {
+                            facePatch[faceI] = getBafflePatch(facePatch, faceI);
+                            nBaffleFaces++;
+
+                            // Mark face as a 'boundary'
+                            markBoundaryFace
+                            (
+                                faceI,
+                                isBoundaryFace,
+                                isBoundaryEdge,
+                                isBoundaryPoint
+                            );
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+
+    // Sync all. (note that pointdata and facedata not used anymore but sync
+    // anyway)
+
+    syncTools::syncPointList
+    (
+        mesh_,
+        isBoundaryPoint,
+        orEqOp<bool>(),
+        false,              // null value
+        false               // no separation
+    );
+
+    syncTools::syncEdgeList
+    (
+        mesh_,
+        isBoundaryEdge,
+        orEqOp<bool>(),
+        false,              // null value
+        false               // no separation
+    );
+
+    syncTools::syncFaceList
+    (
+        mesh_,
+        isBoundaryFace,
+        orEqOp<bool>(),
+        false               // no separation
+    );
+
+
+    // Find faces with all edges on the boundary and make them baffles
+    for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
+    {
+        if (facePatch[faceI] == -1)
+        {
+            const labelList& fEdges = mesh_.faceEdges(faceI, dynFEdges);
+            label nFaceBoundaryEdges = 0;
+
+            forAll(fEdges, fe)
+            {
+                if (isBoundaryEdge[fEdges[fe]])
+                {
+                    nFaceBoundaryEdges++;
+                }
+            }
+
+            if (nFaceBoundaryEdges == fEdges.size())
+            {
+                facePatch[faceI] = getBafflePatch(facePatch, faceI);
+                nBaffleFaces++;
+
+                // Do NOT update boundary data since this would grow blocked
+                // faces across gaps.
+            }
+        }
+    }
+
+    forAll(patches, patchI)
+    {
+        const polyPatch& pp = patches[patchI];
+
+        if (pp.coupled())
+        {
+            label faceI = pp.start();
+
+            forAll(pp, i)
+            {
+                if (facePatch[faceI] == -1)
+                {
+                    const labelList& fEdges = mesh_.faceEdges(faceI, dynFEdges);
+                    label nFaceBoundaryEdges = 0;
+
+                    forAll(fEdges, fe)
+                    {
+                        if (isBoundaryEdge[fEdges[fe]])
+                        {
+                            nFaceBoundaryEdges++;
+                        }
+                    }
+
+                    if (nFaceBoundaryEdges == fEdges.size())
+                    {
+                        facePatch[faceI] = getBafflePatch(facePatch, faceI);
+                        nBaffleFaces++;
+
+                        // Do NOT update boundary data since this would grow
+                        // blocked faces across gaps.
+                    }
+                }
+
+                faceI++;
+            }
+        }
+    }
+
+    Info<< "markFacesOnProblemCells : marked "
+        << returnReduce(nBaffleFaces, sumOp<label>())
+        << " additional internal faces to be converted into baffles."
+        << endl;
+
+    return facePatch;
+}
+//XXXXXXXXXXXXXX
+// Mark faces to be baffled to prevent snapping problems. Does
+// test to find nearest surface and checks which faces would get squashed.
+Foam::labelList Foam::meshRefinement::markFacesOnProblemCellsGeometric
+(
+    const dictionary& motionDict,
+    const labelList& globalToPatch
+) const
+{
+    // Get the labels of added patches.
+    labelList adaptPatchIDs(meshRefinement::addedPatches(globalToPatch));
+
+    // Construct addressing engine.
+    autoPtr<indirectPrimitivePatch> ppPtr
+    (
+        meshRefinement::makePatch
+        (
+            mesh_,
+            adaptPatchIDs
+        )
+    );
+    const indirectPrimitivePatch& pp = ppPtr();
+    const pointField& localPoints = pp.localPoints();
+    const labelList& meshPoints = pp.meshPoints();
+
+    // Find nearest (non-baffle) surface
+    pointField newPoints(mesh_.points());
+    {
+        List<pointIndexHit> hitInfo;
+        labelList hitSurface;
+        surfaces_.findNearest
+        (
+            surfaces_.getUnnamedSurfaces(),
+            localPoints,
+            scalarField(localPoints.size(), sqr(GREAT)),    // sqr of attraction
+            hitSurface,
+            hitInfo
+        );
+    
+        forAll(hitInfo, i)
+        {
+            if (hitInfo[i].hit())
+            {
+                //label pointI = meshPoints[i];
+                //Pout<< "   " << pointI << " moved from "
+                //    << mesh_.points()[pointI] << " by "
+                //    << mag(hitInfo[i].hitPoint()-mesh_.points()[pointI])
+                //    << endl;
+                newPoints[meshPoints[i]] = hitInfo[i].hitPoint();
+            }
+        }
+    }
+
+    // Per face (internal or coupled!) the patch that the
+    // baffle should get (or -1).
+    labelList facePatch(mesh_.nFaces(), -1);
+    // Count of baffled faces
+    label nBaffleFaces = 0;
+
+
+//    // Sync position? Or not since same face on both side so just sync
+//    // result of baffle.
+//
+//    const scalar minArea(readScalar(motionDict.lookup("minArea")));
+//
+//    Pout<< "markFacesOnProblemCellsGeometric : Comparing to minArea:"
+//        << minArea << endl;
+//
+//    pointField facePoints;
+//    for (label faceI = mesh_.nInternalFaces(); faceI < mesh_.nFaces(); faceI++)
+//    {
+//        const face& f = mesh_.faces()[faceI];
+//
+//        bool usesPatchPoint = false;
+//
+//        facePoints.setSize(f.size());
+//        forAll(f, fp)
+//        {
+//            Map<label>::const_iterator iter = pp.meshPointMap().find(f[fp]);
+//
+//            if (iter != pp.meshPointMap().end())
+//            {
+//                facePoints[fp] = newPosition[iter()];
+//                usesPatchPoint = true;
+//            }
+//            else
+//            {
+//                facePoints[fp] = mesh_.points()[f[fp]];
+//            }
+//        }
+//
+//        if (usesPatchPoint)
+//        {
+//            // Check area of face wrt original area
+//            face identFace(identity(f.size()));
+//
+//            if (identFace.mag(facePoints) < minArea)
+//            {
+//                facePatch[faceI] = getBafflePatch(facePatch, faceI);
+//                nBaffleFaces++;
+//            }
+//        }
+//    }
+//
+//
+//    const polyBoundaryMesh& patches = mesh_.boundaryMesh();
+//    forAll(patches, patchI)
+//    {
+//        const polyPatch& pp = patches[patchI];
+//
+//        if (pp.coupled())
+//        {
+//            forAll(pp, i)
+//            {
+//                label faceI = pp.start()+i;
+//
+//                const face& f = mesh_.faces()[faceI];
+//
+//                bool usesPatchPoint = false;
+//
+//                facePoints.setSize(f.size());
+//                forAll(f, fp)
+//                {
+//                    Map<label>::const_iterator iter =
+//                        pp.meshPointMap().find(f[fp]);
+//
+//                    if (iter != pp.meshPointMap().end())
+//                    {
+//                        facePoints[fp] = newPosition[iter()];
+//                        usesPatchPoint = true;
+//                    }
+//                    else
+//                    {
+//                        facePoints[fp] = mesh_.points()[f[fp]];
+//                    }
+//                }
+//
+//                if (usesPatchPoint)
+//                {
+//                    // Check area of face wrt original area
+//                    face identFace(identity(f.size()));
+//
+//                    if (identFace.mag(facePoints) < minArea)
+//                    {
+//                        facePatch[faceI] = getBafflePatch(facePatch, faceI);
+//                        nBaffleFaces++;
+//                    }
+//                }
+//            }
+//        }
+//    }
+
+    {
+        pointField oldPoints(mesh_.points());
+        mesh_.movePoints(newPoints);
+        faceSet wrongFaces(mesh_, "wrongFaces", 100);
+        {
+            //motionSmoother::checkMesh(false, mesh_, motionDict, wrongFaces);
+
+            // Just check the errors from squashing
+            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+            const labelList allFaces(identity(mesh_.nFaces()));
+            label nWrongFaces = 0;
+
+            scalar minArea(readScalar(motionDict.lookup("minArea")));
+            if (minArea > -SMALL)
+            {
+                polyMeshGeometry::checkFaceArea
+                (
+                    false,
+                    minArea,
+                    mesh_,
+                    mesh_.faceAreas(),
+                    allFaces,
+                    &wrongFaces
+                );
+
+                label nNewWrongFaces = returnReduce
+                (
+                    wrongFaces.size(),
+                    sumOp<label>()
+                );
+
+                Info<< "    faces with area < "
+                    << setw(5) << minArea
+                    << " m^2                            : "
+                    << nNewWrongFaces-nWrongFaces << endl;
+
+                nWrongFaces = nNewWrongFaces;
+            }
+
+//            scalar minDet(readScalar(motionDict.lookup("minDeterminant")));
+            scalar minDet = 0.01;
+            if (minDet > -1)
+            {
+                polyMeshGeometry::checkCellDeterminant
+                (
+                    false,
+                    minDet,
+                    mesh_,
+                    mesh_.faceAreas(),
+                    allFaces,
+                    polyMeshGeometry::affectedCells(mesh_, allFaces),
+                    &wrongFaces
+                );
+
+                label nNewWrongFaces = returnReduce
+                (
+                    wrongFaces.size(),
+                    sumOp<label>()
+                );
+
+                Info<< "    faces on cells with determinant < "
+                    << setw(5) << minDet << "                : "
+                    << nNewWrongFaces-nWrongFaces << endl;
+
+                nWrongFaces = nNewWrongFaces;
+            }
+        }
+
+
+        forAllConstIter(faceSet, wrongFaces, iter)
+        {
+            label patchI = mesh_.boundaryMesh().whichPatch(iter.key());
+
+            if (patchI == -1 || mesh_.boundaryMesh()[patchI].coupled())
+            {
+                facePatch[iter.key()] = getBafflePatch(facePatch, iter.key());
+                nBaffleFaces++;
+
+                //Pout<< "    " << iter.key()
+                //    //<< " on patch " << mesh_.boundaryMesh()[patchI].name()
+                //    << " is destined for patch " << facePatch[iter.key()]
+                //    << endl;
+            }
+        }
+        // Restore points.
+        mesh_.movePoints(oldPoints);
+    }
+
+
+    Info<< "markFacesOnProblemCellsGeometric : marked "
+        << returnReduce(nBaffleFaces, sumOp<label>())
+        << " additional internal and coupled faces"
+        << " to be converted into baffles." << endl;
+
+    syncTools::syncFaceList
+    (
+        mesh_,
+        facePatch,
+        maxEqOp<label>(),
+        false               // no separation
+    );
+
+    return facePatch;
+}
+//XXXXXXXX
+
+
+// ************************************************************************* //
diff --git a/src/autoMesh/autoHexMesh/refinementSurfaces/refinementSurfaces.C b/src/autoMesh/autoHexMesh/refinementSurfaces/refinementSurfaces.C
index 06944d6c59f92ddb28631eb21e5c6022a7de007c..bf728dfe48770558c41b8e4c9d96457e4a81b4c8 100644
--- a/src/autoMesh/autoHexMesh/refinementSurfaces/refinementSurfaces.C
+++ b/src/autoMesh/autoHexMesh/refinementSurfaces/refinementSurfaces.C
@@ -53,8 +53,10 @@ Foam::refinementSurfaces::refinementSurfaces
 {
     labelList globalMinLevel(surfaceDicts.size(), 0);
     labelList globalMaxLevel(surfaceDicts.size(), 0);
+    scalarField globalAngle(surfaceDicts.size(), -GREAT);
     List<Map<label> > regionMinLevel(surfaceDicts.size());
     List<Map<label> > regionMaxLevel(surfaceDicts.size());
+    List<Map<scalar> > regionAngle(surfaceDicts.size());
 
     //wordList globalPatchType(surfaceDicts.size());
     //List<HashTable<word> > regionPatchType(surfaceDicts.size());
@@ -80,6 +82,12 @@ Foam::refinementSurfaces::refinementSurfaces
             dict.lookup("zoneInside") >> zoneInside_[surfI];
         }
 
+        // Global perpendicular angle
+        if (dict.found("perpendicularAngle"))
+        {
+            globalAngle[surfI] = readScalar(dict.lookup("perpendicularAngle"));
+        }
+
         //// Global patch name per surface
         //if (dict.found("patchType"))
         //{
@@ -130,6 +138,15 @@ Foam::refinementSurfaces::refinementSurfaces
                         << exit(FatalError);
                 }
                 regionMaxLevel[surfI].insert(regionI, max);
+
+                if (regionDict.found("perpendicularAngle"))
+                {
+                    regionAngle[surfI].insert
+                    (
+                        regionI,
+                        readScalar(regionDict.lookup("perpendicularAngle"))
+                    );
+                }
             }
         }
     }
@@ -170,6 +187,8 @@ Foam::refinementSurfaces::refinementSurfaces
     minLevel_ = 0;
     maxLevel_.setSize(nRegions);
     maxLevel_ = 0;
+    perpendicularAngle_.setSize(nRegions);
+    perpendicularAngle_ = -GREAT;
     //patchName_.setSize(nRegions);
     //patchType_.setSize(nRegions);
 
@@ -182,6 +201,7 @@ Foam::refinementSurfaces::refinementSurfaces
         {
             minLevel_[regionOffset_[surfI] + i] = globalMinLevel[surfI];
             maxLevel_[regionOffset_[surfI] + i] = globalMaxLevel[surfI];
+            perpendicularAngle_[regionOffset_[surfI] + i] = globalAngle[surfI];
         }
 
         // Overwrite with region specific information
@@ -191,6 +211,7 @@ Foam::refinementSurfaces::refinementSurfaces
 
             minLevel_[globalRegionI] = iter();
             maxLevel_[globalRegionI] = regionMaxLevel[surfI][iter.key()];
+            perpendicularAngle_[globalRegionI] = regionAngle[surfI][iter.key()];
 
             // Check validity
             if
@@ -240,8 +261,10 @@ Foam::refinementSurfaces::refinementSurfaces
 {
     labelList globalMinLevel(surfacesDict.size(), 0);
     labelList globalMaxLevel(surfacesDict.size(), 0);
+    scalarField globalAngle(surfacesDict.size(), -GREAT);
     List<Map<label> > regionMinLevel(surfacesDict.size());
     List<Map<label> > regionMaxLevel(surfacesDict.size());
+    List<Map<scalar> > regionAngle(surfacesDict.size());
 
     label surfI = 0;
     forAllConstIter(dictionary, surfacesDict, iter)
@@ -274,6 +297,12 @@ Foam::refinementSurfaces::refinementSurfaces
             dict.lookup("zoneInside") >> zoneInside_[surfI];
         }
 
+        // Global perpendicular angle
+        if (dict.found("perpendicularAngle"))
+        {
+            globalAngle[surfI] = readScalar(dict.lookup("perpendicularAngle"));
+        }
+
         if (dict.found("regions"))
         {
             const dictionary& regionsDict = dict.subDict("regions");
@@ -306,6 +335,15 @@ Foam::refinementSurfaces::refinementSurfaces
 
                     regionMinLevel[surfI].insert(regionI, refLevel[0]);
                     regionMaxLevel[surfI].insert(regionI, refLevel[1]);
+
+                    if (regionDict.found("perpendicularAngle"))
+                    {
+                        regionAngle[surfI].insert
+                        (
+                            regionI,
+                            readScalar(regionDict.lookup("perpendicularAngle"))
+                        );
+                    }
                 }
             }
         }
@@ -326,6 +364,8 @@ Foam::refinementSurfaces::refinementSurfaces
     minLevel_ = 0;
     maxLevel_.setSize(nRegions);
     maxLevel_ = 0;
+    perpendicularAngle_.setSize(nRegions);
+    perpendicularAngle_ = -GREAT;
 
 
     forAll(globalMinLevel, surfI)
@@ -337,6 +377,7 @@ Foam::refinementSurfaces::refinementSurfaces
         {
             minLevel_[regionOffset_[surfI] + i] = globalMinLevel[surfI];
             maxLevel_[regionOffset_[surfI] + i] = globalMaxLevel[surfI];
+            perpendicularAngle_[regionOffset_[surfI] + i] = globalAngle[surfI];
         }
 
         // Overwrite with region specific information
@@ -346,6 +387,7 @@ Foam::refinementSurfaces::refinementSurfaces
 
             minLevel_[globalRegionI] = iter();
             maxLevel_[globalRegionI] = regionMaxLevel[surfI][iter.key()];
+            perpendicularAngle_[globalRegionI] = regionAngle[surfI][iter.key()];
 
             // Check validity
             if
@@ -454,8 +496,6 @@ void Foam::refinementSurfaces::setMinLevelFields
     const shellSurfaces& shells
 )
 {
-    //minLevelFields_.setSize(surfaces_.size());
-
     forAll(surfaces_, surfI)
     {
         const searchableSurface& geom = allGeometry_[surfaces_[surfI]];
diff --git a/src/autoMesh/autoHexMesh/refinementSurfaces/refinementSurfaces.H b/src/autoMesh/autoHexMesh/refinementSurfaces/refinementSurfaces.H
index 83ccec6152e374779f65ebeb330aad435d90e56b..e9adef8e5f4f9be17097b3ba65d12a395d4b17b8 100644
--- a/src/autoMesh/autoHexMesh/refinementSurfaces/refinementSurfaces.H
+++ b/src/autoMesh/autoHexMesh/refinementSurfaces/refinementSurfaces.H
@@ -90,6 +90,9 @@ class refinementSurfaces
         //- From global region number to refinement level
         labelList maxLevel_;
 
+        //- From global region number to perpendicular angle
+        scalarField perpendicularAngle_;
+
 
     // Private Member Functions
 
@@ -178,6 +181,12 @@ public:
                 return maxLevel_;
             }
 
+            //- From global region number to perpendicular angle
+            const scalarField& perpendicularAngle() const
+            {
+                return perpendicularAngle_;
+            }
+
 
         // Helper
 
diff --git a/src/autoMesh/autoHexMesh/shellSurfaces/shellSurfaces.C b/src/autoMesh/autoHexMesh/shellSurfaces/shellSurfaces.C
index 60a6c51e73c0b06146dfb1aa7a1b2c66034f5125..492ceaa58e26ad6527fc7db9d11e3c91d23cb141 100644
--- a/src/autoMesh/autoHexMesh/shellSurfaces/shellSurfaces.C
+++ b/src/autoMesh/autoHexMesh/shellSurfaces/shellSurfaces.C
@@ -59,7 +59,7 @@ const NamedEnum<shellSurfaces::refineMode, 3> shellSurfaces::refineModeNames_;
 
 void Foam::shellSurfaces::setAndCheckLevels
 (
-    const scalar shellI,
+    const label shellI,
     const List<Tuple2<scalar, label> >& distLevels
 )
 {
diff --git a/src/autoMesh/autoHexMesh/shellSurfaces/shellSurfaces.H b/src/autoMesh/autoHexMesh/shellSurfaces/shellSurfaces.H
index d993735a70d1df28b16dc0535d8d4463626613f9..ce62de2bd597e59cd8c1cefa5ba5d222d4c30695 100644
--- a/src/autoMesh/autoHexMesh/shellSurfaces/shellSurfaces.H
+++ b/src/autoMesh/autoHexMesh/shellSurfaces/shellSurfaces.H
@@ -97,7 +97,7 @@ private:
         //- Helper function for initialisation.
         void setAndCheckLevels
         (
-            const scalar shellI,
+            const label shellI,
             const List<Tuple2<scalar, label> >&
         );
 
diff --git a/src/dynamicMesh/polyMeshAdder/polyMeshAdder.C b/src/dynamicMesh/polyMeshAdder/polyMeshAdder.C
index 317a365c91874cfe34ef40e24ede7ce1248f8d98..e8366ec3cb57d576edcc9251a637fd52fc18cb6c 100644
--- a/src/dynamicMesh/polyMeshAdder/polyMeshAdder.C
+++ b/src/dynamicMesh/polyMeshAdder/polyMeshAdder.C
@@ -61,6 +61,29 @@ void Foam::polyMeshAdder::append
 }
 
 
+//- Append all mapped elements of a list to a DynamicList
+void Foam::polyMeshAdder::append
+(
+    const labelList& map,
+    const labelList& lst,
+    const SortableList<label>& sortedLst,
+    DynamicList<label>& dynLst
+)
+{
+    dynLst.setSize(dynLst.size() + lst.size());
+
+    forAll(lst, i)
+    {
+        label newElem = map[lst[i]];
+
+        if (newElem != -1 && findSortedIndex(sortedLst, newElem) == -1)
+        {
+            dynLst.append(newElem);
+        }
+    }
+}
+
+
 // Get index of patch in new set of patchnames/types
 Foam::label Foam::polyMeshAdder::patchIndex
 (
@@ -919,22 +942,33 @@ void Foam::polyMeshAdder::mergePointZones
 
     forAll(pz0, zoneI)
     {
-        DynamicList<label>& newZone = pzPoints[zoneI];
-
-        newZone.setCapacity(pz0[zoneI].size());
+        append(from0ToAllPoints, pz0[zoneI], pzPoints[zoneI]);
+    }
 
-        append(from0ToAllPoints, pz0[zoneI], newZone);
+    // Get sorted zone contents for duplicate element recognition
+    PtrList<SortableList<label> > pzPointsSorted(pzPoints.size());
+    forAll(pzPoints, zoneI)
+    {
+        pzPointsSorted.set
+        (
+            zoneI,
+            new SortableList<label>(pzPoints[zoneI])
+        );
     }
 
     // Now we have full addressing for points so do the pointZones of mesh1.
     forAll(pz1, zoneI)
     {
         // Relabel all points of zone and add to correct pzPoints.
-        DynamicList<label>& newZone = pzPoints[from1ToAll[zoneI]];
+        label allZoneI = from1ToAll[zoneI];
 
-        newZone.setCapacity(newZone.size() + pz1[zoneI].size());
-
-        append(from1ToAllPoints, pz1[zoneI], newZone);
+        append
+        (
+            from1ToAllPoints,
+            pz1[zoneI],
+            pzPointsSorted[allZoneI],
+            pzPoints[allZoneI]
+        );
     }
 
     forAll(pzPoints, i)
@@ -996,11 +1030,25 @@ void Foam::polyMeshAdder::mergeFaceZones
         }
     }
 
+    // Get sorted zone contents for duplicate element recognition
+    PtrList<SortableList<label> > fzFacesSorted(fzFaces.size());
+    forAll(fzFaces, zoneI)
+    {
+        fzFacesSorted.set
+        (
+            zoneI,
+            new SortableList<label>(fzFaces[zoneI])
+        );
+    }
+
     // Now we have full addressing for faces so do the faceZones of mesh1.
     forAll(fz1, zoneI)
     {
-        DynamicList<label>& newZone = fzFaces[from1ToAll[zoneI]];
-        DynamicList<bool>& newFlip = fzFlips[from1ToAll[zoneI]];
+        label allZoneI = from1ToAll[zoneI];
+
+        DynamicList<label>& newZone = fzFaces[allZoneI];
+        const SortableList<label>& newZoneSorted = fzFacesSorted[allZoneI];
+        DynamicList<bool>& newFlip = fzFlips[allZoneI];
 
         newZone.setCapacity(newZone.size() + fz1[zoneI].size());
         newFlip.setCapacity(newZone.size());
@@ -1011,10 +1059,15 @@ void Foam::polyMeshAdder::mergeFaceZones
         forAll(addressing, i)
         {
             label faceI = addressing[i];
+            label allFaceI = from1ToAllFaces[faceI];
 
-            if (from1ToAllFaces[faceI] != -1)
+            if
+            (
+                allFaceI != -1
+             && findSortedIndex(newZoneSorted, allFaceI) == -1
+            )
             {
-                newZone.append(from1ToAllFaces[faceI]);
+                newZone.append(allFaceI);
                 newFlip.append(flipMap[i]);
             }
         }
@@ -1055,7 +1108,6 @@ void Foam::polyMeshAdder::mergeCellZones
     czCells.setSize(zoneNames.size());
     forAll(cz0, zoneI)
     {
-        czCells[zoneI].setCapacity(cz0[zoneI].size());
         // Insert mesh0 cells
         append(cz0[zoneI], czCells[zoneI]);
     }
@@ -1064,11 +1116,9 @@ void Foam::polyMeshAdder::mergeCellZones
     // Cell mapping is trivial.
     forAll(cz1, zoneI)
     {
-        DynamicList<label>& newZone = czCells[from1ToAll[zoneI]];
-
-        newZone.setCapacity(newZone.size() + cz1[zoneI].size());
+        label allZoneI = from1ToAll[zoneI];
 
-        append(from1ToAllCells, cz1[zoneI], newZone);
+        append(from1ToAllCells, cz1[zoneI], czCells[allZoneI]);
     }
 
     forAll(czCells, i)
diff --git a/src/dynamicMesh/polyMeshAdder/polyMeshAdder.H b/src/dynamicMesh/polyMeshAdder/polyMeshAdder.H
index 2fb3b52ea09a07072ba1c3ece94a221ad1a96192..8d5a04c780e9a065709593e448d1c2751f246021 100644
--- a/src/dynamicMesh/polyMeshAdder/polyMeshAdder.H
+++ b/src/dynamicMesh/polyMeshAdder/polyMeshAdder.H
@@ -29,7 +29,7 @@ Description
     Adds two meshes without using any polyMesh morphing.
 
     Gets faces to couple as faceCoupleInfo which is list of faces on both
-    meshes. Holds map from last mesh addition.
+    meshes. Returns map from last mesh addition.
 
 SourceFiles
     polyMeshAdder.C
@@ -43,6 +43,7 @@ SourceFiles
 #include "polyMesh.H"
 #include "mapAddedPolyMesh.H"
 #include "faceCoupleInfo.H"
+#include "SortableList.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
@@ -78,6 +79,16 @@ private:
             DynamicList<label>&
         );
 
+        //- Append all mapped elements of a list to a DynamicList that are
+        //  not already present in the sorted list.
+        static void append
+        (
+            const labelList& map,
+            const labelList& lst,
+            const SortableList<label>& sortedLst,
+            DynamicList<label>&
+        );
+
         //- Index of patch in allPatches. Add if nonexisting.
         static label patchIndex
         (
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/turbulentInlet/turbulentInletFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/turbulentInlet/turbulentInletFvPatchField.C
index 67a78e783da297acf16990506e8747cc04bceece..36d8d744d7f478ae34c9282ec56c3a725cb65146 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/turbulentInlet/turbulentInletFvPatchField.C
+++ b/src/finiteVolume/fields/fvPatchFields/derived/turbulentInlet/turbulentInletFvPatchField.C
@@ -175,9 +175,8 @@ void turbulentInletFvPatchField<Type>::updateCoeffs()
             ranGen_.randomise(randomField[facei]);
         }
 
-        // Correction-factor proposed by Yi Wang to compensate for the loss
-        // of RMS fluctuation due to the temporal correlation introduced by
-        // the alpha parameter.
+        // Correction-factor to compensate for the loss of RMS fluctuation
+        // due to the temporal correlation introduced by the alpha parameter.
         scalar rmsCorr = sqrt(12*(2*alpha_ - sqr(alpha_)))/alpha_;
 
         patchField =
@@ -206,6 +205,7 @@ void turbulentInletFvPatchField<Type>::write(Ostream& os) const
     os.writeKeyword("fluctuationScale")
         << fluctuationScale_ << token::END_STATEMENT << nl;
     referenceField_.writeEntry("referenceField", os);
+    os.writeKeyword("alpha") << alpha_ << token::END_STATEMENT << nl;
     this->writeEntry("value", os);
 }
 
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/turbulentInlet/turbulentInletFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/turbulentInlet/turbulentInletFvPatchField.H
index 8b4cfabf66314f042f4b27454566d707dcadba44..1f9dda159e3d64b47b4aaa0a372ca2e8f0af2491 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/turbulentInlet/turbulentInletFvPatchField.H
+++ b/src/finiteVolume/fields/fvPatchFields/derived/turbulentInlet/turbulentInletFvPatchField.H
@@ -63,7 +63,6 @@ class turbulentInletFvPatchField
 :
     public fixedValueFvPatchField<Type>
 {
-
     // Private data
 
         Random ranGen_;
diff --git a/src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloud.C b/src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloud.C
index c2bd6f84fb5bf8603afc23b164487d028728cbf0..cfd9bef85795be976dadee3f4738eb376dee8f12 100644
--- a/src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloud.C
+++ b/src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloud.C
@@ -35,65 +35,6 @@ License
 
 // * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * * //
 
-template<class ParcelType>
-void Foam::KinematicCloud<ParcelType>::setInjectorCellAndPosition
-(
-    label& pCell,
-    vector& pPosition
-)
-{
-    const vector originalPosition = pPosition;
-
-    bool foundCell = false;
-
-    pCell = mesh_.findCell(pPosition);
-
-    if (pCell >= 0)
-    {
-        const vector& C = mesh_.C()[pCell];
-        pPosition += 1.0e-6*(C - pPosition);
-
-        foundCell = mesh_.pointInCell
-        (
-            pPosition,
-            pCell
-        );
-    }
-    reduce(foundCell, orOp<bool>());
-
-    // Last chance - find nearest cell and try that one
-    // - the point is probably on an edge
-    if (!foundCell)
-    {
-        pCell =  mesh_.findNearestCell(pPosition);
-
-        if (pCell >= 0)
-        {
-            const vector& C = mesh_.C()[pCell];
-            pPosition += 1.0e-6*(C - pPosition);
-
-            foundCell = mesh_.pointInCell
-            (
-                pPosition,
-                pCell
-            );
-        }
-        reduce(foundCell, orOp<bool>());
-    }
-
-    if (!foundCell)
-    {
-        FatalErrorIn
-        (
-            "void KinematicCloud<ParcelType>::findInjectorCell"
-            "(label&, vector&)"
-        )<< "Cannot find parcel injection cell. "
-         << "Parcel position = " << originalPosition << nl
-         << abort(FatalError);
-    }
-}
-
-
 template<class ParcelType>
 Foam::scalar Foam::KinematicCloud<ParcelType>::setNumberOfParticles
 (
@@ -324,7 +265,7 @@ void Foam::KinematicCloud<ParcelType>::evolve()
         g_.value()
     );
 
-    inject(td);
+    inject();
 
     if (coupled_)
     {
@@ -336,15 +277,11 @@ void Foam::KinematicCloud<ParcelType>::evolve()
 
 
 template<class ParcelType>
-template<class TrackingData>
-void Foam::KinematicCloud<ParcelType>::inject
-(
-    TrackingData& td
-)
+void Foam::KinematicCloud<ParcelType>::inject()
 {
     scalar time = this->db().time().value();
 
-    scalar pRho = td.constProps().rho0();
+    scalar pRho = constProps_.rho0();
 
     this->injection().prepareForNextTimeStep(time0_, time);
 
@@ -419,21 +356,21 @@ void Foam::KinematicCloud<ParcelType>::inject
 
         // Determine the injection cell
         label pCell = -1;
-        setInjectorCellAndPosition(pCell, pPosition);
+        this->injection().findInjectorCellAndPosition(pCell, pPosition);
 
         if (pCell >= 0)
         {
             // construct the parcel that is to be injected
             ParcelType* pPtr = new ParcelType
             (
-                td.cloud(),
+                *this,
                 parcelTypeId_,
                 pPosition,
                 pCell,
                 pDiameter,
                 pU,
                 pNumberOfParticles,
-                td.constProps()
+                constProps_
             );
 
             scalar dt = time - timeInj;
@@ -441,7 +378,7 @@ void Foam::KinematicCloud<ParcelType>::inject
             pPtr->stepFraction() = (this->db().time().deltaT().value() - dt)
                 /this->time().deltaT().value();
 
-            this->injectParcel(td, pPtr);
+            this->injectParcel(pPtr);
          }
     }
 
@@ -455,12 +392,7 @@ void Foam::KinematicCloud<ParcelType>::inject
 
 
 template<class ParcelType>
-template<class TrackingData>
-void Foam::KinematicCloud<ParcelType>::injectParcel
-(
-    TrackingData& td,
-    ParcelType* p
-)
+void Foam::KinematicCloud<ParcelType>::injectParcel(ParcelType* p)
 {
     addParticle(p);
     nParcelsAdded_++;
diff --git a/src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloud.H b/src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloud.H
index 780b4ccd7ddddee29e862d158ce8df20fd5a3a8a..252d16a0f1e52e771fd6417591ecdccc2dbda916 100644
--- a/src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloud.H
+++ b/src/lagrangian/intermediate/clouds/Templates/KinematicCloud/KinematicCloud.H
@@ -223,13 +223,6 @@ protected:
 
     // Protected member functions
 
-        //- Set parcel position and cell into which parcel is introduced
-        void setInjectorCellAndPosition
-        (
-            label& pCell,
-            vector& pPosition
-        );
-
         //- Set the number of particles per parcel
         scalar setNumberOfParticles
         (
@@ -241,16 +234,10 @@ protected:
         );
 
         //- Inject more parcels
-        template<class TrackingData>
-        void inject(TrackingData& td);
+        void inject();
 
         //- Inject parcel if it is valid - delete otherwise
-        template<class TrackingData>
-        void injectParcel
-        (
-            TrackingData& td,
-            ParcelType* p
-        );
+        void injectParcel(ParcelType* p);
 
         //- Post-injection checks
         void postInjectCheck();
diff --git a/src/lagrangian/intermediate/clouds/Templates/ReactingCloud/ReactingCloud.C b/src/lagrangian/intermediate/clouds/Templates/ReactingCloud/ReactingCloud.C
index 71da23599d51d0579aca031a23042c849294a80f..93f3bb4f19657054bb6252ad4f8ccdce6e65adce 100644
--- a/src/lagrangian/intermediate/clouds/Templates/ReactingCloud/ReactingCloud.C
+++ b/src/lagrangian/intermediate/clouds/Templates/ReactingCloud/ReactingCloud.C
@@ -174,7 +174,7 @@ void Foam::ReactingCloud<ParcelType>::evolve()
         this->g().value()
     );
 
-    inject(td);
+    inject();
 
     if (this->coupled())
     {
@@ -186,15 +186,11 @@ void Foam::ReactingCloud<ParcelType>::evolve()
 
 
 template<class ParcelType>
-template<class TrackingData>
-void Foam::ReactingCloud<ParcelType>::inject
-(
-    TrackingData& td
-)
+void Foam::ReactingCloud<ParcelType>::inject()
 {
     scalar time = this->db().time().value();
 
-    scalar pRho = td.constProps().rho0();
+    scalar pRho = this->constProps().rho0();
 
     this->injection().prepareForNextTimeStep(this->time0(), time);
 
@@ -269,14 +265,14 @@ void Foam::ReactingCloud<ParcelType>::inject
 
         // Determine the injection cell
         label pCell = -1;
-        this->setInjectorCellAndPosition(pCell, pPosition);
+        this->injection().findInjectorCellAndPosition(pCell, pPosition);
 
         if (pCell >= 0)
         {
             // construct the parcel that is to be injected
             ParcelType* pPtr = new ParcelType
             (
-                td.cloud(),
+                *this,
                 this->parcelTypeId(),
                 pPosition,
                 pCell,
@@ -287,7 +283,7 @@ void Foam::ReactingCloud<ParcelType>::inject
                 composition().YLiquid0(),
                 composition().YSolid0(),
                 composition().YMixture0(),
-                td.constProps()
+                this->constProps()
             );
 
             scalar dt = time - timeInj;
@@ -295,7 +291,7 @@ void Foam::ReactingCloud<ParcelType>::inject
             pPtr->stepFraction() = (this->db().time().deltaT().value() - dt)
                 /this->db().time().deltaT().value();
 
-            this->injectParcel(td, pPtr);
+            this->injectParcel(pPtr);
          }
     }
 
diff --git a/src/lagrangian/intermediate/clouds/Templates/ReactingCloud/ReactingCloud.H b/src/lagrangian/intermediate/clouds/Templates/ReactingCloud/ReactingCloud.H
index 34e50880251acbf498a8b005ab21e294d0e4e8bc..3e07ed56f84445b6a2dbb983b35be4b5c638af9d 100644
--- a/src/lagrangian/intermediate/clouds/Templates/ReactingCloud/ReactingCloud.H
+++ b/src/lagrangian/intermediate/clouds/Templates/ReactingCloud/ReactingCloud.H
@@ -117,8 +117,7 @@ class ReactingCloud
 protected:
 
     //- Inject more parcels
-    template<class TrackingData>
-    void inject(TrackingData& td);
+    void inject();
 
 
 public:
diff --git a/src/lagrangian/intermediate/submodels/IO/DataEntry/Table/Table.C b/src/lagrangian/intermediate/submodels/IO/DataEntry/Table/Table.C
index 40e7ec00870f291ce95da3276f91001be9da1b18..f7d5dff6ca2ba2cbfcf2624081a247d75a457212 100644
--- a/src/lagrangian/intermediate/submodels/IO/DataEntry/Table/Table.C
+++ b/src/lagrangian/intermediate/submodels/IO/DataEntry/Table/Table.C
@@ -78,11 +78,14 @@ Type Foam::Table<Type>::value(const scalar x) const
         i++;
     }
 
-    // Linear interpolation to find value
-    return
+    // Linear interpolation to find value. Note constructor needed for
+    // Table<label> to convert intermediate scalar back to label.
+    return Type
+    (
         (x - table_[i].first())/(table_[i+1].first() - table_[i].first())
       * (table_[i+1].second() - table_[i].second())
-      + table_[i].second();
+      + table_[i].second()
+    );
 }
 
 
diff --git a/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/InjectionModel/InjectionModel.C b/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/InjectionModel/InjectionModel.C
index 890e27353a8fc52d3d679aec5a9b7d997831a2da..465949a1209a17c0c4b5a5d31d7209ee36b8be58 100644
--- a/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/InjectionModel/InjectionModel.C
+++ b/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/InjectionModel/InjectionModel.C
@@ -159,6 +159,57 @@ void Foam::InjectionModel<CloudType>::prepareForNextTimeStep
 }
 
 
+template<class CloudType>
+void Foam::InjectionModel<CloudType>::findInjectorCellAndPosition
+(
+    label& cellI,
+    vector& position
+)
+{
+    const vector p0 = position;
+
+    bool foundCell = false;
+
+    cellI = owner_.mesh().findCell(position);
+
+    if (cellI >= 0)
+    {
+        const vector& C = owner_.mesh().C()[cellI];
+        position += 1.0e-6*(C - position);
+
+        foundCell = owner_.mesh().pointInCell(position, cellI);
+    }
+    reduce(foundCell, orOp<bool>());
+
+    // Last chance - find nearest cell and try that one
+    // - the point is probably on an edge
+    if (!foundCell)
+    {
+        cellI = owner_.mesh().findNearestCell(position);
+
+        if (cellI >= 0)
+        {
+            const vector& C = owner_.mesh().C()[cellI];
+            position += 1.0e-6*(C - position);
+
+            foundCell = owner_.mesh().pointInCell(position, cellI);
+        }
+        reduce(foundCell, orOp<bool>());
+    }
+
+    if (!foundCell)
+    {
+        FatalErrorIn
+        (
+            "InjectionModel<CloudType>::setInjectorCellAndPosition"
+            "(label&, vector&)"
+        )<< "Cannot find parcel injection cell. "
+         << "Parcel position = " << p0 << nl
+         << abort(FatalError);
+    }
+}
+
+
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 #include "NewInjectionModel.C"
diff --git a/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/InjectionModel/InjectionModel.H b/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/InjectionModel/InjectionModel.H
index 5431b1eec1a4417b39a6daaf541ac3bb1447d2b5..780aa2d776f104fe1d625abfc5ed5d41ffd669eb 100644
--- a/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/InjectionModel/InjectionModel.H
+++ b/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/InjectionModel/InjectionModel.H
@@ -208,6 +208,14 @@ public:
 
         // Injection geometry
 
+            //- Find the cell that contains the injector position
+            //  Will modify position slightly towards the owner cell centroid
+            virtual void findInjectorCellAndPosition
+            (
+                label& cellI,
+                vector& position
+            );
+
             //- Return the injection position
             virtual vector position
             (
diff --git a/src/lagrangian/molecularDynamics/potential/pairPotential/basic/pairPotential.C b/src/lagrangian/molecularDynamics/potential/pairPotential/basic/pairPotential.C
index bb850592f13021958d33803d07e375a4ee619306..d17c5c905440ccc1ae922c472e3c9b7373a5b372 100644
--- a/src/lagrangian/molecularDynamics/potential/pairPotential/basic/pairPotential.C
+++ b/src/lagrangian/molecularDynamics/potential/pairPotential/basic/pairPotential.C
@@ -98,7 +98,7 @@ Foam::scalar Foam::pairPotential::forceLookup(const scalar r) const
 {
     scalar k_rIJ = (r - rMin_)/dr_;
 
-    label k(k_rIJ);
+    label k = label(k_rIJ);
 
     if (k < 0)
     {
@@ -135,7 +135,7 @@ Foam::scalar Foam::pairPotential::energyLookup(const scalar r) const
 {
     scalar k_rIJ = (r - rMin_)/dr_;
 
-    label k(k_rIJ);
+    label k = label(k_rIJ);
 
     if (k < 0)
     {
diff --git a/src/postProcessing/Allwmake b/src/postProcessing/Allwmake
index e1f7cc56d8290d962530cc3667457b174a6181ea..ab7328b651f0ec2e2094722574fcf0f3243a7d59 100755
--- a/src/postProcessing/Allwmake
+++ b/src/postProcessing/Allwmake
@@ -3,10 +3,8 @@ cd ${0%/*} || exit 1    # run from this directory
 set -x
 
 wmake libo postCalc
-wmake libso forces
-wmake libso fieldAverage
 wmake libso foamCalcFunctions
-wmake libso minMaxFields
-wmake libso systemCall
+
+(cd functionObjects && ./Allwmake)
 
 # ----------------------------------------------------------------- end-of-file
diff --git a/src/postProcessing/functionObjects/Allwmake b/src/postProcessing/functionObjects/Allwmake
new file mode 100755
index 0000000000000000000000000000000000000000..48e5f4d856bfb35b1ddb8cd1ae466776b91fde1b
--- /dev/null
+++ b/src/postProcessing/functionObjects/Allwmake
@@ -0,0 +1,10 @@
+#!/bin/sh
+cd ${0%/*} || exit 1    # run from this directory
+set -x
+
+wmake libso fieldAverage
+wmake libso forces
+wmake libso minMaxFields
+wmake libso systemCall
+
+# ----------------------------------------------------------------- end-of-file
diff --git a/src/postProcessing/fieldAverage/Make/files b/src/postProcessing/functionObjects/fieldAverage/Make/files
similarity index 100%
rename from src/postProcessing/fieldAverage/Make/files
rename to src/postProcessing/functionObjects/fieldAverage/Make/files
diff --git a/src/postProcessing/fieldAverage/Make/options b/src/postProcessing/functionObjects/fieldAverage/Make/options
similarity index 100%
rename from src/postProcessing/fieldAverage/Make/options
rename to src/postProcessing/functionObjects/fieldAverage/Make/options
diff --git a/src/postProcessing/fieldAverage/controlDict b/src/postProcessing/functionObjects/fieldAverage/controlDict
similarity index 100%
rename from src/postProcessing/fieldAverage/controlDict
rename to src/postProcessing/functionObjects/fieldAverage/controlDict
diff --git a/src/postProcessing/fieldAverage/fieldAverage/IOFieldAverage.H b/src/postProcessing/functionObjects/fieldAverage/fieldAverage/IOFieldAverage.H
similarity index 100%
rename from src/postProcessing/fieldAverage/fieldAverage/IOFieldAverage.H
rename to src/postProcessing/functionObjects/fieldAverage/fieldAverage/IOFieldAverage.H
diff --git a/src/postProcessing/fieldAverage/fieldAverage/fieldAverage.C b/src/postProcessing/functionObjects/fieldAverage/fieldAverage/fieldAverage.C
similarity index 100%
rename from src/postProcessing/fieldAverage/fieldAverage/fieldAverage.C
rename to src/postProcessing/functionObjects/fieldAverage/fieldAverage/fieldAverage.C
diff --git a/src/postProcessing/fieldAverage/fieldAverage/fieldAverage.H b/src/postProcessing/functionObjects/fieldAverage/fieldAverage/fieldAverage.H
similarity index 100%
rename from src/postProcessing/fieldAverage/fieldAverage/fieldAverage.H
rename to src/postProcessing/functionObjects/fieldAverage/fieldAverage/fieldAverage.H
diff --git a/src/postProcessing/fieldAverage/fieldAverage/fieldAverageTemplates.C b/src/postProcessing/functionObjects/fieldAverage/fieldAverage/fieldAverageTemplates.C
similarity index 100%
rename from src/postProcessing/fieldAverage/fieldAverage/fieldAverageTemplates.C
rename to src/postProcessing/functionObjects/fieldAverage/fieldAverage/fieldAverageTemplates.C
diff --git a/src/postProcessing/fieldAverage/fieldAverageFunctionObject/fieldAverageFunctionObject.C b/src/postProcessing/functionObjects/fieldAverage/fieldAverageFunctionObject/fieldAverageFunctionObject.C
similarity index 100%
rename from src/postProcessing/fieldAverage/fieldAverageFunctionObject/fieldAverageFunctionObject.C
rename to src/postProcessing/functionObjects/fieldAverage/fieldAverageFunctionObject/fieldAverageFunctionObject.C
diff --git a/src/postProcessing/fieldAverage/fieldAverageFunctionObject/fieldAverageFunctionObject.H b/src/postProcessing/functionObjects/fieldAverage/fieldAverageFunctionObject/fieldAverageFunctionObject.H
similarity index 100%
rename from src/postProcessing/fieldAverage/fieldAverageFunctionObject/fieldAverageFunctionObject.H
rename to src/postProcessing/functionObjects/fieldAverage/fieldAverageFunctionObject/fieldAverageFunctionObject.H
diff --git a/src/postProcessing/fieldAverage/fieldAverageItem/fieldAverageItem.C b/src/postProcessing/functionObjects/fieldAverage/fieldAverageItem/fieldAverageItem.C
similarity index 100%
rename from src/postProcessing/fieldAverage/fieldAverageItem/fieldAverageItem.C
rename to src/postProcessing/functionObjects/fieldAverage/fieldAverageItem/fieldAverageItem.C
diff --git a/src/postProcessing/fieldAverage/fieldAverageItem/fieldAverageItem.H b/src/postProcessing/functionObjects/fieldAverage/fieldAverageItem/fieldAverageItem.H
similarity index 100%
rename from src/postProcessing/fieldAverage/fieldAverageItem/fieldAverageItem.H
rename to src/postProcessing/functionObjects/fieldAverage/fieldAverageItem/fieldAverageItem.H
diff --git a/src/postProcessing/fieldAverage/fieldAverageItem/fieldAverageItemIO.C b/src/postProcessing/functionObjects/fieldAverage/fieldAverageItem/fieldAverageItemIO.C
similarity index 100%
rename from src/postProcessing/fieldAverage/fieldAverageItem/fieldAverageItemIO.C
rename to src/postProcessing/functionObjects/fieldAverage/fieldAverageItem/fieldAverageItemIO.C
diff --git a/src/postProcessing/forces/Make/files b/src/postProcessing/functionObjects/forces/Make/files
similarity index 100%
rename from src/postProcessing/forces/Make/files
rename to src/postProcessing/functionObjects/forces/Make/files
diff --git a/src/postProcessing/forces/Make/options b/src/postProcessing/functionObjects/forces/Make/options
similarity index 100%
rename from src/postProcessing/forces/Make/options
rename to src/postProcessing/functionObjects/forces/Make/options
diff --git a/src/postProcessing/forces/forceCoeffs/IOforceCoeffs.H b/src/postProcessing/functionObjects/forces/forceCoeffs/IOforceCoeffs.H
similarity index 100%
rename from src/postProcessing/forces/forceCoeffs/IOforceCoeffs.H
rename to src/postProcessing/functionObjects/forces/forceCoeffs/IOforceCoeffs.H
diff --git a/src/postProcessing/forces/forceCoeffs/forceCoeffs.C b/src/postProcessing/functionObjects/forces/forceCoeffs/forceCoeffs.C
similarity index 100%
rename from src/postProcessing/forces/forceCoeffs/forceCoeffs.C
rename to src/postProcessing/functionObjects/forces/forceCoeffs/forceCoeffs.C
diff --git a/src/postProcessing/forces/forceCoeffs/forceCoeffs.H b/src/postProcessing/functionObjects/forces/forceCoeffs/forceCoeffs.H
similarity index 100%
rename from src/postProcessing/forces/forceCoeffs/forceCoeffs.H
rename to src/postProcessing/functionObjects/forces/forceCoeffs/forceCoeffs.H
diff --git a/src/postProcessing/forces/forceCoeffs/forceCoeffsFunctionObject.C b/src/postProcessing/functionObjects/forces/forceCoeffs/forceCoeffsFunctionObject.C
similarity index 100%
rename from src/postProcessing/forces/forceCoeffs/forceCoeffsFunctionObject.C
rename to src/postProcessing/functionObjects/forces/forceCoeffs/forceCoeffsFunctionObject.C
diff --git a/src/postProcessing/forces/forceCoeffs/forceCoeffsFunctionObject.H b/src/postProcessing/functionObjects/forces/forceCoeffs/forceCoeffsFunctionObject.H
similarity index 100%
rename from src/postProcessing/forces/forceCoeffs/forceCoeffsFunctionObject.H
rename to src/postProcessing/functionObjects/forces/forceCoeffs/forceCoeffsFunctionObject.H
diff --git a/src/postProcessing/forces/forces/IOforces.H b/src/postProcessing/functionObjects/forces/forces/IOforces.H
similarity index 100%
rename from src/postProcessing/forces/forces/IOforces.H
rename to src/postProcessing/functionObjects/forces/forces/IOforces.H
diff --git a/src/postProcessing/forces/forces/forces.C b/src/postProcessing/functionObjects/forces/forces/forces.C
similarity index 100%
rename from src/postProcessing/forces/forces/forces.C
rename to src/postProcessing/functionObjects/forces/forces/forces.C
diff --git a/src/postProcessing/forces/forces/forces.H b/src/postProcessing/functionObjects/forces/forces/forces.H
similarity index 100%
rename from src/postProcessing/forces/forces/forces.H
rename to src/postProcessing/functionObjects/forces/forces/forces.H
diff --git a/src/postProcessing/forces/forces/forcesFunctionObject.C b/src/postProcessing/functionObjects/forces/forces/forcesFunctionObject.C
similarity index 100%
rename from src/postProcessing/forces/forces/forcesFunctionObject.C
rename to src/postProcessing/functionObjects/forces/forces/forcesFunctionObject.C
diff --git a/src/postProcessing/forces/forces/forcesFunctionObject.H b/src/postProcessing/functionObjects/forces/forces/forcesFunctionObject.H
similarity index 100%
rename from src/postProcessing/forces/forces/forcesFunctionObject.H
rename to src/postProcessing/functionObjects/forces/forces/forcesFunctionObject.H
diff --git a/src/postProcessing/minMaxFields/IOminMaxFields.H b/src/postProcessing/functionObjects/minMaxFields/IOminMaxFields.H
similarity index 100%
rename from src/postProcessing/minMaxFields/IOminMaxFields.H
rename to src/postProcessing/functionObjects/minMaxFields/IOminMaxFields.H
diff --git a/src/postProcessing/minMaxFields/Make/files b/src/postProcessing/functionObjects/minMaxFields/Make/files
similarity index 100%
rename from src/postProcessing/minMaxFields/Make/files
rename to src/postProcessing/functionObjects/minMaxFields/Make/files
diff --git a/src/postProcessing/minMaxFields/Make/options b/src/postProcessing/functionObjects/minMaxFields/Make/options
similarity index 100%
rename from src/postProcessing/minMaxFields/Make/options
rename to src/postProcessing/functionObjects/minMaxFields/Make/options
diff --git a/src/postProcessing/minMaxFields/minMaxFields.C b/src/postProcessing/functionObjects/minMaxFields/minMaxFields.C
similarity index 100%
rename from src/postProcessing/minMaxFields/minMaxFields.C
rename to src/postProcessing/functionObjects/minMaxFields/minMaxFields.C
diff --git a/src/postProcessing/minMaxFields/minMaxFields.H b/src/postProcessing/functionObjects/minMaxFields/minMaxFields.H
similarity index 100%
rename from src/postProcessing/minMaxFields/minMaxFields.H
rename to src/postProcessing/functionObjects/minMaxFields/minMaxFields.H
diff --git a/src/postProcessing/minMaxFields/minMaxFieldsFunctionObject.C b/src/postProcessing/functionObjects/minMaxFields/minMaxFieldsFunctionObject.C
similarity index 100%
rename from src/postProcessing/minMaxFields/minMaxFieldsFunctionObject.C
rename to src/postProcessing/functionObjects/minMaxFields/minMaxFieldsFunctionObject.C
diff --git a/src/postProcessing/minMaxFields/minMaxFieldsFunctionObject.H b/src/postProcessing/functionObjects/minMaxFields/minMaxFieldsFunctionObject.H
similarity index 100%
rename from src/postProcessing/minMaxFields/minMaxFieldsFunctionObject.H
rename to src/postProcessing/functionObjects/minMaxFields/minMaxFieldsFunctionObject.H
diff --git a/src/postProcessing/minMaxFields/minMaxFieldsTemplates.C b/src/postProcessing/functionObjects/minMaxFields/minMaxFieldsTemplates.C
similarity index 100%
rename from src/postProcessing/minMaxFields/minMaxFieldsTemplates.C
rename to src/postProcessing/functionObjects/minMaxFields/minMaxFieldsTemplates.C
diff --git a/src/postProcessing/systemCall/IOsystemCall.H b/src/postProcessing/functionObjects/systemCall/IOsystemCall.H
similarity index 100%
rename from src/postProcessing/systemCall/IOsystemCall.H
rename to src/postProcessing/functionObjects/systemCall/IOsystemCall.H
diff --git a/src/postProcessing/systemCall/Make/files b/src/postProcessing/functionObjects/systemCall/Make/files
similarity index 100%
rename from src/postProcessing/systemCall/Make/files
rename to src/postProcessing/functionObjects/systemCall/Make/files
diff --git a/src/postProcessing/systemCall/Make/options b/src/postProcessing/functionObjects/systemCall/Make/options
similarity index 100%
rename from src/postProcessing/systemCall/Make/options
rename to src/postProcessing/functionObjects/systemCall/Make/options
diff --git a/src/postProcessing/systemCall/systemCall.C b/src/postProcessing/functionObjects/systemCall/systemCall.C
similarity index 100%
rename from src/postProcessing/systemCall/systemCall.C
rename to src/postProcessing/functionObjects/systemCall/systemCall.C
diff --git a/src/postProcessing/systemCall/systemCall.H b/src/postProcessing/functionObjects/systemCall/systemCall.H
similarity index 100%
rename from src/postProcessing/systemCall/systemCall.H
rename to src/postProcessing/functionObjects/systemCall/systemCall.H
diff --git a/src/postProcessing/systemCall/systemCallFunctionObject.C b/src/postProcessing/functionObjects/systemCall/systemCallFunctionObject.C
similarity index 100%
rename from src/postProcessing/systemCall/systemCallFunctionObject.C
rename to src/postProcessing/functionObjects/systemCall/systemCallFunctionObject.C
diff --git a/src/postProcessing/systemCall/systemCallFunctionObject.H b/src/postProcessing/functionObjects/systemCall/systemCallFunctionObject.H
similarity index 100%
rename from src/postProcessing/systemCall/systemCallFunctionObject.H
rename to src/postProcessing/functionObjects/systemCall/systemCallFunctionObject.H
diff --git a/src/sampling/outputFilters/IOOutputFilter/IOOutputFilter.C b/src/sampling/outputFilters/IOOutputFilter/IOOutputFilter.C
index 2b1f17c54cfb6a077e1d513acaa97f5d70b8c78a..5346e95c2eecd239e3211173b07cc4da26375f1e 100644
--- a/src/sampling/outputFilters/IOOutputFilter/IOOutputFilter.C
+++ b/src/sampling/outputFilters/IOOutputFilter/IOOutputFilter.C
@@ -32,6 +32,7 @@ License
 template<class OutputFilter>
 Foam::IOOutputFilter<OutputFilter>::IOOutputFilter
 (
+    const word& outputFilterName,
     const objectRegistry& obr,
     const fileName& dictName,
     const IOobject::readOption rOpt,
@@ -49,7 +50,7 @@ Foam::IOOutputFilter<OutputFilter>::IOOutputFilter
             IOobject::NO_WRITE
         )
     ),
-    OutputFilter(OutputFilter::typeName, obr, *this, readFromFiles)
+    OutputFilter(outputFilterName, obr, *this, readFromFiles)
 {}
 
 
diff --git a/src/sampling/outputFilters/IOOutputFilter/IOOutputFilter.H b/src/sampling/outputFilters/IOOutputFilter/IOOutputFilter.H
index 1591d289323c4a585c95f55b876dc9b6f8523ad2..51ccc952ae9222a31dfc9edfae3842088a45a387 100644
--- a/src/sampling/outputFilters/IOOutputFilter/IOOutputFilter.H
+++ b/src/sampling/outputFilters/IOOutputFilter/IOOutputFilter.H
@@ -60,7 +60,7 @@ class IOOutputFilter
 {
     // Private Member Functions
 
-        //- Disallow default bitwise copy construct and assignment
+        // Disallow default bitwise copy construct and assignment
         IOOutputFilter(const IOOutputFilter&);
         void operator=(const IOOutputFilter&);
 
@@ -74,6 +74,7 @@ public:
         //  Allow the possibility to load fields from files
         IOOutputFilter
         (
+            const word& outputFilterName,
             const objectRegistry&,
             const fileName& dictName = OutputFilter::typeName() + "Dict",
             const IOobject::readOption rOpt = IOobject::MUST_READ,
@@ -81,9 +82,8 @@ public:
         );
 
 
-    // Destructor
-
-        virtual ~IOOutputFilter();
+    //- Destructor
+    virtual ~IOOutputFilter();
 
 
     // Member Functions
diff --git a/src/sampling/outputFilters/OutputFilterFunctionObject/OutputFilterFunctionObject.C b/src/sampling/outputFilters/OutputFilterFunctionObject/OutputFilterFunctionObject.C
index 8f71db206f5884576288c0e8351a1bd33c64c4f9..45305257e9f760ea57028d8dd395937c36a56479 100644
--- a/src/sampling/outputFilters/OutputFilterFunctionObject/OutputFilterFunctionObject.C
+++ b/src/sampling/outputFilters/OutputFilterFunctionObject/OutputFilterFunctionObject.C
@@ -78,6 +78,7 @@ bool Foam::OutputFilterFunctionObject<OutputFilter>::start()
             (
                 new IOOutputFilter<OutputFilter>
                 (
+                    name_,
                     time_.lookupObject<objectRegistry>(regionName_),
                     dictName_
                 )
diff --git a/src/sampling/sampledSet/sampledSets/sampledSets.C b/src/sampling/sampledSet/sampledSets/sampledSets.C
index 6cbb0183bb0fe7ec5d0d4dc9f3c7e9a803c6c0a8..52374b19c82242208f3d0a75ef824f3e75e25cba 100644
--- a/src/sampling/sampledSet/sampledSets/sampledSets.C
+++ b/src/sampling/sampledSet/sampledSets/sampledSets.C
@@ -102,7 +102,7 @@ bool Foam::sampledSets::checkFieldTypes()
     nFields += grep(symmTensorFields_, fieldTypes);
     nFields += grep(tensorFields_, fieldTypes);
 
-    if (Pstream::master)
+    if (Pstream::master())
     {
         if (debug)
         {
diff --git a/src/turbulenceModels/compressible/turbulenceModel/turbulenceModel.C b/src/turbulenceModels/compressible/turbulenceModel/turbulenceModel.C
index c4cb9811657cade44434a7783f02240b44713143..62559245df4925c22d59552129e06fab2ee9bf4d 100644
--- a/src/turbulenceModels/compressible/turbulenceModel/turbulenceModel.C
+++ b/src/turbulenceModels/compressible/turbulenceModel/turbulenceModel.C
@@ -88,7 +88,7 @@ autoPtr<turbulenceModel> turbulenceModel::New
             )
         );
 
-        turbulencePropertiesDict.lookup("turbulenceModel")
+        turbulencePropertiesDict.lookup("simulationType")
             >> turbulenceModelTypeName;
     }
 
diff --git a/src/turbulenceModels/incompressible/LES/laminar/laminar.C b/src/turbulenceModels/incompressible/LES/laminar/laminar.C
index ae0fd04798e884e8e69bdb18607bd7d197ad4f31..0cb323630df83f7c30c935c2baad3ac0b9666211 100644
--- a/src/turbulenceModels/incompressible/LES/laminar/laminar.C
+++ b/src/turbulenceModels/incompressible/LES/laminar/laminar.C
@@ -26,7 +26,6 @@ License
 
 #include "laminar.H"
 #include "addToRunTimeSelectionTable.H"
-#include "wallDist.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
diff --git a/tutorials/chtMultiRegionFoam/multiRegionHeater/system/fvSchemes b/tutorials/buoyantFoam/hotRoom/constant/turbulenceProperties
similarity index 58%
rename from tutorials/chtMultiRegionFoam/multiRegionHeater/system/fvSchemes
rename to tutorials/buoyantFoam/hotRoom/constant/turbulenceProperties
index 1c38514090a429a2e0338c814693e4917b601438..321c08496ae7cbe64b73cb2b6f5b2b172bcc9eaf 100644
--- a/tutorials/chtMultiRegionFoam/multiRegionHeater/system/fvSchemes
+++ b/tutorials/buoyantFoam/hotRoom/constant/turbulenceProperties
@@ -10,50 +10,13 @@ FoamFile
     version     2.0;
     format      ascii;
     class       dictionary;
-    object      fvSchemes;
+    object      turbulenceProperties;
 }
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
-ddtSchemes
-{
-    default Euler;
-}
-
-gradSchemes
-{
-    default         Gauss linear;
-    grad(U)         Gauss linear;
-    grad(gamma)     Gauss linear;
-}
+//simulationType       laminar;
+simulationType       RASModel;
+//simulationType       LESModel;
 
-divSchemes
-{
-    div(rho*phi,U)  Gauss upwind; //limitedLinearV 1;
-    div(phi,gamma)  Gauss vanLeer;
-    div(phirb,gamma) Gauss interfaceCompression;
-}
-
-laplacianSchemes
-{
-    default         Gauss linear corrected;
-}
-
-interpolationSchemes
-{
-    default         linear;
-}
-
-snGradSchemes
-{
-    default         corrected;
-}
-
-fluxRequired
-{
-    default         no;
-    pd;
-    pcorr;
-    gamma;
-}
 
 // ************************************************************************* //
diff --git a/tutorials/chtMultiRegionFoam/multiRegionHeater/system/bottomAir/changeDictionaryDict b/tutorials/chtMultiRegionFoam/multiRegionHeater/system/bottomAir/changeDictionaryDict
index 285f41a8438936f0aa4945a4d1dda19ed06a48c0..5f75f1a76ddf1691f69796712f10ba8a2ec10238 100644
--- a/tutorials/chtMultiRegionFoam/multiRegionHeater/system/bottomAir/changeDictionaryDict
+++ b/tutorials/chtMultiRegionFoam/multiRegionHeater/system/bottomAir/changeDictionaryDict
@@ -61,7 +61,7 @@ dictionaryReplacement
             }
             bottomAir_to_leftSolid
             {
-                type            solidWallTemperatureCoupled;
+                type            solidWallMixedTemperatureCoupled;
                 neighbourRegionName leftSolid;
                 neighbourPatchName leftSolid_to_bottomAir;
                 neighbourFieldName T;
@@ -71,7 +71,7 @@ dictionaryReplacement
             }
             bottomAir_to_heater
             {
-                type            solidWallTemperatureCoupled;
+                type            solidWallMixedTemperatureCoupled;
                 neighbourRegionName heater;
                 neighbourPatchName heater_to_bottomAir;
                 neighbourFieldName T;
@@ -80,7 +80,7 @@ dictionaryReplacement
             }
             bottomAir_to_rightSolid
             {
-                type            solidWallTemperatureCoupled;
+                type            solidWallMixedTemperatureCoupled;
                 neighbourRegionName rightSolid;
                 neighbourPatchName rightSolid_to_bottomAir;
                 neighbourFieldName T;
@@ -254,49 +254,49 @@ dictionaryReplacement
 
     p
     {
-        internalField   uniform 1000000;
+        internalField   uniform 100000;
         boundaryField
         {
             minX
             {
                 type            calculated;
-                value           uniform 1000000;
+                value           uniform 100000;
             }
             maxX
             {
                 type            calculated;
-                value           uniform 1000000;
+                value           uniform 100000;
             }
             minY
             {
                 type            calculated;
-                value           uniform 1000000;
+                value           uniform 100000;
             }
             minZ
             {
                 type            calculated;
-                value           uniform 1000000;
+                value           uniform 100000;
             }
             maxZ
             {
                 type            calculated;
-                value           uniform 1000000;
+                value           uniform 100000;
             }
 
             bottomAir_to_leftSolid
             {
                 type            calculated;
-                value           uniform 1000000;
+                value           uniform 100000;
             }
             bottomAir_to_heater
             {
                 type            calculated;
-                value           uniform 1000000;
+                value           uniform 100000;
             }
             bottomAir_to_rightSolid
             {
                 type            calculated;
-                value           uniform 1000000;
+                value           uniform 100000;
             }
         }
     }
diff --git a/tutorials/chtMultiRegionFoam/multiRegionHeater/system/changeDictionaryDict b/tutorials/chtMultiRegionFoam/multiRegionHeater/system/changeDictionaryDict
deleted file mode 100644
index 56a984c7d79fe0905dadedba30cadee68ca322e6..0000000000000000000000000000000000000000
--- a/tutorials/chtMultiRegionFoam/multiRegionHeater/system/changeDictionaryDict
+++ /dev/null
@@ -1,192 +0,0 @@
-/*--------------------------------*- C++ -*----------------------------------*\
-| =========                 |                                                 |
-| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
-|  \\    /   O peration     | Version:  1.5                                   |
-|   \\  /    A nd           | Web:      http://www.OpenFOAM.org               |
-|    \\/     M anipulation  |                                                 |
-\*---------------------------------------------------------------------------*/
-FoamFile
-{
-    version     2.0;
-    format      ascii;
-    class       dictionary;
-    object      changeDictionaryDict;
-}
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-dictionaryReplacement
-{
-    T
-    {
-        internalField   uniform 300;
-
-        boundaryField
-        {
-            minY
-            {
-                type            fixedValue;
-                value           uniform 500;
-            }
-
-            minZ
-            {
-                type            zeroGradient;
-            }
-            maxZ
-            {
-                type            zeroGradient;
-            }
-
-            heater_to_domain0
-            {
-                type            solidWallHeatFluxTemperatureCoupled;
-                neighbourRegionName domain0;
-                neighbourPatchName domain0_to_heater;
-                neighbourFieldName T;
-                K               K;
-                value           uniform 300;
-
-            }
-            heater_to_solid1
-            {
-                type            solidWallHeatFluxTemperatureCoupled;
-                neighbourRegionName solid1;
-                neighbourPatchName solid1_to_heater;
-                neighbourFieldName T;
-                K               K;
-                value           uniform 300;
-            }
-            heater_to_solid3
-            {
-                type            solidWallHeatFluxTemperatureCoupled;
-                neighbourRegionName solid3;
-                neighbourPatchName solid3_to_heater;
-                neighbourFieldName T;
-                K               K;
-                value           uniform 300;
-            }
-            heater_to_domain3
-            {
-                type            solidWallHeatFluxTemperatureCoupled;
-                neighbourRegionName domain3;
-                neighbourPatchName domain3_to_heater;
-                neighbourFieldName T;
-                K               K;
-                value           uniform 300;
-            }
-        }
-    }
-
-    rho
-    {
-        internalField   uniform 8000;
-
-        boundaryField
-        {
-            minY
-            {
-                type            zeroGradient;
-            }
-            minZ
-            {
-                type            zeroGradient;
-            }
-            maxZ
-            {
-                type            zeroGradient;
-            }
-            heater_to_domain0
-            {
-                type            zeroGradient;
-            }
-            heater_to_solid1
-            {
-                type            zeroGradient;
-            }
-            heater_to_solid3
-            {
-                type            zeroGradient;
-            }
-            heater_to_domain3
-            {
-                type            zeroGradient;
-            }
-        }
-    }
-
-    K
-    {
-        internalField   uniform 80;
-
-        boundaryField
-        {
-            minY
-            {
-                type            zeroGradient;
-            }
-            minZ
-            {
-                type            zeroGradient;
-            }
-            maxZ
-            {
-                type            zeroGradient;
-            }
-            heater_to_domain0
-            {
-                type            zeroGradient;
-            }
-            heater_to_solid1
-            {
-                type            zeroGradient;
-            }
-            heater_to_solid3
-            {
-                type            zeroGradient;
-            }
-            heater_to_domain3
-            {
-                type            zeroGradient;
-            }
-        }
-    }
-
-    cp
-    {
-        internalField   uniform 450;
-
-        boundaryField
-        {
-            minY
-            {
-                type            zeroGradient;
-            }
-            minZ
-            {
-                type            zeroGradient;
-            }
-            maxZ
-            {
-                type            zeroGradient;
-            }
-            heater_to_domain0
-            {
-                type            zeroGradient;
-            }
-            heater_to_solid1
-            {
-                type            zeroGradient;
-            }
-            heater_to_solid3
-            {
-                type            zeroGradient;
-            }
-            heater_to_domain3
-            {
-                type            zeroGradient;
-            }
-        }
-    }
-}
-
-// ************************************************************************* //
diff --git a/tutorials/chtMultiRegionFoam/multiRegionHeater/system/fvSolution b/tutorials/chtMultiRegionFoam/multiRegionHeater/system/fvSolution
deleted file mode 100644
index a77e8bcd8f196d557d62d2ffbc0ef4c393e020ce..0000000000000000000000000000000000000000
--- a/tutorials/chtMultiRegionFoam/multiRegionHeater/system/fvSolution
+++ /dev/null
@@ -1,123 +0,0 @@
-/*--------------------------------*- C++ -*----------------------------------*\
-| =========                 |                                                 |
-| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
-|  \\    /   O peration     | Version:  1.5                                   |
-|   \\  /    A nd           | Web:      http://www.OpenFOAM.org               |
-|    \\/     M anipulation  |                                                 |
-\*---------------------------------------------------------------------------*/
-FoamFile
-{
-    version     2.0;
-    format      ascii;
-    class       dictionary;
-    object      fvSolution;
-}
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-solvers
-{
-    pcorr PCG
-    {
-        preconditioner   GAMG
-        {
-            tolerance        1e-3;
-            relTol           0;
-
-            smoother         GaussSeidel;
-            nPreSweeps       0;
-            nPostSweeps      2;
-            nBottomSweeps    2;
-
-            cacheAgglomeration false;
-            nCellsInCoarsestLevel 10;
-            agglomerator     faceAreaPair;
-            mergeLevels      1;
-        };
-
-        tolerance        1e-4;
-        relTol           0;
-        maxIter          100;
-    };
-
-    pd GAMG
-    {
-        tolerance        1e-8;
-        relTol           0.05;
-
-        smoother         GaussSeidel;
-        nPreSweeps       0;
-        nPostSweeps      2;
-        nFinestSweeps    2;
-
-        cacheAgglomeration false;
-        nCellsInCoarsestLevel 10;
-        agglomerator     faceAreaPair;
-        mergeLevels      1;
-    };
-
-    pdFinal PCG
-    {
-        preconditioner GAMG
-        {
-            tolerance        1e-8;
-            relTol           0;
-
-            nVcycles         2;
-
-            smoother         GaussSeidel;
-            nPreSweeps       0;
-            nPostSweeps      2;
-            nFinestSweeps    2;
-
-            cacheAgglomeration false;
-            nCellsInCoarsestLevel 10;
-            agglomerator     faceAreaPair;
-            mergeLevels      1;
-        };
-
-        tolerance        1e-8;
-        relTol           0;
-        maxIter          20;
-    };
-
-    U smoothSolver
-    {
-        smoother         GaussSeidel;
-        tolerance        1e-6;
-        relTol           0;
-        nSweeps          1;
-    };
-
-    k PBiCG
-    {
-        preconditioner   DILU;
-        tolerance        1e-08;
-        relTol           0;
-    };
-    B PBiCG
-    {
-        preconditioner   DILU;
-        tolerance        1e-08;
-        relTol           0;
-    };
-    nuTilda PBiCG
-    {
-        preconditioner   DILU;
-        tolerance        1e-08;
-        relTol           0;
-    };
-}
-
-PISO
-{
-    momentumPredictor no;
-    nCorrectors     3;
-    nNonOrthogonalCorrectors 0;
-    nGammaCorr      1;
-    nGammaSubCycles 3;
-    cGamma          1;
-    pdRefCell       0;
-    pdRefValue      0;
-}
-
-// ************************************************************************* //
diff --git a/tutorials/chtMultiRegionFoam/multiRegionHeater/system/heater/changeDictionaryDict b/tutorials/chtMultiRegionFoam/multiRegionHeater/system/heater/changeDictionaryDict
index b4226ef4844a0fdb5eb834a3a8907bb4cde64608..92038e31df8fd503518e3a30e581e9d16756227c 100644
--- a/tutorials/chtMultiRegionFoam/multiRegionHeater/system/heater/changeDictionaryDict
+++ b/tutorials/chtMultiRegionFoam/multiRegionHeater/system/heater/changeDictionaryDict
@@ -39,7 +39,7 @@ dictionaryReplacement
 
             heater_to_bottomAir
             {
-                type            solidWallHeatFluxTemperatureCoupled;
+                type            solidWallMixedTemperatureCoupled;
                 neighbourRegionName bottomAir;
                 neighbourPatchName bottomAir_to_heater;
                 neighbourFieldName T;
@@ -49,7 +49,7 @@ dictionaryReplacement
             }
             heater_to_leftSolid
             {
-                type            solidWallHeatFluxTemperatureCoupled;
+                type            solidWallMixedTemperatureCoupled;
                 neighbourRegionName leftSolid;
                 neighbourPatchName leftSolid_to_heater;
                 neighbourFieldName T;
@@ -58,7 +58,7 @@ dictionaryReplacement
             }
             heater_to_rightSolid
             {
-                type            solidWallHeatFluxTemperatureCoupled;
+                type            solidWallMixedTemperatureCoupled;
                 neighbourRegionName rightSolid;
                 neighbourPatchName rightSolid_to_heater;
                 neighbourFieldName T;
@@ -67,7 +67,7 @@ dictionaryReplacement
             }
             heater_to_topAir
             {
-                type            solidWallHeatFluxTemperatureCoupled;
+                type            solidWallMixedTemperatureCoupled;
                 neighbourRegionName topAir;
                 neighbourPatchName topAir_to_heater;
                 neighbourFieldName T;
diff --git a/tutorials/chtMultiRegionFoam/multiRegionHeater/system/leftSolid/changeDictionaryDict b/tutorials/chtMultiRegionFoam/multiRegionHeater/system/leftSolid/changeDictionaryDict
index 86ac71c3cb0286947e32e15704e3a418dbd8d284..c30a9b5c4bb180f2b7541a0cbaefa68c62791b40 100644
--- a/tutorials/chtMultiRegionFoam/multiRegionHeater/system/leftSolid/changeDictionaryDict
+++ b/tutorials/chtMultiRegionFoam/multiRegionHeater/system/leftSolid/changeDictionaryDict
@@ -36,7 +36,7 @@ dictionaryReplacement
             }
             leftSolid_to_bottomAir
             {
-                type            solidWallHeatFluxTemperatureCoupled;
+                type            solidWallMixedTemperatureCoupled;
                 neighbourRegionName bottomAir;
                 neighbourPatchName bottomAir_to_leftSolid;
                 neighbourFieldName T;
@@ -46,7 +46,7 @@ dictionaryReplacement
             }
             leftSolid_to_heater
             {
-                type            solidWallTemperatureCoupled;
+                type            solidWallMixedTemperatureCoupled;
                 neighbourRegionName heater;
                 neighbourPatchName heater_to_leftSolid;
                 neighbourFieldName T;
@@ -55,7 +55,7 @@ dictionaryReplacement
             }
             leftSolid_to_topAir
             {
-                type            solidWallHeatFluxTemperatureCoupled;
+                type            solidWallMixedTemperatureCoupled;
                 neighbourRegionName topAir;
                 neighbourPatchName topAir_to_leftSolid;
                 neighbourFieldName T;
diff --git a/tutorials/chtMultiRegionFoam/multiRegionHeater/system/rightSolid/changeDictionaryDict b/tutorials/chtMultiRegionFoam/multiRegionHeater/system/rightSolid/changeDictionaryDict
index b27b29bfcdc0de7ca1e8856defe9732399f1eca9..292f92f1d3b4efdd81831370545adc34357fd586 100644
--- a/tutorials/chtMultiRegionFoam/multiRegionHeater/system/rightSolid/changeDictionaryDict
+++ b/tutorials/chtMultiRegionFoam/multiRegionHeater/system/rightSolid/changeDictionaryDict
@@ -36,7 +36,7 @@ dictionaryReplacement
             }
             rightSolid_to_heater
             {
-                type            solidWallTemperatureCoupled;
+                type            solidWallMixedTemperatureCoupled;
                 neighbourRegionName heater;
                 neighbourPatchName heater_to_rightSolid;
                 neighbourFieldName T;
@@ -45,7 +45,7 @@ dictionaryReplacement
             }
             rightSolid_to_bottomAir
             {
-                type            solidWallHeatFluxTemperatureCoupled;
+                type            solidWallMixedTemperatureCoupled;
                 neighbourRegionName bottomAir;
                 neighbourPatchName bottomAir_to_rightSolid;
                 neighbourFieldName T;
@@ -54,7 +54,7 @@ dictionaryReplacement
             }
             rightSolid_to_topAir
             {
-                type            solidWallHeatFluxTemperatureCoupled;
+                type            solidWallMixedTemperatureCoupled;
                 neighbourRegionName topAir;
                 neighbourPatchName topAir_to_rightSolid;
                 neighbourFieldName T;
diff --git a/tutorials/chtMultiRegionFoam/multiRegionHeater/system/topAir/changeDictionaryDict b/tutorials/chtMultiRegionFoam/multiRegionHeater/system/topAir/changeDictionaryDict
index 058056571ae270fc3a3a9078f991c2748bc5803f..e13083daa743d89571b74dfcac14d8605ea0b60b 100644
--- a/tutorials/chtMultiRegionFoam/multiRegionHeater/system/topAir/changeDictionaryDict
+++ b/tutorials/chtMultiRegionFoam/multiRegionHeater/system/topAir/changeDictionaryDict
@@ -62,7 +62,7 @@ dictionaryReplacement
             }
             topAir_to_leftSolid
             {
-                type            solidWallTemperatureCoupled;
+                type            solidWallMixedTemperatureCoupled;
                 neighbourRegionName leftSolid;
                 neighbourPatchName leftSolid_to_topAir;
                 neighbourFieldName T;
@@ -72,7 +72,7 @@ dictionaryReplacement
             }
             topAir_to_heater
             {
-                type            solidWallTemperatureCoupled;
+                type            solidWallMixedTemperatureCoupled;
                 neighbourRegionName heater;
                 neighbourPatchName heater_to_topAir;
                 neighbourFieldName T;
@@ -81,7 +81,7 @@ dictionaryReplacement
             }
             topAir_to_rightSolid
             {
-                type            solidWallTemperatureCoupled;
+                type            solidWallMixedTemperatureCoupled;
                 neighbourRegionName rightSolid;
                 neighbourPatchName rightSolid_to_topAir;
                 neighbourFieldName T;
@@ -263,50 +263,50 @@ dictionaryReplacement
 
     p
     {
-        internalField   uniform 1000000;
+        internalField   uniform 100000;
 
         boundaryField
         {
             minX
             {
                 type            calculated;
-                value           uniform 1000000;
+                value           uniform 100000;
             }
             maxX
             {
                 type            calculated;
-                value           uniform 1000000;
+                value           uniform 100000;
             }
             maxY
             {
                 type            calculated;
-                value           uniform 1000000;
+                value           uniform 100000;
             }
             minZ
             {
                 type            calculated;
-                value           uniform 1000000;
+                value           uniform 100000;
             }
             maxZ
             {
                 type            calculated;
-                value           uniform 1000000;
+                value           uniform 100000;
             }
 
             topAir_to_leftSolid
             {
                 type            calculated;
-                value           uniform 1000000;
+                value           uniform 100000;
             }
             topAir_to_heater
             {
                 type            calculated;
-                value           uniform 1000000;
+                value           uniform 100000;
             }
             topAir_to_rightSolid
             {
                 type            calculated;
-                value           uniform 1000000;
+                value           uniform 100000;
             }
         }
     }
diff --git a/tutorials/compressibleLesInterFoam/depthCharge2D/0/U b/tutorials/compressibleInterFoam/depthCharge2D/0/U
similarity index 100%
rename from tutorials/compressibleLesInterFoam/depthCharge2D/0/U
rename to tutorials/compressibleInterFoam/depthCharge2D/0/U
diff --git a/tutorials/compressibleLesInterFoam/depthCharge2D/0/alpha1.org b/tutorials/compressibleInterFoam/depthCharge2D/0/alpha1.org
similarity index 100%
rename from tutorials/compressibleLesInterFoam/depthCharge2D/0/alpha1.org
rename to tutorials/compressibleInterFoam/depthCharge2D/0/alpha1.org
diff --git a/tutorials/compressibleLesInterFoam/depthCharge2D/0/pd.org b/tutorials/compressibleInterFoam/depthCharge2D/0/pd.org
similarity index 100%
rename from tutorials/compressibleLesInterFoam/depthCharge2D/0/pd.org
rename to tutorials/compressibleInterFoam/depthCharge2D/0/pd.org
diff --git a/tutorials/compressibleLesInterFoam/depthCharge2D/Allrun b/tutorials/compressibleInterFoam/depthCharge2D/Allrun
similarity index 100%
rename from tutorials/compressibleLesInterFoam/depthCharge2D/Allrun
rename to tutorials/compressibleInterFoam/depthCharge2D/Allrun
diff --git a/tutorials/compressibleLesInterFoam/depthCharge3D/constant/LESProperties b/tutorials/compressibleInterFoam/depthCharge2D/constant/LESProperties
similarity index 98%
rename from tutorials/compressibleLesInterFoam/depthCharge3D/constant/LESProperties
rename to tutorials/compressibleInterFoam/depthCharge2D/constant/LESProperties
index 130d0947d9c4402eba4cf9ee019bdd81b319ad1b..bb84772ba51036c08aa1082c7e6720dfe9d65037 100644
--- a/tutorials/compressibleLesInterFoam/depthCharge3D/constant/LESProperties
+++ b/tutorials/compressibleInterFoam/depthCharge2D/constant/LESProperties
@@ -16,7 +16,9 @@ FoamFile
 
 LESModel        laminar;
 
-delta           smooth;
+turbulence      off;
+
+delta           cubeRootVol;
 
 laminarCoeffs
 {
diff --git a/tutorials/compressibleLesInterFoam/depthCharge2D/constant/environmentalProperties b/tutorials/compressibleInterFoam/depthCharge2D/constant/environmentalProperties
similarity index 100%
rename from tutorials/compressibleLesInterFoam/depthCharge2D/constant/environmentalProperties
rename to tutorials/compressibleInterFoam/depthCharge2D/constant/environmentalProperties
diff --git a/tutorials/compressibleLesInterFoam/depthCharge2D/constant/polyMesh/blockMeshDict b/tutorials/compressibleInterFoam/depthCharge2D/constant/polyMesh/blockMeshDict
similarity index 100%
rename from tutorials/compressibleLesInterFoam/depthCharge2D/constant/polyMesh/blockMeshDict
rename to tutorials/compressibleInterFoam/depthCharge2D/constant/polyMesh/blockMeshDict
diff --git a/tutorials/compressibleLesInterFoam/depthCharge2D/constant/polyMesh/boundary b/tutorials/compressibleInterFoam/depthCharge2D/constant/polyMesh/boundary
similarity index 78%
rename from tutorials/compressibleLesInterFoam/depthCharge2D/constant/polyMesh/boundary
rename to tutorials/compressibleInterFoam/depthCharge2D/constant/polyMesh/boundary
index e1e2119e32dbd8fc336ad4c3ce9de73c190ff41f..a6a3281fd72f7a13b8fb5bd5a0d44edc0abc0059 100644
--- a/tutorials/compressibleLesInterFoam/depthCharge2D/constant/polyMesh/boundary
+++ b/tutorials/compressibleInterFoam/depthCharge2D/constant/polyMesh/boundary
@@ -1,15 +1,16 @@
 /*--------------------------------*- C++ -*----------------------------------*\
 | =========                 |                                                 |
 | \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
-|  \\    /   O peration     | Version:  dev                                   |
-|   \\  /    A nd           | Web:      http://www.OpenFOAM.org               |
-|    \\/     M anipulation  |                                                 |
+|  \\    /   O peration     | Version:  dev-09ca1eb6b56f                      |
+|   \\  /    A nd           |                                                 |
+|    \\/     M anipulation  |                                www.OpenFOAM.org |
 \*---------------------------------------------------------------------------*/
 FoamFile
 {
     version     2.0;
     format      ascii;
     class       polyBoundaryMesh;
+    location    "constant/polyMesh";
     object      boundary;
 }
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/tutorials/compressibleLesInterFoam/depthCharge2D/constant/transportProperties b/tutorials/compressibleInterFoam/depthCharge2D/constant/transportProperties
similarity index 100%
rename from tutorials/compressibleLesInterFoam/depthCharge2D/constant/transportProperties
rename to tutorials/compressibleInterFoam/depthCharge2D/constant/transportProperties
diff --git a/tutorials/compressibleInterFoam/depthCharge2D/constant/turbulenceProperties b/tutorials/compressibleInterFoam/depthCharge2D/constant/turbulenceProperties
new file mode 100644
index 0000000000000000000000000000000000000000..d3f32ecb06e6235cefb9e465d2767faa80138f38
--- /dev/null
+++ b/tutorials/compressibleInterFoam/depthCharge2D/constant/turbulenceProperties
@@ -0,0 +1,22 @@
+/*--------------------------------*- C++ -*----------------------------------*\
+| =========                 |                                                 |
+| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
+|  \\    /   O peration     | Version:  1.5                                   |
+|   \\  /    A nd           | Web:      http://www.OpenFOAM.org               |
+|    \\/     M anipulation  |                                                 |
+\*---------------------------------------------------------------------------*/
+FoamFile
+{
+    version     2.0;
+    format      ascii;
+    class       dictionary;
+    object      turbulenceProperties;
+}
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+//simulationType       laminar;
+//simulationType       RASModel;
+simulationType       LESModel;
+
+
+// ************************************************************************* //
diff --git a/tutorials/compressibleLesInterFoam/depthCharge2D/system/controlDict b/tutorials/compressibleInterFoam/depthCharge2D/system/controlDict
similarity index 100%
rename from tutorials/compressibleLesInterFoam/depthCharge2D/system/controlDict
rename to tutorials/compressibleInterFoam/depthCharge2D/system/controlDict
diff --git a/tutorials/compressibleLesInterFoam/depthCharge2D/system/fvSchemes b/tutorials/compressibleInterFoam/depthCharge2D/system/fvSchemes
similarity index 100%
rename from tutorials/compressibleLesInterFoam/depthCharge2D/system/fvSchemes
rename to tutorials/compressibleInterFoam/depthCharge2D/system/fvSchemes
diff --git a/tutorials/compressibleLesInterFoam/depthCharge3D/system/fvSolution b/tutorials/compressibleInterFoam/depthCharge2D/system/fvSolution
similarity index 99%
rename from tutorials/compressibleLesInterFoam/depthCharge3D/system/fvSolution
rename to tutorials/compressibleInterFoam/depthCharge2D/system/fvSolution
index f97cf54032ec4b42a7b0bb04cdd33dcd4deb1de7..868252473975e23b298727de38f9dd66fbef0b56 100644
--- a/tutorials/compressibleLesInterFoam/depthCharge3D/system/fvSolution
+++ b/tutorials/compressibleInterFoam/depthCharge2D/system/fvSolution
@@ -120,7 +120,7 @@ PISO
     nNonOrthogonalCorrectors 0;
     nAlphaCorr      1;
     nAlphaSubCycles 1;
-    cGamma          1;
+    cAlpha          1;
 }
 
 // ************************************************************************* //
diff --git a/tutorials/compressibleLesInterFoam/depthCharge2D/system/setFieldsDict b/tutorials/compressibleInterFoam/depthCharge2D/system/setFieldsDict
similarity index 100%
rename from tutorials/compressibleLesInterFoam/depthCharge2D/system/setFieldsDict
rename to tutorials/compressibleInterFoam/depthCharge2D/system/setFieldsDict
diff --git a/tutorials/compressibleLesInterFoam/depthCharge3D/0/U b/tutorials/compressibleInterFoam/depthCharge3D/0/U
similarity index 100%
rename from tutorials/compressibleLesInterFoam/depthCharge3D/0/U
rename to tutorials/compressibleInterFoam/depthCharge3D/0/U
diff --git a/tutorials/compressibleLesInterFoam/depthCharge3D/0/alpha1.org b/tutorials/compressibleInterFoam/depthCharge3D/0/alpha1.org
similarity index 100%
rename from tutorials/compressibleLesInterFoam/depthCharge3D/0/alpha1.org
rename to tutorials/compressibleInterFoam/depthCharge3D/0/alpha1.org
diff --git a/tutorials/compressibleLesInterFoam/depthCharge3D/0/pd.org b/tutorials/compressibleInterFoam/depthCharge3D/0/pd.org
similarity index 100%
rename from tutorials/compressibleLesInterFoam/depthCharge3D/0/pd.org
rename to tutorials/compressibleInterFoam/depthCharge3D/0/pd.org
diff --git a/tutorials/compressibleLesInterFoam/depthCharge3D/Allclean b/tutorials/compressibleInterFoam/depthCharge3D/Allclean
similarity index 100%
rename from tutorials/compressibleLesInterFoam/depthCharge3D/Allclean
rename to tutorials/compressibleInterFoam/depthCharge3D/Allclean
diff --git a/tutorials/compressibleLesInterFoam/depthCharge3D/Allrun b/tutorials/compressibleInterFoam/depthCharge3D/Allrun
similarity index 100%
rename from tutorials/compressibleLesInterFoam/depthCharge3D/Allrun
rename to tutorials/compressibleInterFoam/depthCharge3D/Allrun
diff --git a/tutorials/compressibleLesInterFoam/depthCharge2D/constant/LESProperties b/tutorials/compressibleInterFoam/depthCharge3D/constant/LESProperties
similarity index 98%
rename from tutorials/compressibleLesInterFoam/depthCharge2D/constant/LESProperties
rename to tutorials/compressibleInterFoam/depthCharge3D/constant/LESProperties
index 130d0947d9c4402eba4cf9ee019bdd81b319ad1b..bb84772ba51036c08aa1082c7e6720dfe9d65037 100644
--- a/tutorials/compressibleLesInterFoam/depthCharge2D/constant/LESProperties
+++ b/tutorials/compressibleInterFoam/depthCharge3D/constant/LESProperties
@@ -16,7 +16,9 @@ FoamFile
 
 LESModel        laminar;
 
-delta           smooth;
+turbulence      off;
+
+delta           cubeRootVol;
 
 laminarCoeffs
 {
diff --git a/tutorials/compressibleLesInterFoam/depthCharge3D/constant/environmentalProperties b/tutorials/compressibleInterFoam/depthCharge3D/constant/environmentalProperties
similarity index 100%
rename from tutorials/compressibleLesInterFoam/depthCharge3D/constant/environmentalProperties
rename to tutorials/compressibleInterFoam/depthCharge3D/constant/environmentalProperties
diff --git a/tutorials/compressibleLesInterFoam/depthCharge3D/constant/polyMesh/blockMeshDict b/tutorials/compressibleInterFoam/depthCharge3D/constant/polyMesh/blockMeshDict
similarity index 100%
rename from tutorials/compressibleLesInterFoam/depthCharge3D/constant/polyMesh/blockMeshDict
rename to tutorials/compressibleInterFoam/depthCharge3D/constant/polyMesh/blockMeshDict
diff --git a/tutorials/compressibleLesInterFoam/depthCharge3D/constant/polyMesh/boundary b/tutorials/compressibleInterFoam/depthCharge3D/constant/polyMesh/boundary
similarity index 75%
rename from tutorials/compressibleLesInterFoam/depthCharge3D/constant/polyMesh/boundary
rename to tutorials/compressibleInterFoam/depthCharge3D/constant/polyMesh/boundary
index 178b2ace003c711381d84ede00541b384556c3bd..3517ca55be180a00b154b971fd6945bd75fd1afc 100644
--- a/tutorials/compressibleLesInterFoam/depthCharge3D/constant/polyMesh/boundary
+++ b/tutorials/compressibleInterFoam/depthCharge3D/constant/polyMesh/boundary
@@ -1,15 +1,16 @@
 /*--------------------------------*- C++ -*----------------------------------*\
 | =========                 |                                                 |
 | \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
-|  \\    /   O peration     | Version:  dev                                   |
-|   \\  /    A nd           | Web:      http://www.OpenFOAM.org               |
-|    \\/     M anipulation  |                                                 |
+|  \\    /   O peration     | Version:  dev-09ca1eb6b56f                      |
+|   \\  /    A nd           |                                                 |
+|    \\/     M anipulation  |                                www.OpenFOAM.org |
 \*---------------------------------------------------------------------------*/
 FoamFile
 {
     version     2.0;
     format      ascii;
     class       polyBoundaryMesh;
+    location    "constant/polyMesh";
     object      boundary;
 }
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/tutorials/compressibleLesInterFoam/depthCharge3D/constant/transportProperties b/tutorials/compressibleInterFoam/depthCharge3D/constant/transportProperties
similarity index 100%
rename from tutorials/compressibleLesInterFoam/depthCharge3D/constant/transportProperties
rename to tutorials/compressibleInterFoam/depthCharge3D/constant/transportProperties
diff --git a/tutorials/compressibleInterFoam/depthCharge3D/constant/turbulenceProperties b/tutorials/compressibleInterFoam/depthCharge3D/constant/turbulenceProperties
new file mode 100644
index 0000000000000000000000000000000000000000..fe67e8fecae0729e7345802955479523972bb72d
--- /dev/null
+++ b/tutorials/compressibleInterFoam/depthCharge3D/constant/turbulenceProperties
@@ -0,0 +1,22 @@
+/*--------------------------------*- C++ -*----------------------------------*\
+| =========                 |                                                 |
+| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
+|  \\    /   O peration     | Version:  1.5                                   |
+|   \\  /    A nd           | Web:      http://www.OpenFOAM.org               |
+|    \\/     M anipulation  |                                                 |
+\*---------------------------------------------------------------------------*/
+FoamFile
+{
+    version     2.0;
+    format      ascii;
+    class       dictionary;
+    object      turbulenceProperties;
+}
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+//simulationType laminar;
+//simulationType RASModel;
+simulationType LESModel;
+
+
+// ************************************************************************* //
diff --git a/tutorials/compressibleLesInterFoam/depthCharge3D/system/controlDict b/tutorials/compressibleInterFoam/depthCharge3D/system/controlDict
similarity index 100%
rename from tutorials/compressibleLesInterFoam/depthCharge3D/system/controlDict
rename to tutorials/compressibleInterFoam/depthCharge3D/system/controlDict
diff --git a/tutorials/compressibleLesInterFoam/depthCharge3D/system/decomposeParDict b/tutorials/compressibleInterFoam/depthCharge3D/system/decomposeParDict
similarity index 100%
rename from tutorials/compressibleLesInterFoam/depthCharge3D/system/decomposeParDict
rename to tutorials/compressibleInterFoam/depthCharge3D/system/decomposeParDict
diff --git a/tutorials/compressibleLesInterFoam/depthCharge3D/system/fvSchemes b/tutorials/compressibleInterFoam/depthCharge3D/system/fvSchemes
similarity index 100%
rename from tutorials/compressibleLesInterFoam/depthCharge3D/system/fvSchemes
rename to tutorials/compressibleInterFoam/depthCharge3D/system/fvSchemes
diff --git a/tutorials/compressibleLesInterFoam/depthCharge2D/system/fvSolution b/tutorials/compressibleInterFoam/depthCharge3D/system/fvSolution
similarity index 99%
rename from tutorials/compressibleLesInterFoam/depthCharge2D/system/fvSolution
rename to tutorials/compressibleInterFoam/depthCharge3D/system/fvSolution
index f97cf54032ec4b42a7b0bb04cdd33dcd4deb1de7..868252473975e23b298727de38f9dd66fbef0b56 100644
--- a/tutorials/compressibleLesInterFoam/depthCharge2D/system/fvSolution
+++ b/tutorials/compressibleInterFoam/depthCharge3D/system/fvSolution
@@ -120,7 +120,7 @@ PISO
     nNonOrthogonalCorrectors 0;
     nAlphaCorr      1;
     nAlphaSubCycles 1;
-    cGamma          1;
+    cAlpha          1;
 }
 
 // ************************************************************************* //
diff --git a/tutorials/compressibleLesInterFoam/depthCharge3D/system/machines b/tutorials/compressibleInterFoam/depthCharge3D/system/machines
similarity index 100%
rename from tutorials/compressibleLesInterFoam/depthCharge3D/system/machines
rename to tutorials/compressibleInterFoam/depthCharge3D/system/machines
diff --git a/tutorials/compressibleLesInterFoam/depthCharge3D/system/setFieldsDict b/tutorials/compressibleInterFoam/depthCharge3D/system/setFieldsDict
similarity index 100%
rename from tutorials/compressibleLesInterFoam/depthCharge3D/system/setFieldsDict
rename to tutorials/compressibleInterFoam/depthCharge3D/system/setFieldsDict
diff --git a/tutorials/interDyMFoam/sloshingTank2D/Allrun b/tutorials/interDyMFoam/sloshingTank2D/Allrun
index 748dcf65ba56b28289c079d37d4abde3e95f3257..df799d7732174c55cd675c8ed99294bf8c4a4897 100755
--- a/tutorials/interDyMFoam/sloshingTank2D/Allrun
+++ b/tutorials/interDyMFoam/sloshingTank2D/Allrun
@@ -2,7 +2,7 @@
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
-m4 < constant/polyMesh/blockMeshDict.m4 > constant/polyMesh/blockMeshDict
+m4 constant/polyMesh/blockMeshDict.m4 > constant/polyMesh/blockMeshDict
 runApplication blockMesh
 cp 0/gamma.org 0/gamma
 runApplication setFields
diff --git a/tutorials/interDyMFoam/sloshingTank2D3DoF/Allrun b/tutorials/interDyMFoam/sloshingTank2D3DoF/Allrun
index 748dcf65ba56b28289c079d37d4abde3e95f3257..df799d7732174c55cd675c8ed99294bf8c4a4897 100755
--- a/tutorials/interDyMFoam/sloshingTank2D3DoF/Allrun
+++ b/tutorials/interDyMFoam/sloshingTank2D3DoF/Allrun
@@ -2,7 +2,7 @@
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
-m4 < constant/polyMesh/blockMeshDict.m4 > constant/polyMesh/blockMeshDict
+m4 constant/polyMesh/blockMeshDict.m4 > constant/polyMesh/blockMeshDict
 runApplication blockMesh
 cp 0/gamma.org 0/gamma
 runApplication setFields
diff --git a/tutorials/interDyMFoam/sloshingTank3D/Allrun b/tutorials/interDyMFoam/sloshingTank3D/Allrun
index 748dcf65ba56b28289c079d37d4abde3e95f3257..df799d7732174c55cd675c8ed99294bf8c4a4897 100755
--- a/tutorials/interDyMFoam/sloshingTank3D/Allrun
+++ b/tutorials/interDyMFoam/sloshingTank3D/Allrun
@@ -2,7 +2,7 @@
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
-m4 < constant/polyMesh/blockMeshDict.m4 > constant/polyMesh/blockMeshDict
+m4 constant/polyMesh/blockMeshDict.m4 > constant/polyMesh/blockMeshDict
 runApplication blockMesh
 cp 0/gamma.org 0/gamma
 runApplication setFields
diff --git a/tutorials/interDyMFoam/sloshingTank3D3DoF/Allrun b/tutorials/interDyMFoam/sloshingTank3D3DoF/Allrun
index 748dcf65ba56b28289c079d37d4abde3e95f3257..df799d7732174c55cd675c8ed99294bf8c4a4897 100755
--- a/tutorials/interDyMFoam/sloshingTank3D3DoF/Allrun
+++ b/tutorials/interDyMFoam/sloshingTank3D3DoF/Allrun
@@ -2,7 +2,7 @@
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
-m4 < constant/polyMesh/blockMeshDict.m4 > constant/polyMesh/blockMeshDict
+m4 constant/polyMesh/blockMeshDict.m4 > constant/polyMesh/blockMeshDict
 runApplication blockMesh
 cp 0/gamma.org 0/gamma
 runApplication setFields
diff --git a/tutorials/interDyMFoam/sloshingTank3D6DoF/Allrun b/tutorials/interDyMFoam/sloshingTank3D6DoF/Allrun
index 748dcf65ba56b28289c079d37d4abde3e95f3257..df799d7732174c55cd675c8ed99294bf8c4a4897 100755
--- a/tutorials/interDyMFoam/sloshingTank3D6DoF/Allrun
+++ b/tutorials/interDyMFoam/sloshingTank3D6DoF/Allrun
@@ -2,7 +2,7 @@
 # Source tutorial run functions
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
-m4 < constant/polyMesh/blockMeshDict.m4 > constant/polyMesh/blockMeshDict
+m4 constant/polyMesh/blockMeshDict.m4 > constant/polyMesh/blockMeshDict
 runApplication blockMesh
 cp 0/gamma.org 0/gamma
 runApplication setFields
diff --git a/tutorials/mhdFoam/Allrun b/tutorials/mhdFoam/Allrun
index df0077cf0531e4bd76c3c48178fc57049104f957..aca66b35332378f5c60c899af6ddd07101b6f780 100755
--- a/tutorials/mhdFoam/Allrun
+++ b/tutorials/mhdFoam/Allrun
@@ -3,8 +3,9 @@
 . $WM_PROJECT_DIR/bin/tools/RunFunctions
 
 # Get application name from directory
-application="mdEquilibrationFoam"
+application="mhdFoam"
 
 (cd hartmann && runApplication blockMesh)
 (cd hartmann && runApplication $application)
+(cd hartmann && runApplication foamCalc components U)
 (cd hartmann && runApplication sample)
diff --git a/tutorials/mhdFoam/hartmann/constant/polyMesh/boundary b/tutorials/mhdFoam/hartmann/constant/polyMesh/boundary
index acc4e4c3901830fa60e474db082969f05dad5b2e..0be28ca2082b6a0b68d2ee50bd36df6db0680dac 100644
--- a/tutorials/mhdFoam/hartmann/constant/polyMesh/boundary
+++ b/tutorials/mhdFoam/hartmann/constant/polyMesh/boundary
@@ -1,8 +1,8 @@
 /*--------------------------------*- C++ -*----------------------------------*\
 | =========                 |                                                 |
 | \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
-|  \\    /   O peration     | Version:  1.5                                   |
-|   \\  /    A nd           | Web:      http://www.OpenFOAM.org               |
+|  \\    /   O peration     | Version:  dev-8cbffd16687e                      |
+|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
 |    \\/     M anipulation  |                                                 |
 \*---------------------------------------------------------------------------*/
 FoamFile
@@ -10,6 +10,7 @@ FoamFile
     version     2.0;
     format      ascii;
     class       polyBoundaryMesh;
+    location    "constant/polyMesh";
     object      boundary;
 }
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/tutorials/mhdFoam/hartmann/system/sampleDict b/tutorials/mhdFoam/hartmann/system/sampleDict
index d7c5a97c45a9ca29dfdaf1702621deb5cf2f7c58..e62120c869735ae45ea76e62cde6f7ae2d551a3b 100644
--- a/tutorials/mhdFoam/hartmann/system/sampleDict
+++ b/tutorials/mhdFoam/hartmann/system/sampleDict
@@ -18,9 +18,9 @@ interpolationScheme cellPoint;
 
 setFormat     raw;
 
-sets      
+sets
 (
-    line_centreProfile 
+    line_centreProfile
     {
         type            uniform;
 
@@ -34,9 +34,9 @@ sets
 surfaces
 ();
 
-fields          
+fields
 (
-    U.component(0)
+    Ux
 );
 
 // ************************************************************************* //
diff --git a/tutorials/rhoSonicFoam/shockTube/Allrun b/tutorials/rhoSonicFoam/shockTube/Allrun
new file mode 100755
index 0000000000000000000000000000000000000000..6ce183dba87274008dc2920bfaaeb0721c53aff2
--- /dev/null
+++ b/tutorials/rhoSonicFoam/shockTube/Allrun
@@ -0,0 +1,10 @@
+#!/bin/sh
+# Source tutorial run functions
+. $WM_PROJECT_DIR/bin/tools/RunFunctions
+
+# Get application name from directory
+application="rhoSonicFoam"
+
+runApplication blockMesh
+runApplication setFields
+runApplication $application
diff --git a/tutorials/twoPhaseEulerFoam/bed2/constant/polyMesh/boundary b/tutorials/twoPhaseEulerFoam/bed2/constant/polyMesh/boundary
index 8b28212be9ff78cf8b96cbff88c8877307023d04..e2e0e3a9f23e9f26addc8bba6e079d4e67c0de81 100644
--- a/tutorials/twoPhaseEulerFoam/bed2/constant/polyMesh/boundary
+++ b/tutorials/twoPhaseEulerFoam/bed2/constant/polyMesh/boundary
@@ -1,8 +1,8 @@
 /*--------------------------------*- C++ -*----------------------------------*\
 | =========                 |                                                 |
 | \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
-|  \\    /   O peration     | Version:  1.5                                   |
-|   \\  /    A nd           | Web:      http://www.OpenFOAM.org               |
+|  \\    /   O peration     | Version:  dev-8cbffd16687e                      |
+|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
 |    \\/     M anipulation  |                                                 |
 \*---------------------------------------------------------------------------*/
 FoamFile
@@ -10,39 +10,37 @@ FoamFile
     version     2.0;
     format      ascii;
     class       polyBoundaryMesh;
+    location    "constant/polyMesh";
     object      boundary;
 }
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 4
 (
-inlet
-{
-    type patch;
-    nFaces 30;
-    startFace 11770;
-}
-
-outlet
-{
-    type patch;
-    nFaces 30;
-    startFace 11800;
-}
-
-walls
-{
-    type wall;
-    nFaces 400;
-    startFace 11830;
-}
-
-frontAndBackPlanes
-{
-    type empty;
-    nFaces 12000;
-    startFace 12230;
-}
+    inlet
+    {
+        type            patch;
+        nFaces          30;
+        startFace       11770;
+    }
+    outlet
+    {
+        type            patch;
+        nFaces          30;
+        startFace       11800;
+    }
+    walls
+    {
+        type            wall;
+        nFaces          400;
+        startFace       11830;
+    }
+    frontAndBackPlanes
+    {
+        type            empty;
+        nFaces          12000;
+        startFace       12230;
+    }
 )
 
 // ************************************************************************* //
diff --git a/tutorials/twoPhaseEulerFoam/bed2/system/controlDict b/tutorials/twoPhaseEulerFoam/bed2/system/controlDict
index 8deea7de4ad2e0cf25ab9144ca27308e8796f91e..85c8fc5cb84d409f16b9751dc6c3d99182104c1f 100644
--- a/tutorials/twoPhaseEulerFoam/bed2/system/controlDict
+++ b/tutorials/twoPhaseEulerFoam/bed2/system/controlDict
@@ -60,6 +60,8 @@ functions
         // Where to load it from (if not already in solver)
         functionObjectLibs ("libfieldAverage.so");
 
+        outputControl outputTime;
+
         // Fields to be  averaged - runTime modifiable
         fields
         (
diff --git a/wmake/rules/General/flex++ b/wmake/rules/General/flex++
index 823649beababbba8eba77924ed143e07b2536f37..6f68d78001b65064e3407c2d4bf0453d271384f9 100644
--- a/wmake/rules/General/flex++
+++ b/wmake/rules/General/flex++
@@ -1,6 +1,6 @@
 .SUFFIXES: .L
 
-Ltoo = flex++ -f $$SOURCE ; mv lex.yy.cc $*.C ; $(CC) $(c++FLAGS) -c $*.C -o $@ 
+Ltoo = flex --c++ -f $$SOURCE ; mv lex.yy.cc $*.C ; $(CC) $(c++FLAGS) -c $*.C -o $@
 
 .L.dep:
 	$(MAKE_DEP)
diff --git a/wmake/rules/SiCortex64Gcc/X b/wmake/rules/SiCortex64Gcc/X
new file mode 100644
index 0000000000000000000000000000000000000000..5d1f9c5cc54b4689118c6f1f54f0a2d6d7a29827
--- /dev/null
+++ b/wmake/rules/SiCortex64Gcc/X
@@ -0,0 +1,3 @@
+XFLAGS     =
+XINC       = $(XFLAGS) -I/usr/X11R6/include
+XLIBS      = -L/usr/X11R6/lib64 -lXext -lX11
diff --git a/wmake/rules/SiCortex64Gcc/c b/wmake/rules/SiCortex64Gcc/c
new file mode 100644
index 0000000000000000000000000000000000000000..21a13e04b8cb58a2ea6f7385d5d56a3bedba066b
--- /dev/null
+++ b/wmake/rules/SiCortex64Gcc/c
@@ -0,0 +1,17 @@
+.SUFFIXES: .c .h
+
+cWARN        = -Wall
+
+cc          = gcc -mabi=64
+#cc          = scgcc -mabi=64
+
+include $(RULES)/c$(WM_COMPILE_OPTION)
+
+cFLAGS      = -G0 $(GFLAGS) $(cWARN) $(cOPT) $(cDBUG) $(LIB_HEADER_DIRS) -fPIC
+
+ctoo        = $(WM_SCHEDULER) $(cc) $(cFLAGS) -c $$SOURCE -o $@
+
+LINK_LIBS   = $(cDBUG)
+
+LINKLIBSO   = $(cc) -shared
+LINKEXE     = $(cc) -Xlinker -z -Xlinker nodefs
diff --git a/wmake/rules/SiCortex64Gcc/c++ b/wmake/rules/SiCortex64Gcc/c++
new file mode 100644
index 0000000000000000000000000000000000000000..f0a8cf5041d46e58888c74e711e087c7f887cbdc
--- /dev/null
+++ b/wmake/rules/SiCortex64Gcc/c++
@@ -0,0 +1,22 @@
+.SUFFIXES: .C .cxx .cc .cpp
+
+c++WARN     = -Wall -Wno-strict-aliasing -Wextra -Wno-unused-parameter -Wold-style-cast
+
+CC          = g++ -mabi=64
+#CC          = scg++ -mabi=64
+
+include $(RULES)/c++$(WM_COMPILE_OPTION)
+
+ptFLAGS     = -DNoRepository -ftemplate-depth-40
+
+c++FLAGS    = -G0 $(GFLAGS) $(c++WARN) $(c++OPT) $(c++DBUG) $(ptFLAGS) $(LIB_HEADER_DIRS) -fPIC
+
+Ctoo        = $(WM_SCHEDULER) $(CC) $(c++FLAGS) -c $$SOURCE -o $@
+cxxtoo      = $(Ctoo)
+cctoo       = $(Ctoo)
+cpptoo      = $(Ctoo)
+
+LINK_LIBS   = $(c++DBUG)
+
+LINKLIBSO   = $(CC) $(c++FLAGS) -shared
+LINKEXE     = $(CC) $(c++FLAGS)
diff --git a/wmake/rules/SiCortex64Gcc/c++Debug b/wmake/rules/SiCortex64Gcc/c++Debug
new file mode 100644
index 0000000000000000000000000000000000000000..19bdb9c3346fc7a69380dfedd6e7911fe220a965
--- /dev/null
+++ b/wmake/rules/SiCortex64Gcc/c++Debug
@@ -0,0 +1,2 @@
+c++DBUG    = -ggdb3 -DFULLDEBUG
+c++OPT      = -O0 -fdefault-inline
diff --git a/wmake/rules/SiCortex64Gcc/c++Opt b/wmake/rules/SiCortex64Gcc/c++Opt
new file mode 100644
index 0000000000000000000000000000000000000000..636689e9175bf6ba1007c8316e94855b11f35332
--- /dev/null
+++ b/wmake/rules/SiCortex64Gcc/c++Opt
@@ -0,0 +1,4 @@
+c++DBUG     = 
+c++OPT      = -O3
+#c++OPT      = -O3
+# -ftree-vectorize -ftree-vectorizer-verbose=3
diff --git a/wmake/rules/SiCortex64Gcc/c++Prof b/wmake/rules/SiCortex64Gcc/c++Prof
new file mode 100644
index 0000000000000000000000000000000000000000..3bda4dad55e898a8198f6e8bfe21e8d829d7230a
--- /dev/null
+++ b/wmake/rules/SiCortex64Gcc/c++Prof
@@ -0,0 +1,2 @@
+c++DBUG    = -pg
+c++OPT     = -O2
diff --git a/wmake/rules/SiCortex64Gcc/cDebug b/wmake/rules/SiCortex64Gcc/cDebug
new file mode 100644
index 0000000000000000000000000000000000000000..72b638f458220e329d52b59e3566a3c807101f9d
--- /dev/null
+++ b/wmake/rules/SiCortex64Gcc/cDebug
@@ -0,0 +1,2 @@
+cDBUG       = -ggdb -DFULLDEBUG
+cOPT        = -O1 -fdefault-inline -finline-functions
diff --git a/wmake/rules/SiCortex64Gcc/cOpt b/wmake/rules/SiCortex64Gcc/cOpt
new file mode 100644
index 0000000000000000000000000000000000000000..aaaebef3d3e351358499981b5d4ef1dd2caace7b
--- /dev/null
+++ b/wmake/rules/SiCortex64Gcc/cOpt
@@ -0,0 +1,2 @@
+cDBUG       = 
+cOPT        = -O3 -fno-gcse
diff --git a/wmake/rules/SiCortex64Gcc/cProf b/wmake/rules/SiCortex64Gcc/cProf
new file mode 100644
index 0000000000000000000000000000000000000000..ca3ac9bf5f0cd61fe99e0f05fa1bd4bdf9fa6cf7
--- /dev/null
+++ b/wmake/rules/SiCortex64Gcc/cProf
@@ -0,0 +1,2 @@
+cDBUG       = -pg
+cOPT        = -O2
diff --git a/wmake/rules/SiCortex64Gcc/flex++ b/wmake/rules/SiCortex64Gcc/flex++
new file mode 100644
index 0000000000000000000000000000000000000000..d745628aab811f36da7ffa1f40444583af479041
--- /dev/null
+++ b/wmake/rules/SiCortex64Gcc/flex++
@@ -0,0 +1,6 @@
+.SUFFIXES: .L
+
+Ltoo = flex --c++ -f $$SOURCE ; mv lex.yy.cc $*.C ; $(CC) $(c++FLAGS) -c $*.C -o $@ 
+
+.L.dep:
+	$(MAKE_DEP)
diff --git a/wmake/rules/SiCortex64Gcc/general b/wmake/rules/SiCortex64Gcc/general
new file mode 100644
index 0000000000000000000000000000000000000000..11b48acc3fc0c67c177b464c70de18248881c12d
--- /dev/null
+++ b/wmake/rules/SiCortex64Gcc/general
@@ -0,0 +1,11 @@
+CPP        = /lib/cpp $(GFLAGS)
+LD         = ld -A64
+
+PROJECT_LIBS = -l$(WM_PROJECT) -liberty -ldl
+
+include $(GENERAL_RULES)/standard
+
+include $(RULES)/X
+include $(RULES)/c
+include $(RULES)/c++
+include $(GENERAL_RULES)/cint
diff --git a/wmake/rules/SiCortex64Gcc/mplib b/wmake/rules/SiCortex64Gcc/mplib
new file mode 100644
index 0000000000000000000000000000000000000000..8a84b4014695e82f55b709ed5144f4b528412137
--- /dev/null
+++ b/wmake/rules/SiCortex64Gcc/mplib
@@ -0,0 +1,3 @@
+PFLAGS     = 
+PINC       = 
+PLIBS      = 
diff --git a/wmake/rules/SiCortex64Gcc/mplibMPI b/wmake/rules/SiCortex64Gcc/mplibMPI
new file mode 100644
index 0000000000000000000000000000000000000000..4b284e2439dd849fc5ec1e3b2d6a578babd3204c
--- /dev/null
+++ b/wmake/rules/SiCortex64Gcc/mplibMPI
@@ -0,0 +1,3 @@
+PFLAGS     = -DMPICH_SKIP_MPICXX
+PINC       = 
+PLIBS      = -lscmpi
diff --git a/wmake/wmakePrintBuild b/wmake/wmakePrintBuild
index 4baefe616c4bc043a2f7daa3b61b1147da7ced4b..13009261da30da1f22333f3c5e386e66e6f87977 100755
--- a/wmake/wmakePrintBuild
+++ b/wmake/wmakePrintBuild
@@ -93,14 +93,19 @@ then
     # specified a version - no error possible
     rc=0
 else
-    # building under git (get the head SHA1)
-    version=$(git show-ref --hash=12 --head HEAD 2>/dev/null)
-    rc=$?
+    # get the head SHA1 when building under git
+    # if there are multiple values (eg, HEAD, origin/HEAD, ...)
+    # only take the first one, which is 'HEAD'
+    version=$(git show-ref --hash=12 --head HEAD 2>/dev/null | head -1)
 
-    # prefix with WM_PROJECT_VERSION
-    if [ $rc -eq 0 ]
+    if [ -n "$version" ]
     then
+        # mark as success and prefix with WM_PROJECT_VERSION
+        rc=0
         version="${WM_PROJECT_VERSION}-$version"
+    else
+        # mark as failure
+        rc=1
     fi
 fi