From e2eab734f8cc76a2ebbddef1ff7d1b100904ef14 Mon Sep 17 00:00:00 2001
From: andy <a.heather@opencfd.co.uk>
Date: Fri, 15 Jan 2010 11:59:29 +0000
Subject: [PATCH] Clean-up of patch field default field name I/O

---
 .../activeBaffleVelocityFvPatchVectorField.C  | 32 +++++++++----------
 ...MappedVelocityFluxFixedValueFvPatchField.C | 22 ++++++-------
 .../fixedFluxPressureFvPatchScalarField.C     | 15 ++-------
 ...ureCompressibleDensityFvPatchScalarField.C |  6 ++--
 .../fluxCorrectedVelocityFvPatchVectorField.C | 10 ++----
 ...OutletTotalTemperatureFvPatchScalarField.C | 17 ++--------
 .../movingWallVelocityFvPatchVectorField.C    | 22 ++++++++-----
 .../movingWallVelocityFvPatchVectorField.H    |  5 +++
 ...tedInletOutletVelocityFvPatchVectorField.C | 10 ++----
 ...eDirectedInletVelocityFvPatchVectorField.C | 10 ++----
 ...ureInletOutletVelocityFvPatchVectorField.C |  5 +--
 .../pressureInletVelocityFvPatchVectorField.C | 10 ++----
 ...ngUniformTotalPressureFvPatchScalarField.C | 10 ++----
 .../totalTemperatureFvPatchScalarField.C      | 17 ++--------
 ...sityKineticEnergyInletFvPatchScalarField.C |  8 ++++-
 ...sityKineticEnergyInletFvPatchScalarField.H |  4 +++
 16 files changed, 80 insertions(+), 123 deletions(-)

diff --git a/src/finiteVolume/fields/fvPatchFields/derived/activeBaffleVelocity/activeBaffleVelocityFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/activeBaffleVelocity/activeBaffleVelocityFvPatchVectorField.C
index 1e4f3ffcc5c..0ef1c8e35a4 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/activeBaffleVelocity/activeBaffleVelocityFvPatchVectorField.C
+++ b/src/finiteVolume/fields/fvPatchFields/derived/activeBaffleVelocity/activeBaffleVelocityFvPatchVectorField.C
@@ -84,7 +84,7 @@ activeBaffleVelocityFvPatchVectorField
 )
 :
     fixedValueFvPatchVectorField(p, iF),
-    pName_("p"),
+    pName_(dict.lookupOrDefault<word>("p", "p")),
     cyclicPatchName_(dict.lookup("cyclicPatch")),
     cyclicPatchLabel_(p.patch().boundaryMesh().findPatchID(cyclicPatchName_)),
     orientation_(readLabel(dict.lookup("orientation"))),
@@ -96,11 +96,6 @@ activeBaffleVelocityFvPatchVectorField
     curTimeIndex_(-1)
 {
     fvPatchVectorField::operator=(vector::zero);
-
-    if (dict.found("p"))
-    {
-        dict.lookup("p") >> pName_;
-    }
 }
 
 
@@ -219,15 +214,21 @@ void Foam::activeBaffleVelocityFvPatchVectorField::updateCoeffs()
         }
 
         openFraction_ =
-            max(min(
-                openFraction_
-              + max
+            max
+            (
+                min
                 (
-                    this->db().time().deltaTValue()/openingTime_,
-                    maxOpenFractionDelta_
-                )
-               *(orientation_*sign(forceDiff)),
-              1 - 1e-6), 1e-6);
+                    openFraction_
+                  + max
+                    (
+                        this->db().time().deltaTValue()/openingTime_,
+                        maxOpenFractionDelta_
+                    )
+                   *(orientation_*sign(forceDiff)),
+                    1 - 1e-6
+                ),
+                1e-6
+            );
 
         Info<< "openFraction = " << openFraction_ << endl;
 
@@ -264,8 +265,7 @@ void Foam::activeBaffleVelocityFvPatchVectorField::write(Ostream& os) const
         << maxOpenFractionDelta_ << token::END_STATEMENT << nl;
     os.writeKeyword("openFraction")
         << openFraction_ << token::END_STATEMENT << nl;
-    os.writeKeyword("p")
-        << pName_ << token::END_STATEMENT << nl;
+    writeEntryIfDifferent<word>(os, "p", "p", pName_);
     writeEntry("value", os);
 }
 
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/directMappedVelocityFluxFixedValue/directMappedVelocityFluxFixedValueFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/directMappedVelocityFluxFixedValue/directMappedVelocityFluxFixedValueFvPatchField.C
index 526ee956394..0d1a344e038 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/directMappedVelocityFluxFixedValue/directMappedVelocityFluxFixedValueFvPatchField.C
+++ b/src/finiteVolume/fields/fvPatchFields/derived/directMappedVelocityFluxFixedValue/directMappedVelocityFluxFixedValueFvPatchField.C
@@ -46,7 +46,7 @@ directMappedVelocityFluxFixedValueFvPatchField
 )
 :
     fixedValueFvPatchVectorField(p, iF),
-    phiName_("undefinedPhi")
+    phiName_("phi")
 {}
 
 
@@ -93,22 +93,22 @@ directMappedVelocityFluxFixedValueFvPatchField
 )
 :
     fixedValueFvPatchVectorField(p, iF, dict),
-    phiName_(dict.lookup("phi"))
+    phiName_(dict.lookupOrDefault<word>("phi", "phi"))
 {
     if (!isA<directMappedPatchBase>(this->patch().patch()))
     {
         FatalErrorIn
         (
             "directMappedVelocityFluxFixedValueFvPatchField::"
-            "directMappedVelocityFluxFixedValueFvPatchField\n"
-            "(\n"
-            "    const fvPatch& p,\n"
-            "    const DimensionedField<vector, volMesh>& iF,\n"
-            "    const dictionary& dict\n"
-            ")\n"
-        )   << "\n    patch type '" << p.type()
+            "directMappedVelocityFluxFixedValueFvPatchField"
+            "("
+                "const fvPatch&, "
+                "const DimensionedField<vector, volMesh>& iF, "
+                "const dictionary&"
+            ")"
+        )   << "patch type '" << p.type()
             << "' not type '" << directMappedPatchBase::typeName << "'"
-            << "\n    for patch " << p.name()
+            << " for patch " << p.name()
             << " of field " << dimensionedInternalField().name()
             << " in file " << dimensionedInternalField().objectPath()
             << exit(FatalError);
@@ -274,7 +274,7 @@ void directMappedVelocityFluxFixedValueFvPatchField::updateCoeffs()
 void directMappedVelocityFluxFixedValueFvPatchField::write(Ostream& os) const
 {
     fvPatchVectorField::write(os);
-    os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl;
+    writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
     this->writeEntry("value", os);
 }
 
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fixedFluxPressure/fixedFluxPressureFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/fixedFluxPressure/fixedFluxPressureFvPatchScalarField.C
index 8c20f2922c8..ac55d86ee2c 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/fixedFluxPressure/fixedFluxPressureFvPatchScalarField.C
+++ b/src/finiteVolume/fields/fvPatchFields/derived/fixedFluxPressure/fixedFluxPressureFvPatchScalarField.C
@@ -161,18 +161,9 @@ void Foam::fixedFluxPressureFvPatchScalarField::updateCoeffs()
 void Foam::fixedFluxPressureFvPatchScalarField::write(Ostream& os) const
 {
     fvPatchScalarField::write(os);
-    if (UName_ != "U")
-    {
-        os.writeKeyword("U") << UName_ << token::END_STATEMENT << nl;
-    }
-    if (phiName_ != "phi")
-    {
-        os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl;
-    }
-    if (rhoName_ != "rho")
-    {
-        os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl;
-    }
+    writeEntryIfDifferent<word>(os, "U", "U", UName_);
+    writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
+    writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
     os.writeKeyword("adjoint") << adjoint_ << token::END_STATEMENT << nl;
     gradient().writeEntry("gradient", os);
 }
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fixedPressureCompressibleDensity/fixedPressureCompressibleDensityFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/fixedPressureCompressibleDensity/fixedPressureCompressibleDensityFvPatchScalarField.C
index 0f01c960b00..a89929e4280 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/fixedPressureCompressibleDensity/fixedPressureCompressibleDensityFvPatchScalarField.C
+++ b/src/finiteVolume/fields/fvPatchFields/derived/fixedPressureCompressibleDensity/fixedPressureCompressibleDensityFvPatchScalarField.C
@@ -45,7 +45,7 @@ fixedPressureCompressibleDensityFvPatchScalarField
 )
 :
     fixedValueFvPatchField<scalar>(p, iF),
-    pName_("pNameIsUndefined")
+    pName_("p")
 {}
 
 
@@ -72,7 +72,7 @@ fixedPressureCompressibleDensityFvPatchScalarField
 )
 :
     fixedValueFvPatchField<scalar>(p, iF, dict),
-    pName_(dict.lookup("p"))
+    pName_(dict.lookupOrDefault<word>("p", "p"))
 {}
 
 
@@ -134,7 +134,7 @@ void fixedPressureCompressibleDensityFvPatchScalarField::write
 ) const
 {
     fvPatchField<scalar>::write(os);
-    os.writeKeyword("p") << pName_ << token::END_STATEMENT << nl;
+    writeEntryIfDifferent<word>(os, "p", "p", pName_);
     writeEntry("value", os);
 }
 
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/fluxCorrectedVelocity/fluxCorrectedVelocityFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/fluxCorrectedVelocity/fluxCorrectedVelocityFvPatchVectorField.C
index 7de0e1f9d8d..675762c7387 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/fluxCorrectedVelocity/fluxCorrectedVelocityFvPatchVectorField.C
+++ b/src/finiteVolume/fields/fvPatchFields/derived/fluxCorrectedVelocity/fluxCorrectedVelocityFvPatchVectorField.C
@@ -143,14 +143,8 @@ void Foam::fluxCorrectedVelocityFvPatchVectorField::evaluate
 void Foam::fluxCorrectedVelocityFvPatchVectorField::write(Ostream& os) const
 {
     fvPatchVectorField::write(os);
-    if (phiName_ != "phi")
-    {
-        os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl;
-    }
-    if (rhoName_ != "rho")
-    {
-        os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl;
-    }
+    writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
+    writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
     writeEntry("value", os);
 }
 
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/inletOutletTotalTemperature/inletOutletTotalTemperatureFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/inletOutletTotalTemperature/inletOutletTotalTemperatureFvPatchScalarField.C
index d6a83b07cbd..1d9141aa10a 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/inletOutletTotalTemperature/inletOutletTotalTemperatureFvPatchScalarField.C
+++ b/src/finiteVolume/fields/fvPatchFields/derived/inletOutletTotalTemperature/inletOutletTotalTemperatureFvPatchScalarField.C
@@ -30,8 +30,6 @@ License
 #include "volFields.H"
 #include "surfaceFields.H"
 
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
 Foam::inletOutletTotalTemperatureFvPatchScalarField::
@@ -193,18 +191,9 @@ void Foam::inletOutletTotalTemperatureFvPatchScalarField::write(Ostream& os)
 const
 {
     fvPatchScalarField::write(os);
-    if (UName_ != "U")
-    {
-        os.writeKeyword("U") << UName_ << token::END_STATEMENT << nl;
-    }
-    if (phiName_ != "phi")
-    {
-        os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl;
-    }
-    if (phiName_ != "psi")
-    {
-        os.writeKeyword("psi") << psiName_ << token::END_STATEMENT << nl;
-    }
+    writeEntryIfDifferent<word>(os, "U", "U", UName_);
+    writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
+    writeEntryIfDifferent<word>(os, "psi", "psi", psiName_);
     os.writeKeyword("gamma") << gamma_ << token::END_STATEMENT << nl;
     T0_.writeEntry("T0", os);
     writeEntry("value", os);
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/movingWallVelocity/movingWallVelocityFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/movingWallVelocity/movingWallVelocityFvPatchVectorField.C
index 9c24dae9ccf..ebffe092db3 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/movingWallVelocity/movingWallVelocityFvPatchVectorField.C
+++ b/src/finiteVolume/fields/fvPatchFields/derived/movingWallVelocity/movingWallVelocityFvPatchVectorField.C
@@ -43,7 +43,8 @@ movingWallVelocityFvPatchVectorField::movingWallVelocityFvPatchVectorField
     const DimensionedField<vector, volMesh>& iF
 )
 :
-    fixedValueFvPatchVectorField(p, iF)
+    fixedValueFvPatchVectorField(p, iF),
+    UName_("U")
 {}
 
 
@@ -55,7 +56,8 @@ movingWallVelocityFvPatchVectorField::movingWallVelocityFvPatchVectorField
     const fvPatchFieldMapper& mapper
 )
 :
-    fixedValueFvPatchVectorField(ptf, p, iF, mapper)
+    fixedValueFvPatchVectorField(ptf, p, iF, mapper),
+    UName_(ptf.UName_)
 {}
 
 
@@ -66,7 +68,8 @@ movingWallVelocityFvPatchVectorField::movingWallVelocityFvPatchVectorField
     const dictionary& dict
 )
 :
-    fixedValueFvPatchVectorField(p, iF)
+    fixedValueFvPatchVectorField(p, iF),
+    UName_(dict.lookupOrDefault<word>("U", "U"))
 {
     fvPatchVectorField::operator=(vectorField("value", dict, p.size()));
 }
@@ -74,20 +77,22 @@ movingWallVelocityFvPatchVectorField::movingWallVelocityFvPatchVectorField
 
 movingWallVelocityFvPatchVectorField::movingWallVelocityFvPatchVectorField
 (
-    const movingWallVelocityFvPatchVectorField& pivpvf
+    const movingWallVelocityFvPatchVectorField& mwvpvf
 )
 :
-    fixedValueFvPatchVectorField(pivpvf)
+    fixedValueFvPatchVectorField(mwvpvf),
+    UName_(mwvpvf.UName_)
 {}
 
 
 movingWallVelocityFvPatchVectorField::movingWallVelocityFvPatchVectorField
 (
-    const movingWallVelocityFvPatchVectorField& pivpvf,
+    const movingWallVelocityFvPatchVectorField& mwvpvf,
     const DimensionedField<vector, volMesh>& iF
 )
 :
-    fixedValueFvPatchVectorField(pivpvf, iF)
+    fixedValueFvPatchVectorField(mwvpvf, iF),
+    UName_(mwvpvf.UName_)
 {}
 
 
@@ -114,7 +119,7 @@ void movingWallVelocityFvPatchVectorField::updateCoeffs()
 
     vectorField Up = (pp.faceCentres() - oldFc)/mesh.time().deltaTValue();
 
-    const volVectorField& U = db().lookupObject<volVectorField>("U");
+    const volVectorField& U = db().lookupObject<volVectorField>(UName_);
     scalarField phip =
         p.patchField<surfaceScalarField, scalar>(fvc::meshPhi(U));
 
@@ -132,6 +137,7 @@ void movingWallVelocityFvPatchVectorField::updateCoeffs()
 void movingWallVelocityFvPatchVectorField::write(Ostream& os) const
 {
     fvPatchVectorField::write(os);
+    writeEntryIfDifferent<word>(os, "U", "U", UName_);
     writeEntry("value", os);
 }
 
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/movingWallVelocity/movingWallVelocityFvPatchVectorField.H b/src/finiteVolume/fields/fvPatchFields/derived/movingWallVelocity/movingWallVelocityFvPatchVectorField.H
index 11118714be5..ba76e373f3a 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/movingWallVelocity/movingWallVelocityFvPatchVectorField.H
+++ b/src/finiteVolume/fields/fvPatchFields/derived/movingWallVelocity/movingWallVelocityFvPatchVectorField.H
@@ -52,6 +52,11 @@ class movingWallVelocityFvPatchVectorField
 :
     public fixedValueFvPatchVectorField
 {
+    // Private data
+
+       //- Name of velocity field
+       word UName_;
+
 
 public:
 
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/pressureDirectedInletOutletVelocity/pressureDirectedInletOutletVelocityFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/pressureDirectedInletOutletVelocity/pressureDirectedInletOutletVelocityFvPatchVectorField.C
index 49923ea891a..432a8f0c51e 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/pressureDirectedInletOutletVelocity/pressureDirectedInletOutletVelocityFvPatchVectorField.C
+++ b/src/finiteVolume/fields/fvPatchFields/derived/pressureDirectedInletOutletVelocity/pressureDirectedInletOutletVelocityFvPatchVectorField.C
@@ -196,14 +196,8 @@ void pressureDirectedInletOutletVelocityFvPatchVectorField::
 write(Ostream& os) const
 {
     fvPatchVectorField::write(os);
-    if (phiName_ != "phi")
-    {
-        os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl;
-    }
-    if (rhoName_ != "rho")
-    {
-        os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl;
-    }
+    writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
+    writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
     inletDir_.writeEntry("inletDirection", os);
     writeEntry("value", os);
 }
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/pressureDirectedInletVelocity/pressureDirectedInletVelocityFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/pressureDirectedInletVelocity/pressureDirectedInletVelocityFvPatchVectorField.C
index 287bb5b4b0c..af47c957884 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/pressureDirectedInletVelocity/pressureDirectedInletVelocityFvPatchVectorField.C
+++ b/src/finiteVolume/fields/fvPatchFields/derived/pressureDirectedInletVelocity/pressureDirectedInletVelocityFvPatchVectorField.C
@@ -184,14 +184,8 @@ void pressureDirectedInletVelocityFvPatchVectorField::updateCoeffs()
 void pressureDirectedInletVelocityFvPatchVectorField::write(Ostream& os) const
 {
     fvPatchVectorField::write(os);
-    if (phiName_ != "phi")
-    {
-        os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl;
-    }
-    if (rhoName_ != "rho")
-    {
-        os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl;
-    }
+    writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
+    writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
     inletDir_.writeEntry("inletDirection", os);
     writeEntry("value", os);
 }
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/pressureInletOutletVelocity/pressureInletOutletVelocityFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/pressureInletOutletVelocity/pressureInletOutletVelocityFvPatchVectorField.C
index 9b78fe83f8b..c4cd883748e 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/pressureInletOutletVelocity/pressureInletOutletVelocityFvPatchVectorField.C
+++ b/src/finiteVolume/fields/fvPatchFields/derived/pressureInletOutletVelocity/pressureInletOutletVelocityFvPatchVectorField.C
@@ -188,10 +188,7 @@ void pressureInletOutletVelocityFvPatchVectorField::updateCoeffs()
 void pressureInletOutletVelocityFvPatchVectorField::write(Ostream& os) const
 {
     fvPatchVectorField::write(os);
-    if (phiName_ != "phi")
-    {
-        os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl;
-    }
+    writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
     if (tangentialVelocity_.size())
     {
         tangentialVelocity_.writeEntry("tangentialVelocity", os);
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/pressureInletVelocity/pressureInletVelocityFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/pressureInletVelocity/pressureInletVelocityFvPatchVectorField.C
index d6bcbf8e8d0..2c0775523b8 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/pressureInletVelocity/pressureInletVelocityFvPatchVectorField.C
+++ b/src/finiteVolume/fields/fvPatchFields/derived/pressureInletVelocity/pressureInletVelocityFvPatchVectorField.C
@@ -146,14 +146,8 @@ void pressureInletVelocityFvPatchVectorField::updateCoeffs()
 void pressureInletVelocityFvPatchVectorField::write(Ostream& os) const
 {
     fvPatchVectorField::write(os);
-    if (phiName_ != "phi")
-    {
-        os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl;
-    }
-    if (rhoName_ != "rho")
-    {
-        os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl;
-    }
+    writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
+    writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
     writeEntry("value", os);
 }
 
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingUniformTotalPressure/timeVaryingUniformTotalPressureFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingUniformTotalPressure/timeVaryingUniformTotalPressureFvPatchScalarField.C
index 1ee28c88a3a..ef5a22a6bf6 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingUniformTotalPressure/timeVaryingUniformTotalPressureFvPatchScalarField.C
+++ b/src/finiteVolume/fields/fvPatchFields/derived/timeVaryingUniformTotalPressure/timeVaryingUniformTotalPressureFvPatchScalarField.C
@@ -218,14 +218,8 @@ void Foam::timeVaryingUniformTotalPressureFvPatchScalarField::
 write(Ostream& os) const
 {
     fvPatchScalarField::write(os);
-    if (UName_ != "U")
-    {
-        os.writeKeyword("U") << UName_ << token::END_STATEMENT << nl;
-    }
-    if (phiName_ != "phi")
-    {
-        os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl;
-    }
+    writeEntryIfDifferent<word>(os, "U", "U", UName_);
+    writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
     os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl;
     os.writeKeyword("psi") << psiName_ << token::END_STATEMENT << nl;
     os.writeKeyword("gamma") << gamma_ << token::END_STATEMENT << nl;
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/totalTemperature/totalTemperatureFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/totalTemperature/totalTemperatureFvPatchScalarField.C
index 402ed3325f5..7554aa281d6 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/totalTemperature/totalTemperatureFvPatchScalarField.C
+++ b/src/finiteVolume/fields/fvPatchFields/derived/totalTemperature/totalTemperatureFvPatchScalarField.C
@@ -30,8 +30,6 @@ License
 #include "volFields.H"
 #include "surfaceFields.H"
 
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-
 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
 
 Foam::totalTemperatureFvPatchScalarField::totalTemperatureFvPatchScalarField
@@ -180,18 +178,9 @@ void Foam::totalTemperatureFvPatchScalarField::updateCoeffs()
 void Foam::totalTemperatureFvPatchScalarField::write(Ostream& os) const
 {
     fvPatchScalarField::write(os);
-    if (UName_ != "U")
-    {
-        os.writeKeyword("U") << UName_ << token::END_STATEMENT << nl;
-    }
-    if (phiName_ != "phi")
-    {
-        os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl;
-    }
-    if (psiName_ != "psi")
-    {
-        os.writeKeyword("psi") << psiName_ << token::END_STATEMENT << nl;
-    }
+    writeEntryIfDifferent<word>(os, "U", "U", UName_);
+    writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
+    writeEntryIfDifferent<word>(os, "psi", "psi", psiName_);
     os.writeKeyword("gamma") << gamma_ << token::END_STATEMENT << nl;
     T0_.writeEntry("T0", os);
     writeEntry("value", os);
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/turbulentIntensityKineticEnergyInlet/turbulentIntensityKineticEnergyInletFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/turbulentIntensityKineticEnergyInlet/turbulentIntensityKineticEnergyInletFvPatchScalarField.C
index c81934c111c..3aa3fccdae3 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/turbulentIntensityKineticEnergyInlet/turbulentIntensityKineticEnergyInletFvPatchScalarField.C
+++ b/src/finiteVolume/fields/fvPatchFields/derived/turbulentIntensityKineticEnergyInlet/turbulentIntensityKineticEnergyInletFvPatchScalarField.C
@@ -40,6 +40,7 @@ turbulentIntensityKineticEnergyInletFvPatchScalarField
 )
 :
     fixedValueFvPatchField<scalar>(p, iF),
+    UName_("U"),
     intensity_(0.05)
 {}
 
@@ -53,6 +54,7 @@ turbulentIntensityKineticEnergyInletFvPatchScalarField
 )
 :
     fixedValueFvPatchField<scalar>(ptf, p, iF, mapper),
+    UName_(ptf.UName_),
     intensity_(ptf.intensity_)
 {}
 
@@ -65,6 +67,7 @@ turbulentIntensityKineticEnergyInletFvPatchScalarField
 )
 :
     fixedValueFvPatchField<scalar>(p, iF, dict),
+    UName_(dict.lookupOrDefault<word>("U", "U")),
     intensity_(readScalar(dict.lookup("intensity")))
 {
     if (intensity_ < 0 || intensity_ > 1)
@@ -92,6 +95,7 @@ turbulentIntensityKineticEnergyInletFvPatchScalarField
 )
 :
     fixedValueFvPatchField<scalar>(ptf),
+    UName_(ptf.UName_),
     intensity_(ptf.intensity_)
 {}
 
@@ -104,6 +108,7 @@ turbulentIntensityKineticEnergyInletFvPatchScalarField
 )
 :
     fixedValueFvPatchField<scalar>(ptf, iF),
+    UName_(ptf.UName_),
     intensity_(ptf.intensity_)
 {}
 
@@ -119,7 +124,7 @@ updateCoeffs()
     }
 
     const fvPatchField<vector>& Up =
-        patch().lookupPatchField<volVectorField, vector>("U");
+        patch().lookupPatchField<volVectorField, vector>(UName_);
 
     operator==(1.5*sqr(intensity_)*magSqr(Up));
 
@@ -133,6 +138,7 @@ void Foam::turbulentIntensityKineticEnergyInletFvPatchScalarField::write
 ) const
 {
     fvPatchField<scalar>::write(os);
+    writeEntryIfDifferent<word>(os, "U", "U", UName_);
     os.writeKeyword("intensity") << intensity_ << token::END_STATEMENT << nl;
     writeEntry("value", os);
 }
diff --git a/src/finiteVolume/fields/fvPatchFields/derived/turbulentIntensityKineticEnergyInlet/turbulentIntensityKineticEnergyInletFvPatchScalarField.H b/src/finiteVolume/fields/fvPatchFields/derived/turbulentIntensityKineticEnergyInlet/turbulentIntensityKineticEnergyInletFvPatchScalarField.H
index 6b4dfdb1833..894f2b45208 100644
--- a/src/finiteVolume/fields/fvPatchFields/derived/turbulentIntensityKineticEnergyInlet/turbulentIntensityKineticEnergyInletFvPatchScalarField.H
+++ b/src/finiteVolume/fields/fvPatchFields/derived/turbulentIntensityKineticEnergyInlet/turbulentIntensityKineticEnergyInletFvPatchScalarField.H
@@ -34,6 +34,7 @@ Description
         inlet
         {
             type        turbulentIntensityKineticEnergyInlet;
+            U           U;              // Name of U field (optional)
             intensity   0.05;           // 5% turbulence
             value       uniform 1;      // placeholder
         }
@@ -64,6 +65,9 @@ class turbulentIntensityKineticEnergyInletFvPatchScalarField
 {
     // Private data
 
+        //- Name of belocity field
+        word UName_;
+
         //- Turbulent intensity as fraction of mean velocity
         scalar intensity_;
 
-- 
GitLab