From 5973afc3e85403fe240969572a6962dbf5cb8d22 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Tue, 23 Jan 2024 09:03:59 +0100
Subject: [PATCH] ENH: use tmp field factory methods [1] (#2723)

- src/OpenFOAM, src/meshTools, src/mesh, src/dynamicMesh, src/sampling
  src/topoChanger src/overset src/fvMotionSolver
---
 .../GeometricField/uniformInterpolate.C       |  3 +-
 .../LduMatrix/LduMatrix/LduMatrixOperations.C |  5 +-
 src/OpenFOAM/meshes/polyMesh/polyMesh.C       |  2 +-
 .../polyPatches/polyPatch/polyPatch.C         |  8 ++--
 .../interfaceTrackingFvMesh.C                 | 41 +++++-----------
 .../layerAdditionRemoval/addCellLayer.C       |  4 +-
 .../displacementInterpolationMotionSolver.C   |  4 +-
 .../displacementLayeredMotionMotionSolver.C   | 25 ++++------
 .../pairPatchAgglomeration.C                  |  4 +-
 ...lacementComponentLaplacianFvMotionSolver.C |  4 +-
 ...velocityComponentLaplacianFvMotionSolver.C |  2 +-
 .../surfaceAlignedSBRStressFvMotionSolver.C   | 47 ++++++-------------
 .../snappyHexMeshDriver/snappyLayerDriver.C   |  4 +-
 .../snappyHexMeshDriver/snappySnapDriver.C    | 22 ++++-----
 src/meshTools/cellQuality/cellQuality.C       | 43 ++++-------------
 .../edgeMeshTools/edgeMeshFeatureProximity.C  |  4 +-
 .../momentOfInertia/momentOfInertia.C         |  5 +-
 .../triSurfaceTools/triSurfaceCloseness.C     |  4 +-
 .../cellCellStencilTemplates.C                | 15 ++----
 .../oversetPolyPatch/oversetFvPatchField.C    |  5 +-
 .../oversetPolyPatch/oversetFvPatchField.H    | 20 ++------
 .../rigidBodyMotion/rigidBodyMotion.C         | 12 ++---
 .../rigidBodyMeshMotion/rigidBodyMeshMotion.C |  4 +-
 src/sampling/meshToMesh/meshToMeshTemplates.C | 42 ++++++-----------
 .../sampledCuttingPlane/sampledCuttingPlane.C | 27 +++--------
 .../sixDoFRigidBodyMotion.C                   |  4 +-
 .../sixDoFRigidBodyMotionSolver.C             |  4 +-
 .../linearValveLayersFvMesh.C                 |  8 +---
 .../movingConeTopoFvMesh.C                    |  4 +-
 29 files changed, 126 insertions(+), 250 deletions(-)

diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/uniformInterpolate.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/uniformInterpolate.C
index 6476a59d354..559f7fe26ff 100644
--- a/src/OpenFOAM/fields/GeometricFields/GeometricField/uniformInterpolate.C
+++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/uniformInterpolate.C
@@ -46,7 +46,8 @@ Foam::tmp<GeoField> Foam::uniformInterpolate
             field0.time().timeName(),
             field0.db(),
             IOobject::NO_READ,
-            IOobject::AUTO_WRITE
+            IOobject::AUTO_WRITE,
+            IOobject::REGISTER
         ),
         weights[0]*(*fields[indices[0]])
     );
diff --git a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrixOperations.C b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrixOperations.C
index 7fa0cd403c3..ea60f737314 100644
--- a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrixOperations.C
+++ b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrixOperations.C
@@ -90,10 +90,7 @@ template<class Type, class DType, class LUType>
 Foam::tmp<Foam::Field<Type>>
 Foam::LduMatrix<Type, DType, LUType>::H(const Field<Type>& psi) const
 {
-    tmp<Field<Type>> tHpsi
-    (
-        new Field<Type>(lduAddr().size(), Zero)
-    );
+    auto tHpsi = tmp<Field<Type>>::New(lduAddr().size(), Zero);
 
     if (lowerPtr_ || upperPtr_)
     {
diff --git a/src/OpenFOAM/meshes/polyMesh/polyMesh.C b/src/OpenFOAM/meshes/polyMesh/polyMesh.C
index 00480e7669d..5aba0e0d2f4 100644
--- a/src/OpenFOAM/meshes/polyMesh/polyMesh.C
+++ b/src/OpenFOAM/meshes/polyMesh/polyMesh.C
@@ -1195,7 +1195,7 @@ void Foam::polyMesh::movePoints(const pointField& newPoints)
     {
         if (debug)
         {
-            Info<< "tmp<scalarField> polyMesh::movePoints(const pointField&) : "
+            Info<< "void polyMesh::movePoints(const pointField&) : "
                 << " Storing current points for time " << time().value()
                 << " index " << time().timeIndex() << endl;
         }
diff --git a/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.C b/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.C
index 1a5e79754c9..3f2530d6da8 100644
--- a/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.C
+++ b/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.C
@@ -333,8 +333,8 @@ const Foam::vectorField::subField Foam::polyPatch::faceAreas() const
 
 Foam::tmp<Foam::vectorField> Foam::polyPatch::faceCellCentres() const
 {
-    tmp<vectorField> tcc(new vectorField(size()));
-    vectorField& cc = tcc.ref();
+    auto tcc = tmp<vectorField>::New(size());
+    auto& cc = tcc.ref();
 
     // get reference to global cell centres
     const vectorField& gcc = boundaryMesh_.mesh().cellCentres();
@@ -352,8 +352,8 @@ Foam::tmp<Foam::vectorField> Foam::polyPatch::faceCellCentres() const
 
 Foam::tmp<Foam::scalarField> Foam::polyPatch::areaFraction() const
 {
-    tmp<scalarField> tfraction(new scalarField(size()));
-    scalarField& fraction = tfraction.ref();
+    auto tfraction = tmp<scalarField>::New(size());
+    auto& fraction = tfraction.ref();
 
     const vectorField::subField faceAreas = this->faceAreas();
     const pointField& points = this->points();
diff --git a/src/dynamicFaMesh/interfaceTrackingFvMesh/interfaceTrackingFvMesh.C b/src/dynamicFaMesh/interfaceTrackingFvMesh/interfaceTrackingFvMesh.C
index ef431b1d9e4..4197ef6bac7 100644
--- a/src/dynamicFaMesh/interfaceTrackingFvMesh/interfaceTrackingFvMesh.C
+++ b/src/dynamicFaMesh/interfaceTrackingFvMesh/interfaceTrackingFvMesh.C
@@ -295,46 +295,31 @@ void Foam::interfaceTrackingFvMesh::makeControlPoints()
             << abort(FatalError);
     }
 
-    IOobject controlPointsHeader
+    IOobject pointsIO
     (
         "controlPoints",
         mesh().time().timeName(),
         mesh(),
-        IOobject::MUST_READ
+        IOobject::MUST_READ,
+        IOobject::AUTO_WRITE,
+        IOobject::REGISTER
     );
 
-    if (controlPointsHeader.typeHeaderOk<vectorIOField>())
+    if (pointsIO.typeHeaderOk<vectorIOField>())
     {
         Info<< "Reading control points" << endl;
-        controlPointsPtr_ =
-            new vectorIOField
-            (
-                IOobject
-                (
-                    "controlPoints",
-                    mesh().time().timeName(),
-                    mesh(),
-                    IOobject::MUST_READ,
-                    IOobject::AUTO_WRITE
-                )
-            );
+        controlPointsPtr_ = new vectorIOField(pointsIO);
     }
     else
     {
+        pointsIO.readOpt(IOobject::NO_READ);
+
         Info<< "Creating new control points" << endl;
-        controlPointsPtr_ =
-            new vectorIOField
-            (
-                IOobject
-                (
-                    "controlPoints",
-                    mesh().time().timeName(),
-                    mesh(),
-                    IOobject::NO_READ,
-                    IOobject::AUTO_WRITE
-                ),
-                aMesh().areaCentres().internalField()
-            );
+        controlPointsPtr_ = new vectorIOField
+        (
+            pointsIO,
+            aMesh().areaCentres().internalField()
+        );
 
         initializeControlPointsPosition();
     }
diff --git a/src/dynamicMesh/layerAdditionRemoval/addCellLayer.C b/src/dynamicMesh/layerAdditionRemoval/addCellLayer.C
index 2c6eb27b362..43f12a7cd7e 100644
--- a/src/dynamicMesh/layerAdditionRemoval/addCellLayer.C
+++ b/src/dynamicMesh/layerAdditionRemoval/addCellLayer.C
@@ -47,8 +47,8 @@ Foam::tmp<Foam::vectorField> Foam::layerAdditionRemoval::extrusionDir() const
     const pointField& points = mesh.points();
     const labelList& mp = masterFaceLayer.meshPoints();
 
-    tmp<vectorField> textrusionDir(new vectorField(mp.size()));
-    vectorField& extrusionDir = textrusionDir.ref();
+    auto textrusionDir = tmp<vectorField>::New(mp.size());
+    auto& extrusionDir = textrusionDir.ref();
 
     if (setLayerPairing())
     {
diff --git a/src/dynamicMesh/motionSolvers/displacement/interpolation/displacementInterpolationMotionSolver.C b/src/dynamicMesh/motionSolvers/displacement/interpolation/displacementInterpolationMotionSolver.C
index dbd93a73fbc..2026e4e09e4 100644
--- a/src/dynamicMesh/motionSolvers/displacement/interpolation/displacementInterpolationMotionSolver.C
+++ b/src/dynamicMesh/motionSolvers/displacement/interpolation/displacementInterpolationMotionSolver.C
@@ -339,8 +339,8 @@ Foam::displacementInterpolationMotionSolver::curPoints() const
             << " points." << exit(FatalError);
     }
 
-    tmp<pointField> tcurPoints(new pointField(points0()));
-    pointField& curPoints = tcurPoints.ref();
+    auto tcurPoints = tmp<pointField>::New(points0());
+    auto& curPoints = tcurPoints.ref();
 
     // Interpolate the displacement of the face zones.
     vectorField zoneDisp(displacements_.size(), Zero);
diff --git a/src/dynamicMesh/motionSolvers/displacement/layeredSolver/displacementLayeredMotionMotionSolver.C b/src/dynamicMesh/motionSolvers/displacement/layeredSolver/displacementLayeredMotionMotionSolver.C
index 5b88d28c572..645be3cea28 100644
--- a/src/dynamicMesh/motionSolvers/displacement/layeredSolver/displacementLayeredMotionMotionSolver.C
+++ b/src/dynamicMesh/motionSolvers/displacement/layeredSolver/displacementLayeredMotionMotionSolver.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2016 OpenFOAM Foundation
-    Copyright (C) 2015-2019 OpenCFD Ltd.
+    Copyright (C) 2015-2023 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -338,14 +338,9 @@ void Foam::displacementLayeredMotionMotionSolver::cellZoneSolve
             patchi,
             new pointVectorField
             (
-                IOobject
+                mesh().newIOobject
                 (
-                    mesh().cellZones()[cellZoneI].name() + "_" + fz.name(),
-                    mesh().time().timeName(),
-                    mesh(),
-                    IOobject::NO_READ,
-                    IOobject::NO_WRITE,
-                    IOobject::NO_REGISTER
+                    mesh().cellZones()[cellZoneI].name() + "_" + fz.name()
                 ),
                 pointDisplacement_  // to inherit the boundary conditions
             )
@@ -429,20 +424,18 @@ void Foam::displacementLayeredMotionMotionSolver::cellZoneSolve
     if (debug)
     {
         // Normalised distance
-        pointScalarField distance
+        auto tdistance = pointScalarField::New
         (
-            IOobject
+            IOobject::scopedName
             (
-                mesh().cellZones()[cellZoneI].name() + ":distance",
-                mesh().time().timeName(),
-                mesh(),
-                IOobject::NO_READ,
-                IOobject::NO_WRITE,
-                IOobject::NO_REGISTER
+                mesh().cellZones()[cellZoneI].name(),
+                "distance"
             ),
+            IOobject::NO_REGISTER,
             pointMesh::New(mesh()),
             dimensionedScalar(dimLength, Zero)
         );
+        auto& distance = tdistance.ref();
 
         for (const label pointi : isZonePoint)
         {
diff --git a/src/fvAgglomerationMethods/pairPatchAgglomeration/pairPatchAgglomeration.C b/src/fvAgglomerationMethods/pairPatchAgglomeration/pairPatchAgglomeration.C
index 16314968ad1..3db5770d179 100644
--- a/src/fvAgglomerationMethods/pairPatchAgglomeration/pairPatchAgglomeration.C
+++ b/src/fvAgglomerationMethods/pairPatchAgglomeration/pairPatchAgglomeration.C
@@ -664,8 +664,8 @@ Foam::tmp<Foam::labelField> Foam::pairPatchAgglomeration::agglomerateOneLevel
 {
     const label nFineFaces = patch.size();
 
-    tmp<labelField> tcoarseCellMap(new labelField(nFineFaces, -1));
-    labelField& coarseCellMap = tcoarseCellMap.ref();
+    auto tcoarseCellMap = tmp<labelField>::New(nFineFaces, -1);
+    auto& coarseCellMap = tcoarseCellMap.ref();
 
     const labelListList& faceFaces = patch.faceFaces();
 
diff --git a/src/fvMotionSolver/fvMotionSolvers/componentDisplacement/componentLaplacian/displacementComponentLaplacianFvMotionSolver.C b/src/fvMotionSolver/fvMotionSolvers/componentDisplacement/componentLaplacian/displacementComponentLaplacianFvMotionSolver.C
index c0656e0516e..541cc4882ba 100644
--- a/src/fvMotionSolver/fvMotionSolvers/componentDisplacement/componentLaplacian/displacementComponentLaplacianFvMotionSolver.C
+++ b/src/fvMotionSolver/fvMotionSolvers/componentDisplacement/componentLaplacian/displacementComponentLaplacianFvMotionSolver.C
@@ -186,8 +186,8 @@ Foam::displacementComponentLaplacianFvMotionSolver::curPoints() const
     }
     else
     {
-        tmp<pointField> tcurPoints(new pointField(fvMesh_.points()));
-        pointField& curPoints = tcurPoints.ref();
+        auto tcurPoints = tmp<pointField>::New(fvMesh_.points());
+        auto& curPoints = tcurPoints.ref();
 
         curPoints.replace
         (
diff --git a/src/fvMotionSolver/fvMotionSolvers/componentVelocity/componentLaplacian/velocityComponentLaplacianFvMotionSolver.C b/src/fvMotionSolver/fvMotionSolvers/componentVelocity/componentLaplacian/velocityComponentLaplacianFvMotionSolver.C
index 68d95d1f981..9fd45f1149a 100644
--- a/src/fvMotionSolver/fvMotionSolvers/componentVelocity/componentLaplacian/velocityComponentLaplacianFvMotionSolver.C
+++ b/src/fvMotionSolver/fvMotionSolvers/componentVelocity/componentLaplacian/velocityComponentLaplacianFvMotionSolver.C
@@ -104,7 +104,7 @@ Foam::velocityComponentLaplacianFvMotionSolver::curPoints() const
         pointMotionU_
     );
 
-    tmp<pointField> tcurPoints(new pointField(fvMesh_.points()));
+    auto tcurPoints = tmp<pointField>::New(fvMesh_.points());
 
     tcurPoints.ref().replace
     (
diff --git a/src/fvMotionSolver/fvMotionSolvers/displacement/surfaceAlignedSBRStress/surfaceAlignedSBRStressFvMotionSolver.C b/src/fvMotionSolver/fvMotionSolvers/displacement/surfaceAlignedSBRStress/surfaceAlignedSBRStressFvMotionSolver.C
index 0d6c19e100c..f886e65d230 100644
--- a/src/fvMotionSolver/fvMotionSolvers/displacement/surfaceAlignedSBRStress/surfaceAlignedSBRStressFvMotionSolver.C
+++ b/src/fvMotionSolver/fvMotionSolvers/displacement/surfaceAlignedSBRStress/surfaceAlignedSBRStressFvMotionSolver.C
@@ -301,28 +301,18 @@ void Foam::surfaceAlignedSBRStressFvMotionSolver::solve()
     // Calculate rotations on surface intersection
     calculateCellRot();
 
-    tmp<volVectorField> tUd
+    auto tUd = volVectorField::New
     (
-        new volVectorField
+        "Ud",
+        IOobject::NO_REGISTER,
+        fvMesh_,
+        dimensionedVector(dimLength, Zero),
+        cellMotionBoundaryTypes<vector>
         (
-            IOobject
-            (
-                "Ud",
-                fvMesh_.time().timeName(),
-                fvMesh_,
-                IOobject::NO_READ,
-                IOobject::NO_WRITE
-            ),
-            fvMesh_,
-            dimensionedVector(dimLength, Zero),
-            cellMotionBoundaryTypes<vector>
-            (
-                pointDisplacement().boundaryField()
-            )
+            pointDisplacement().boundaryField()
         )
     );
-
-    volVectorField& Ud = tUd.ref();
+    auto& Ud = tUd.ref();
 
     const vectorList& C = fvMesh_.C();
     forAll(Ud, i)
@@ -346,23 +336,14 @@ void Foam::surfaceAlignedSBRStressFvMotionSolver::solve()
 
     const volTensorField gradD("gradD", fvc::grad(Ud));
 
-    tmp<volScalarField> tmu
+    auto tmu = volScalarField::New
     (
-        new volScalarField
-        (
-            IOobject
-            (
-                "mu",
-                fvMesh_.time().timeName(),
-                fvMesh_,
-                IOobject::NO_READ,
-                IOobject::NO_WRITE
-            ),
-            fvMesh_,
-            dimensionedScalar(dimless, Zero)
-        )
+        "mu",
+        IOobject::NO_REGISTER,
+        fvMesh_,
+        dimensionedScalar(dimless, Zero)
     );
-    volScalarField& mu =  tmu.ref();
+    auto& mu = tmu.ref();
 
     const scalarList& V = fvMesh_.V();
     mu.primitiveFieldRef() = (1.0/V);
diff --git a/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappyLayerDriver.C b/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappyLayerDriver.C
index 2f857a3d56e..072e39dfeb9 100644
--- a/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappyLayerDriver.C
+++ b/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappyLayerDriver.C
@@ -113,8 +113,8 @@ Foam::tmp<Foam::scalarField> Foam::snappyLayerDriver::avgPointData
     const scalarField& pointFld
 )
 {
-    tmp<scalarField> tfaceFld(new scalarField(pp.size(), Zero));
-    scalarField& faceFld = tfaceFld.ref();
+    auto tfaceFld = tmp<scalarField>::New(pp.size(), Zero);
+    auto& faceFld = tfaceFld.ref();
 
     forAll(pp.localFaces(), facei)
     {
diff --git a/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappySnapDriver.C b/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappySnapDriver.C
index 9667c057837..b38620a13f0 100644
--- a/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappySnapDriver.C
+++ b/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappySnapDriver.C
@@ -257,8 +257,8 @@ Foam::tmp<Foam::pointField> Foam::snappySnapDriver::smoothInternalDisplacement
     // Add coupled contributions
     weightedPosition::syncPoints(mesh, sumLocation);
 
-    tmp<pointField> tdisplacement(new pointField(mesh.nPoints(), Zero));
-    pointField& displacement = tdisplacement.ref();
+    auto tdisplacement = tmp<pointField>::New(mesh.nPoints(), Zero);
+    auto& displacement = tdisplacement.ref();
 
     label nAdapted = 0;
 
@@ -490,8 +490,8 @@ Foam::tmp<Foam::pointField> Foam::snappySnapDriver::smoothPatchDisplacement
 
 
     // Displacement to calculate.
-    tmp<pointField> tpatchDisp(new pointField(meshPoints.size(), Zero));
-    pointField& patchDisp = tpatchDisp.ref();
+    auto tpatchDisp = tmp<pointField>::New(meshPoints.size(), Zero);
+    auto& patchDisp = tpatchDisp.ref();
 
     forAll(pointFaces, i)
     {
@@ -571,8 +571,8 @@ Foam::tmp<Foam::pointField> Foam::snappySnapDriver::smoothPatchDisplacement
 //    const labelListList& pointEdges = pp.pointEdges();
 //    const edgeList& edges = pp.edges();
 //
-//    tmp<pointField> tavg(new pointField(pointEdges.size(), Zero));
-//    pointField& avg = tavg();
+//    auto tavg = tmp<pointField>::New(pointEdges.size(), Zero);
+//    auto& avg = tavg.ref();
 //
 //    forAll(pointEdges, verti)
 //    {
@@ -658,8 +658,8 @@ Foam::tmp<Foam::scalarField> Foam::snappySnapDriver::edgePatchDist
     );
 
     // Copy edge values into scalarField
-    tmp<scalarField> tedgeDist(new scalarField(mesh.nEdges()));
-    scalarField& edgeDist = tedgeDist.ref();
+    auto tedgeDist = tmp<scalarField>::New(mesh.nEdges());
+    auto& edgeDist = tedgeDist.ref();
 
     forAll(allEdgeInfo, edgei)
     {
@@ -1057,7 +1057,7 @@ Foam::tmp<Foam::pointField> Foam::snappySnapDriver::avgCellCentres
     // Add coupled contributions
     weightedPosition::syncPoints(mesh, pp.meshPoints(), avgBoundary);
 
-    tmp<pointField> tavgBoundary(new pointField(avgBoundary.size()));
+    auto tavgBoundary = tmp<pointField>::New(avgBoundary.size());
     weightedPosition::getPoints(avgBoundary, tavgBoundary.ref());
 
     return tavgBoundary;
@@ -1073,8 +1073,8 @@ Foam::tmp<Foam::pointField> Foam::snappySnapDriver::avgCellCentres
 //    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 //    // (Ripped from snappyLayerDriver)
 //
-//    tmp<scalarField> tedgeLen(new scalarField(pp.nPoints()));
-//    scalarField& edgeLen = tedgeLen();
+//    auto tedgeLen = tmp<scalarField>::New(pp.nPoints());
+//    auto& edgeLen = tedgeLen.ref();
 //    {
 //        const fvMesh& mesh = meshRefiner_.mesh();
 //        const scalar edge0Len = meshRefiner_.meshCutter().level0EdgeLength();
diff --git a/src/meshTools/cellQuality/cellQuality.C b/src/meshTools/cellQuality/cellQuality.C
index 2ee6a6c4c3d..fc5f7df5200 100644
--- a/src/meshTools/cellQuality/cellQuality.C
+++ b/src/meshTools/cellQuality/cellQuality.C
@@ -41,15 +41,8 @@ Foam::cellQuality::cellQuality(const polyMesh& mesh)
 
 Foam::tmp<Foam::scalarField> Foam::cellQuality::nonOrthogonality() const
 {
-    tmp<scalarField> tresult
-    (
-        new scalarField
-        (
-            mesh_.nCells(), 0.0
-        )
-    );
-
-    scalarField& result = tresult.ref();
+    auto tresult = tmp<scalarField>::New(mesh_.nCells(), Zero);
+    auto& result = tresult.ref();
 
     scalarField sumArea(mesh_.nCells(), Zero);
 
@@ -103,14 +96,8 @@ Foam::tmp<Foam::scalarField> Foam::cellQuality::nonOrthogonality() const
 
 Foam::tmp<Foam::scalarField> Foam::cellQuality::skewness() const
 {
-    tmp<scalarField> tresult
-    (
-        new scalarField
-        (
-            mesh_.nCells(), 0.0
-        )
-    );
-    scalarField& result = tresult.ref();
+    auto tresult = tmp<scalarField>::New(mesh_.nCells(), Zero);
+    auto& result = tresult.ref();
 
     scalarField sumArea(mesh_.nCells(), Zero);
 
@@ -182,15 +169,8 @@ Foam::tmp<Foam::scalarField> Foam::cellQuality::skewness() const
 
 Foam::tmp<Foam::scalarField> Foam::cellQuality::faceNonOrthogonality() const
 {
-    tmp<scalarField> tresult
-    (
-        new scalarField
-        (
-            mesh_.nFaces(), 0.0
-        )
-    );
-    scalarField& result = tresult.ref();
-
+    auto tresult = tmp<scalarField>::New(mesh_.nFaces(), Zero);
+    auto& result = tresult.ref();
 
     const vectorField& centres = mesh_.cellCentres();
     const vectorField& areas = mesh_.faceAreas();
@@ -242,15 +222,8 @@ Foam::tmp<Foam::scalarField> Foam::cellQuality::faceNonOrthogonality() const
 
 Foam::tmp<Foam::scalarField> Foam::cellQuality::faceSkewness() const
 {
-    tmp<scalarField> tresult
-    (
-        new scalarField
-        (
-            mesh_.nFaces(), 0.0
-        )
-    );
-    scalarField& result = tresult.ref();
-
+    auto tresult = tmp<scalarField>::New(mesh_.nFaces(), Zero);
+    auto& result = tresult.ref();
 
     const vectorField& cellCtrs = mesh_.cellCentres();
     const vectorField& faceCtrs = mesh_.faceCentres();
diff --git a/src/meshTools/edgeMesh/edgeMeshTools/edgeMeshFeatureProximity.C b/src/meshTools/edgeMesh/edgeMeshTools/edgeMeshFeatureProximity.C
index fbb851e4b37..6458779c7f6 100644
--- a/src/meshTools/edgeMesh/edgeMeshTools/edgeMeshFeatureProximity.C
+++ b/src/meshTools/edgeMesh/edgeMeshTools/edgeMeshFeatureProximity.C
@@ -143,8 +143,8 @@ Foam::tmp<Foam::scalarField> Foam::edgeMeshTools::featureProximity
     const scalar searchDistance
 )
 {
-    tmp<scalarField> tfld(new scalarField(surf.size(), searchDistance));
-    scalarField& featureProximity = tfld.ref();
+    auto tfld = tmp<scalarField>::New(surf.size(), searchDistance);
+    auto& featureProximity = tfld.ref();
 
     Info<< "Extracting proximity of close feature points and "
         << "edges to the surface" << endl;
diff --git a/src/meshTools/momentOfInertia/momentOfInertia.C b/src/meshTools/momentOfInertia/momentOfInertia.C
index 3ea48e84723..ffb296a3a02 100644
--- a/src/meshTools/momentOfInertia/momentOfInertia.C
+++ b/src/meshTools/momentOfInertia/momentOfInertia.C
@@ -354,9 +354,8 @@ Foam::tmp<Foam::tensorField> Foam::momentOfInertia::meshInertia
     const polyMesh& mesh
 )
 {
-    tmp<tensorField> tTf = tmp<tensorField>(new tensorField(mesh.nCells()));
-
-    tensorField& tf = tTf.ref();
+    auto tTf = tmp<tensorField>::New(mesh.nCells());
+    auto& tf = tTf.ref();
 
     forAll(tf, cI)
     {
diff --git a/src/meshTools/triSurface/triSurfaceTools/triSurfaceCloseness.C b/src/meshTools/triSurface/triSurfaceTools/triSurfaceCloseness.C
index c47ee9e62fd..b9add2217b7 100644
--- a/src/meshTools/triSurface/triSurfaceTools/triSurfaceCloseness.C
+++ b/src/meshTools/triSurface/triSurfaceTools/triSurfaceCloseness.C
@@ -103,8 +103,8 @@ Foam::triSurfaceTools::writeCloseness
 {
     Pair<tmp<scalarField>> tpair
     (
-        tmp<scalarField>(new scalarField(surf.size(), GREAT)),
-        tmp<scalarField>(new scalarField(surf.size(), GREAT))
+        tmp<scalarField>::New(surf.size(), GREAT),
+        tmp<scalarField>::New(surf.size(), GREAT)
     );
 
     Info<< "Extracting internal and external closeness of surface." << endl;
diff --git a/src/overset/cellCellStencil/cellCellStencil/cellCellStencilTemplates.C b/src/overset/cellCellStencil/cellCellStencil/cellCellStencilTemplates.C
index bb441cb79a2..80237911108 100644
--- a/src/overset/cellCellStencil/cellCellStencil/cellCellStencilTemplates.C
+++ b/src/overset/cellCellStencil/cellCellStencil/cellCellStencilTemplates.C
@@ -158,22 +158,15 @@ Foam::cellCellStencil::createField
     const UList<Type>& psi
 )
 {
-    auto tfld = tmp<volScalarField>::New
+    auto tfld = volScalarField::New
     (
-        IOobject
-        (
-            name,
-            mesh.time().timeName(),
-            mesh,
-            IOobject::NO_READ,
-            IOobject::NO_WRITE,
-            IOobject::NO_REGISTER
-        ),
+        name,
+        IOobject::NO_REGISTER,
         mesh,
         dimensionedScalar(dimless, Zero),
         fvPatchFieldBase::zeroGradientType()
     );
-    volScalarField& fld = tfld.ref();
+    auto& fld = tfld.ref();
 
     forAll(psi, cellI)
     {
diff --git a/src/overset/oversetPolyPatch/oversetFvPatchField.C b/src/overset/oversetPolyPatch/oversetFvPatchField.C
index 3beba4a72f3..1ab511b730d 100644
--- a/src/overset/oversetPolyPatch/oversetFvPatchField.C
+++ b/src/overset/oversetPolyPatch/oversetFvPatchField.C
@@ -585,10 +585,7 @@ template<class Type>
 Foam::tmp<Foam::Field<Type>> Foam::oversetFvPatchField<Type>::
 patchNeighbourField() const
 {
-    return tmp<Field<Type>>
-    (
-        new Field<Type>(this->size(), Zero)
-    );
+    return tmp<Field<Type>>::New(this->size(), Zero);
 }
 
 
diff --git a/src/overset/oversetPolyPatch/oversetFvPatchField.H b/src/overset/oversetPolyPatch/oversetFvPatchField.H
index cb22fb67268..ead67e8fab9 100644
--- a/src/overset/oversetPolyPatch/oversetFvPatchField.H
+++ b/src/overset/oversetPolyPatch/oversetFvPatchField.H
@@ -195,10 +195,7 @@ public:
                 const tmp<scalarField>&
             ) const
             {
-                return tmp<Field<Type>>
-                (
-                    new Field<Type>(this->size(), Zero)
-                );
+                return tmp<Field<Type>>::New(this->size(), Foam::zero{});
             }
 
             //- Return the matrix source coefficients corresponding to the
@@ -208,30 +205,21 @@ public:
                 const tmp<scalarField>&
             ) const
             {
-                return tmp<Field<Type>>
-                (
-                    new Field<Type>(this->size(), Zero)
-                );
+                return tmp<Field<Type>>::New(this->size(), Foam::zero{});
             }
 
             //- Return the matrix diagonal coefficients corresponding to the
             //- evaluation of the gradient of this patchField
             tmp<Field<Type>> gradientInternalCoeffs() const
             {
-                return tmp<Field<Type>>
-                (
-                    new Field<Type>(this->size(), Zero)
-                );
+                return tmp<Field<Type>>::New(this->size(), Foam::zero{});
             }
 
             //- Return the matrix source coefficients corresponding to the
             //- evaluation of the gradient of this patchField
             tmp<Field<Type>> gradientBoundaryCoeffs() const
             {
-                return tmp<Field<Type>>
-                (
-                    new Field<Type>(this->size(), Zero)
-                );
+                return tmp<Field<Type>>::New(this->size(), Foam::zero{});
             }
 
             //- Manipulate matrix
diff --git a/src/rigidBodyDynamics/rigidBodyMotion/rigidBodyMotion.C b/src/rigidBodyDynamics/rigidBodyMotion/rigidBodyMotion.C
index cc03840da3e..88cdd4e3af2 100644
--- a/src/rigidBodyDynamics/rigidBodyMotion/rigidBodyMotion.C
+++ b/src/rigidBodyDynamics/rigidBodyMotion/rigidBodyMotion.C
@@ -238,8 +238,8 @@ Foam::tmp<Foam::pointField> Foam::RBD::rigidBodyMotion::transformPoints
     // to the current state in the global frame
     spatialTransform X(X0(bodyID).inv() & X00(bodyID));
 
-    tmp<pointField> tpoints(new pointField(initialPoints.size()));
-    pointField& points = tpoints.ref();
+    auto tpoints = tmp<pointField>::New(initialPoints.size());
+    auto& points = tpoints.ref();
 
     forAll(points, i)
     {
@@ -265,8 +265,8 @@ Foam::tmp<Foam::pointField> Foam::RBD::rigidBodyMotion::transformPoints
     // interpolation
     septernion s(X);
 
-    tmp<pointField> tpoints(new pointField(initialPoints));
-    pointField& points = tpoints.ref();
+    auto tpoints = tmp<pointField>::New(initialPoints);
+    auto& points = tpoints.ref();
 
     forAll(points, i)
     {
@@ -314,8 +314,8 @@ Foam::tmp<Foam::pointField> Foam::RBD::rigidBodyMotion::transformPoints
         ss[bi] = septernion(X);
     }
 
-    tmp<pointField> tpoints(new pointField(initialPoints));
-    pointField& points = tpoints.ref();
+    auto tpoints = tmp<pointField>::New(initialPoints);
+    auto& points = tpoints.ref();
 
     List<scalar> w(ss.size());
 
diff --git a/src/rigidBodyMeshMotion/rigidBodyMeshMotion/rigidBodyMeshMotion.C b/src/rigidBodyMeshMotion/rigidBodyMeshMotion/rigidBodyMeshMotion.C
index 780844e6e7a..e7f4d71072a 100644
--- a/src/rigidBodyMeshMotion/rigidBodyMeshMotion/rigidBodyMeshMotion.C
+++ b/src/rigidBodyMeshMotion/rigidBodyMeshMotion/rigidBodyMeshMotion.C
@@ -224,8 +224,8 @@ Foam::rigidBodyMeshMotion::curPoints() const
     }
     else
     {
-        tmp<pointField> ttransformedPts(new pointField(mesh().points()));
-        pointField& transformedPts = ttransformedPts.ref();
+        auto ttransformedPts = tmp<pointField>::New(mesh().points());
+        auto& transformedPts = ttransformedPts.ref();
 
         UIndirectList<point>(transformedPts, pointIDs()) =
             pointField(newPoints.ref(), pointIDs());
diff --git a/src/sampling/meshToMesh/meshToMeshTemplates.C b/src/sampling/meshToMesh/meshToMeshTemplates.C
index a1f8b6f637b..a1df9365556 100644
--- a/src/sampling/meshToMesh/meshToMeshTemplates.C
+++ b/src/sampling/meshToMesh/meshToMeshTemplates.C
@@ -218,14 +218,7 @@ Foam::tmp<Foam::Field<Type>> Foam::meshToMesh::mapSrcToTgt
     const CombineOp& cop
 ) const
 {
-    tmp<Field<Type>> tresult
-    (
-        new Field<Type>
-        (
-            tgtToSrcCellAddr_.size(),
-            Zero
-        )
-    );
+    auto tresult = tmp<Field<Type>>::New(tgtToSrcCellAddr_.size(), Zero);
 
     mapSrcToTgt(srcField, cop, tresult.ref());
 
@@ -423,14 +416,7 @@ Foam::tmp<Foam::Field<Type>> Foam::meshToMesh::mapTgtToSrc
     const CombineOp& cop
 ) const
 {
-    tmp<Field<Type>> tresult
-    (
-        new Field<Type>
-        (
-            srcToTgtCellAddr_.size(),
-            Zero
-        )
-    );
+    auto tresult = tmp<Field<Type>>::New(srcToTgtCellAddr_.size(), Zero);
 
     mapTgtToSrc(tgtField, cop, tresult.ref());
 
@@ -645,13 +631,13 @@ Foam::meshToMesh::mapSrcToTgt
     auto tresult =
         tmp<VolumeField<Type>>::New
         (
-            IOobject
+            tgtMesh.newIOobject
             (
-                type() + ":interpolate(" + field.name() + ")",
-                tgtMesh.time().timeName(),
-                tgtMesh,
-                IOobject::NO_READ,
-                IOobject::NO_WRITE
+                IOobject::scopedName
+                (
+                    type(),
+                    "interpolate(" + field.name() + ")"
+                )
             ),
             tgtMesh,
             field.dimensions(),
@@ -876,13 +862,13 @@ Foam::meshToMesh::mapTgtToSrc
     auto tresult =
         tmp<VolumeField<Type>>::New
         (
-            IOobject
+            srcMesh.newIOobject
             (
-                type() + ":interpolate(" + field.name() + ")",
-                srcMesh.time().timeName(),
-                srcMesh,
-                IOobject::NO_READ,
-                IOobject::NO_WRITE
+                IOobject::scopedName
+                (
+                    type(),
+                    "interpolate(" + field.name() + ")"
+                )
             ),
             srcMesh,
             field.dimensions(),
diff --git a/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C b/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C
index 17cb45fb9e8..2d47649cd5e 100644
--- a/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C
+++ b/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C
@@ -464,20 +464,12 @@ void Foam::sampledCuttingPlane::createGeometry()
     (
         new volScalarField
         (
-            IOobject
-            (
-                "cellDistance",
-                mesh.time().timeName(),
-                mesh.time(),
-                IOobject::NO_READ,
-                IOobject::NO_WRITE,
-                IOobject::NO_REGISTER
-            ),
+            mesh.newIOobject("cellDistance"),
             mesh,
             dimensionedScalar(dimLength, Zero)
         )
     );
-    const volScalarField& cellDistance = cellDistancePtr_();
+    const auto& cellDistance = *cellDistancePtr_;
 
     setDistanceFields(plane_);
 
@@ -485,20 +477,15 @@ void Foam::sampledCuttingPlane::createGeometry()
     {
         Pout<< "Writing cell distance:" << cellDistance.objectPath() << endl;
         cellDistance.write();
-        pointScalarField pointDist
+        auto tpointDist = pointScalarField::New
         (
-            IOobject
-            (
-                "pointDistance",
-                mesh.time().timeName(),
-                mesh.time(),
-                IOobject::NO_READ,
-                IOobject::NO_WRITE,
-                IOobject::NO_REGISTER
-            ),
+            "pointDistance",
+            IOobject::NO_REGISTER,
             pointMesh::New(mesh),
             dimensionedScalar(dimLength, Zero)
         );
+        auto& pointDist = tpointDist.ref();
+
         pointDist.primitiveFieldRef() = pointDistance_;
 
         Pout<< "Writing point distance:" << pointDist.objectPath() << endl;
diff --git a/src/sixDoFRigidBodyMotion/sixDoFRigidBodyMotion/sixDoFRigidBodyMotion.C b/src/sixDoFRigidBodyMotion/sixDoFRigidBodyMotion/sixDoFRigidBodyMotion.C
index 349493e0962..9b0e0a592ef 100644
--- a/src/sixDoFRigidBodyMotion/sixDoFRigidBodyMotion/sixDoFRigidBodyMotion.C
+++ b/src/sixDoFRigidBodyMotion/sixDoFRigidBodyMotion/sixDoFRigidBodyMotion.C
@@ -393,8 +393,8 @@ Foam::tmp<Foam::pointField> Foam::sixDoFRigidBodyMotion::transform
         quaternion(Q().T() & initialQ())
     );
 
-    tmp<pointField> tpoints(new pointField(initialPoints));
-    pointField& points = tpoints.ref();
+    auto tpoints = tmp<pointField>::New(initialPoints);
+    auto& points = tpoints.ref();
 
     forAll(points, pointi)
     {
diff --git a/src/sixDoFRigidBodyMotion/sixDoFRigidBodyMotionSolver/sixDoFRigidBodyMotionSolver.C b/src/sixDoFRigidBodyMotion/sixDoFRigidBodyMotionSolver/sixDoFRigidBodyMotionSolver.C
index 267fc196430..33de436dcf9 100644
--- a/src/sixDoFRigidBodyMotion/sixDoFRigidBodyMotionSolver/sixDoFRigidBodyMotionSolver.C
+++ b/src/sixDoFRigidBodyMotion/sixDoFRigidBodyMotionSolver/sixDoFRigidBodyMotionSolver.C
@@ -173,8 +173,8 @@ Foam::sixDoFRigidBodyMotionSolver::curPoints() const
 
     if (!moveAllCells())
     {
-        tmp<pointField> ttransformedPts(new pointField(mesh().points()));
-        pointField& transformedPts = ttransformedPts.ref();
+        auto ttransformedPts = tmp<pointField>::New(mesh().points());
+        auto& transformedPts = ttransformedPts.ref();
 
         UIndirectList<point>(transformedPts, pointIDs()) =
             pointField(newPoints.ref(), pointIDs());
diff --git a/src/topoChangerFvMesh/linearValveLayersFvMesh/linearValveLayersFvMesh.C b/src/topoChangerFvMesh/linearValveLayersFvMesh/linearValveLayersFvMesh.C
index 4e56adeb3d8..d4dc7990d4f 100644
--- a/src/topoChangerFvMesh/linearValveLayersFvMesh/linearValveLayersFvMesh.C
+++ b/src/topoChangerFvMesh/linearValveLayersFvMesh/linearValveLayersFvMesh.C
@@ -275,12 +275,8 @@ bool Foam::linearValveLayersFvMesh::attached() const
 
 Foam::tmp<Foam::pointField> Foam::linearValveLayersFvMesh::newPoints() const
 {
-    tmp<pointField> tnewPoints
-    (
-        new pointField(points())
-    );
-
-    pointField& np = tnewPoints();
+    auto tnewPoints = tmp<pointField>::New(points());
+    auto& np = tnewPoints();
 
     const word layerPatchName
     (
diff --git a/src/topoChangerFvMesh/movingConeTopoFvMesh/movingConeTopoFvMesh.C b/src/topoChangerFvMesh/movingConeTopoFvMesh/movingConeTopoFvMesh.C
index 51221b8fadf..0b0d1e8bef5 100644
--- a/src/topoChangerFvMesh/movingConeTopoFvMesh/movingConeTopoFvMesh.C
+++ b/src/topoChangerFvMesh/movingConeTopoFvMesh/movingConeTopoFvMesh.C
@@ -70,8 +70,8 @@ Foam::tmp<Foam::scalarField> Foam::movingConeTopoFvMesh::vertexMarkup
     Info<< "Updating vertex markup.  curLeft: "
         << curLeft << " curRight: " << curRight << endl;
 
-    tmp<scalarField> tvertexMarkup(new scalarField(p.size()));
-    scalarField& vertexMarkup = tvertexMarkup.ref();
+    auto tvertexMarkup = tmp<scalarField>::New(p.size());
+    auto& vertexMarkup = tvertexMarkup.ref();
 
     forAll(p, pI)
     {
-- 
GitLab