Canoe
Comprehensive Atmosphere N' Ocean Engine
molecules.hpp
Go to the documentation of this file.
1 #ifndef SRC_SNAP_THERMODYNAMICS_MOLECULES_HPP_
2 #define SRC_SNAP_THERMODYNAMICS_MOLECULES_HPP_
3 
4 // C/C++
5 #include <array>
6 #include <cmath>
7 #include <iostream>
8 #include <memory>
9 #include <string>
10 #include <vector>
11 
42 // number of Shomate coefficients
43 #define NSHOMATE 7
44 
45 // maximum number of shomate expressions
46 #define MAXSHOMATE 3
47 
48 class Molecule {
49  friend std::ostream &operator<<(std::ostream &os, Molecule const &mol);
50 
51  protected:
52  std::string m_name;
53 
56 
58 
59  std::array<double, MAXSHOMATE * NSHOMATE> m_shomate;
60 
61  std::array<double, MAXSHOMATE + 1> m_shomate_sp;
62 
63  public:
64  Molecule(std::string name = "")
65  : m_name(name),
66  m_mu(0),
67  m_cp(0),
68  m_latent(0),
69  m_entropy(0),
70  m_enthalpy(0),
71  m_gibbs(0),
72  m_tr(0),
73  m_pr(0),
74  m_tc(0),
75  m_pc(0),
76  m_cliq(0),
77  m_enliq(0),
78  m_csld(0),
79  m_ensld(0),
80  m_beta(0),
81  m_gamma(0),
82  m_nshomate(0) {
83  std::fill(m_shomate.begin(), m_shomate.end(), 0.);
84  std::fill(m_shomate_sp.begin(), m_shomate_sp.end(), 0.);
85  }
86 
87  virtual ~Molecule() {}
88 
89  void LoadThermodynamicFile(std::string chemfile);
90 
91  virtual double cp(double T) const;
92 
93  virtual double enthalpy(double T) const;
94 
95  virtual double entropy(double T) const;
96 
97  virtual double latent(double T) const;
98 
99  double sat_vapor_p(double T) const {
100  return m_pr * exp((1. - m_tr / T) * m_beta - m_gamma * log(T / m_tr));
101  };
102 
103  double isat_vapor_p(double P) const;
104 
105  std::string name() const { return m_name; }
106 
107  double mu() const { return m_mu; }
108 
109  double cp() const { return m_cp; }
110 
111  double tr() const { return m_tr; }
112 
113  double pr() const { return m_pr; }
114 
115  double tc() const { return m_tc; }
116 
117  double pc() const { return m_pc; }
118 
119  double latent() const { return m_latent; }
120 };
121 
122 class Hydrogen {
123  public:
124  Hydrogen();
125 
126  static double fpara_equil(double T);
127  static double cp_para(double T);
128  static double cp_ortho(double T);
129  static double cp_norm(double T);
130  static double cp_equil(double T);
131  static double cp_nist(double T);
132 
133  private:
134  static double FJ_[20];
135  static double DJ_[20];
136  static double nist_shomate1_[7]; // 298 ~ 1000 K
137  static double nist_shomate2_[7]; // 1000 ~ 2500 K
138  static double nist_shomate3_[7]; // 2500 ~ 6000 K
139  static void get_cp_(double *cp_para, double *cp_equil, double *cp_norm,
140  double *cp_ortho, double T);
141 };
142 
143 class Helium {
144  public:
145  static double cp_nist(double T);
146 
147  private:
148  static double nist_shomate_[7]; // 300 ~ 600 K
149 };
150 
151 class Methane {
152  public:
153  static double cp_nist(double T);
154 
155  private:
156  static double nist_shomate1_[7]; // 298 ~ 1300 K
157  static double nist_shomate2_[7]; // 1300 ~ 6000 K
158 };
159 
160 #endif // SRC_SNAP_THERMODYNAMICS_MOLECULES_HPP_
static double cp_nist(double T)
static double nist_shomate_[7]
Definition: molecules.hpp:148
static double fpara_equil(double T)
static double nist_shomate3_[7]
Definition: molecules.hpp:138
static double cp_equil(double T)
static double cp_ortho(double T)
static double DJ_[20]
Definition: molecules.hpp:135
static double nist_shomate1_[7]
Definition: molecules.hpp:136
static double nist_shomate2_[7]
Definition: molecules.hpp:137
static double cp_norm(double T)
static void get_cp_(double *cp_para, double *cp_equil, double *cp_norm, double *cp_ortho, double T)
static double cp_nist(double T)
static double cp_para(double T)
static double FJ_[20]
Definition: molecules.hpp:134
static double nist_shomate1_[7]
Definition: molecules.hpp:156
static double cp_nist(double T)
static double nist_shomate2_[7]
Definition: molecules.hpp:157
double cp() const
Definition: molecules.hpp:109
Molecule(std::string name="")
Definition: molecules.hpp:64
double m_enliq
Definition: molecules.hpp:55
int m_nshomate
Definition: molecules.hpp:57
double isat_vapor_p(double P) const
Definition: molecules.cpp:111
double m_mu
Definition: molecules.hpp:54
double m_cliq
Definition: molecules.hpp:55
std::string m_name
Definition: molecules.hpp:52
std::array< double, MAXSHOMATE+1 > m_shomate_sp
Definition: molecules.hpp:61
double m_latent
Definition: molecules.hpp:54
double m_gibbs
Definition: molecules.hpp:54
virtual double entropy(double T) const
Definition: molecules.cpp:88
std::string name() const
Definition: molecules.hpp:105
double m_beta
Definition: molecules.hpp:55
double tc() const
Definition: molecules.hpp:115
double m_pr
Definition: molecules.hpp:54
virtual ~Molecule()
Definition: molecules.hpp:87
virtual double enthalpy(double T) const
Definition: molecules.cpp:72
double m_tc
Definition: molecules.hpp:54
double pc() const
Definition: molecules.hpp:117
friend std::ostream & operator<<(std::ostream &os, Molecule const &mol)
Definition: molecules.cpp:22
double m_entropy
Definition: molecules.hpp:54
double pr() const
Definition: molecules.hpp:113
double m_cp
Definition: molecules.hpp:54
double m_tr
Definition: molecules.hpp:54
void LoadThermodynamicFile(std::string chemfile)
Definition: molecules.cpp:36
double latent() const
Definition: molecules.hpp:119
std::array< double, MAXSHOMATE *NSHOMATE > m_shomate
Definition: molecules.hpp:59
double tr() const
Definition: molecules.hpp:111
double m_ensld
Definition: molecules.hpp:55
double mu() const
Definition: molecules.hpp:107
double sat_vapor_p(double T) const
Definition: molecules.hpp:99
double m_csld
Definition: molecules.hpp:55
double m_enthalpy
Definition: molecules.hpp:54
double m_pc
Definition: molecules.hpp:55
double m_gamma
Definition: molecules.hpp:55