Reaktoro  v2.6.0
A unified framework for modeling chemically reactive systems
ChemicalPropsPhase.hpp
1 // Reaktoro is a unified framework for modeling chemically reactive phases.
2 //
3 // Copyright © 2014-2022 Allan Leal
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library. If not, see <http://www.gnu.org/licenses/>.
17 
18 #pragma once
19 
20 // Reaktoro includes
21 #include <Reaktoro/Common/ArrayStream.hpp>
22 #include <Reaktoro/Common/Constants.hpp>
23 #include <Reaktoro/Common/TypeOp.hpp>
24 #include <Reaktoro/Core/Phase.hpp>
25 #include <Reaktoro/Core/StateOfMatter.hpp>
26 
27 namespace Reaktoro {
28 
30 template<template<typename> typename TypeOp>
32 {
34  TypeOp<real> T;
35 
37  TypeOp<real> P;
38 
40  TypeOp<ArrayXr> n;
41 
43  TypeOp<real> nsum;
44 
46  TypeOp<real> msum;
47 
49  TypeOp<ArrayXr> x;
50 
52  TypeOp<ArrayXr> G0;
53 
55  TypeOp<ArrayXr> H0;
56 
58  TypeOp<ArrayXr> V0;
59 
61  TypeOp<ArrayXr> VT0;
62 
64  TypeOp<ArrayXr> VP0;
65 
67  TypeOp<ArrayXr> Cp0;
68 
70  TypeOp<real> Vx;
71 
73  TypeOp<real> VxT;
74 
76  TypeOp<real> VxP;
77 
79  TypeOp<real> Gx;
80 
82  TypeOp<real> Hx;
83 
85  TypeOp<real> Cpx;
86 
88  TypeOp<ArrayXr> ln_g;
89 
91  TypeOp<ArrayXr> ln_a;
92 
94  TypeOp<ArrayXr> u;
95 
97  TypeOp<StateOfMatter> som;
98 
100  template<template<typename> typename OtherTypeOp>
102  {
103  T = other.T;
104  P = other.P;
105  n = other.n;
106  nsum = other.nsum;
107  msum = other.msum;
108  x = other.x;
109  G0 = other.G0;
110  H0 = other.H0;
111  V0 = other.V0;
112  VT0 = other.VT0;
113  VP0 = other.VP0;
114  Cp0 = other.Cp0;
115  Vx = other.Vx;
116  VxT = other.VxT;
117  VxP = other.VxP;
118  Gx = other.Gx;
119  Hx = other.Hx;
120  Cpx = other.Cpx;
121  ln_g = other.ln_g;
122  ln_a = other.ln_a;
123  u = other.u;
124  som = other.som;
125  return *this;
126  }
127 
129  template<template<typename> typename OtherTypeOp>
131  {
132  return { T, P, n, nsum, msum, x, G0, H0, V0, VT0, VP0, Cp0, Vx, VxT, VxP, Gx, Hx, Cpx, ln_g, ln_a, u, som };
133  }
134 
136  template<template<typename> typename OtherTypeOp>
138  {
139  return { T, P, n, nsum, msum, x, G0, H0, V0, VT0, VP0, Cp0, Vx, VxT, VxP, Gx, Hx, Cpx, ln_g, ln_a, u, som };
140  }
141 
143  auto operator=(const ArrayStream<real>& array)
144  {
145  array.to(T, P, n, nsum, msum, x, G0, H0, V0, VT0, VP0, Cp0, Vx, VxT, VxP, Gx, Hx, Cpx, ln_g, ln_a, u, som);
146  return *this;
147  }
148 
150  operator ArrayStream<real>() const
151  {
152  return { T, P, n, nsum, msum, x, G0, H0, V0, VT0, VP0, Cp0, Vx, VxT, VxP, Gx, Hx, Cpx, ln_g, ln_a, u, som };
153  }
154 };
155 
158 
161 
164 
167 
169 template<template<typename> typename TypeOp>
171 {
172 public:
175  : mphase(phase)
176  {
177  const auto N = phase.species().size();
178 
179  mdata.n = ArrayXr::Zero(N);
180  mdata.x = ArrayXr::Zero(N);
181  mdata.G0 = ArrayXr::Zero(N);
182  mdata.H0 = ArrayXr::Zero(N);
183  mdata.V0 = ArrayXr::Zero(N);
184  mdata.VT0 = ArrayXr::Zero(N);
185  mdata.VP0 = ArrayXr::Zero(N);
186  mdata.Cp0 = ArrayXr::Zero(N);
187  mdata.ln_g = ArrayXr::Zero(N);
188  mdata.ln_a = ArrayXr::Zero(N);
189  mdata.u = ArrayXr::Zero(N);
190  }
191 
194  : mphase(phase), mdata(data)
195  {}
196 
198  template<template<typename> typename OtherTypeOp>
200  : mphase(other.mphase), mdata(other.mdata)
201  {}
202 
204  template<template<typename> typename OtherTypeOp>
206  : mphase(other.mphase), mdata(other.mdata)
207  {}
208 
214  auto update(const real& T, const real& P, ArrayXrConstRef n, Map<String, Any>& extra)
215  {
216  _update<false>(T, P, n, extra);
217  }
218 
224  auto updateIdeal(const real& T, const real& P, ArrayXrConstRef n, Map<String, Any>& extra)
225  {
226  _update<true>(T, P, n, extra);
227  }
228 
231  {
232  mdata = data;
233  }
234 
236  auto phase() const -> const Phase&
237  {
238  return mphase;
239  }
240 
242  auto data() const -> const ChemicalPropsPhaseBaseData<TypeOp>&
243  {
244  return mdata;
245  }
246 
248  auto stateOfMatter() const -> StateOfMatter
249  {
250  return mdata.som;
251  }
252 
254  auto temperature() const -> real
255  {
256  return mdata.T;
257  }
258 
260  auto pressure() const -> real
261  {
262  return mdata.P;
263  }
264 
267  {
268  return mdata.n;
269  }
270 
273  {
274  return mdata.x;
275  }
276 
279  {
280  return mdata.ln_g;
281  }
282 
285  {
286  return mdata.ln_a;
287  }
288 
291  {
292  return mdata.u;
293  }
294 
297  {
298  return mdata.V0;
299  }
300 
303  {
304  return mdata.VT0;
305  }
306 
309  {
310  return mdata.VP0;
311  }
312 
315  {
316  return mdata.G0;
317  }
318 
321  {
322  return mdata.H0;
323  }
324 
327  {
328  return (mdata.H0 - mdata.G0)/mdata.T; // from G0 = H0 - T*S0
329  }
330 
333  {
334  return mdata.H0 - mdata.P * mdata.V0; // from H0 = U0 + P*V0
335  }
336 
339  {
340  return mdata.G0 - mdata.P * mdata.V0; // from A0 = U0 - T*S0 = (H0 - P*V0) + (G0 - H0) = G0 - P*V0
341  }
342 
345  {
346  return mdata.Cp0;
347  }
348 
351  {
352  const auto& Cp0 = mdata.Cp0;
353  const auto& T = mdata.T;
354  const auto& VT0 = mdata.VT0;
355  const auto& VP0 = mdata.VP0;
356  return (VP0 == 0.0).select(Cp0, Cp0 + T*VT0*VT0/VP0); // from Cv0 = Cp0 + T*VT0*VT0/VP0
357  }
358 
360  auto molarMass() const -> real
361  {
362  return mdata.msum / mdata.nsum;
363  }
364 
366  auto molarVolume() const -> real
367  {
368  return (mdata.x * mdata.V0).sum() + mdata.Vx;
369  }
370 
372  auto molarVolumeT() const -> real
373  {
374  return (mdata.x * mdata.VT0).sum() + mdata.VxT;
375  }
376 
378  auto molarVolumeP() const -> real
379  {
380  return (mdata.x * mdata.VP0).sum() + mdata.VxP;
381  }
382 
384  auto molarGibbsEnergy() const -> real
385  {
386  return (mdata.x * mdata.G0).sum() + mdata.Gx;
387  }
388 
390  auto molarEnthalpy() const -> real
391  {
392  return (mdata.x * mdata.H0).sum() + mdata.Hx;
393  }
394 
396  auto molarEntropy() const -> real
397  {
398  const auto S0 = (mdata.H0 - mdata.G0)/mdata.T; // from G0 = H0 - T*S0
399  const auto Sx = (mdata.Hx - mdata.Gx)/mdata.T; // from Gx = Hx - T*Sx
400  return (mdata.x * S0).sum() + Sx;
401  }
402 
404  auto molarInternalEnergy() const -> real
405  {
406  const auto U0 = mdata.H0 - mdata.P * mdata.V0; // from H0 = U0 + P*V0
407  const auto Ux = mdata.Hx - mdata.P * mdata.Vx; // from Hx = U0 + P*Vx
408  return (mdata.x * U0).sum() + Ux;
409  }
410 
412  auto molarHelmholtzEnergy() const -> real
413  {
414  const auto A0 = mdata.G0 - mdata.P * mdata.V0; // from A0 = U0 - T*S0 = (H0 - P*V0) + (G0 - H0) = G0 - P*V0
415  const auto Ax = mdata.Gx - mdata.P * mdata.Vx; // from Ax = U0 - T*Sx = (Hx - P*Vx) + (Gx - Hx) = Gx - P*Vx
416  return (mdata.x * A0).sum() + Ax;
417  }
418 
421  {
422  return (mdata.x * mdata.Cp0).sum() + mdata.Cpx;
423  }
424 
427  {
428  const auto Cp = molarHeatCapacityConstP();
429  const auto VT = molarVolumeT();
430  const auto VP = molarVolumeP();
431  const auto T = temperature();
432  return VP == 0.0 ? Cp : Cp + T*VT*VT/VP;
433  }
434 
436  auto specificVolume() const -> real
437  {
438  return molarVolume() / molarMass();
439  }
440 
442  auto specificVolumeT() const -> real
443  {
444  return molarVolumeT() / molarMass();
445  }
446 
448  auto specificVolumeP() const -> real
449  {
450  return molarVolumeP() / molarMass();
451  }
452 
454  auto specificGibbsEnergy() const -> real
455  {
456  return molarGibbsEnergy() / molarMass();
457  }
458 
460  auto specificEnthalpy() const -> real
461  {
462  return molarEnthalpy() / molarMass();
463  }
464 
466  auto specificEntropy() const -> real
467  {
468  return molarEntropy() / molarMass();
469  }
470 
472  auto specificInternalEnergy() const -> real
473  {
474  return molarInternalEnergy() / molarMass();
475  }
476 
479  {
480  return molarHelmholtzEnergy() / molarMass();
481  }
482 
485  {
486  return molarHeatCapacityConstP() / molarMass();
487  }
488 
491  {
492  return molarHeatCapacityConstV() / molarMass();
493  }
494 
496  auto density() const -> real
497  {
498  return molarMass() / molarVolume();
499  }
500 
502  auto amount() const -> real
503  {
504  return mdata.nsum;
505  }
506 
508  auto mass() const -> real
509  {
510  return mdata.msum;
511  }
512 
514  auto volume() const -> real
515  {
516  return molarVolume() * amount();
517  }
518 
520  auto volumeT() const -> real
521  {
522  return molarVolumeT() * amount();
523  }
524 
526  auto volumeP() const -> real
527  {
528  return molarVolumeP() * amount();
529  }
530 
532  auto gibbsEnergy() const -> real
533  {
534  return molarGibbsEnergy() * amount();
535  }
536 
538  auto enthalpy() const -> real
539  {
540  return molarEnthalpy() * amount();
541  }
542 
544  auto entropy() const -> real
545  {
546  return molarEntropy() * amount();
547  }
548 
550  auto internalEnergy() const -> real
551  {
552  return molarInternalEnergy() * amount();
553  }
554 
556  auto helmholtzEnergy() const -> real
557  {
558  return molarHelmholtzEnergy() * amount();
559  }
560 
562  auto heatCapacityConstP() const -> real
563  {
564  return molarHeatCapacityConstP() * amount();
565  }
566 
568  auto heatCapacityConstV() const -> real
569  {
570  return molarHeatCapacityConstV() * amount();
571  }
572 
574  auto soundSpeed() const -> real
575  {
576  const auto rho = density();
577  const auto Cp = molarHeatCapacityConstP();
578  const auto Cv = molarHeatCapacityConstV();
579  const auto VP = molarVolumeP();
580  const auto MM = molarMass();
581  return sqrt(-MM * Cp/Cv / VP) / rho;
582  }
583 
585  auto operator=(const ArrayStream<real>& array)
586  {
587  mdata = array;
588  return *this;
589  }
590 
592  operator ArrayStream<real>() const
593  {
594  return mdata;
595  }
596 
597  // Ensure other ChemicalPropsPhaseBase types are friend among themselves.
598  template<template<typename> typename OtherTypeOp>
599  friend class ChemicalPropsPhaseBase;
600 
601 private:
603  Phase mphase;
604 
607 
608 private:
609 
615  template<bool use_ideal_activity_model>
616  auto _update(const real& T, const real& P, ArrayXrConstRef n, Map<String, Any>& extra)
617  {
618  mdata.T = T;
619  mdata.P = P;
620  mdata.n = n;
621 
622  const auto R = universalGasConstant;
623 
624  auto& nsum = mdata.nsum;
625  auto& msum = mdata.msum;
626  auto& x = mdata.x;
627  auto& G0 = mdata.G0;
628  auto& H0 = mdata.H0;
629  auto& V0 = mdata.V0;
630  auto& VT0 = mdata.VT0;
631  auto& VP0 = mdata.VP0;
632  auto& Cp0 = mdata.Cp0;
633  auto& Vx = mdata.Vx;
634  auto& VxT = mdata.VxT;
635  auto& VxP = mdata.VxP;
636  auto& Gx = mdata.Gx;
637  auto& Hx = mdata.Hx;
638  auto& Cpx = mdata.Cpx;
639  auto& ln_g = mdata.ln_g;
640  auto& ln_a = mdata.ln_a;
641  auto& u = mdata.u;
642  auto& som = mdata.som;
643 
644  const auto& species = phase().species();
645  const auto N = species.size();
646 
647  assert( n.size() == N );
648  assert( G0.size() == N );
649  assert( H0.size() == N );
650  assert( V0.size() == N );
651  assert( VT0.size() == N );
652  assert( VP0.size() == N );
653  assert( Cp0.size() == N );
654  assert( ln_g.size() == N );
655  assert( ln_a.size() == N );
656  assert( u.size() == N );
657 
658  // Compute the standard thermodynamic properties of the species in the phase.
660  for(auto i = 0; i < N; ++i)
661  {
662  aux = species[i].standardThermoProps(T, P);
663  G0[i] = aux.G0;
664  H0[i] = aux.H0;
665  V0[i] = aux.V0;
666  VT0[i] = aux.VT0;
667  VP0[i] = aux.VP0;
668  Cp0[i] = aux.Cp0;
669  }
670 
671  // Compute the amount of the phase
672  nsum = n.sum();
673 
674  // Compute the mass of the phase
675  msum = (n * mphase.speciesMolarMasses()).sum();
676 
677  // Compute the mole fractions of the species
678  if(nsum == 0.0)
679  x = (N == 1) ? 1.0 : 0.0;
680  else x = n / nsum;
681 
682  // Ensure there are no zero mole fractions
683  error(x.minCoeff() == 0.0, "Could not compute the chemical properties of phase ",
684  phase().name(), " because it has one or more species with zero amounts.");
685 
686  // Compute the activity properties of the phase
687  ActivityPropsRef aprops{ Vx, VxT, VxP, Gx, Hx, Cpx, ln_g, ln_a, som, extra };
688  ActivityModelArgs args{ T, P, x };
689  const ActivityModel& activity_model = use_ideal_activity_model ? // IMPORTANT: Use `const ActivityModel&` here instead of `ActivityModel`, otherwise a new model is constructed without cache, and so memoization will not take effect.
690  phase().idealActivityModel() : phase().activityModel();
691 
692  if(nsum == 0.0) aprops = 0.0;
693  else activity_model(aprops, args);
694 
695  // Compute the chemical potentials of the species
696  u = G0 + R*T*ln_a;
697  }
698 };
699 
702 
705 
708 
709 } // namespace Reaktoro
The class used to serialize/deserialize data using array.
Definition: ArrayStream.hpp:28
auto to(Args &... args) const
Transfer this ArrayStream object data to given list of scalars and/or arrays.
Definition: ArrayStream.hpp:54
The base type for chemical properties of a phase and its species.
Definition: ChemicalPropsPhase.hpp:171
auto molarVolume() const -> real
Return the molar volume of the phase (in m³/mol).
Definition: ChemicalPropsPhase.hpp:366
auto molarVolumeP() const -> real
Return the pressure derivative of the molar volume of the phase (in m³/(mol·Pa)).
Definition: ChemicalPropsPhase.hpp:378
auto temperature() const -> real
Return the temperature of the phase (in K).
Definition: ChemicalPropsPhase.hpp:254
auto speciesStandardVolumesT() const -> ArrayXrConstRef
Return the temperature derivative of the standard molar volumes of the species in the phase (in m³/(m...
Definition: ChemicalPropsPhase.hpp:302
auto specificGibbsEnergy() const -> real
Return the specific Gibbs energy of formation of the phase (in J/kg).
Definition: ChemicalPropsPhase.hpp:454
auto pressure() const -> real
Return the pressure of the phase (in Pa).
Definition: ChemicalPropsPhase.hpp:260
auto volumeT() const -> real
Return the temperature derivative of the volume of the phase (in m³/K).
Definition: ChemicalPropsPhase.hpp:520
auto speciesStandardInternalEnergies() const -> ArrayXr
Return the standard partial molar internal energies of formation of the species in the phase (in J/mo...
Definition: ChemicalPropsPhase.hpp:332
auto mass() const -> real
Return the sum of species masses in the phase (in kg).
Definition: ChemicalPropsPhase.hpp:508
auto speciesActivitiesLn() const -> ArrayXrConstRef
Return the ln activities of the species in the phase.
Definition: ChemicalPropsPhase.hpp:284
auto heatCapacityConstP() const -> real
Return the isobaric heat capacity of the phase (in J/K).
Definition: ChemicalPropsPhase.hpp:562
auto speciesChemicalPotentials() const -> ArrayXrConstRef
Return the chemical potentials of the species in the phase (in J/mol).
Definition: ChemicalPropsPhase.hpp:290
auto speciesStandardHeatCapacitiesConstP() const -> ArrayXrConstRef
Return the standard partial molar isobaric heat capacities of the species in the phase (in J/(mol·K))...
Definition: ChemicalPropsPhase.hpp:344
auto speciesStandardEntropies() const -> ArrayXr
Return the standard partial molar entropies of formation of the species in the phase (in J/(mol·K)).
Definition: ChemicalPropsPhase.hpp:326
auto speciesStandardGibbsEnergies() const -> ArrayXrConstRef
Return the standard partial molar Gibbs energies of formation of the species in the phase (in J/mol).
Definition: ChemicalPropsPhase.hpp:314
auto updateWithData(const ChemicalPropsPhaseBaseData< TypeOp > &data)
Update the chemical properties of the phase with given data.
Definition: ChemicalPropsPhase.hpp:230
auto entropy() const -> real
Return the entropy of the phase (in J/K).
Definition: ChemicalPropsPhase.hpp:544
ChemicalPropsPhaseBase(ChemicalPropsPhaseBase< OtherTypeOp > &other)
Construct a ChemicalPropsPhaseBase instance.
Definition: ChemicalPropsPhase.hpp:199
auto specificInternalEnergy() const -> real
Return the specific internal energy of formation of the phase (in J/kg).
Definition: ChemicalPropsPhase.hpp:472
auto speciesStandardEnthalpies() const -> ArrayXrConstRef
Return the standard partial molar enthalpies of formation of the species in the phase (in J/mol).
Definition: ChemicalPropsPhase.hpp:320
auto volume() const -> real
Return the volume of the phase (in m³).
Definition: ChemicalPropsPhase.hpp:514
auto data() const -> const ChemicalPropsPhaseBaseData< TypeOp > &
Return the primary chemical property data of the phase from which others are calculated.
Definition: ChemicalPropsPhase.hpp:242
auto molarHeatCapacityConstV() const -> real
Return the molar isochoric heat capacity of the phase (in J/(mol·K)).
Definition: ChemicalPropsPhase.hpp:426
auto speciesActivityCoefficientsLn() const -> ArrayXrConstRef
Return the ln activity coefficients of the species in the phase.
Definition: ChemicalPropsPhase.hpp:278
auto phase() const -> const Phase &
Return the underlying Phase object.
Definition: ChemicalPropsPhase.hpp:236
auto specificVolume() const -> real
Return the specific volume of the phase (in m³/kg).
Definition: ChemicalPropsPhase.hpp:436
auto speciesStandardVolumes() const -> ArrayXrConstRef
Return the standard partial molar volumes of the species in the phase (in m³/mol).
Definition: ChemicalPropsPhase.hpp:296
auto specificEnthalpy() const -> real
Return the specific enthalpy of formation of the phase (in J/kg).
Definition: ChemicalPropsPhase.hpp:460
auto speciesAmounts() const -> ArrayXrConstRef
Return the amounts of the species in the phase (in mol).
Definition: ChemicalPropsPhase.hpp:266
auto specificVolumeT() const -> real
Return the temperature derivative of the specific volume of the phase (in m³/(kg·K)).
Definition: ChemicalPropsPhase.hpp:442
auto specificHeatCapacityConstV() const -> real
Return the specific isochoric heat capacity of the phase (in J/(kg·K)).
Definition: ChemicalPropsPhase.hpp:490
auto specificHeatCapacityConstP() const -> real
Return the specific isobaric heat capacity of the phase (in J/(kg·K)).
Definition: ChemicalPropsPhase.hpp:484
auto internalEnergy() const -> real
Return the internal energy of the phase (in J).
Definition: ChemicalPropsPhase.hpp:550
auto molarGibbsEnergy() const -> real
Return the molar Gibbs energy of formation of the phase (in J/mol).
Definition: ChemicalPropsPhase.hpp:384
auto update(const real &T, const real &P, ArrayXrConstRef n, Map< String, Any > &extra)
Update the chemical properties of the phase.
Definition: ChemicalPropsPhase.hpp:214
auto molarHeatCapacityConstP() const -> real
Return the molar isobaric heat capacity of the phase (in J/(mol·K)).
Definition: ChemicalPropsPhase.hpp:420
auto molarHelmholtzEnergy() const -> real
Return the molar Helmholtz energy of formation of the phase (in J/mol).
Definition: ChemicalPropsPhase.hpp:412
auto specificHelmholtzEnergy() const -> real
Return the specific Helmholtz energy of formation of the phase (in J/kg).
Definition: ChemicalPropsPhase.hpp:478
auto helmholtzEnergy() const -> real
Return the Helmholtz energy of the phase (in J).
Definition: ChemicalPropsPhase.hpp:556
auto amount() const -> real
Return the sum of species amounts in the phase (in mol).
Definition: ChemicalPropsPhase.hpp:502
auto molarEntropy() const -> real
Return the molar entropy of formation of the phase (in J/(mol·K)).
Definition: ChemicalPropsPhase.hpp:396
ChemicalPropsPhaseBase(const ChemicalPropsPhaseBase< OtherTypeOp > &other)
Construct a ChemicalPropsPhaseBase instance.
Definition: ChemicalPropsPhase.hpp:205
auto speciesMoleFractions() const -> ArrayXrConstRef
Return the mole fractions of the species in the phase.
Definition: ChemicalPropsPhase.hpp:272
auto stateOfMatter() const -> StateOfMatter
Return the state of matter of the phase.
Definition: ChemicalPropsPhase.hpp:248
auto speciesStandardVolumesP() const -> ArrayXrConstRef
Return the pressure derivative of the standard molar volumes of the species in the phase (in m³/(mol·...
Definition: ChemicalPropsPhase.hpp:308
auto heatCapacityConstV() const -> real
Return the isochoric heat capacity of the phase (in J/K).
Definition: ChemicalPropsPhase.hpp:568
auto molarInternalEnergy() const -> real
Return the molar internal energy of formation of the phase (in J/mol).
Definition: ChemicalPropsPhase.hpp:404
auto volumeP() const -> real
Return the pressure derivative of the volume of the phase (in m³/Pa).
Definition: ChemicalPropsPhase.hpp:526
auto operator=(const ArrayStream< real > &array)
Assign the given array data to this ChemicalPropsPhaseBase object.
Definition: ChemicalPropsPhase.hpp:585
ChemicalPropsPhaseBase(const Phase &phase)
Construct a ChemicalPropsPhaseBase instance.
Definition: ChemicalPropsPhase.hpp:174
auto gibbsEnergy() const -> real
Return the Gibbs energy of the phase (in J).
Definition: ChemicalPropsPhase.hpp:532
auto speciesStandardHeatCapacitiesConstV() const -> ArrayXr
Return the standard partial molar isochoric heat capacities of the species in the phase (in J/(mol·K)...
Definition: ChemicalPropsPhase.hpp:350
auto molarMass() const -> real
Return the molar mass of the phase (in kg/mol).
Definition: ChemicalPropsPhase.hpp:360
auto molarVolumeT() const -> real
Return the temperature derivative of the molar volume of the phase (in m³/(mol·K)).
Definition: ChemicalPropsPhase.hpp:372
auto updateIdeal(const real &T, const real &P, ArrayXrConstRef n, Map< String, Any > &extra)
Update the chemical properties of the phase using ideal activity models.
Definition: ChemicalPropsPhase.hpp:224
auto soundSpeed() const -> real
Return the speed of sound in the phase (in m/s).
Definition: ChemicalPropsPhase.hpp:574
ChemicalPropsPhaseBase(const Phase &phase, const ChemicalPropsPhaseBaseData< TypeOp > &data)
Construct a ChemicalPropsPhaseBase instance.
Definition: ChemicalPropsPhase.hpp:193
auto speciesStandardHelmholtzEnergies() const -> ArrayXr
Return the standard partial molar Helmholtz energies of formation of the species in the phase (in J/m...
Definition: ChemicalPropsPhase.hpp:338
auto enthalpy() const -> real
Return the enthalpy of the phase (in J).
Definition: ChemicalPropsPhase.hpp:538
auto specificEntropy() const -> real
Return the specific entropy of formation of the phase (in J/(kg·K)).
Definition: ChemicalPropsPhase.hpp:466
auto specificVolumeP() const -> real
Return the pressure derivative of the specific volume of the phase (in m³/(kg·Pa)).
Definition: ChemicalPropsPhase.hpp:448
auto density() const -> real
Return the density of the phase (in kg/m³).
Definition: ChemicalPropsPhase.hpp:496
auto molarEnthalpy() const -> real
Return the molar enthalpy of formation of the phase (in J/mol).
Definition: ChemicalPropsPhase.hpp:390
A type used to define a phase and its attributes.
Definition: Phase.hpp:33
auto speciesMolarMasses() const -> ArrayXdConstRef
Return the molar masses of the species in the phase (in kg/mol).
The namespace containing all components of the Reaktoro library.
Definition: Algorithms.hpp:28
Fn< void(ChemicalPropsPhaseDataRef, const real &, const real &, ArrayXrConstRef)> ChemicalPropsPhaseFn
The type of functions that computes the primary chemical property data of a phase.
Definition: ChemicalPropsPhase.hpp:166
constexpr auto universalGasConstant
The universal gas constant (in J/(mol*K))
Definition: Constants.hpp:26
Model< ActivityProps(ActivityModelArgs)> ActivityModel
The function type for the calculation of activity and corrective thermodynamic properties of a phase.
Definition: ActivityModel.hpp:49
autodiff::real real
The number type used throughout the library.
Definition: Real.hpp:26
ActivityPropsBase< TypeOpRef > ActivityPropsRef
The non-const view to the activity and corrective thermodynamic properties of a phase.
Definition: ActivityProps.hpp:157
auto sum(std::size_t ibegin, std::size_t iend, const Function &f)
Return the sum f(ibegin) + ... + f(iend-1) for a given function f.
Definition: Algorithms.hpp:256
auto error(bool condition, Args... items) -> void
Raise a runtime error if condition is true.
Definition: Exception.hpp:106
auto sqrt(const Eigen::MatrixBase< Derived > &mat) -> decltype(mat.cwiseSqrt())
Return the component-wise square root of a matrix.
Definition: Matrix.hpp:804
std::function< F > Fn
Convenient alias for std::function<R(Args...)>.
Definition: Types.hpp:110
StateOfMatter
The list of states of matter for phases.
Definition: StateOfMatter.hpp:27
Eigen::Ref< const ArrayXr > ArrayXrConstRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:89
autodiff::ArrayXreal ArrayXr
Convenient alias to Eigen type.
Definition: Matrix.hpp:87
std::unordered_map< Key, T > Map
Convenient alias for std::unordered_map<Key, T>.
Definition: Types.hpp:74
The base type for primary chemical property data of a phase from which others are computed.
Definition: ChemicalPropsPhase.hpp:32
TypeOp< real > nsum
The amount of the phase as the sum of species amounts (in mol).
Definition: ChemicalPropsPhase.hpp:43
TypeOp< real > msum
The mass of the phase as the sum of species masses (in kg).
Definition: ChemicalPropsPhase.hpp:46
TypeOp< real > P
The pressure of the phase (in Pa).
Definition: ChemicalPropsPhase.hpp:37
TypeOp< ArrayXr > ln_a
The activities (natural log) of the species in the phase.
Definition: ChemicalPropsPhase.hpp:91
TypeOp< real > Gx
The corrective molar Gibbs energy of the phase (in units of J/mol).
Definition: ChemicalPropsPhase.hpp:79
TypeOp< real > VxT
The temperature derivative of the corrective molar volume at constant pressure (in m³/(mol·K)).
Definition: ChemicalPropsPhase.hpp:73
TypeOp< ArrayXr > x
The mole fractions of the species in the phase (in mol/mol).
Definition: ChemicalPropsPhase.hpp:49
TypeOp< ArrayXr > G0
The standard molar Gibbs energies of formation of the species in the phase (in J/mol)
Definition: ChemicalPropsPhase.hpp:52
auto operator=(const ChemicalPropsPhaseBaseData< OtherTypeOp > &other)
Assign a ChemicalPropsPhaseBaseData object to this.
Definition: ChemicalPropsPhase.hpp:101
TypeOp< real > Hx
The corrective molar enthalpy of the phase (in units of J/mol).
Definition: ChemicalPropsPhase.hpp:82
TypeOp< real > Cpx
The corrective molar isobaric heat capacity of the phase (in units of J/(mol·K)).
Definition: ChemicalPropsPhase.hpp:85
TypeOp< ArrayXr > ln_g
The activity coefficients (natural log) of the species in the phase.
Definition: ChemicalPropsPhase.hpp:88
TypeOp< ArrayXr > V0
The standard molar volumes of the species in the phase (in m³/mol)
Definition: ChemicalPropsPhase.hpp:58
TypeOp< ArrayXr > Cp0
The standard molar isobaric heat capacities of the species in the phase (in J/(mol·K))
Definition: ChemicalPropsPhase.hpp:67
TypeOp< ArrayXr > VP0
The pressure derivative of the standard molar volumes of the species in the phase (in m³/(mol·Pa)).
Definition: ChemicalPropsPhase.hpp:64
TypeOp< ArrayXr > H0
The standard molar enthalpies of formation of the species in the phase (in J/mol)
Definition: ChemicalPropsPhase.hpp:55
TypeOp< ArrayXr > VT0
The temperature derivative of the standard molar volumes of the species in the phase (in m³/(mol·K)).
Definition: ChemicalPropsPhase.hpp:61
TypeOp< ArrayXr > n
The amounts of each species in the phase (in mol).
Definition: ChemicalPropsPhase.hpp:40
TypeOp< ArrayXr > u
The chemical potentials of the species in the phase.
Definition: ChemicalPropsPhase.hpp:94
TypeOp< StateOfMatter > som
The state of matter of the phase.
Definition: ChemicalPropsPhase.hpp:97
auto operator=(const ArrayStream< real > &array)
Assign the given array data to this ChemicalPropsPhaseBaseData object.
Definition: ChemicalPropsPhase.hpp:143
TypeOp< real > Vx
The corrective molar volume of the phase (in m³/mol).
Definition: ChemicalPropsPhase.hpp:70
TypeOp< real > VxP
The pressure derivative of the corrective molar volume at constant temperature (in m³/(mol·Pa)).
Definition: ChemicalPropsPhase.hpp:76
TypeOp< real > T
The temperature of the phase (in K).
Definition: ChemicalPropsPhase.hpp:34
The primary standard thermodynamic properties of a chemical species.
Definition: StandardThermoProps.hpp:27
real VP0
The pressure derivative of the standard molar volume of the species (in m³/(mol·Pa)).
Definition: StandardThermoProps.hpp:44
real VT0
The temperature derivative of the standard molar volume of the species (in m³/(mol·K)).
Definition: StandardThermoProps.hpp:41
real H0
The standard molar enthalpy of formation of the species (in J/mol).
Definition: StandardThermoProps.hpp:32
real G0
The standard molar Gibbs energy of formation of the species (in J/mol).
Definition: StandardThermoProps.hpp:29
real V0
The standard molar volume of the species (in m³/mol).
Definition: StandardThermoProps.hpp:35
real Cp0
The standard molar isobaric heat capacity of the species (in J/(mol·K)).
Definition: StandardThermoProps.hpp:38