From 3efb4ebe20152c396f7fe25c5a9debe4c6c5db8d Mon Sep 17 00:00:00 2001
From: mattijs <mattijs@hunt.opencfd.co.uk>
Date: Tue, 21 Oct 2008 15:04:18 +0100
Subject: [PATCH] merge from master

---
 .../test/DynamicList/DynamicListTest.C        | 50 +++++++++++--
 applications/test/xfer/xferListTest.C         | 32 ++++++---
 etc/settings.csh                              |  2 +-
 etc/settings.sh                               |  2 +-
 .../HashTables/HashTable/HashTable.C          |  2 +-
 .../StaticHashTable/StaticHashTable.C         |  2 +-
 .../Lists/CompactListList/CompactListList.C   |  2 +-
 .../Lists/DynamicList/DynamicList.H           | 48 ++++++-------
 .../Lists/DynamicList/DynamicListI.H          | 54 +++++++-------
 src/OpenFOAM/containers/Lists/List/List.C     |  5 +-
 .../containers/Lists/PackedList/PackedList.C  |  2 +-
 .../containers/Lists/PtrList/PtrList.C        |  2 +-
 .../Lists/SortableList/SortableList.C         |  4 +-
 src/OpenFOAM/containers/Lists/UList/UList.C   |  2 +-
 .../containers/Lists/UPtrList/UPtrList.C      |  2 +-
 src/OpenFOAM/db/IOobjects/IOField/IOField.C   | 19 +++++
 src/OpenFOAM/db/IOobjects/IOField/IOField.H   |  7 +-
 src/OpenFOAM/db/IOobjects/IOList/IOList.C     | 19 +++++
 src/OpenFOAM/db/IOobjects/IOList/IOList.H     |  3 +
 src/OpenFOAM/db/IOobjects/IOMap/IOMap.C       | 19 +++++
 src/OpenFOAM/db/IOobjects/IOMap/IOMap.H       |  7 +-
 .../db/IOobjects/IOPtrList/IOPtrList.C        | 19 +++++
 .../db/IOobjects/IOPtrList/IOPtrList.H        |  3 +
 .../DimensionedField/DimensionedField.C       | 35 ++++++++--
 .../DimensionedField/DimensionedField.H       | 15 +++-
 .../FieldFields/FieldField/FieldField.H       |  1 +
 src/OpenFOAM/fields/Fields/Field/Field.C      | 21 ++++++
 src/OpenFOAM/fields/Fields/Field/Field.H      | 10 +++
 src/OpenFOAM/memory/xfer/xfer.H               | 70 +++++++++++--------
 src/OpenFOAM/memory/xfer/xferI.H              |  8 +--
 src/OpenFOAM/meshes/MeshObject/MeshObject.C   | 47 ++++++++++++-
 src/OpenFOAM/meshes/MeshObject/MeshObject.H   | 34 ++++++++-
 src/OpenFOAM/meshes/polyMesh/polyMesh.H       | 43 ++++++++++++
 .../meshes/polyMesh/polyMeshInitMesh.C        |  6 ++
 .../meshes/primitiveMesh/primitiveMesh.C      | 58 +++++++++------
 .../meshes/primitiveMesh/primitiveMesh.H      | 11 +++
 src/conversion/meshReader/calcPointCells.C    | 20 ++----
 src/conversion/meshReader/meshReader.C        |  2 +-
 src/conversion/meshReader/meshReader.H        |  7 --
 src/finiteVolume/fvMesh/fvMesh.H              | 26 ++++++-
 .../schemes/quadraticFit/quadraticFit.H       | 13 +++-
 .../schemes/quadraticFit/quadraticFitData.C   | 28 +++-----
 .../schemes/quadraticFit/quadraticFitData.H   | 24 ++++---
 wmake/wmakeScheduler                          | 20 +-----
 44 files changed, 585 insertions(+), 221 deletions(-)

diff --git a/applications/test/DynamicList/DynamicListTest.C b/applications/test/DynamicList/DynamicListTest.C
index 0233dbd4745..6cdbb84890f 100644
--- a/applications/test/DynamicList/DynamicListTest.C
+++ b/applications/test/DynamicList/DynamicListTest.C
@@ -43,20 +43,58 @@ int main(int argc, char *argv[])
     ldl[0](3) = 3;
     ldl[0](1) = 1;
 
-    ldl[1](0) = 1;
-    ldl[1](1) = 2;
+    ldl[0].setSize(5);     // increase allocated size
+    ldl[1].setSize(10);    // increase allocated size
+    ldl[1](2) = 2;
 
     ldl[1] = 3;
 
-    Info<< ldl[1];
+    Info<< "<ldl>" << ldl << "</ldl>" << nl << "sizes: ";
+    forAll(ldl, i)
+    {
+        Info<< " " << ldl[i].size() << "/" << ldl[i].allocSize();
+    }
+    Info<< endl;
 
     List<List<label> > ll(2);
-    ll[0].transfer(ldl[0].shrink());
+    ll[0].transfer(ldl[0]);
     ll[1].transfer(ldl[1].shrink());
 
-    Info<< ll << endl;
+    Info<< "<ldl>" << ldl << "</ldl>" << nl << "sizes: ";
+    forAll(ldl, i)
+    {
+        Info<< " " << ldl[i].size() << "/" << ldl[i].allocSize();
+    }
+    Info<< endl;
+
+    Info<< "<ll>" << ll << "</ll>" << nl << endl;
+
+
+    // test the transfer between DynamicLists
+    DynamicList<label, 1, 0> dlA;
+    DynamicList<label, 1, 0> dlB;
+
+    for (label i = 0; i < 5; i++)
+    {
+        dlA.append(i);
+    }
+    dlA.setSize(10);
+
+    Info<< "<dlA>" << dlA << "</dlA>" << nl << "sizes: "
+        << " " << dlA.size() << "/" << dlA.allocSize() << endl;
+
+    dlB.transfer(dlA);
+
+    // provokes memory error if previous transfer did not maintain
+    // the correct allocated space
+    dlB[6] = 6;
+
+    Info<< "Transferred to dlB" << endl;
+    Info<< "<dlA>" << dlA << "</dlA>" << nl << "sizes: "
+        << " " << dlA.size() << "/" << dlA.allocSize() << endl;
+    Info<< "<dlB>" << dlB << "</dlB>" << nl << "sizes: "
+        << " " << dlB.size() << "/" << dlB.allocSize() << endl;
 
-    Info << "\nEnd\n" << endl;
 
     return 0;
 }
diff --git a/applications/test/xfer/xferListTest.C b/applications/test/xfer/xferListTest.C
index 6fce6b2bd0e..0089569394c 100644
--- a/applications/test/xfer/xferListTest.C
+++ b/applications/test/xfer/xferListTest.C
@@ -52,34 +52,48 @@ int main(int argc, char *argv[])
     Info<< "lstA: " << lstA << endl;
     Info<< "lstC: " << lstC << endl;
 
-    xfer<List<label> > xA(lstA, true);
+    xfer<List<label> > xA = xferMove(lstA);
     xfer<List<label> > xB;
 
-//    List<label> lstB( xferTmp(List<label>, lstC) );
-//    List<label> lstB( xfer<List<label> >(lstC) );
     List<label> lstB( xA );
 
-    Info<< "xA: " << *xA << endl;
-    Info<< "xB: " << *xB << endl;
+    Info<< "xA: " << xA() << endl;
+    Info<< "xB: " << xB() << endl;
     Info<< "lstA: " << lstA << endl;
     Info<< "lstB: " << lstB << endl;
     Info<< "lstC: " << lstC << endl;
 
     xA = lstB;
 
-    Info<< "xA: " << *xA << endl;
-    Info<< "xB: " << *xB << endl;
+    Info<< "xA: " << xA() << endl;
+    Info<< "xB: " << xB() << endl;
     Info<< "lstA: " << lstA << endl;
     Info<< "lstB: " << lstB << endl;
     Info<< "lstC: " << lstC << endl;
 
     xB = xA;
+    
+    List<label> lstD(xferCopy(lstC));
+    List<label> lstE(xferMove(lstC));
+    
+    // this must be empty
+    List<label> lstF = xferCopy(lstC);
 
-    Info<< "xA: " << *xA << endl;
-    Info<< "xB: " << *xB << endl;
+    Info<< "xA: " << xA() << endl;
+    Info<< "xB: " << xB() << endl;
     Info<< "lstA: " << lstA << endl;
     Info<< "lstB: " << lstB << endl;
     Info<< "lstC: " << lstC << endl;
+    Info<< "lstD: " << lstD << endl;
+    Info<< "lstE: " << lstE << endl;
+    Info<< "lstF: " << lstF << endl;
+
+    Info<< "xB size: " << xB->size() << endl;
+
+    // clear the underlying List
+    xB->clear();
+
+    Info<< "xB size: " << xB->size() << endl;
 
     return 0;
 }
diff --git a/etc/settings.csh b/etc/settings.csh
index 1958e71787a..0a38b78f6a0 100644
--- a/etc/settings.csh
+++ b/etc/settings.csh
@@ -121,7 +121,7 @@ unset MPI_ARCH_PATH
 
 switch ("$WM_MPLIB")
 case OPENMPI:
-    set mpi_version=openmpi-1.2.6
+    set mpi_version=openmpi-1.2.8
     setenv MPI_HOME $WM_THIRD_PARTY_DIR/$mpi_version
     setenv MPI_ARCH_PATH $MPI_HOME/platforms/$WM_OPTIONS
 
diff --git a/etc/settings.sh b/etc/settings.sh
index 133137d3a4f..6519bd9682b 100644
--- a/etc/settings.sh
+++ b/etc/settings.sh
@@ -151,7 +151,7 @@ unset MPI_ARCH_PATH
 
 case "$WM_MPLIB" in
 OPENMPI)
-    mpi_version=openmpi-1.2.6
+    mpi_version=openmpi-1.2.8
     export MPI_HOME=$WM_THIRD_PARTY_DIR/$mpi_version
     export MPI_ARCH_PATH=$MPI_HOME/platforms/$WM_OPTIONS
 
diff --git a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C
index 676d579bb8f..d9d74fd1ad4 100644
--- a/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C
+++ b/src/OpenFOAM/containers/HashTables/HashTable/HashTable.C
@@ -93,7 +93,7 @@ HashTable<T, Key, Hash>::HashTable(const xfer<HashTable<T, Key, Hash> >& ht)
     endIter_(*this, NULL, 0),
     endConstIter_(*this, NULL, 0)
 {
-    transfer(*ht);
+    transfer(ht());
 }
 
 
diff --git a/src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTable.C b/src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTable.C
index 688abd467dc..c4afe4c0443 100644
--- a/src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTable.C
+++ b/src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTable.C
@@ -90,7 +90,7 @@ StaticHashTable<T, Key, Hash>::StaticHashTable
     endIter_(*this, 0, 0),
     endConstIter_(*this, 0, 0)
 {
-    transfer(*ht);
+    transfer(ht());
 }
 
 
diff --git a/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.C b/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.C
index 1f683d98a52..614bcc08f13 100644
--- a/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.C
+++ b/src/OpenFOAM/containers/Lists/CompactListList/CompactListList.C
@@ -95,7 +95,7 @@ CompactListList<T>::CompactListList(const UList<label>& rowSizes, const T& t)
 template<class T>
 CompactListList<T>::CompactListList(const xfer<CompactListList<T> >& lst)
 {
-    transfer(*lst);
+    transfer(lst());
 }
 
 template<class T>
diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H
index 3891ad0ea8e..214c7806200 100644
--- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H
+++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicList.H
@@ -115,39 +115,36 @@ public:
 
         // Access
 
-            //- Size of the underlying storage.
-            inline label allocSize() const;
+        //- Size of the underlying storage.
+        inline label allocSize() const;
 
 
         // Edit
 
-            //- Alter the list size.
-            //  When the new size is greater than the addressed list size, the
-            //  allocated list sizes is adjusted and the
-            //  addressed size does not change.
-            //  Otherwise the addressed list size is just reduced and the
-            //  allocated size does not change.
-            inline void setSize(const label);
+        //- Alter the list size.
+        //  When the new size is greater than the addressed list size, the
+        //  allocated list sizes is adjusted and the
+        //  addressed size does not change.
+        //  Otherwise the addressed list size is just reduced and the
+        //  allocated size does not change.
+        inline void setSize(const label);
 
-            //- Clear the list, i.e. set the size to zero.
-            //  Allocated size does not change
-            inline void clear();
+        //- Clear the list, i.e. set the size to zero.
+        //  Allocated size does not change
+        inline void clear();
 
-            //- Clear the list and delete storage.
-            inline void clearStorage();
+        //- Clear the list and delete storage.
+        inline void clearStorage();
 
-            //- Shrink the List<T> to the number of elements used
-            inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& shrink();
+        //- Shrink the allocated space to the number of elements used.
+        //  Returns a reference to the DynamicList.
+        inline DynamicList<T, SizeInc, SizeMult, SizeDiv>& shrink();
 
-            //- Transfer the contents of the argument List into this List
-            //  and annull the argument list. Is same as List::transfer except
-            //  checks that you're not changing the underlying list to something
-            //  smaller than allocSize_.
-            inline void transfer(List<T>&);
+        //- Transfer contents of the argument List into this DynamicList
+        inline void transfer(List<T>&);
 
-            //- Transfer the contents of the argument DynamicList into this
-            //  DynamicList and annull the argument list.
-            inline void transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>&);
+        //- Transfer contents of the argument DynamicList into this DynamicList
+        inline void transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>&);
 
 
     // Member Operators
@@ -158,8 +155,7 @@ public:
         //- Remove and return the top element
         inline T remove();
 
-        //- Return non-const access to an element,
-        //  resizing the list if necessary
+        //- Return non-const access to an element, resizing list if necessary
         inline T& operator()(const label);
 
         //- Assignment of all addressed entries to the given value
diff --git a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H
index 434dfcb4682..1a40bdd0acd 100644
--- a/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H
+++ b/src/OpenFOAM/containers/Lists/DynamicList/DynamicListI.H
@@ -26,7 +26,6 @@ License
 
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
-//- Construct null
 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
 inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList()
 :
@@ -37,7 +36,6 @@ inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList()
 }
 
 
-//- Construct given size
 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
 inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList
 (
@@ -51,15 +49,14 @@ inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList
 }
 
 
-//- Construct given size
 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
 inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList
 (
-    const UList<T>& s
+    const UList<T>& lst
 )
 :
-    List<T>(s),
-    allocSize_(s.size())
+    List<T>(lst),
+    allocSize_(lst.size())
 {}
 
 
@@ -114,31 +111,24 @@ template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
 inline Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>&
 Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::shrink()
 {
-    allocSize_ = List<T>::size();
-    List<T>::setSize(allocSize_);
+    if (allocSize_ > List<T>::size())
+    {
+        allocSize_ = List<T>::size();
+        // force re-allocation/copying in List<T>::setSize() by temporarily
+        // faking a larger list size that will be truncated
+        List<T>::size(allocSize_+1);
+        List<T>::setSize(allocSize_);
+    }
     return *this;
 }
 
 
 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
 inline void
-Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::transfer(List<T>& l)
+Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::transfer(List<T>& lst)
 {
-    if (l.size() < List<T>::size())
-    {
-        FatalErrorIn
-        (
-            "void DynamicList<T, SizeInc, SizeMult"
-            ", SizeDiv>::transfer(List<T>&)"
-        )   << "Cannot replace the underlying storage of this DynamicList"
-            << " of which " << List<T>::size() << " elements are used" << nl
-            << "with a List of size " << l.size() << abort(FatalError);
-    }
-    else
-    {
-        allocSize_ = l.size();
-        List<T>::transfer(l);   // take over storage
-    }
+    allocSize_ = lst.size();
+    List<T>::transfer(lst);   // take over storage, clear addressing for lst.
 }
 
 
@@ -146,11 +136,14 @@ template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
 inline void
 Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::transfer
 (
-    DynamicList<T, SizeInc, SizeMult, SizeDiv>& l
+    DynamicList<T, SizeInc, SizeMult, SizeDiv>& lst
 )
 {
-    allocSize_ = l.allocSize();
-    List<T>::transfer(l);       // take over storage. Null l.
+    // take over storage as-is (without shrink), clear addressing for lst.
+    allocSize_ = lst.allocSize_;
+    lst.allocSize_ = 0;
+
+    List<T>::transfer(static_cast<List<T>&>(lst));
 }
 
 
@@ -240,10 +233,13 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::operator=
 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
 inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::operator=
 (
-    const List<T>& l
+    const List<T>& lst
 )
 {
-    List<T>::operator=(l);
+    // make the entire storage available for the copy operation:
+    List<T>::size(allocSize_);
+
+    List<T>::operator=(lst);
     allocSize_ = List<T>::size();
 }
 
diff --git a/src/OpenFOAM/containers/Lists/List/List.C b/src/OpenFOAM/containers/Lists/List/List.C
index 02e83b011b4..d9a929f1a96 100644
--- a/src/OpenFOAM/containers/Lists/List/List.C
+++ b/src/OpenFOAM/containers/Lists/List/List.C
@@ -129,7 +129,7 @@ Foam::List<T>::List(const List<T>& a)
 template<class T>
 Foam::List<T>::List(const xfer<List<T> >& lst)
 {
-    transfer(*lst);
+    transfer(lst());
 }
 
 
@@ -430,6 +430,9 @@ template<class T>
 template<unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
 void Foam::List<T>::transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>& a)
 {
+    // shrink the allocated space to the number of elements used
+    a.shrink();
+
     if (this->v_) delete[] this->v_;
     this->size_ = a.size_;
     this->v_ = a.v_;
diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedList.C b/src/OpenFOAM/containers/Lists/PackedList/PackedList.C
index 23e72713bfe..8c31ea08544 100644
--- a/src/OpenFOAM/containers/Lists/PackedList/PackedList.C
+++ b/src/OpenFOAM/containers/Lists/PackedList/PackedList.C
@@ -57,7 +57,7 @@ PackedList<nBits>::PackedList(const PackedList<nBits>& PList)
 template<int nBits>
 PackedList<nBits>::PackedList(const xfer<PackedList<nBits> >& lst)
 {
-    transfer(*lst);
+    transfer(lst());
 }
 
 
diff --git a/src/OpenFOAM/containers/Lists/PtrList/PtrList.C b/src/OpenFOAM/containers/Lists/PtrList/PtrList.C
index 68c5d613a0b..561dff8b253 100644
--- a/src/OpenFOAM/containers/Lists/PtrList/PtrList.C
+++ b/src/OpenFOAM/containers/Lists/PtrList/PtrList.C
@@ -74,7 +74,7 @@ Foam::PtrList<T>::PtrList(const PtrList<T>& a, const CloneArg& cloneArg)
 template<class T>
 Foam::PtrList<T>::PtrList(const xfer<PtrList<T> >& lst)
 {
-    transfer(*lst);
+    transfer(lst());
 }
 
 
diff --git a/src/OpenFOAM/containers/Lists/SortableList/SortableList.C b/src/OpenFOAM/containers/Lists/SortableList/SortableList.C
index 1f3f53a165d..7ebfa9de9ef 100644
--- a/src/OpenFOAM/containers/Lists/SortableList/SortableList.C
+++ b/src/OpenFOAM/containers/Lists/SortableList/SortableList.C
@@ -45,9 +45,9 @@ template <class Type>
 Foam::SortableList<Type>::SortableList(const xfer<List<Type> >& values)
 :
     List<Type>(),
-    indices_((*values).size())
+    indices_(values->size())
 {
-    List<Type>::transfer(*values);
+    List<Type>::transfer(values());
     sort();
 }
 
diff --git a/src/OpenFOAM/containers/Lists/UList/UList.C b/src/OpenFOAM/containers/Lists/UList/UList.C
index 85ee1bb4add..c77e6bfb809 100644
--- a/src/OpenFOAM/containers/Lists/UList/UList.C
+++ b/src/OpenFOAM/containers/Lists/UList/UList.C
@@ -45,7 +45,7 @@ void Foam::UList<T>::assign(const UList<T>& a)
 {
     if (a.size_ != this->size_)
     {
-        FatalErrorIn("UList<T>::operator=(const UList<T>&)")
+        FatalErrorIn("UList<T>::assign(const UList<T>&)")
             << "ULists have different sizes: "
             << this->size_ << " " << a.size_
             << abort(FatalError);
diff --git a/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.C b/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.C
index 8a2336922ca..7321f791b85 100644
--- a/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.C
+++ b/src/OpenFOAM/containers/Lists/UPtrList/UPtrList.C
@@ -53,7 +53,7 @@ UPtrList<T>::UPtrList(const label s)
 template<class T>
 UPtrList<T>::UPtrList(const xfer<UPtrList<T> >& lst)
 {
-    transfer(*lst);
+    transfer(lst());
 }
 
 
diff --git a/src/OpenFOAM/db/IOobjects/IOField/IOField.C b/src/OpenFOAM/db/IOobjects/IOField/IOField.C
index 973f7de1c19..3e927fd3d05 100644
--- a/src/OpenFOAM/db/IOobjects/IOField/IOField.C
+++ b/src/OpenFOAM/db/IOobjects/IOField/IOField.C
@@ -87,6 +87,25 @@ Foam::IOField<Type>::IOField(const IOobject& io, const Field<Type>& f)
 }
 
 
+template<class Type>
+Foam::IOField<Type>::IOField(const IOobject& io, const xfer<Field<Type> >& f)
+:
+    regIOobject(io)
+{
+    Field<Type>::transfer(f());
+
+    if
+    (
+        io.readOpt() == IOobject::MUST_READ
+     || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
+    )
+    {
+        readStream(typeName) >> *this;
+        close();
+    }
+}
+
+
 // * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * * //
 
 template<class Type>
diff --git a/src/OpenFOAM/db/IOobjects/IOField/IOField.H b/src/OpenFOAM/db/IOobjects/IOField/IOField.H
index e42cca65db5..0cd06bdb09c 100644
--- a/src/OpenFOAM/db/IOobjects/IOField/IOField.H
+++ b/src/OpenFOAM/db/IOobjects/IOField/IOField.H
@@ -65,11 +65,14 @@ public:
         //- Construct from IOobject
         IOField(const IOobject&);
 
+        //- Construct from IOobject and size (does not set values)
+        IOField(const IOobject&, const label size);
+
         //- Construct from components
         IOField(const IOobject&, const Field<Type>&);
 
-        //- Construct from IOobject and size (does not set values)
-        IOField(const IOobject&, const label size);
+        //- Construct by transferring the Field contents
+        IOField(const IOobject&, const xfer<Field<Type> >&);
 
 
     // Destructor
diff --git a/src/OpenFOAM/db/IOobjects/IOList/IOList.C b/src/OpenFOAM/db/IOobjects/IOList/IOList.C
index 11a80cbb2ca..fc9f4498d4a 100644
--- a/src/OpenFOAM/db/IOobjects/IOList/IOList.C
+++ b/src/OpenFOAM/db/IOobjects/IOList/IOList.C
@@ -87,6 +87,25 @@ Foam::IOList<T>::IOList(const IOobject& io, const List<T>& list)
 }
 
 
+template<class T>
+Foam::IOList<T>::IOList(const IOobject& io, const xfer<List<T> >& list)
+:
+    regIOobject(io)
+{
+    List<T>::transfer(list());
+
+    if
+    (
+        io.readOpt() == IOobject::MUST_READ
+     || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
+    )
+    {
+        readStream(typeName) >> *this;
+        close();
+    }
+}
+
+
 // * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * * //
 
 template<class T>
diff --git a/src/OpenFOAM/db/IOobjects/IOList/IOList.H b/src/OpenFOAM/db/IOobjects/IOList/IOList.H
index d7ab7ec6882..1bf7f34fcc9 100644
--- a/src/OpenFOAM/db/IOobjects/IOList/IOList.H
+++ b/src/OpenFOAM/db/IOobjects/IOList/IOList.H
@@ -72,6 +72,9 @@ public:
         //- Construct from IOobject and a List
         IOList(const IOobject&, const List<T>&);
 
+        //- Construct by transferring the List contents
+        IOList(const IOobject&, const xfer<List<T> >&);
+
 
     // Destructor
 
diff --git a/src/OpenFOAM/db/IOobjects/IOMap/IOMap.C b/src/OpenFOAM/db/IOobjects/IOMap/IOMap.C
index dffbda46d6a..1c15804a4de 100644
--- a/src/OpenFOAM/db/IOobjects/IOMap/IOMap.C
+++ b/src/OpenFOAM/db/IOobjects/IOMap/IOMap.C
@@ -86,6 +86,25 @@ Foam::IOMap<T>::IOMap(const IOobject& io, const Map<T>& map)
 }
 
 
+template<class T>
+Foam::IOMap<T>::IOMap(const IOobject& io, const xfer<Map<T> >& map)
+:
+    regIOobject(io)
+{
+    Map<T>::transfer(map());
+
+    if
+    (
+        io.readOpt() == IOobject::MUST_READ
+     || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
+    )
+    {
+        readStream(typeName) >> *this;
+        close();
+    }
+}
+
+
 // * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * * //
 
 template<class T>
diff --git a/src/OpenFOAM/db/IOobjects/IOMap/IOMap.H b/src/OpenFOAM/db/IOobjects/IOMap/IOMap.H
index e2c503ae46c..dd86337f3f3 100644
--- a/src/OpenFOAM/db/IOobjects/IOMap/IOMap.H
+++ b/src/OpenFOAM/db/IOobjects/IOMap/IOMap.H
@@ -66,11 +66,14 @@ public:
         //- Construct from IOobject
         IOMap(const IOobject&);
 
+        //- Construct from IOobject and size of Map
+        IOMap(const IOobject&, const label);
+
         //- Construct from IOobject and a Map
         IOMap(const IOobject&, const Map<T>&);
 
-        //- Construct from IOobject and size of Map
-        IOMap(const IOobject&, const label);
+        //- Construct by transferring the Map contents
+        IOMap(const IOobject&, const xfer<Map<T> >&);
 
 
     // Destructor
diff --git a/src/OpenFOAM/db/IOobjects/IOPtrList/IOPtrList.C b/src/OpenFOAM/db/IOobjects/IOPtrList/IOPtrList.C
index e6fae97c275..4197a74ee9a 100644
--- a/src/OpenFOAM/db/IOobjects/IOPtrList/IOPtrList.C
+++ b/src/OpenFOAM/db/IOobjects/IOPtrList/IOPtrList.C
@@ -84,6 +84,25 @@ Foam::IOPtrList<T>::IOPtrList(const IOobject& io, const PtrList<T>& list)
 }
 
 
+template<class T>
+Foam::IOPtrList<T>::IOPtrList(const IOobject& io, const xfer<PtrList<T> >& list)
+:
+    regIOobject(io)
+{
+    PtrList<T>::transfer(list());
+
+    if
+    (
+        io.readOpt() == IOobject::MUST_READ
+     || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
+    )
+    {
+        PtrList<T>::read(readStream(typeName), INew<T>());
+        close();
+    }
+}
+
+
 // * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * * //
 
 template<class T>
diff --git a/src/OpenFOAM/db/IOobjects/IOPtrList/IOPtrList.H b/src/OpenFOAM/db/IOobjects/IOPtrList/IOPtrList.H
index 27ab0bbb5aa..cb23363c05c 100644
--- a/src/OpenFOAM/db/IOobjects/IOPtrList/IOPtrList.H
+++ b/src/OpenFOAM/db/IOobjects/IOPtrList/IOPtrList.H
@@ -73,6 +73,9 @@ public:
         //- Construct from IOobject and a PtrList
         IOPtrList(const IOobject&, const PtrList<T>&);
 
+        //- Construct by transferring the PtrList contents
+        IOPtrList(const IOobject&, const xfer<PtrList<T> >&);
+
 
     // Destructor
 
diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.C b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.C
index 67100f518ba..41e0bcf1312 100644
--- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.C
+++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.C
@@ -138,6 +138,19 @@ DimensionedField<Type, GeoMesh>::DimensionedField
 {}
 
 
+template<class Type, class GeoMesh>
+DimensionedField<Type, GeoMesh>::DimensionedField
+(
+    const xfer<DimensionedField<Type, GeoMesh> >& df
+)
+:
+    regIOobject(df(), true),
+    Field<Type>(df),
+    mesh_(df->mesh_),
+    dimensions_(df->dimensions_)
+{}
+
+
 #ifdef ConstructFromTmp
 template<class Type, class GeoMesh>
 DimensionedField<Type, GeoMesh>::DimensionedField
@@ -202,6 +215,20 @@ DimensionedField<Type, GeoMesh>::DimensionedField
 {}
 
 
+template<class Type, class GeoMesh>
+DimensionedField<Type, GeoMesh>::DimensionedField
+(
+    const word& newName,
+    const xfer<DimensionedField<Type, GeoMesh> >& df
+)
+:
+    regIOobject(IOobject(newName, df->time().timeName(), df->db())),
+    Field<Type>(df),
+    mesh_(df->mesh_),
+    dimensions_(df->dimensions_)
+{}
+
+
 #ifdef ConstructFromTmp
 template<class Type, class GeoMesh>
 DimensionedField<Type, GeoMesh>::DimensionedField
@@ -248,7 +275,7 @@ DimensionedField<Type, GeoMesh>::~DimensionedField()
 template<class Type, class GeoMesh>
 const DimensionedField<Type, GeoMesh>& DimensionedField<Type, GeoMesh>::null()
 {
-    DimensionedField<Type, GeoMesh>* nullPtr = 
+    DimensionedField<Type, GeoMesh>* nullPtr =
         reinterpret_cast<DimensionedField<Type, GeoMesh>*>(NULL);
     return *nullPtr;
 }
@@ -258,8 +285,8 @@ template<class Type, class GeoMesh>
 tmp
 <
     DimensionedField
-        <typename DimensionedField<Type, GeoMesh>::cmptType, GeoMesh> 
-> 
+        <typename DimensionedField<Type, GeoMesh>::cmptType, GeoMesh>
+>
 DimensionedField<Type, GeoMesh>::component
 (
     const direction d
@@ -315,7 +342,7 @@ void DimensionedField<Type, GeoMesh>::replace
 
 
 template<class Type, class GeoMesh>
-tmp<DimensionedField<Type, GeoMesh> > 
+tmp<DimensionedField<Type, GeoMesh> >
 DimensionedField<Type, GeoMesh>::T() const
 {
     tmp<DimensionedField<Type, GeoMesh> > result
diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H
index 8a3fbea7573..00354276724 100644
--- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H
+++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H
@@ -49,7 +49,7 @@ namespace Foam
 {
 
 // Forward declaration of friend functions and operators
- 
+
 template<class Type, class GeoMesh> class DimensionedField;
 
 template<class Type, class GeoMesh> Ostream& operator<<
@@ -156,6 +156,12 @@ public:
             bool reUse
         );
 
+        //- Construct by transferring the DimensionedField
+        DimensionedField
+        (
+            const xfer<DimensionedField<Type, GeoMesh> >&
+        );
+
         //- Construct as copy of tmp<DimensionedField> deleting argument
 #       ifdef ConstructFromTmp
         DimensionedField
@@ -186,6 +192,13 @@ public:
             bool reUse
         );
 
+        //- Construct by transferring the DimensionedField with a new name
+        DimensionedField
+        (
+            const word& newName,
+            const xfer<DimensionedField<Type, GeoMesh> >&
+        );
+
         //- Construct as copy resetting name
 #       ifdef ConstructFromTmp
         DimensionedField
diff --git a/src/OpenFOAM/fields/FieldFields/FieldField/FieldField.H b/src/OpenFOAM/fields/FieldFields/FieldField/FieldField.H
index 958e2f259be..4d7bb8552d6 100644
--- a/src/OpenFOAM/fields/FieldFields/FieldField/FieldField.H
+++ b/src/OpenFOAM/fields/FieldFields/FieldField/FieldField.H
@@ -37,6 +37,7 @@ SourceFiles
 #define FieldField_H
 
 #include "tmp.H"
+#include "xfer.H"
 #include "PtrList.H"
 #include "scalar.H"
 #include "direction.H"
diff --git a/src/OpenFOAM/fields/Fields/Field/Field.C b/src/OpenFOAM/fields/Fields/Field/Field.C
index c14b08b2b90..994f8ee6301 100644
--- a/src/OpenFOAM/fields/Fields/Field/Field.C
+++ b/src/OpenFOAM/fields/Fields/Field/Field.C
@@ -155,6 +155,13 @@ Field<Type>::Field(Field<Type>& f, bool reUse)
 {}
 
 
+template<class Type>
+Field<Type>::Field(const xfer<Field<Type> >& f)
+:
+    List<Type>(f)
+{}
+
+
 template<class Type>
 Field<Type>::Field(const typename Field<Type>::subField& sf)
 :
@@ -568,6 +575,20 @@ void Field<Type>::replace
 }
 
 
+template<class Type>
+void Field<Type>::transfer(Field<Type>& f)
+{
+    List<Type>::transfer(f);
+}
+
+
+template<class Type>
+void Field<Type>::transfer(List<Type>& lst)
+{
+    List<Type>::transfer(lst);
+}
+
+
 template<class Type>
 tmp<Field<Type> > Field<Type>::T() const
 {
diff --git a/src/OpenFOAM/fields/Fields/Field/Field.H b/src/OpenFOAM/fields/Fields/Field/Field.H
index 3c60dcf126f..8e168cb0ac9 100644
--- a/src/OpenFOAM/fields/Fields/Field/Field.H
+++ b/src/OpenFOAM/fields/Fields/Field/Field.H
@@ -43,6 +43,7 @@ SourceFiles
 #define Field_H
 
 #include "tmp.H"
+#include "xfer.H"
 #include "direction.H"
 #include "VectorSpace.H"
 #include "scalarList.H"
@@ -164,6 +165,9 @@ public:
         //- Construct as copy or re-use as specified.
         Field(Field<Type>&, bool reUse);
 
+        //- Construct by transferring the Field contents
+        Field(const xfer<Field<Type> >&);
+
         //- Construct as copy of subField
         Field(const typename Field<Type>::subField&);
 
@@ -293,6 +297,12 @@ public:
         //- Replace a component field of the field
         void replace(const direction, const cmptType&);
 
+        //- Transfer the contents of the argument Field into this Field
+        void transfer(Field<Type>&);
+
+        //- Transfer the contents of the argument List into this Field
+        void transfer(List<Type>&);
+
         //- Return the field transpose (only defined for second rank tensors)
         tmp<Field<Type> > T() const;
 
diff --git a/src/OpenFOAM/memory/xfer/xfer.H b/src/OpenFOAM/memory/xfer/xfer.H
index 45912d39a80..e13782c9f4c 100644
--- a/src/OpenFOAM/memory/xfer/xfer.H
+++ b/src/OpenFOAM/memory/xfer/xfer.H
@@ -30,7 +30,7 @@ Description
     of objects of type \<T\>.
 
     Since it is decided upon construction of the xfer object whether the
-    parameter is to be copied or transferred, the contents of resulting
+    parameter is to be copied or transferred, the contents of the resulting
     object can be transferred unconditionally.
 
     This greatly simplifies defining the constructors for other classes
@@ -39,10 +39,6 @@ Description
     The wrapped object of type \<T\> must implement a transfer() method and
     an operator=() copy method.
 
-Note
-    The macros xferCopy(T,arg) and xferMove(T,arg) can be used as
-    workarounds for passing temporaries to copy-constructors.
-
 SourceFiles
     xferI.H
 
@@ -56,6 +52,9 @@ SourceFiles
 namespace Foam
 {
 
+// Forward declaration of classes
+template<class T> class tmp;
+
 /*---------------------------------------------------------------------------*\
                            Class xfer Declaration
 \*---------------------------------------------------------------------------*/
@@ -97,52 +96,65 @@ public:
         //- Transfer the contents into the object
         inline void operator=(const xfer<T>&);
 
-        //- Return a non-const reference to const object
-        //  @sa xferCopy, xferMove macros alternatives for copy-constructors
-        inline const xfer<T>& operator()() const;
-
         //- Reference to the underlying datatype
-        inline T& operator*() const;
+        inline T& operator()() const;
+
+        //- Pointer to the underlying datatype
+        inline T* operator->() const;
 
 };
 
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
-} // End namespace Foam
-
 /**
- * @def xferCopy(T,arg)
+ * @fn template<class T> xferCopy(const T&)
  * Construct by copying the contents of the @a arg
- * and return a const reference to an xfer of type \<T\>
- *
- * Useful for constructors where the argument is temporary.
- * This is a workaround for a template resolution issue.
  *
- * @sa xferMove and Foam::xfer
+ * @sa xferMove, xferTmp and Foam::xfer
 */
-#define xferCopy(T,arg) \
-    (static_cast<const Foam::xfer< T >&>(Foam::xfer< T >(arg)()))
+template<class T>
+Foam::xfer<T> xferCopy(const T& t)
+{
+    return Foam::xfer<T>(t);
+}
+
 
 /**
- * @def xferMove(T,arg)
+ * @fn template<class T> xferMove(T&)
  * Construct by transferring the contents of the @a arg
- * and return a const reference to an xfer of type \<T\>
- *
- * Useful for constructors where the argument is temporary.
- * This is a workaround for a template resolution issue.
  *
  * @par Example Use
  * @code
  *     List<label> a;
  *     ...
- *     List<label> b(xferMove(List<label>, a));
+ *     List<label> b(xferMove(a));
  * @endcode
  *
- * @sa xferCopy and Foam::xfer
+ * @sa xferCopy, xferTmp and Foam::xfer
 */
-#define xferMove(T,arg) \
-    (static_cast<const Foam::xfer< T >&>(Foam::xfer< T >(arg, true)()))
+template<class T>
+Foam::xfer<T> xferMove(T& t)
+{
+    return Foam::xfer<T>(t, true);
+}
+
+
+/**
+ * @fn template<class T> xferTmp(tmp<T>&)
+ * Construct by transferring the contents of the @a arg
+ *
+ * @sa xferCopy, xferMove and Foam::xfer
+*/
+template<class T>
+Foam::xfer<T> xferTmp(Foam::tmp<T>& tt)
+{
+    return Foam::xfer<T>(tt(), tt.isTmp());
+}
+
+
+} // End namespace Foam
+
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
diff --git a/src/OpenFOAM/memory/xfer/xferI.H b/src/OpenFOAM/memory/xfer/xferI.H
index 8ad7ceb3aa1..55830008a98 100644
--- a/src/OpenFOAM/memory/xfer/xferI.H
+++ b/src/OpenFOAM/memory/xfer/xferI.H
@@ -98,16 +98,16 @@ inline void Foam::xfer<T>::operator=(const xfer<T>& t)
 
 
 template<class T>
-inline const Foam::xfer<T>& Foam::xfer<T>::operator()() const
+inline T& Foam::xfer<T>::operator()() const
 {
-    return *this;
+    return *ptr_;
 }
 
 
 template<class T>
-inline T& Foam::xfer<T>::operator*() const
+inline T* Foam::xfer<T>::operator->() const
 {
-    return *ptr_;
+    return ptr_;
 }
 
 // ************************************************************************* //
diff --git a/src/OpenFOAM/meshes/MeshObject/MeshObject.C b/src/OpenFOAM/meshes/MeshObject/MeshObject.C
index ba675177003..340df29e67b 100644
--- a/src/OpenFOAM/meshes/MeshObject/MeshObject.C
+++ b/src/OpenFOAM/meshes/MeshObject/MeshObject.C
@@ -65,11 +65,11 @@ const Type& Foam::MeshObject<Mesh, Type>::New
 
 
 template<class Mesh, class Type>
-template<class Data>
+template<class Data1>
 const Type& Foam::MeshObject<Mesh, Type>::New
 (
     const Mesh& mesh,
-    const Data& d
+    const Data1& d
 )
 {
     if (!mesh.db().objectRegistry::foundObject<Type>(Type::typeName))
@@ -103,6 +103,49 @@ const Type& Foam::MeshObject<Mesh, Type>::New
 }
 
 
+template<class Mesh, class Type>
+template<class Data1, class Data2, class Data3>
+const Type& Foam::MeshObject<Mesh, Type>::New
+(
+    const Mesh& mesh,
+    const Data1& d1,
+    const Data2& d2,
+    const Data3& d3
+)
+{
+    if (!mesh.db().objectRegistry::foundObject<Type>(Type::typeName))
+    {
+        return store(new Type(mesh, d1, d2, d3));
+    }
+    else
+    {
+        return mesh.db().objectRegistry::lookupObject<Type>(Type::typeName);
+    }
+}
+
+
+template<class Mesh, class Type>
+template<class Data1, class Data2, class Data3, class Data4>
+const Type& Foam::MeshObject<Mesh, Type>::New
+(
+    const Mesh& mesh,
+    const Data1& d1,
+    const Data2& d2,
+    const Data3& d3,
+    const Data4& d4
+)
+{
+    if (!mesh.db().objectRegistry::foundObject<Type>(Type::typeName))
+    {
+        return store(new Type(mesh, d3, d4));
+    }
+    else
+    {
+        return mesh.db().objectRegistry::lookupObject<Type>(Type::typeName);
+    }
+}
+
+
 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * //
 
 template<class Mesh, class Type>
diff --git a/src/OpenFOAM/meshes/MeshObject/MeshObject.H b/src/OpenFOAM/meshes/MeshObject/MeshObject.H
index ee20ccfa3e4..3bf11b5f6a3 100644
--- a/src/OpenFOAM/meshes/MeshObject/MeshObject.H
+++ b/src/OpenFOAM/meshes/MeshObject/MeshObject.H
@@ -69,11 +69,39 @@ public:
 
         static const Type& New(const Mesh& mesh);
 
-        template<class Data>
-        static const Type& New(const Mesh& mesh, const Data& d);
+        template<class Data1>
+        static const Type& New
+        (
+            const Mesh& mesh,
+            const Data1& d
+        );
 
         template<class Data1, class Data2>
-        static const Type& New(const Mesh& mesh, const Data1&, const Data2&);
+        static const Type& New
+        (
+            const Mesh& mesh,
+            const Data1&,
+            const Data2&
+        );
+
+        template<class Data1, class Data2, class Data3>
+        static const Type& New
+        (
+            const Mesh& mesh,
+            const Data1&,
+            const Data2&,
+            const Data3&
+        );
+
+        template<class Data1, class Data2, class Data3, class Data4>
+        static const Type& New
+        (
+            const Mesh& mesh,
+            const Data1&,
+            const Data2&,
+            const Data3&,
+            const Data4&
+        );
 
 
     // Destructor
diff --git a/src/OpenFOAM/meshes/polyMesh/polyMesh.H b/src/OpenFOAM/meshes/polyMesh/polyMesh.H
index b813aa7c685..d7947052164 100644
--- a/src/OpenFOAM/meshes/polyMesh/polyMesh.H
+++ b/src/OpenFOAM/meshes/polyMesh/polyMesh.H
@@ -170,6 +170,9 @@ private:
         //- Initialise the polyMesh from the given set of cells
         void initMesh(cellList& c);
 
+        //- Initialise the polyMesh from the given set of cells
+        void initMesh(const xfer<cellList>& c);
+
         //- Calculate the valid directions in the mesh from the boundaries
         void calcDirections() const;
 
@@ -226,6 +229,18 @@ public:
             const bool syncPar = true
         );
 
+        //- Construct without boundary from components.
+        //  Boundary is added using addPatches() member function
+        polyMesh
+        (
+            const IOobject& io,
+            const xfer<pointField>& points,
+            const xfer<faceList>& faces,
+            const xfer<labelList>& owner,
+            const xfer<labelList>& neighbour,
+            const bool syncPar = true
+        );
+
         //- Construct without boundary with cells rather than owner/neighbour.
         //  Boundary is added using addPatches() member function
         polyMesh
@@ -237,6 +252,17 @@ public:
             const bool syncPar = true
         );
 
+        //- Construct without boundary with cells rather than owner/neighbour.
+        //  Boundary is added using addPatches() member function
+        polyMesh
+        (
+            const IOobject& io,
+            const xfer<pointField>& points,
+            const xfer<faceList>& faces,
+            const xfer<cellList>& cells,
+            const bool syncPar = true
+        );
+
         //- Construct from cell shapes
         polyMesh
         (
@@ -444,6 +470,23 @@ public:
                 const bool validBoundary = true
             );
 
+            //- Reset mesh primitive data. Assumes all patch info correct
+            //  (so does e.g. parallel communication). If not use
+            //  validBoundary=false
+            //  (still assumes patchStarts[0] = nInternalFaces and last
+            //  patch ends at nActiveFaces) and change patches with addPatches.
+            void resetPrimitives
+            (
+                const label nUsedFaces,
+                const xfer<pointField>& points,
+                const xfer<faceList>& faces,
+                const xfer<labelList>& owner,
+                const xfer<labelList>& neighbour,
+                const labelList& patchSizes,
+                const labelList& patchStarts,
+                const bool validBoundary = true
+            );
+
 
         //  Storage management
 
diff --git a/src/OpenFOAM/meshes/polyMesh/polyMeshInitMesh.C b/src/OpenFOAM/meshes/polyMesh/polyMeshInitMesh.C
index a1cfa9c63a3..d4d74ee22da 100644
--- a/src/OpenFOAM/meshes/polyMesh/polyMeshInitMesh.C
+++ b/src/OpenFOAM/meshes/polyMesh/polyMeshInitMesh.C
@@ -155,4 +155,10 @@ void Foam::polyMesh::initMesh(cellList& c)
 }
 
 
+void Foam::polyMesh::initMesh(const xfer<cellList>& clst)
+{
+    initMesh(clst());
+}
+
+
 // ************************************************************************* //
diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.C b/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.C
index 6bcc2af56f4..fece5b2220a 100644
--- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.C
+++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.C
@@ -29,16 +29,15 @@ License
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
+// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
 namespace Foam
 {
-
-// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
-
-defineTypeNameAndDebug(primitiveMesh, 0);
+    defineTypeNameAndDebug(primitiveMesh, 0);
+}
 
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
-primitiveMesh::primitiveMesh()
+Foam::primitiveMesh::primitiveMesh()
 :
     nInternalPoints_(0),    // note: points are considered ordered on empty mesh
     nPoints_(0),
@@ -76,8 +75,8 @@ primitiveMesh::primitiveMesh()
 
 
 // Construct from components
-// WARNING: ASSUMES CORRECT ORDERING OF DATA. 
-primitiveMesh::primitiveMesh
+// WARNING: ASSUMES CORRECT ORDERING OF DATA.
+Foam::primitiveMesh::primitiveMesh
 (
     const label nPoints,
     const label nInternalFaces,
@@ -114,14 +113,12 @@ primitiveMesh::primitiveMesh
     faceCentresPtr_(NULL),
     cellVolumesPtr_(NULL),
     faceAreasPtr_(NULL)
-{
-    
-}
+{}
 
 
 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
 
-primitiveMesh::~primitiveMesh()
+Foam::primitiveMesh::~primitiveMesh()
 {
     clearOut();
 }
@@ -129,7 +126,7 @@ primitiveMesh::~primitiveMesh()
 
 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
 
-bool primitiveMesh::calcPointOrder
+bool Foam::primitiveMesh::calcPointOrder
 (
     label& nInternalPoints,
     labelList& oldToNew,
@@ -208,7 +205,7 @@ bool primitiveMesh::calcPointOrder
 }
 
 
-void primitiveMesh::reset
+void Foam::primitiveMesh::reset
 (
     const label nPoints,
     const label nInternalFaces,
@@ -264,13 +261,13 @@ void primitiveMesh::reset
 }
 
 
-void primitiveMesh::reset
+void Foam::primitiveMesh::reset
 (
     const label nPoints,
     const label nInternalFaces,
     const label nFaces,
     const label nCells,
-    cellList& c
+    cellList& clst
 )
 {
     reset
@@ -281,11 +278,32 @@ void primitiveMesh::reset
         nCells
     );
 
-    cfPtr_ = new cellList(c, true);
+    cfPtr_ = new cellList(clst, true);
 }
 
 
-tmp<scalarField> primitiveMesh::movePoints
+void Foam::primitiveMesh::reset
+(
+    const label nPoints,
+    const label nInternalFaces,
+    const label nFaces,
+    const label nCells,
+    const xfer<cellList>& clst
+)
+{
+    reset
+    (
+        nPoints,
+        nInternalFaces,
+        nFaces,
+        nCells
+    );
+
+    cfPtr_ = new cellList(clst);
+}
+
+
+Foam::tmp<Foam::scalarField> Foam::primitiveMesh::movePoints
 (
     const pointField& newPoints,
     const pointField& oldPoints
@@ -320,7 +338,7 @@ tmp<scalarField> primitiveMesh::movePoints
 }
 
 
-const cellShapeList& primitiveMesh::cellShapes() const
+const Foam::cellShapeList& Foam::primitiveMesh::cellShapes() const
 {
     if (!cellShapesPtr_)
     {
@@ -331,8 +349,4 @@ const cellShapeList& primitiveMesh::cellShapes() const
 }
 
 
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
-} // End namespace Foam
-
 // ************************************************************************* //
diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.H b/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.H
index 6f24944cbc7..6150670a7f4 100644
--- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.H
+++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.H
@@ -375,6 +375,17 @@ public:
         );
 
 
+        //- Reset this primitiveMesh given the primitive array sizes and cells
+        void reset
+        (
+            const label nPoints,
+            const label nInternalFaces,
+            const label nFaces,
+            const label nCells,
+            const xfer<cellList>& cells
+        );
+
+
         // Access
 
             // Mesh size parameters
diff --git a/src/conversion/meshReader/calcPointCells.C b/src/conversion/meshReader/calcPointCells.C
index 59d47a2f3b8..03a92afe225 100644
--- a/src/conversion/meshReader/calcPointCells.C
+++ b/src/conversion/meshReader/calcPointCells.C
@@ -30,9 +30,6 @@ Description
 
 #include "meshReader.H"
 
-// for transition - in case someone really relied on the old behaviour
-#undef LEAVE_UNUSED_POINTS
-
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 void Foam::meshReader::calcPointCells() const
@@ -46,7 +43,7 @@ void Foam::meshReader::calcPointCells() const
             << abort(FatalError);
     }
 
-    label nPoints = points().size();
+    label nPoints = points_.size();
 
     pointCellsPtr_ = new labelListList(nPoints);
     labelListList& ptCells = *pointCellsPtr_;
@@ -132,19 +129,15 @@ void Foam::meshReader::calcPointCells() const
     // report unused points
     if (nPoints > pointI)
     {
-#ifdef LEAVE_UNUSED_POINTS
-        FatalErrorIn("meshReader::calcPointCells() const")
-            << "mesh has " << (nPoints - pointI)
-            << " points that were declared but not used" << endl;
-#else
-
         Info<< "removing " << (nPoints - pointI) << " unused points" << endl;
 
         nPoints = pointI;
 
-        // adjust points and truncate
-        inplaceReorder(oldToNew, points());
-        points().setSize(nPoints);
+        // adjust points and truncate - bend const-ness
+        pointField& adjustedPoints = const_cast<pointField&>(points_);
+
+        inplaceReorder(oldToNew, adjustedPoints);
+        adjustedPoints.setSize(nPoints);
 
         // adjust pointCells and truncate
         inplaceReorder(oldToNew, ptCells);
@@ -162,7 +155,6 @@ void Foam::meshReader::calcPointCells() const
                 inplaceRenumber(oldToNew, faces[i]);
             }
         }
-#endif
     }
 }
 
diff --git a/src/conversion/meshReader/meshReader.C b/src/conversion/meshReader/meshReader.C
index 8449c93e224..d35429c8dbb 100644
--- a/src/conversion/meshReader/meshReader.C
+++ b/src/conversion/meshReader/meshReader.C
@@ -142,7 +142,7 @@ Foam::autoPtr<Foam::polyMesh> Foam::meshReader::mesh
                 "constant",
                 registry
             ),
-            points(),
+            points_,
             meshFaces_,
             cellPolys_
         )
diff --git a/src/conversion/meshReader/meshReader.H b/src/conversion/meshReader/meshReader.H
index e14ef191375..422eb6c58d3 100644
--- a/src/conversion/meshReader/meshReader.H
+++ b/src/conversion/meshReader/meshReader.H
@@ -291,13 +291,6 @@ protected:
         //- Subclasses are required to supply this information
         virtual bool readGeometry(const scalar scaleFactor = 1.0) = 0;
 
-        //- Return mesh points
-        pointField& points() const
-        {
-            return const_cast<pointField&>(points_);
-        }
-
-
 public:
 
     // Static Members
diff --git a/src/finiteVolume/fvMesh/fvMesh.H b/src/finiteVolume/fvMesh/fvMesh.H
index f28c72ad4ea..d89b92a82d1 100644
--- a/src/finiteVolume/fvMesh/fvMesh.H
+++ b/src/finiteVolume/fvMesh/fvMesh.H
@@ -180,6 +180,18 @@ public:
             const bool syncPar = true
         );
 
+        //- Construct from components without boundary.
+        //  Boundary is added using addFvPatches() member function
+        fvMesh
+        (
+            const IOobject& io,
+            const xfer<pointField>& points,
+            const xfer<faceList>& faces,
+            const xfer<labelList>& allOwner,
+            const xfer<labelList>& allNeighbour,
+            const bool syncPar = true
+        );
+
         //- Construct from components with cells rather than owner
         //  and neighbourwithout boundary.
         //  Boundary is added using addPatches() member function
@@ -192,6 +204,18 @@ public:
             const bool syncPar = true
         );
 
+        //- Construct from components with cells rather than owner
+        //  and neighbourwithout boundary.
+        //  Boundary is added using addPatches() member function
+        fvMesh
+        (
+            const IOobject& io,
+            const xfer<pointField>& points,
+            const xfer<faceList>& faces,
+            const xfer<cellList>& cells,
+            const bool syncPar = true
+        );
+
 
     // Destructor
 
@@ -295,7 +319,7 @@ public:
             virtual void updateMesh(const mapPolyMesh& mpm);
 
             //- Move points, returns volumes swept by faces in motion
-            virtual tmp<scalarField> movePoints(const vectorField&);
+            virtual tmp<scalarField> movePoints(const pointField&);
 
             //- Map all fields in time using given map.
             virtual void mapFields(const mapPolyMesh& mpm);
diff --git a/src/finiteVolume/interpolation/surfaceInterpolation/schemes/quadraticFit/quadraticFit.H b/src/finiteVolume/interpolation/surfaceInterpolation/schemes/quadraticFit/quadraticFit.H
index ff9a668f3d3..c1308c6ba3e 100644
--- a/src/finiteVolume/interpolation/surfaceInterpolation/schemes/quadraticFit/quadraticFit.H
+++ b/src/finiteVolume/interpolation/surfaceInterpolation/schemes/quadraticFit/quadraticFit.H
@@ -23,7 +23,7 @@ License
     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
 Class
-    quadraticFit
+    Foam::quadraticFit
 
 Description
     Quadratic fit interpolation scheme which applies an explicit correction to
@@ -56,8 +56,16 @@ class quadraticFit
     public linear<Type>
 {
     // Private Data
+
+        //- Factor the fit is allowed to deviate from linear.
+        //  This limits the amount of high-order correction and increases
+        //  stability on bad meshes
+        const scalar linearLimitFactor_;
+
+        //- Weights for central stencil
         const scalar centralWeight_;
 
+
     // Private Member Functions
 
         //- Disallow default bitwise copy construct
@@ -79,6 +87,7 @@ public:
         quadraticFit(const fvMesh& mesh, Istream& is)
         :
             linear<Type>(mesh),
+            linearLimitFactor_(readScalar(is)),
             centralWeight_(readScalar(is))
         {}
 
@@ -92,6 +101,7 @@ public:
         )
         :
             linear<Type>(mesh),
+            linearLimitFactor_(readScalar(is)),
             centralWeight_(readScalar(is))
         {}
 
@@ -123,6 +133,7 @@ public:
             (
                 mesh,
                 stencil,
+                linearLimitFactor_,
                 centralWeight_
             );
 
diff --git a/src/finiteVolume/interpolation/surfaceInterpolation/schemes/quadraticFit/quadraticFitData.C b/src/finiteVolume/interpolation/surfaceInterpolation/schemes/quadraticFit/quadraticFitData.C
index c5269877d8d..868d33b6f3f 100644
--- a/src/finiteVolume/interpolation/surfaceInterpolation/schemes/quadraticFit/quadraticFitData.C
+++ b/src/finiteVolume/interpolation/surfaceInterpolation/schemes/quadraticFit/quadraticFitData.C
@@ -41,16 +41,16 @@ namespace Foam
 
 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
 
-static int count = 0;
-
 Foam::quadraticFitData::quadraticFitData
 (
     const fvMesh& mesh,
     const extendedCentredStencil& stencil,
+    const scalar linearLimitFactor,
     const scalar cWeight
 )
 :
     MeshObject<fvMesh, quadraticFitData>(mesh),
+    linearLimitFactor_(linearLimitFactor),
     centralWeight_(cWeight),
 #   ifdef SPHERICAL_GEOMETRY
     dim_(2),
@@ -61,7 +61,7 @@ Foam::quadraticFitData::quadraticFitData
     (
         dim_ == 1 ? 3 :
         dim_ == 2 ? 6 :
-        dim_ == 3 ? 9 : 0
+        dim_ == 3 ? 7 : 0
     ),
     fit_(mesh.nInternalFaces())
 {
@@ -116,8 +116,6 @@ Foam::quadraticFitData::quadraticFitData
         interpPolySize[faci] = calcFit(stencilPoints[faci], faci);
     }
 
-    Pout<< "count = " << count << endl;
-
     if (debug)
     {
         Info<< "quadraticFitData::quadraticFitData() :"
@@ -243,14 +241,14 @@ Foam::label Foam::quadraticFitData::calcFit
         {
             B[ip][is++] = wts[ip]*py;
             B[ip][is++] = wts[ip]*px*py;
-            B[ip][is++] = wts[ip]*sqr(py);
+            //B[ip][is++] = wts[ip]*sqr(py);
         }
         if (dim_ == 3)
         {
             B[ip][is++] = wts[ip]*pz;
             B[ip][is++] = wts[ip]*px*pz;
             //B[ip][is++] = wts[ip]*py*pz;
-            B[ip][is++] = wts[ip]*sqr(pz);
+            //B[ip][is++] = wts[ip]*sqr(pz);
         }
     }
 
@@ -274,15 +272,15 @@ Foam::label Foam::quadraticFitData::calcFit
         //goodFit = (fit0 > 0 && fit1 > 0);
 
         goodFit =
-            (mag(fit0 - w[faci])/w[faci] < 0.15)
-         && (mag(fit1 - (1 - w[faci]))/(1 - w[faci]) < 0.15);
+            (mag(fit0 - w[faci])/w[faci] < linearLimitFactor_)
+         && (mag(fit1 - (1 - w[faci]))/(1 - w[faci]) < linearLimitFactor_);
 
         //scalar w0Err = fit0/w[faci];
         //scalar w1Err = fit1/(1 - w[faci]);
 
         //goodFit =
-        //    (w0Err > 0.5 && w0Err < 1.5)
-        // && (w1Err > 0.5 && w1Err < 1.5);
+        //    (w0Err > linearLimitFactor_ && w0Err < (1 + linearLimitFactor_))
+        // && (w1Err > linearLimitFactor_ && w1Err < (1 + linearLimitFactor_));
 
         if (goodFit)
         {
@@ -324,13 +322,6 @@ Foam::label Foam::quadraticFitData::calcFit
 
     if (goodFit)
     {
-         if ((mag(fit_[faci][0] - w[faci])/w[faci] < 0.15)
-         && (mag(fit_[faci][1] - (1 - w[faci]))/(1 - w[faci]) < 0.15))
-         {
-             count++;
-             //Pout<< "fit " << mag(fit_[faci][0] - w[faci])/w[faci] << " " << mag(fit_[faci][1] - (1 - w[faci]))/(1 - w[faci]) << endl;
-         }
-
         // scalar limiter =
         // max
         // (
@@ -358,6 +349,7 @@ Foam::label Foam::quadraticFitData::calcFit
         Pout<< "Could not fit face " << faci
             << " " << fit_[faci][0] << " " << w[faci]
             << " " << fit_[faci][1] << " " << 1 - w[faci]<< endl;
+
         fit_[faci] = 0;
     }
 
diff --git a/src/finiteVolume/interpolation/surfaceInterpolation/schemes/quadraticFit/quadraticFitData.H b/src/finiteVolume/interpolation/surfaceInterpolation/schemes/quadraticFit/quadraticFitData.H
index b44a2e4d90f..f0da60901da 100644
--- a/src/finiteVolume/interpolation/surfaceInterpolation/schemes/quadraticFit/quadraticFitData.H
+++ b/src/finiteVolume/interpolation/surfaceInterpolation/schemes/quadraticFit/quadraticFitData.H
@@ -23,7 +23,7 @@ License
     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
 Class
-    quadraticFitData
+    Foam::quadraticFitData
 
 Description
     Data for the quadratic fit correction interpolation scheme
@@ -56,13 +56,18 @@ class quadraticFitData
 {
     // Private data
 
-        //- weights for central stencil
+        //- Factor the fit is allowed to deviate from linear.
+        //  This limits the amount of high-order correction and increases
+        //  stability on bad meshes
+        const scalar linearLimitFactor_;
+
+        //- Weights for central stencil
         const scalar centralWeight_;
 
-        //- dimensionality of the geometry
+        //- Dimensionality of the geometry
         const label dim_;
 
-        //- minimum stencil size
+        //- Minimum stencil size
         const label minSize_;
 
         //- For each cell in the mesh store the values which multiply the
@@ -96,19 +101,18 @@ public:
         (
             const fvMesh& mesh,
             const extendedCentredStencil& stencil,
-            scalar cWeightDim
+            const scalar linearLimitFactor,
+            const scalar centralWeight
         );
 
 
-    // Destructor
-
-        virtual ~quadraticFitData()
-        {}
+    //- Destructor
+    virtual ~quadraticFitData()
+    {}
 
 
     // Member functions
 
-
         //- Return reference to fit coefficients
         const List<scalarList>& fit() const
         {
diff --git a/wmake/wmakeScheduler b/wmake/wmakeScheduler
index a4c88624abc..17a7a2b7485 100755
--- a/wmake/wmakeScheduler
+++ b/wmake/wmakeScheduler
@@ -163,18 +163,6 @@ colourPipe()
 }
 
 
-#
-# prefix message with [HOSTNAME]
-#
-prefixPipe()
-{
-   while read line
-   do
-      echo "[$@] $line"
-   done
-}
-
-
 colourIndex=0
 
 while :
@@ -202,19 +190,15 @@ do
 
                if [ "$host" = "$HOST" ]; then
                   eval $* 2>&1 | colourPipe "$colour"
-               elif [ -n "$JOB_ID" ]; then
-                  qrsh -inherit -v PWD $host "$rcmd"
                else
                   ssh $host "$sourceFoam 2>/dev/null; cd $PWD && $rcmd" 2>&1 | colourPipe "$colour"
                fi
                retval=$?
             else
                if [ "$host" = "$HOST" ]; then
-                  eval $* 2>&1 | prefixPipe "$host"
-               elif [ -n "$JOB_ID" ]; then
-                  qrsh -inherit -v PWD $host "$rcmd" | prefixPipe "$host"
+                  eval $* 2>&1
                else
-                  ssh $host "$sourceFoam 2>/dev/null; cd $PWD && $rcmd" 2>&1 | prefixPipe "$host"
+                  ssh $host "$sourceFoam 2>/dev/null; cd $PWD && $rcmd" 2>&1
                fi
                retval=$?
             fi
-- 
GitLab