diff --git a/applications/solvers/incompressible/pimpleFoam/SRFPimpleFoam/UrelEqn.H b/applications/solvers/incompressible/pimpleFoam/SRFPimpleFoam/UrelEqn.H
index a86b142276ba8cccd075949e562729427648ed96..8b496a6aed5f73765f5156be78af592d1c97e65d 100644
--- a/applications/solvers/incompressible/pimpleFoam/SRFPimpleFoam/UrelEqn.H
+++ b/applications/solvers/incompressible/pimpleFoam/SRFPimpleFoam/UrelEqn.H
@@ -9,4 +9,6 @@
 
     UrelEqn().relax();
 
-    solve(UrelEqn() == -fvc::grad(p));
+    sources.constrain(UrelEqn());
+
+    solve(UrelEqn() == -fvc::grad(p) + sources(Urel));
diff --git a/applications/solvers/incompressible/pimpleFoam/SRFPimpleFoam/pEqn.H b/applications/solvers/incompressible/pimpleFoam/SRFPimpleFoam/pEqn.H
index df3b09adc642da17702decfcd0e0d33f0296d840..72c0d66290957d3e37016cf535f2a34711b4fe51 100644
--- a/applications/solvers/incompressible/pimpleFoam/SRFPimpleFoam/pEqn.H
+++ b/applications/solvers/incompressible/pimpleFoam/SRFPimpleFoam/pEqn.H
@@ -1,5 +1,5 @@
 volScalarField rAUrel(1.0/UrelEqn().A());
-Urel = rAUrel*UrelEqn().H();
+Urel = rAUrel*(UrelEqn() == sources(Urel))().H();
 
 if (pimple.nCorrPISO() <= 1)
 {
@@ -37,3 +37,4 @@ p.relax();
 // Momentum corrector
 Urel -= rAUrel*fvc::grad(p);
 Urel.correctBoundaryConditions();
+sources.correct(Urel);
diff --git a/applications/solvers/incompressible/pimpleFoam/UEqn.H b/applications/solvers/incompressible/pimpleFoam/UEqn.H
index d7be010a9f91f0515516495b6abf0ea84becab9b..a6aef51dafb35a9fee2033b0a07a38f8404f2296 100644
--- a/applications/solvers/incompressible/pimpleFoam/UEqn.H
+++ b/applications/solvers/incompressible/pimpleFoam/UEqn.H
@@ -5,8 +5,6 @@ tmp<fvVectorMatrix> UEqn
     fvm::ddt(U)
   + fvm::div(phi, U)
   + turbulence->divDevReff(U)
-  ==
-    sources(U)
 );
 
 UEqn().relax();
@@ -17,5 +15,5 @@ volScalarField rAU(1.0/UEqn().A());
 
 if (pimple.momentumPredictor())
 {
-    solve(UEqn() == -fvc::grad(p));
+    solve(UEqn() == -fvc::grad(p) + sources(U));
 }
diff --git a/applications/solvers/incompressible/pimpleFoam/pEqn.H b/applications/solvers/incompressible/pimpleFoam/pEqn.H
index 61acd7d69788d444525800cbce5ccf778af0e461..55062637c215dd4cca03f4f0142505c3240f9f7a 100644
--- a/applications/solvers/incompressible/pimpleFoam/pEqn.H
+++ b/applications/solvers/incompressible/pimpleFoam/pEqn.H
@@ -1,4 +1,4 @@
-U = rAU*UEqn().H();
+U = rAU*(UEqn() == sources(U))().H();
 
 if (pimple.nCorrPISO() <= 1)
 {
@@ -36,3 +36,4 @@ p.relax();
 
 U -= rAU*fvc::grad(p);
 U.correctBoundaryConditions();
+sources.correct(U);
diff --git a/applications/solvers/incompressible/pimpleFoam/pimpleDyMFoam/UEqn.H b/applications/solvers/incompressible/pimpleFoam/pimpleDyMFoam/UEqn.H
index 5a211caa9c2f2e6bbf5614928d1eb6d35e307777..618816f5fe1e3a54d658632ab07d43f12920e9f0 100644
--- a/applications/solvers/incompressible/pimpleFoam/pimpleDyMFoam/UEqn.H
+++ b/applications/solvers/incompressible/pimpleFoam/pimpleDyMFoam/UEqn.H
@@ -9,9 +9,11 @@ tmp<fvVectorMatrix> UEqn
 
 UEqn().relax();
 
+sources.constrain(UEqn());
+
 rAU = 1.0/UEqn().A();
 
 if (pimple.momentumPredictor())
 {
-    solve(UEqn() == -fvc::grad(p));
+    solve(UEqn() == -fvc::grad(p) + sources(U));
 }
diff --git a/applications/solvers/incompressible/pimpleFoam/pimpleDyMFoam/pEqn.H b/applications/solvers/incompressible/pimpleFoam/pimpleDyMFoam/pEqn.H
index aeef26a83770ff7e235bf60f7ae15c0bd82417cb..dd90826e7d0f62b2e08f2d084dd30b99b788c2e6 100644
--- a/applications/solvers/incompressible/pimpleFoam/pimpleDyMFoam/pEqn.H
+++ b/applications/solvers/incompressible/pimpleFoam/pimpleDyMFoam/pEqn.H
@@ -1,4 +1,4 @@
-U = rAU*UEqn().H();
+U = rAU*(UEqn() == sources(U))().H();
 
 if (pimple.nCorrPISO() <= 1)
 {
@@ -46,3 +46,4 @@ fvc::makeRelative(phi, U);
 
 U -= rAU*fvc::grad(p);
 U.correctBoundaryConditions();
+sources.correct(U);
diff --git a/applications/solvers/incompressible/potentialFreeSurfaceFoam/UEqn.H b/applications/solvers/incompressible/potentialFreeSurfaceFoam/UEqn.H
index c869df39a235b7f8bdc94b7a8bd552be584defc7..74e84d9bfc9a9c41ce65b7f570ece27c735bcdb8 100644
--- a/applications/solvers/incompressible/potentialFreeSurfaceFoam/UEqn.H
+++ b/applications/solvers/incompressible/potentialFreeSurfaceFoam/UEqn.H
@@ -3,8 +3,6 @@ tmp<fvVectorMatrix> UEqn
     fvm::ddt(U)
   + fvm::div(phi, U)
   + turbulence->divDevReff(U)
-  ==
-    sources(U)
 );
 
 
@@ -14,5 +12,5 @@ sources.constrain(UEqn());
 
 if (pimple.momentumPredictor())
 {
-    solve(UEqn() == -fvc::grad(p_gh));
+    solve(UEqn() == -fvc::grad(p_gh) + sources(U));
 }
diff --git a/applications/solvers/incompressible/potentialFreeSurfaceFoam/pEqn.H b/applications/solvers/incompressible/potentialFreeSurfaceFoam/pEqn.H
index a5adeb9e9142f00802c3ba62db09f2834cc7f886..d7cf6cd5b17fe7dc27377bb65e5676768542738c 100644
--- a/applications/solvers/incompressible/potentialFreeSurfaceFoam/pEqn.H
+++ b/applications/solvers/incompressible/potentialFreeSurfaceFoam/pEqn.H
@@ -1,7 +1,7 @@
 volScalarField rAU(1.0/UEqn().A());
 surfaceScalarField rAUf(rAU.name() + 'f', fvc::interpolate(rAU));
 
-U = rAU*UEqn().H();
+U = rAU*(UEqn() == sources(U))().H();
 
 if (pimple.nCorrPISO() <= 1)
 {
@@ -41,3 +41,4 @@ p = p_gh + (g & (mesh.C() + zeta - refLevel));
 
 U -= rAU*fvc::grad(p_gh);
 U.correctBoundaryConditions();
+sources.correct(U);
diff --git a/applications/solvers/incompressible/simpleFoam/MRFSimpleFoam/pEqn.H b/applications/solvers/incompressible/simpleFoam/MRFSimpleFoam/pEqn.H
index 2d2540d3038a8e28c966ab847fb5fe6d22798749..93d6537b6a99dce1380fd3ecb50d319a2254c3c7 100644
--- a/applications/solvers/incompressible/simpleFoam/MRFSimpleFoam/pEqn.H
+++ b/applications/solvers/incompressible/simpleFoam/MRFSimpleFoam/pEqn.H
@@ -34,4 +34,5 @@
     // Momentum corrector
     U -= rAU*fvc::grad(p);
     U.correctBoundaryConditions();
+    sources.correct(U);
 }
diff --git a/applications/solvers/incompressible/simpleFoam/SRFSimpleFoam/pEqn.H b/applications/solvers/incompressible/simpleFoam/SRFSimpleFoam/pEqn.H
index 54eab9cba7b6c2aa9e110a534c9f6e00ee33ff41..b9a9079b92ca8f21ac0bf65fbd23c98c29a46508 100644
--- a/applications/solvers/incompressible/simpleFoam/SRFSimpleFoam/pEqn.H
+++ b/applications/solvers/incompressible/simpleFoam/SRFSimpleFoam/pEqn.H
@@ -34,4 +34,5 @@
     // Momentum corrector
     Urel -= rAUrel*fvc::grad(p);
     Urel.correctBoundaryConditions();
+    sources.correct(Urel);
 }
diff --git a/applications/solvers/incompressible/simpleFoam/pEqn.H b/applications/solvers/incompressible/simpleFoam/pEqn.H
index 966dedb61688d8c98d50cfd2b83163ce874903a4..78dd40500babb1cea0a56903032b5bb739f5cda7 100644
--- a/applications/solvers/incompressible/simpleFoam/pEqn.H
+++ b/applications/solvers/incompressible/simpleFoam/pEqn.H
@@ -34,4 +34,5 @@
     // Momentum corrector
     U -= rAU*fvc::grad(p);
     U.correctBoundaryConditions();
+    sources.correct(U);
 }
diff --git a/applications/solvers/incompressible/simpleFoam/porousSimpleFoam/Make/options b/applications/solvers/incompressible/simpleFoam/porousSimpleFoam/Make/options
index f1887d9aff0c41bc0b8ae9164e8b783d975522a2..8ffc7f6d586a11055aa706b9fd6038b6662998a3 100644
--- a/applications/solvers/incompressible/simpleFoam/porousSimpleFoam/Make/options
+++ b/applications/solvers/incompressible/simpleFoam/porousSimpleFoam/Make/options
@@ -5,11 +5,16 @@ EXE_INC = \
     -I$(LIB_SRC)/transportModels \
     -I$(LIB_SRC)/transportModels/incompressible/singlePhaseTransportModel \
     -I$(LIB_SRC)/finiteVolume/lnInclude \
-    -I$(LIB_SRC)/meshTools/lnInclude
+    -I$(LIB_SRC)/meshTools/lnInclude \
+    -I$(LIB_SRC)/fieldSources/lnInclude \
+    -I$(LIB_SRC)/sampling/lnInclude
+
 
 EXE_LIBS = \
     -lincompressibleTurbulenceModel \
     -lincompressibleRASModels \
     -lincompressibleTransportModels \
     -lfiniteVolume \
-    -lmeshTools
+    -lmeshTools \
+    -lfieldSources \
+    -lsampling
diff --git a/applications/solvers/lagrangian/LTSReactingParcelFoam/UEqn.H b/applications/solvers/lagrangian/LTSReactingParcelFoam/UEqn.H
index 70f752019068876aae9753ab101b6fd0a3fcb9ef..b381b2901d3776a69c403f623176f49d4761dfbd 100644
--- a/applications/solvers/lagrangian/LTSReactingParcelFoam/UEqn.H
+++ b/applications/solvers/lagrangian/LTSReactingParcelFoam/UEqn.H
@@ -7,7 +7,6 @@
      ==
         rho.dimensionedInternalField()*g
       + parcels.SU(U)
-      + sources(rho, U)
     );
 
     sources.constrain(UEqn);
@@ -16,5 +15,5 @@
 
     if (pimple.momentumPredictor())
     {
-        solve(UEqn == -fvc::grad(p));
+        solve(UEqn == -fvc::grad(p) + sources(rho, U));
     }
diff --git a/applications/solvers/lagrangian/LTSReactingParcelFoam/pEqn.H b/applications/solvers/lagrangian/LTSReactingParcelFoam/pEqn.H
index 141faa30bf2ea0fe7e738720fa5977a22d338bb2..8a77a2656e4e371f6fd0acb45c5662e9a746875a 100644
--- a/applications/solvers/lagrangian/LTSReactingParcelFoam/pEqn.H
+++ b/applications/solvers/lagrangian/LTSReactingParcelFoam/pEqn.H
@@ -6,7 +6,7 @@
     thermo.rho() -= psi*p;
 
     volScalarField rAU(1.0/UEqn.A());
-    U = rAU*UEqn.H();
+    U = rAU*(UEqn == sources(rho, U))().H();
 
     if (pZones.size() > 0)
     {
@@ -60,6 +60,7 @@
 
     U -= rAU*fvc::grad(p);
     U.correctBoundaryConditions();
+    sources.correct(U);
 
     rho = thermo.rho();
     rho = max(rho, rhoMin);
diff --git a/applications/solvers/lagrangian/coalChemistryFoam/UEqn.H b/applications/solvers/lagrangian/coalChemistryFoam/UEqn.H
index fe7b047d9a24e41d4baa7f54324f75e3cc08f160..24f56e83d23232a5a3e97018f420f73cd13f4abc 100644
--- a/applications/solvers/lagrangian/coalChemistryFoam/UEqn.H
+++ b/applications/solvers/lagrangian/coalChemistryFoam/UEqn.H
@@ -7,7 +7,6 @@
         rho.dimensionedInternalField()*g
       + coalParcels.SU(U)
       + limestoneParcels.SU(U)
-      + sources(rho, U)
     );
 
     UEqn.relax();
@@ -16,6 +15,6 @@
 
     if (pimple.momentumPredictor())
     {
-        solve(UEqn == -fvc::grad(p));
+        solve(UEqn == -fvc::grad(p) + sources(rho, U));
         K = 0.5*magSqr(U);
     }
diff --git a/applications/solvers/lagrangian/coalChemistryFoam/pEqn.H b/applications/solvers/lagrangian/coalChemistryFoam/pEqn.H
index 56435d31ce12c0c67ef9b8730b49022048c824ef..cb8553bbfbb4615d6a0934faaaefca80a027f95e 100644
--- a/applications/solvers/lagrangian/coalChemistryFoam/pEqn.H
+++ b/applications/solvers/lagrangian/coalChemistryFoam/pEqn.H
@@ -1,7 +1,7 @@
 rho = thermo.rho();
 
 volScalarField rAU(1.0/UEqn.A());
-U = rAU*UEqn.H();
+U = rAU*(UEqn == sources(rho, U))().H();
 
 if (pimple.transonic())
 {
@@ -74,6 +74,8 @@ else
 
 U -= rAU*fvc::grad(p);
 U.correctBoundaryConditions();
+sources.correct(U);
+
 K = 0.5*magSqr(U);
 
 dpdt = fvc::ddt(p);
diff --git a/applications/solvers/lagrangian/porousExplicitSourceReactingParcelFoam/UEqn.H b/applications/solvers/lagrangian/porousExplicitSourceReactingParcelFoam/UEqn.H
index 28f6f81d9f0f2c1c8499d292d5d8473c0233bf84..ce25309532bd6f99d79bc79bb6052107c082540b 100644
--- a/applications/solvers/lagrangian/porousExplicitSourceReactingParcelFoam/UEqn.H
+++ b/applications/solvers/lagrangian/porousExplicitSourceReactingParcelFoam/UEqn.H
@@ -7,7 +7,6 @@
      ==
         rho.dimensionedInternalField()*g
       + parcels.SU(U)
-      + sources(rho, U)
     );
 
     UEqn.relax();
@@ -18,7 +17,7 @@
 
     if (pimple.momentumPredictor())
     {
-        solve(UEqn == -fvc::grad(p));
+        solve(UEqn == -fvc::grad(p) + sources(rho, U));
         K = 0.5*magSqr(U);
     }
 
diff --git a/applications/solvers/lagrangian/porousExplicitSourceReactingParcelFoam/pEqn.H b/applications/solvers/lagrangian/porousExplicitSourceReactingParcelFoam/pEqn.H
index 080faeccedd2c9cd2d4a85d762510d6ee796ea19..6ed7affe77c42f3280f66f4ec5df56520a2a7b74 100644
--- a/applications/solvers/lagrangian/porousExplicitSourceReactingParcelFoam/pEqn.H
+++ b/applications/solvers/lagrangian/porousExplicitSourceReactingParcelFoam/pEqn.H
@@ -6,7 +6,7 @@
     thermo.rho() -= psi*p;
 
     volScalarField rAU(1.0/UEqn.A());
-    U = rAU*UEqn.H();
+    U = rAU*(UEqn == sources(rho, U))().H();
 
     if (pZones.size() > 0)
     {
@@ -59,6 +59,8 @@
 
     U -= rAU*fvc::grad(p);
     U.correctBoundaryConditions();
+    sources.correct(U);
+
     K = 0.5*magSqr(U);
 
     dpdt = fvc::ddt(p);
diff --git a/applications/solvers/lagrangian/sprayFoam/Make/options b/applications/solvers/lagrangian/sprayFoam/Make/options
index f9cb15cc2f13d2e82e8b2dbe335191b79071759b..9d6d7d5398124134f399ab3162a7c97535eef45d 100644
--- a/applications/solvers/lagrangian/sprayFoam/Make/options
+++ b/applications/solvers/lagrangian/sprayFoam/Make/options
@@ -1,4 +1,5 @@
 EXE_INC = \
+    -I$(FOAM_SOLVERS)/lagrangian/reactingParcelFoam \
     -I$(LIB_SRC)/finiteVolume/lnInclude \
     -I${LIB_SRC}/meshTools/lnInclude \
     -I$(LIB_SRC)/turbulenceModels/compressible/turbulenceModel \
@@ -20,8 +21,7 @@ EXE_INC = \
     -I$(LIB_SRC)/ODE/lnInclude \
     -I$(LIB_SRC)/regionModels/regionModel/lnInclude \
     -I$(LIB_SRC)/regionModels/surfaceFilmModels/lnInclude \
-    -I$(LIB_SRC)/combustionModels/lnInclude \
-    -I$(FOAM_SOLVERS)/lagrangian/reactingParcelFoam
+    -I$(LIB_SRC)/combustionModels/lnInclude
 
 
 EXE_LIBS = \
diff --git a/applications/solvers/lagrangian/sprayFoam/sprayEnginFoam/Make/files b/applications/solvers/lagrangian/sprayFoam/sprayEngineFoam/Make/files
similarity index 100%
rename from applications/solvers/lagrangian/sprayFoam/sprayEnginFoam/Make/files
rename to applications/solvers/lagrangian/sprayFoam/sprayEngineFoam/Make/files
diff --git a/applications/solvers/lagrangian/sprayFoam/sprayEnginFoam/Make/options b/applications/solvers/lagrangian/sprayFoam/sprayEngineFoam/Make/options
similarity index 100%
rename from applications/solvers/lagrangian/sprayFoam/sprayEnginFoam/Make/options
rename to applications/solvers/lagrangian/sprayFoam/sprayEngineFoam/Make/options
diff --git a/applications/solvers/lagrangian/sprayFoam/sprayEnginFoam/createClouds.H b/applications/solvers/lagrangian/sprayFoam/sprayEngineFoam/createClouds.H
similarity index 100%
rename from applications/solvers/lagrangian/sprayFoam/sprayEnginFoam/createClouds.H
rename to applications/solvers/lagrangian/sprayFoam/sprayEngineFoam/createClouds.H
diff --git a/applications/solvers/lagrangian/sprayFoam/sprayEnginFoam/logSummary.H b/applications/solvers/lagrangian/sprayFoam/sprayEngineFoam/logSummary.H
similarity index 100%
rename from applications/solvers/lagrangian/sprayFoam/sprayEnginFoam/logSummary.H
rename to applications/solvers/lagrangian/sprayFoam/sprayEngineFoam/logSummary.H
diff --git a/applications/solvers/lagrangian/sprayFoam/sprayEngineFoam/pEqn.H b/applications/solvers/lagrangian/sprayFoam/sprayEngineFoam/pEqn.H
new file mode 100644
index 0000000000000000000000000000000000000000..5109788ea13c896f9e8e989266d546125e958691
--- /dev/null
+++ b/applications/solvers/lagrangian/sprayFoam/sprayEngineFoam/pEqn.H
@@ -0,0 +1,73 @@
+rho = thermo.rho();
+
+volScalarField rAU(1.0/UEqn.A());
+U = rAU*UEqn.H();
+
+if (pimple.transonic())
+{
+    surfaceScalarField phid
+    (
+        "phid",
+        fvc::interpolate(psi)
+       *(
+            ((fvc::interpolate(U) & mesh.Sf()) - fvc::meshPhi(rho, U))
+          + fvc::ddtPhiCorr(rAU, rho, U, phi)
+        )
+    );
+
+    while (pimple.correctNonOrthogonal())
+    {
+        fvScalarMatrix pEqn
+        (
+            fvm::ddt(psi, p)
+          + fvm::div(phid, p)
+          - fvm::laplacian(rho*rAU, p)
+         ==
+            parcels.Srho()
+        );
+
+        pEqn.solve(mesh.solver(p.select(pimple.finalInnerIter())));
+
+        if (pimple.finalNonOrthogonalIter())
+        {
+            phi == pEqn.flux();
+        }
+    }
+}
+else
+{
+    phi =
+        fvc::interpolate(rho)
+       *(
+            ((fvc::interpolate(U) & mesh.Sf()) - fvc::meshPhi(rho, U))
+          + fvc::ddtPhiCorr(rAU, rho, U, phi)
+        );
+
+    while (pimple.correctNonOrthogonal())
+    {
+        fvScalarMatrix pEqn
+        (
+            fvm::ddt(psi, p)
+          + fvc::div(phi)
+          - fvm::laplacian(rho*rAU, p)
+         ==
+            parcels.Srho()
+        );
+
+        pEqn.solve(mesh.solver(p.select(pimple.finalInnerIter())));
+
+        if (pimple.finalNonOrthogonalIter())
+        {
+            phi += pEqn.flux();
+        }
+    }
+}
+
+#include "rhoEqn.H"
+#include "compressibleContinuityErrs.H"
+
+U -= rAU*fvc::grad(p);
+U.correctBoundaryConditions();
+K = 0.5*magSqr(U);
+
+dpdt = fvc::ddt(p);
diff --git a/applications/solvers/lagrangian/sprayFoam/sprayEnginFoam/readEngineTimeControls.H b/applications/solvers/lagrangian/sprayFoam/sprayEngineFoam/readEngineTimeControls.H
similarity index 100%
rename from applications/solvers/lagrangian/sprayFoam/sprayEnginFoam/readEngineTimeControls.H
rename to applications/solvers/lagrangian/sprayFoam/sprayEngineFoam/readEngineTimeControls.H
diff --git a/applications/solvers/lagrangian/sprayFoam/sprayEnginFoam/sprayEngineFoam.C b/applications/solvers/lagrangian/sprayFoam/sprayEngineFoam/sprayEngineFoam.C
similarity index 99%
rename from applications/solvers/lagrangian/sprayFoam/sprayEnginFoam/sprayEngineFoam.C
rename to applications/solvers/lagrangian/sprayFoam/sprayEngineFoam/sprayEngineFoam.C
index 7014cc1af336606af346029cf124c96557915bf0..a4ae147f51817a5573035b4ae97ddb856e4d6965 100644
--- a/applications/solvers/lagrangian/sprayFoam/sprayEnginFoam/sprayEngineFoam.C
+++ b/applications/solvers/lagrangian/sprayFoam/sprayEngineFoam/sprayEngineFoam.C
@@ -74,6 +74,8 @@ int main(int argc, char *argv[])
 
         Info<< "Crank angle = " << runTime.theta() << " CA-deg" << endl;
 
+        mesh.move();
+
         parcels.evolve();
 
         #include "rhoEqn.H"
diff --git a/applications/solvers/lagrangian/sprayFoam/sprayEnginFoam/startSummary.H b/applications/solvers/lagrangian/sprayFoam/sprayEngineFoam/startSummary.H
similarity index 100%
rename from applications/solvers/lagrangian/sprayFoam/sprayEnginFoam/startSummary.H
rename to applications/solvers/lagrangian/sprayFoam/sprayEngineFoam/startSummary.H
diff --git a/applications/solvers/multiphase/compressibleTwoPhaseEulerFoam/interfacialModels/dragModels/dragModel/dragModel.H b/applications/solvers/multiphase/compressibleTwoPhaseEulerFoam/interfacialModels/dragModels/dragModel/dragModel.H
index 6d2add98f97c412410157f228fce20353b195ebc..97c9d455f12810b35b053f257694e1ff0d79c073 100644
--- a/applications/solvers/multiphase/compressibleTwoPhaseEulerFoam/interfacialModels/dragModels/dragModel/dragModel.H
+++ b/applications/solvers/multiphase/compressibleTwoPhaseEulerFoam/interfacialModels/dragModels/dragModel/dragModel.H
@@ -114,11 +114,11 @@ public:
         //- the dragfunction K used in the momentum eq.
         //    ddt(alpha*rhoa*Ua) + ... = ... alpha*beta*K*(Ua-Ub)
         //    ddt(beta*rhob*Ub) + ...  = ... alpha*beta*K*(Ub-Ua)
-        // **********************************�NB ! *****************************
+        // ********************************** NB! *****************************
         // for numerical reasons alpha and beta has been
         // extracted from the dragFunction K,
         // so you MUST divide K by alpha*beta when implemnting the drag function
-        // **********************************�NB ! *****************************
+        // ********************************** NB! *****************************
         virtual tmp<volScalarField> K(const volScalarField& Ur) const = 0;
 };
 
diff --git a/applications/solvers/multiphase/compressibleTwoPhaseEulerFoam/interfacialModels/heatTransferModels/heatTransferModel/heatTransferModel.H b/applications/solvers/multiphase/compressibleTwoPhaseEulerFoam/interfacialModels/heatTransferModels/heatTransferModel/heatTransferModel.H
index e4871f2c515bcba99fc9f3b5b80cef0fc27735de..f83a03804b088836ed24352039d524640538f376 100644
--- a/applications/solvers/multiphase/compressibleTwoPhaseEulerFoam/interfacialModels/heatTransferModels/heatTransferModel/heatTransferModel.H
+++ b/applications/solvers/multiphase/compressibleTwoPhaseEulerFoam/interfacialModels/heatTransferModels/heatTransferModel/heatTransferModel.H
@@ -114,12 +114,12 @@ public:
         //- the heat-transfer function K used in the enthalpy eq.
         //    ddt(alpha*rhoa*ha) + ... = ... alpha*beta*K*(Ta - Tb)
         //    ddt(beta*rhob*hb) + ...  = ... alpha*beta*K*(Tb - Ta)
-        // **********************************�NB ! *****************************
+        // ********************************** NB!*****************************
         // for numerical reasons alpha and beta has been
         // extracted from the heat-transfer function K,
         // so you MUST divide K by alpha*beta when implementing the
         // heat-transfer function
-        // **********************************�NB ! *****************************
+        // ********************************** NB!*****************************
         virtual tmp<volScalarField> K(const volScalarField& Ur) const = 0;
 };
 
diff --git a/applications/solvers/multiphase/interFoam/alphaEqn.H b/applications/solvers/multiphase/interFoam/alphaEqn.H
index d19ae9bb702d0be3752e33f4feaad92cb8dd4bff..dc1146944e5f46bc362b3213f697a1048c8b6eca 100644
--- a/applications/solvers/multiphase/interFoam/alphaEqn.H
+++ b/applications/solvers/multiphase/interFoam/alphaEqn.H
@@ -30,7 +30,7 @@
     }
 
     Info<< "Liquid phase volume fraction = "
-        << alpha1.weightedAverage(mesh.V()).value()
+        << alpha1.weightedAverage(mesh.Vsc()).value()
         << "  Min(alpha1) = " << min(alpha1).value()
         << "  Max(alpha1) = " << max(alpha1).value()
         << endl;
diff --git a/applications/solvers/multiphase/interPhaseChangeFoam/phaseChangeTwoPhaseMixtures/Kunz/Kunz.H b/applications/solvers/multiphase/interPhaseChangeFoam/phaseChangeTwoPhaseMixtures/Kunz/Kunz.H
index 31ea8164dfd69a51938942a0a96df60dba6339da..74f8f2b931b563f475fac6f92c3092d54ee31dbd 100644
--- a/applications/solvers/multiphase/interPhaseChangeFoam/phaseChangeTwoPhaseMixtures/Kunz/Kunz.H
+++ b/applications/solvers/multiphase/interPhaseChangeFoam/phaseChangeTwoPhaseMixtures/Kunz/Kunz.H
@@ -35,8 +35,8 @@ Description
     \verbatim
         Kunz, R.F., Boger, D.A., Stinebring, D.R., Chyczewski, Lindau. J.W.,
         Gibeling, H.J., Venkateswaran, S., Govindan, T.R.,
-        “A Preconditioned Implicit Method for Two-Phase Flows with Application
-         to Cavitation Prediction,”
+        "A Preconditioned Implicit Method for Two-Phase Flows with Application
+         to Cavitation Prediction,"
         Computers and Fluids,
         29(8):849-875, 2000.
     \endverbatim
diff --git a/applications/solvers/multiphase/multiphaseEulerFoam/interfacialModels/dragModels/dragModel/dragModel.H b/applications/solvers/multiphase/multiphaseEulerFoam/interfacialModels/dragModels/dragModel/dragModel.H
index a775d91e4566a168dc0a22dddcd3e54496b73e67..3a9536c88104a010357996accb665433b568f219 100644
--- a/applications/solvers/multiphase/multiphaseEulerFoam/interfacialModels/dragModels/dragModel/dragModel.H
+++ b/applications/solvers/multiphase/multiphaseEulerFoam/interfacialModels/dragModels/dragModel/dragModel.H
@@ -131,11 +131,11 @@ public:
         //- the dragfunction K used in the momentum eq.
         //    ddt(alpha*rhoa*Ua) + ... = ... alpha*beta*K*(Ua-Ub)
         //    ddt(beta*rhob*Ub) + ...  = ... alpha*beta*K*(Ub-Ua)
-        // **********************************�NB ! *****************************
+        // ********************************** NB! *****************************
         // for numerical reasons alpha and beta has been
         // extracted from the dragFunction K,
         // so you MUST divide K by alpha*beta when implemnting the drag function
-        // **********************************�NB ! *****************************
+        // ********************************** NB! *****************************
         virtual tmp<volScalarField> K(const volScalarField& Ur) const = 0;
 };
 
diff --git a/applications/solvers/multiphase/multiphaseEulerFoam/interfacialModels/heatTransferModels/heatTransferModel/heatTransferModel.H b/applications/solvers/multiphase/multiphaseEulerFoam/interfacialModels/heatTransferModels/heatTransferModel/heatTransferModel.H
index e4871f2c515bcba99fc9f3b5b80cef0fc27735de..5541795bfd38b112a540cd7f769a4d4b5239b3e4 100644
--- a/applications/solvers/multiphase/multiphaseEulerFoam/interfacialModels/heatTransferModels/heatTransferModel/heatTransferModel.H
+++ b/applications/solvers/multiphase/multiphaseEulerFoam/interfacialModels/heatTransferModels/heatTransferModel/heatTransferModel.H
@@ -114,12 +114,12 @@ public:
         //- the heat-transfer function K used in the enthalpy eq.
         //    ddt(alpha*rhoa*ha) + ... = ... alpha*beta*K*(Ta - Tb)
         //    ddt(beta*rhob*hb) + ...  = ... alpha*beta*K*(Tb - Ta)
-        // **********************************�NB ! *****************************
+        // ********************************** NB! *****************************
         // for numerical reasons alpha and beta has been
         // extracted from the heat-transfer function K,
         // so you MUST divide K by alpha*beta when implementing the
         // heat-transfer function
-        // **********************************�NB ! *****************************
+        // ********************************** NB! *****************************
         virtual tmp<volScalarField> K(const volScalarField& Ur) const = 0;
 };
 
diff --git a/applications/solvers/multiphase/multiphaseEulerFoam/pEqn.H b/applications/solvers/multiphase/multiphaseEulerFoam/pEqn.H
index b93ea3a020b37862b4e9bf7acc4a615b67c0048b..675a410a167c197c7bfe59de0b0cbbde53ba726e 100644
--- a/applications/solvers/multiphase/multiphaseEulerFoam/pEqn.H
+++ b/applications/solvers/multiphase/multiphaseEulerFoam/pEqn.H
@@ -155,7 +155,6 @@
         phasei++;
     }
     Dp = mag(Dp);
-    adjustPhi(phi0, U, p);
 
     while (pimple.correctNonOrthogonal())
     {
diff --git a/applications/solvers/multiphase/twoPhaseEulerFoam/interfacialModels/dragModels/dragModel/dragModel.H b/applications/solvers/multiphase/twoPhaseEulerFoam/interfacialModels/dragModels/dragModel/dragModel.H
index 237c7cfb641125a44185231903f5a5ffc3deeb48..0831f158b62caf9719adce81a03cb2562ffc9e04 100644
--- a/applications/solvers/multiphase/twoPhaseEulerFoam/interfacialModels/dragModels/dragModel/dragModel.H
+++ b/applications/solvers/multiphase/twoPhaseEulerFoam/interfacialModels/dragModels/dragModel/dragModel.H
@@ -114,11 +114,11 @@ public:
         //- the dragfunction K used in the momentum eq.
         //    ddt(alpha*rhoa*Ua) + ... = ... alpha*beta*K*(Ua-Ub)
         //    ddt(beta*rhob*Ub) + ...  = ... alpha*beta*K*(Ub-Ua)
-        // **********************************�NB ! *****************************
+        // ********************************** NB ! *****************************
         // for numerical reasons alpha and beta has been
         // extracted from the dragFunction K,
         // so you MUST divide K by alpha*beta when implemnting the drag function
-        // **********************************�NB ! *****************************
+        // ********************************** NB ! *****************************
         virtual tmp<volScalarField> K(const volScalarField& Ur) const = 0;
 };
 
diff --git a/applications/test/DLList/Test-DLList.C b/applications/test/DLList/Test-DLList.C
index 8e76baa6e1133360e2e168abd48b71ce473cb30d..d3703489825c0cae6b42521ad06e93d9da2cb10b 100644
--- a/applications/test/DLList/Test-DLList.C
+++ b/applications/test/DLList/Test-DLList.C
@@ -65,30 +65,36 @@ int main(int argc, char *argv[])
     }
 
     myList.append(500.3);
+    myList.append(200.3);
     myList.append(100.3);
 
 
     Info<< nl << "And again using STL const_iterator: " << nl << endl;
 
-    const DLList<scalar>& const_myList = myList;
 
-    forAllConstIter(DLList<scalar>, const_myList, iter)
+    forAllConstIter(DLList<scalar>, myList, iter)
     {
         Info<< "element:" << *iter << endl;
     }
 
+    Info<< nl << "Testing swapUp and swapDown: " << endl;
+
+    Info<< nl << "swapUp" << endl;
+
     myList.swapUp(myList.DLListBase::first());
     myList.swapUp(myList.DLListBase::last());
 
-    forAllConstIter(DLList<scalar>, const_myList, iter)
+    forAllIter(DLList<scalar>, myList, iter)
     {
         Info<< "element:" << *iter << endl;
     }
 
+    Info<< nl << "swapDown" << endl;
+
     myList.swapDown(myList.DLListBase::first());
     myList.swapDown(myList.DLListBase::last());
 
-    forAllConstIter(DLList<scalar>, const_myList, iter)
+    forAllIter(DLList<scalar>, myList, iter)
     {
         Info<< "element:" << *iter << endl;
     }
@@ -103,8 +109,8 @@ int main(int argc, char *argv[])
     Info<< nl << "source: " << myList << nl
         << nl << "target: " << newList << endl;
 
-
     Info<< nl << "Done." << endl;
+
     return 0;
 }
 
diff --git a/applications/test/findSphereFeatureEdges-octree/Make/files b/applications/test/findSphereFeatureEdges-octree/Make/files
new file mode 100644
index 0000000000000000000000000000000000000000..b9c5a5027f0388256bee54a568165c9176ff3972
--- /dev/null
+++ b/applications/test/findSphereFeatureEdges-octree/Make/files
@@ -0,0 +1,3 @@
+Test-findSphereFeatureEdges-octree.C
+
+EXE = $(FOAM_USER_APPBIN)/Test-findSphereFeatureEdges-octree
diff --git a/applications/test/findSphereFeatureEdges-octree/Make/options b/applications/test/findSphereFeatureEdges-octree/Make/options
new file mode 100644
index 0000000000000000000000000000000000000000..606903451472483dd2b1136556b156bddbaeabe7
--- /dev/null
+++ b/applications/test/findSphereFeatureEdges-octree/Make/options
@@ -0,0 +1,9 @@
+EXE_INC = \
+    -I$(LIB_SRC)/finiteVolume/lnInclude \
+    -I$(LIB_SRC)/meshTools/lnInclude \
+    -I$(LIB_SRC)/edgeMesh/lnInclude
+
+EXE_LIBS = \
+    -lfiniteVolume \
+    -lmeshTools \
+    -ledgeMesh
diff --git a/applications/test/findSphereFeatureEdges-octree/Test-findSphereFeatureEdges-octree.C b/applications/test/findSphereFeatureEdges-octree/Test-findSphereFeatureEdges-octree.C
new file mode 100644
index 0000000000000000000000000000000000000000..4842756d48f7a2a98ce91617dc14ea5791d56138
--- /dev/null
+++ b/applications/test/findSphereFeatureEdges-octree/Test-findSphereFeatureEdges-octree.C
@@ -0,0 +1,134 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+     \\/     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 3 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, see <http://www.gnu.org/licenses/>.
+
+\*---------------------------------------------------------------------------*/
+
+#include "argList.H"
+#include "Time.H"
+#include "fvMesh.H"
+#include "IStringStream.H"
+#include "indexedOctree.H"
+#include "treeDataEdge.H"
+#include "OFstream.H"
+#include "extendedFeatureEdgeMesh.H"
+
+using namespace Foam;
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+// Main program:
+
+int main(int argc, char *argv[])
+{
+
+#   include "setRootCase.H"
+#   include "createTime.H"
+#   include "createMesh.H"
+
+    fileName sFeatFileName("unit_cube_rotated.extendedFeatureEdgeMesh");
+
+    extendedFeatureEdgeMesh efem
+    (
+        IOobject
+        (
+            sFeatFileName,
+            runTime.time().constant(),
+            "extendedFeatureEdgeMesh",
+            runTime.time(),
+            IOobject::MUST_READ,
+            IOobject::NO_WRITE
+        )
+    );
+
+    // Slightly extended bb. Slightly off-centred just so on symmetric
+    // geometry there are less face/edge aligned items.
+    treeBoundBox bb
+    (
+        efem.points()
+    );
+
+    bb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
+    bb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
+
+    labelList allEdges(identity(efem.edges().size()));
+
+    indexedOctree<treeDataEdge> edgeTree
+    (
+        treeDataEdge
+        (
+            false,          // cachebb
+            efem.edges(),        // edges
+            efem.points(),       // points
+            allEdges        // selected edges
+        ),
+        bb,     // bb
+        8,      // maxLevel
+        10,     // leafsize
+        3.0     // duplicity
+    );
+
+    Info<< "Points: " << efem.points() << nl << endl;
+    Info<< "Edges: " << efem.edges() << nl << endl;
+
+    Info<< "Find edge labels within sphere from point (0, 0, 0):" << endl;
+
+    Info<< "    Radius = 0            : "
+        << edgeTree.findSphere(point(0, 0, 0), 0) << endl;
+
+    Info<< "    Radius = 1            : "
+        << edgeTree.findSphere(point(0, 0, 0), 1) << endl;
+
+    Info<< "    Radius = root(1.5)    : "
+        << edgeTree.findSphere(point(0, 0, 0), 1.5) << endl;
+
+    Info<< "    Radius = root(2)      : "
+        << edgeTree.findSphere(point(0, 0, 0), 2) << endl;
+
+    Info<< "    Radius = root(0.5)    : "
+        << edgeTree.findSphere(point(1, 0, 0), 0.5) << endl;
+
+    Info<< "    Radius = root(0.25)   : "
+        << edgeTree.findSphere(point(0, 0, 0.5), 0.25) << endl;
+
+    treeBoundBox tbb(point(0,0,0), point(0.1,0.1,0.1));
+    Info<< "    Box = " << tbb << "    : "
+        << edgeTree.findBox(tbb) << endl;
+
+    treeBoundBox tbb1(point(0,0,0), point(1,1,0.1));
+    Info<< "    Box = " << tbb1 << "        : "
+        << edgeTree.findBox(tbb1) << endl;
+
+    treeBoundBox tbb2(point(0.3,0,0), point(1,0.3,1));
+    Info<< "    Box = " << tbb2 << "      : "
+        << edgeTree.findBox(tbb2) << endl;
+
+    treeBoundBox tbb3(point(-0.2,0.5,0), point(0.3,0.9,1));
+    Info<< "    Box = " << tbb3 << " : "
+        << edgeTree.findBox(tbb3) << endl;
+
+    Info<< "End\n" << endl;
+
+    return 0;
+}
+
+
+// ************************************************************************* //
diff --git a/applications/test/momentOfInertia/Test-momentOfInertia.C b/applications/test/momentOfInertia/Test-momentOfInertia.C
index 0a825df73fbff5093a555d00cc4b82d07ba00bf1..73aaee649b2439555930d8209041ac878519c0e0 100644
--- a/applications/test/momentOfInertia/Test-momentOfInertia.C
+++ b/applications/test/momentOfInertia/Test-momentOfInertia.C
@@ -2,7 +2,7 @@
  =========                   |
  \\      /   F ield          | OpenFOAM: The Open Source CFD Toolbox
   \\    /    O peration      |
-   \\  /     A nd            | Copyright (C) 2011 OpenFOAM Foundation
+   \\  /     A nd            | Copyright (C) 2012 OpenFOAM Foundation
     \\/      M anipulation   |
 -------------------------------------------------------------------------------
 License
@@ -35,7 +35,7 @@ Description
 #include "polyMesh.H"
 #include "ListOps.H"
 #include "face.H"
-#include "tetPointRef.H"
+#include "tetrahedron.H"
 #include "triFaceList.H"
 #include "OFstream.H"
 #include "meshTools.H"
diff --git a/applications/utilities/mesh/generation/extrude/extrudeToRegionMesh/extrudeToRegionMesh.C b/applications/utilities/mesh/generation/extrude/extrudeToRegionMesh/extrudeToRegionMesh.C
index 4ba6d43b4ed59ce56119d42aec0629eb85cdd9fb..b32c249e7c201c96e633d75e0163ef32b905e3d9 100644
--- a/applications/utilities/mesh/generation/extrude/extrudeToRegionMesh/extrudeToRegionMesh.C
+++ b/applications/utilities/mesh/generation/extrude/extrudeToRegionMesh/extrudeToRegionMesh.C
@@ -1637,6 +1637,7 @@ int main(int argc, char *argv[])
 
     #include "addRegionOption.H"
     #include "addOverwriteOption.H"
+    argList::addOption("dict", "name", "specify alternative dictionary");
 
     #include "setRootCase.H"
     #include "createTime.H"
diff --git a/applications/utilities/mesh/manipulation/createBaffles/createBaffles.C b/applications/utilities/mesh/manipulation/createBaffles/createBaffles.C
index 01c97079586b57d6657af056faa842c1ba72d4cb..b3d9d3f5150628cb4d47f5784edcfbdb53e5c545 100644
--- a/applications/utilities/mesh/manipulation/createBaffles/createBaffles.C
+++ b/applications/utilities/mesh/manipulation/createBaffles/createBaffles.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -290,18 +290,6 @@ int main(int argc, char *argv[])
 
     // Whether first use of face (modify) or consecutive (add)
     PackedBoolList modifiedFace(mesh.nFaces());
-    // Never modify coupled faces
-    forAll(patches, patchI)
-    {
-        const polyPatch& pp = patches[patchI];
-        if (pp.coupled())
-        {
-            forAll(pp, i)
-            {
-                modifiedFace[pp.start()+i] = 1;
-            }
-        }
-    }
     label nModified = 0;
 
     forAll(newMasterPatches, i)
diff --git a/applications/utilities/mesh/manipulation/createPatch/createPatch.C b/applications/utilities/mesh/manipulation/createPatch/createPatch.C
index 7afe8356a6f1e599e4ad5abecaac21a7c3ee33c0..7922d487a2bd34012bc3fbdfdb39eeae17a7ca09 100644
--- a/applications/utilities/mesh/manipulation/createPatch/createPatch.C
+++ b/applications/utilities/mesh/manipulation/createPatch/createPatch.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -490,11 +490,17 @@ void syncPoints
 
 int main(int argc, char *argv[])
 {
-#   include "addOverwriteOption.H"
-#   include "addRegionOption.H"
+    #include "addOverwriteOption.H"
+    #include "addRegionOption.H"
+    argList::addOption
+    (
+        "dict",
+        "word",
+        "name of dictionary to provide patch information"
+    );
 
-#   include "setRootCase.H"
-#   include "createTime.H"
+    #include "setRootCase.H"
+    #include "createTime.H"
     runTime.functionObjects().off();
 
     Foam::word meshRegionName = polyMesh::defaultRegion;
@@ -502,13 +508,18 @@ int main(int argc, char *argv[])
 
     const bool overwrite = args.optionFound("overwrite");
 
-    Info<< "Reading createPatchDict." << nl << endl;
+    word dictName
+    (
+        args.optionLookupOrDefault<word>("dict", "createPatchDict")
+    );
+
+    Info<< "Reading " << dictName << nl << endl;
 
     IOdictionary dict
     (
         IOobject
         (
-            "createPatchDict",
+            dictName,
             runTime.system(),
             (
                 meshRegionName != polyMesh::defaultRegion
@@ -526,7 +537,7 @@ int main(int argc, char *argv[])
     // Whether to synchronise points
     const Switch pointSync(dict.lookup("pointSync"));
 
-#   include "createNamedPolyMesh.H"
+    #include "createNamedPolyMesh.H"
 
     const word oldInstance = mesh.pointsInstance();
 
@@ -607,6 +618,11 @@ int main(int argc, char *argv[])
                     ).ptr()
                 );
             }
+            else
+            {
+                Info<< "Patch '" << patchName << "' already exists.  Only "
+                    << "moving patch faces - type will remain the same" << endl;
+            }
         }
 
         // Copy old patches.
diff --git a/applications/utilities/mesh/manipulation/mergeMeshes/mergeMeshes.C b/applications/utilities/mesh/manipulation/mergeMeshes/mergeMeshes.C
index 99631e1e49adf47f741be5f74a352f7f1800636a..3841e16bf3291dcc1217dd7fdd8780322cd988d8 100644
--- a/applications/utilities/mesh/manipulation/mergeMeshes/mergeMeshes.C
+++ b/applications/utilities/mesh/manipulation/mergeMeshes/mergeMeshes.C
@@ -61,6 +61,8 @@ int main(int argc, char *argv[])
     );
 
     argList::noParallel();
+    #include "addOverwriteOption.H"
+
     argList::validArgs.append("masterCase");
     argList::addOption
     (
@@ -83,6 +85,8 @@ int main(int argc, char *argv[])
          FatalError.exit();
     }
 
+    const bool overwrite = args.optionFound("overwrite");
+
     fileName masterCase = args[1];
     word masterRegion = polyMesh::defaultRegion;
     args.optionReadIfPresent("masterRegion", masterRegion);
@@ -126,7 +130,10 @@ int main(int argc, char *argv[])
         )
     );
 
-    runTimeMaster++;
+    if (!overwrite)
+    {
+        runTimeMaster++;
+    }
 
     Info<< "Writing combined mesh to " << runTimeMaster.timeName() << endl;
 
diff --git a/applications/utilities/mesh/manipulation/renumberMesh/Make/options b/applications/utilities/mesh/manipulation/renumberMesh/Make/options
index dc78db34365c567e370f0f69ad03db91f958f30d..6a2c95738da7f4140e83311e1fa333fed7ed5827 100644
--- a/applications/utilities/mesh/manipulation/renumberMesh/Make/options
+++ b/applications/utilities/mesh/manipulation/renumberMesh/Make/options
@@ -2,7 +2,7 @@ EXE_INC = \
     -I$(LIB_SRC)/meshTools/lnInclude \
     -I$(LIB_SRC)/dynamicMesh/lnInclude \
     -I$(LIB_SRC)/finiteVolume/lnInclude \
-    -I$(LIB_SRC)/renumberMethods/lnInclude \
+    -I$(LIB_SRC)/renumber/renumberMethods/lnInclude \
     -I$(LIB_SRC)/parallel/decompose/decompositionMethods/lnInclude
 
 EXE_LIBS = \
diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/foamToEnsightParts.C b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/foamToEnsightParts.C
index a96179e9707417622b55273bb0186c894405cbc2..cb7f5705aa902207f7fbbc1440bca6a33204c410 100644
--- a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/foamToEnsightParts.C
+++ b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/foamToEnsightParts.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -35,6 +35,9 @@ Usage
     \param -ascii \n
     Write Ensight data in ASCII format instead of "C Binary"
 
+    \parm -name \<subdir\>\n
+    define sub-directory name to use for Ensight data (default: "Ensight")
+
     \param -noZero \n
     Exclude the often incomplete initial conditions.
 
@@ -46,6 +49,9 @@ Usage
     Suppress writing the geometry. Can be useful for converting partial
     results for a static geometry.
 
+    \param -width \<n\>\n
+    width of Ensight data subdir
+
 Note
     - no parallel data.
     - writes to \a Ensight directory to avoid collisions with foamToEnsight.
@@ -96,6 +102,19 @@ int main(int argc, char *argv[])
         "suppress writing the geometry. "
         "Can be useful for converting partial results for a static geometry"
     );
+    argList::addOption
+    (
+        "name",
+        "subdir",
+        "define sub-directory name to use for Ensight data "
+        "(default: \"Ensight\")"
+    );
+    argList::addOption
+    (
+        "width",
+        "n",
+        "width of Ensight data subdir"
+    );
 
     // the volume field types that we handle
     wordHashSet volFieldTypes;
@@ -133,7 +152,21 @@ int main(int argc, char *argv[])
     // always write the geometry, unless the -noMesh option is specified
     bool optNoMesh = args.optionFound("noMesh");
 
-    fileName ensightDir = args.rootPath()/args.globalCaseName()/"Ensight";
+    // adjust output width
+    if (args.optionFound("width"))
+    {
+        ensightFile::subDirWidth(args.optionRead<label>("width"));
+    }
+
+    // define sub-directory name to use for Ensight data
+    fileName ensightDir = "Ensight";
+    args.optionReadIfPresent("name", ensightDir);
+
+    if (!ensightDir.isAbsolute())
+    {
+        ensightDir = args.rootPath()/args.globalCaseName()/ensightDir;
+    }
+
     fileName dataDir = ensightDir/"data";
     fileName caseFileName = "Ensight.case";
     fileName dataMask = fileName("data")/ensightFile::mask();
diff --git a/applications/utilities/postProcessing/miscellaneous/execFlowFunctionObjects/execFlowFunctionObjects.C b/applications/utilities/postProcessing/miscellaneous/execFlowFunctionObjects/execFlowFunctionObjects.C
index f0487ac2a2a5c5c9b62ff39ba8168c93a1615099..6531073136cec0d02abf3898e681223370e16637 100644
--- a/applications/utilities/postProcessing/miscellaneous/execFlowFunctionObjects/execFlowFunctionObjects.C
+++ b/applications/utilities/postProcessing/miscellaneous/execFlowFunctionObjects/execFlowFunctionObjects.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -47,7 +47,7 @@ Description
 #include "incompressible/RAS/RASModel/RASModel.H"
 #include "incompressible/LES/LESModel/LESModel.H"
 
-#include "basicPsiThermo.H"
+#include "basicThermo.H"
 #include "compressible/RAS/RASModel/RASModel.H"
 #include "compressible/LES/LESModel/LESModel.H"
 
@@ -265,7 +265,7 @@ void Foam::calc(const argList& args, const Time& runTime, const fvMesh& mesh)
         }
         else if (phi.dimensions() == dimensionSet(1, 0, -1, 0, 0))
         {
-            autoPtr<basicPsiThermo> thermo(basicPsiThermo::New(mesh));
+            autoPtr<basicThermo> thermo(basicThermo::New(mesh));
 
             volScalarField rho
             (
diff --git a/applications/utilities/postProcessing/patch/patchAverage/patchAverage.C b/applications/utilities/postProcessing/patch/patchAverage/patchAverage.C
index d8f651c9684633dfd352dc8fc3761745bc8e45ef..f7948701cc584552f0ee8b3fa9c66484e9adda3d 100644
--- a/applications/utilities/postProcessing/patch/patchAverage/patchAverage.C
+++ b/applications/utilities/postProcessing/patch/patchAverage/patchAverage.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -32,17 +32,59 @@ Description
 #include "fvCFD.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+template<class FieldType>
+void printAverage
+(
+    const fvMesh& mesh,
+    const IOobject& fieldHeader,
+    const scalar area,
+    const label patchI,
+    bool& done
+)
+{
+    if (!done && fieldHeader.headerClassName() == FieldType::typeName)
+    {
+        Info<< "    Reading " << fieldHeader.headerClassName() << " "
+            << fieldHeader.name() << endl;
+
+        FieldType field(fieldHeader, mesh);
+
+        typename FieldType::value_type sumField =
+            pTraits<typename FieldType::value_type>::zero;
+
+        if (area > 0)
+        {
+            sumField = gSum
+            (
+                mesh.magSf().boundaryField()[patchI]
+              * field.boundaryField()[patchI]
+            ) / area;
+        }
+
+        Info<< "    Average of " << fieldHeader.headerClassName()
+            << " over patch "
+            << mesh.boundary()[patchI].name()
+            << '[' << patchI << ']' << " = "
+            << sumField << endl;
+
+        done = true;
+    }
+}
+
+
 // Main program:
 
 int main(int argc, char *argv[])
 {
     timeSelector::addOptions();
+    #include "addRegionOption.H"
     argList::validArgs.append("fieldName");
     argList::validArgs.append("patchName");
 #   include "setRootCase.H"
 #   include "createTime.H"
     instantList timeDirs = timeSelector::select0(runTime, args);
-#   include "createMesh.H"
+#   include "createNamedMesh.H"
 
     const word fieldName = args[1];
     const word patchName = args[2];
@@ -52,7 +94,7 @@ int main(int argc, char *argv[])
         runTime.setTime(timeDirs[timeI], timeI);
         Info<< "Time = " << runTime.timeName() << endl;
 
-        IOobject fieldHeader
+        IOobject io
         (
             fieldName,
             runTime.timeName(),
@@ -61,7 +103,7 @@ int main(int argc, char *argv[])
         );
 
         // Check field exists
-        if (fieldHeader.headerOk())
+        if (io.headerOk())
         {
             mesh.readUpdate();
 
@@ -72,32 +114,21 @@ int main(int argc, char *argv[])
                     << "Unable to find patch " << patchName << nl
                     << exit(FatalError);
             }
+            scalar area = gSum(mesh.magSf().boundaryField()[patchI]);
 
-            if (fieldHeader.headerClassName() == "volScalarField")
-            {
-                Info<< "    Reading volScalarField " << fieldName << endl;
-                volScalarField field(fieldHeader, mesh);
-
-                scalar area = gSum(mesh.magSf().boundaryField()[patchI]);
-                scalar sumField = 0;
-
-                if (area > 0)
-                {
-                    sumField = gSum
-                    (
-                        mesh.magSf().boundaryField()[patchI]
-                      * field.boundaryField()[patchI]
-                    ) / area;
-                }
-
-                Info<< "    Average of " << fieldName << " over patch "
-                    << patchName << '[' << patchI << ']' << " = "
-                    << sumField << endl;
-            }
-            else
+            bool done = false;
+            printAverage<volScalarField>(mesh, io, area, patchI, done);
+            printAverage<volVectorField>(mesh, io, area, patchI, done);
+            printAverage<volSphericalTensorField>(mesh, io, area, patchI, done);
+            printAverage<volSymmTensorField>(mesh, io, area, patchI, done);
+            printAverage<volTensorField>(mesh, io, area, patchI, done);
+
+            if (!done)
             {
                 FatalError
-                    << "Only possible to average volScalarFields "
+                    << "Only possible to average volFields."
+                    << " Field " << fieldName << " is of type "
+                    << io.headerClassName()
                     << nl << exit(FatalError);
             }
         }
diff --git a/applications/utilities/postProcessing/patch/patchIntegrate/patchIntegrate.C b/applications/utilities/postProcessing/patch/patchIntegrate/patchIntegrate.C
index 8696c6ffde90c9f5a48a65fa29ea6e69b3cf851d..5004df4c9e5c85f63aab1c8b0cdb0ef64efc8dbb 100644
--- a/applications/utilities/postProcessing/patch/patchIntegrate/patchIntegrate.C
+++ b/applications/utilities/postProcessing/patch/patchIntegrate/patchIntegrate.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -32,12 +32,83 @@ Description
 #include "fvCFD.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+template<class FieldType>
+void printIntegrate
+(
+    const fvMesh& mesh,
+    const IOobject& fieldHeader,
+    const label patchI,
+    bool& done
+)
+{
+    if (!done && fieldHeader.headerClassName() == FieldType::typeName)
+    {
+        Info<< "    Reading " << fieldHeader.headerClassName() << " "
+            << fieldHeader.name() << endl;
+
+        FieldType field(fieldHeader, mesh);
+
+        Info<< "    Integral of " << fieldHeader.name()
+            << " over vector area of patch "
+            << mesh.boundary()[patchI].name() << '[' << patchI << ']' << " = "
+            << gSum
+               (
+                   mesh.Sf().boundaryField()[patchI]
+                  *field.boundaryField()[patchI]
+               )
+            << nl;
+
+        Info<< "    Integral of " << fieldHeader.name()
+            << " over area magnitude of patch "
+            << mesh.boundary()[patchI].name() << '[' << patchI << ']' << " = "
+            << gSum
+               (
+                   mesh.magSf().boundaryField()[patchI]
+                  *field.boundaryField()[patchI]
+               )
+            << nl;
+
+        done = true;
+    }
+}
+
+
+template<class FieldType>
+void printSum
+(
+    const fvMesh& mesh,
+    const IOobject& fieldHeader,
+    const label patchI,
+    bool& done
+)
+{
+    if (!done && fieldHeader.headerClassName() == FieldType::typeName)
+    {
+        Info<< "    Reading " << FieldType::typeName << " "
+            << fieldHeader.name() << endl;
+
+        FieldType field(fieldHeader, mesh);
+        typename FieldType::value_type sumField = gSum
+        (
+            field.boundaryField()[patchI]
+        );
+
+        Info<< "    Integral of " << fieldHeader.name() << " over patch "
+            << mesh.boundary()[patchI].name() << '[' << patchI << ']' << " = "
+            << sumField << nl;
+
+        done = true;
+    }
+}
+
+
 // Main program:
 
 int main(int argc, char *argv[])
 {
-#   include "addRegionOption.H"
     timeSelector::addOptions();
+#   include "addRegionOption.H"
     argList::validArgs.append("fieldName");
     argList::validArgs.append("patchName");
 #   include "setRootCase.H"
@@ -83,54 +154,88 @@ int main(int argc, char *argv[])
                 << gSum(mesh.magSf().boundaryField()[patchI]) << endl;
 
             // Read field and calc integral
-            if (fieldHeader.headerClassName() == volScalarField::typeName)
-            {
-                Info<< "    Reading " << volScalarField::typeName << " "
-                    << fieldName << endl;
-
-                volScalarField field(fieldHeader, mesh);
-
-                Info<< "    Integral of " << fieldName
-                    << " over vector area of patch "
-                    << patchName << '[' << patchI << ']' << " = "
-                    << gSum
-                       (
-                           mesh.Sf().boundaryField()[patchI]
-                          *field.boundaryField()[patchI]
-                       )
-                    << nl;
-
-                Info<< "    Integral of " << fieldName
-                    << " over area magnitude of patch "
-                    << patchName << '[' << patchI << ']' << " = "
-                    << gSum
-                       (
-                           mesh.magSf().boundaryField()[patchI]
-                          *field.boundaryField()[patchI]
-                       )
-                    << nl;
-            }
-            else if
+            bool done = false;
+            printIntegrate<volScalarField>
             (
-                fieldHeader.headerClassName() == surfaceScalarField::typeName
-            )
-            {
-                Info<< "    Reading " << surfaceScalarField::typeName << " "
-                    << fieldName << endl;
+                mesh,
+                fieldHeader,
+                patchI,
+                done
+            );
+            printIntegrate<volVectorField>
+            (
+                mesh,
+                fieldHeader,
+                patchI,
+                done
+            );
 
-                surfaceScalarField field(fieldHeader, mesh);
-                scalar sumField = gSum(field.boundaryField()[patchI]);
+            //- No tensor integrations
+            //printIntegrate<volSphericalTensorField>
+            //(
+            //    mesh,
+            //    fieldHeader,
+            //    patchI,
+            //    done
+            //);
+            //printIntegrate<volSymmTensorField>
+            //(
+            //    mesh,
+            //    fieldHeader,
+            //    patchI,
+            //    done
+            //);
+            //printIntegrate<volTensorField>
+            //(
+            //    mesh,
+            //    fieldHeader,
+            //    patchI,
+            //    done
+            //);
 
-                Info<< "    Integral of " << fieldName << " over patch "
-                    << patchName << '[' << patchI << ']' << " = "
-                    << sumField << nl;
-            }
-            else
+            printSum<surfaceScalarField>
+            (
+                mesh,
+                fieldHeader,
+                patchI,
+                done
+            );
+            printSum<surfaceVectorField>
+            (
+                mesh,
+                fieldHeader,
+                patchI,
+                done
+            );
+            printSum<volSphericalTensorField>
+            (
+                mesh,
+                fieldHeader,
+                patchI,
+                done
+            );
+            printSum<volSymmTensorField>
+            (
+                mesh,
+                fieldHeader,
+                patchI,
+                done
+            );
+            printSum<volTensorField>
+            (
+                mesh,
+                fieldHeader,
+                patchI,
+                done
+            );
+
+            if (!done)
             {
                 FatalError
                     << "Only possible to integrate "
-                    << volScalarField::typeName << "s "
-                    << "and " << surfaceScalarField::typeName << "s"
+                    << "volFields and surfaceFields."
+                    << " Field " << fieldName << " is of type "
+                    << fieldHeader.headerClassName()
                     << nl << exit(FatalError);
             }
         }
diff --git a/applications/utilities/postProcessing/velocityField/Mach/Mach.C b/applications/utilities/postProcessing/velocityField/Mach/Mach.C
index 2233465bfe98b9fb070661d5aa2163aed31f452b..3463175d7725ab445f191ed7c0d736a8215dd4fa 100644
--- a/applications/utilities/postProcessing/velocityField/Mach/Mach.C
+++ b/applications/utilities/postProcessing/velocityField/Mach/Mach.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -33,9 +33,10 @@ Description
 \*---------------------------------------------------------------------------*/
 
 #include "calc.H"
-#include "basicPsiThermo.H"
+#include "basicThermo.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
 void Foam::calc(const argList& args, const Time& runTime, const fvMesh& mesh)
 {
     bool writeResults = !args.optionFound("noWrite");
@@ -74,9 +75,9 @@ void Foam::calc(const argList& args, const Time& runTime, const fvMesh& mesh)
         )
         {
             // thermophysical Mach
-            autoPtr<basicPsiThermo> thermo
+            autoPtr<basicThermo> thermo
             (
-                basicPsiThermo::New(mesh)
+                basicThermo::New(mesh)
             );
 
             volScalarField Cp(thermo->Cp());
diff --git a/applications/utilities/postProcessing/velocityField/Mach/thermophysicalMach.H b/applications/utilities/postProcessing/velocityField/Mach/thermophysicalMach.H
index 7283802f7790a6c0cf209195a9273e51697fc017..4e4ea81b3d87463b4c8d91fb115e0ea465e4b41b 100644
--- a/applications/utilities/postProcessing/velocityField/Mach/thermophysicalMach.H
+++ b/applications/utilities/postProcessing/velocityField/Mach/thermophysicalMach.H
@@ -18,9 +18,9 @@
         {
             volVectorField U(Uheader, mesh);
 
-            autoPtr<basicPsiThermo> thermo
+            autoPtr<basicThermo> thermo
             (
-                basicPsiThermo::New(mesh)
+                basicThermo::New(mesh)
             );
 
             volScalarField Cp = thermo->Cp();
diff --git a/applications/utilities/postProcessing/velocityField/Pe/Pe.C b/applications/utilities/postProcessing/velocityField/Pe/Pe.C
index c77c0cee056cda1e1e06ab8415ebd63ad118676b..c262482ce734e742ab063b8ac4b3463c832934b8 100644
--- a/applications/utilities/postProcessing/velocityField/Pe/Pe.C
+++ b/applications/utilities/postProcessing/velocityField/Pe/Pe.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -39,7 +39,7 @@ Description
 #include "incompressible/singlePhaseTransportModel/singlePhaseTransportModel.H"
 #include "incompressible/RAS/RASModel/RASModel.H"
 #include "incompressible/LES/LESModel/LESModel.H"
-#include "basicPsiThermo.H"
+#include "basicThermo.H"
 #include "compressible/RAS/RASModel/RASModel.H"
 #include "compressible/LES/LESModel/LESModel.H"
 
@@ -204,7 +204,7 @@ void Foam::calc(const argList& args, const Time& runTime, const fvMesh& mesh)
             {
                 IOdictionary RASProperties(RASPropertiesHeader);
 
-                autoPtr<basicPsiThermo> thermo(basicPsiThermo::New(mesh));
+                autoPtr<basicThermo> thermo(basicThermo::New(mesh));
 
                 volScalarField rho
                 (
@@ -252,7 +252,7 @@ void Foam::calc(const argList& args, const Time& runTime, const fvMesh& mesh)
             {
                 IOdictionary LESProperties(LESPropertiesHeader);
 
-                autoPtr<basicPsiThermo> thermo(basicPsiThermo::New(mesh));
+                autoPtr<basicThermo> thermo(basicThermo::New(mesh));
 
                 volScalarField rho
                 (
diff --git a/applications/utilities/postProcessing/wall/solidWallHeatFlux/Make/files b/applications/utilities/postProcessing/wall/solidWallHeatFlux/Make/files
new file mode 100644
index 0000000000000000000000000000000000000000..bdf785fe20e88586224b4b014f354575ba9c9fef
--- /dev/null
+++ b/applications/utilities/postProcessing/wall/solidWallHeatFlux/Make/files
@@ -0,0 +1,3 @@
+solidWallHeatFlux.C
+
+EXE = $(FOAM_APPBIN)/solidWallHeatFlux
diff --git a/applications/utilities/postProcessing/wall/solidWallHeatFlux/Make/options b/applications/utilities/postProcessing/wall/solidWallHeatFlux/Make/options
new file mode 100644
index 0000000000000000000000000000000000000000..64d31222de00a8534b59c82b06161f38699097b4
--- /dev/null
+++ b/applications/utilities/postProcessing/wall/solidWallHeatFlux/Make/options
@@ -0,0 +1,12 @@
+EXE_INC = \
+    -I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \
+    -I$(LIB_SRC)/thermophysicalModels/specie/lnInclude \
+    -I$(LIB_SRC)/thermophysicalModels/basicSolidThermo/lnInclude \
+    -I$(LIB_SRC)/finiteVolume/lnInclude
+
+EXE_LIBS = \
+    -lbasicThermophysicalModels \
+    -lbasicSolidThermo \
+    -lspecie \
+    -lfiniteVolume \
+    -lgenericPatchFields
diff --git a/applications/utilities/postProcessing/wall/solidWallHeatFlux/createFields.H b/applications/utilities/postProcessing/wall/solidWallHeatFlux/createFields.H
new file mode 100644
index 0000000000000000000000000000000000000000..c845710399bd7dd773c2c81221efffb6fdfbe6fb
--- /dev/null
+++ b/applications/utilities/postProcessing/wall/solidWallHeatFlux/createFields.H
@@ -0,0 +1,6 @@
+autoPtr<basicSolidThermo> thermo
+(
+    basicSolidThermo::New(mesh)
+);
+
+volScalarField& T = thermo->T();
diff --git a/applications/utilities/postProcessing/wall/solidWallHeatFlux/solidWallHeatFlux.C b/applications/utilities/postProcessing/wall/solidWallHeatFlux/solidWallHeatFlux.C
new file mode 100644
index 0000000000000000000000000000000000000000..f728a626b18ec33551cf9e71dd5a5438d7804617
--- /dev/null
+++ b/applications/utilities/postProcessing/wall/solidWallHeatFlux/solidWallHeatFlux.C
@@ -0,0 +1,102 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
+     \\/     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 3 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, see <http://www.gnu.org/licenses/>.
+
+Application
+    solidWallHeatFlux
+
+Description
+    Calculates and writes the heat flux for all patches as the boundary field
+    of a volScalarField and also prints the integrated flux for all wall
+    patches.
+
+\*---------------------------------------------------------------------------*/
+
+#include "fvCFD.H"
+#include "wallFvPatch.H"
+#include "basicSolidThermo.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+int main(int argc, char *argv[])
+{
+    timeSelector::addOptions();
+#   include "addRegionOption.H"
+    #include "setRootCase.H"
+    #include "createTime.H"
+    instantList timeDirs = timeSelector::select0(runTime, args);
+    #include "createNamedMesh.H"
+
+    forAll(timeDirs, timeI)
+    {
+        runTime.setTime(timeDirs[timeI], timeI);
+        Info<< "Time = " << runTime.timeName() << endl;
+        mesh.readUpdate();
+
+        // Read temperature
+        #include "createFields.H"
+
+        // Create heat flux as volScalarField with as boundary values
+        // the heat flux
+        volScalarField wallHeatFlux
+        (
+            IOobject
+            (
+                "solidWallHeatFlux",
+                runTime.timeName(),
+                mesh
+            ),
+            mesh,
+            dimensionedScalar("solidWallHeatFlux", dimPower/dimArea, 0.0)
+        );
+
+        Info<< "\nWall heat fluxes [W]" << endl;
+        forAll(wallHeatFlux.boundaryField(), patchi)
+        {
+            wallHeatFlux.boundaryField()[patchi] =
+                thermo().K(patchi)
+               *T.boundaryField()[patchi].snGrad();
+
+            if (isA<wallFvPatch>(mesh.boundary()[patchi]))
+            {
+                Info<< mesh.boundary()[patchi].name()
+                    << " "
+                    << gSum
+                       (
+                           mesh.magSf().boundaryField()[patchi]
+                          *wallHeatFlux.boundaryField()[patchi]
+                       )
+                    << endl;
+            }
+        }
+
+        wallHeatFlux.write();
+
+        Info<< endl;
+    }
+
+    Info<< "End" << endl;
+
+    return 0;
+}
+
+// ************************************************************************* //
diff --git a/applications/utilities/postProcessing/wall/wallHeatFlux/createFields.H b/applications/utilities/postProcessing/wall/wallHeatFlux/createFields.H
index 609d4c3776006ef5be5295695fbcce84cf8a2ca7..d4f142d54523aa937da214a2f8dfc623fd80422c 100644
--- a/applications/utilities/postProcessing/wall/wallHeatFlux/createFields.H
+++ b/applications/utilities/postProcessing/wall/wallHeatFlux/createFields.H
@@ -1,6 +1,6 @@
-autoPtr<basicPsiThermo> thermo
+autoPtr<basicThermo> thermo
 (
-    basicPsiThermo::New(mesh)
+    basicThermo::New(mesh)
 );
 
 const volScalarField& h = thermo->h();
diff --git a/applications/utilities/postProcessing/wall/wallHeatFlux/wallHeatFlux.C b/applications/utilities/postProcessing/wall/wallHeatFlux/wallHeatFlux.C
index 070869ce28e93fa995d493afdc475613af847e75..2789b52f83d7d96655ac1fb30732b4693b0ca75d 100644
--- a/applications/utilities/postProcessing/wall/wallHeatFlux/wallHeatFlux.C
+++ b/applications/utilities/postProcessing/wall/wallHeatFlux/wallHeatFlux.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -41,10 +41,11 @@ Description
 int main(int argc, char *argv[])
 {
     timeSelector::addOptions();
+#   include "addRegionOption.H"
     #include "setRootCase.H"
     #include "createTime.H"
     instantList timeDirs = timeSelector::select0(runTime, args);
-    #include "createMesh.H"
+    #include "createNamedMesh.H"
 
     forAll(timeDirs, timeI)
     {
@@ -69,7 +70,7 @@ int main(int argc, char *argv[])
             {
                 Info<< mesh.boundary()[patchi].name()
                     << " "
-                    << sum
+                    << gSum
                        (
                            mesh.magSf().boundaryField()[patchi]
                           *patchHeatFlux[patchi]
diff --git a/applications/utilities/postProcessing/wall/wallShearStress/wallShearStress.C b/applications/utilities/postProcessing/wall/wallShearStress/wallShearStress.C
index 6069837b9513d27ca51c72792ffde69f3eec68a4..83a1e57f42dccc7b522af52ac22430dd3be18830 100644
--- a/applications/utilities/postProcessing/wall/wallShearStress/wallShearStress.C
+++ b/applications/utilities/postProcessing/wall/wallShearStress/wallShearStress.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -38,7 +38,7 @@ Description
 #include "incompressible/singlePhaseTransportModel/singlePhaseTransportModel.H"
 #include "incompressible/RAS/RASModel/RASModel.H"
 
-#include "basicPsiThermo.H"
+#include "basicThermo.H"
 #include "compressible/RAS/RASModel/RASModel.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@@ -101,11 +101,8 @@ void calcCompressible
 
     #include "compressibleCreatePhi.H"
 
-    autoPtr<basicPsiThermo> pThermo
-    (
-        basicPsiThermo::New(mesh)
-    );
-    basicPsiThermo& thermo = pThermo();
+    autoPtr<basicThermo> pThermo(basicThermo::New(mesh));
+    basicThermo& thermo = pThermo();
 
     autoPtr<compressible::RASModel> model
     (
diff --git a/applications/utilities/postProcessing/wall/yPlusRAS/yPlusRAS.C b/applications/utilities/postProcessing/wall/yPlusRAS/yPlusRAS.C
index 359c3bcb4fa7ddec8b5af27d19d10c95902c4c4e..c8de884de96c61ff6ba1571fecd27f6ebfe60746 100644
--- a/applications/utilities/postProcessing/wall/yPlusRAS/yPlusRAS.C
+++ b/applications/utilities/postProcessing/wall/yPlusRAS/yPlusRAS.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -39,7 +39,7 @@ Description
 #include "incompressible/RAS/RASModel/RASModel.H"
 #include "nutkWallFunction/nutkWallFunctionFvPatchScalarField.H"
 
-#include "basicPsiThermo.H"
+#include "basicThermo.H"
 #include "compressible/RAS/RASModel/RASModel.H"
 #include "mutkWallFunction/mutkWallFunctionFvPatchScalarField.H"
 
@@ -130,11 +130,11 @@ void calcCompressibleYPlus
 
     #include "compressibleCreatePhi.H"
 
-    autoPtr<basicPsiThermo> pThermo
+    autoPtr<basicThermo> pThermo
     (
-        basicPsiThermo::New(mesh)
+        basicThermo::New(mesh)
     );
-    basicPsiThermo& thermo = pThermo();
+    basicThermo& thermo = pThermo();
 
     autoPtr<compressible::RASModel> RASModel
     (
diff --git a/etc/config/settings.csh b/etc/config/settings.csh
index 2566cd6a9acb0027922c53a016749de767351f08..5eaed0c13ca5ff34af5c15e5fc3164d87f0ff7ad 100644
--- a/etc/config/settings.csh
+++ b/etc/config/settings.csh
@@ -372,7 +372,7 @@ unsetenv MPI_ARCH_PATH MPI_HOME FOAM_MPI_LIBBIN
 
 switch ("$WM_MPLIB")
 case OPENMPI:
-    setenv FOAM_MPI openmpi-1.5.3
+    setenv FOAM_MPI openmpi-1.5.4
     # optional configuration tweaks:
     _foamSource `$WM_PROJECT_DIR/bin/foamEtcFile config/openmpi.csh`
 
diff --git a/etc/config/settings.sh b/etc/config/settings.sh
index 55810e6e9f18f038f56e8efaa064fa540a43a8a3..13939070cd3848ca825b6c538e9e28014770b410 100644
--- a/etc/config/settings.sh
+++ b/etc/config/settings.sh
@@ -114,6 +114,16 @@ Linux)
         export WM_LDFLAGS='-mabi=64 -G0'
         ;;
 
+    armv7l)
+        WM_ARCH=linuxARM7
+        export WM_COMPILER_LIB_ARCH=32
+        export WM_CC='gcc'
+        export WM_CXX='g++'
+        export WM_CFLAGS='-fPIC'
+        export WM_CXXFLAGS='-fPIC'
+        export WM_LDFLAGS=
+        ;;
+
     ppc64)
         WM_ARCH=linuxPPC64
         export WM_COMPILER_LIB_ARCH=64
@@ -393,7 +403,7 @@ unset MPI_ARCH_PATH MPI_HOME FOAM_MPI_LIBBIN
 
 case "$WM_MPLIB" in
 OPENMPI)
-    export FOAM_MPI=openmpi-1.5.3
+    export FOAM_MPI=openmpi-1.5.4
     # optional configuration tweaks:
     _foamSource `$WM_PROJECT_DIR/bin/foamEtcFile config/openmpi.sh`
 
diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files
index 4bab8ad32a5c8e5612f4fb2242deeb15432a6643..fefabee6901b217ba62982c408c5b0e5a2eda18f 100644
--- a/src/OpenFOAM/Make/files
+++ b/src/OpenFOAM/Make/files
@@ -45,7 +45,9 @@ primitives/Tensor/lists/symmTensorList.C
 primitives/Tensor/lists/tensorList.C
 
 primitives/Vector/complexVector/complexVector.C
+#if !defined(WM_SP)
 primitives/Vector/floatVector/floatVector.C
+#endif
 primitives/Vector/labelVector/labelVector.C
 primitives/Vector/vector/vector.C
 primitives/Vector/lists/vectorList.C
diff --git a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.C b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.C
index f837ec3e66a1fee4c98e388ad63af32224519e54..95476fd89a7a15f71cf9bd8d6f78596cfcbec95d 100644
--- a/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.C
+++ b/src/OpenFOAM/containers/LinkedLists/linkTypes/DLListBase/DLListBase.C
@@ -94,23 +94,23 @@ bool Foam::DLListBase::swapUp(DLListBase::link* a)
         if (ap == first_)
         {
             first_ = a;
+            ap->prev_ = a;
+        }
+        else
+        {
+            ap->prev_->next_ = a;
         }
 
         if (a == last_)
         {
             last_ = ap;
+            a->next_ = ap;
         }
-
-        if (a->next_)
+        else
         {
             a->next_->prev_ = ap;
         }
 
-        if (ap->prev_)
-        {
-            ap->prev_->next_ = a;
-        }
-
         a->prev_ = ap->prev_;
         ap->prev_ = a;
 
@@ -135,19 +135,19 @@ bool Foam::DLListBase::swapDown(DLListBase::link* a)
         if (a == first_)
         {
             first_ = an;
+            a->prev_ = an;
         }
-
-        if (an == last_)
+        else
         {
-            last_ = a;
+            a->prev_->next_ = an;
         }
 
-        if (a->prev_)
+        if (an == last_)
         {
-            a->prev_->next_ = an;
+            last_ = a;
+            an->next_ = a;
         }
-
-        if (an->next_)
+        else
         {
             an->next_->prev_ = a;
         }
diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C b/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C
index a45d38589423a9d35ac3354748e8a49f42087693..d0a3d87276c3a23580db3ac8d13d9886f4fa7bf3 100644
--- a/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C
+++ b/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -254,5 +254,11 @@ Foam::UPstream::commsTypes Foam::UPstream::defaultCommsType
     commsTypeNames.read(debug::optimisationSwitches().lookup("commsType"))
 );
 
+// Number of polling cycles in processor updates
+int Foam::UPstream::nPollProcInterfaces
+(
+    debug::optimisationSwitch("nPollProcInterfaces", 0)
+);
+
 
 // ************************************************************************* //
diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H
index 6ae1dfb368ebc63fd9a156d2eca72f4353cdf4e0..1ad4aa99ccc9e9b09c1798ca4e24f780e6012971 100644
--- a/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H
+++ b/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -242,6 +242,8 @@ public:
         //- Default commsType
         static commsTypes defaultCommsType;
 
+        //- Number of polling cycles in processor updates
+        static int nPollProcInterfaces;
 
     // Constructors
 
@@ -273,6 +275,9 @@ public:
             //- Wait until all requests (from start onwards) have finished.
             static void waitRequests(const label start = 0);
 
+            //- Wait until request i has finished.
+            static void waitRequest(const label i);
+
             //- Non-blocking comms: has request i finished?
             static bool finishedRequest(const label i);
 
diff --git a/src/OpenFOAM/db/Time/Time.C b/src/OpenFOAM/db/Time/Time.C
index 7abcf7f9a0dc85ecc2e14bc14701cc3ea02eddef..7ba18b3cc8fc5894ae2f2b4330c18fbd757c4a3f 100644
--- a/src/OpenFOAM/db/Time/Time.C
+++ b/src/OpenFOAM/db/Time/Time.C
@@ -203,10 +203,15 @@ void Foam::Time::setControls()
         )
     );
 
-    if (timeDict.readIfPresent("deltaT", deltaT_))
+    // Read and set the deltaT only if time-step adjustment is active
+    // otherwise use the deltaT from the controlDict
+    if (controlDict_.lookupOrDefault<Switch>("adjustTimeStep", false))
     {
-        deltaTSave_ = deltaT_;
-        deltaT0_ = deltaT_;
+        if (timeDict.readIfPresent("deltaT", deltaT_))
+        {
+            deltaTSave_ = deltaT_;
+            deltaT0_ = deltaT_;
+        }
     }
 
     timeDict.readIfPresent("deltaT0", deltaT0_);
@@ -984,6 +989,17 @@ Foam::Time& Foam::Time::operator++()
             << " to " << precision_
             << " to distinguish between timeNames at time " << value()
             << endl;
+
+        if (precision_ == 100 && precision_ != oldPrecision)
+        {
+            // Reached limit.
+            WarningIn("Time::operator++()")
+                << "Current time name " << dimensionedScalar::name()
+                << " is the old as the previous one " << oldTimeName
+                << endl
+                << "    This might result in overwriting old results."
+                << endl;
+        }
     }
 
 
diff --git a/src/OpenFOAM/global/argList/argList.C b/src/OpenFOAM/global/argList/argList.C
index 5d8758e2d2978145f83e5e15935c7b254ab7e582..16f6157a227fc12ecd16473a271184d1cb49e2e5 100644
--- a/src/OpenFOAM/global/argList/argList.C
+++ b/src/OpenFOAM/global/argList/argList.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -772,10 +772,11 @@ Foam::argList::argList
                 Info<< "Roots  : " << roots << nl;
             }
             Info<< "Pstream initialized with:" << nl
-                << "    floatTransfer     : " << Pstream::floatTransfer << nl
-                << "    nProcsSimpleSum   : " << Pstream::nProcsSimpleSum << nl
-                << "    commsType         : "
-                << Pstream::commsTypeNames[Pstream::defaultCommsType]
+                << "    floatTransfer      : " << Pstream::floatTransfer << nl
+                << "    nProcsSimpleSum    : " << Pstream::nProcsSimpleSum << nl
+                << "    commsType          : "
+                << Pstream::commsTypeNames[Pstream::defaultCommsType] << nl
+                << "    polling iterations : " << Pstream::nPollProcInterfaces
                 << endl;
         }
     }
diff --git a/src/OpenFOAM/matrices/lduMatrix/lduAddressing/lduInterfaceFields/lduInterfaceField/lduInterfaceField.H b/src/OpenFOAM/matrices/lduMatrix/lduAddressing/lduInterfaceFields/lduInterfaceField/lduInterfaceField.H
index 040c7f8da8fd13b9618bc91c9577162d48aa6923..b8180a2b3ec086d043fc52e4c1d590f5bbd0ef87 100644
--- a/src/OpenFOAM/matrices/lduMatrix/lduAddressing/lduInterfaceFields/lduInterfaceField/lduInterfaceField.H
+++ b/src/OpenFOAM/matrices/lduMatrix/lduAddressing/lduInterfaceFields/lduInterfaceField/lduInterfaceField.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -60,6 +60,10 @@ class lduInterfaceField
         //- Reference to the coupled patch this field is defined for
         const lduInterface& interface_;
 
+        //- Update index used so that updateInterfaceMatrix is called only once
+        //  during the construction of the matrix
+        bool updatedMatrix_;
+
 
     // Private Member Functions
 
@@ -69,7 +73,6 @@ class lduInterfaceField
         //- Disallow default bitwise assignment
         void operator=(const lduInterfaceField&);
 
-
 public:
 
     //- Runtime type information
@@ -81,7 +84,8 @@ public:
         //- Construct given coupled patch
         lduInterfaceField(const lduInterface& patch)
         :
-            interface_(patch)
+            interface_(patch),
+            updatedMatrix_(false)
         {}
 
 
@@ -120,6 +124,24 @@ public:
             ) const
             {}
 
+            //- Whether matrix has been updated
+            bool updatedMatrix() const
+            {
+                return updatedMatrix_;
+            }
+
+            //- Whether matrix has been updated
+            bool& updatedMatrix()
+            {
+                return updatedMatrix_;
+            }
+
+            //- Is all data available
+            virtual bool ready() const
+            {
+                return true;
+            }
+
             //- Update result field based on interface functionality
             virtual void updateInterfaceMatrix
             (
diff --git a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixOperations.C b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixOperations.C
index 45654d9731abed335b0b8bd7eb3da6bfda55b963..07260b4a91009fdbdc7265ab6ad6765f75183c40 100644
--- a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixOperations.C
+++ b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixOperations.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -205,7 +205,15 @@ void Foam::lduMatrix::operator+=(const lduMatrix& A)
         if (debug > 1)
         {
             WarningIn("lduMatrix::operator+=(const lduMatrix& A)")
-                << "Unknown matrix type combination"
+                << "Unknown matrix type combination" << nl
+                << "    this :"
+                << " diagonal:" << diagonal()
+                << " symmetric:" << symmetric()
+                << " asymmetric:" << asymmetric() << nl
+                << "    A    :"
+                << " diagonal:" << A.diagonal()
+                << " symmetric:" << A.symmetric()
+                << " asymmetric:" << A.asymmetric()
                 << endl;
         }
     }
@@ -276,7 +284,15 @@ void Foam::lduMatrix::operator-=(const lduMatrix& A)
         if (debug > 1)
         {
             WarningIn("lduMatrix::operator-=(const lduMatrix& A)")
-                << "Unknown matrix type combination"
+                << "Unknown matrix type combination" << nl
+                << "    this :"
+                << " diagonal:" << diagonal()
+                << " symmetric:" << symmetric()
+                << " asymmetric:" << asymmetric() << nl
+                << "    A    :"
+                << " diagonal:" << A.diagonal()
+                << " symmetric:" << A.symmetric()
+                << " asymmetric:" << A.asymmetric()
                 << endl;
         }
     }
diff --git a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixUpdateMatrixInterfaces.C b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixUpdateMatrixInterfaces.C
index c401c3e47764068938556e15bc3762e6cfa900e0..62d00b7626c7c04929f6f69bc18e6562e92dea0f 100644
--- a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixUpdateMatrixInterfaces.C
+++ b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixUpdateMatrixInterfaces.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -87,7 +87,7 @@ void Foam::lduMatrix::initMatrixInterfaces
     }
     else
     {
-        FatalErrorIn("lduMatrix::initMatrixInterfaces")
+        FatalErrorIn("lduMatrix::initMatrixInterfaces(..)")
             << "Unsuported communications type "
             << Pstream::commsTypeNames[Pstream::defaultCommsType]
             << exit(FatalError);
@@ -104,25 +104,92 @@ void Foam::lduMatrix::updateMatrixInterfaces
     const direction cmpt
 ) const
 {
-    if
-    (
-        Pstream::defaultCommsType == Pstream::blocking
-     || Pstream::defaultCommsType == Pstream::nonBlocking
-    )
+    if (Pstream::defaultCommsType == Pstream::blocking)
     {
-        // Block until all sends/receives have been finished
-        if
-        (
-            Pstream::parRun()
-         && Pstream::defaultCommsType == Pstream::nonBlocking
-        )
+        forAll(interfaces, interfaceI)
         {
-            UPstream::waitRequests();
+            if (interfaces.set(interfaceI))
+            {
+                interfaces[interfaceI].updateInterfaceMatrix
+                (
+                    psiif,
+                    result,
+                    *this,
+                    coupleCoeffs[interfaceI],
+                    cmpt,
+                    Pstream::defaultCommsType
+                );
+            }
+        }
+    }
+    else if (Pstream::defaultCommsType == Pstream::nonBlocking)
+    {
+        // Try and consume interfaces as they become available
+        bool allUpdated = false;
+
+        for (label i = 0; i < UPstream::nPollProcInterfaces; i++)
+        {
+            allUpdated = true;
+
+            forAll(interfaces, interfaceI)
+            {
+                if (interfaces.set(interfaceI))
+                {
+                    if (!interfaces[interfaceI].updatedMatrix())
+                    {
+                        if (interfaces[interfaceI].ready())
+                        {
+                            interfaces[interfaceI].updateInterfaceMatrix
+                            (
+                                psiif,
+                                result,
+                                *this,
+                                coupleCoeffs[interfaceI],
+                                cmpt,
+                                Pstream::defaultCommsType
+                            );
+                        }
+                        else
+                        {
+                            allUpdated = false;
+                        }
+                    }
+                }
+            }
+
+            if (allUpdated)
+            {
+                break;
+            }
+        }
+
+        // Block for everything
+        if (Pstream::parRun())
+        {
+            if (allUpdated)
+            {
+                // All received. Just remove all storage of requests
+                // Note that we don't know what starting number of requests
+                // was before start of sends and receives (since set from
+                // initMatrixInterfaces) so set to 0 and loose any in-flight
+                // requests.
+                UPstream::resetRequests(0);
+            }
+            else
+            {
+                // Block for all requests and remove storage
+                UPstream::waitRequests();
+            }
         }
 
+        // Consume
         forAll(interfaces, interfaceI)
         {
-            if (interfaces.set(interfaceI))
+            if
+            (
+                interfaces.set(interfaceI)
+            && !interfaces[interfaceI].updatedMatrix()
+            )
             {
                 interfaces[interfaceI].updateInterfaceMatrix
                 (
@@ -199,7 +266,7 @@ void Foam::lduMatrix::updateMatrixInterfaces
     }
     else
     {
-        FatalErrorIn("lduMatrix::updateMatrixInterfaces")
+        FatalErrorIn("lduMatrix::updateMatrixInterfaces(..)")
             << "Unsuported communications type "
             << Pstream::commsTypeNames[Pstream::defaultCommsType]
             << exit(FatalError);
diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaceFields/processorGAMGInterfaceField/processorGAMGInterfaceField.C b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaceFields/processorGAMGInterfaceField/processorGAMGInterfaceField.C
index 3b6d1ee026590ef420f99f54137dfe5ff47a4b0f..b8fa744ff6b0673f1174fee7fc22bb43ca95eccd 100644
--- a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaceFields/processorGAMGInterfaceField/processorGAMGInterfaceField.C
+++ b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaceFields/processorGAMGInterfaceField/processorGAMGInterfaceField.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -80,11 +80,38 @@ void Foam::processorGAMGInterfaceField::initInterfaceMatrixUpdate
     const Pstream::commsTypes commsType
 ) const
 {
-    procInterface_.compressedSend
-    (
-        commsType,
-        procInterface_.interfaceInternalField(psiInternal)()
-    );
+    procInterface_.interfaceInternalField(psiInternal, scalarSendBuf_);
+
+    if (commsType == Pstream::nonBlocking && !Pstream::floatTransfer)
+    {
+        // Fast path.
+        scalarReceiveBuf_.setSize(scalarSendBuf_.size());
+        outstandingRecvRequest_ = UPstream::nRequests();
+        IPstream::read
+        (
+            Pstream::nonBlocking,
+            procInterface_.neighbProcNo(),
+            reinterpret_cast<char*>(scalarReceiveBuf_.begin()),
+            scalarReceiveBuf_.byteSize(),
+            procInterface_.tag()
+        );
+
+        outstandingSendRequest_ = UPstream::nRequests();
+        OPstream::write
+        (
+            Pstream::nonBlocking,
+            procInterface_.neighbProcNo(),
+            reinterpret_cast<const char*>(scalarSendBuf_.begin()),
+            scalarSendBuf_.byteSize(),
+            procInterface_.tag()
+        );
+    }
+    else
+    {
+        procInterface_.compressedSend(commsType, scalarSendBuf_);
+    }
+
+    const_cast<processorGAMGInterfaceField&>(*this).updatedMatrix() = false;
 }
 
 
@@ -98,18 +125,54 @@ void Foam::processorGAMGInterfaceField::updateInterfaceMatrix
     const Pstream::commsTypes commsType
 ) const
 {
-    scalarField pnf
-    (
-        procInterface_.compressedReceive<scalar>(commsType, coeffs.size())
-    );
-    transformCoupleField(pnf, cmpt);
+    if (updatedMatrix())
+    {
+        return;
+    }
 
     const labelUList& faceCells = procInterface_.faceCells();
 
-    forAll(faceCells, elemI)
+    if (commsType == Pstream::nonBlocking && !Pstream::floatTransfer)
     {
-        result[faceCells[elemI]] -= coeffs[elemI]*pnf[elemI];
+        // Fast path.
+        if
+        (
+            outstandingRecvRequest_ >= 0
+         && outstandingRecvRequest_ < Pstream::nRequests()
+        )
+        {
+            UPstream::waitRequest(outstandingRecvRequest_);
+        }
+        // Recv finished so assume sending finished as well.
+        outstandingSendRequest_ = -1;
+        outstandingRecvRequest_ = -1;
+
+        // Consume straight from scalarReceiveBuf_
+
+        // Transform according to the transformation tensor
+        transformCoupleField(scalarReceiveBuf_, cmpt);
+
+        // Multiply the field by coefficients and add into the result
+        forAll(faceCells, elemI)
+        {
+            result[faceCells[elemI]] -= coeffs[elemI]*scalarReceiveBuf_[elemI];
+        }
     }
+    else
+    {
+        scalarField pnf
+        (
+            procInterface_.compressedReceive<scalar>(commsType, coeffs.size())
+        );
+        transformCoupleField(pnf, cmpt);
+
+        forAll(faceCells, elemI)
+        {
+            result[faceCells[elemI]] -= coeffs[elemI]*pnf[elemI];
+        }
+    }
+
+    const_cast<processorGAMGInterfaceField&>(*this).updatedMatrix() = true;
 }
 
 
diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaceFields/processorGAMGInterfaceField/processorGAMGInterfaceField.H b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaceFields/processorGAMGInterfaceField/processorGAMGInterfaceField.H
index c1bdac02460856c176ab80f4efc3f1ea893c986d..48d64baacf369908a2bec65f6cc88fabe2b669aa 100644
--- a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaceFields/processorGAMGInterfaceField/processorGAMGInterfaceField.H
+++ b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaceFields/processorGAMGInterfaceField/processorGAMGInterfaceField.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -65,6 +65,22 @@ class processorGAMGInterfaceField
         int rank_;
 
 
+        // Sending and receiving
+
+            //- Outstanding request
+            mutable label outstandingSendRequest_;
+
+            //- Outstanding request
+            mutable label outstandingRecvRequest_;
+
+            //- Scalar send buffer
+            mutable Field<scalar> scalarSendBuf_;
+
+            //- Scalar receive buffer
+            mutable Field<scalar> scalarReceiveBuf_;
+
+
+
     // Private Member Functions
 
         //- Disallow default bitwise copy construct
diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaces/GAMGInterface/GAMGInterface.H b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaces/GAMGInterface/GAMGInterface.H
index 8f25335415cb61771af91da86573ac6459408a97..ed6c7ca7468009f6849e67e6e5ce173378287585 100644
--- a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaces/GAMGInterface/GAMGInterface.H
+++ b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaces/GAMGInterface/GAMGInterface.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -188,6 +188,14 @@ public:
                 const UList<Type>& internalData
             ) const;
 
+            //- Get the interface internal field of the given field
+            template<class Type>
+            void interfaceInternalField
+            (
+                const UList<Type>& internalData,
+                List<Type>&
+            ) const;
+
             //- Return the values of the given internal data adjacent to
             //  the interface as a field
             virtual tmp<labelField> interfaceInternalField
diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaces/GAMGInterface/GAMGInterfaceTemplates.C b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaces/GAMGInterface/GAMGInterfaceTemplates.C
index 0d42d04cef72ae192b4cddada9dbe19963ecf73e..4890618ab12781c44a18b40239c013386b89dbaf 100644
--- a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaces/GAMGInterface/GAMGInterfaceTemplates.C
+++ b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaces/GAMGInterface/GAMGInterfaceTemplates.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -34,14 +34,24 @@ Foam::tmp<Foam::Field<Type> > Foam::GAMGInterface::interfaceInternalField
 ) const
 {
     tmp<Field<Type> > tresult(new Field<Type>(size()));
-    Field<Type>& result = tresult();
+    interfaceInternalField(iF, tresult());
+    return tresult;
+}
+
+
+template<class Type>
+void Foam::GAMGInterface::interfaceInternalField
+(
+    const UList<Type>& iF,
+    List<Type>& result
+) const
+{
+    result.setSize(size());
 
     forAll(result, elemI)
     {
         result[elemI] = iF[faceCells_[elemI]];
     }
-
-    return tresult;
 }
 
 
diff --git a/src/OpenFOAM/meshes/meshShapes/tetCell/tetCell.H b/src/OpenFOAM/meshes/meshShapes/tetCell/tetCell.H
index a237335ccc77fa2cdd91bf0c3e45b37bc3fbc1b2..91e3926c7f9d0675b898d9e9caf4dcac32fd1528 100644
--- a/src/OpenFOAM/meshes/meshShapes/tetCell/tetCell.H
+++ b/src/OpenFOAM/meshes/meshShapes/tetCell/tetCell.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -43,7 +43,7 @@ SourceFiles
 #include "triFace.H"
 #include "edge.H"
 #include "pointField.H"
-#include "tetPointRef.H"
+#include "tetrahedron.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
diff --git a/src/OpenFOAM/meshes/polyMesh/polyMeshTetDecomposition/polyMeshTetDecomposition.H b/src/OpenFOAM/meshes/polyMesh/polyMeshTetDecomposition/polyMeshTetDecomposition.H
index 181a2d11220d78ce3f0d41056d51b9abcec4aefe..e1dfbfbf63f3da5417a4a9e0ed5ded0ee7109926 100644
--- a/src/OpenFOAM/meshes/polyMesh/polyMeshTetDecomposition/polyMeshTetDecomposition.H
+++ b/src/OpenFOAM/meshes/polyMesh/polyMeshTetDecomposition/polyMeshTetDecomposition.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -42,7 +42,7 @@ SourceFiles
 #include "polyMesh.H"
 #include "coupledPolyPatch.H"
 #include "syncTools.H"
-#include "tetPointRef.H"
+#include "tetrahedron.H"
 #include "tetIndices.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/src/OpenFOAM/meshes/polyMesh/polyMeshTetDecomposition/tetIndices.H b/src/OpenFOAM/meshes/polyMesh/polyMeshTetDecomposition/tetIndices.H
index 76f82fa78c6d65d07b901ab865b16261de52b623..f0dea9aad8bee212f9e328c4ff97c72d4cb7e85a 100644
--- a/src/OpenFOAM/meshes/polyMesh/polyMeshTetDecomposition/tetIndices.H
+++ b/src/OpenFOAM/meshes/polyMesh/polyMeshTetDecomposition/tetIndices.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -38,7 +38,7 @@ SourceFiles
 #define tetIndices_H
 
 #include "label.H"
-#include "tetPointRef.H"
+#include "tetrahedron.H"
 #include "triPointRef.H"
 #include "polyMesh.H"
 #include "triFace.H"
diff --git a/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicPolyPatch.C b/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicPolyPatch.C
index 84fd20affc8f428a13989f82b09841d3f91f79d5..b5d12a042c818d0a4610a989f9a255bf16e32258 100644
--- a/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicPolyPatch.C
+++ b/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicPolyPatch.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -419,146 +419,148 @@ void Foam::cyclicPolyPatch::getCentresAndAnchors
             << gAverage(half1Ctrs) << endl;
     }
 
-    switch (transform_)
+    if (half0Ctrs.size())
     {
-        case ROTATIONAL:
-        {
-            vector n0 = findFaceMaxRadius(half0Ctrs);
-            vector n1 = -findFaceMaxRadius(half1Ctrs);
-            n0 /= mag(n0) + VSMALL;
-            n1 /= mag(n1) + VSMALL;
-
-            if (debug)
-            {
-                Pout<< "cyclicPolyPatch::getCentresAndAnchors :"
-                    << " patch:" << name()
-                    << " Specified rotation :"
-                    << " n0:" << n0 << " n1:" << n1 << endl;
-            }
-
-            // Extended tensor from two local coordinate systems calculated
-            // using normal and rotation axis
-            const tensor E0
-            (
-                rotationAxis_,
-                (n0 ^ rotationAxis_),
-                n0
-            );
-            const tensor E1
-            (
-                rotationAxis_,
-                (-n1 ^ rotationAxis_),
-                -n1
-            );
-            const tensor revT(E1.T() & E0);
-
-            // Rotation
-            forAll(half0Ctrs, faceI)
-            {
-                half0Ctrs[faceI] =
-                    Foam::transform
-                    (
-                        revT,
-                        half0Ctrs[faceI] - rotationCentre_
-                    )
-                  + rotationCentre_;
-                anchors0[faceI] =
-                    Foam::transform
-                    (
-                        revT,
-                        anchors0[faceI] - rotationCentre_
-                    )
-                  + rotationCentre_;
-            }
-
-            break;
-        }
-        case TRANSLATIONAL:
+        switch (transform_)
         {
-            // Transform 0 points.
-
-            if (debug)
+            case ROTATIONAL:
             {
-                Pout<< "cyclicPolyPatch::getCentresAndAnchors :"
-                    << " patch:" << name()
-                    << "Specified translation : " << separationVector_
-                    << endl;
-            }
-
-            // Note: getCentresAndAnchors gets called on the slave side
-            // so separationVector is owner-slave points.
+                vector n0 = findFaceMaxRadius(half0Ctrs);
+                vector n1 = -findFaceMaxRadius(half1Ctrs);
+                n0 /= mag(n0) + VSMALL;
+                n1 /= mag(n1) + VSMALL;
 
-            half0Ctrs -= separationVector_;
-            anchors0 -= separationVector_;
-            break;
-        }
-        default:
-        {
-            // Assumes that cyclic is planar. This is also the initial
-            // condition for patches without faces.
-
-            // Determine the face with max area on both halves. These
-            // two faces are used to determine the transformation tensors
-            label max0I = findMaxArea(pp0.points(), pp0);
-            vector n0 = pp0[max0I].normal(pp0.points());
-            n0 /= mag(n0) + VSMALL;
-
-            label max1I = findMaxArea(pp1.points(), pp1);
-            vector n1 = pp1[max1I].normal(pp1.points());
-            n1 /= mag(n1) + VSMALL;
-
-            if (mag(n0 & n1) < 1-matchTolerance())
-            {
                 if (debug)
                 {
                     Pout<< "cyclicPolyPatch::getCentresAndAnchors :"
                         << " patch:" << name()
-                        << " Detected rotation :"
+                        << " Specified rotation :"
                         << " n0:" << n0 << " n1:" << n1 << endl;
                 }
 
-                // Rotation (around origin)
-                const tensor revT(rotationTensor(n0, -n1));
+                // Extended tensor from two local coordinate systems calculated
+                // using normal and rotation axis
+                const tensor E0
+                (
+                    rotationAxis_,
+                    (n0 ^ rotationAxis_),
+                    n0
+                );
+                const tensor E1
+                (
+                    rotationAxis_,
+                    (-n1 ^ rotationAxis_),
+                    -n1
+                );
+                const tensor revT(E1.T() & E0);
 
                 // Rotation
                 forAll(half0Ctrs, faceI)
                 {
-                    half0Ctrs[faceI] = Foam::transform
-                    (
-                        revT,
-                        half0Ctrs[faceI]
-                    );
-                    anchors0[faceI] = Foam::transform
-                    (
-                        revT,
-                        anchors0[faceI]
-                    );
+                    half0Ctrs[faceI] =
+                        Foam::transform
+                        (
+                            revT,
+                            half0Ctrs[faceI] - rotationCentre_
+                        )
+                      + rotationCentre_;
+                    anchors0[faceI] =
+                        Foam::transform
+                        (
+                            revT,
+                            anchors0[faceI] - rotationCentre_
+                        )
+                      + rotationCentre_;
                 }
+
+                break;
             }
-            else
+            case TRANSLATIONAL:
             {
-                // Parallel translation. Get average of all used points.
-
-                const point ctr0(sum(pp0.localPoints())/pp0.nPoints());
-                const point ctr1(sum(pp1.localPoints())/pp1.nPoints());
+                // Transform 0 points.
 
                 if (debug)
                 {
                     Pout<< "cyclicPolyPatch::getCentresAndAnchors :"
                         << " patch:" << name()
-                        << " Detected translation :"
-                        << " n0:" << n0 << " n1:" << n1
-                        << " ctr0:" << ctr0 << " ctr1:" << ctr1 << endl;
+                        << "Specified translation : " << separationVector_
+                        << endl;
                 }
 
-                half0Ctrs += ctr1 - ctr0;
-                anchors0 += ctr1 - ctr0;
+                // Note: getCentresAndAnchors gets called on the slave side
+                // so separationVector is owner-slave points.
+
+                half0Ctrs -= separationVector_;
+                anchors0 -= separationVector_;
+                break;
+            }
+            default:
+            {
+                // Assumes that cyclic is planar. This is also the initial
+                // condition for patches without faces.
+
+                // Determine the face with max area on both halves. These
+                // two faces are used to determine the transformation tensors
+                label max0I = findMaxArea(pp0.points(), pp0);
+                vector n0 = pp0[max0I].normal(pp0.points());
+                n0 /= mag(n0) + VSMALL;
+
+                label max1I = findMaxArea(pp1.points(), pp1);
+                vector n1 = pp1[max1I].normal(pp1.points());
+                n1 /= mag(n1) + VSMALL;
+
+                if (mag(n0 & n1) < 1-matchTolerance())
+                {
+                    if (debug)
+                    {
+                        Pout<< "cyclicPolyPatch::getCentresAndAnchors :"
+                            << " patch:" << name()
+                            << " Detected rotation :"
+                            << " n0:" << n0 << " n1:" << n1 << endl;
+                    }
+
+                    // Rotation (around origin)
+                    const tensor revT(rotationTensor(n0, -n1));
+
+                    // Rotation
+                    forAll(half0Ctrs, faceI)
+                    {
+                        half0Ctrs[faceI] = Foam::transform
+                        (
+                            revT,
+                            half0Ctrs[faceI]
+                        );
+                        anchors0[faceI] = Foam::transform
+                        (
+                            revT,
+                            anchors0[faceI]
+                        );
+                    }
+                }
+                else
+                {
+                    // Parallel translation. Get average of all used points.
+
+                    const point ctr0(sum(pp0.localPoints())/pp0.nPoints());
+                    const point ctr1(sum(pp1.localPoints())/pp1.nPoints());
+
+                    if (debug)
+                    {
+                        Pout<< "cyclicPolyPatch::getCentresAndAnchors :"
+                            << " patch:" << name()
+                            << " Detected translation :"
+                            << " n0:" << n0 << " n1:" << n1
+                            << " ctr0:" << ctr0 << " ctr1:" << ctr1 << endl;
+                    }
+
+                    half0Ctrs += ctr1 - ctr0;
+                    anchors0 += ctr1 - ctr0;
+                }
+                break;
             }
-            break;
         }
     }
 
-
     // Calculate typical distance per face
     tols = matchTolerance()*calcFaceTol(pp1, pp1.points(), half1Ctrs);
 }
@@ -1270,7 +1272,7 @@ bool Foam::cyclicPolyPatch::order
     rotation.setSize(pp.size());
     rotation = 0;
 
-    if (pp.empty() || transform_ == NOORDERING)
+    if (transform_ == NOORDERING)
     {
         // No faces, nothing to change.
         return false;
diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshCheck.C b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshCheck.C
index f5f189dbc41482a4c2c4d9443cc2dd7592ff098d..bf103c225420e5a45add6e802caf3c347d7dda0f 100644
--- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshCheck.C
+++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshCheck.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -25,7 +25,7 @@ License
 
 #include "primitiveMesh.H"
 #include "pyramidPointFaceRef.H"
-#include "tetPointRef.H"
+#include "tetrahedron.H"
 #include "ListOps.H"
 #include "unitConversion.H"
 #include "SortableList.H"
diff --git a/src/sampling/meshToMeshInterpolation/tetOverlapVolume/tetPoints.H b/src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetPoints.H
similarity index 99%
rename from src/sampling/meshToMeshInterpolation/tetOverlapVolume/tetPoints.H
rename to src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetPoints.H
index b23f7540dca3bc411730dcf77e0ddcad7434c1e1..2e1ecf288dcc38a5c52986e3edbbc057f1fef8be 100644
--- a/src/sampling/meshToMeshInterpolation/tetOverlapVolume/tetPoints.H
+++ b/src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetPoints.H
@@ -35,9 +35,9 @@ SourceFiles
 #ifndef tetPoints_H
 #define tetPoints_H
 
+#include "tetrahedron.H"
 #include "FixedList.H"
 #include "treeBoundBox.H"
-#include "tetPointRef.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
diff --git a/src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetrahedron.H b/src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetrahedron.H
index a2ccbc250f657ec50398f06c62d6e124b04cb193..1a76022205d646e8e2cbd36e8c6626d80be1519b 100644
--- a/src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetrahedron.H
+++ b/src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetrahedron.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -54,6 +54,8 @@ namespace Foam
 
 class Istream;
 class Ostream;
+class tetPoints;
+class plane;
 
 // Forward declaration of friend functions and operators
 
@@ -73,6 +75,7 @@ inline Ostream& operator<<
     const tetrahedron<Point, PointRef>&
 );
 
+typedef tetrahedron<point, const point&> tetPointRef;
 
 /*---------------------------------------------------------------------------*\
                            class tetrahedron Declaration
@@ -81,10 +84,71 @@ inline Ostream& operator<<
 template<class Point, class PointRef>
 class tetrahedron
 {
+public:
+
+        // Classes for use in sliceWithPlane. What to do with decomposition
+        // of tet.
+
+            //- Dummy
+            class dummyOp
+            {
+            public:
+                inline void operator()(const tetPoints&);
+            };
+
+            //- Sum resulting volumes
+            class sumVolOp
+            {
+            public:
+                scalar vol_;
+
+                inline sumVolOp();
+
+                inline void operator()(const tetPoints&);
+            };
+
+            //- Store resulting tets
+            class storeOp
+            {
+                FixedList<tetPoints, 200>& tets_;
+                label& nTets_;
+
+            public:
+                inline storeOp(FixedList<tetPoints, 200>&, label&);
+
+                inline void operator()(const tetPoints&);
+            };
+
+private:
+
     // Private data
 
         PointRef a_, b_, c_, d_;
 
+        inline static point planeIntersection
+        (
+            const FixedList<scalar, 4>&,
+            const tetPoints&,
+            const label,
+            const label
+        );
+
+        template<class TetOp>
+        inline static void decomposePrism
+        (
+            const FixedList<point, 6>& points,
+            TetOp& op
+        );
+
+        template<class AboveTetOp, class BelowTetOp>
+        inline static void tetSliceWithPlane
+        (
+            const plane& pl,
+            const tetPoints& tet,
+            AboveTetOp& aboveOp,
+            BelowTetOp& belowOp
+        );
+
 
 public:
 
@@ -184,6 +248,16 @@ public:
             //- Return true if point is inside tetrahedron
             inline bool inside(const point& pt) const;
 
+            //- Decompose tet into tets above and below plane
+            template<class AboveTetOp, class BelowTetOp>
+            inline void sliceWithPlane
+            (
+                const plane& pl,
+                AboveTetOp& aboveOp,
+                BelowTetOp& belowOp
+            ) const;
+
+
             //- Return (min)containment sphere, i.e. the smallest sphere with
             //  all points inside. Returns pointHit with:
             //  - hit         : if sphere is equal to circumsphere
diff --git a/src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetrahedronI.H b/src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetrahedronI.H
index 40b38f806752b7e19cbb134fe561b67c168aff9d..8a69e88e0434b931eb1d7eeadf285f8eea47291e 100644
--- a/src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetrahedronI.H
+++ b/src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetrahedronI.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -25,7 +25,8 @@ License
 
 #include "triangle.H"
 #include "IOstreams.H"
-#include "triPointRef.H"
+#include "tetPoints.H"
+#include "plane.H"
 
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
@@ -492,6 +493,483 @@ bool Foam::tetrahedron<Point, PointRef>::inside(const point& pt) const
 }
 
 
+template<class Point, class PointRef>
+inline void Foam::tetrahedron<Point, PointRef>::dummyOp::operator()
+(
+    const tetPoints&
+)
+{}
+
+
+template<class Point, class PointRef>
+inline Foam::tetrahedron<Point, PointRef>::sumVolOp::sumVolOp()
+:
+    vol_(0.0)
+{}
+
+
+template<class Point, class PointRef>
+inline void Foam::tetrahedron<Point, PointRef>::sumVolOp::operator()
+(
+    const tetPoints& tet
+)
+{
+    vol_ += tet.tet().mag();
+}
+
+
+template<class Point, class PointRef>
+inline Foam::tetrahedron<Point, PointRef>::storeOp::storeOp
+(
+    FixedList<tetPoints, 200>& tets,
+    label& nTets
+)
+:
+    tets_(tets),
+    nTets_(nTets)
+{}
+
+
+template<class Point, class PointRef>
+inline void Foam::tetrahedron<Point, PointRef>::storeOp::operator()
+(
+    const tetPoints& tet
+)
+{
+    tets_[nTets_++] = tet;
+}
+
+
+template<class Point, class PointRef>
+inline Foam::point Foam::tetrahedron<Point, PointRef>::planeIntersection
+(
+    const FixedList<scalar, 4>& d,
+    const tetPoints& t,
+    const label negI,
+    const label posI
+)
+{
+    return
+        (d[posI]*t[negI] - d[negI]*t[posI])
+      / (-d[negI]+d[posI]);
+}
+
+
+template<class Point, class PointRef>
+template<class TetOp>
+inline void Foam::tetrahedron<Point, PointRef>::decomposePrism
+(
+    const FixedList<point, 6>& points,
+    TetOp& op
+)
+{
+    op(tetPoints(points[1], points[3], points[2], points[0]));
+    op(tetPoints(points[1], points[2], points[3], points[4]));
+    op(tetPoints(points[4], points[2], points[3], points[5]));
+}
+
+
+template<class Point, class PointRef>
+template<class AboveTetOp, class BelowTetOp>
+inline void Foam::tetrahedron<Point, PointRef>::
+tetSliceWithPlane
+(
+    const plane& pl,
+    const tetPoints& tet,
+    AboveTetOp& aboveOp,
+    BelowTetOp& belowOp
+)
+{
+    // Distance to plane
+    FixedList<scalar, 4> d;
+    label nPos = 0;
+    forAll(tet, i)
+    {
+        d[i] = ((tet[i]-pl.refPoint()) & pl.normal());
+        if (d[i] > 0)
+        {
+            nPos++;
+        }
+    }
+
+    if (nPos == 4)
+    {
+        aboveOp(tet);
+    }
+    else if (nPos == 3)
+    {
+        // Sliced into below tet and above prism. Prism gets split into
+        // two tets.
+
+        // Find the below tet
+        label i0 = -1;
+        forAll(d, i)
+        {
+            if (d[i] <= 0)
+            {
+                i0 = i;
+                break;
+            }
+        }
+
+        label i1 = d.fcIndex(i0);
+        label i2 = d.fcIndex(i1);
+        label i3 = d.fcIndex(i2);
+
+        point p01 = planeIntersection(d, tet, i0, i1);
+        point p02 = planeIntersection(d, tet, i0, i2);
+        point p03 = planeIntersection(d, tet, i0, i3);
+
+        // i0 = tetCell vertex 0: p01,p02,p03 outwards pointing triad
+        //          ,,         1 :     ,,     inwards pointing triad
+        //          ,,         2 :     ,,     outwards pointing triad
+        //          ,,         3 :     ,,     inwards pointing triad
+
+        //Pout<< "Split 3pos tet " << tet << " d:" << d << " into" << nl;
+
+        if (i0 == 0 || i0 == 2)
+        {
+            tetPoints t(tet[i0], p01, p02, p03);
+            //Pout<< "    belowtet:" << t << " around i0:" << i0 << endl;
+            //checkTet(t, "nPos 3, belowTet i0==0 or 2");
+            belowOp(t);
+
+            // Prism
+            FixedList<point, 6> p;
+            p[0] = tet[i1];
+            p[1] = tet[i3];
+            p[2] = tet[i2];
+            p[3] = p01;
+            p[4] = p03;
+            p[5] = p02;
+            //Pout<< "    aboveprism:" << p << endl;
+            decomposePrism(p, aboveOp);
+        }
+        else
+        {
+            tetPoints t(p01, p02, p03, tet[i0]);
+            //Pout<< "    belowtet:" << t << " around i0:" << i0 << endl;
+            //checkTet(t, "nPos 3, belowTet i0==1 or 3");
+            belowOp(t);
+
+            // Prism
+            FixedList<point, 6> p;
+            p[0] = tet[i3];
+            p[1] = tet[i1];
+            p[2] = tet[i2];
+            p[3] = p03;
+            p[4] = p01;
+            p[5] = p02;
+            //Pout<< "    aboveprism:" << p << endl;
+            decomposePrism(p, aboveOp);
+        }
+    }
+    else if (nPos == 2)
+    {
+        // Tet cut into two prisms. Determine the positive one.
+        label pos0 = -1;
+        label pos1 = -1;
+        label neg0 = -1;
+        label neg1 = -1;
+        forAll(d, i)
+        {
+            if (d[i] > 0)
+            {
+                if (pos0 == -1)
+                {
+                    pos0 = i;
+                }
+                else
+                {
+                    pos1 = i;
+                }
+            }
+            else
+            {
+                if (neg0 == -1)
+                {
+                    neg0 = i;
+                }
+                else
+                {
+                    neg1 = i;
+                }
+            }
+        }
+
+        //Pout<< "Split 2pos tet " << tet << " d:" << d
+        //    << " around pos0:" << pos0 << " pos1:" << pos1
+        //    << " neg0:" << neg0 << " neg1:" << neg1 << " into" << nl;
+
+        const edge posEdge(pos0, pos1);
+
+        if (posEdge == edge(0, 1))
+        {
+            point p02 = planeIntersection(d, tet, 0, 2);
+            point p03 = planeIntersection(d, tet, 0, 3);
+            point p12 = planeIntersection(d, tet, 1, 2);
+            point p13 = planeIntersection(d, tet, 1, 3);
+            // Split the resulting prism
+            {
+                FixedList<point, 6> p;
+                p[0] = tet[0];
+                p[1] = p02;
+                p[2] = p03;
+                p[3] = tet[1];
+                p[4] = p12;
+                p[5] = p13;
+                //Pout<< "    01 aboveprism:" << p << endl;
+                decomposePrism(p, aboveOp);
+            }
+            {
+                FixedList<point, 6> p;
+                p[0] = tet[2];
+                p[1] = p02;
+                p[2] = p12;
+                p[3] = tet[3];
+                p[4] = p03;
+                p[5] = p13;
+                //Pout<< "    01 belowprism:" << p << endl;
+                decomposePrism(p, belowOp);
+            }
+        }
+        else if (posEdge == edge(1, 2))
+        {
+            point p01 = planeIntersection(d, tet, 0, 1);
+            point p13 = planeIntersection(d, tet, 1, 3);
+            point p02 = planeIntersection(d, tet, 0, 2);
+            point p23 = planeIntersection(d, tet, 2, 3);
+            // Split the resulting prism
+            {
+                FixedList<point, 6> p;
+                p[0] = tet[1];
+                p[1] = p01;
+                p[2] = p13;
+                p[3] = tet[2];
+                p[4] = p02;
+                p[5] = p23;
+                //Pout<< "    12 aboveprism:" << p << endl;
+                decomposePrism(p, aboveOp);
+            }
+            {
+                FixedList<point, 6> p;
+                p[0] = tet[3];
+                p[1] = p23;
+                p[2] = p13;
+                p[3] = tet[0];
+                p[4] = p02;
+                p[5] = p01;
+                //Pout<< "    12 belowprism:" << p << endl;
+                decomposePrism(p, belowOp);
+            }
+        }
+        else if (posEdge == edge(2, 0))
+        {
+            point p01 = planeIntersection(d, tet, 0, 1);
+            point p03 = planeIntersection(d, tet, 0, 3);
+            point p12 = planeIntersection(d, tet, 1, 2);
+            point p23 = planeIntersection(d, tet, 2, 3);
+            // Split the resulting prism
+            {
+                FixedList<point, 6> p;
+                p[0] = tet[2];
+                p[1] = p12;
+                p[2] = p23;
+                p[3] = tet[0];
+                p[4] = p01;
+                p[5] = p03;
+                //Pout<< "    20 aboveprism:" << p << endl;
+                decomposePrism(p, aboveOp);
+            }
+            {
+                FixedList<point, 6> p;
+                p[0] = tet[1];
+                p[1] = p12;
+                p[2] = p01;
+                p[3] = tet[3];
+                p[4] = p23;
+                p[5] = p03;
+                //Pout<< "    20 belowprism:" << p << endl;
+                decomposePrism(p, belowOp);
+            }
+        }
+        else if (posEdge == edge(0, 3))
+        {
+            point p01 = planeIntersection(d, tet, 0, 1);
+            point p02 = planeIntersection(d, tet, 0, 2);
+            point p13 = planeIntersection(d, tet, 1, 3);
+            point p23 = planeIntersection(d, tet, 2, 3);
+            // Split the resulting prism
+            {
+                FixedList<point, 6> p;
+                p[0] = tet[3];
+                p[1] = p23;
+                p[2] = p13;
+                p[3] = tet[0];
+                p[4] = p02;
+                p[5] = p01;
+                //Pout<< "    03 aboveprism:" << p << endl;
+                decomposePrism(p, aboveOp);
+            }
+            {
+                FixedList<point, 6> p;
+                p[0] = tet[2];
+                p[1] = p23;
+                p[2] = p02;
+                p[3] = tet[1];
+                p[4] = p13;
+                p[5] = p01;
+                //Pout<< "    03 belowprism:" << p << endl;
+                decomposePrism(p, belowOp);
+            }
+        }
+        else if (posEdge == edge(1, 3))
+        {
+            point p01 = planeIntersection(d, tet, 0, 1);
+            point p12 = planeIntersection(d, tet, 1, 2);
+            point p03 = planeIntersection(d, tet, 0, 3);
+            point p23 = planeIntersection(d, tet, 2, 3);
+            // Split the resulting prism
+            {
+                FixedList<point, 6> p;
+                p[0] = tet[1];
+                p[1] = p12;
+                p[2] = p01;
+                p[3] = tet[3];
+                p[4] = p23;
+                p[5] = p03;
+                //Pout<< "    13 aboveprism:" << p << endl;
+                decomposePrism(p, aboveOp);
+            }
+            {
+                FixedList<point, 6> p;
+                p[0] = tet[2];
+                p[1] = p12;
+                p[2] = p23;
+                p[3] = tet[0];
+                p[4] = p01;
+                p[5] = p03;
+                //Pout<< "    13 belowprism:" << p << endl;
+                decomposePrism(p, belowOp);
+            }
+        }
+        else if (posEdge == edge(2, 3))
+        {
+            point p02 = planeIntersection(d, tet, 0, 2);
+            point p12 = planeIntersection(d, tet, 1, 2);
+            point p03 = planeIntersection(d, tet, 0, 3);
+            point p13 = planeIntersection(d, tet, 1, 3);
+            // Split the resulting prism
+            {
+                FixedList<point, 6> p;
+                p[0] = tet[2];
+                p[1] = p02;
+                p[2] = p12;
+                p[3] = tet[3];
+                p[4] = p03;
+                p[5] = p13;
+                //Pout<< "    23 aboveprism:" << p << endl;
+                decomposePrism(p, aboveOp);
+            }
+            {
+                FixedList<point, 6> p;
+                p[0] = tet[0];
+                p[1] = p02;
+                p[2] = p03;
+                p[3] = tet[1];
+                p[4] = p12;
+                p[5] = p13;
+                //Pout<< "    23 belowprism:" << p << endl;
+                decomposePrism(p, belowOp);
+            }
+        }
+        else
+        {
+            FatalErrorIn("tetSliceWithPlane(..)")
+                << "Missed edge:" << posEdge
+                << abort(FatalError);
+        }
+    }
+    else if (nPos == 1)
+    {
+        // Find the positive tet
+        label i0 = -1;
+        forAll(d, i)
+        {
+            if (d[i] > 0)
+            {
+                i0 = i;
+                break;
+            }
+        }
+
+        label i1 = d.fcIndex(i0);
+        label i2 = d.fcIndex(i1);
+        label i3 = d.fcIndex(i2);
+
+        point p01 = planeIntersection(d, tet, i0, i1);
+        point p02 = planeIntersection(d, tet, i0, i2);
+        point p03 = planeIntersection(d, tet, i0, i3);
+
+        //Pout<< "Split 1pos tet " << tet << " d:" << d << " into" << nl;
+
+        if (i0 == 0 || i0 == 2)
+        {
+            tetPoints t(tet[i0], p01, p02, p03);
+            //Pout<< "    abovetet:" << t << " around i0:" << i0 << endl;
+            //checkTet(t, "nPos 1, aboveTets i0==0 or 2");
+            aboveOp(t);
+
+            // Prism
+            FixedList<point, 6> p;
+            p[0] = tet[i1];
+            p[1] = tet[i3];
+            p[2] = tet[i2];
+            p[3] = p01;
+            p[4] = p03;
+            p[5] = p02;
+            //Pout<< "    belowprism:" << p << endl;
+            decomposePrism(p, belowOp);
+        }
+        else
+        {
+            tetPoints t(p01, p02, p03, tet[i0]);
+            //Pout<< "    abovetet:" << t << " around i0:" << i0 << endl;
+            //checkTet(t, "nPos 1, aboveTets i0==1 or 3");
+            aboveOp(t);
+
+            // Prism
+            FixedList<point, 6> p;
+            p[0] = tet[i3];
+            p[1] = tet[i1];
+            p[2] = tet[i2];
+            p[3] = p03;
+            p[4] = p01;
+            p[5] = p02;
+            //Pout<< "    belowprism:" << p << endl;
+            decomposePrism(p, belowOp);
+        }
+    }
+    else    // nPos == 0
+    {
+        belowOp(tet);
+    }
+}
+
+
+template<class Point, class PointRef>
+template<class AboveTetOp, class BelowTetOp>
+inline void Foam::tetrahedron<Point, PointRef>::sliceWithPlane
+(
+    const plane& pl,
+    AboveTetOp& aboveOp,
+    BelowTetOp& belowOp
+) const
+{
+    tetSliceWithPlane(pl, tetPoints(a_, b_, c_, d_), aboveOp, belowOp);
+}
+
+
 // * * * * * * * * * * * * * * * Ostream Operator  * * * * * * * * * * * * * //
 
 template<class Point, class PointRef>
diff --git a/src/OpenFOAM/primitives/Vector/floatVector/floatVector.H b/src/OpenFOAM/primitives/Vector/floatVector/floatVector.H
index 438adc17765c911b1a1c4a233a0ddc0d436d8538..9d8eee773d2d59f685d95627120e89316dcc6bf8 100644
--- a/src/OpenFOAM/primitives/Vector/floatVector/floatVector.H
+++ b/src/OpenFOAM/primitives/Vector/floatVector/floatVector.H
@@ -47,11 +47,11 @@ namespace Foam
 
 typedef Vector<float> floatVector;
 
-
 //- Data associated with floatVector type are contiguous
+#if !defined(WM_SP)
 template<>
 inline bool contiguous<floatVector>() {return true;}
-
+#endif
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
diff --git a/src/OpenFOAM/primitives/functions/DataEntry/TableFile/TableFile.H b/src/OpenFOAM/primitives/functions/DataEntry/TableFile/TableFile.H
index f128f5ad51e71c38249692d678a85fc389cdfb4a..60106598b1e9d6d1aeec05a86e4add24ecaa9da3 100644
--- a/src/OpenFOAM/primitives/functions/DataEntry/TableFile/TableFile.H
+++ b/src/OpenFOAM/primitives/functions/DataEntry/TableFile/TableFile.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
diff --git a/src/Pstream/dummy/UPstream.C b/src/Pstream/dummy/UPstream.C
index f208ac880e58f752df53d1d882a00a34fc7aad18..5cd8bbcbcbd5cd2e984723939f14bf250433ba4d 100644
--- a/src/Pstream/dummy/UPstream.C
+++ b/src/Pstream/dummy/UPstream.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -74,6 +74,10 @@ void Foam::UPstream::waitRequests(const label start)
 {}
 
 
+void Foam::UPstream::waitRequest(const label i)
+{}
+
+
 bool Foam::UPstream::finishedRequest(const label i)
 {
     notImplemented("UPstream::finishedRequest()");
diff --git a/src/Pstream/mpi/UPstream.C b/src/Pstream/mpi/UPstream.C
index c85f341d8f6708da934caa87654981612c3cca24..1605eca8ce7d62c6dcf656555215a08da98824f3 100644
--- a/src/Pstream/mpi/UPstream.C
+++ b/src/Pstream/mpi/UPstream.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -516,11 +516,55 @@ void Foam::UPstream::waitRequests(const label start)
 }
 
 
+void Foam::UPstream::waitRequest(const label i)
+{
+    if (debug)
+    {
+        Pout<< "UPstream::waitRequest : starting wait for request:" << i
+            << endl;
+    }
+
+    if (i >= PstreamGlobals::outstandingRequests_.size())
+    {
+        FatalErrorIn
+        (
+            "UPstream::waitRequest(const label)"
+        )   << "There are " << PstreamGlobals::outstandingRequests_.size()
+            << " outstanding send requests and you are asking for i=" << i
+            << nl
+            << "Maybe you are mixing blocking/non-blocking comms?"
+            << Foam::abort(FatalError);
+    }
+
+    int flag;
+    if
+    (
+        MPI_Wait
+        (
+           &PstreamGlobals::outstandingRequests_[i],
+            MPI_STATUS_IGNORE
+        )
+    )
+    {
+        FatalErrorIn
+        (
+            "UPstream::waitRequest()"
+        )   << "MPI_Wait returned with error" << Foam::endl;
+    }
+
+    if (debug)
+    {
+        Pout<< "UPstream::waitRequest : finished wait for request:" << i
+            << endl;
+    }
+}
+
+
 bool Foam::UPstream::finishedRequest(const label i)
 {
     if (debug)
     {
-        Pout<< "UPstream::waitRequests : starting wait for request:" << i
+        Pout<< "UPstream::waitRequests : checking finishedRequest:" << i
             << endl;
     }
 
@@ -546,7 +590,7 @@ bool Foam::UPstream::finishedRequest(const label i)
 
     if (debug)
     {
-        Pout<< "UPstream::waitRequests : finished wait for request:" << i
+        Pout<< "UPstream::waitRequests : finished finishedRequest:" << i
             << endl;
     }
 
@@ -554,6 +598,4 @@ bool Foam::UPstream::finishedRequest(const label i)
 }
 
 
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
 // ************************************************************************* //
diff --git a/src/conversion/ensight/file/ensightFile.C b/src/conversion/ensight/file/ensightFile.C
index 7748a236f26234af01cec5b604a39f279f25cda7..9c8219424ba143a71c8ff13fececabbb4b380b7f 100644
--- a/src/conversion/ensight/file/ensightFile.C
+++ b/src/conversion/ensight/file/ensightFile.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -24,6 +24,7 @@ License
 \*---------------------------------------------------------------------------*/
 
 #include "ensightFile.H"
+#include <sstream>
 
 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
 
@@ -31,6 +32,53 @@ bool Foam::ensightFile::allowUndef_ = false;
 
 Foam::scalar Foam::ensightFile::undefValue_ = Foam::floatScalarVGREAT;
 
+// default is width 8
+Foam::string Foam::ensightFile::mask_ = "********";
+
+Foam::string Foam::ensightFile::dirFmt_ = "%08d";
+
+
+// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
+
+Foam::string Foam::ensightFile::mask()
+{
+    return mask_;
+}
+
+
+Foam::string Foam::ensightFile::subDir(const label n)
+{
+    char buf[32];
+
+    sprintf(buf, dirFmt_.c_str(), n);
+    return buf;
+}
+
+
+void Foam::ensightFile::subDirWidth(const label n)
+{
+    // enforce max limit to avoid buffer overflow in subDir()
+    if (n < 1 || n > 31)
+    {
+        return;
+    }
+
+    // appropriate printf format
+    std::ostringstream oss;
+    oss << "%0" << n << "d";
+    dirFmt_ = oss.str();
+
+    // set mask accordingly
+    mask_.resize(n, '*');
+}
+
+
+Foam::label Foam::ensightFile::subDirWidth()
+{
+    return mask_.size();
+}
+
+
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
 Foam::ensightFile::ensightFile
@@ -247,22 +295,4 @@ Foam::Ostream& Foam::ensightFile::writeBinaryHeader()
 }
 
 
-// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
-
-Foam::string Foam::ensightFile::mask()
-{
-    char buf[16] = "********";
-    return buf;
-}
-
-
-Foam::string Foam::ensightFile::subDir(const label n)
-{
-    char buf[16];
-
-    sprintf(buf, "%08d", n);
-    return buf;
-}
-
-
 // ************************************************************************* //
diff --git a/src/conversion/ensight/file/ensightFile.H b/src/conversion/ensight/file/ensightFile.H
index 17cd722c22251a02a6935e03013180913b513b0c..f8c24755b7398704a28c8263ae1f29ada606de5a 100644
--- a/src/conversion/ensight/file/ensightFile.H
+++ b/src/conversion/ensight/file/ensightFile.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -57,6 +57,12 @@ class ensightFile
         //- value to represent undef in results
         static scalar undefValue_;
 
+        //- The '*' mask appropriate for subDir
+        static string mask_;
+
+        //- The printf format for zero-padded subdirectory numbers
+        static string dirFmt_;
+
 
     // Private Member Functions
 
@@ -88,12 +94,19 @@ public:
         //- Return setting for whether 'undef' values are allowed in results
         static bool allowUndef();
 
-        //- '*' mask appropriate for subDir
+        //- The '*' mask appropriate for subDir
         static string mask();
 
-        //- consistent zero-padded numbers for subdirectories
+        //- Consistent zero-padded numbers for subdirectories
         static string subDir(const label);
 
+        //- Set width of subDir and mask. Default width is 8 digits.
+        //  Max width is 31 digits.
+        static void subDirWidth(const label);
+
+        //- Return current width of subDir and mask.
+        static label subDirWidth();
+
 
     // Edit
 
diff --git a/src/dynamicMesh/motionSmoother/polyMeshGeometry/polyMeshGeometry.C b/src/dynamicMesh/motionSmoother/polyMeshGeometry/polyMeshGeometry.C
index afac7228300ea94b007cf43c41a942488c4bcfb3..1670de1c9237f194b283ce13e4d636fa554fb40c 100644
--- a/src/dynamicMesh/motionSmoother/polyMeshGeometry/polyMeshGeometry.C
+++ b/src/dynamicMesh/motionSmoother/polyMeshGeometry/polyMeshGeometry.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -26,7 +26,7 @@ License
 #include "polyMeshGeometry.H"
 #include "polyMeshTetDecomposition.H"
 #include "pyramidPointFaceRef.H"
-#include "tetPointRef.H"
+#include "tetrahedron.H"
 #include "syncTools.H"
 #include "unitConversion.H"
 
diff --git a/src/edgeMesh/edgeFormats/emesh/EMESHedgeFormat.C b/src/edgeMesh/edgeFormats/emesh/EMESHedgeFormat.C
index b7e0be2279d963830f9704f24aed660278fcce63..aa9028e4634772a98305ac2d29da0530e92bee00 100644
--- a/src/edgeMesh/edgeFormats/emesh/EMESHedgeFormat.C
+++ b/src/edgeMesh/edgeFormats/emesh/EMESHedgeFormat.C
@@ -176,7 +176,7 @@ void Foam::fileFormats::EMESHedgeFormat::write
         << "    version     " << os.version() << ";\n"
         << "    format      " << os.format() << ";\n"
         << "    class       " << "featureEdgeMesh" << ";\n"
-        << "    note        " << "written " + clock::dateTime() << nl
+        << "    note        " << "written " + clock::dateTime() << ";\n"
         << "    object      " << filename.name() << ";\n"
         << "}" << nl;
 
diff --git a/src/edgeMesh/extendedFeatureEdgeMesh/extendedFeatureEdgeMesh.C b/src/edgeMesh/extendedFeatureEdgeMesh/extendedFeatureEdgeMesh.C
index 1ec37f1a2f02fd9e3896e763b82201552e65738e..9f621b24ee64fd5fc9e6034496eb0c3fdc4d177d 100644
--- a/src/edgeMesh/extendedFeatureEdgeMesh/extendedFeatureEdgeMesh.C
+++ b/src/edgeMesh/extendedFeatureEdgeMesh/extendedFeatureEdgeMesh.C
@@ -756,6 +756,66 @@ void Foam::extendedFeatureEdgeMesh::nearestFeatureEdgeByType
 }
 
 
+void Foam::extendedFeatureEdgeMesh::allNearestFeatureEdges
+(
+    const point& sample,
+    const scalar searchRadiusSqr,
+    List<pointIndexHit>& info
+) const
+{
+    const PtrList<indexedOctree<treeDataEdge> >& edgeTrees = edgeTreesByType();
+
+    info.setSize(edgeTrees.size());
+
+    labelList sliceStarts(edgeTrees.size());
+
+    sliceStarts[0] = externalStart_;
+    sliceStarts[1] = internalStart_;
+    sliceStarts[2] = flatStart_;
+    sliceStarts[3] = openStart_;
+    sliceStarts[4] = multipleStart_;
+
+    DynamicList<pointIndexHit> dynEdgeHit;
+
+    // Loop over all the feature edge types
+    forAll(edgeTrees, i)
+    {
+        // Pick up all the edges that intersect the search sphere
+        labelList elems = edgeTrees[i].findSphere
+        (
+            sample,
+            searchRadiusSqr
+        );
+
+        forAll(elems, elemI)
+        {
+            label index = elems[elemI];
+            label edgeI = edgeTrees[i].shapes().edgeLabels()[index];
+            const edge& e = edges()[edgeI];
+
+            pointHit hitPoint = e.line(points()).nearestDist(sample);
+
+            label hitIndex = index + sliceStarts[i];
+
+            pointIndexHit nearHit;
+
+            if (!hitPoint.hit())
+            {
+                nearHit = pointIndexHit(true, hitPoint.missPoint(), hitIndex);
+            }
+            else
+            {
+                nearHit = pointIndexHit(true, hitPoint.hitPoint(), hitIndex);
+            }
+
+            dynEdgeHit.append(nearHit);
+        }
+    }
+
+    info.transfer(dynEdgeHit);
+}
+
+
 const Foam::indexedOctree<Foam::treeDataEdge>&
 Foam::extendedFeatureEdgeMesh::edgeTree() const
 {
diff --git a/src/edgeMesh/extendedFeatureEdgeMesh/extendedFeatureEdgeMesh.H b/src/edgeMesh/extendedFeatureEdgeMesh/extendedFeatureEdgeMesh.H
index 82aef34ab0a727db8f77bcc56c799ab462f91924..3268e719c5f7c00da82db4cc2bfee23cb1dadbb9 100644
--- a/src/edgeMesh/extendedFeatureEdgeMesh/extendedFeatureEdgeMesh.H
+++ b/src/edgeMesh/extendedFeatureEdgeMesh/extendedFeatureEdgeMesh.H
@@ -271,6 +271,14 @@ public:
                 List<pointIndexHit>& info
             ) const;
 
+            //- Find all the feature edges within searchDistSqr of sample
+            void allNearestFeatureEdges
+            (
+                const point& sample,
+                const scalar searchRadiusSqr,
+                List<pointIndexHit>& info
+            ) const;
+
         // Access
 
             //- Return the index of the start of the convex feature points
diff --git a/src/fieldSources/basicSource/basicSource/IObasicSourceList.H b/src/fieldSources/basicSource/basicSource/IObasicSourceList.H
index 9b915899fb059a8519e94286192cf973d08578cb..69070b18db33a865361fa022a2fb4bf57a94b58e 100644
--- a/src/fieldSources/basicSource/basicSource/IObasicSourceList.H
+++ b/src/fieldSources/basicSource/basicSource/IObasicSourceList.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -45,7 +45,7 @@ namespace Foam
 {
 
 /*---------------------------------------------------------------------------*\
-                        Class IObasicSourceList Declaration
+                      Class IObasicSourceList Declaration
 \*---------------------------------------------------------------------------*/
 
 class IObasicSourceList
@@ -80,6 +80,8 @@ public:
         {}
 
 
+    // Member Functions
+
         //- Read dictionary
         virtual bool read();
 };
diff --git a/src/fieldSources/basicSource/basicSource/basicSource.C b/src/fieldSources/basicSource/basicSource/basicSource.C
index 40f283a78a06f70daac4619bb4361369793900bd..355073b33a2a190399d585d66684596d6096cbec 100644
--- a/src/fieldSources/basicSource/basicSource/basicSource.C
+++ b/src/fieldSources/basicSource/basicSource/basicSource.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -26,6 +26,7 @@ License
 #include "basicSource.H"
 #include "fvMesh.H"
 #include "fvMatrices.H"
+#include "volFields.H"
 #include "addToRunTimeSelectionTable.H"
 
 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@@ -161,7 +162,7 @@ void Foam::basicSource::setCellSet()
         }
         case smMapRegion:
         {
-            if(active_)
+            if (active_)
             {
                 Info<< indent << "- selecting inter region mapping" << endl;
                 const fvMesh& secondaryMesh =
@@ -170,7 +171,6 @@ void Foam::basicSource::setCellSet()
                 const boundBox secondaryBB = secondaryMesh.bounds();
                 if (secondaryBB.overlaps(primaryBB))
                 {
-
                     // Dummy patches
                     wordList cuttingPatches;
                     HashTable<word> patchMap;
@@ -218,7 +218,7 @@ void Foam::basicSource::setCellSet()
     }
 
     // Set volume information
-    if(selectionMode_ != smMapRegion)
+    if (selectionMode_ != smMapRegion)
     {
         V_ = 0.0;
         forAll(cells_, i)
@@ -303,6 +303,7 @@ Foam::autoPtr<Foam::basicSource> Foam::basicSource::New
     return autoPtr<basicSource>(cstrIter()(name, modelType, coeffs, mesh));
 }
 
+
 Foam::basicSource::~basicSource()
 {
     if (!secondaryToPrimaryInterpPtr_.empty())
@@ -364,6 +365,36 @@ void Foam::basicSource::checkApplied() const
 }
 
 
+void Foam::basicSource::correct(volScalarField& fld)
+{
+    // do nothing
+}
+
+
+void Foam::basicSource::correct(volVectorField& fld)
+{
+    // do nothing
+}
+
+
+void Foam::basicSource::correct(volSphericalTensorField& fld)
+{
+    // do nothing
+}
+
+
+void Foam::basicSource::correct(volSymmTensorField& fld)
+{
+    // do nothing
+}
+
+
+void Foam::basicSource::correct(volTensorField& fld)
+{
+    // do nothing
+}
+
+
 void Foam::basicSource::addSup(fvMatrix<scalar>& eqn, const label fieldI)
 {
     // do nothing
diff --git a/src/fieldSources/basicSource/basicSource/basicSource.H b/src/fieldSources/basicSource/basicSource/basicSource.H
index 1bff3121115e99a8e98eb999b5e3530b9b38ef8c..ca105f90b1883bf444bc9588556e123d3d306101 100644
--- a/src/fieldSources/basicSource/basicSource/basicSource.H
+++ b/src/fieldSources/basicSource/basicSource/basicSource.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -47,6 +47,7 @@ SourceFiles
 #define basicSource_H
 
 #include "fvMatricesFwd.H"
+#include "volFieldsFwd.H"
 #include "cellSet.H"
 #include "autoPtr.H"
 #include "meshToMesh.H"
@@ -60,7 +61,6 @@ namespace Foam
 
 class fvMesh;
 
-
 /*---------------------------------------------------------------------------*\
                          Class basicSource Declaration
 \*---------------------------------------------------------------------------*/
@@ -330,6 +330,24 @@ public:
 
         // Evaluation
 
+            // Correct
+
+                //- Scalar
+                virtual void correct(volScalarField& fld);
+
+                //- Vector
+                virtual void correct(volVectorField& fld);
+
+                //- Spherical tensor
+                virtual void correct(volSphericalTensorField& fld);
+
+                //- Symmetric tensor
+                virtual void correct(volSymmTensorField& fld);
+
+                //- Tensor
+                virtual void correct(volTensorField& fld);
+
+
             // Add explicit and implicit contributions
 
                 //- Scalar
diff --git a/src/fieldSources/basicSource/basicSource/basicSourceI.H b/src/fieldSources/basicSource/basicSource/basicSourceI.H
index 84444144f3071540bd9044cea1c5c86f74b3d2c7..6ffc096defc8473514f2f5f9cf3a48a237ebdb37 100644
--- a/src/fieldSources/basicSource/basicSource/basicSourceI.H
+++ b/src/fieldSources/basicSource/basicSource/basicSourceI.H
@@ -135,4 +135,5 @@ inline const Foam::word Foam::basicSource::mapRegionName() const
     return mapRegionName_;
 }
 
+
 // ************************************************************************* //
diff --git a/src/fieldSources/basicSource/basicSource/basicSourceList.H b/src/fieldSources/basicSource/basicSource/basicSourceList.H
index 5e5b5fda141fae6b082dd5e0cff967faf1fbb35b..7d77de55d12b284cf7fde37abbed53b0f8a9fbd3 100644
--- a/src/fieldSources/basicSource/basicSource/basicSourceList.H
+++ b/src/fieldSources/basicSource/basicSource/basicSourceList.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -95,6 +95,11 @@ public:
 
     // Member Functions
 
+        //- Correct
+        template<class Type>
+        void correct(GeometricField<Type, fvPatchField, volMesh>& fld);
+
+
         // Sources
 
             //- Return source for equation
diff --git a/src/fieldSources/basicSource/basicSource/basicSourceListTemplates.C b/src/fieldSources/basicSource/basicSource/basicSourceListTemplates.C
index aafa91d0983a83a4f3b7cac66847629f2b1e916f..7c83f7f5224906b5bcca627ec70cf3360095689c 100644
--- a/src/fieldSources/basicSource/basicSource/basicSourceListTemplates.C
+++ b/src/fieldSources/basicSource/basicSource/basicSourceListTemplates.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -25,6 +25,39 @@ License
 
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
+template<class Type>
+void Foam::basicSourceList::correct
+(
+    GeometricField<Type, fvPatchField, volMesh>& fld
+)
+{
+    const word& fieldName = fld.name();
+
+    forAll(*this, i)
+    {
+        basicSource& source = this->operator[](i);
+
+        label fieldI = source.applyToField(fieldName);
+
+        if (fieldI != -1)
+        {
+            source.setApplied(fieldI);
+
+            if (source.isActive())
+            {
+                if (debug)
+                {
+                    Info<< "Correcting source " << source.name()
+                        << " for field " << fieldName << endl;
+                }
+
+                source.correct(fld);
+            }
+        }
+    }
+}
+
+
 template<class Type>
 Foam::tmp<Foam::fvMatrix<Type> > Foam::basicSourceList::operator()
 (
diff --git a/src/fieldSources/basicSource/pressureGradientExplicitSource/pressureGradientExplicitSource.C b/src/fieldSources/basicSource/pressureGradientExplicitSource/pressureGradientExplicitSource.C
index e3ff7ca50e6c28b25745108e428f86fadc5430d6..c13720b831923e6f251b0885d24948d76b9757fa 100644
--- a/src/fieldSources/basicSource/pressureGradientExplicitSource/pressureGradientExplicitSource.C
+++ b/src/fieldSources/basicSource/pressureGradientExplicitSource/pressureGradientExplicitSource.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -69,53 +69,6 @@ void Foam::pressureGradientExplicitSource::writeGradP() const
 }
 
 
-void Foam::pressureGradientExplicitSource::update(fvMatrix<vector>& eqn)
-{
-    volVectorField& U = const_cast<volVectorField&>(eqn.psi());
-
-    const volScalarField& rAU =
-        mesh_.lookupObject<volScalarField>("(1|A(" + U.name() + "))");
-
-    // Integrate flow variables over cell set
-    scalar magUbarAve = 0.0;
-    scalar rAUave = 0.0;
-    const scalarField& cv = mesh_.V();
-    forAll(cells_, i)
-    {
-        label cellI = cells_[i];
-        scalar volCell = cv[cellI];
-        magUbarAve += (flowDir_ & U[cellI])*volCell;
-        rAUave += rAU[cellI]*volCell;
-    }
-
-    // Collect across all processors
-    reduce(magUbarAve, sumOp<scalar>());
-
-    // Volume averages
-    magUbarAve /= V_;
-    rAUave /= V_;
-
-    // Calculate the pressure gradient increment needed to adjust the average
-    // flow-rate to the desired value
-    scalar gradPplus = (mag(Ubar_) - magUbarAve)/rAUave;
-
-    // Apply correction to velocity field
-    forAll(cells_, i)
-    {
-        label cellI = cells_[i];
-        U[cellI] += flowDir_*rAU[cellI]*gradPplus;
-    }
-
-    // Update pressure gradient
-    gradP_.value() += gradPplus;
-
-    Info<< "Uncorrected Ubar = " << magUbarAve << tab
-        << "Pressure gradient = " << gradP_.value() << endl;
-
-    writeGradP();
-}
-
-
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
 Foam::pressureGradientExplicitSource::pressureGradientExplicitSource
@@ -123,7 +76,7 @@ Foam::pressureGradientExplicitSource::pressureGradientExplicitSource
     const word& sourceName,
     const word& modelType,
     const dictionary& dict,
-    const fvMesh& mesh    
+    const fvMesh& mesh
 )
 :
     basicSource(sourceName, modelType, dict, mesh),
@@ -133,6 +86,23 @@ Foam::pressureGradientExplicitSource::pressureGradientExplicitSource
     flowDir_(Ubar_/mag(Ubar_))
 {
     coeffs_.lookup("fieldNames") >> fieldNames_;
+
+    if (fieldNames_.size() != 1)
+    {
+        FatalErrorIn
+        (
+            "Foam::pressureGradientExplicitSource::"
+            "pressureGradientExplicitSource"
+            "("
+                "onst word&, "
+                "const word&, "
+                "const dictionary&, "
+                "const fvMesh&"
+            ")"
+        )   << "Source can only be applied to a single field.  Current "
+            << "settings are:" << fieldNames_ << exit(FatalError);
+    }
+
     applied_.setSize(fieldNames_.size(), false);
 
     // Read the initial pressure gradient from file if it exists
@@ -160,8 +130,6 @@ void Foam::pressureGradientExplicitSource::addSup
     const label fieldI
 )
 {
-    update(eqn);
-
     DimensionedField<vector, volMesh> Su
     (
         IOobject
@@ -178,7 +146,53 @@ void Foam::pressureGradientExplicitSource::addSup
 
     UIndirectList<vector>(Su, cells_) = flowDir_*gradP_.value();
 
-    eqn -= Su;
+    eqn += Su;
+}
+
+
+void Foam::pressureGradientExplicitSource::correct(volVectorField& U)
+{
+    const volScalarField& rAU =
+        mesh_.lookupObject<volScalarField>("(1|A(" + U.name() + "))");
+
+    // Integrate flow variables over cell set
+    scalar magUbarAve = 0.0;
+    scalar rAUave = 0.0;
+    const scalarField& cv = mesh_.V();
+    forAll(cells_, i)
+    {
+        label cellI = cells_[i];
+        scalar volCell = cv[cellI];
+        magUbarAve += (flowDir_ & U[cellI])*volCell;
+        rAUave += rAU[cellI]*volCell;
+    }
+
+    // Collect across all processors
+    reduce(magUbarAve, sumOp<scalar>());
+    reduce(rAUave, sumOp<scalar>());
+
+    // Volume averages
+    magUbarAve /= V_;
+    rAUave /= V_;
+
+    // Calculate the pressure gradient increment needed to adjust the average
+    // flow-rate to the desired value
+    scalar gradPplus = (mag(Ubar_) - magUbarAve)/rAUave;
+
+    // Apply correction to velocity field
+    forAll(cells_, i)
+    {
+        label cellI = cells_[i];
+        U[cellI] += flowDir_*rAU[cellI]*gradPplus;
+    }
+
+    // Update pressure gradient
+    gradP_.value() += gradPplus;
+
+    Info<< "Pressure gradient source: uncorrected Ubar = " << magUbarAve
+        << ", pressure gradient = " << gradP_.value() << endl;
+
+    writeGradP();
 }
 
 
diff --git a/src/fieldSources/basicSource/pressureGradientExplicitSource/pressureGradientExplicitSource.H b/src/fieldSources/basicSource/pressureGradientExplicitSource/pressureGradientExplicitSource.H
index 287c1701f3f8cdb85ebd3dfd28984ed2edf9ddda..bf760254afb888a6a80fc8039dad9fc1b028f7ff 100644
--- a/src/fieldSources/basicSource/pressureGradientExplicitSource/pressureGradientExplicitSource.H
+++ b/src/fieldSources/basicSource/pressureGradientExplicitSource/pressureGradientExplicitSource.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -118,7 +118,10 @@ public:
 
     // Member Functions
 
-        // Access
+        // Evaluate
+
+            //- Correct the pressure gradient
+            virtual void correct(volVectorField& U);
 
             //- Add explicit contribution to equation
             virtual void addSup(fvMatrix<vector>& eqn, const label fieldI);
diff --git a/src/finiteVolume/Make/files b/src/finiteVolume/Make/files
index 2d4930f3851def77abcdf42527abc4a6c312f6ba..db1aee788a3152ac089918a42dd0021d269ed7fb 100644
--- a/src/finiteVolume/Make/files
+++ b/src/finiteVolume/Make/files
@@ -170,7 +170,7 @@ $(derivedFvPatchFields)/swirlFlowRateInletVelocity/swirlFlowRateInletVelocityFvP
 $(derivedFvPatchFields)/cylindricalInletVelocity/cylindricalInletVelocityFvPatchVectorField.C
 $(derivedFvPatchFields)/outletMappedUniformInlet/outletMappedUniformInletFvPatchFields.C
 $(derivedFvPatchFields)/waveSurfacePressure/waveSurfacePressureFvPatchScalarField.C
-
+$(derivedFvPatchFields)/phaseHydrostaticPressure/phaseHydrostaticPressureFvPatchScalarField.C
 
 fvsPatchFields = fields/fvsPatchFields
 $(fvsPatchFields)/fvsPatchField/fvsPatchFields.C
diff --git a/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.C
index acf50983ef8971edf292e3d669e52426f6db2f9c..f530fd1ac9d6e2955bc05e8c5465dacdda4c7309 100644
--- a/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.C
+++ b/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -198,6 +198,17 @@ tmp<Field<Type> > slicedFvPatchField<Type>::patchInternalField() const
 }
 
 
+template<class Type>
+void slicedFvPatchField<Type>::patchInternalField(Field<Type>&) const
+{
+    notImplemented
+    (
+        "slicedFvPatchField<Type>::"
+        "patchInternalField(Field<Type>&)"
+    );
+}
+
+
 template<class Type>
 tmp<Field<Type> > slicedFvPatchField<Type>::patchNeighbourField
 (
diff --git a/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.H
index 9784c51323d4be818a58d1f1898e32669dc74b7e..a40d212cd70e35470b2b9a7f594a0bb10adae8e6 100644
--- a/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.H
+++ b/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -148,6 +148,9 @@ public:
             //- Return internal field next to patch as patch field
             virtual tmp<Field<Type> > patchInternalField() const;
 
+            //- Return internal field next to patch as patch field
+            virtual void patchInternalField(Field<Type>&) const;
+
             //- Return neighbour coupled given internal cell data
             virtual tmp<Field<Type> > patchNeighbourField
             (
diff --git a/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchField.C
index 4bf8e67cd798a2b38d7a8e693f715fabb1e32153..a44ea4cc5c9c4f789006e4134a673d201cb53077 100644
--- a/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchField.C
+++ b/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchField.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -43,7 +43,12 @@ processorFvPatchField<Type>::processorFvPatchField
 )
 :
     coupledFvPatchField<Type>(p, iF),
-    procPatch_(refCast<const processorFvPatch>(p))
+    procPatch_(refCast<const processorFvPatch>(p)),
+    sendBuf_(0),
+    outstandingSendRequest_(-1),
+    outstandingRecvRequest_(-1),
+    scalarSendBuf_(0),
+    scalarReceiveBuf_(0)
 {}
 
 
@@ -56,7 +61,12 @@ processorFvPatchField<Type>::processorFvPatchField
 )
 :
     coupledFvPatchField<Type>(p, iF, f),
-    procPatch_(refCast<const processorFvPatch>(p))
+    procPatch_(refCast<const processorFvPatch>(p)),
+    sendBuf_(0),
+    outstandingSendRequest_(-1),
+    outstandingRecvRequest_(-1),
+    scalarSendBuf_(0),
+    scalarReceiveBuf_(0)
 {}
 
 
@@ -71,7 +81,12 @@ processorFvPatchField<Type>::processorFvPatchField
 )
 :
     coupledFvPatchField<Type>(ptf, p, iF, mapper),
-    procPatch_(refCast<const processorFvPatch>(p))
+    procPatch_(refCast<const processorFvPatch>(p)),
+    sendBuf_(0),
+    outstandingSendRequest_(-1),
+    outstandingRecvRequest_(-1),
+    scalarSendBuf_(0),
+    scalarReceiveBuf_(0)
 {
     if (!isA<processorFvPatch>(this->patch()))
     {
@@ -91,6 +106,12 @@ processorFvPatchField<Type>::processorFvPatchField
             << " in file " << this->dimensionedInternalField().objectPath()
             << exit(FatalIOError);
     }
+    if (debug && !ptf.ready())
+    {
+        FatalErrorIn("processorFvPatchField<Type>::processorFvPatchField(..)")
+            << "On patch " << procPatch_.name() << " outstanding request."
+            << abort(FatalError);
+    }
 }
 
 
@@ -103,7 +124,12 @@ processorFvPatchField<Type>::processorFvPatchField
 )
 :
     coupledFvPatchField<Type>(p, iF, dict),
-    procPatch_(refCast<const processorFvPatch>(p))
+    procPatch_(refCast<const processorFvPatch>(p)),
+    sendBuf_(0),
+    outstandingSendRequest_(-1),
+    outstandingRecvRequest_(-1),
+    scalarSendBuf_(0),
+    scalarReceiveBuf_(0)
 {
     if (!isA<processorFvPatch>(p))
     {
@@ -134,8 +160,20 @@ processorFvPatchField<Type>::processorFvPatchField
 :
     processorLduInterfaceField(),
     coupledFvPatchField<Type>(ptf),
-    procPatch_(refCast<const processorFvPatch>(ptf.patch()))
-{}
+    procPatch_(refCast<const processorFvPatch>(ptf.patch())),
+    sendBuf_(ptf.sendBuf_.xfer()),
+    outstandingSendRequest_(-1),
+    outstandingRecvRequest_(-1),
+    scalarSendBuf_(ptf.scalarSendBuf_.xfer()),
+    scalarReceiveBuf_(ptf.scalarReceiveBuf_.xfer())
+{
+    if (debug && !ptf.ready())
+    {
+        FatalErrorIn("processorFvPatchField<Type>::processorFvPatchField(..)")
+            << "On patch " << procPatch_.name() << " outstanding request."
+            << abort(FatalError);
+    }
+}
 
 
 template<class Type>
@@ -146,8 +184,20 @@ processorFvPatchField<Type>::processorFvPatchField
 )
 :
     coupledFvPatchField<Type>(ptf, iF),
-    procPatch_(refCast<const processorFvPatch>(ptf.patch()))
-{}
+    procPatch_(refCast<const processorFvPatch>(ptf.patch())),
+    sendBuf_(0),
+    outstandingSendRequest_(-1),
+    outstandingRecvRequest_(-1),
+    scalarSendBuf_(0),
+    scalarReceiveBuf_(0)
+{
+    if (debug && !ptf.ready())
+    {
+        FatalErrorIn("processorFvPatchField<Type>::processorFvPatchField(..)")
+            << "On patch " << procPatch_.name() << " outstanding request."
+            << abort(FatalError);
+    }
+}
 
 
 // * * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * //
@@ -162,6 +212,13 @@ processorFvPatchField<Type>::~processorFvPatchField()
 template<class Type>
 tmp<Field<Type> > processorFvPatchField<Type>::patchNeighbourField() const
 {
+    if (debug && !this->ready())
+    {
+        FatalErrorIn("processorFvPatchField<Type>::patchNeighbourField()")
+            << "On patch " << procPatch_.name()
+            << " outstanding request."
+            << abort(FatalError);
+    }
     return *this;
 }
 
@@ -174,7 +231,36 @@ void processorFvPatchField<Type>::initEvaluate
 {
     if (Pstream::parRun())
     {
-        procPatch_.compressedSend(commsType, this->patchInternalField()());
+        this->patchInternalField(sendBuf_);
+
+        if (commsType == Pstream::nonBlocking && !Pstream::floatTransfer)
+        {
+            // Fast path. Receive into *this
+            this->setSize(sendBuf_.size());
+            outstandingRecvRequest_ = UPstream::nRequests();
+            IPstream::read
+            (
+                Pstream::nonBlocking,
+                procPatch_.neighbProcNo(),
+                reinterpret_cast<char*>(this->begin()),
+                this->byteSize(),
+                procPatch_.tag()
+            );
+
+            outstandingSendRequest_ = UPstream::nRequests();
+            OPstream::write
+            (
+                Pstream::nonBlocking,
+                procPatch_.neighbProcNo(),
+                reinterpret_cast<const char*>(sendBuf_.begin()),
+                this->byteSize(),
+                procPatch_.tag()
+            );
+        }
+        else
+        {
+            procPatch_.compressedSend(commsType, sendBuf_);
+        }
     }
 }
 
@@ -187,7 +273,25 @@ void processorFvPatchField<Type>::evaluate
 {
     if (Pstream::parRun())
     {
-        procPatch_.compressedReceive<Type>(commsType, *this);
+        if (commsType == Pstream::nonBlocking && !Pstream::floatTransfer)
+        {
+            // Fast path. Received into *this
+
+            if
+            (
+                outstandingRecvRequest_ >= 0
+             && outstandingRecvRequest_ < Pstream::nRequests()
+            )
+            {
+                UPstream::waitRequest(outstandingRecvRequest_);
+            }
+            outstandingSendRequest_ = -1;
+            outstandingRecvRequest_ = -1;
+        }
+        else
+        {
+            procPatch_.compressedReceive<Type>(commsType, *this);
+        }
 
         if (doTransform())
         {
@@ -215,11 +319,49 @@ void processorFvPatchField<Type>::initInterfaceMatrixUpdate
     const Pstream::commsTypes commsType
 ) const
 {
-    procPatch_.compressedSend
-    (
-        commsType,
-        this->patch().patchInternalField(psiInternal)()
-    );
+    this->patch().patchInternalField(psiInternal, scalarSendBuf_);
+
+    if (commsType == Pstream::nonBlocking && !Pstream::floatTransfer)
+    {
+        // Fast path.
+        if (debug && !this->ready())
+        {
+            FatalErrorIn
+            (
+                "processorFvPatchField<Type>::initInterfaceMatrixUpdate(..)"
+            )   << "On patch " << procPatch_.name()
+                << " outstanding request."
+                << abort(FatalError);
+        }
+
+
+        scalarReceiveBuf_.setSize(scalarSendBuf_.size());
+        outstandingRecvRequest_ = UPstream::nRequests();
+        IPstream::read
+        (
+            Pstream::nonBlocking,
+            procPatch_.neighbProcNo(),
+            reinterpret_cast<char*>(scalarReceiveBuf_.begin()),
+            scalarReceiveBuf_.byteSize(),
+            procPatch_.tag()
+        );
+
+        outstandingSendRequest_ = UPstream::nRequests();
+        OPstream::write
+        (
+            Pstream::nonBlocking,
+            procPatch_.neighbProcNo(),
+            reinterpret_cast<const char*>(scalarSendBuf_.begin()),
+            scalarSendBuf_.byteSize(),
+            procPatch_.tag()
+        );
+    }
+    else
+    {
+        procPatch_.compressedSend(commsType, scalarSendBuf_);
+    }
+
+    const_cast<processorFvPatchField<Type>&>(*this).updatedMatrix() = false;
 }
 
 
@@ -234,22 +376,92 @@ void processorFvPatchField<Type>::updateInterfaceMatrix
     const Pstream::commsTypes commsType
 ) const
 {
-    scalarField pnf
-    (
-        procPatch_.compressedReceive<scalar>(commsType, this->size())()
-    );
+    if (this->updatedMatrix())
+    {
+        return;
+    }
 
-    // Transform according to the transformation tensor
-    transformCoupleField(pnf, cmpt);
+    const labelUList& faceCells = this->patch().faceCells();
 
-    // Multiply the field by coefficients and add into the result
+    if (commsType == Pstream::nonBlocking && !Pstream::floatTransfer)
+    {
+        // Fast path.
+        if
+        (
+            outstandingRecvRequest_ >= 0
+         && outstandingRecvRequest_ < Pstream::nRequests()
+        )
+        {
+            UPstream::waitRequest(outstandingRecvRequest_);
+        }
+        // Recv finished so assume sending finished as well.
+        outstandingSendRequest_ = -1;
+        outstandingRecvRequest_ = -1;
 
-    const labelUList& faceCells = this->patch().faceCells();
+        // Consume straight from scalarReceiveBuf_
+
+        // Transform according to the transformation tensor
+        transformCoupleField(scalarReceiveBuf_, cmpt);
+
+        // Multiply the field by coefficients and add into the result
+        forAll(faceCells, elemI)
+        {
+            result[faceCells[elemI]] -= coeffs[elemI]*scalarReceiveBuf_[elemI];
+        }
+    }
+    else
+    {
+        scalarField pnf
+        (
+            procPatch_.compressedReceive<scalar>(commsType, this->size())()
+        );
+
+        // Transform according to the transformation tensor
+        transformCoupleField(pnf, cmpt);
+
+        // Multiply the field by coefficients and add into the result
+        forAll(faceCells, elemI)
+        {
+            result[faceCells[elemI]] -= coeffs[elemI]*pnf[elemI];
+        }
+    }
+
+    const_cast<processorFvPatchField<Type>&>(*this).updatedMatrix() = true;
+}
+
+
+template<class Type>
+bool processorFvPatchField<Type>::ready() const
+{
+    if
+    (
+        outstandingSendRequest_ >= 0
+     && outstandingSendRequest_ < Pstream::nRequests()
+    )
+    {
+        bool finished = UPstream::finishedRequest(outstandingSendRequest_);
+        if (!finished)
+        {
+            return false;
+        }
+    }
+    outstandingSendRequest_ = -1;
 
-    forAll(faceCells, elemI)
+    if
+    (
+        outstandingRecvRequest_ >= 0
+     && outstandingRecvRequest_ < Pstream::nRequests()
+    )
     {
-        result[faceCells[elemI]] -= coeffs[elemI]*pnf[elemI];
+        bool finished = UPstream::finishedRequest(outstandingRecvRequest_);
+        if (!finished)
+        {
+            return false;
+        }
     }
+    outstandingRecvRequest_ = -1;
+
+    return true;
 }
 
 
diff --git a/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchField.H
index 0130909d04d4a88bbe8c46dd8af564bc8a0a5491..9541e80ea56a3f040837f5092cddee9e90320412 100644
--- a/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchField.H
+++ b/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchField.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -59,6 +59,22 @@ class processorFvPatchField
         //- Local reference cast into the processor patch
         const processorFvPatch& procPatch_;
 
+        // Sending and receiving
+
+            //- Send buffer.
+            mutable Field<Type> sendBuf_;
+
+            //- Outstanding request
+            mutable label outstandingSendRequest_;
+
+            //- Outstanding request
+            mutable label outstandingRecvRequest_;
+
+            //- Scalar send buffer
+            mutable Field<scalar> scalarSendBuf_;
+
+            //- Scalar receive buffer
+            mutable Field<scalar> scalarReceiveBuf_;
 
 public:
 
@@ -179,6 +195,9 @@ public:
                 const Pstream::commsTypes commsType
             ) const;
 
+            //- Is all data available
+            virtual bool ready() const;
+
             //- Update result field based on interface functionality
             virtual void updateInterfaceMatrix
             (
@@ -221,6 +240,7 @@ public:
             {
                 return pTraits<Type>::rank;
             }
+
 };
 
 
diff --git a/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchScalarField.C
index b94e8049f9872ed4011cb56ebdcc6d9168491366..c15b1c1be7f8950c9354099b2913704bb2c41840 100644
--- a/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchScalarField.C
+++ b/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchScalarField.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -43,11 +43,53 @@ void processorFvPatchField<scalar>::initInterfaceMatrixUpdate
     const Pstream::commsTypes commsType
 ) const
 {
-    procPatch_.compressedSend
+    this->patch().patchInternalField(psiInternal, scalarSendBuf_);
+
+    if
     (
-        commsType,
-        patch().patchInternalField(psiInternal)()
-    );
+        Pstream::defaultCommsType == Pstream::nonBlocking
+    && !Pstream::floatTransfer
+    )
+    {
+        // Fast path.
+        if (debug && !this->ready())
+        {
+            FatalErrorIn
+            (
+                "processorFvPatchField<scalar>::initInterfaceMatrixUpdate(..)"
+            )   << "On patch " << procPatch_.name()
+                << " outstanding request."
+                << abort(FatalError);
+        }
+
+
+        scalarReceiveBuf_.setSize(scalarSendBuf_.size());
+        outstandingRecvRequest_ = UPstream::nRequests();
+        IPstream::read
+        (
+            Pstream::nonBlocking,
+            procPatch_.neighbProcNo(),
+            reinterpret_cast<char*>(scalarReceiveBuf_.begin()),
+            scalarReceiveBuf_.byteSize(),
+            procPatch_.tag()
+        );
+
+        outstandingSendRequest_ = UPstream::nRequests();
+        OPstream::write
+        (
+            Pstream::nonBlocking,
+            procPatch_.neighbProcNo(),
+            reinterpret_cast<const char*>(scalarSendBuf_.begin()),
+            scalarSendBuf_.byteSize(),
+            procPatch_.tag()
+        );
+    }
+    else
+    {
+        procPatch_.compressedSend(commsType, scalarSendBuf_);
+    }
+
+    const_cast<processorFvPatchField<scalar>&>(*this).updatedMatrix() = false;
 }
 
 
@@ -62,17 +104,48 @@ void processorFvPatchField<scalar>::updateInterfaceMatrix
     const Pstream::commsTypes commsType
 ) const
 {
-    scalarField pnf
-    (
-        procPatch_.compressedReceive<scalar>(commsType, this->size())()
-    );
+    if (this->updatedMatrix())
+    {
+        return;
+    }
 
-    const labelUList& faceCells = patch().faceCells();
+    const labelUList& faceCells = this->patch().faceCells();
 
-    forAll(faceCells, facei)
+    if (commsType == Pstream::nonBlocking && !Pstream::floatTransfer)
     {
-        result[faceCells[facei]] -= coeffs[facei]*pnf[facei];
+        // Fast path.
+        if
+        (
+            outstandingRecvRequest_ >= 0
+         && outstandingRecvRequest_ < Pstream::nRequests()
+        )
+        {
+            UPstream::waitRequest(outstandingRecvRequest_);
+        }
+        outstandingSendRequest_ = -1;
+        outstandingRecvRequest_ = -1;
+
+
+        // Consume straight from scalarReceiveBuf_
+        forAll(faceCells, elemI)
+        {
+            result[faceCells[elemI]] -= coeffs[elemI]*scalarReceiveBuf_[elemI];
+        }
     }
+    else
+    {
+        scalarField pnf
+        (
+            procPatch_.compressedReceive<scalar>(commsType, this->size())()
+        );
+
+        forAll(faceCells, elemI)
+        {
+            result[faceCells[elemI]] -= coeffs[elemI]*pnf[elemI];
+        }
+    }
+
+    const_cast<processorFvPatchField<scalar>&>(*this).updatedMatrix() = true;
 }
 
 
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/phaseHydrostaticPressure/phaseHydrostaticPressureFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/phaseHydrostaticPressure/phaseHydrostaticPressureFvPatchScalarField.C
new file mode 100644
index 0000000000000000000000000000000000000000..6b9a22da0fb48fb67df5eaf87b91098a236a341d
--- /dev/null
+++ b/src/finiteVolume/fields/fvPatchFields/derived/phaseHydrostaticPressure/phaseHydrostaticPressureFvPatchScalarField.C
@@ -0,0 +1,202 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+     \\/     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 3 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, see <http://www.gnu.org/licenses/>.
+
+\*---------------------------------------------------------------------------*/
+
+#include "phaseHydrostaticPressureFvPatchScalarField.H"
+#include "addToRunTimeSelectionTable.H"
+#include "fvPatchFieldMapper.H"
+#include "volFields.H"
+#include "surfaceFields.H"
+#include "uniformDimensionedFields.H"
+
+// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
+
+Foam::phaseHydrostaticPressureFvPatchScalarField::
+phaseHydrostaticPressureFvPatchScalarField
+(
+    const fvPatch& p,
+    const DimensionedField<scalar, volMesh>& iF
+)
+:
+    mixedFvPatchScalarField(p, iF),
+    phaseName_("alpha"),
+    rho_(0.0),
+    pRefValue_(0.0),
+    pRefPoint_(vector::zero)
+{
+    this->refValue() = 0.0;
+    this->refGrad() = 0.0;
+    this->valueFraction() = 0.0;
+}
+
+
+Foam::phaseHydrostaticPressureFvPatchScalarField::
+phaseHydrostaticPressureFvPatchScalarField
+(
+    const fvPatch& p,
+    const DimensionedField<scalar, volMesh>& iF,
+    const dictionary& dict
+)
+:
+    mixedFvPatchScalarField(p, iF),
+    phaseName_(dict.lookupOrDefault<word>("phaseName", "alpha")),
+    rho_(readScalar(dict.lookup("rho"))),
+    pRefValue_(readScalar(dict.lookup("pRefValue"))),
+    pRefPoint_(dict.lookup("pRefPoint"))
+{
+    this->refValue() = pRefValue_;
+
+    if (dict.found("value"))
+    {
+        fvPatchScalarField::operator=
+        (
+            scalarField("value", dict, p.size())
+        );
+    }
+    else
+    {
+        fvPatchScalarField::operator=(this->refValue());
+    }
+
+    this->refGrad() = 0.0;
+    this->valueFraction() = 0.0;
+}
+
+
+Foam::phaseHydrostaticPressureFvPatchScalarField::
+phaseHydrostaticPressureFvPatchScalarField
+(
+    const phaseHydrostaticPressureFvPatchScalarField& ptf,
+    const fvPatch& p,
+    const DimensionedField<scalar, volMesh>& iF,
+    const fvPatchFieldMapper& mapper
+)
+:
+    mixedFvPatchScalarField(ptf, p, iF, mapper),
+    phaseName_(ptf.phaseName_),
+    rho_(ptf.rho_),
+    pRefValue_(ptf.pRefValue_),
+    pRefPoint_(ptf.pRefPoint_)
+{}
+
+
+Foam::phaseHydrostaticPressureFvPatchScalarField::
+phaseHydrostaticPressureFvPatchScalarField
+(
+    const phaseHydrostaticPressureFvPatchScalarField& ptf
+)
+:
+    mixedFvPatchScalarField(ptf),
+    phaseName_(ptf.phaseName_)
+{}
+
+
+Foam::phaseHydrostaticPressureFvPatchScalarField::
+phaseHydrostaticPressureFvPatchScalarField
+(
+    const phaseHydrostaticPressureFvPatchScalarField& ptf,
+    const DimensionedField<scalar, volMesh>& iF
+)
+:
+    mixedFvPatchScalarField(ptf, iF),
+    phaseName_(ptf.phaseName_),
+    rho_(ptf.rho_),
+    pRefValue_(ptf.pRefValue_),
+    pRefPoint_(ptf.pRefPoint_)
+{}
+
+
+// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
+
+void Foam::phaseHydrostaticPressureFvPatchScalarField::updateCoeffs()
+{
+    if (this->updated())
+    {
+        return;
+    }
+
+    const scalarField& alphap =
+        patch().lookupPatchField<volScalarField, scalar>
+        (
+            phaseName_
+        );
+
+    const uniformDimensionedVectorField& g =
+        db().lookupObject<uniformDimensionedVectorField>("g");
+
+    // scalar rhor = 1000;
+    // scalarField alphap1 = max(min(alphap, 1.0), 0.0);
+    // valueFraction() = alphap1/(alphap1 + rhor*(1.0 - alphap1));
+    valueFraction() = max(min(alphap, 1.0), 0.0);
+
+    refValue() =
+        pRefValue_
+      + rho_*((g.value() & patch().Cf()) - (g.value() & pRefPoint_));
+
+    mixedFvPatchScalarField::updateCoeffs();
+}
+
+
+void Foam::phaseHydrostaticPressureFvPatchScalarField::write(Ostream& os) const
+{
+    fvPatchScalarField::write(os);
+    if (phaseName_ != "alpha")
+    {
+        os.writeKeyword("phaseName")
+            << phaseName_ << token::END_STATEMENT << nl;
+    }
+    os.writeKeyword("rho") << rho_ << token::END_STATEMENT << nl;
+    os.writeKeyword("pRefValue") << pRefValue_ << token::END_STATEMENT << nl;
+    os.writeKeyword("pRefPoint") << pRefPoint_ << token::END_STATEMENT << nl;
+    writeEntry("value", os);
+}
+
+
+// * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
+
+void Foam::phaseHydrostaticPressureFvPatchScalarField::operator=
+(
+    const fvPatchScalarField& ptf
+)
+{
+    fvPatchScalarField::operator=
+    (
+        valueFraction()*refValue()
+        + (1 - valueFraction())*ptf
+    );
+}
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+    makePatchTypeField
+    (
+        fvPatchScalarField,
+        phaseHydrostaticPressureFvPatchScalarField
+    );
+}
+
+// ************************************************************************* //
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/phaseHydrostaticPressure/phaseHydrostaticPressureFvPatchScalarField.H b/src/finiteVolume/fields/fvPatchFields/derived/phaseHydrostaticPressure/phaseHydrostaticPressureFvPatchScalarField.H
new file mode 100644
index 0000000000000000000000000000000000000000..4c14094f496ad1afaefe9c4d63273272eebf23ca
--- /dev/null
+++ b/src/finiteVolume/fields/fvPatchFields/derived/phaseHydrostaticPressure/phaseHydrostaticPressureFvPatchScalarField.H
@@ -0,0 +1,223 @@
+/*---------------------------------------------------------------------------*\
+  =========                 |
+  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+   \\    /   O peration     |
+    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+     \\/     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 3 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, see <http://www.gnu.org/licenses/>.
+
+Class
+    Foam::phaseHydrostaticPressureFvPatchScalarField
+
+Description
+    Phase hydrostatic pressure boundary condition calculated as
+
+    pRefValue + rho*g.(x - pRefPoint)
+
+    where rho is provided and assumed uniform
+
+    applied according to the phase-fraction field provided:
+        1 -> fix value to that provided
+        0 -> zero-gradient
+
+SourceFiles
+    phaseHydrostaticPressureFvPatchScalarField.C
+
+\*---------------------------------------------------------------------------*/
+
+#ifndef phaseHydrostaticPressureFvPatchScalarField_H
+#define phaseHydrostaticPressureFvPatchScalarField_H
+
+#include "mixedFvPatchFields.H"
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+namespace Foam
+{
+
+/*---------------------------------------------------------------------------*\
+              Class phaseHydrostaticPressureFvPatch Declaration
+\*---------------------------------------------------------------------------*/
+
+class phaseHydrostaticPressureFvPatchScalarField
+:
+    public mixedFvPatchScalarField
+{
+
+protected:
+
+    // Protected data
+
+        //- Name of phase-fraction field
+        word phaseName_;
+
+        //- Constant density in the far-field
+        scalar rho_;
+
+        //- Reference pressure
+        scalar pRefValue_;
+
+        //- Reference pressure location
+        vector pRefPoint_;
+
+
+public:
+
+    //- Runtime type information
+    TypeName("phaseHydrostaticPressure");
+
+
+    // Constructors
+
+        //- Construct from patch and internal field
+        phaseHydrostaticPressureFvPatchScalarField
+        (
+            const fvPatch&,
+            const DimensionedField<scalar, volMesh>&
+        );
+
+        //- Construct from patch, internal field and dictionary
+        phaseHydrostaticPressureFvPatchScalarField
+        (
+            const fvPatch&,
+            const DimensionedField<scalar, volMesh>&,
+            const dictionary&
+        );
+
+        //- Construct by mapping given
+        //  phaseHydrostaticPressureFvPatchScalarField onto a new patch
+        phaseHydrostaticPressureFvPatchScalarField
+        (
+            const phaseHydrostaticPressureFvPatchScalarField&,
+            const fvPatch&,
+            const DimensionedField<scalar, volMesh>&,
+            const fvPatchFieldMapper&
+        );
+
+        //- Construct as copy
+        phaseHydrostaticPressureFvPatchScalarField
+        (
+            const phaseHydrostaticPressureFvPatchScalarField&
+        );
+
+        //- Construct and return a clone
+        virtual tmp<fvPatchScalarField> clone() const
+        {
+            return tmp<fvPatchScalarField >
+            (
+                new phaseHydrostaticPressureFvPatchScalarField(*this)
+            );
+        }
+
+        //- Construct as copy setting internal field reference
+        phaseHydrostaticPressureFvPatchScalarField
+        (
+            const phaseHydrostaticPressureFvPatchScalarField&,
+            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 phaseHydrostaticPressureFvPatchScalarField(*this, iF)
+            );
+        }
+
+
+    // Member functions
+
+        // Access
+
+            //- Return the phaseName
+            const word& phaseName() const
+            {
+                return phaseName_;
+            }
+
+            //- Return reference to the phaseName to allow adjustment
+            word& phaseName()
+            {
+                return phaseName_;
+            }
+
+            //- Return the constant density in the far-field
+            scalar rho() const
+            {
+                return rho_;
+            }
+
+            //- Return reference to the constant density in the far-field
+            //  to allow adjustment
+            scalar& rho()
+            {
+                return rho_;
+            }
+
+            //- Return the reference pressure
+            scalar pRefValue() const
+            {
+                return pRefValue_;
+            }
+
+            //- Return reference to the reference pressure to allow adjustment
+            scalar& pRefValue()
+            {
+                return pRefValue_;
+            }
+
+            //- Return the pressure reference location
+            const vector& pRefPoint() const
+            {
+                return pRefPoint_;
+            }
+
+            //- Return reference to the pressure reference location
+            //  to allow adjustment
+            vector& pRefPoint()
+            {
+                return pRefPoint_;
+            }
+
+
+        //- Update the coefficients associated with the patch field
+        virtual void updateCoeffs();
+
+        //- Write
+        virtual void write(Ostream&) const;
+
+
+    // Member operators
+
+        virtual void operator=(const fvPatchScalarField& pvf);
+};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+} // End namespace Foam
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+#endif
+
+// ************************************************************************* //
diff --git a/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.C b/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.C
index 63038d3dd3e492625de5457d40304e3cf0ef284c..9266ab274987dbd3b6da0a788c78a99209093151 100644
--- a/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.C
+++ b/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -190,6 +190,13 @@ Foam::fvPatchField<Type>::patchInternalField() const
 }
 
 
+template<class Type>
+void Foam::fvPatchField<Type>::patchInternalField(Field<Type>& pif) const
+{
+    patch_.patchInternalField(internalField_, pif);
+}
+
+
 template<class Type>
 void Foam::fvPatchField<Type>::autoMap
 (
diff --git a/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.H b/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.H
index 4d9d2e0f880814905538a4e69e17f2524bef24c1..369246d3b0eda9dde14ba36848887e313a7f15e5 100644
--- a/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.H
+++ b/src/finiteVolume/fields/fvPatchFields/fvPatchField/fvPatchField.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -352,6 +352,9 @@ public:
             //- Return internal field next to patch as patch field
             virtual tmp<Field<Type> > patchInternalField() const;
 
+            //- Return internal field next to patch as patch field
+            virtual void patchInternalField(Field<Type>&) const;
+
             //- Return patchField on the opposite patch of a coupled patch
             virtual tmp<Field<Type> > patchNeighbourField() const
             {
diff --git a/src/finiteVolume/fvMesh/fvPatches/constraint/cyclicAMI/cyclicAMIFvPatch.C b/src/finiteVolume/fvMesh/fvPatches/constraint/cyclicAMI/cyclicAMIFvPatch.C
index 9717c96e6c10094984da271398f4535c7ce67226..7b11172119e501bbb6ffe58aa1fc0fc22ad5afc3 100644
--- a/src/finiteVolume/fvMesh/fvPatches/constraint/cyclicAMI/cyclicAMIFvPatch.C
+++ b/src/finiteVolume/fvMesh/fvPatches/constraint/cyclicAMI/cyclicAMIFvPatch.C
@@ -75,8 +75,8 @@ Foam::tmp<Foam::vectorField> Foam::cyclicAMIFvPatch::delta() const
     {
         forAll(patchD, faceI)
         {
-            vector ddi = patchD[faceI];
-            vector dni = nbrPatchD[faceI];
+            const vector& ddi = patchD[faceI];
+            const vector& dni = nbrPatchD[faceI];
 
             pdv[faceI] = ddi - dni;
         }
@@ -85,8 +85,8 @@ Foam::tmp<Foam::vectorField> Foam::cyclicAMIFvPatch::delta() const
     {
         forAll(patchD, faceI)
         {
-            vector ddi = patchD[faceI];
-            vector dni = nbrPatchD[faceI];
+            const vector& ddi = patchD[faceI];
+            const vector& dni = nbrPatchD[faceI];
 
             pdv[faceI] = ddi - transform(forwardT()[0], dni);
         }
diff --git a/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatch.H b/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatch.H
index be7ee1bda475e0e2210c11ae142b13a65b45b785..28a07343e500c0be1a63c3c2808937b0a4387f11 100644
--- a/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatch.H
+++ b/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatch.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -239,6 +239,10 @@ public:
             template<class Type>
             tmp<Field<Type> > patchInternalField(const UList<Type>&) const;
 
+            //- Return given internal field next to patch as patch field
+            template<class Type>
+            void patchInternalField(const UList<Type>&, Field<Type>&) const;
+
             //- Return the corresponding patchField of the named field
             template<class GeometricField, class Type>
             const typename GeometricField::PatchFieldType& patchField
diff --git a/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatchTemplates.C b/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatchTemplates.C
index 5d47411fa0406bb16161df167ee5146c7e55670d..11aef36b05ffdec01c37739ce04570618b9e1b39 100644
--- a/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatchTemplates.C
+++ b/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatchTemplates.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -47,6 +47,24 @@ Foam::tmp<Foam::Field<Type> > Foam::fvPatch::patchInternalField
 }
 
 
+template<class Type>
+void Foam::fvPatch::patchInternalField
+(
+    const UList<Type>& f,
+    Field<Type>& pif
+) const
+{
+    pif.setSize(size());
+
+    const labelUList& faceCells = this->faceCells();
+
+    forAll(pif, facei)
+    {
+        pif[facei] = f[faceCells[facei]];
+    }
+}
+
+
 template<class GeometricField, class Type>
 const typename GeometricField::PatchFieldType& Foam::fvPatch::patchField
 (
diff --git a/src/finiteVolume/interpolation/interpolation/interpolationCellPoint/cellPointWeight/cellPointWeight.C b/src/finiteVolume/interpolation/interpolation/interpolationCellPoint/cellPointWeight/cellPointWeight.C
index 13828ff7cf785bb3af57c5279d93218b27d29a59..9d75e3233624107cd518d9dc46e8da0979787485 100644
--- a/src/finiteVolume/interpolation/interpolation/interpolationCellPoint/cellPointWeight/cellPointWeight.C
+++ b/src/finiteVolume/interpolation/interpolation/interpolationCellPoint/cellPointWeight/cellPointWeight.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -25,7 +25,6 @@ License
 
 #include "cellPointWeight.H"
 #include "polyMesh.H"
-#include "tetPointRef.H"
 #include "polyMeshTetDecomposition.H"
 
 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
diff --git a/src/lagrangian/basic/Cloud/Cloud.H b/src/lagrangian/basic/Cloud/Cloud.H
index 56b4759f1aa1829e6bcc219a9b76b99c8205afaf..dd7358d2c74a298be0f5766429cdf5c1f52cdd2a 100644
--- a/src/lagrangian/basic/Cloud/Cloud.H
+++ b/src/lagrangian/basic/Cloud/Cloud.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -41,9 +41,6 @@ SourceFiles
 #include "IOField.H"
 #include "CompactIOField.H"
 #include "polyMesh.H"
-#include "indexedOctree.H"
-#include "treeDataCell.H"
-#include "tetPointRef.H"
 #include "PackedBoolList.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/src/lagrangian/basic/particle/particle.H b/src/lagrangian/basic/particle/particle.H
index 08913b41459c8d21c57210fc1157d318d42ec834..8ab17472d01c50b9ba634cfcd278f9ca2a1f5f37 100644
--- a/src/lagrangian/basic/particle/particle.H
+++ b/src/lagrangian/basic/particle/particle.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -35,11 +35,10 @@ Description
 #include "vector.H"
 #include "Cloud.H"
 #include "IDLList.H"
-#include "labelList.H"
 #include "pointField.H"
 #include "faceList.H"
 #include "OFstream.H"
-#include "tetPointRef.H"
+#include "tetrahedron.H"
 #include "FixedList.H"
 #include "polyMeshTetDecomposition.H"
 
diff --git a/src/lagrangian/intermediate/parcels/Templates/ReactingParcel/ReactingParcelIO.C b/src/lagrangian/intermediate/parcels/Templates/ReactingParcel/ReactingParcelIO.C
index 6641e4301ca84ba45481c4903163235584c525fb..159b70c08252c90d5d179493953f65078bd38ab9 100644
--- a/src/lagrangian/intermediate/parcels/Templates/ReactingParcel/ReactingParcelIO.C
+++ b/src/lagrangian/intermediate/parcels/Templates/ReactingParcel/ReactingParcelIO.C
@@ -128,7 +128,7 @@ void Foam::ReactingParcel<ParcelType>::readFields
     wordList stateLabels(nPhases, "");
     if (compModel.nPhase() == 1)
     {
-        stateLabels = compModel.stateLabels();
+        stateLabels = compModel.stateLabels()[0];
     }
 
 
@@ -198,7 +198,7 @@ void Foam::ReactingParcel<ParcelType>::writeFields
         wordList stateLabels(phaseTypes.size(), "");
         if (compModel.nPhase() == 1)
         {
-            stateLabels = compModel.stateLabels();
+            stateLabels = compModel.stateLabels()[0];
         }
 
         forAll(phaseTypes, j)
diff --git a/src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchPostProcessing/PatchPostProcessing.C b/src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchPostProcessing/PatchPostProcessing.C
index 2b60f241b536d8195a92363a88e6e9c834bd941a..b2e878055cb4e85c710ae27de31f826d47ca819c 100644
--- a/src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchPostProcessing/PatchPostProcessing.C
+++ b/src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchPostProcessing/PatchPostProcessing.C
@@ -26,6 +26,7 @@ License
 #include "PatchPostProcessing.H"
 #include "Pstream.H"
 #include "stringListOps.H"
+#include "ListOps.H"
 #include "ListListOps.H"
 
 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
@@ -55,9 +56,12 @@ void Foam::PatchPostProcessing<CloudType>::write()
 {
     forAll(patchData_, i)
     {
+        List<List<scalar> > procTimes(Pstream::nProcs());
+        procTimes[Pstream::myProcNo()] = times_[i];
+        Pstream::gatherList(procTimes);
+
         List<List<string> > procData(Pstream::nProcs());
         procData[Pstream::myProcNo()] = patchData_[i];
-
         Pstream::gatherList(procData);
 
         if (Pstream::master())
@@ -100,18 +104,33 @@ void Foam::PatchPostProcessing<CloudType>::write()
                 procData,
                 accessOp<List<string> >()
             );
-            sort(globalData);
+
+            List<scalar> globalTimes;
+            globalTimes = ListListOps::combine<List<scalar> >
+            (
+                procTimes,
+                accessOp<List<scalar> >()
+            );
+
+            labelList indices;
+            sortedOrder(globalTimes, indices);
 
             string header("# Time currentProc " + parcelType::propHeader);
             patchOutFile<< header.c_str() << nl;
 
-            forAll(globalData, dataI)
+            forAll(globalTimes, i)
             {
-                patchOutFile<< globalData[dataI].c_str() << nl;
+                label dataI = indices[i];
+
+                patchOutFile
+                    << globalTimes[dataI] << ' '
+                    << globalData[dataI].c_str()
+                    << nl;
             }
         }
 
         patchData_[i].clearStorage();
+        times_[i].clearStorage();
     }
 }
 
@@ -128,6 +147,7 @@ Foam::PatchPostProcessing<CloudType>::PatchPostProcessing
     CloudFunctionObject<CloudType>(dict, owner, typeName),
     maxStoredParcels_(readScalar(this->coeffDict().lookup("maxStoredParcels"))),
     patchIDs_(),
+    times_(),
     patchData_()
 {
     const wordList allPatchNames = owner.mesh().boundaryMesh().names();
@@ -167,6 +187,7 @@ Foam::PatchPostProcessing<CloudType>::PatchPostProcessing
     }
 
     patchData_.setSize(patchIDs_.size());
+    times_.setSize(patchIDs_.size());
 }
 
 
@@ -179,6 +200,7 @@ Foam::PatchPostProcessing<CloudType>::PatchPostProcessing
     CloudFunctionObject<CloudType>(ppm),
     maxStoredParcels_(ppm.maxStoredParcels_),
     patchIDs_(ppm.patchIDs_),
+    times_(ppm.times_),
     patchData_(ppm.patchData_)
 {}
 
@@ -203,9 +225,11 @@ void Foam::PatchPostProcessing<CloudType>::postPatch
     const label localPatchI = applyToPatch(patchI);
     if (localPatchI != -1 && patchData_[localPatchI].size() < maxStoredParcels_)
     {
+        times_[localPatchI].append(this->owner().time().value());
+
         OStringStream data;
-        data<< this->owner().time().timeName() << ' ' << Pstream::myProcNo()
-            << ' ' << p;
+        data<< Pstream::myProcNo() << ' ' << p;
+
         patchData_[localPatchI].append(data.str());
     }
 }
diff --git a/src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchPostProcessing/PatchPostProcessing.H b/src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchPostProcessing/PatchPostProcessing.H
index 83aaa1663bf1519eb9fb8934108b45bbe8cc5d2f..9945d24b587f23840c4483e45696d761435a45c6 100644
--- a/src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchPostProcessing/PatchPostProcessing.H
+++ b/src/lagrangian/intermediate/submodels/CloudFunctionObjects/PatchPostProcessing/PatchPostProcessing.H
@@ -61,6 +61,9 @@ class PatchPostProcessing
         //- List of patch indices to post-process
         labelList patchIDs_;
 
+        //- List of time for each data record
+        List<DynamicList<scalar> > times_;
+
         //- List of output data per patch
         List<DynamicList<string> > patchData_;
 
diff --git a/src/lagrangian/molecularDynamics/molecule/reducedUnits/reducedUnits.H b/src/lagrangian/molecularDynamics/molecule/reducedUnits/reducedUnits.H
index 632e5d37adc12f0dd9ea10d0bf8e1fca3e520129..8319bf50bc46ba14df732c80283ae47b14bbe34b 100644
--- a/src/lagrangian/molecularDynamics/molecule/reducedUnits/reducedUnits.H
+++ b/src/lagrangian/molecularDynamics/molecule/reducedUnits/reducedUnits.H
@@ -76,7 +76,7 @@ class reducedUnits
 
                 scalar refPressure_;
 
-               scalar refMassDensity_;
+                scalar refMassDensity_;
 
                 scalar refNumberDensity_;
 
@@ -103,9 +103,9 @@ public:
     // Constructors
 
         //- Construct with no argument, uses default values:
-        // length  = 1nm
-        // mass = 1.660538782e−27kg (unified atomic mass unit)
-        // temperature = 1K (therefore, energy = 1*kb)
+        //  length  = 1nm
+        //  mass = 1.660538782e-27kg (unified atomic mass unit)
+        //  temperature = 1K (therefore, energy = 1*kb)
         reducedUnits();
 
         //- Construct from components
diff --git a/src/lagrangian/molecularDynamics/old/reducedUnits/reducedUnits.H b/src/lagrangian/molecularDynamics/old/reducedUnits/reducedUnits.H
index 632e5d37adc12f0dd9ea10d0bf8e1fca3e520129..8319bf50bc46ba14df732c80283ae47b14bbe34b 100644
--- a/src/lagrangian/molecularDynamics/old/reducedUnits/reducedUnits.H
+++ b/src/lagrangian/molecularDynamics/old/reducedUnits/reducedUnits.H
@@ -76,7 +76,7 @@ class reducedUnits
 
                 scalar refPressure_;
 
-               scalar refMassDensity_;
+                scalar refMassDensity_;
 
                 scalar refNumberDensity_;
 
@@ -103,9 +103,9 @@ public:
     // Constructors
 
         //- Construct with no argument, uses default values:
-        // length  = 1nm
-        // mass = 1.660538782e−27kg (unified atomic mass unit)
-        // temperature = 1K (therefore, energy = 1*kb)
+        //  length  = 1nm
+        //  mass = 1.660538782e-27kg (unified atomic mass unit)
+        //  temperature = 1K (therefore, energy = 1*kb)
         reducedUnits();
 
         //- Construct from components
diff --git a/src/lagrangian/spray/submodels/BreakupModel/PilchErdman/PilchErdman.C b/src/lagrangian/spray/submodels/BreakupModel/PilchErdman/PilchErdman.C
index bb4477a83bc1da98a4f0aff3f31751dc9d27d6a9..d900260410f2762bca73ed3d7c018ad1a844cdfa 100644
--- a/src/lagrangian/spray/submodels/BreakupModel/PilchErdman/PilchErdman.C
+++ b/src/lagrangian/spray/submodels/BreakupModel/PilchErdman/PilchErdman.C
@@ -101,25 +101,28 @@ bool Foam::PilchErdman<CloudType>::update
         // We > 1335, wave crest stripping
         scalar taubBar = 5.5;
 
-        if (We > 175.0)
+        if (We < 1335)
         {
-            // sheet stripping
-            taubBar = 0.766*pow(2.0*We - 12.0, 0.25);
-        }
-        else if (We > 22.0)
-        {
-            // Bag-and-stamen breakup
-            taubBar = 14.1*pow(2.0*We - 12.0, -0.25);
-        }
-        else if (We > 9.0)
-        {
-            // Bag breakup
-            taubBar = 2.45*pow(2.0*We - 12.0, 0.25);
-        }
-        else if (We > 6.0)
-        {
-            // Vibrational breakup
-            taubBar = 6.0*pow(2.0*We - 12.0, -0.25);
+            if (We > 175.0)
+            {
+                // sheet stripping
+                taubBar = 0.766*pow(2.0*We - 12.0, 0.25);
+            }
+            else if (We > 22.0)
+            {
+                // Bag-and-stamen breakup
+                taubBar = 14.1*pow(2.0*We - 12.0, -0.25);
+            }
+            else if (We > 9.0)
+            {
+                // Bag breakup
+                taubBar = 2.45*pow(2.0*We - 12.0, 0.25);
+            }
+            else if (We > 6.0)
+            {
+                // Vibrational breakup
+                taubBar = 6.0*pow(2.0*We - 12.0, -0.25);
+            }
         }
 
         scalar rho12 = sqrt(rhoc/rho);
diff --git a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriver.C b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriver.C
index 67d4fec174ed7203a3ba8735cb68a387d71289e8..f70381471bda91d4c1a73244c5a1b2b68f2f2c64 100644
--- a/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriver.C
+++ b/src/mesh/autoMesh/autoHexMesh/autoHexMeshDriver/autoLayerDriver.C
@@ -1144,6 +1144,7 @@ void Foam::autoLayerDriver::syncPatchDisplacement
         );
 
         // Reset if differs
+        // 1. take max
         forAll(syncPatchNLayers, i)
         {
             if (syncPatchNLayers[i] != patchNLayers[i])
@@ -1174,6 +1175,7 @@ void Foam::autoLayerDriver::syncPatchDisplacement
         );
 
         // Reset if differs
+        // 2. take min
         forAll(syncPatchNLayers, i)
         {
             if (syncPatchNLayers[i] != patchNLayers[i])
@@ -2726,7 +2728,7 @@ void Foam::autoLayerDriver::addLayers
             Info<< "Writing shrunk mesh to " << meshRefiner_.timeName() << endl;
 
             // See comment in autoSnapDriver why we should not remove meshPhi
-            // using mesh.clearPout().
+            // using mesh.clearOut().
 
             meshRefiner_.write
             (
diff --git a/src/meshTools/AMIInterpolation/patches/cyclic/cyclicAMIPolyPatch/cyclicAMIPolyPatch.C b/src/meshTools/AMIInterpolation/patches/cyclic/cyclicAMIPolyPatch/cyclicAMIPolyPatch.C
index 821ef00dec23323a4992dd3c532edb4d75f3fc85..67414fa432e2cef1f123af532de3f7174cf668e9 100644
--- a/src/meshTools/AMIInterpolation/patches/cyclic/cyclicAMIPolyPatch/cyclicAMIPolyPatch.C
+++ b/src/meshTools/AMIInterpolation/patches/cyclic/cyclicAMIPolyPatch/cyclicAMIPolyPatch.C
@@ -366,7 +366,7 @@ Foam::cyclicAMIPolyPatch::cyclicAMIPolyPatch
     AMIPtr_(NULL),
     AMIReverse_(false),
     surfPtr_(NULL),
-    surfDict_(dictionary::null)
+    surfDict_(fileName("surface"))
 {
     // Neighbour patch might not be valid yet so no transformation
     // calculation possible
@@ -474,7 +474,7 @@ Foam::cyclicAMIPolyPatch::cyclicAMIPolyPatch
     AMIPtr_(NULL),
     AMIReverse_(pp.AMIReverse_),
     surfPtr_(NULL),
-    surfDict_(dictionary::null)
+    surfDict_(pp.surfDict_)
 {
     // Neighbour patch might not be valid yet so no transformation
     // calculation possible
@@ -501,7 +501,7 @@ Foam::cyclicAMIPolyPatch::cyclicAMIPolyPatch
     AMIPtr_(NULL),
     AMIReverse_(pp.AMIReverse_),
     surfPtr_(NULL),
-    surfDict_(dictionary::null)
+    surfDict_(pp.surfDict_)
 {
     if (nbrPatchName_ == name())
     {
@@ -825,7 +825,7 @@ void Foam::cyclicAMIPolyPatch::write(Ostream& os) const
             << token::END_STATEMENT << nl;
     }
 
-    if (surfDict_ != dictionary::null)
+    if (!surfDict_.empty())
     {
         os.writeKeyword(surfDict_.dictName());
         os  << surfDict_;
diff --git a/src/meshTools/indexedOctree/treeDataEdge.C b/src/meshTools/indexedOctree/treeDataEdge.C
index d3945822365653f909edc5cd04fba28719507715..62ba5f2917c95eff27e0810d802cc04651c068ca 100644
--- a/src/meshTools/indexedOctree/treeDataEdge.C
+++ b/src/meshTools/indexedOctree/treeDataEdge.C
@@ -128,14 +128,37 @@ bool Foam::treeDataEdge::overlaps
     const treeBoundBox& cubeBb
 ) const
 {
-    if (cacheBb_)
-    {
-        return cubeBb.overlaps(bbs_[index]);
-    }
-    else
+    const edge& e = edges_[edgeLabels_[index]];
+
+    const point& start = points_[e.start()];
+    const point& end = points_[e.end()];
+
+    point intersect;
+
+    return cubeBb.intersects(start, end, intersect);
+}
+
+
+// Check if any point on shape is inside sphere.
+bool Foam::treeDataEdge::overlaps
+(
+    const label index,
+    const point& centre,
+    const scalar radiusSqr
+) const
+{
+    const edge& e = edges_[edgeLabels_[index]];
+
+    const pointHit nearHit = e.line(points_).nearestDist(centre);
+
+    const scalar distSqr = sqr(nearHit.distance());
+
+    if (distSqr <= radiusSqr)
     {
-        return cubeBb.overlaps(calcBb(edgeLabels_[index]));
+        return true;
     }
+
+    return false;
 }
 
 
diff --git a/src/meshTools/indexedOctree/treeDataEdge.H b/src/meshTools/indexedOctree/treeDataEdge.H
index c6af44e9edb8bd5f0bc48953c0dddd296e5f67de..9a8deadb73c2883e9869bb80442ad2dd289e8b9a 100644
--- a/src/meshTools/indexedOctree/treeDataEdge.H
+++ b/src/meshTools/indexedOctree/treeDataEdge.H
@@ -148,6 +148,14 @@ public:
                 const treeBoundBox& sampleBb
             ) const;
 
+            //- Does (bb of) shape at index overlap bb
+            bool overlaps
+            (
+                const label index,
+                const point& centre,
+                const scalar radiusSqr
+            ) const;
+
             //- Calculates nearest (to sample) point in shape.
             //  Returns actual point and distance (squared)
             void findNearest
diff --git a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C
index ec3d7c7471c843c9fbc96ec18d95a35e01859817..9ccaf089c0217470f3982ff48850a3a3cc79c5a3 100644
--- a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C
+++ b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBase.C
@@ -798,7 +798,7 @@ Foam::mappedPatchBase::mappedPatchBase
     AMIPtr_(NULL),
     AMIReverse_(false),
     surfPtr_(NULL),
-    surfDict_(dictionary::null)
+    surfDict_(fileName("surface"))
 {}
 
 
@@ -824,7 +824,7 @@ Foam::mappedPatchBase::mappedPatchBase
     AMIPtr_(NULL),
     AMIReverse_(false),
     surfPtr_(NULL),
-    surfDict_(dictionary::null)
+    surfDict_(fileName("surface"))
 {}
 
 
@@ -850,7 +850,7 @@ Foam::mappedPatchBase::mappedPatchBase
     AMIPtr_(NULL),
     AMIReverse_(false),
     surfPtr_(NULL),
-    surfDict_(dictionary::null)
+    surfDict_(fileName("surface"))
 {}
 
 
@@ -876,7 +876,7 @@ Foam::mappedPatchBase::mappedPatchBase
     AMIPtr_(NULL),
     AMIReverse_(false),
     surfPtr_(NULL),
-    surfDict_(dictionary::null)
+    surfDict_(fileName("surface"))
 {}
 
 
@@ -1216,8 +1216,11 @@ void Foam::mappedPatchBase::write(Ostream& os) const
                 << token::END_STATEMENT << nl;
         }
 
-        os.writeKeyword(surfDict_.dictName());
-        os  << surfDict_;
+        if (!surfDict_.empty())
+        {
+            os.writeKeyword(surfDict_.dictName());
+            os  << surfDict_;
+        }
     }
 }
 
diff --git a/src/meshTools/momentOfInertia/momentOfInertia.H b/src/meshTools/momentOfInertia/momentOfInertia.H
index a4d03ad8084e6b754ff86040b750e78bd19c3142..f21f1f298311da10a97d81ae2fbb5365200ee33a 100644
--- a/src/meshTools/momentOfInertia/momentOfInertia.H
+++ b/src/meshTools/momentOfInertia/momentOfInertia.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -37,7 +37,6 @@ SourceFiles
 #ifndef momentOfInertia_H
 #define momentOfInertia_H
 
-#include "tetPointRef.H"
 #include "triFaceList.H"
 #include "triSurface.H"
 #include "polyMesh.H"
diff --git a/src/meshTools/regionSplit/regionSplit.C b/src/meshTools/regionSplit/regionSplit.C
index 21fc55f0e61a08522d793884d42e58bb031d5510..77e1ca434630f17363de2ae8e4c764b40a71bc5a 100644
--- a/src/meshTools/regionSplit/regionSplit.C
+++ b/src/meshTools/regionSplit/regionSplit.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -128,7 +128,7 @@ void Foam::regionSplit::fillSeedMask
     changedFaces.setSize(nFaces);
 
 
-    // Loop over changed faces. MeshWave in small.
+    // Loop over changed faces. FaceCellWave in small.
 
     while (changedFaces.size())
     {
@@ -260,7 +260,7 @@ void Foam::regionSplit::fillSeedMask
 }
 
 
-Foam::label Foam::regionSplit::calcRegionSplit
+Foam::label Foam::regionSplit::calcLocalRegionSplit
 (
     const boolList& blockedFace,
     const List<labelPair>& explicitConnections,
@@ -282,7 +282,7 @@ Foam::label Foam::regionSplit::calcRegionSplit
                 {
                     FatalErrorIn
                     (
-                        "regionSplit::calcRegionSplit(..)"
+                        "regionSplit::calcLocalRegionSplit(..)"
                     )   << "Face " << faceI << " not synchronised. My value:"
                         << blockedFace[faceI] << "  coupled value:"
                         << syncBlockedFace[faceI]
@@ -313,7 +313,7 @@ Foam::label Foam::regionSplit::calcRegionSplit
     // ~~~~~~~~~~~~~~~~~~~~
 
     // Start with region 0
-    label nRegions = 0;
+    label nLocalRegions = 0;
 
     label unsetCellI = 0;
 
@@ -340,11 +340,11 @@ Foam::label Foam::regionSplit::calcRegionSplit
             cellRegion,
             faceRegion,
             unsetCellI,
-            nRegions
+            nLocalRegions
         );
 
         // Current unsetCell has now been handled. Go to next region.
-        nRegions++;
+        nLocalRegions++;
         unsetCellI++;
     }
     while (true);
@@ -356,7 +356,7 @@ Foam::label Foam::regionSplit::calcRegionSplit
         {
             if (cellRegion[cellI] < 0)
             {
-                FatalErrorIn("regionSplit::calcRegionSplit(..)")
+                FatalErrorIn("regionSplit::calcLocalRegionSplit(..)")
                     << "cell:" << cellI << " region:" << cellRegion[cellI]
                     << abort(FatalError);
             }
@@ -366,34 +366,62 @@ Foam::label Foam::regionSplit::calcRegionSplit
         {
             if (faceRegion[faceI] == -1)
             {
-                FatalErrorIn("regionSplit::calcRegionSplit(..)")
+                FatalErrorIn("regionSplit::calcLocalRegionSplit(..)")
                     << "face:" << faceI << " region:" << faceRegion[faceI]
                     << abort(FatalError);
             }
         }
     }
 
+    return nLocalRegions;
+}
+
 
+Foam::autoPtr<Foam::globalIndex> Foam::regionSplit::calcRegionSplit
+(
+    const boolList& blockedFace,
+    const List<labelPair>& explicitConnections,
 
-    // Assign global regions
-    // ~~~~~~~~~~~~~~~~~~~~~
+    labelList& cellRegion
+) const
+{
+    // See header in regionSplit.H
+
+    // 1. Do local analysis
+    label nLocalRegions = calcLocalRegionSplit
+    (
+        blockedFace,
+        explicitConnections,
+        cellRegion
+    );
+
+    if (!Pstream::parRun())
+    {
+        return autoPtr<globalIndex>(new globalIndex(nLocalRegions));
+    }
+
+
+    // 2. Assign global regions
+    // ~~~~~~~~~~~~~~~~~~~~~~~~
     // Offset local regions to create unique global regions.
 
-    globalIndex globalRegions(nRegions);
+    globalIndex globalRegions(nLocalRegions);
 
 
-    // Merge global regions
-    // ~~~~~~~~~~~~~~~~~~~~
+    // Convert regions to global ones
+    forAll(cellRegion, cellI)
+    {
+        cellRegion[cellI] = globalRegions.toGlobal(cellRegion[cellI]);
+    }
+
+
+    // 3. Merge global regions
+    // ~~~~~~~~~~~~~~~~~~~~~~~
     // Regions across non-blocked proc patches get merged.
     // This will set merged global regions to be the min of both.
     // (this will create gaps in the global region list so they will get
     // merged later on)
 
-    // Map from global to merged global
-    labelList mergedGlobal(identity(globalRegions.size()));
-
-
-    // See if any regions get merged. Only nessecary for parallel
     while (Pstream::parRun())
     {
         if (debug)
@@ -401,123 +429,81 @@ Foam::label Foam::regionSplit::calcRegionSplit
             Pout<< nl << "-- Starting Iteration --" << endl;
         }
 
+
         const polyBoundaryMesh& patches = mesh_.boundaryMesh();
 
-        // Send global regions across (or -2 if blocked face)
+        labelList nbrRegion(mesh_.nFaces()-mesh_.nInternalFaces(), -1);
         forAll(patches, patchI)
         {
             const polyPatch& pp = patches[patchI];
 
-            if (isA<processorPolyPatch>(pp))
+            if (pp.coupled())
             {
-                labelList myGlobalRegions(pp.size());
-
-                label faceI = pp.start();
+                const labelList& patchCells = pp.faceCells();
+                SubList<label> patchNbrRegion
+                (
+                    nbrRegion,
+                    pp.size(),
+                    pp.start()-mesh_.nInternalFaces()
+                );
 
-                forAll(pp, i)
+                forAll(patchCells, i)
                 {
-                    if (faceRegion[faceI] < 0)
+                    label faceI = pp.start()+i;
+                    if (!blockedFace.size() || !blockedFace[faceI])
                     {
-                        myGlobalRegions[i] = faceRegion[faceI];
+                        patchNbrRegion[i] = cellRegion[patchCells[i]];
                     }
-                    else
-                    {
-                        myGlobalRegions[i] = mergedGlobal
-                        [globalRegions.toGlobal(faceRegion[faceI])];
-                    }
-
-                    faceI++;
                 }
-
-                OPstream toProcNbr
-                (
-                    Pstream::blocking,
-                    refCast<const processorPolyPatch>(pp).neighbProcNo()
-                );
-
-                toProcNbr << myGlobalRegions;
             }
         }
+        syncTools::swapBoundaryFaceList(mesh_, nbrRegion);
 
-
-        // Receive global regions
-
-        label nMerged = 0;
+        Map<label> globalToMerged(mesh_.nFaces()-mesh_.nInternalFaces());
 
         forAll(patches, patchI)
         {
             const polyPatch& pp = patches[patchI];
 
-            if (isA<processorPolyPatch>(pp))
+            if (pp.coupled())
             {
-                const processorPolyPatch& procPp =
-                    refCast<const processorPolyPatch>(pp);
-
-                IPstream fromProcNbr(Pstream::blocking, procPp.neighbProcNo());
-
-                labelList nbrRegions(fromProcNbr);
-
-
-                // Compare with my regions to see which get merged.
-
-                label faceI = pp.start();
+                const labelList& patchCells = pp.faceCells();
+                SubList<label> patchNbrRegion
+                (
+                    nbrRegion,
+                    pp.size(),
+                    pp.start()-mesh_.nInternalFaces()
+                );
 
-                forAll(pp, i)
+                forAll(patchCells, i)
                 {
-                    if
-                    (
-                        faceRegion[faceI] < 0
-                     || nbrRegions[i] < 0
-                    )
-                    {
-                        if (faceRegion[faceI] != nbrRegions[i])
-                        {
-                            FatalErrorIn("regionSplit::calcRegionSplit(..)")
-                                << "On patch:" << pp.name()
-                                << " face:" << faceI
-                                << " my local region:" << faceRegion[faceI]
-                                << " neighbouring region:"
-                                << nbrRegions[i] << nl
-                                << "Maybe your blockedFaces are not"
-                                << " synchronized across coupled faces?"
-                                << abort(FatalError);
-                        }
-                    }
-                    else
-                    {
-                        label uncompactGlobal =
-                            globalRegions.toGlobal(faceRegion[faceI]);
+                    label faceI = pp.start()+i;
 
-                        label myGlobal = mergedGlobal[uncompactGlobal];
-
-                        if (myGlobal != nbrRegions[i])
+                    if (!blockedFace.size() || !blockedFace[faceI])
+                    {
+                        if (patchNbrRegion[i] < cellRegion[patchCells[i]])
                         {
-                            label minRegion = min(myGlobal, nbrRegions[i]);
-
-                            if (debug)
-                            {
-                                Pout<< "Merging region " << myGlobal
-                                    << " (on proc " << Pstream::myProcNo()
-                                    << ") and region " << nbrRegions[i]
-                                    << " (on proc " << procPp.neighbProcNo()
-                                    << ") into region " << minRegion << endl;
-                            }
-
-                            mergedGlobal[uncompactGlobal] = minRegion;
-                            mergedGlobal[myGlobal] = minRegion;
-                            mergedGlobal[nbrRegions[i]] = minRegion;
-
-                            nMerged++;
+                            //Pout<< "on patch:" << pp.name()
+                            //    << " cell:" << patchCells[i]
+                            //    << " at:"
+                            // << mesh_.cellCentres()[patchCells[i]]
+                            //    << " was:" << cellRegion[patchCells[i]]
+                            //    << " nbr:" << patchNbrRegion[i]
+                            //    << endl;
+
+                            globalToMerged.insert
+                            (
+                                cellRegion[patchCells[i]],
+                                patchNbrRegion[i]
+                            );
                         }
                     }
-
-                    faceI++;
                 }
             }
         }
 
 
-        reduce(nMerged, sumOp<label>());
+        label nMerged = returnReduce(globalToMerged.size(), sumOp<label>());
 
         if (debug)
         {
@@ -529,51 +515,176 @@ Foam::label Foam::regionSplit::calcRegionSplit
             break;
         }
 
-        // Merge the compacted regions.
-        Pstream::listCombineGather(mergedGlobal, minEqOp<label>());
-        Pstream::listCombineScatter(mergedGlobal);
+        // Renumber the regions according to the globalToMerged
+        forAll(cellRegion, cellI)
+        {
+            label regionI = cellRegion[cellI];
+            Map<label>::const_iterator iter = globalToMerged.find(regionI);
+            if (iter != globalToMerged.end())
+            {
+                 cellRegion[cellI] = iter();
+            }
+        }
+    }
+
+
+    // Now our cellRegion will have non-local elements in it. So compact
+    // it.
+
+    // 4a: count. Use a labelHashSet to count regions only once.
+    label nCompact = 0;
+    {
+        labelHashSet localRegion(mesh_.nFaces()-mesh_.nInternalFaces());
+        forAll(cellRegion, cellI)
+        {
+            if
+            (
+                globalRegions.isLocal(cellRegion[cellI])
+             && localRegion.insert(cellRegion[cellI])
+            )
+            {
+                nCompact++;
+            }
+        }
     }
 
+    if (debug)
+    {
+        Pout<< "Compacted from " << nLocalRegions
+            << " down to " << nCompact << " local regions." << endl;
+    }
 
-    // Compact global regions
-    // ~~~~~~~~~~~~~~~~~~~~~~
 
-    // All procs will have the same global mergedGlobal region.
-    // There might be gaps in it however so compact.
+    // Global numbering for compacted local regions
+    autoPtr<globalIndex> globalCompactPtr(new globalIndex(nCompact));
+    const globalIndex& globalCompact = globalCompactPtr();
 
-    labelList mergedToCompacted(globalRegions.size(), -1);
 
-    label compactI = 0;
+    // 4b: renumber
+    // Renumber into compact indices. Note that since we've already made
+    // all regions global we now need a Map to store the compacting information
+    // instead of a labelList - otherwise we could have used a straight
+    // labelList.
 
-    forAll(mergedGlobal, i)
+    // Local compaction map
+    Map<label> globalToCompact(2*nCompact);
+    // Remote regions we want the compact number for
+    List<labelHashSet> nonLocal(Pstream::nProcs());
+    forAll(nonLocal, procI)
     {
-        label merged = mergedGlobal[i];
+        nonLocal[procI].resize((nLocalRegions-nCompact)/Pstream::nProcs());
+    }
 
-        if (mergedToCompacted[merged] == -1)
+    forAll(cellRegion, cellI)
+    {
+        label region = cellRegion[cellI];
+        if (globalRegions.isLocal(region))
         {
-            mergedToCompacted[merged] = compactI++;
+            Map<label>::const_iterator iter = globalToCompact.find(region);
+            if (iter == globalToCompact.end())
+            {
+                label compactRegion = globalCompact.toGlobal
+                (
+                    globalToCompact.size()
+                );
+                globalToCompact.insert(region, compactRegion);
+            }
+        }
+        else
+        {
+            nonLocal[globalRegions.whichProcID(region)].insert(region);
+        }
+    }
+
+
+    // Now we have all the local regions compacted. Now we need to get the
+    // non-local ones from the processors to whom they are local.
+    // Convert the nonLocal (labelHashSets) to labelLists.
+
+    labelListList sendNonLocal(Pstream::nProcs());
+    labelList nNonLocal(Pstream::nProcs(), 0);
+    forAll(sendNonLocal, procI)
+    {
+        sendNonLocal[procI].setSize(nonLocal[procI].size());
+        forAllConstIter(labelHashSet, nonLocal[procI], iter)
+        {
+            sendNonLocal[procI][nNonLocal[procI]++] = iter.key();
         }
     }
 
     if (debug)
     {
-        Pout<< "Compacted down to " << compactI << " regions." << endl;
+        forAll(nNonLocal, procI)
+        {
+            Pout<< "    from processor " << procI
+                << " want " << nNonLocal[procI]
+                << " region numbers."
+                << endl;
+        }
+        Pout<< endl;
     }
 
-    // Renumber cellRegion to be global regions
-    forAll(cellRegion, cellI)
+
+    // Get the wanted region labels into recvNonLocal
+    labelListList recvNonLocal;
+    labelListList sizes;
+    Pstream::exchange<labelList, label>
+    (
+        sendNonLocal,
+        recvNonLocal,
+        sizes
+    );
+
+    // Now we have the wanted compact region labels that procI wants in
+    // recvNonLocal[procI]. Construct corresponding list of compact
+    // region labels to send back.
+
+    labelListList sendWantedLocal(Pstream::nProcs());
+    forAll(recvNonLocal, procI)
     {
-        label region = cellRegion[cellI];
+        const labelList& nonLocal = recvNonLocal[procI];
+        sendWantedLocal[procI].setSize(nonLocal.size());
 
-        if (region >= 0)
+        forAll(nonLocal, i)
         {
-            label merged = mergedGlobal[globalRegions.toGlobal(region)];
+            sendWantedLocal[procI][i] = globalToCompact[nonLocal[i]];
+        }
+    }
+
 
-            cellRegion[cellI] = mergedToCompacted[merged];
+    // Send back (into recvNonLocal)
+    recvNonLocal.clear();
+    sizes.clear();
+    Pstream::exchange<labelList, label>
+    (
+        sendWantedLocal,
+        recvNonLocal,
+        sizes
+    );
+    sendWantedLocal.clear();
+
+    // Now recvNonLocal contains for every element in setNonLocal the
+    // corresponding compact number. Insert these into the local compaction
+    // map.
+
+    forAll(recvNonLocal, procI)
+    {
+        const labelList& wantedRegions = sendNonLocal[procI];
+        const labelList& compactRegions = recvNonLocal[procI];
+
+        forAll(wantedRegions, i)
+        {
+            globalToCompact.insert(wantedRegions[i], compactRegions[i]);
         }
     }
 
-    return compactI;
+    // Finally renumber the regions
+    forAll(cellRegion, cellI)
+    {
+        cellRegion[cellI] = globalToCompact[cellRegion[cellI]];
+    }
+
+    return globalCompactPtr;
 }
 
 
@@ -582,9 +693,15 @@ Foam::label Foam::regionSplit::calcRegionSplit
 Foam::regionSplit::regionSplit(const polyMesh& mesh)
 :
     labelList(mesh.nCells(), -1),
-    mesh_(mesh),
-    nRegions_(calcRegionSplit(boolList(0, false), List<labelPair>(0), *this))
-{}
+    mesh_(mesh)
+{
+    globalNumberingPtr_ = calcRegionSplit
+    (
+        boolList(0, false), //blockedFaces
+        List<labelPair>(0), //explicitConnections,
+        *this
+    );
+}
 
 
 Foam::regionSplit::regionSplit
@@ -594,9 +711,15 @@ Foam::regionSplit::regionSplit
 )
 :
     labelList(mesh.nCells(), -1),
-    mesh_(mesh),
-    nRegions_(calcRegionSplit(blockedFace, List<labelPair>(0), *this))
-{}
+    mesh_(mesh)
+{
+    globalNumberingPtr_ = calcRegionSplit
+    (
+        blockedFace,        //blockedFaces
+        List<labelPair>(0), //explicitConnections,
+        *this
+    );
+}
 
 
 Foam::regionSplit::regionSplit
@@ -607,12 +730,20 @@ Foam::regionSplit::regionSplit
 )
 :
     labelList(mesh.nCells(), -1),
-    mesh_(mesh),
-    nRegions_(calcRegionSplit(blockedFace, explicitConnections, *this))
-{}
+    mesh_(mesh)
+{
+    globalNumberingPtr_ = calcRegionSplit
+    (
+        blockedFace,            //blockedFaces
+        explicitConnections,    //explicitConnections,
+        *this
+    );
+}
 
 
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
 
+
+
 // ************************************************************************* //
diff --git a/src/meshTools/regionSplit/regionSplit.H b/src/meshTools/regionSplit/regionSplit.H
index d1d32971817e02a38c2c4f643d53068d7aa6af09..83a055a8e08af1c53a9b2a844a4ce1c115f7abf8 100644
--- a/src/meshTools/regionSplit/regionSplit.H
+++ b/src/meshTools/regionSplit/regionSplit.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -26,7 +26,66 @@ Class
 
 Description
     This class separates the mesh into distinct unconnected regions,
-    each of which is then given a label.
+    each of which is then given a label according to globalNumbering().
+
+
+    Say 6 cells, 3 processors, with single baffle on proc1.
+
+              baffle
+                |
+    +---+---+---+---+---+---+
+    |   |   |   |   |   |   |
+    +---+---+---+---+---+---+
+      proc0 | proc1 | proc2
+
+
+
+    1: determine local regions (uncoupled)
+
+    +---+---+---+---+---+---+
+    | 0 | 0 | 0 | 1 | 0 | 0 |
+    +---+---+---+---+---+---+
+      proc0 | proc1 | proc2
+
+
+
+    2: make global
+
+    +---+---+---+---+---+---+
+    | 0 | 0 | 1 | 2 | 3 | 3 |
+    +---+---+---+---+---+---+
+      proc0 | proc1 | proc2
+
+
+
+    3: merge connected across procs
+
+    +---+---+---+---+---+---+
+    | 0 | 0 | 0 | 2 | 2 | 2 |
+    +---+---+---+---+---+---+
+      proc0 | proc1 | proc2
+
+
+
+    4. determine locally owner regions. determine compact numbering for the
+    local regions and send these to all processors that need them:
+
+    proc0 uses regions:
+        - 0 which is local to it.
+    proc1 uses regions
+        - 0 which originates from proc0
+        - 2 which is local to it
+    proc2 uses regions
+        - 2 which originates from proc1
+
+    So proc1 needs to get the compact number for region 0 from proc0 and proc2
+    needs to get the compact number for region 2 from proc1:
+
+    +---+---+---+---+---+---+
+    | 0 | 0 | 0 | 1 | 1 | 1 |
+    +---+---+---+---+---+---+
+      proc0 | proc1 | proc2
+
 
 SourceFiles
     regionSplit.C
@@ -36,14 +95,17 @@ SourceFiles
 #ifndef regionSplit_H
 #define regionSplit_H
 
-#include "polyMesh.H"
-#include "demandDrivenData.H"
+#include "globalIndex.H"
+#include "labelPair.H"
+#include "boolList.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 namespace Foam
 {
 
+class polyMesh;
+
 /*---------------------------------------------------------------------------*\
                            Class regionSplit Declaration
 \*---------------------------------------------------------------------------*/
@@ -57,8 +119,7 @@ class regionSplit
         //- Reference to mesh
         const polyMesh& mesh_;
 
-        //- Number of regions
-        label nRegions_;
+        mutable autoPtr<globalIndex> globalNumberingPtr_;
 
 
     // Private Member Functions
@@ -84,8 +145,16 @@ class regionSplit
             const label markValue
         ) const;
 
-        //- Calculate region split. Return number of regions.
-        label calcRegionSplit
+        //- Calculate local region split. Return number of regions.
+        label calcLocalRegionSplit
+        (
+            const boolList& blockedFace,
+            const List<labelPair>& explicitConnections,
+            labelList& cellRegion
+        ) const;
+
+        //- Calculate global region split. Return globalIndex.
+        autoPtr<globalIndex> calcRegionSplit
         (
             const boolList& blockedFace,
             const List<labelPair>& explicitConnections,
@@ -118,11 +187,18 @@ public:
 
     // Member Functions
 
-        //- Return number of regions
+        //- Return global region numbering
+        const globalIndex& globalNumbering() const
+        {
+            return globalNumberingPtr_();
+        }
+
+        //- Return total number of regions
         label nRegions() const
         {
-            return nRegions_;
+            return globalNumbering().size();
         }
+
 };
 
 
diff --git a/src/regionModels/regionModel/regionProperties/regionProperties.C b/src/regionModels/regionModel/regionProperties/regionProperties.C
index c2cd718cce80e24579b01c26e0c4f167bb603214..7a7d6a646e7ad7a93b002ce58c565dff6632fdaf 100644
--- a/src/regionModels/regionModel/regionProperties/regionProperties.C
+++ b/src/regionModels/regionModel/regionProperties/regionProperties.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -52,4 +52,5 @@ Foam::regionProperties::regionProperties(const Time& runTime)
 Foam::regionProperties::~regionProperties()
 {}
 
+
 // ************************************************************************* //
diff --git a/src/sampling/meshToMeshInterpolation/tetOverlapVolume/tetOverlapVolume.C b/src/sampling/meshToMeshInterpolation/tetOverlapVolume/tetOverlapVolume.C
index d36730a0eeac32ad5f6e7dd6e5433f2ea38272b4..16d311815ce6cced07b6339cd29a1c7940df0271 100644
--- a/src/sampling/meshToMeshInterpolation/tetOverlapVolume/tetOverlapVolume.C
+++ b/src/sampling/meshToMeshInterpolation/tetOverlapVolume/tetOverlapVolume.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -24,436 +24,27 @@ License
 \*---------------------------------------------------------------------------*/
 
 #include "tetOverlapVolume.H"
+#include "tetrahedron.H"
+#include "tetPoints.H"
+#include "polyMesh.H"
+#include "OFstream.H"
+#include "treeBoundBox.H"
+#include "indexedOctree.H"
+#include "treeDataCell.H"
 
 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
 
 defineTypeNameAndDebug(Foam::tetOverlapVolume, 0);
 
+
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
 Foam::tetOverlapVolume::tetOverlapVolume()
 {}
 
 
-// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
-
-Foam::tetOverlapVolume::~tetOverlapVolume()
-{}
-
-
 // * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * * * //
 
-Foam::point Foam::tetOverlapVolume::planeIntersection
-(
-    const FixedList<scalar, 4>& d,
-    const tetPoints& t,
-    const label negI,
-    const label posI
-)
-{
-    return (d[posI]*t[negI] - d[negI]*t[posI])/(-d[negI]+d[posI]);
-}
-
-
-template <class TetOp>
-inline void Foam::tetOverlapVolume::decomposePrism
-(
-    const FixedList<point, 6>& points,
-    TetOp& op
-)
-{
-    op(tetPoints(points[1], points[3], points[2], points[0]));
-    op(tetPoints(points[1], points[2], points[3], points[4]));
-    op(tetPoints(points[4], points[2], points[3], points[5]));
-}
-
-
-template <class AboveTetOp, class BelowTetOp>
-inline void Foam::tetOverlapVolume::tetSliceWithPlane
-(
-    const tetPoints& tet,
-    const plane& pl,
-
-    AboveTetOp& aboveOp,
-    BelowTetOp& belowOp
-)
-{
-    // Distance to plane
-    FixedList<scalar, 4> d;
-    label nPos = 0;
-    forAll(tet, i)
-    {
-        d[i] = ((tet[i]-pl.refPoint()) & pl.normal());
-        if (d[i] > 0)
-        {
-            nPos++;
-        }
-    }
-
-    if (nPos == 4)
-    {
-        aboveOp(tet);
-    }
-    else if (nPos == 3)
-    {
-        // Sliced into below tet and above prism. Prism gets split into
-        // two tets.
-
-        // Find the below tet
-        label i0 = -1;
-        forAll(d, i)
-        {
-            if (d[i] <= 0)
-            {
-                i0 = i;
-                break;
-            }
-        }
-
-        label i1 = d.fcIndex(i0);
-        label i2 = d.fcIndex(i1);
-        label i3 = d.fcIndex(i2);
-
-        point p01 = planeIntersection(d, tet, i0, i1);
-        point p02 = planeIntersection(d, tet, i0, i2);
-        point p03 = planeIntersection(d, tet, i0, i3);
-
-        // i0 = tetCell vertex 0: p01,p02,p03 outwards pointing triad
-        //          ,,         1 :     ,,     inwards pointing triad
-        //          ,,         2 :     ,,     outwards pointing triad
-        //          ,,         3 :     ,,     inwards pointing triad
-
-        //Pout<< "Split 3pos tet " << tet << " d:" << d << " into" << nl;
-
-        if (i0 == 0 || i0 == 2)
-        {
-            tetPoints t(tet[i0], p01, p02, p03);
-            //Pout<< "    belowtet:" << t << " around i0:" << i0 << endl;
-            //checkTet(t, "nPos 3, belowTet i0==0 or 2");
-            belowOp(t);
-
-            // Prism
-            FixedList<point, 6> p;
-            p[0] = tet[i1];
-            p[1] = tet[i3];
-            p[2] = tet[i2];
-            p[3] = p01;
-            p[4] = p03;
-            p[5] = p02;
-            //Pout<< "    aboveprism:" << p << endl;
-            decomposePrism(p, aboveOp);
-        }
-        else
-        {
-            tetPoints t(p01, p02, p03, tet[i0]);
-            //Pout<< "    belowtet:" << t << " around i0:" << i0 << endl;
-            //checkTet(t, "nPos 3, belowTet i0==1 or 3");
-            belowOp(t);
-
-            // Prism
-            FixedList<point, 6> p;
-            p[0] = tet[i3];
-            p[1] = tet[i1];
-            p[2] = tet[i2];
-            p[3] = p03;
-            p[4] = p01;
-            p[5] = p02;
-            //Pout<< "    aboveprism:" << p << endl;
-            decomposePrism(p, aboveOp);
-        }
-    }
-    else if (nPos == 2)
-    {
-        // Tet cut into two prisms. Determine the positive one.
-        label pos0 = -1;
-        label pos1 = -1;
-        label neg0 = -1;
-        label neg1 = -1;
-        forAll(d, i)
-        {
-            if (d[i] > 0)
-            {
-                if (pos0 == -1)
-                {
-                    pos0 = i;
-                }
-                else
-                {
-                    pos1 = i;
-                }
-            }
-            else
-            {
-                if (neg0 == -1)
-                {
-                    neg0 = i;
-                }
-                else
-                {
-                    neg1 = i;
-                }
-            }
-        }
-
-        //Pout<< "Split 2pos tet " << tet << " d:" << d
-        //    << " around pos0:" << pos0 << " pos1:" << pos1
-        //    << " neg0:" << neg0 << " neg1:" << neg1 << " into" << nl;
-
-        const edge posEdge(pos0, pos1);
-
-        if (posEdge == edge(0, 1))
-        {
-            point p02 = planeIntersection(d, tet, 0, 2);
-            point p03 = planeIntersection(d, tet, 0, 3);
-            point p12 = planeIntersection(d, tet, 1, 2);
-            point p13 = planeIntersection(d, tet, 1, 3);
-            // Split the resulting prism
-            {
-                FixedList<point, 6> p;
-                p[0] = tet[0];
-                p[1] = p02;
-                p[2] = p03;
-                p[3] = tet[1];
-                p[4] = p12;
-                p[5] = p13;
-                //Pout<< "    01 aboveprism:" << p << endl;
-                decomposePrism(p, aboveOp);
-            }
-            {
-                FixedList<point, 6> p;
-                p[0] = tet[2];
-                p[1] = p02;
-                p[2] = p12;
-                p[3] = tet[3];
-                p[4] = p03;
-                p[5] = p13;
-                //Pout<< "    01 belowprism:" << p << endl;
-                decomposePrism(p, belowOp);
-            }
-        }
-        else if (posEdge == edge(1, 2))
-        {
-            point p01 = planeIntersection(d, tet, 0, 1);
-            point p13 = planeIntersection(d, tet, 1, 3);
-            point p02 = planeIntersection(d, tet, 0, 2);
-            point p23 = planeIntersection(d, tet, 2, 3);
-            // Split the resulting prism
-            {
-                FixedList<point, 6> p;
-                p[0] = tet[1];
-                p[1] = p01;
-                p[2] = p13;
-                p[3] = tet[2];
-                p[4] = p02;
-                p[5] = p23;
-                //Pout<< "    12 aboveprism:" << p << endl;
-                decomposePrism(p, aboveOp);
-            }
-            {
-                FixedList<point, 6> p;
-                p[0] = tet[3];
-                p[1] = p23;
-                p[2] = p13;
-                p[3] = tet[0];
-                p[4] = p02;
-                p[5] = p01;
-                //Pout<< "    12 belowprism:" << p << endl;
-                decomposePrism(p, belowOp);
-            }
-        }
-        else if (posEdge == edge(2, 0))
-        {
-            point p01 = planeIntersection(d, tet, 0, 1);
-            point p03 = planeIntersection(d, tet, 0, 3);
-            point p12 = planeIntersection(d, tet, 1, 2);
-            point p23 = planeIntersection(d, tet, 2, 3);
-            // Split the resulting prism
-            {
-                FixedList<point, 6> p;
-                p[0] = tet[2];
-                p[1] = p12;
-                p[2] = p23;
-                p[3] = tet[0];
-                p[4] = p01;
-                p[5] = p03;
-                //Pout<< "    20 aboveprism:" << p << endl;
-                decomposePrism(p, aboveOp);
-            }
-            {
-                FixedList<point, 6> p;
-                p[0] = tet[1];
-                p[1] = p12;
-                p[2] = p01;
-                p[3] = tet[3];
-                p[4] = p23;
-                p[5] = p03;
-                //Pout<< "    20 belowprism:" << p << endl;
-                decomposePrism(p, belowOp);
-            }
-        }
-        else if (posEdge == edge(0, 3))
-        {
-            point p01 = planeIntersection(d, tet, 0, 1);
-            point p02 = planeIntersection(d, tet, 0, 2);
-            point p13 = planeIntersection(d, tet, 1, 3);
-            point p23 = planeIntersection(d, tet, 2, 3);
-            // Split the resulting prism
-            {
-                FixedList<point, 6> p;
-                p[0] = tet[3];
-                p[1] = p23;
-                p[2] = p13;
-                p[3] = tet[0];
-                p[4] = p02;
-                p[5] = p01;
-                //Pout<< "    03 aboveprism:" << p << endl;
-                decomposePrism(p, aboveOp);
-            }
-            {
-                FixedList<point, 6> p;
-                p[0] = tet[2];
-                p[1] = p23;
-                p[2] = p02;
-                p[3] = tet[1];
-                p[4] = p13;
-                p[5] = p01;
-                //Pout<< "    03 belowprism:" << p << endl;
-                decomposePrism(p, belowOp);
-            }
-        }
-        else if (posEdge == edge(1, 3))
-        {
-            point p01 = planeIntersection(d, tet, 0, 1);
-            point p12 = planeIntersection(d, tet, 1, 2);
-            point p03 = planeIntersection(d, tet, 0, 3);
-            point p23 = planeIntersection(d, tet, 2, 3);
-            // Split the resulting prism
-            {
-                FixedList<point, 6> p;
-                p[0] = tet[1];
-                p[1] = p12;
-                p[2] = p01;
-                p[3] = tet[3];
-                p[4] = p23;
-                p[5] = p03;
-                //Pout<< "    13 aboveprism:" << p << endl;
-                decomposePrism(p, aboveOp);
-            }
-            {
-                FixedList<point, 6> p;
-                p[0] = tet[2];
-                p[1] = p12;
-                p[2] = p23;
-                p[3] = tet[0];
-                p[4] = p01;
-                p[5] = p03;
-                //Pout<< "    13 belowprism:" << p << endl;
-                decomposePrism(p, belowOp);
-            }
-        }
-        else if (posEdge == edge(2, 3))
-        {
-            point p02 = planeIntersection(d, tet, 0, 2);
-            point p12 = planeIntersection(d, tet, 1, 2);
-            point p03 = planeIntersection(d, tet, 0, 3);
-            point p13 = planeIntersection(d, tet, 1, 3);
-            // Split the resulting prism
-            {
-                FixedList<point, 6> p;
-                p[0] = tet[2];
-                p[1] = p02;
-                p[2] = p12;
-                p[3] = tet[3];
-                p[4] = p03;
-                p[5] = p13;
-                //Pout<< "    23 aboveprism:" << p << endl;
-                decomposePrism(p, aboveOp);
-            }
-            {
-                FixedList<point, 6> p;
-                p[0] = tet[0];
-                p[1] = p02;
-                p[2] = p03;
-                p[3] = tet[1];
-                p[4] = p12;
-                p[5] = p13;
-                //Pout<< "    23 belowprism:" << p << endl;
-                decomposePrism(p, belowOp);
-            }
-        }
-        else
-        {
-            FatalErrorIn("tetSliceWithPlane(..)") << "Missed edge:" << posEdge
-                << abort(FatalError);
-        }
-    }
-    else if (nPos == 1)
-    {
-        // Find the positive tet
-        label i0 = -1;
-        forAll(d, i)
-        {
-            if (d[i] > 0)
-            {
-                i0 = i;
-                break;
-            }
-        }
-
-        label i1 = d.fcIndex(i0);
-        label i2 = d.fcIndex(i1);
-        label i3 = d.fcIndex(i2);
-
-        point p01 = planeIntersection(d, tet, i0, i1);
-        point p02 = planeIntersection(d, tet, i0, i2);
-        point p03 = planeIntersection(d, tet, i0, i3);
-
-        //Pout<< "Split 1pos tet " << tet << " d:" << d << " into" << nl;
-
-        if (i0 == 0 || i0 == 2)
-        {
-            tetPoints t(tet[i0], p01, p02, p03);
-            //Pout<< "    abovetet:" << t << " around i0:" << i0 << endl;
-            //checkTet(t, "nPos 1, aboveTets i0==0 or 2");
-            aboveOp(t);
-
-            // Prism
-            FixedList<point, 6> p;
-            p[0] = tet[i1];
-            p[1] = tet[i3];
-            p[2] = tet[i2];
-            p[3] = p01;
-            p[4] = p03;
-            p[5] = p02;
-            //Pout<< "    belowprism:" << p << endl;
-            decomposePrism(p, belowOp);
-        }
-        else
-        {
-            tetPoints t(p01, p02, p03, tet[i0]);
-            //Pout<< "    abovetet:" << t << " around i0:" << i0 << endl;
-            //checkTet(t, "nPos 1, aboveTets i0==1 or 3");
-            aboveOp(t);
-
-            // Prism
-            FixedList<point, 6> p;
-            p[0] = tet[i3];
-            p[1] = tet[i1];
-            p[2] = tet[i2];
-            p[3] = p03;
-            p[4] = p01;
-            p[5] = p02;
-            //Pout<< "    belowprism:" << p << endl;
-            decomposePrism(p, belowOp);
-        }
-    }
-    else    // nPos == 0
-    {
-        belowOp(tet);
-    }
-}
-
-
 void Foam::tetOverlapVolume::tetTetOverlap
 (
     const tetPoints& tetA,
@@ -462,16 +53,15 @@ void Foam::tetOverlapVolume::tetTetOverlap
     label& nInside,
     FixedList<tetPoints, 200>& outsideTets,
     label& nOutside
-)
+) const
 {
     // Work storage
     FixedList<tetPoints, 200> cutInsideTets;
     label nCutInside = 0;
 
-    storeTetOp inside(insideTets, nInside);
-    storeTetOp cutInside(cutInsideTets, nCutInside);
-    dummyTetOp outside;
-
+    tetPointRef::storeOp inside(insideTets, nInside);
+    tetPointRef::storeOp cutInside(cutInsideTets, nCutInside);
+    tetPointRef::dummyOp outside;
 
 
     // Cut tetA with all inwards pointing faces of tetB. Any tets remaining
@@ -484,7 +74,7 @@ void Foam::tetOverlapVolume::tetTetOverlap
         // Cut and insert subtets into cutInsideTets (either by getting
         // an index from freeSlots or by appending to insideTets) or
         // insert into outsideTets
-        tetSliceWithPlane(tetA, pl0, cutInside, outside);
+        tetA.tet().sliceWithPlane(pl0, cutInside, outside);
     }
 
     if (nCutInside == 0)
@@ -501,7 +91,7 @@ void Foam::tetOverlapVolume::tetTetOverlap
 
         for (label i = 0; i < nCutInside; i++)
         {
-            tetSliceWithPlane(cutInsideTets[i], pl1, inside, outside);
+            cutInsideTets[i].tet().sliceWithPlane(pl1, inside, outside);
         }
 
         if (nInside == 0)
@@ -518,7 +108,7 @@ void Foam::tetOverlapVolume::tetTetOverlap
 
         for (label i = 0; i < nInside; i++)
         {
-            tetSliceWithPlane(insideTets[i], pl2, cutInside, outside);
+            insideTets[i].tet().sliceWithPlane(pl2, cutInside, outside);
         }
 
         if (nCutInside == 0)
@@ -536,28 +126,27 @@ void Foam::tetOverlapVolume::tetTetOverlap
 
         for (label i = 0; i < nCutInside; i++)
         {
-            tetSliceWithPlane(cutInsideTets[i], pl3, inside, outside);
+            cutInsideTets[i].tet().sliceWithPlane(pl3, inside, outside);
         }
     }
 }
 
 
-inline Foam::scalar
-Foam::tetOverlapVolume::tetTetOverlapVol
+Foam::scalar Foam::tetOverlapVolume::tetTetOverlapVol
 (
     const tetPoints& tetA,
     const tetPoints& tetB
-)
+) const
 {
     FixedList<tetPoints, 200> insideTets;
     label nInside = 0;
     FixedList<tetPoints, 200> cutInsideTets;
     label nCutInside = 0;
 
-    storeTetOp inside(insideTets, nInside);
-    storeTetOp cutInside(cutInsideTets, nCutInside);
-    sumTetVolOp volInside;
-    dummyTetOp outside;
+    tetPointRef::storeOp inside(insideTets, nInside);
+    tetPointRef::storeOp cutInside(cutInsideTets, nCutInside);
+    tetPointRef::sumVolOp volInside;
+    tetPointRef::dummyOp outside;
 
     // face0
     plane pl0(tetB[1], tetB[3], tetB[2]);
@@ -605,12 +194,12 @@ Foam::tetOverlapVolume::tetTetOverlapVol
 }
 
 
-inline const Foam::treeBoundBox Foam::tetOverlapVolume::pyrBb
+Foam::treeBoundBox Foam::tetOverlapVolume::pyrBb
 (
     const pointField& points,
     const face& f,
     const point& fc
-)
+) const
 {
     treeBoundBox bb(fc, fc);
     forAll(f, fp)
@@ -750,8 +339,8 @@ Foam::scalar Foam::tetOverlapVolume::cellCellOverlapVolumeMinDecomp
 
 Foam::labelList Foam::tetOverlapVolume::overlappingCells
 (
-    const fvMesh& fromMesh,
-    const fvMesh& toMesh,
+    const polyMesh& fromMesh,
+    const polyMesh& toMesh,
     const label iTo
 ) const
 {
@@ -766,30 +355,4 @@ Foam::labelList Foam::tetOverlapVolume::overlappingCells
 }
 
 
-/*
-
-        forAll(cellsA, i)
-        {
-            label cellAI = cellsA[i];
-            treeBoundBox bbA
-            (
-                pointField(meshA.points(), meshA.cellPoints()[cellAI])
-            );
-
-            scalar v = cellCellOverlapVolumeMinDecomp
-            (
-                meshA,
-                cellAI,
-                bbA,
-                meshB,
-                cellBI,
-                bbB
-            );
-
-            overlapVol += v;
-            nOverlapTests++;
-        }
-
-*/
-
 // ************************************************************************* //
diff --git a/src/sampling/meshToMeshInterpolation/tetOverlapVolume/tetOverlapVolume.H b/src/sampling/meshToMeshInterpolation/tetOverlapVolume/tetOverlapVolume.H
index d0891c14d14170ae54cabff0ac4ce364a2d16478..388f645f3fa5eff60455562d21d498690f6782cc 100644
--- a/src/sampling/meshToMeshInterpolation/tetOverlapVolume/tetOverlapVolume.H
+++ b/src/sampling/meshToMeshInterpolation/tetOverlapVolume/tetOverlapVolume.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -36,21 +36,17 @@ SourceFiles
 #ifndef tetOverlapVolume_H
 #define tetOverlapVolume_H
 
-#include "tetrahedron.H"
-#include "fvMesh.H"
-#include "plane.H"
-#include "tetPointRef.H"
-#include "OFstream.H"
-#include "meshTools.H"
-#include "indexedOctree.H"
-#include "treeDataCell.H"
-#include "tetPoints.H"
-#include "tetCell.H"
-#include "EdgeMap.H"
+#include "FixedList.H"
+#include "labelList.H"
+#include "treeBoundBox.H"
 
 namespace Foam
 {
 
+class primitiveMesh;
+class polyMesh;
+class tetPoints;
+
 /*---------------------------------------------------------------------------*\
                          Class tetOverlapVolume Declaration
 \*---------------------------------------------------------------------------*/
@@ -59,82 +55,6 @@ class tetOverlapVolume
 {
     // Private member functions
 
-        //- Plane intersection
-        inline point planeIntersection
-        (
-            const FixedList<scalar, 4>& d,
-            const tetPoints& t,
-            const label negI,
-            const label posI
-        );
-
-
-        //- Decompose prism
-        template <class TetOp> inline void decomposePrism
-        (
-            const FixedList<point, 6>& points,
-            TetOp& op
-        );
-
-
-        //- Helping cľasses
-        class dummyTetOp
-        {
-         public:
-
-            inline void operator()(const tetPoints&){}
-        };
-
-
-        class sumTetVolOp
-        {
-         public:
-            scalar vol_;
-
-            inline sumTetVolOp()
-            :
-                vol_(0.0)
-            {}
-
-            inline void operator()(const tetPoints& tet)
-            {
-                vol_ += tet.tet().mag();
-            }
-        };
-
-
-        class storeTetOp
-        {
-            FixedList<tetPoints, 200>& tets_;
-            label& nTets_;
-
-         public:
-
-            inline storeTetOp(FixedList<tetPoints, 200>& tets, label& nTets)
-            :
-                tets_(tets),
-                nTets_(nTets)
-            {}
-
-            inline void operator()(const tetPoints& tet)
-            {
-                tets_[nTets_++] = tet;
-            }
-        };
-
-
-        //- Slice. Split tet into subtets above and below plane
-        template <class AboveTetOp, class BelowTetOp>
-        inline void tetSliceWithPlane
-        (
-            const tetPoints& tet,
-            const plane& pl,
-
-            AboveTetOp& aboveOp,
-            BelowTetOp& belowOp
-        );
-
-
         //- Tet overlap
         void tetTetOverlap
         (
@@ -144,31 +64,28 @@ class tetOverlapVolume
             label& nInside,
             FixedList<tetPoints, 200>& outsideTets,
             label& nOutside
-        );
-
+        ) const;
 
         //- Tet Overlap Vol
-        inline scalar tetTetOverlapVol
+        scalar tetTetOverlapVol
         (
             const tetPoints& tetA,
             const tetPoints& tetB
-        );
-
+        ) const;
 
         //- Return a const treeBoundBox
-        inline const treeBoundBox pyrBb
+        treeBoundBox pyrBb
         (
             const pointField& points,
             const face& f,
             const point& fc
-        );
+        ) const;
 
 
 public:
 
-
     //- Runtime type information
-    TypeName("tetOverlapVolume");
+    ClassName("tetOverlapVolume");
 
 
     // Constructors
@@ -177,18 +94,14 @@ public:
         tetOverlapVolume();
 
 
-    //- Destructor
-     virtual ~tetOverlapVolume();
-
-
     // Public members
 
         //- Return a list of cells in meshA which overlaps with cellBI in
         // meshB
         labelList overlappingCells
         (
-            const fvMesh& meshA,
-            const fvMesh& meshB,
+            const polyMesh& meshA,
+            const polyMesh& meshB,
             const label cellBI
         ) const;
 
diff --git a/src/sampling/meshToMeshInterpolation/tetOverlapVolume/tetrahedron.C b/src/sampling/meshToMeshInterpolation/tetOverlapVolume/tetrahedron.C
deleted file mode 100644
index d82cf30a506fc26c985ac204038b26de85c087e0..0000000000000000000000000000000000000000
--- a/src/sampling/meshToMeshInterpolation/tetOverlapVolume/tetrahedron.C
+++ /dev/null
@@ -1,341 +0,0 @@
-/*---------------------------------------------------------------------------*\
-  =========                 |
-  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
-   \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2012-2012 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 3 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, see <http://www.gnu.org/licenses/>.
-
-Description
-    Calculation of shape function product for a tetrahedron
-
-\*---------------------------------------------------------------------------*/
-
-#include "tetrahedron.H"
-#include "triPointRef.H"
-#include "scalarField.H"
-
-// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
-
-// (Probably very inefficient) minimum containment sphere calculation.
-// From http://www.imr.sandia.gov/papers/imr11/shewchuk2.pdf:
-// Sphere ctr is smallest one of
-// - tet circumcentre
-// - triangle circumcentre
-// - edge mids
-template<class Point, class PointRef>
-Foam::pointHit Foam::tetrahedron<Point, PointRef>::containmentSphere
-(
-    const scalar tol
-) const
-{
-    const scalar fac = 1 + tol;
-
-    // Halve order of tolerance for comparisons of sqr.
-    const scalar facSqr = Foam::sqrt(fac);
-
-
-    // 1. Circumcentre itself.
-
-    pointHit pHit(circumCentre());
-    pHit.setHit();
-    scalar minRadiusSqr = magSqr(pHit.rawPoint() - a_);
-
-
-    // 2. Try circumcentre of tet triangles. Create circumcircle for triFace and
-    // check if 4th point is inside.
-
-    {
-        point ctr = triPointRef(a_, b_, c_).circumCentre();
-        scalar radiusSqr = magSqr(ctr - a_);
-
-        if
-        (
-            radiusSqr < minRadiusSqr
-         && Foam::magSqr(d_-ctr) <= facSqr*radiusSqr
-        )
-        {
-            pHit.setMiss(false);
-            pHit.setPoint(ctr);
-            minRadiusSqr = radiusSqr;
-        }
-    }
-    {
-        point ctr = triPointRef(a_, b_, d_).circumCentre();
-        scalar radiusSqr = magSqr(ctr - a_);
-
-        if
-        (
-            radiusSqr < minRadiusSqr
-         && Foam::magSqr(c_-ctr) <= facSqr*radiusSqr
-        )
-        {
-            pHit.setMiss(false);
-            pHit.setPoint(ctr);
-            minRadiusSqr = radiusSqr;
-        }
-    }
-    {
-        point ctr = triPointRef(a_, c_, d_).circumCentre();
-        scalar radiusSqr = magSqr(ctr - a_);
-
-        if
-        (
-            radiusSqr < minRadiusSqr
-         && Foam::magSqr(b_-ctr) <= facSqr*radiusSqr
-        )
-        {
-            pHit.setMiss(false);
-            pHit.setPoint(ctr);
-            minRadiusSqr = radiusSqr;
-        }
-    }
-    {
-        point ctr = triPointRef(b_, c_, d_).circumCentre();
-        scalar radiusSqr = magSqr(ctr - b_);
-
-        if
-        (
-            radiusSqr < minRadiusSqr
-         && Foam::magSqr(a_-ctr) <= facSqr*radiusSqr
-        )
-        {
-            pHit.setMiss(false);
-            pHit.setPoint(ctr);
-            minRadiusSqr = radiusSqr;
-        }
-    }
-
-
-    // 3. Try midpoints of edges
-
-    // mid of edge A-B
-    {
-        point ctr = 0.5*(a_ + b_);
-        scalar radiusSqr = magSqr(a_ - ctr);
-        scalar testRadSrq = facSqr*radiusSqr;
-
-        if
-        (
-            radiusSqr < minRadiusSqr
-         && magSqr(c_-ctr) <= testRadSrq
-         && magSqr(d_-ctr) <= testRadSrq)
-        {
-            pHit.setMiss(false);
-            pHit.setPoint(ctr);
-            minRadiusSqr = radiusSqr;
-        }
-    }
-
-    // mid of edge A-C
-    {
-        point ctr = 0.5*(a_ + c_);
-        scalar radiusSqr = magSqr(a_ - ctr);
-        scalar testRadSrq = facSqr*radiusSqr;
-
-        if
-        (
-            radiusSqr < minRadiusSqr
-         && magSqr(b_-ctr) <= testRadSrq
-         && magSqr(d_-ctr) <= testRadSrq
-        )
-        {
-            pHit.setMiss(false);
-            pHit.setPoint(ctr);
-            minRadiusSqr = radiusSqr;
-        }
-    }
-
-    // mid of edge A-D
-    {
-        point ctr = 0.5*(a_ + d_);
-        scalar radiusSqr = magSqr(a_ - ctr);
-        scalar testRadSrq = facSqr*radiusSqr;
-
-        if
-        (
-            radiusSqr < minRadiusSqr
-         && magSqr(b_-ctr) <= testRadSrq
-         && magSqr(c_-ctr) <= testRadSrq
-        )
-        {
-            pHit.setMiss(false);
-            pHit.setPoint(ctr);
-            minRadiusSqr = radiusSqr;
-        }
-    }
-
-    // mid of edge B-C
-    {
-        point ctr = 0.5*(b_ + c_);
-        scalar radiusSqr = magSqr(b_ - ctr);
-        scalar testRadSrq = facSqr*radiusSqr;
-
-        if
-        (
-            radiusSqr < minRadiusSqr
-         && magSqr(a_-ctr) <= testRadSrq
-         && magSqr(d_-ctr) <= testRadSrq
-        )
-        {
-            pHit.setMiss(false);
-            pHit.setPoint(ctr);
-            minRadiusSqr = radiusSqr;
-        }
-    }
-
-    // mid of edge B-D
-    {
-        point ctr = 0.5*(b_ + d_);
-        scalar radiusSqr = magSqr(b_ - ctr);
-        scalar testRadSrq = facSqr*radiusSqr;
-
-        if
-        (
-            radiusSqr < minRadiusSqr
-         && magSqr(a_-ctr) <= testRadSrq
-         && magSqr(c_-ctr) <= testRadSrq)
-        {
-            pHit.setMiss(false);
-            pHit.setPoint(ctr);
-            minRadiusSqr = radiusSqr;
-        }
-    }
-
-    // mid of edge C-D
-    {
-        point ctr = 0.5*(c_ + d_);
-        scalar radiusSqr = magSqr(c_ - ctr);
-        scalar testRadSrq = facSqr*radiusSqr;
-
-        if
-        (
-            radiusSqr < minRadiusSqr
-         && magSqr(a_-ctr) <= testRadSrq
-         && magSqr(b_-ctr) <= testRadSrq
-        )
-        {
-            pHit.setMiss(false);
-            pHit.setPoint(ctr);
-            minRadiusSqr = radiusSqr;
-        }
-    }
-
-
-    pHit.setDistance(sqrt(minRadiusSqr));
-
-    return pHit;
-}
-
-
-template<class Point, class PointRef>
-void Foam::tetrahedron<Point, PointRef>::gradNiSquared
-(
-    scalarField& buffer
-) const
-{
-    // Change of sign between face area vector and gradient
-    // does not matter because of square
-
-    // Warning: Added a mag to produce positive coefficients even if
-    // the tetrahedron is twisted inside out.  This is pretty
-    // dangerous, but essential for mesh motion.
-    scalar magVol = Foam::mag(mag());
-
-    buffer[0] = (1.0/9.0)*magSqr(Sa())/magVol;
-    buffer[1] = (1.0/9.0)*magSqr(Sb())/magVol;
-    buffer[2] = (1.0/9.0)*magSqr(Sc())/magVol;
-    buffer[3] = (1.0/9.0)*magSqr(Sd())/magVol;
-}
-
-
-template<class Point, class PointRef>
-void Foam::tetrahedron<Point, PointRef>::gradNiDotGradNj
-(
-    scalarField& buffer
-) const
-{
-    // Warning. Ordering of edges needs to be the same for a tetrahedron
-    // class, a tetrahedron cell shape model and a tetCell
-
-    // Warning: Added a mag to produce positive coefficients even if
-    // the tetrahedron is twisted inside out.  This is pretty
-    // dangerous, but essential for mesh motion.
-
-    // Double change of sign between face area vector and gradient
-
-    scalar magVol = Foam::mag(mag());
-    vector sa = Sa();
-    vector sb = Sb();
-    vector sc = Sc();
-    vector sd = Sd();
-
-    buffer[0] = (1.0/9.0)*(sa & sb)/magVol;
-    buffer[1] = (1.0/9.0)*(sa & sc)/magVol;
-    buffer[2] = (1.0/9.0)*(sa & sd)/magVol;
-    buffer[3] = (1.0/9.0)*(sd & sb)/magVol;
-    buffer[4] = (1.0/9.0)*(sb & sc)/magVol;
-    buffer[5] = (1.0/9.0)*(sd & sc)/magVol;
-}
-
-
-template<class Point, class PointRef>
-void Foam::tetrahedron<Point, PointRef>::gradNiGradNi
-(
-    tensorField& buffer
-) const
-{
-    // Change of sign between face area vector and gradient
-    // does not matter because of square
-
-    scalar magVol = Foam::mag(mag());
-
-    buffer[0] = (1.0/9.0)*sqr(Sa())/magVol;
-    buffer[1] = (1.0/9.0)*sqr(Sb())/magVol;
-    buffer[2] = (1.0/9.0)*sqr(Sc())/magVol;
-    buffer[3] = (1.0/9.0)*sqr(Sd())/magVol;
-}
-
-
-template<class Point, class PointRef>
-void Foam::tetrahedron<Point, PointRef>::gradNiGradNj
-(
-    tensorField& buffer
-) const
-{
-    // Warning. Ordering of edges needs to be the same for a tetrahedron
-    // class, a tetrahedron cell shape model and a tetCell
-
-    // Double change of sign between face area vector and gradient
-
-    scalar magVol = Foam::mag(mag());
-    vector sa = Sa();
-    vector sb = Sb();
-    vector sc = Sc();
-    vector sd = Sd();
-
-    buffer[0] = (1.0/9.0)*(sa * sb)/magVol;
-    buffer[1] = (1.0/9.0)*(sa * sc)/magVol;
-    buffer[2] = (1.0/9.0)*(sa * sd)/magVol;
-    buffer[3] = (1.0/9.0)*(sd * sb)/magVol;
-    buffer[4] = (1.0/9.0)*(sb * sc)/magVol;
-    buffer[5] = (1.0/9.0)*(sd * sc)/magVol;
-}
-
-
-// ************************************************************************* //
diff --git a/src/sampling/meshToMeshInterpolation/tetOverlapVolume/tetrahedron.H b/src/sampling/meshToMeshInterpolation/tetOverlapVolume/tetrahedron.H
deleted file mode 100644
index 13e7acd4eb87e8f6bbc5a09fcd8e59c960fd1592..0000000000000000000000000000000000000000
--- a/src/sampling/meshToMeshInterpolation/tetOverlapVolume/tetrahedron.H
+++ /dev/null
@@ -1,315 +0,0 @@
-/*---------------------------------------------------------------------------*\
-  =========                 |
-  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
-   \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2012-2012 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 3 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, see <http://www.gnu.org/licenses/>.
-
-Class
-    Foam::tetrahedron
-
-Description
-    A tetrahedron primitive.
-
-    Ordering of edges needs to be the same for a tetrahedron
-    class, a tetrahedron cell shape model and a tetCell.
-
-SourceFiles
-    tetrahedronI.H
-    tetrahedron.C
-
-\*---------------------------------------------------------------------------*/
-
-#ifndef tetrahedron_H
-#define tetrahedron_H
-
-#include "point.H"
-#include "primitiveFieldsFwd.H"
-#include "pointHit.H"
-#include "cachedRandom.H"
-#include "Random.H"
-#include "FixedList.H"
-#include "UList.H"
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-namespace Foam
-{
-
-class Istream;
-class Ostream;
-class tetPoints;
-class plane;
-
-// Forward declaration of friend functions and operators
-
-template<class Point, class PointRef> class tetrahedron;
-
-template<class Point, class PointRef>
-inline Istream& operator>>
-(
-    Istream&,
-    tetrahedron<Point, PointRef>&
-);
-
-template<class Point, class PointRef>
-inline Ostream& operator<<
-(
-    Ostream&,
-    const tetrahedron<Point, PointRef>&
-);
-
-
-/*---------------------------------------------------------------------------*\
-                           class tetrahedron Declaration
-\*---------------------------------------------------------------------------*/
-
-template<class Point, class PointRef>
-class tetrahedron
-{
-public:
-
-        // Classes for use in sliceWithPlane. What to do with decomposition
-        // of tet.
-
-            //- Dummy
-            class dummyOp
-            {
-            public:
-                inline void operator()(const tetPoints&);
-            };
-
-            //- Sum resulting volumes
-            class sumVolOp
-            {
-            public:
-                scalar vol_;
-
-                inline sumVolOp();
-
-                inline void operator()(const tetPoints&);
-            };
-
-            //- Store resulting tets
-            class storeOp
-            {
-                FixedList<tetPoints, 200>& tets_;
-                label& nTets_;
-
-            public:
-                inline storeOp(FixedList<tetPoints, 200>&, label&);
-
-                inline void operator()(const tetPoints&);
-            };
-
-private:
-
-    // Private data
-
-        PointRef a_, b_, c_, d_;
-
-        inline static point planeIntersection
-        (
-            const FixedList<scalar, 4>&,
-            const tetPoints&,
-            const label,
-            const label
-        );
-
-        template<class TetOp>
-        inline static void decomposePrism
-        (
-            const FixedList<point, 6>& points,
-            TetOp& op
-        );
-
-        template<class AboveTetOp, class BelowTetOp>
-        inline static void tetSliceWithPlane
-        (
-            const plane& pl,
-            const tetPoints& tet,
-            AboveTetOp& aboveOp,
-            BelowTetOp& belowOp
-        );
-
-
-public:
-
-    // Member constants
-
-        enum
-        {
-            nVertices = 4,  // Number of vertices in tetrahedron
-            nEdges = 6      // Number of edges in tetrahedron
-        };
-
-
-    // Constructors
-
-        //- Construct from points
-        inline tetrahedron
-        (
-            const Point& a,
-            const Point& b,
-            const Point& c,
-            const Point& d
-        );
-
-        //- Construct from four points in the list of points
-        inline tetrahedron
-        (
-            const UList<Point>&,
-            const FixedList<label, 4>& indices
-        );
-
-        //- Construct from Istream
-        inline tetrahedron(Istream&);
-
-
-    // Member Functions
-
-        // Access
-
-            //- Return vertices
-            inline const Point& a() const;
-
-            inline const Point& b() const;
-
-            inline const Point& c() const;
-
-            inline const Point& d() const;
-
-
-        // Properties
-
-            //- Return face normal
-            inline vector Sa() const;
-
-            inline vector Sb() const;
-
-            inline vector Sc() const;
-
-            inline vector Sd() const;
-
-            //- Return centre (centroid)
-            inline Point centre() const;
-
-            //- Return volume
-            inline scalar mag() const;
-
-            //- Return circum-centre
-            inline Point circumCentre() const;
-
-            //- Return circum-radius
-            inline scalar circumRadius() const;
-
-            //- Return quality: Ratio of tetrahedron and circum-sphere
-            //  volume, scaled so that a regular tetrahedron has a
-            //  quality of 1
-            inline scalar quality() const;
-
-            //- Return a random point in the tetrahedron from a
-            //  uniform distribution
-            inline Point randomPoint(Random& rndGen) const;
-
-            //- Return a random point in the tetrahedron from a
-            //  uniform distribution
-            inline Point randomPoint(cachedRandom& rndGen) const;
-
-            //- Calculate the barycentric coordinates of the given
-            //  point, in the same order as a, b, c, d.  Returns the
-            //  determinant of the solution.
-            inline scalar barycentric
-            (
-                const point& pt,
-                List<scalar>& bary
-            ) const;
-
-            //- Return nearest point to p on tetrahedron
-            inline pointHit nearestPoint(const point& p) const;
-
-            //- Return true if point is inside tetrahedron
-            inline bool inside(const point& pt) const;
-
-            //- Decompose tet into tets above and below plane
-            template<class AboveTetOp, class BelowTetOp>
-            inline void sliceWithPlane
-            (
-                const plane& pl,
-                AboveTetOp& aboveOp,
-                BelowTetOp& belowOp
-            ) const;
-
-
-            //- Return (min)containment sphere, i.e. the smallest sphere with
-            //  all points inside. Returns pointHit with:
-            //  - hit         : if sphere is equal to circumsphere
-            //                  (biggest sphere)
-            //  - point       : centre of sphere
-            //  - distance    : radius of sphere
-            //  - eligiblemiss: false
-            // Tol (small compared to 1, e.g. 1E-9) is used to determine
-            // whether point is inside: mag(pt - ctr) < (1+tol)*radius.
-            pointHit containmentSphere(const scalar tol) const;
-
-            //- Fill buffer with shape function products
-            void gradNiSquared(scalarField& buffer) const;
-
-            void gradNiDotGradNj(scalarField& buffer) const;
-
-            void gradNiGradNi(tensorField& buffer) const;
-
-            void gradNiGradNj(tensorField& buffer) const;
-
-
-    // IOstream operators
-
-        friend Istream& operator>> <Point, PointRef>
-        (
-            Istream&,
-            tetrahedron&
-        );
-
-        friend Ostream& operator<< <Point, PointRef>
-        (
-            Ostream&,
-            const tetrahedron&
-        );
-};
-
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-} // End namespace Foam
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-#include "tetrahedronI.H"
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-#ifdef NoRepository
-#   include "tetrahedron.C"
-#endif
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-#endif
-
-// ************************************************************************* //
diff --git a/src/sampling/meshToMeshInterpolation/tetOverlapVolume/tetrahedronI.H b/src/sampling/meshToMeshInterpolation/tetOverlapVolume/tetrahedronI.H
deleted file mode 100644
index 922ae0057ea0a1e0dc3264b83a80e8dc624d963d..0000000000000000000000000000000000000000
--- a/src/sampling/meshToMeshInterpolation/tetOverlapVolume/tetrahedronI.H
+++ /dev/null
@@ -1,1012 +0,0 @@
-/*---------------------------------------------------------------------------*\
-  =========                 |
-  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
-   \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2012-2012 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 3 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, see <http://www.gnu.org/licenses/>.
-
-\*---------------------------------------------------------------------------*/
-
-#include "triangle.H"
-#include "IOstreams.H"
-#include "triPointRef.H"
-#include "tetPoints.H"
-#include "plane.H"
-
-// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
-
-template<class Point, class PointRef>
-inline Foam::tetrahedron<Point, PointRef>::tetrahedron
-(
-    const Point& a,
-    const Point& b,
-    const Point& c,
-    const Point& d
-)
-:
-    a_(a),
-    b_(b),
-    c_(c),
-    d_(d)
-{}
-
-
-template<class Point, class PointRef>
-inline Foam::tetrahedron<Point, PointRef>::tetrahedron
-(
-    const UList<Point>& points,
-    const FixedList<label, 4>& indices
-)
-:
-    a_(points[indices[0]]),
-    b_(points[indices[1]]),
-    c_(points[indices[2]]),
-    d_(points[indices[3]])
-{}
-
-
-template<class Point, class PointRef>
-inline Foam::tetrahedron<Point, PointRef>::tetrahedron(Istream& is)
-{
-    is  >> *this;
-}
-
-
-// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
-
-template<class Point, class PointRef>
-inline const Point& Foam::tetrahedron<Point, PointRef>::a() const
-{
-    return a_;
-}
-
-
-template<class Point, class PointRef>
-inline const Point& Foam::tetrahedron<Point, PointRef>::b() const
-{
-    return b_;
-}
-
-
-template<class Point, class PointRef>
-inline const Point& Foam::tetrahedron<Point, PointRef>::c() const
-{
-    return c_;
-}
-
-
-template<class Point, class PointRef>
-inline const Point& Foam::tetrahedron<Point, PointRef>::d() const
-{
-    return d_;
-}
-
-
-template<class Point, class PointRef>
-inline Foam::vector Foam::tetrahedron<Point, PointRef>::Sa() const
-{
-    return triangle<Point, PointRef>(b_, c_, d_).normal();
-}
-
-
-template<class Point, class PointRef>
-inline Foam::vector Foam::tetrahedron<Point, PointRef>::Sb() const
-{
-    return triangle<Point, PointRef>(a_, d_, c_).normal();
-}
-
-
-template<class Point, class PointRef>
-inline Foam::vector Foam::tetrahedron<Point, PointRef>::Sc() const
-{
-    return triangle<Point, PointRef>(a_, b_, d_).normal();
-}
-
-
-template<class Point, class PointRef>
-inline Foam::vector Foam::tetrahedron<Point, PointRef>::Sd() const
-{
-    return triangle<Point, PointRef>(a_, c_, b_).normal();
-}
-
-
-template<class Point, class PointRef>
-inline Point Foam::tetrahedron<Point, PointRef>::centre() const
-{
-    return 0.25*(a_ + b_ + c_ + d_);
-}
-
-
-template<class Point, class PointRef>
-inline Foam::scalar Foam::tetrahedron<Point, PointRef>::mag() const
-{
-    return (1.0/6.0)*(((b_ - a_) ^ (c_ - a_)) & (d_ - a_));
-}
-
-
-template<class Point, class PointRef>
-inline Point Foam::tetrahedron<Point, PointRef>::circumCentre() const
-{
-    vector a = b_ - a_;
-    vector b = c_ - a_;
-    vector c = d_ - a_;
-
-    scalar lambda = magSqr(c) - (a & c);
-    scalar mu = magSqr(b) - (a & b);
-
-    vector ba = b ^ a;
-    vector ca = c ^ a;
-
-    vector num = lambda*ba - mu*ca;
-    scalar denom = (c & ba);
-
-    if (Foam::mag(denom) < ROOTVSMALL)
-    {
-        // Degenerate tetrahedron, returning centre instead of circumCentre.
-
-        return centre();
-    }
-
-    return a_ + 0.5*(a + num/denom);
-}
-
-
-template<class Point, class PointRef>
-inline Foam::scalar Foam::tetrahedron<Point, PointRef>::circumRadius() const
-{
-    vector a = b_ - a_;
-    vector b = c_ - a_;
-    vector c = d_ - a_;
-
-    scalar lambda = magSqr(c) - (a & c);
-    scalar mu = magSqr(b) - (a & b);
-
-    vector ba = b ^ a;
-    vector ca = c ^ a;
-
-    vector num = lambda*ba - mu*ca;
-    scalar denom = (c & ba);
-
-    if (Foam::mag(denom) < ROOTVSMALL)
-    {
-        // Degenerate tetrahedron, returning GREAT for circumRadius.
-        return GREAT;
-    }
-
-    return Foam::mag(0.5*(a + num/denom));
-}
-
-
-template<class Point, class PointRef>
-inline Foam::scalar Foam::tetrahedron<Point, PointRef>::quality() const
-{
-    return
-        mag()
-       /(
-            8.0/(9.0*sqrt(3.0))
-           *pow3(min(circumRadius(), GREAT))
-          + ROOTVSMALL
-        );
-}
-
-
-template<class Point, class PointRef>
-inline Point Foam::tetrahedron<Point, PointRef>::randomPoint
-(
-    Random& rndGen
-) const
-{
-    // Adapted from
-    // http://vcg.isti.cnr.it/activities/geometryegraphics/pointintetraedro.html
-
-    scalar s = rndGen.scalar01();
-    scalar t = rndGen.scalar01();
-    scalar u = rndGen.scalar01();
-
-    if (s + t > 1.0)
-    {
-        s = 1.0 - s;
-        t = 1.0 - t;
-    }
-
-    if (t + u > 1.0)
-    {
-        scalar tmp = u;
-        u = 1.0 - s - t;
-        t = 1.0 - tmp;
-    }
-    else if (s + t + u > 1.0)
-    {
-        scalar tmp = u;
-        u = s + t + u - 1.0;
-        s = 1.0 - t - tmp;
-    }
-
-    return (1 - s - t - u)*a_ + s*b_ + t*c_ + u*d_;
-}
-
-
-template<class Point, class PointRef>
-inline Point Foam::tetrahedron<Point, PointRef>::randomPoint
-(
-    cachedRandom& rndGen
-) const
-{
-    // Adapted from
-    // http://vcg.isti.cnr.it/activities/geometryegraphics/pointintetraedro.html
-
-    scalar s = rndGen.sample01<scalar>();
-    scalar t = rndGen.sample01<scalar>();
-    scalar u = rndGen.sample01<scalar>();
-
-    if (s + t > 1.0)
-    {
-        s = 1.0 - s;
-        t = 1.0 - t;
-    }
-
-    if (t + u > 1.0)
-    {
-        scalar tmp = u;
-        u = 1.0 - s - t;
-        t = 1.0 - tmp;
-    }
-    else if (s + t + u > 1.0)
-    {
-        scalar tmp = u;
-        u = s + t + u - 1.0;
-        s = 1.0 - t - tmp;
-    }
-
-    return (1 - s - t - u)*a_ + s*b_ + t*c_ + u*d_;
-}
-
-
-template<class Point, class PointRef>
-Foam::scalar Foam::tetrahedron<Point, PointRef>::barycentric
-(
-    const point& pt,
-    List<scalar>& bary
-) const
-{
-    // From:
-    // http://en.wikipedia.org/wiki/Barycentric_coordinate_system_(mathematics)
-
-    vector e0(a_ - d_);
-    vector e1(b_ - d_);
-    vector e2(c_ - d_);
-
-    tensor t
-    (
-        e0.x(), e1.x(), e2.x(),
-        e0.y(), e1.y(), e2.y(),
-        e0.z(), e1.z(), e2.z()
-    );
-
-    scalar detT = det(t);
-
-    if (Foam::mag(detT) < SMALL)
-    {
-        // Degenerate tetrahedron, returning 1/4 barycentric coordinates.
-
-        bary = List<scalar>(4, 0.25);
-
-        return detT;
-    }
-
-    vector res = inv(t, detT) & (pt - d_);
-
-    bary.setSize(4);
-
-    bary[0] = res.x();
-    bary[1] = res.y();
-    bary[2] = res.z();
-    bary[3] = (1.0 - res.x() - res.y() - res.z());
-
-    return detT;
-}
-
-
-template<class Point, class PointRef>
-inline Foam::pointHit Foam::tetrahedron<Point, PointRef>::nearestPoint
-(
-    const point& p
-) const
-{
-    // Adapted from:
-    // Real-time collision detection, Christer Ericson, 2005, p142-144
-
-    // Assuming initially that the point is inside all of the
-    // halfspaces, so closest to itself.
-
-    point closestPt = p;
-
-    scalar minOutsideDistance = VGREAT;
-
-    bool inside = true;
-
-    if (((p - b_) & Sa()) >= 0)
-    {
-        // p is outside halfspace plane of tri
-        pointHit info = triangle<Point, PointRef>(b_, c_, d_).nearestPoint(p);
-
-        inside = false;
-
-        if (info.distance() < minOutsideDistance)
-        {
-            closestPt = info.rawPoint();
-
-            minOutsideDistance = info.distance();
-        }
-    }
-
-    if (((p - a_) & Sb()) >= 0)
-    {
-        // p is outside halfspace plane of tri
-        pointHit info = triangle<Point, PointRef>(a_, d_, c_).nearestPoint(p);
-
-        inside = false;
-
-        if (info.distance() < minOutsideDistance)
-        {
-            closestPt = info.rawPoint();
-
-            minOutsideDistance = info.distance();
-        }
-    }
-
-    if (((p - a_) & Sc()) >= 0)
-    {
-        // p is outside halfspace plane of tri
-        pointHit info = triangle<Point, PointRef>(a_, b_, d_).nearestPoint(p);
-
-        inside = false;
-
-        if (info.distance() < minOutsideDistance)
-        {
-            closestPt = info.rawPoint();
-
-            minOutsideDistance = info.distance();
-        }
-    }
-
-    if (((p - a_) & Sd()) >= 0)
-    {
-        // p is outside halfspace plane of tri
-        pointHit info = triangle<Point, PointRef>(a_, c_, b_).nearestPoint(p);
-
-        inside = false;
-
-        if (info.distance() < minOutsideDistance)
-        {
-            closestPt = info.rawPoint();
-
-            minOutsideDistance = info.distance();
-        }
-    }
-
-    // If the point is inside, then the distance to the closest point
-    // is zero
-    if (inside)
-    {
-        minOutsideDistance = 0;
-    }
-
-    return pointHit
-    (
-        inside,
-        closestPt,
-        minOutsideDistance,
-        !inside
-    );
-}
-
-
-template<class Point, class PointRef>
-bool Foam::tetrahedron<Point, PointRef>::inside(const point& pt) const
-{
-    // For robustness, assuming that the point is in the tet unless
-    // "definitively" shown otherwise by obtaining a positive dot
-    // product greater than a tolerance of SMALL.
-
-    // The tet is defined: tet(Cc, tetBasePt, pA, pB) where the normal
-    // vectors and base points for the half-space planes are:
-    // area[0] = Sa();
-    // area[1] = Sb();
-    // area[2] = Sc();
-    // area[3] = Sd();
-    // planeBase[0] = tetBasePt = b_
-    // planeBase[1] = ptA       = c_
-    // planeBase[2] = tetBasePt = b_
-    // planeBase[3] = tetBasePt = b_
-
-    vector n = vector::zero;
-
-    {
-        // 0, a
-        const point& basePt = b_;
-
-        n = Sa();
-        n /= (Foam::mag(n) + VSMALL);
-
-        if (((pt - basePt) & n) > SMALL)
-        {
-            return false;
-        }
-    }
-
-    {
-        // 1, b
-        const point& basePt = c_;
-
-        n = Sb();
-        n /= (Foam::mag(n) + VSMALL);
-
-        if (((pt - basePt) & n) > SMALL)
-        {
-            return false;
-        }
-    }
-
-    {
-        // 2, c
-        const point& basePt = b_;
-
-        n = Sc();
-        n /= (Foam::mag(n) + VSMALL);
-
-        if (((pt - basePt) & n) > SMALL)
-        {
-            return false;
-        }
-    }
-
-    {
-        // 3, d
-        const point& basePt = b_;
-
-        n = Sd();
-        n /= (Foam::mag(n) + VSMALL);
-
-        if (((pt - basePt) & n) > SMALL)
-        {
-            return false;
-        }
-    }
-
-    return true;
-}
-
-
-template<class Point, class PointRef>
-inline void Foam::tetrahedron<Point, PointRef>::dummyOp::operator()
-(
-    const tetPoints&
-)
-{}
-
-
-template<class Point, class PointRef>
-inline Foam::tetrahedron<Point, PointRef>::sumVolOp::sumVolOp()
-:
-    vol_(0.0)
-{}
-
-
-template<class Point, class PointRef>
-inline void Foam::tetrahedron<Point, PointRef>::sumVolOp::operator()
-(
-    const tetPoints& tet
-)
-{
-    vol_ += tet.tet().mag();
-}
-
-
-template<class Point, class PointRef>
-inline Foam::tetrahedron<Point, PointRef>::storeOp::storeOp
-(
-    FixedList<tetPoints, 200>& tets,
-    label& nTets
-)
-:
-    tets_(tets),
-    nTets_(nTets)
-{}
-
-
-template<class Point, class PointRef>
-inline void Foam::tetrahedron<Point, PointRef>::storeOp::operator()
-(
-    const tetPoints& tet
-)
-{
-    tets_[nTets_++] = tet;
-}
-
-
-template<class Point, class PointRef>
-inline Foam::point Foam::tetrahedron<Point, PointRef>::planeIntersection
-(
-    const FixedList<scalar, 4>& d,
-    const tetPoints& t,
-    const label negI,
-    const label posI
-)
-{
-    return
-        (d[posI]*t[negI] - d[negI]*t[posI])
-      / (-d[negI]+d[posI]);
-}
-
-
-template<class Point, class PointRef>
-template<class TetOp>
-inline void Foam::tetrahedron<Point, PointRef>::decomposePrism
-(
-    const FixedList<point, 6>& points,
-    TetOp& op
-)
-{
-    op(tetPoints(points[1], points[3], points[2], points[0]));
-    op(tetPoints(points[1], points[2], points[3], points[4]));
-    op(tetPoints(points[4], points[2], points[3], points[5]));
-}
-
-
-template<class Point, class PointRef>
-template<class AboveTetOp, class BelowTetOp>
-inline void Foam::tetrahedron<Point, PointRef>::
-tetSliceWithPlane
-(
-    const plane& pl,
-    const tetPoints& tet,
-    AboveTetOp& aboveOp,
-    BelowTetOp& belowOp
-)
-{
-    // Distance to plane
-    FixedList<scalar, 4> d;
-    label nPos = 0;
-    forAll(tet, i)
-    {
-        d[i] = ((tet[i]-pl.refPoint()) & pl.normal());
-        if (d[i] > 0)
-        {
-            nPos++;
-        }
-    }
-
-    if (nPos == 4)
-    {
-        aboveOp(tet);
-    }
-    else if (nPos == 3)
-    {
-        // Sliced into below tet and above prism. Prism gets split into
-        // two tets.
-
-        // Find the below tet
-        label i0 = -1;
-        forAll(d, i)
-        {
-            if (d[i] <= 0)
-            {
-                i0 = i;
-                break;
-            }
-        }
-
-        label i1 = d.fcIndex(i0);
-        label i2 = d.fcIndex(i1);
-        label i3 = d.fcIndex(i2);
-
-        point p01 = planeIntersection(d, tet, i0, i1);
-        point p02 = planeIntersection(d, tet, i0, i2);
-        point p03 = planeIntersection(d, tet, i0, i3);
-
-        // i0 = tetCell vertex 0: p01,p02,p03 outwards pointing triad
-        //          ,,         1 :     ,,     inwards pointing triad
-        //          ,,         2 :     ,,     outwards pointing triad
-        //          ,,         3 :     ,,     inwards pointing triad
-
-        //Pout<< "Split 3pos tet " << tet << " d:" << d << " into" << nl;
-
-        if (i0 == 0 || i0 == 2)
-        {
-            tetPoints t(tet[i0], p01, p02, p03);
-            //Pout<< "    belowtet:" << t << " around i0:" << i0 << endl;
-            //checkTet(t, "nPos 3, belowTet i0==0 or 2");
-            belowOp(t);
-
-            // Prism
-            FixedList<point, 6> p;
-            p[0] = tet[i1];
-            p[1] = tet[i3];
-            p[2] = tet[i2];
-            p[3] = p01;
-            p[4] = p03;
-            p[5] = p02;
-            //Pout<< "    aboveprism:" << p << endl;
-            decomposePrism(p, aboveOp);
-        }
-        else
-        {
-            tetPoints t(p01, p02, p03, tet[i0]);
-            //Pout<< "    belowtet:" << t << " around i0:" << i0 << endl;
-            //checkTet(t, "nPos 3, belowTet i0==1 or 3");
-            belowOp(t);
-
-            // Prism
-            FixedList<point, 6> p;
-            p[0] = tet[i3];
-            p[1] = tet[i1];
-            p[2] = tet[i2];
-            p[3] = p03;
-            p[4] = p01;
-            p[5] = p02;
-            //Pout<< "    aboveprism:" << p << endl;
-            decomposePrism(p, aboveOp);
-        }
-    }
-    else if (nPos == 2)
-    {
-        // Tet cut into two prisms. Determine the positive one.
-        label pos0 = -1;
-        label pos1 = -1;
-        label neg0 = -1;
-        label neg1 = -1;
-        forAll(d, i)
-        {
-            if (d[i] > 0)
-            {
-                if (pos0 == -1)
-                {
-                    pos0 = i;
-                }
-                else
-                {
-                    pos1 = i;
-                }
-            }
-            else
-            {
-                if (neg0 == -1)
-                {
-                    neg0 = i;
-                }
-                else
-                {
-                    neg1 = i;
-                }
-            }
-        }
-
-        //Pout<< "Split 2pos tet " << tet << " d:" << d
-        //    << " around pos0:" << pos0 << " pos1:" << pos1
-        //    << " neg0:" << neg0 << " neg1:" << neg1 << " into" << nl;
-
-        const edge posEdge(pos0, pos1);
-
-        if (posEdge == edge(0, 1))
-        {
-            point p02 = planeIntersection(d, tet, 0, 2);
-            point p03 = planeIntersection(d, tet, 0, 3);
-            point p12 = planeIntersection(d, tet, 1, 2);
-            point p13 = planeIntersection(d, tet, 1, 3);
-            // Split the resulting prism
-            {
-                FixedList<point, 6> p;
-                p[0] = tet[0];
-                p[1] = p02;
-                p[2] = p03;
-                p[3] = tet[1];
-                p[4] = p12;
-                p[5] = p13;
-                //Pout<< "    01 aboveprism:" << p << endl;
-                decomposePrism(p, aboveOp);
-            }
-            {
-                FixedList<point, 6> p;
-                p[0] = tet[2];
-                p[1] = p02;
-                p[2] = p12;
-                p[3] = tet[3];
-                p[4] = p03;
-                p[5] = p13;
-                //Pout<< "    01 belowprism:" << p << endl;
-                decomposePrism(p, belowOp);
-            }
-        }
-        else if (posEdge == edge(1, 2))
-        {
-            point p01 = planeIntersection(d, tet, 0, 1);
-            point p13 = planeIntersection(d, tet, 1, 3);
-            point p02 = planeIntersection(d, tet, 0, 2);
-            point p23 = planeIntersection(d, tet, 2, 3);
-            // Split the resulting prism
-            {
-                FixedList<point, 6> p;
-                p[0] = tet[1];
-                p[1] = p01;
-                p[2] = p13;
-                p[3] = tet[2];
-                p[4] = p02;
-                p[5] = p23;
-                //Pout<< "    12 aboveprism:" << p << endl;
-                decomposePrism(p, aboveOp);
-            }
-            {
-                FixedList<point, 6> p;
-                p[0] = tet[3];
-                p[1] = p23;
-                p[2] = p13;
-                p[3] = tet[0];
-                p[4] = p02;
-                p[5] = p01;
-                //Pout<< "    12 belowprism:" << p << endl;
-                decomposePrism(p, belowOp);
-            }
-        }
-        else if (posEdge == edge(2, 0))
-        {
-            point p01 = planeIntersection(d, tet, 0, 1);
-            point p03 = planeIntersection(d, tet, 0, 3);
-            point p12 = planeIntersection(d, tet, 1, 2);
-            point p23 = planeIntersection(d, tet, 2, 3);
-            // Split the resulting prism
-            {
-                FixedList<point, 6> p;
-                p[0] = tet[2];
-                p[1] = p12;
-                p[2] = p23;
-                p[3] = tet[0];
-                p[4] = p01;
-                p[5] = p03;
-                //Pout<< "    20 aboveprism:" << p << endl;
-                decomposePrism(p, aboveOp);
-            }
-            {
-                FixedList<point, 6> p;
-                p[0] = tet[1];
-                p[1] = p12;
-                p[2] = p01;
-                p[3] = tet[3];
-                p[4] = p23;
-                p[5] = p03;
-                //Pout<< "    20 belowprism:" << p << endl;
-                decomposePrism(p, belowOp);
-            }
-        }
-        else if (posEdge == edge(0, 3))
-        {
-            point p01 = planeIntersection(d, tet, 0, 1);
-            point p02 = planeIntersection(d, tet, 0, 2);
-            point p13 = planeIntersection(d, tet, 1, 3);
-            point p23 = planeIntersection(d, tet, 2, 3);
-            // Split the resulting prism
-            {
-                FixedList<point, 6> p;
-                p[0] = tet[3];
-                p[1] = p23;
-                p[2] = p13;
-                p[3] = tet[0];
-                p[4] = p02;
-                p[5] = p01;
-                //Pout<< "    03 aboveprism:" << p << endl;
-                decomposePrism(p, aboveOp);
-            }
-            {
-                FixedList<point, 6> p;
-                p[0] = tet[2];
-                p[1] = p23;
-                p[2] = p02;
-                p[3] = tet[1];
-                p[4] = p13;
-                p[5] = p01;
-                //Pout<< "    03 belowprism:" << p << endl;
-                decomposePrism(p, belowOp);
-            }
-        }
-        else if (posEdge == edge(1, 3))
-        {
-            point p01 = planeIntersection(d, tet, 0, 1);
-            point p12 = planeIntersection(d, tet, 1, 2);
-            point p03 = planeIntersection(d, tet, 0, 3);
-            point p23 = planeIntersection(d, tet, 2, 3);
-            // Split the resulting prism
-            {
-                FixedList<point, 6> p;
-                p[0] = tet[1];
-                p[1] = p12;
-                p[2] = p01;
-                p[3] = tet[3];
-                p[4] = p23;
-                p[5] = p03;
-                //Pout<< "    13 aboveprism:" << p << endl;
-                decomposePrism(p, aboveOp);
-            }
-            {
-                FixedList<point, 6> p;
-                p[0] = tet[2];
-                p[1] = p12;
-                p[2] = p23;
-                p[3] = tet[0];
-                p[4] = p01;
-                p[5] = p03;
-                //Pout<< "    13 belowprism:" << p << endl;
-                decomposePrism(p, belowOp);
-            }
-        }
-        else if (posEdge == edge(2, 3))
-        {
-            point p02 = planeIntersection(d, tet, 0, 2);
-            point p12 = planeIntersection(d, tet, 1, 2);
-            point p03 = planeIntersection(d, tet, 0, 3);
-            point p13 = planeIntersection(d, tet, 1, 3);
-            // Split the resulting prism
-            {
-                FixedList<point, 6> p;
-                p[0] = tet[2];
-                p[1] = p02;
-                p[2] = p12;
-                p[3] = tet[3];
-                p[4] = p03;
-                p[5] = p13;
-                //Pout<< "    23 aboveprism:" << p << endl;
-                decomposePrism(p, aboveOp);
-            }
-            {
-                FixedList<point, 6> p;
-                p[0] = tet[0];
-                p[1] = p02;
-                p[2] = p03;
-                p[3] = tet[1];
-                p[4] = p12;
-                p[5] = p13;
-                //Pout<< "    23 belowprism:" << p << endl;
-                decomposePrism(p, belowOp);
-            }
-        }
-        else
-        {
-            FatalErrorIn("tetSliceWithPlane(..)")
-                << "Missed edge:" << posEdge
-                << abort(FatalError);
-        }
-    }
-    else if (nPos == 1)
-    {
-        // Find the positive tet
-        label i0 = -1;
-        forAll(d, i)
-        {
-            if (d[i] > 0)
-            {
-                i0 = i;
-                break;
-            }
-        }
-
-        label i1 = d.fcIndex(i0);
-        label i2 = d.fcIndex(i1);
-        label i3 = d.fcIndex(i2);
-
-        point p01 = planeIntersection(d, tet, i0, i1);
-        point p02 = planeIntersection(d, tet, i0, i2);
-        point p03 = planeIntersection(d, tet, i0, i3);
-
-        //Pout<< "Split 1pos tet " << tet << " d:" << d << " into" << nl;
-
-        if (i0 == 0 || i0 == 2)
-        {
-            tetPoints t(tet[i0], p01, p02, p03);
-            //Pout<< "    abovetet:" << t << " around i0:" << i0 << endl;
-            //checkTet(t, "nPos 1, aboveTets i0==0 or 2");
-            aboveOp(t);
-
-            // Prism
-            FixedList<point, 6> p;
-            p[0] = tet[i1];
-            p[1] = tet[i3];
-            p[2] = tet[i2];
-            p[3] = p01;
-            p[4] = p03;
-            p[5] = p02;
-            //Pout<< "    belowprism:" << p << endl;
-            decomposePrism(p, belowOp);
-        }
-        else
-        {
-            tetPoints t(p01, p02, p03, tet[i0]);
-            //Pout<< "    abovetet:" << t << " around i0:" << i0 << endl;
-            //checkTet(t, "nPos 1, aboveTets i0==1 or 3");
-            aboveOp(t);
-
-            // Prism
-            FixedList<point, 6> p;
-            p[0] = tet[i3];
-            p[1] = tet[i1];
-            p[2] = tet[i2];
-            p[3] = p03;
-            p[4] = p01;
-            p[5] = p02;
-            //Pout<< "    belowprism:" << p << endl;
-            decomposePrism(p, belowOp);
-        }
-    }
-    else    // nPos == 0
-    {
-        belowOp(tet);
-    }
-}
-
-
-template<class Point, class PointRef>
-template<class AboveTetOp, class BelowTetOp>
-inline void Foam::tetrahedron<Point, PointRef>::sliceWithPlane
-(
-    const plane& pl,
-    AboveTetOp& aboveOp,
-    BelowTetOp& belowOp
-) const
-{
-    tetSliceWithPlane(pl, tetPoints(a_, b_, c_, d_), aboveOp, belowOp);
-}
-
-
-// * * * * * * * * * * * * * * * Ostream Operator  * * * * * * * * * * * * * //
-
-template<class Point, class PointRef>
-inline Foam::Istream& Foam::operator>>
-(
-    Istream& is,
-    tetrahedron<Point, PointRef>& t
-)
-{
-    is.readBegin("tetrahedron");
-    is  >> t.a_ >> t.b_ >> t.c_ >> t.d_;
-    is.readEnd("tetrahedron");
-
-    is.check("Istream& operator>>(Istream&, tetrahedron&)");
-
-    return is;
-}
-
-
-template<class Point, class PointRef>
-inline Foam::Ostream& Foam::operator<<
-(
-    Ostream& os,
-    const tetrahedron<Point, PointRef>& t
-)
-{
-    os  << nl
-        << token::BEGIN_LIST
-        << t.a_ << token::SPACE
-        << t.b_ << token::SPACE
-        << t.c_ << token::SPACE
-        << t.d_
-        << token::END_LIST;
-
-    return os;
-}
-
-
-// ************************************************************************* //
diff --git a/src/thermophysicalModels/basic/Make/files b/src/thermophysicalModels/basic/Make/files
index 1a9d82af062507e937dcaa3fe2c4d3633f60dd97..1c08f455dfd1f1231e23ddf8d4b1835b2cec8fb9 100644
--- a/src/thermophysicalModels/basic/Make/files
+++ b/src/thermophysicalModels/basic/Make/files
@@ -2,6 +2,7 @@ mixtures/basicMixture/basicMixture.C
 mixtures/basicMixture/basicMixtures.C
 
 basicThermo/basicThermo.C
+basicThermo/basicThermoNew.C
 
 psiThermo/basicPsiThermo/basicPsiThermo.C
 psiThermo/basicPsiThermo/basicPsiThermoNew.C
diff --git a/src/thermophysicalModels/basic/basicThermo/basicThermo.C b/src/thermophysicalModels/basic/basicThermo/basicThermo.C
index 7b0d81aea78eb41e44baba35b885f283a451212f..ad40123d6eed02483f6c60a456757caace07808b 100644
--- a/src/thermophysicalModels/basic/basicThermo/basicThermo.C
+++ b/src/thermophysicalModels/basic/basicThermo/basicThermo.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -39,6 +39,7 @@ License
 namespace Foam
 {
     defineTypeNameAndDebug(basicThermo, 0);
+    defineRunTimeSelectionTable(basicThermo, fvMesh);
 }
 
 // * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * //
diff --git a/src/thermophysicalModels/basic/basicThermo/basicThermo.H b/src/thermophysicalModels/basic/basicThermo/basicThermo.H
index aa331ded7e1a86f57e98ca4b17757c91af04d9eb..0bb67f8b49557e891f55791f29ccd4c7f7031f9d 100644
--- a/src/thermophysicalModels/basic/basicThermo/basicThermo.H
+++ b/src/thermophysicalModels/basic/basicThermo/basicThermo.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -29,7 +29,7 @@ Description
 
 SourceFiles
     basicThermo.C
-    newBasicThermo.C
+    basicThermoNew.C
 
 \*---------------------------------------------------------------------------*/
 
@@ -109,12 +109,25 @@ public:
     TypeName("basicThermo");
 
 
+    //- Declare run-time constructor selection table
+    declareRunTimeSelectionTable
+    (
+        autoPtr,
+        basicThermo,
+        fvMesh,
+        (const fvMesh& mesh),
+        (mesh)
+    );
+
     // Constructors
 
         //- Construct from mesh
         basicThermo(const fvMesh&);
 
 
+    //- Selector
+    static autoPtr<basicThermo> New(const fvMesh&);
+
     //- Destructor
     virtual ~basicThermo();
 
diff --git a/src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetPointRef.H b/src/thermophysicalModels/basic/basicThermo/basicThermoNew.C
similarity index 51%
rename from src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetPointRef.H
rename to src/thermophysicalModels/basic/basicThermo/basicThermoNew.C
index 56382a55c7cbddb25d7a2bebff7fc291c2c9aeac..e7dda0d9d548d8543a47f6346c02de0895bdbacb 100644
--- a/src/OpenFOAM/meshes/primitiveShapes/tetrahedron/tetPointRef.H
+++ b/src/thermophysicalModels/basic/basicThermo/basicThermoNew.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -21,32 +21,51 @@ License
     You should have received a copy of the GNU General Public License
     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
 
-Typedef
-    Foam::tetPointRef
-
-Description
-
 \*---------------------------------------------------------------------------*/
 
-#ifndef tetPointRef_H
-#define tetPointRef_H
-
-#include "point.H"
-#include "tetrahedron.H"
+#include "basicThermo.H"
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
-namespace Foam
+Foam::autoPtr<Foam::basicThermo> Foam::basicThermo::New
+(
+    const fvMesh& mesh
+)
 {
+    // get model name, but do not register the dictionary
+    // otherwise it is registered in the database twice
+    const word modelType
+    (
+        IOdictionary
+        (
+            IOobject
+            (
+                "thermophysicalProperties",
+                mesh.time().constant(),
+                mesh,
+                IOobject::MUST_READ_IF_MODIFIED,
+                IOobject::NO_WRITE,
+                false
+            )
+        ).lookup("thermoType")
+    );
+
+    Info<< "Selecting thermodynamics package " << modelType << endl;
+
+    fvMeshConstructorTable::iterator cstrIter =
+        fvMeshConstructorTablePtr_->find(modelType);
+
+    if (cstrIter == fvMeshConstructorTablePtr_->end())
+    {
+        FatalErrorIn("basicThermo::New(const fvMesh&)")
+            << "Unknown basicThermo type " << modelType << nl << nl
+            << "Valid basicThermo types are:" << nl
+            << fvMeshConstructorTablePtr_->sortedToc() << nl
+            << exit(FatalError);
+    }
+
+    return autoPtr<basicThermo>(cstrIter()(mesh));
+}
 
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-typedef tetrahedron<point, const point&> tetPointRef;
-
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-} // End namespace Foam
-
-#endif
 
 // ************************************************************************* //
diff --git a/src/thermophysicalModels/basic/psiThermo/basicPsiThermo/makeBasicPsiThermo.H b/src/thermophysicalModels/basic/psiThermo/basicPsiThermo/makeBasicPsiThermo.H
index 890b5f2b90f197863c5ecc793c067a831eca7d5d..d9322918d59a9f76e9050e2ce68376015f2852b4 100644
--- a/src/thermophysicalModels/basic/psiThermo/basicPsiThermo/makeBasicPsiThermo.H
+++ b/src/thermophysicalModels/basic/psiThermo/basicPsiThermo/makeBasicPsiThermo.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -55,7 +55,14 @@ addToRunTimeSelectionTable                                                    \
     basicPsiThermo,                                                           \
     Cthermo##Mixture##Transport##Thermo##EqnOfState,                          \
     fvMesh                                                                    \
-)
+);                                                                            \
+                                                                              \
+addToRunTimeSelectionTable                                                    \
+(                                                                             \
+    basicThermo,                                                              \
+    Cthermo##Mixture##Transport##Thermo##EqnOfState,                          \
+    fvMesh                                                                    \
+);
 
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/src/thermophysicalModels/basic/rhoThermo/basicRhoThermo/makeBasicRhoThermo.H b/src/thermophysicalModels/basic/rhoThermo/basicRhoThermo/makeBasicRhoThermo.H
index 3edfa3a69c03407913421cd850d4bbadaf6f7cf8..e7a4de187e1272083c4f07eb27ce7d3e4a9fc63d 100644
--- a/src/thermophysicalModels/basic/rhoThermo/basicRhoThermo/makeBasicRhoThermo.H
+++ b/src/thermophysicalModels/basic/rhoThermo/basicRhoThermo/makeBasicRhoThermo.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -55,7 +55,14 @@ addToRunTimeSelectionTable                                                    \
     basicRhoThermo,                                                           \
     Cthermo##Mixture##Transport##Thermo##EqnOfState,                          \
     fvMesh                                                                    \
-)
+);                                                                            \
+                                                                              \
+addToRunTimeSelectionTable                                                    \
+(                                                                             \
+    basicThermo,                                                              \
+    Cthermo##Mixture##Transport##Thermo##EqnOfState,                          \
+    fvMesh                                                                    \
+);
 
 
 #define makeBasicRhoPolyThermo(Cthermo,Mixture,Order)                         \
@@ -88,7 +95,14 @@ addToRunTimeSelectionTable                                                    \
     basicRhoThermo,                                                           \
     Cthermo##Mixture##icoPoly##Order##ThermoPhysics,                          \
     fvMesh                                                                    \
-)
+);                                                                            \
+                                                                              \
+addToRunTimeSelectionTable                                                    \
+(                                                                             \
+    basicThermo,                                                              \
+    Cthermo##Mixture##icoPoly##Order##ThermoPhysics,                          \
+    fvMesh                                                                    \
+);
 
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/src/turbulenceModels/compressible/LES/Smagorinsky/Smagorinsky.H b/src/turbulenceModels/compressible/LES/Smagorinsky/Smagorinsky.H
index f0bc077531c1993e6a4b634a8feb59f891cec411..947b49fa75ded3eb25f14d759ab4a175c937eab4 100644
--- a/src/turbulenceModels/compressible/LES/Smagorinsky/Smagorinsky.H
+++ b/src/turbulenceModels/compressible/LES/Smagorinsky/Smagorinsky.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2011-2012 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -113,7 +113,13 @@ public:
         //  calculated from the given velocity gradient
         tmp<volScalarField> k(const tmp<volTensorField>& gradU) const
         {
-            return (2.0*ck_/ce_)*sqr(delta())*magSqr(dev(symm(gradU)));
+            volSymmTensorField D(symm(gradU));
+
+            volScalarField a(ce_/delta());
+            volScalarField b((2.0/3.0)*tr(D));
+            volScalarField c(2*ck_*delta()*(dev(D) && D));
+
+            return sqr((-b + sqrt(sqr(b) + 4*a*c))/(2*a));
         }
 
         //- Return SGS kinetic energy
diff --git a/src/turbulenceModels/compressible/RAS/SpalartAllmaras/SpalartAllmaras.H b/src/turbulenceModels/compressible/RAS/SpalartAllmaras/SpalartAllmaras.H
index 9faed1215ccbda45fa7a8af497975a11900655e2..f3b83a114873c1b6586e641c24d608103d219d84 100644
--- a/src/turbulenceModels/compressible/RAS/SpalartAllmaras/SpalartAllmaras.H
+++ b/src/turbulenceModels/compressible/RAS/SpalartAllmaras/SpalartAllmaras.H
@@ -33,7 +33,7 @@ Description
         "A One-Equation Turbulence Model for Aerodynamic Flows"
         P.R. Spalart,
         S.R. Allmaras,
-        La Recherche A´rospatiale, No. 1, 1994, pp. 5–21.
+        La Recherche Aerospatiale, No. 1, 1994, pp. 5-21.
 
         Extended according to:
 
diff --git a/src/turbulenceModels/incompressible/RAS/SpalartAllmaras/SpalartAllmaras.H b/src/turbulenceModels/incompressible/RAS/SpalartAllmaras/SpalartAllmaras.H
index f3104787abdf34e4e1db950e667be215a7fd7bb9..fbd1248181036cdf5116a3ab4d6d1cdd2a103039 100644
--- a/src/turbulenceModels/incompressible/RAS/SpalartAllmaras/SpalartAllmaras.H
+++ b/src/turbulenceModels/incompressible/RAS/SpalartAllmaras/SpalartAllmaras.H
@@ -33,7 +33,7 @@ Description
         "A One-Equation Turbulence Model for Aerodynamic Flows"
         P.R. Spalart,
         S.R. Allmaras,
-        La Recherche A´rospatiale, No. 1, 1994, pp. 5–21.
+        La Recherche Aerospatiale, No. 1, 1994, pp. 5-21.
 
         Extended according to:
 
diff --git a/tutorials/Alltest b/tutorials/Alltest
index 8d8790a58de3a86b4f0568e3d33505dd23cf4bae..63a70167c681de5e7b6c601a29167eb0ccc91e8e 100755
--- a/tutorials/Alltest
+++ b/tutorials/Alltest
@@ -39,6 +39,7 @@ usage()
 usage: ${0##*/} [OPTION]
 
 options:
+  -root <dir>       specify root folder to run tests from
   -default          sets up a default scheme on all schemes
   -help             print the usage
 
@@ -52,16 +53,22 @@ USAGE
 
 unset DEFAULT_SCHEMES
 
+ROOT="./"
+
 # parse options
 while [ "$#" -gt 0 ]
 do
     case "$1" in
+    -r | -root)
+        [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
+        ROOT="$2"
+        shift
+        ;;
     -h | -help)
         usage
         ;;
     -d | -default)
         DEFAULT_SCHEMES=true
-        shift
         ;;
     -*)
         usage "unknown option: '$*'"
@@ -70,6 +77,7 @@ do
         break
         ;;
     esac
+    shift
 done
 
 
@@ -123,7 +131,7 @@ done
 [ -f "$MAIN_CONTROL_DICT" ] || usage "main controlDict not found"
 
 
-TUTORIALS_DIR=.
+TUTORIALS_DIR=$ROOT
 TEST_RUN_DIR=../tutorialsTest
 FV_SCHEMES=\
 " \
@@ -198,8 +206,10 @@ then
     done
 fi
 
+cp -f $FOAM_TUTORIALS/Allrun .
 ./Allrun
 
+
 sed -e :a -e '/\\$/N; s/\\\n//; ta' Allrun > temp
 APPLICATIONS=\
     `grep "applications=" temp | sed 's/applications=\"\([A-Za-z \t]*\)\"/\1/g'`
diff --git a/tutorials/heatTransfer/chtMultiRegionFoam/multiRegionHeater/constant/heater/solidThermophysicalProperties b/tutorials/heatTransfer/chtMultiRegionFoam/multiRegionHeater/constant/heater/solidThermophysicalProperties
index eff5806ae739a5cbcf1fbebeae6746eb799fafd1..ec1061eb2d75128ea53cbeefe2007fbca7971dd3 100644
--- a/tutorials/heatTransfer/chtMultiRegionFoam/multiRegionHeater/constant/heater/solidThermophysicalProperties
+++ b/tutorials/heatTransfer/chtMultiRegionFoam/multiRegionHeater/constant/heater/solidThermophysicalProperties
@@ -136,7 +136,7 @@ charCoeffs
     thermodynamics
     {
         Hf      0;
-        C0      611.0;; // Cp = C0*(T/Tref)^n0
+        C0      611.0; // Cp = C0*(T/Tref)^n0
         Tref    300;
         n0      1.31;
     }
diff --git a/tutorials/heatTransfer/chtMultiRegionFoam/multiRegionLiquidHeater/constant/heater/solidThermophysicalProperties b/tutorials/heatTransfer/chtMultiRegionFoam/multiRegionLiquidHeater/constant/heater/solidThermophysicalProperties
index d169d6aebd448345872055f1978d8b46156e1b8d..b345dace24db64ade62003bc906fb1bb296eec67 100644
--- a/tutorials/heatTransfer/chtMultiRegionFoam/multiRegionLiquidHeater/constant/heater/solidThermophysicalProperties
+++ b/tutorials/heatTransfer/chtMultiRegionFoam/multiRegionLiquidHeater/constant/heater/solidThermophysicalProperties
@@ -141,7 +141,7 @@ charCoeffs
     thermodynamics
     {
         Hf      0;
-        C0      611.0;; // Cp = C0*(T/Tref)^n0
+        C0      611.0; // Cp = C0*(T/Tref)^n0
         Tref    300;
         n0      1.31;
     }
diff --git a/tutorials/heatTransfer/chtMultiRegionFoam/snappyMultiRegionHeater/constant/heater/solidThermophysicalProperties b/tutorials/heatTransfer/chtMultiRegionFoam/snappyMultiRegionHeater/constant/heater/solidThermophysicalProperties
index fdad307ca23e8469f208d548814d50cb15357c39..54ca602eee896e1a52b8f963df4b96964d7891b3 100644
--- a/tutorials/heatTransfer/chtMultiRegionFoam/snappyMultiRegionHeater/constant/heater/solidThermophysicalProperties
+++ b/tutorials/heatTransfer/chtMultiRegionFoam/snappyMultiRegionHeater/constant/heater/solidThermophysicalProperties
@@ -136,7 +136,7 @@ charCoeffs
     thermodynamics
     {
         Hf      0;
-        C0      611.0;; // Cp = C0*(T/Tref)^n0
+        C0      611.0; // Cp = C0*(T/Tref)^n0
         Tref    300;
         n0      1.31;
     }
diff --git a/tutorials/heatTransfer/chtMultiRegionSimpleFoam/multiRegionHeater/Allclean b/tutorials/heatTransfer/chtMultiRegionSimpleFoam/multiRegionHeater/Allclean
index 01acce567027f86bc81805aefd0daaa43cd52369..0ff2d80fa23c022c97cf87fdf526e56aecc71558 100755
--- a/tutorials/heatTransfer/chtMultiRegionSimpleFoam/multiRegionHeater/Allclean
+++ b/tutorials/heatTransfer/chtMultiRegionSimpleFoam/multiRegionHeater/Allclean
@@ -18,5 +18,6 @@ rm -rf constant/topAir/polyMesh
 rm -rf constant/heater/polyMesh
 rm -rf constant/leftSolid/polyMesh
 rm -rf constant/rightSolid/polyMesh
+rm -rf topAir_maxX topAir_minX
 
 # ----------------------------------------------------------------- end-of-file
diff --git a/tutorials/heatTransfer/chtMultiRegionSimpleFoam/multiRegionHeater/system/controlDict b/tutorials/heatTransfer/chtMultiRegionSimpleFoam/multiRegionHeater/system/controlDict
index 4b163dd8614c90456f23e4b4c532a42bf52c4f9a..3c2b0204f2db0a35d0e0dfc75d305fa3d31b1498 100644
--- a/tutorials/heatTransfer/chtMultiRegionSimpleFoam/multiRegionHeater/system/controlDict
+++ b/tutorials/heatTransfer/chtMultiRegionSimpleFoam/multiRegionHeater/system/controlDict
@@ -45,4 +45,74 @@ timePrecision   6;
 
 runTimeModifiable true;
 
+functions
+{
+    topAir_minX
+    {
+        type            faceSource;
+        functionObjectLibs ("libfieldFunctionObjects.so");
+
+        enabled         true;
+        outputControl   outputTime;
+
+        region          topAir;
+
+        // Output to log&file (true) or to file only
+        log             true;
+
+        // Output field values as well
+        valueOutput     false;  //true;
+
+        // Type of source: patch/faceZone/sampledSurface
+        source          patch;
+
+        // if patch or faceZone: name of patch or faceZone
+        sourceName      minX;
+
+        // Operation: areaAverage/sum/weightedAverage ...
+        operation       areaIntegrate;
+
+        fields
+        (
+            p
+            phi         // surface fields not supported for sampledSurface
+            U
+        );
+    }
+
+    topAir_maxX
+    {
+        type            faceSource;
+        functionObjectLibs ("libfieldFunctionObjects.so");
+
+        enabled         true;
+        outputControl   outputTime;
+
+        region          topAir;
+
+        // Output to log&file (true) or to file only
+        log             true;
+
+        // Output field values as well
+        valueOutput     false;  //true;
+
+        // Type of source: patch/faceZone/sampledSurface
+        source          patch;
+
+        // if patch or faceZone: name of patch or faceZone
+        sourceName      maxX;
+
+        // Operation: areaAverage/sum/weightedAverage ...
+        operation       areaIntegrate;
+
+        fields
+        (
+            p
+            phi         // surface fields not supported for sampledSurface
+            U
+        );
+    }
+
+}
+
 // ************************************************************************* //
diff --git a/tutorials/heatTransfer/chtMultiRegionSimpleFoam/multiRegionHeaterRadiation/constant/heater/solidThermophysicalProperties b/tutorials/heatTransfer/chtMultiRegionSimpleFoam/multiRegionHeaterRadiation/constant/heater/solidThermophysicalProperties
index 4921a907f14899a6520fbcab5a595848935769e5..004cda2c14a96c9419875792f52993a330bbcf8c 100644
--- a/tutorials/heatTransfer/chtMultiRegionSimpleFoam/multiRegionHeaterRadiation/constant/heater/solidThermophysicalProperties
+++ b/tutorials/heatTransfer/chtMultiRegionSimpleFoam/multiRegionHeaterRadiation/constant/heater/solidThermophysicalProperties
@@ -141,7 +141,7 @@ charCoeffs
     thermodynamics
     {
         Hf      0;
-        C0      611.0;; // Cp = C0*(T/Tref)^n0
+        C0      611.0; // Cp = C0*(T/Tref)^n0
         Tref    300;
         n0      1.31;
     }
diff --git a/tutorials/incompressible/pisoFoam/les/motorBike/lesFiles/fvSolution b/tutorials/incompressible/pisoFoam/les/motorBike/lesFiles/fvSolution
index b9746715211f160ea595414c9fe836b06a7a0983..c8105e447dce84705f3eeada89e3c056ba9863cd 100644
--- a/tutorials/incompressible/pisoFoam/les/motorBike/lesFiles/fvSolution
+++ b/tutorials/incompressible/pisoFoam/les/motorBike/lesFiles/fvSolution
@@ -105,8 +105,8 @@ PIMPLE
 
 relaxationFactors
 {
-    U               1;
-    nuTilda         1;
+    "U.*"               1;
+    "nuTilda.*"         1;
 }
 
 
diff --git a/tutorials/multiphase/interDyMFoam/ras/floatingObject/system/fvSolution b/tutorials/multiphase/interDyMFoam/ras/floatingObject/system/fvSolution
index 570725e73782db0c77a19e2a78dd52a92ed698db..c93b34506bf660eb43f6f13df73ecc48be3a00c9 100644
--- a/tutorials/multiphase/interDyMFoam/ras/floatingObject/system/fvSolution
+++ b/tutorials/multiphase/interDyMFoam/ras/floatingObject/system/fvSolution
@@ -128,7 +128,7 @@ relaxationFactors
     }
     equations
     {
-        "(U|k|epsilon|omega|R|nuTilda)" 1;
+        "(U|k|epsilon|omega|R|nuTilda).*" 1;
     }
 }
 
diff --git a/tutorials/multiphase/interFoam/ras/damBreakPorousBaffle/system/fvSolution b/tutorials/multiphase/interFoam/ras/damBreakPorousBaffle/system/fvSolution
index 8ae8ee05ae7e45479d2b8de9d51c589159b2fa8a..97d24d6130ffd7e01954d2f82a1b8dc7b376b8d8 100644
--- a/tutorials/multiphase/interFoam/ras/damBreakPorousBaffle/system/fvSolution
+++ b/tutorials/multiphase/interFoam/ras/damBreakPorousBaffle/system/fvSolution
@@ -68,11 +68,11 @@ PIMPLE
     cAlpha          2;
 }
 
-relaxation
+relaxationFactors
 {
-    U           1;
-    k           1;
-    epsilon     1;
+    "U.*"           1;
+    "k.*"           1;
+    "epsilon.*"     1;
 }
 
 // ************************************************************************* //
diff --git a/wmake/rules/linuxARM7Gcc/c b/wmake/rules/linuxARM7Gcc/c
new file mode 100644
index 0000000000000000000000000000000000000000..5be3206f843bba17a0e86f7a1c1b60093fc882be
--- /dev/null
+++ b/wmake/rules/linuxARM7Gcc/c
@@ -0,0 +1,16 @@
+.SUFFIXES: .c .h
+
+cWARN        = -Wall
+
+cc          = gcc
+
+include $(RULES)/c$(WM_COMPILE_OPTION)
+
+cFLAGS      = $(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 --add-needed -Xlinker -z -Xlinker nodefs
diff --git a/wmake/rules/linuxARM7Gcc/c++ b/wmake/rules/linuxARM7Gcc/c++
new file mode 100644
index 0000000000000000000000000000000000000000..10d6b9cb33051e819e125c045ed80fc6fd453fdd
--- /dev/null
+++ b/wmake/rules/linuxARM7Gcc/c++
@@ -0,0 +1,21 @@
+.SUFFIXES: .C .cxx .cc .cpp
+
+c++WARN     = -Wall -Wextra -Wno-unused-parameter -Wold-style-cast
+
+CC          = g++
+
+include $(RULES)/c++$(WM_COMPILE_OPTION)
+
+ptFLAGS     = -DNoRepository -ftemplate-depth-100
+
+c++FLAGS    = $(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 -Xlinker --add-needed -Xlinker --no-as-needed
+LINKEXE     = $(CC) $(c++FLAGS) -Xlinker --add-needed -Xlinker --no-as-needed
diff --git a/wmake/rules/linuxARM7Gcc/c++Debug b/wmake/rules/linuxARM7Gcc/c++Debug
new file mode 100644
index 0000000000000000000000000000000000000000..19bdb9c3346fc7a69380dfedd6e7911fe220a965
--- /dev/null
+++ b/wmake/rules/linuxARM7Gcc/c++Debug
@@ -0,0 +1,2 @@
+c++DBUG    = -ggdb3 -DFULLDEBUG
+c++OPT      = -O0 -fdefault-inline
diff --git a/wmake/rules/linuxARM7Gcc/c++Opt b/wmake/rules/linuxARM7Gcc/c++Opt
new file mode 100644
index 0000000000000000000000000000000000000000..f671fe305b15167af342f2241bad4947ca84ba72
--- /dev/null
+++ b/wmake/rules/linuxARM7Gcc/c++Opt
@@ -0,0 +1,3 @@
+c++DBUG     =
+#c++OPT      = -O3 -floop-optimize -falign-loops -falign-labels -falign-functions -falign-jumps -mcpu=cortex-a9 -mfpu=vfpv3-d16 -mfloat-abi=hard
+c++OPT      = -O3 -floop-optimize -falign-loops -falign-labels -falign-functions -falign-jumps -mcpu=cortex-a9 -mfpu=vfpv3-d16 -mcpu=cortex-a9 -mfpu=vfpv3-d16 -mfloat-abi=softfp
diff --git a/wmake/rules/linuxARM7Gcc/c++Prof b/wmake/rules/linuxARM7Gcc/c++Prof
new file mode 100644
index 0000000000000000000000000000000000000000..3bda4dad55e898a8198f6e8bfe21e8d829d7230a
--- /dev/null
+++ b/wmake/rules/linuxARM7Gcc/c++Prof
@@ -0,0 +1,2 @@
+c++DBUG    = -pg
+c++OPT     = -O2
diff --git a/wmake/rules/linuxARM7Gcc/cDebug b/wmake/rules/linuxARM7Gcc/cDebug
new file mode 100644
index 0000000000000000000000000000000000000000..72b638f458220e329d52b59e3566a3c807101f9d
--- /dev/null
+++ b/wmake/rules/linuxARM7Gcc/cDebug
@@ -0,0 +1,2 @@
+cDBUG       = -ggdb -DFULLDEBUG
+cOPT        = -O1 -fdefault-inline -finline-functions
diff --git a/wmake/rules/linuxARM7Gcc/cOpt b/wmake/rules/linuxARM7Gcc/cOpt
new file mode 100644
index 0000000000000000000000000000000000000000..7679006dd398ef4ba314ab907f5c4fe344aa60ce
--- /dev/null
+++ b/wmake/rules/linuxARM7Gcc/cOpt
@@ -0,0 +1,3 @@
+cDBUG       =
+#cOPT        = -O3 -floop-optimize -falign-loops -falign-labels -falign-functions -falign-jumps -mcpu=cortex-a9 -mfpu=vfpv3-d16 -mfloat-abi=hard
+cOPT        = -O3 -floop-optimize -falign-loops -falign-labels -falign-functions -falign-jumps -mcpu=cortex-a9 -mfpu=vfpv3-d16 -mcpu=cortex-a9 -mfpu=vfpv3-d16 -mfloat-abi=softfp
diff --git a/wmake/rules/linuxARM7Gcc/cProf b/wmake/rules/linuxARM7Gcc/cProf
new file mode 100644
index 0000000000000000000000000000000000000000..ca3ac9bf5f0cd61fe99e0f05fa1bd4bdf9fa6cf7
--- /dev/null
+++ b/wmake/rules/linuxARM7Gcc/cProf
@@ -0,0 +1,2 @@
+cDBUG       = -pg
+cOPT        = -O2
diff --git a/wmake/rules/linuxARM7Gcc/general b/wmake/rules/linuxARM7Gcc/general
new file mode 100644
index 0000000000000000000000000000000000000000..376c6148463e5a83766e9f1882812d1c9b3e27f6
--- /dev/null
+++ b/wmake/rules/linuxARM7Gcc/general
@@ -0,0 +1,9 @@
+CPP        = cpp -traditional-cpp $(GFLAGS)
+LD         = ld
+
+PROJECT_LIBS = -l$(WM_PROJECT) -ldl
+
+include $(GENERAL_RULES)/standard
+
+include $(RULES)/c
+include $(RULES)/c++
diff --git a/wmake/rules/linuxARM7Gcc/mplibHPMPI b/wmake/rules/linuxARM7Gcc/mplibHPMPI
new file mode 100644
index 0000000000000000000000000000000000000000..8aff40632bd23af9607d63c4eb675a8de0cd287c
--- /dev/null
+++ b/wmake/rules/linuxARM7Gcc/mplibHPMPI
@@ -0,0 +1,3 @@
+PFLAGS     =
+PINC       = -I$(MPI_ARCH_PATH)/include -D_MPICC_H
+PLIBS      = -L$(MPI_ARCH_PATH)/lib/linux_ia32 -lmpi