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

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

Protected Attributes

NekDouble m_a
 
NekDouble m_b
 
- Protected Attributes inherited from Nektar::EquationOfState
NekDouble m_gamma
 
NekDouble m_gasConstant
 

Private Member Functions

 VanDerWaalsEoS (const LibUtilities::SessionReaderSharedPtr &pSession)
 
virtual ~VanDerWaalsEoS (void)
 

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...
 
NekDouble GetPressure (const NekDouble &rho, const NekDouble &e)
 Calculate the pressure. More...
 
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 49 of file VanDerWaalsEoS.cpp.

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

51  : EquationOfState(pSession)
52 {
53  NekDouble Tcrit, Pcrit;
54  pSession->LoadParameter("Tcrit", Tcrit);
55  pSession->LoadParameter("Pcrit", Pcrit);
56 
57  m_a = 27.0 / 64.0 * m_gasConstant * m_gasConstant * Tcrit * Tcrit / Pcrit;
58  m_b = 1.0 / 8.0 * m_gasConstant * Tcrit / Pcrit;
59 }
EquationOfState(const LibUtilities::SessionReaderSharedPtr &pSession)
Constructor.
double NekDouble

◆ ~VanDerWaalsEoS()

virtual Nektar::VanDerWaalsEoS::~VanDerWaalsEoS ( void  )
inlineprivatevirtual

Definition at line 88 of file VanDerWaalsEoS.h.

88 {};

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.

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

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.

◆ v_GetDPDe_rho()

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

Implements Nektar::EquationOfState.

Definition at line 95 of file VanDerWaalsEoS.cpp.

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

97 {
98  boost::ignore_unused(e);
99  return (m_gamma - 1) / (1.0 / rho - m_b);
100 }

◆ v_GetDPDrho_e()

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

Implements Nektar::EquationOfState.

Definition at line 83 of file VanDerWaalsEoS.cpp.

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

85 {
86  NekDouble result;
87 
88  result = (m_gamma - 1) * (e + 2 * m_a * rho - m_a * m_b * rho * rho);
89  result = result / ((1 - m_b * rho) * (1 - m_b * rho));
90  result = result - 2 * m_a * rho;
91 
92  return result;
93 }
double NekDouble

◆ v_GetEFromRhoP()

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

Implements Nektar::EquationOfState.

Definition at line 102 of file VanDerWaalsEoS.cpp.

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

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

◆ v_GetEntropy()

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

Implements Nektar::EquationOfState.

Definition at line 74 of file VanDerWaalsEoS.cpp.

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

75 {
76  NekDouble T = GetTemperature(rho, e);
77  NekDouble sIg =
78  m_gasConstant / (m_gamma - 1) * log(T) - m_gasConstant * log(rho);
79 
80  return sIg + m_gasConstant * log(1 - m_b * rho);
81 }
double NekDouble
NekDouble GetTemperature(const NekDouble &rho, const NekDouble &e)
Calculate the temperature.

◆ v_GetPressure()

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

Implements Nektar::EquationOfState.

Definition at line 67 of file VanDerWaalsEoS.cpp.

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

69 {
70  return (e + m_a * rho) * (m_gamma - 1) / (1.0 / rho - m_b) -
71  m_a * rho * rho;
72 }

◆ v_GetRhoFromPT()

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

Implements Nektar::EquationOfState.

Definition at line 109 of file VanDerWaalsEoS.cpp.

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

110 {
111  // First solve for the compressibility factor Z using the cubic equation
112  // Z^3 + k1 * Z^2 + k2 * Z + k3 = 0
113  // for van der Waals:
114  // k1 = -(B+1), k2 = A, k3 = -AB
115  // where A = aP/(RT)^2, B = bP/(RT)
116  NekDouble A = m_a * p / (m_gasConstant * m_gasConstant * T * T);
117  NekDouble B = m_b * p / (m_gasConstant * T);
118 
119  NekDouble k1 = -(B + 1);
120  NekDouble k2 = A;
121  NekDouble k3 = -A * B;
122 
123  // Use ideal gas (Z=1) as starting guess for iteration
124  NekDouble Z = 1.0;
125  // Newton-Raphson iteration to find Z
126  NekDouble tol = 1e-6;
127  NekDouble maxIter = 100;
128  NekDouble residual = 1;
129  NekDouble f, df;
130  unsigned int cnt = 0;
131  while (abs(residual) > tol && cnt < maxIter)
132  {
133  f = Z * Z * Z + k1 * Z * Z + k2 * Z + k3;
134  df = 3 * Z * Z + 2 * k1 * Z + k2;
135  residual = f / df;
136  Z -= residual;
137  ++cnt;
138  }
139  if (cnt == maxIter)
140  {
141  cout << "Newton-Raphson in VanDerWaalsEoS::v_GetRhoFromPT did not "
142  "converge in "
143  << maxIter << " iterations (residual = " << residual << ")"
144  << endl;
145  }
146 
147  // Now calculate rho = p/(ZRT)
148  return p / (Z * m_gasConstant * T);
149 }
double NekDouble

◆ v_GetTemperature()

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

Implements Nektar::EquationOfState.

Definition at line 61 of file VanDerWaalsEoS.cpp.

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

63 {
64  return (e + m_a * rho) * (m_gamma - 1) / m_gasConstant;
65 }

Friends And Related Function Documentation

◆ MemoryManager< VanDerWaalsEoS >

friend class MemoryManager< VanDerWaalsEoS >
friend

Definition at line 52 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.")

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