From 4257d65bf496c97c54f381de6c361b87d015282e Mon Sep 17 00:00:00 2001
From: ToKiNoBug <tokinobug@163.com>
Date: Wed, 9 Jul 2025 20:21:48 +0800
Subject: [PATCH] Add pOffset to rhoThermo to support gauge pressure

---
 .../basic/rhoFluidThermo/RhoFluidThermo.C     | 44 ++++++++++---------
 .../basic/rhoFluidThermo/rhoFluidThermo.H     |  1 +
 .../basic/rhoThermo/rhoThermo.C               | 20 ++++++++-
 .../basic/rhoThermo/rhoThermo.H               | 14 +++++-
 4 files changed, 55 insertions(+), 24 deletions(-)

diff --git a/src/thermophysicalModels/basic/rhoFluidThermo/RhoFluidThermo.C b/src/thermophysicalModels/basic/rhoFluidThermo/RhoFluidThermo.C
index fec017b057..f304b74586 100644
--- a/src/thermophysicalModels/basic/rhoFluidThermo/RhoFluidThermo.C
+++ b/src/thermophysicalModels/basic/rhoFluidThermo/RhoFluidThermo.C
@@ -32,6 +32,8 @@ void Foam::RhoFluidThermo<BaseThermo>::calculate()
 {
     const scalarField& hCells = this->he();
     const scalarField& pCells = this->p_;
+    // Add pressureOffset to p, allowing gauge pressure
+    const scalar pressureOffset = this->pOffset().value();
 
     scalarField& TCells = this->T_.primitiveFieldRef();
     scalarField& CpCells = this->Cp_.primitiveFieldRef();
@@ -57,18 +59,18 @@ void Foam::RhoFluidThermo<BaseThermo>::calculate()
         TCells[celli] = thermoMixture.The
         (
             hCells[celli],
-            pCells[celli],
+            pCells[celli]+pressureOffset,
             TCells[celli]
         );
 
-        CpCells[celli] = thermoMixture.Cp(pCells[celli], TCells[celli]);
-        CvCells[celli] = thermoMixture.Cv(pCells[celli], TCells[celli]);
-        psiCells[celli] = thermoMixture.psi(pCells[celli], TCells[celli]);
-        rhoCells[celli] = thermoMixture.rho(pCells[celli], TCells[celli]);
+        CpCells[celli] = thermoMixture.Cp(pCells[celli]+pressureOffset, TCells[celli]);
+        CvCells[celli] = thermoMixture.Cv(pCells[celli]+pressureOffset, TCells[celli]);
+        psiCells[celli] = thermoMixture.psi(pCells[celli]+pressureOffset, TCells[celli]);
+        rhoCells[celli] = thermoMixture.rho(pCells[celli]+pressureOffset, TCells[celli]);
 
-        muCells[celli] = transportMixture.mu(pCells[celli], TCells[celli]);
+        muCells[celli] = transportMixture.mu(pCells[celli]+pressureOffset, TCells[celli]);
         kappaCells[celli] =
-            transportMixture.kappa(pCells[celli], TCells[celli]);
+            transportMixture.kappa(pCells[celli]+pressureOffset, TCells[celli]);
     }
 
     volScalarField::Boundary& pBf =
@@ -124,15 +126,15 @@ void Foam::RhoFluidThermo<BaseThermo>::calculate()
                     transportMixture =
                     this->transportMixture(composition, thermoMixture);
 
-                phe[facei] = thermoMixture.he(pp[facei], pT[facei]);
+                phe[facei] = thermoMixture.he(pp[facei]+pressureOffset, pT[facei]);
 
-                pCp[facei] = thermoMixture.Cp(pp[facei], pT[facei]);
-                pCv[facei] = thermoMixture.Cv(pp[facei], pT[facei]);
-                ppsi[facei] = thermoMixture.psi(pp[facei], pT[facei]);
-                prho[facei] = thermoMixture.rho(pp[facei], pT[facei]);
+                pCp[facei] = thermoMixture.Cp(pp[facei]+pressureOffset, pT[facei]);
+                pCv[facei] = thermoMixture.Cv(pp[facei]+pressureOffset, pT[facei]);
+                ppsi[facei] = thermoMixture.psi(pp[facei]+pressureOffset, pT[facei]);
+                prho[facei] = thermoMixture.rho(pp[facei]+pressureOffset, pT[facei]);
 
-                pmu[facei] = transportMixture.mu(pp[facei], pT[facei]);
-                pkappa[facei] = transportMixture.kappa(pp[facei], pT[facei]);
+                pmu[facei] = transportMixture.mu(pp[facei]+pressureOffset, pT[facei]);
+                pkappa[facei] = transportMixture.kappa(pp[facei]+pressureOffset, pT[facei]);
             }
         }
         else
@@ -149,15 +151,15 @@ void Foam::RhoFluidThermo<BaseThermo>::calculate()
                     transportMixture =
                     this->transportMixture(composition, thermoMixture);
 
-                pT[facei] = thermoMixture.The(phe[facei], pp[facei], pT[facei]);
+                pT[facei] = thermoMixture.The(phe[facei], pp[facei]+pressureOffset, pT[facei]);
 
-                pCp[facei] = thermoMixture.Cp(pp[facei], pT[facei]);
-                pCv[facei] = thermoMixture.Cv(pp[facei], pT[facei]);
-                ppsi[facei] = thermoMixture.psi(pp[facei], pT[facei]);
-                prho[facei] = thermoMixture.rho(pp[facei], pT[facei]);
+                pCp[facei] = thermoMixture.Cp(pp[facei]+pressureOffset, pT[facei]);
+                pCv[facei] = thermoMixture.Cv(pp[facei]+pressureOffset, pT[facei]);
+                ppsi[facei] = thermoMixture.psi(pp[facei]+pressureOffset, pT[facei]);
+                prho[facei] = thermoMixture.rho(pp[facei]+pressureOffset, pT[facei]);
 
-                pmu[facei] = transportMixture.mu(pp[facei], pT[facei]);
-                pkappa[facei] = transportMixture.kappa(pp[facei], pT[facei]);
+                pmu[facei] = transportMixture.mu(pp[facei]+pressureOffset, pT[facei]);
+                pkappa[facei] = transportMixture.kappa(pp[facei]+pressureOffset, pT[facei]);
             }
         }
     }
diff --git a/src/thermophysicalModels/basic/rhoFluidThermo/rhoFluidThermo.H b/src/thermophysicalModels/basic/rhoFluidThermo/rhoFluidThermo.H
index b0da199e72..5f69c055a1 100644
--- a/src/thermophysicalModels/basic/rhoFluidThermo/rhoFluidThermo.H
+++ b/src/thermophysicalModels/basic/rhoFluidThermo/rhoFluidThermo.H
@@ -55,6 +55,7 @@ namespace Foam
 class rhoFluidThermo
 :
     virtual public rhoThermo,
+    //virtual public rhoThermo,
     virtual public fluidThermo
 {
 public:
diff --git a/src/thermophysicalModels/basic/rhoThermo/rhoThermo.C b/src/thermophysicalModels/basic/rhoThermo/rhoThermo.C
index 2403b915ce..324589599c 100644
--- a/src/thermophysicalModels/basic/rhoThermo/rhoThermo.C
+++ b/src/thermophysicalModels/basic/rhoThermo/rhoThermo.C
@@ -18,7 +18,7 @@ License
     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     for more details.
 
-    You should have received a copy of the GNU General Public License
+    You should have received a copy of the GNU General Public Licensedisclose
     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
 
 \*---------------------------------------------------------------------------*/
@@ -46,8 +46,17 @@ Foam::rhoThermo::implementation::implementation
         ),
         mesh,
         dimDensity
+    ),
+    pOffset_(
+        dict.lookupOrDefault<dimensionedScalar>
+        (
+            "pOffset",
+            dimensionedScalar{"pOffset",dimPressure,0.0}
+        )
     )
-{}
+{
+    Info<<"Pressure offset is "<<this->pOffset().value()<<" Pa\n";
+}
 
 
 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
@@ -83,5 +92,12 @@ Foam::volScalarField& Foam::rhoThermo::implementation::rho()
     return rho_;
 }
 
+const Foam::dimensionedScalar & Foam::rhoThermo::implementation::pOffset() const {
+    return this->pOffset_;
+}
+
+Foam::dimensionedScalar & Foam::rhoThermo::implementation::pOffset() {
+    return this->pOffset_;
+}
 
 // ************************************************************************* //
diff --git a/src/thermophysicalModels/basic/rhoThermo/rhoThermo.H b/src/thermophysicalModels/basic/rhoThermo/rhoThermo.H
index c12d3831be..3193b04933 100644
--- a/src/thermophysicalModels/basic/rhoThermo/rhoThermo.H
+++ b/src/thermophysicalModels/basic/rhoThermo/rhoThermo.H
@@ -77,6 +77,12 @@ public:
 
             //- Return non-const access to the local density field [kg/m^3]
             virtual volScalarField& rho() = 0;
+
+            //- Pressure offset when correcting physical properties [Pa]
+            virtual const dimensionedScalar &pOffset() const = 0;
+
+            //- Return non-const access to pressure offset [Pa]
+            virtual dimensionedScalar& pOffset() = 0;
 };
 
 
@@ -94,7 +100,8 @@ protected:
 
         //- Density field [kg/m^3]
         volScalarField rho_;
-
+        //- Pressure offset when correcting physical properties [Pa]. 0 [Pa] by default.
+        dimensionedScalar pOffset_;
 
 public:
 
@@ -124,6 +131,11 @@ public:
             //- Return non-const access to the local density field [kg/m^3]
             virtual volScalarField& rho();
 
+            //- Pressure offset when correcting physical properties [Pa]
+            virtual const dimensionedScalar &pOffset() const;
+
+            //- Return non-const access to pressure offset [Pa]
+            virtual dimensionedScalar& pOffset();
 
     // Member Operators
 
-- 
2.50.0

