Nektar++
VanDerWaalsEoS.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: VanDerWaalsEoS.cpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description: Van der Waals equation of state
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#include "VanDerWaalsEoS.h"
36
37using namespace std;
38
39namespace Nektar
40{
41
42std::string VanDerWaalsEoS::className =
44 "VanDerWaals", VanDerWaalsEoS::create,
45 "Van der Waals equation of state.");
46
49 : EquationOfState(pSession)
50{
51 NekDouble Tcrit, Pcrit;
52 pSession->LoadParameter("Tcrit", Tcrit);
53 pSession->LoadParameter("Pcrit", Pcrit);
54
55 m_a = 27.0 / 64.0 * m_gasConstant * m_gasConstant * Tcrit * Tcrit / Pcrit;
56 m_b = 1.0 / 8.0 * m_gasConstant * Tcrit / Pcrit;
57}
58
60 const NekDouble &e)
61{
62 return GetTemperatureKernel(rho, e);
63}
64
66{
67 return GetTemperatureKernel(rho, e);
68}
69
71 const NekDouble &e)
72{
73 return GetPressureKernel(rho, e);
74}
75
77{
78 return GetPressureKernel(rho, e);
79}
80
82{
83 NekDouble T = GetTemperature(rho, e);
84 NekDouble sIg =
85 m_gasConstant / (m_gamma - 1) * log(T) - m_gasConstant * log(rho);
86
87 return sIg + m_gasConstant * log(1 - m_b * rho);
88}
89
91 const NekDouble &e)
92{
93 NekDouble result;
94
95 result = (m_gamma - 1) * (e + 2 * m_a * rho - m_a * m_b * rho * rho);
96 result = result / ((1 - m_b * rho) * (1 - m_b * rho));
97 result = result - 2 * m_a * rho;
98
99 return result;
100}
101
103 [[maybe_unused]] const NekDouble &e)
104{
105 return (m_gamma - 1) / (1.0 / rho - m_b);
106}
107
109 const NekDouble &p)
110{
111 return (p + m_a * rho * rho) * (1.0 / rho - m_b) / (m_gamma - 1) -
112 m_a * rho;
113}
114
116{
117 // First solve for the compressibility factor Z using the cubic equation
118 // Z^3 + k1 * Z^2 + k2 * Z + k3 = 0
119 // for van der Waals:
120 // k1 = -(B+1), k2 = A, k3 = -AB
121 // where A = aP/(RT)^2, B = bP/(RT)
122 NekDouble A = m_a * p / (m_gasConstant * m_gasConstant * T * T);
123 NekDouble B = m_b * p / (m_gasConstant * T);
124
125 NekDouble k1 = -(B + 1);
126 NekDouble k2 = A;
127 NekDouble k3 = -A * B;
128
129 // Use ideal gas (Z=1) as starting guess for iteration
130 NekDouble Z = 1.0;
131 // Newton-Raphson iteration to find Z
132 NekDouble tol = 1e-6;
133 NekDouble maxIter = 100;
134 NekDouble residual = 1;
135 NekDouble f, df;
136 unsigned int cnt = 0;
137 while (abs(residual) > tol && cnt < maxIter)
138 {
139 f = Z * Z * Z + k1 * Z * Z + k2 * Z + k3;
140 df = 3 * Z * Z + 2 * k1 * Z + k2;
141 residual = f / df;
142 Z -= residual;
143 ++cnt;
144 }
145 if (cnt == maxIter)
146 {
147 cout << "Newton-Raphson in VanDerWaalsEoS::v_GetRhoFromPT did not "
148 "converge in "
149 << maxIter << " iterations (residual = " << residual << ")"
150 << endl;
151 }
152
153 // Now calculate rho = p/(ZRT)
154 return p / (Z * m_gasConstant * T);
155}
156} // namespace Nektar
Encapsulates equations of state allowing us to obtain thermodynamic properties: most relations are in...
NekDouble GetTemperature(const NekDouble &rho, const NekDouble &e)
Calculate the temperature.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:197
NekDouble v_GetPressure(const NekDouble &rho, const NekDouble &e) final
T GetTemperatureKernel(const T &rho, const T &e)
static EquationOfStateSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession)
Creates an instance of this class.
NekDouble v_GetEntropy(const NekDouble &rho, const NekDouble &e) final
NekDouble v_GetTemperature(const NekDouble &rho, const NekDouble &e) final
T GetPressureKernel(const T &rho, const T &e)
NekDouble v_GetEFromRhoP(const NekDouble &rho, const NekDouble &p) final
VanDerWaalsEoS(const LibUtilities::SessionReaderSharedPtr &pSession)
NekDouble v_GetDPDe_rho(const NekDouble &rho, const NekDouble &e) final
NekDouble v_GetRhoFromPT(const NekDouble &rho, const NekDouble &p) final
NekDouble v_GetDPDrho_e(const NekDouble &rho, const NekDouble &e) final
static std::string className
Name of the class.
std::shared_ptr< SessionReader > SessionReaderSharedPtr
EquationOfStateFactory & GetEquationOfStateFactory()
Declaration of the equation of state factory singleton.
tinysimd::simd< NekDouble > vec_t
double NekDouble
scalarT< T > abs(scalarT< T > in)
Definition: scalar.hpp:298
scalarT< T > log(scalarT< T > in)
Definition: scalar.hpp:303