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

van der Waals equation of state: p = RT/(1/rho - b) - a * rho^2 with a = 27/64 * (R*Tc)^2 / Pc b = 1/8 * (R*Tc) / Pc More...

#include <VanDerWaalsEoS.h>

Inheritance diagram for Nektar::VanDerWaalsEoS:
[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
 
- Protected Attributes inherited from Nektar::EquationOfState
NekDouble m_gamma
 
NekDouble m_gasConstant
 
NekDouble m_gammaMone
 
NekDouble m_gammaMoneOgasConst
 

Private Member Functions

 VanDerWaalsEoS (const LibUtilities::SessionReaderSharedPtr &pSession)
 
 ~VanDerWaalsEoS (void) override
 
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< VanDerWaalsEoS >
 

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

van der Waals equation of state: p = RT/(1/rho - b) - a * rho^2 with a = 27/64 * (R*Tc)^2 / Pc b = 1/8 * (R*Tc) / Pc

Definition at line 49 of file VanDerWaalsEoS.h.

Constructor & Destructor Documentation

◆ VanDerWaalsEoS()

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

Definition at line 47 of file VanDerWaalsEoS.cpp.

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}
EquationOfState(const LibUtilities::SessionReaderSharedPtr &pSession)
Constructor.
double NekDouble

References m_a, m_b, and Nektar::EquationOfState::m_gasConstant.

◆ ~VanDerWaalsEoS()

Nektar::VanDerWaalsEoS::~VanDerWaalsEoS ( void  )
inlineoverrideprivate

Definition at line 91 of file VanDerWaalsEoS.h.

91{};

Member Function Documentation

◆ create()

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

Creates an instance of this class.

Definition at line 55 of file VanDerWaalsEoS.h.

57 {
60 return p;
61 }
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::VanDerWaalsEoS::GetPressureKernel ( const T &  rho,
const T &  e 
)
inlineprivate

Definition at line 104 of file VanDerWaalsEoS.h.

105 {
106 return (e + m_a * rho) * (m_gamma - 1) / (1.0 / rho - m_b) -
107 m_a * rho * rho;
108 }

References m_a, m_b, and Nektar::EquationOfState::m_gamma.

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::VanDerWaalsEoS::GetTemperatureKernel ( const T &  rho,
const T &  e 
)
inlineprivate

Definition at line 96 of file VanDerWaalsEoS.h.

97 {
98 return (e + m_a * rho) * (m_gamma - 1) / m_gasConstant;
99 }

References m_a, Nektar::EquationOfState::m_gamma, and Nektar::EquationOfState::m_gasConstant.

Referenced by v_GetTemperature().

◆ v_GetDPDe_rho()

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

Implements Nektar::EquationOfState.

Definition at line 102 of file VanDerWaalsEoS.cpp.

104{
105 return (m_gamma - 1) / (1.0 / rho - m_b);
106}

References m_b, and Nektar::EquationOfState::m_gamma.

◆ v_GetDPDrho_e()

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

Implements Nektar::EquationOfState.

Definition at line 90 of file VanDerWaalsEoS.cpp.

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}

References m_a, m_b, and Nektar::EquationOfState::m_gamma.

◆ v_GetEFromRhoP()

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

Implements Nektar::EquationOfState.

Definition at line 108 of file VanDerWaalsEoS.cpp.

110{
111 return (p + m_a * rho * rho) * (1.0 / rho - m_b) / (m_gamma - 1) -
112 m_a * rho;
113}

References m_a, m_b, Nektar::EquationOfState::m_gamma, and CellMLToNektar.cellml_metadata::p.

◆ v_GetEntropy()

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

Implements Nektar::EquationOfState.

Definition at line 81 of file VanDerWaalsEoS.cpp.

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}
NekDouble GetTemperature(const NekDouble &rho, const NekDouble &e)
Calculate the temperature.
scalarT< T > log(scalarT< T > in)
Definition: scalar.hpp:303

References Nektar::EquationOfState::GetTemperature(), tinysimd::log(), m_b, Nektar::EquationOfState::m_gamma, and Nektar::EquationOfState::m_gasConstant.

◆ v_GetPressure() [1/2]

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

Implements Nektar::EquationOfState.

Definition at line 70 of file VanDerWaalsEoS.cpp.

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

References GetPressureKernel().

◆ v_GetPressure() [2/2]

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

Implements Nektar::EquationOfState.

Definition at line 76 of file VanDerWaalsEoS.cpp.

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

References GetPressureKernel().

◆ v_GetRhoFromPT()

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

Implements Nektar::EquationOfState.

Definition at line 115 of file VanDerWaalsEoS.cpp.

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}
scalarT< T > abs(scalarT< T > in)
Definition: scalar.hpp:298

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

◆ v_GetTemperature() [1/2]

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

Implements Nektar::EquationOfState.

Definition at line 59 of file VanDerWaalsEoS.cpp.

61{
62 return GetTemperatureKernel(rho, e);
63}
T GetTemperatureKernel(const T &rho, const T &e)

References GetTemperatureKernel().

◆ v_GetTemperature() [2/2]

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

Implements Nektar::EquationOfState.

Definition at line 65 of file VanDerWaalsEoS.cpp.

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

References GetTemperatureKernel().

Friends And Related Function Documentation

◆ MemoryManager< VanDerWaalsEoS >

friend class MemoryManager< VanDerWaalsEoS >
friend

Definition at line 1 of file VanDerWaalsEoS.h.

Member Data Documentation

◆ className

std::string Nektar::VanDerWaalsEoS::className
static
Initial value:
=
"VanDerWaals", VanDerWaalsEoS::create,
"Van der Waals 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 64 of file VanDerWaalsEoS.h.

◆ m_a

NekDouble Nektar::VanDerWaalsEoS::m_a
protected

◆ m_b

NekDouble Nektar::VanDerWaalsEoS::m_b
protected