Nektar++
Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Friends | List of all members
Nektar::PengRobinsonEoS Class Reference

Peng-Robinson equation of state: p = RT/(1/rho - b) - a*Alpha(T/Tc) / (1/rho^2 + 2*b/rho - b^2) with a = 0.45724 * (R*Tc)^2 / Pc b = 0.0778 * (R*Tc) / Pc Alpha(T/Tc) = [1 + fw * (1 - sqrt(T/ Tc))]^2 fw = 0.37464 + 1.54226*omega - 0.2699*omega*omega. More...

#include <PengRobinsonEoS.h>

Inheritance diagram for Nektar::PengRobinsonEoS:
[legend]

Static Public Member Functions

static EquationOfStateSharedPtr create (const LibUtilities::SessionReaderSharedPtr &pSession)
 Creates an instance of this class. More...
 

Static Public Attributes

static std::string className
 Name of the class. More...
 

Protected Member Functions

NekDouble v_GetTemperature (const NekDouble &rho, const NekDouble &e) final
 
vec_t v_GetTemperature (const vec_t &rho, const vec_t &e) final
 
NekDouble v_GetPressure (const NekDouble &rho, const NekDouble &e) final
 
vec_t v_GetPressure (const vec_t &rho, const vec_t &e) final
 
NekDouble v_GetEntropy (const NekDouble &rho, const NekDouble &e) final
 
NekDouble v_GetDPDrho_e (const NekDouble &rho, const NekDouble &e) final
 
NekDouble v_GetDPDe_rho (const NekDouble &rho, const NekDouble &e) final
 
NekDouble v_GetEFromRhoP (const NekDouble &rho, const NekDouble &p) final
 
NekDouble v_GetRhoFromPT (const NekDouble &rho, const NekDouble &p) final
 
- Protected Member Functions inherited from Nektar::EquationOfState
 EquationOfState (const LibUtilities::SessionReaderSharedPtr &pSession)
 Constructor. More...
 
 EquationOfState (const NekDouble &gamma, const NekDouble &gasConstant)
 Programmatic Constructor. More...
 
virtual NekDouble v_GetTemperature (const NekDouble &rho, const NekDouble &e)=0
 
virtual vec_t v_GetTemperature (const vec_t &rho, const vec_t &e)=0
 
virtual NekDouble v_GetPressure (const NekDouble &rho, const NekDouble &e)=0
 
virtual vec_t v_GetPressure (const vec_t &rho, const vec_t &e)=0
 
virtual NekDouble v_GetSoundSpeed (const NekDouble &rho, const NekDouble &e)
 
virtual NekDouble v_GetEntropy (const NekDouble &rho, const NekDouble &e)=0
 
virtual NekDouble v_GetDPDrho_e (const NekDouble &rho, const NekDouble &e)=0
 
virtual NekDouble v_GetDPDe_rho (const NekDouble &rho, const NekDouble &e)=0
 
virtual NekDouble v_GetEFromRhoP (const NekDouble &rho, const NekDouble &p)=0
 
virtual NekDouble v_GetRhoFromPT (const NekDouble &rho, const NekDouble &p)=0
 

Protected Attributes

NekDouble m_a
 
NekDouble m_b
 
NekDouble m_Tc
 
NekDouble m_Pc
 
NekDouble m_omega
 
NekDouble m_fw
 
- Protected Attributes inherited from Nektar::EquationOfState
NekDouble m_gamma
 
NekDouble m_gasConstant
 
NekDouble m_gammaMone
 
NekDouble m_gammaMoneOgasConst
 

Private Member Functions

 PengRobinsonEoS (const LibUtilities::SessionReaderSharedPtr &pSession)
 
 ~PengRobinsonEoS (void) override
 
template<class T , typename = typename std::enable_if< std::is_floating_point<T>::value || tinysimd::is_vector_floating_point<T>::value>::type>
Alpha (const T &temp)
 
template<class T , typename = typename std::enable_if< std::is_floating_point<T>::value || tinysimd::is_vector_floating_point<T>::value>::type>
LogTerm (const T &rho)
 
template<class T , typename = typename std::enable_if< std::is_floating_point<T>::value || tinysimd::is_vector_floating_point<T>::value>::type>
GetTemperatureKernel (const T &rho, const T &e)
 
template<class T , typename = typename std::enable_if< std::is_floating_point<T>::value || tinysimd::is_vector_floating_point<T>::value>::type>
GetPressureKernel (const T &rho, const T &e)
 

Friends

class MemoryManager< PengRobinsonEoS >
 

Additional Inherited Members

- Public Member Functions inherited from Nektar::EquationOfState
virtual ~EquationOfState ()
 
NekDouble GetTemperature (const NekDouble &rho, const NekDouble &e)
 Calculate the temperature. More...
 
vec_t GetTemperature (const vec_t &rho, const vec_t &e)
 
NekDouble GetPressure (const NekDouble &rho, const NekDouble &e)
 Calculate the pressure. More...
 
vec_t GetPressure (const vec_t &rho, const vec_t &e)
 
NekDouble GetSoundSpeed (const NekDouble &rho, const NekDouble &e)
 Calculate the sound speed. More...
 
NekDouble GetEntropy (const NekDouble &rho, const NekDouble &e)
 Calculate the entropy. More...
 
NekDouble GetDPDrho_e (const NekDouble &rho, const NekDouble &e)
 Calculate the partial derivative of P(rho,e) with respect to rho. More...
 
NekDouble GetDPDe_rho (const NekDouble &rho, const NekDouble &e)
 Calculate the partial derivative of P(rho,e) with respect to e. More...
 
NekDouble GetEFromRhoP (const NekDouble &rho, const NekDouble &p)
 Obtain the internal energy from rho and P. More...
 
NekDouble GetRhoFromPT (const NekDouble &p, const NekDouble &T)
 Obtain the density from P and T. More...
 

Detailed Description

Peng-Robinson equation of state: p = RT/(1/rho - b) - a*Alpha(T/Tc) / (1/rho^2 + 2*b/rho - b^2) with a = 0.45724 * (R*Tc)^2 / Pc b = 0.0778 * (R*Tc) / Pc Alpha(T/Tc) = [1 + fw * (1 - sqrt(T/ Tc))]^2 fw = 0.37464 + 1.54226*omega - 0.2699*omega*omega.

Definition at line 51 of file PengRobinsonEoS.h.

Constructor & Destructor Documentation

◆ PengRobinsonEoS()

Nektar::PengRobinsonEoS::PengRobinsonEoS ( const LibUtilities::SessionReaderSharedPtr pSession)
private

Definition at line 47 of file PengRobinsonEoS.cpp.

49 : EquationOfState(pSession)
50{
51 pSession->LoadParameter("Tcrit", m_Tc);
52 pSession->LoadParameter("Pcrit", m_Pc);
53 pSession->LoadParameter("AcentricFactor", m_omega);
54
55 m_a = 0.45724 * m_gasConstant * m_gasConstant * m_Tc * m_Tc / m_Pc;
56 m_b = 0.0778 * m_gasConstant * m_Tc / m_Pc;
57 m_fw = 0.37464 + 1.54226 * m_omega - 0.2699 * m_omega * m_omega;
58}
EquationOfState(const LibUtilities::SessionReaderSharedPtr &pSession)
Constructor.

References m_a, m_b, m_fw, Nektar::EquationOfState::m_gasConstant, m_omega, m_Pc, and m_Tc.

◆ ~PengRobinsonEoS()

Nektar::PengRobinsonEoS::~PengRobinsonEoS ( void  )
inlineoverrideprivate

Definition at line 97 of file PengRobinsonEoS.h.

97{};

Member Function Documentation

◆ Alpha()

template<class T , typename = typename std::enable_if< std::is_floating_point<T>::value || tinysimd::is_vector_floating_point<T>::value>::type>
T Nektar::PengRobinsonEoS::Alpha ( const T &  temp)
inlineprivate

Definition at line 103 of file PengRobinsonEoS.h.

104 {
105 T sqrtAlpha = 1.0 + m_fw * (1.0 - sqrt(temp / m_Tc));
106 return sqrtAlpha * sqrtAlpha;
107 }
scalarT< T > sqrt(scalarT< T > in)
Definition: scalar.hpp:294

References m_fw, m_Tc, and tinysimd::sqrt().

Referenced by GetPressureKernel(), v_GetDPDe_rho(), v_GetDPDrho_e(), v_GetEFromRhoP(), v_GetEntropy(), and v_GetRhoFromPT().

◆ create()

static EquationOfStateSharedPtr Nektar::PengRobinsonEoS::create ( const LibUtilities::SessionReaderSharedPtr pSession)
inlinestatic

Creates an instance of this class.

Definition at line 57 of file PengRobinsonEoS.h.

59 {
62 return p;
63 }
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
std::shared_ptr< EquationOfState > EquationOfStateSharedPtr
A shared pointer to an equation of state object.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), and CellMLToNektar.cellml_metadata::p.

◆ GetPressureKernel()

template<class T , typename = typename std::enable_if< std::is_floating_point<T>::value || tinysimd::is_vector_floating_point<T>::value>::type>
T Nektar::PengRobinsonEoS::GetPressureKernel ( const T &  rho,
const T &  e 
)
inlineprivate

Definition at line 147 of file PengRobinsonEoS.h.

148 {
149 T temp = GetTemperatureKernel(rho, e);
150 T oneOrho = 1.0 / rho;
151 T p = m_gasConstant * temp / (oneOrho - m_b) -
152 m_a * Alpha(temp) /
153 (oneOrho * oneOrho + 2.0 * m_b * oneOrho - m_b * m_b);
154
155 return p;
156 }
T GetTemperatureKernel(const T &rho, const T &e)
T Alpha(const T &temp)

References Alpha(), GetTemperatureKernel(), m_a, m_b, Nektar::EquationOfState::m_gasConstant, and CellMLToNektar.cellml_metadata::p.

Referenced by v_GetPressure().

◆ GetTemperatureKernel()

template<class T , typename = typename std::enable_if< std::is_floating_point<T>::value || tinysimd::is_vector_floating_point<T>::value>::type>
T Nektar::PengRobinsonEoS::GetTemperatureKernel ( const T &  rho,
const T &  e 
)
inlineprivate

Definition at line 122 of file PengRobinsonEoS.h.

123 {
124 // First we need to evaluate the log term
125 // ln[(1/rho + b - b*sqrt(2)) / (1/rho + b + b*sqrt(2))]
126 NekDouble sqrt2 = sqrt(2.0);
127 T logTerm = LogTerm(rho);
128
129 // The temperature can be expressed as an equation in the form
130 // A * (T^1/2)^2 + B * T^1/2 + C = 0
131
132 NekDouble A = m_gasConstant / (m_gamma - 1.0);
133 NekDouble f1 = m_a / (m_b * 2.0 * sqrt2);
134 NekDouble f2 = (1.0 + m_fw);
135 T B = -f1 * logTerm / sqrt(m_Tc) * m_fw * f2;
136 T C = f1 * logTerm * f2 * f2 - e;
137
138 // Solve for T^1/2 (positive root)
139 T sqrtT = (sqrt(B * B - 4 * A * C) - B) / (2 * A);
140 // Calculate the temperature
141 return sqrtT * sqrtT;
142 }
double NekDouble

References LogTerm(), m_a, m_b, m_fw, Nektar::EquationOfState::m_gamma, Nektar::EquationOfState::m_gasConstant, m_Tc, and tinysimd::sqrt().

Referenced by GetPressureKernel(), and v_GetTemperature().

◆ LogTerm()

template<class T , typename = typename std::enable_if< std::is_floating_point<T>::value || tinysimd::is_vector_floating_point<T>::value>::type>
T Nektar::PengRobinsonEoS::LogTerm ( const T &  rho)
inlineprivate

Definition at line 113 of file PengRobinsonEoS.h.

114 {
115 return log((1.0 / rho + m_b - m_b * sqrt(2)) /
116 (1.0 / rho + m_b + m_b * sqrt(2)));
117 }
scalarT< T > log(scalarT< T > in)
Definition: scalar.hpp:303

References tinysimd::log(), m_b, and tinysimd::sqrt().

Referenced by GetTemperatureKernel(), v_GetDPDe_rho(), v_GetEFromRhoP(), and v_GetEntropy().

◆ v_GetDPDe_rho()

NekDouble Nektar::PengRobinsonEoS::v_GetDPDe_rho ( const NekDouble rho,
const NekDouble e 
)
finalprotectedvirtual

Implements Nektar::EquationOfState.

Definition at line 126 of file PengRobinsonEoS.cpp.

128{
129 NekDouble T = GetTemperature(rho, e);
130 NekDouble logTerm = LogTerm(rho);
131
132 // First calculate the denominator 1/rho^2 + 2*b/rho - b^2
133 // and sqrt(Alpha) = 1+f_w*(1-sqrt(Tr))
134 NekDouble denom = 1.0 / (rho * rho) + 2.0 * m_b / rho - m_b * m_b;
135 NekDouble sqrtA = sqrt(Alpha(T));
136
137 // Compute cv = dedT_rho
138 NekDouble cv = m_gasConstant / (m_gamma - 1) -
139 m_a / (2 * m_b * sqrt(8)) * logTerm * (m_fw * (1 + m_fw)) /
140 sqrt(T * m_Tc);
141
142 // Now we obtain dPdT_rho
143 NekDouble dPdT = m_gasConstant / (1.0 / rho - m_b) +
144 m_a / sqrt(T * m_Tc) * m_fw * sqrtA / denom;
145
146 // The result is dPde_rho = dPdT_rho / cv
147 return dPdT / cv;
148}
NekDouble GetTemperature(const NekDouble &rho, const NekDouble &e)
Calculate the temperature.

References Alpha(), Nektar::EquationOfState::GetTemperature(), LogTerm(), m_a, m_b, m_fw, Nektar::EquationOfState::m_gamma, Nektar::EquationOfState::m_gasConstant, m_Tc, and tinysimd::sqrt().

◆ v_GetDPDrho_e()

NekDouble Nektar::PengRobinsonEoS::v_GetDPDrho_e ( const NekDouble rho,
const NekDouble e 
)
finalprotectedvirtual

Implements Nektar::EquationOfState.

Definition at line 101 of file PengRobinsonEoS.cpp.

103{
104 NekDouble T = GetTemperature(rho, e);
105 NekDouble dPde = GetDPDe_rho(rho, e);
106
107 // First calculate the denominator 1/rho^2 + 2*b/rho - b^2
108 // and alpha = [1+f_w*(1-sqrt(Tr))]^2
109 NekDouble denom = 1.0 / (rho * rho) + 2.0 * m_b / rho - m_b * m_b;
110 NekDouble alpha = Alpha(T);
111
112 // Calculate dPdrho_T
113 NekDouble dPdrho_T =
114 m_gasConstant * T / ((1.0 - m_b * rho) * (1.0 - m_b * rho)) -
115 2 * m_a * alpha * rho * (1 + m_b * rho) /
116 ((denom * rho * rho) * (denom * rho * rho));
117
118 // Calculate dedrho_T
119 NekDouble dedrho_T =
120 -m_a * sqrt(alpha) * (1.0 + m_fw) / (denom * rho * rho);
121
122 // The result is dPdrho_e = dPdrho_T - dPde_rho * dedrho_T
123 return dPdrho_T - dPde * dedrho_T;
124}
NekDouble GetDPDe_rho(const NekDouble &rho, const NekDouble &e)
Calculate the partial derivative of P(rho,e) with respect to e.

References Alpha(), Nektar::EquationOfState::GetDPDe_rho(), Nektar::EquationOfState::GetTemperature(), m_a, m_b, m_fw, Nektar::EquationOfState::m_gasConstant, and tinysimd::sqrt().

◆ v_GetEFromRhoP()

NekDouble Nektar::PengRobinsonEoS::v_GetEFromRhoP ( const NekDouble rho,
const NekDouble p 
)
finalprotectedvirtual

Implements Nektar::EquationOfState.

Definition at line 150 of file PengRobinsonEoS.cpp.

152{
153 NekDouble denom = 1.0 / (rho * rho) + 2.0 * m_b / rho - m_b * m_b;
154 NekDouble logTerm = LogTerm(rho);
155 // First we solve for the temperature, which can be expressed as
156 // A * (T^1/2)^2 + B * T^1/2 + C = 0
157 NekDouble A, B, C;
158
159 A = m_gasConstant / (1.0 / rho - m_b) -
160 (m_a * m_fw * m_fw) / (denom * m_Tc);
161 B = 2 * m_a / denom * m_fw * (1.0 + m_fw) / sqrt(m_Tc);
162 C = -m_a * (1.0 + m_fw) * (1 + m_fw) / denom - p;
163
164 // Solve for T^1/2 (positive root)
165 NekDouble T = (-B + sqrt(B * B - 4 * A * C)) / (2 * A);
166 T = T * T;
167
168 // Calculate alpha(T))
169 NekDouble alpha = Alpha(T);
170 // sqrt(Tr)
171 NekDouble sqrtTr = sqrt(T / m_Tc);
172 // Calculate internal energy
173 return m_gasConstant * T / (m_gamma - 1) +
174 m_a / (m_b * sqrt(8)) * logTerm *
175 (alpha + sqrt(alpha) * m_fw * sqrtTr);
176}

References Alpha(), LogTerm(), m_a, m_b, m_fw, Nektar::EquationOfState::m_gamma, Nektar::EquationOfState::m_gasConstant, m_Tc, CellMLToNektar.cellml_metadata::p, and tinysimd::sqrt().

◆ v_GetEntropy()

NekDouble Nektar::PengRobinsonEoS::v_GetEntropy ( const NekDouble rho,
const NekDouble e 
)
finalprotectedvirtual

Implements Nektar::EquationOfState.

Definition at line 82 of file PengRobinsonEoS.cpp.

84{
85 NekDouble T = GetTemperature(rho, e);
86 NekDouble logTerm = LogTerm(rho);
87 // Entropy for an ideal gas
88 NekDouble sIg =
89 m_gasConstant / (m_gamma - 1) * log(T) - m_gasConstant * log(rho);
90
91 // First sqrt(Alpha) = 1+_w*(1-sqrt(Tr)) and sqrt(Tr)
92 NekDouble sqrtA = sqrt(Alpha(T));
93 NekDouble sqrtTr = sqrt(T / m_Tc);
94
95 NekDouble deltaS = m_gasConstant * log(1 - m_b * rho);
96 deltaS += m_a * sqrtA * m_fw * logTerm * (sqrtTr / T) / (m_b * sqrt(8));
97
98 return sIg + deltaS;
99}

References Alpha(), Nektar::EquationOfState::GetTemperature(), tinysimd::log(), LogTerm(), m_a, m_b, m_fw, Nektar::EquationOfState::m_gamma, Nektar::EquationOfState::m_gasConstant, m_Tc, and tinysimd::sqrt().

◆ v_GetPressure() [1/2]

NekDouble Nektar::PengRobinsonEoS::v_GetPressure ( const NekDouble rho,
const NekDouble e 
)
finalprotectedvirtual

Implements Nektar::EquationOfState.

Definition at line 71 of file PengRobinsonEoS.cpp.

73{
74 return GetPressureKernel(rho, e);
75}
T GetPressureKernel(const T &rho, const T &e)

References GetPressureKernel().

◆ v_GetPressure() [2/2]

vec_t Nektar::PengRobinsonEoS::v_GetPressure ( const vec_t rho,
const vec_t e 
)
finalprotectedvirtual

Implements Nektar::EquationOfState.

Definition at line 77 of file PengRobinsonEoS.cpp.

78{
79 return GetPressureKernel(rho, e);
80}

References GetPressureKernel().

◆ v_GetRhoFromPT()

NekDouble Nektar::PengRobinsonEoS::v_GetRhoFromPT ( const NekDouble rho,
const NekDouble p 
)
finalprotectedvirtual

Implements Nektar::EquationOfState.

Definition at line 178 of file PengRobinsonEoS.cpp.

180{
181 // First solve for the compressibility factor Z using the cubic equation
182 // Z^3 + k1 * Z^2 + k2 * Z + k3 = 0
183 // for PengRobinson:
184 // k1 = B-1, k2 = A - 2*B - 3*B^2, k3 = - AB + B^2 + B^3
185 // where A = a*alpha(T)*P/(RT)^2, B = bP/(RT)
186 NekDouble A = m_a * Alpha(T) * p / (m_gasConstant * m_gasConstant * T * T);
187 NekDouble B = m_b * p / (m_gasConstant * T);
188
189 NekDouble k1 = B - 1.0;
190 NekDouble k2 = A - 2 * B - 3 * B * B;
191 NekDouble k3 = -A * B + B * B + B * B * B;
192
193 // Use ideal gas (Z=1) as starting guess for iteration
194 NekDouble Z = 1.0;
195 // Newton-Raphson iteration to find Z
196 NekDouble tol = 1e-6;
197 NekDouble maxIter = 100;
198 NekDouble residual = 1;
199 NekDouble f, df;
200 unsigned int cnt = 0;
201 while ((fabs(residual) > tol) && cnt < maxIter)
202 {
203 f = Z * Z * Z + k1 * Z * Z + k2 * Z + k3;
204 df = 3 * Z * Z + 2 * k1 * Z + k2;
205 residual = f / df;
206 Z -= residual;
207 ++cnt;
208 }
209 if (cnt == maxIter)
210 {
211 cout << "Newton-Raphson in PengRobinsonEoS::v_GetRhoFromPT did not "
212 "converge in "
213 << maxIter << " iterations (residual = " << residual << ")"
214 << endl;
215 }
216
217 // Now calculate rho = p/(ZRT)
218 return p / (Z * m_gasConstant * T);
219}

References Alpha(), m_a, m_b, Nektar::EquationOfState::m_gasConstant, and CellMLToNektar.cellml_metadata::p.

◆ v_GetTemperature() [1/2]

NekDouble Nektar::PengRobinsonEoS::v_GetTemperature ( const NekDouble rho,
const NekDouble e 
)
finalprotectedvirtual

Implements Nektar::EquationOfState.

Definition at line 60 of file PengRobinsonEoS.cpp.

62{
63 return GetTemperatureKernel(rho, e);
64}

References GetTemperatureKernel().

◆ v_GetTemperature() [2/2]

vec_t Nektar::PengRobinsonEoS::v_GetTemperature ( const vec_t rho,
const vec_t e 
)
finalprotectedvirtual

Implements Nektar::EquationOfState.

Definition at line 66 of file PengRobinsonEoS.cpp.

67{
68 return GetTemperatureKernel(rho, e);
69}

References GetTemperatureKernel().

Friends And Related Function Documentation

◆ MemoryManager< PengRobinsonEoS >

friend class MemoryManager< PengRobinsonEoS >
friend

Definition at line 1 of file PengRobinsonEoS.h.

Member Data Documentation

◆ className

std::string Nektar::PengRobinsonEoS::className
static
Initial value:
=
"PengRobinson", PengRobinsonEoS::create,
"Peng-Robinson equation of state.")
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:197
static EquationOfStateSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession)
Creates an instance of this class.
EquationOfStateFactory & GetEquationOfStateFactory()
Declaration of the equation of state factory singleton.

Name of the class.

Definition at line 66 of file PengRobinsonEoS.h.

◆ m_a

NekDouble Nektar::PengRobinsonEoS::m_a
protected

◆ m_b

NekDouble Nektar::PengRobinsonEoS::m_b
protected

◆ m_fw

NekDouble Nektar::PengRobinsonEoS::m_fw
protected

◆ m_omega

NekDouble Nektar::PengRobinsonEoS::m_omega
protected

Definition at line 73 of file PengRobinsonEoS.h.

Referenced by PengRobinsonEoS().

◆ m_Pc

NekDouble Nektar::PengRobinsonEoS::m_Pc
protected

Definition at line 72 of file PengRobinsonEoS.h.

Referenced by PengRobinsonEoS().

◆ m_Tc

NekDouble Nektar::PengRobinsonEoS::m_Tc
protected