Reaktoro  v2.11.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-2024 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<ArrayXr> Vxi;
80 
82  TypeOp<real> Gx;
83 
85  TypeOp<real> Hx;
86 
88  TypeOp<real> Cpx;
89 
91  TypeOp<ArrayXr> ln_g;
92 
94  TypeOp<ArrayXr> ln_a;
95 
97  TypeOp<ArrayXr> u;
98 
100  TypeOp<StateOfMatter> som;
101 
103  template<template<typename> typename OtherTypeOp>
105  {
106  T = other.T;
107  P = other.P;
108  n = other.n;
109  nsum = other.nsum;
110  msum = other.msum;
111  x = other.x;
112  G0 = other.G0;
113  H0 = other.H0;
114  V0 = other.V0;
115  VT0 = other.VT0;
116  VP0 = other.VP0;
117  Cp0 = other.Cp0;
118  Vx = other.Vx;
119  VxT = other.VxT;
120  VxP = other.VxP;
121  Vxi = other.Vxi;
122  Gx = other.Gx;
123  Hx = other.Hx;
124  Cpx = other.Cpx;
125  ln_g = other.ln_g;
126  ln_a = other.ln_a;
127  u = other.u;
128  som = other.som;
129  return *this;
130  }
131 
133  template<template<typename> typename OtherTypeOp>
135  {
136  return { T, P, n, nsum, msum, x, G0, H0, V0, VT0, VP0, Cp0, Vx, VxT, VxP, Vxi, Gx, Hx, Cpx, ln_g, ln_a, u, som };
137  }
138 
140  template<template<typename> typename OtherTypeOp>
142  {
143  return { T, P, n, nsum, msum, x, G0, H0, V0, VT0, VP0, Cp0, Vx, VxT, VxP, Vxi, Gx, Hx, Cpx, ln_g, ln_a, u, som };
144  }
145 
147  auto operator=(const ArrayStream<real>& array)
148  {
149  array.to(T, P, n, nsum, msum, x, G0, H0, V0, VT0, VP0, Cp0, Vx, VxT, VxP, Vxi, Gx, Hx, Cpx, ln_g, ln_a, u, som);
150  return *this;
151  }
152 
154  operator ArrayStream<real>() const
155  {
156  return { T, P, n, nsum, msum, x, G0, H0, V0, VT0, VP0, Cp0, Vx, VxT, VxP, Vxi, Gx, Hx, Cpx, ln_g, ln_a, u, som };
157  }
158 };
159 
162 
165 
168 
171 
173 template<template<typename> typename TypeOp>
175 {
176 public:
179  : mphase(phase)
180  {
181  const auto N = phase.species().size();
182 
183  mdata.n = ArrayXr::Zero(N);
184  mdata.x = ArrayXr::Zero(N);
185  mdata.G0 = ArrayXr::Zero(N);
186  mdata.H0 = ArrayXr::Zero(N);
187  mdata.V0 = ArrayXr::Zero(N);
188  mdata.VT0 = ArrayXr::Zero(N);
189  mdata.VP0 = ArrayXr::Zero(N);
190  mdata.Cp0 = ArrayXr::Zero(N);
191  mdata.Vxi = ArrayXr::Zero(N);
192  mdata.ln_g = ArrayXr::Zero(N);
193  mdata.ln_a = ArrayXr::Zero(N);
194  mdata.u = ArrayXr::Zero(N);
195  }
196 
199  : mphase(phase), mdata(data)
200  {}
201 
203  template<template<typename> typename OtherTypeOp>
205  : mphase(other.mphase), mdata(other.mdata)
206  {}
207 
209  template<template<typename> typename OtherTypeOp>
211  : mphase(other.mphase), mdata(other.mdata)
212  {}
213 
219  auto update(const real& T, const real& P, ArrayXrConstRef n, Map<String, Any>& extra)
220  {
221  _update<false>(T, P, n, extra);
222  }
223 
229  auto updateIdeal(const real& T, const real& P, ArrayXrConstRef n, Map<String, Any>& extra)
230  {
231  _update<true>(T, P, n, extra);
232  }
233 
236  {
237  mdata = data;
238  }
239 
241  auto phase() const -> const Phase&
242  {
243  return mphase;
244  }
245 
247  auto data() const -> const ChemicalPropsPhaseBaseData<TypeOp>&
248  {
249  return mdata;
250  }
251 
253  auto stateOfMatter() const -> StateOfMatter
254  {
255  return mdata.som;
256  }
257 
259  auto temperature() const -> real
260  {
261  return mdata.T;
262  }
263 
265  auto pressure() const -> real
266  {
267  return mdata.P;
268  }
269 
272  {
273  return mdata.n;
274  }
275 
278  {
279  return mdata.x;
280  }
281 
284  {
285  return mdata.ln_g;
286  }
287 
290  {
291  return mdata.ln_a;
292  }
293 
296  {
297  return mdata.u;
298  }
299 
302  {
303  return mdata.V0 + mdata.Vxi;
304  }
305 
308  {
309  return mdata.V0;
310  }
311 
314  {
315  return mdata.VT0;
316  }
317 
320  {
321  return mdata.VP0;
322  }
323 
326  {
327  return mdata.G0;
328  }
329 
332  {
333  return mdata.H0;
334  }
335 
338  {
339  return (mdata.H0 - mdata.G0)/mdata.T; // from G0 = H0 - T*S0
340  }
341 
344  {
345  return mdata.H0 - mdata.P * mdata.V0; // from H0 = U0 + P*V0
346  }
347 
350  {
351  return mdata.G0 - mdata.P * mdata.V0; // from A0 = U0 - T*S0 = (H0 - P*V0) + (G0 - H0) = G0 - P*V0
352  }
353 
356  {
357  return mdata.Cp0;
358  }
359 
362  {
363  const auto& Cp0 = mdata.Cp0;
364  const auto& T = mdata.T;
365  const auto& VT0 = mdata.VT0;
366  const auto& VP0 = mdata.VP0;
367  return (VP0 == 0.0).select(Cp0, Cp0 + T*VT0*VT0/VP0); // from Cv0 = Cp0 + T*VT0*VT0/VP0
368  }
369 
371  auto molarMass() const -> real
372  {
373  return mdata.msum / mdata.nsum;
374  }
375 
377  auto molarVolume() const -> real
378  {
379  return (mdata.x * mdata.V0).sum() + mdata.Vx;
380  }
381 
383  auto molarVolumeT() const -> real
384  {
385  return (mdata.x * mdata.VT0).sum() + mdata.VxT;
386  }
387 
389  auto molarVolumeP() const -> real
390  {
391  return (mdata.x * mdata.VP0).sum() + mdata.VxP;
392  }
393 
395  auto molarGibbsEnergy() const -> real
396  {
397  return (mdata.x * mdata.G0).sum() + mdata.Gx;
398  }
399 
401  auto molarEnthalpy() const -> real
402  {
403  return (mdata.x * mdata.H0).sum() + mdata.Hx;
404  }
405 
407  auto molarEntropy() const -> real
408  {
409  const auto S0 = (mdata.H0 - mdata.G0)/mdata.T; // from G0 = H0 - T*S0
410  const auto Sx = (mdata.Hx - mdata.Gx)/mdata.T; // from Gx = Hx - T*Sx
411  return (mdata.x * S0).sum() + Sx;
412  }
413 
415  auto molarInternalEnergy() const -> real
416  {
417  const auto U0 = mdata.H0 - mdata.P * mdata.V0; // from H0 = U0 + P*V0
418  const auto Ux = mdata.Hx - mdata.P * mdata.Vx; // from Hx = U0 + P*Vx
419  return (mdata.x * U0).sum() + Ux;
420  }
421 
423  auto molarHelmholtzEnergy() const -> real
424  {
425  const auto A0 = mdata.G0 - mdata.P * mdata.V0; // from A0 = U0 - T*S0 = (H0 - P*V0) + (G0 - H0) = G0 - P*V0
426  const auto Ax = mdata.Gx - mdata.P * mdata.Vx; // from Ax = U0 - T*Sx = (Hx - P*Vx) + (Gx - Hx) = Gx - P*Vx
427  return (mdata.x * A0).sum() + Ax;
428  }
429 
432  {
433  return (mdata.x * mdata.Cp0).sum() + mdata.Cpx;
434  }
435 
438  {
439  const auto Cp = molarHeatCapacityConstP();
440  const auto VT = molarVolumeT();
441  const auto VP = molarVolumeP();
442  const auto T = temperature();
443  return VP == 0.0 ? Cp : Cp + T*VT*VT/VP;
444  }
445 
447  auto specificVolume() const -> real
448  {
449  return molarVolume() / molarMass();
450  }
451 
453  auto specificVolumeT() const -> real
454  {
455  return molarVolumeT() / molarMass();
456  }
457 
459  auto specificVolumeP() const -> real
460  {
461  return molarVolumeP() / molarMass();
462  }
463 
465  auto specificGibbsEnergy() const -> real
466  {
467  return molarGibbsEnergy() / molarMass();
468  }
469 
471  auto specificEnthalpy() const -> real
472  {
473  return molarEnthalpy() / molarMass();
474  }
475 
477  auto specificEntropy() const -> real
478  {
479  return molarEntropy() / molarMass();
480  }
481 
483  auto specificInternalEnergy() const -> real
484  {
485  return molarInternalEnergy() / molarMass();
486  }
487 
490  {
491  return molarHelmholtzEnergy() / molarMass();
492  }
493 
496  {
497  return molarHeatCapacityConstP() / molarMass();
498  }
499 
502  {
503  return molarHeatCapacityConstV() / molarMass();
504  }
505 
507  auto density() const -> real
508  {
509  return molarMass() / molarVolume();
510  }
511 
513  auto amount() const -> real
514  {
515  return mdata.nsum;
516  }
517 
519  auto mass() const -> real
520  {
521  return mdata.msum;
522  }
523 
525  auto volume() const -> real
526  {
527  return molarVolume() * amount();
528  }
529 
531  auto volumeT() const -> real
532  {
533  return molarVolumeT() * amount();
534  }
535 
537  auto volumeP() const -> real
538  {
539  return molarVolumeP() * amount();
540  }
541 
543  auto gibbsEnergy() const -> real
544  {
545  return molarGibbsEnergy() * amount();
546  }
547 
549  auto enthalpy() const -> real
550  {
551  return molarEnthalpy() * amount();
552  }
553 
555  auto entropy() const -> real
556  {
557  return molarEntropy() * amount();
558  }
559 
561  auto internalEnergy() const -> real
562  {
563  return molarInternalEnergy() * amount();
564  }
565 
567  auto helmholtzEnergy() const -> real
568  {
569  return molarHelmholtzEnergy() * amount();
570  }
571 
573  auto heatCapacityConstP() const -> real
574  {
575  return molarHeatCapacityConstP() * amount();
576  }
577 
579  auto heatCapacityConstV() const -> real
580  {
581  return molarHeatCapacityConstV() * amount();
582  }
583 
585  auto soundSpeed() const -> real
586  {
587  const auto rho = density();
588  const auto Cp = molarHeatCapacityConstP();
589  const auto Cv = molarHeatCapacityConstV();
590  const auto VP = molarVolumeP();
591  const auto MM = molarMass();
592  return sqrt(-MM * Cp/Cv / VP) / rho;
593  }
594 
596  auto operator=(const ArrayStream<real>& array)
597  {
598  mdata = array;
599  return *this;
600  }
601 
603  operator ArrayStream<real>() const
604  {
605  return mdata;
606  }
607 
608  // Ensure other ChemicalPropsPhaseBase types are friend among themselves.
609  template<template<typename> typename OtherTypeOp>
610  friend class ChemicalPropsPhaseBase;
611 
612 private:
614  Phase mphase;
615 
618 
619 private:
620 
626  template<bool use_ideal_activity_model>
627  auto _update(const real& T, const real& P, ArrayXrConstRef n, Map<String, Any>& extra)
628  {
629  mdata.T = T;
630  mdata.P = P;
631  mdata.n = n;
632 
633  const auto R = universalGasConstant;
634 
635  auto& nsum = mdata.nsum;
636  auto& msum = mdata.msum;
637  auto& x = mdata.x;
638  auto& G0 = mdata.G0;
639  auto& H0 = mdata.H0;
640  auto& V0 = mdata.V0;
641  auto& VT0 = mdata.VT0;
642  auto& VP0 = mdata.VP0;
643  auto& Cp0 = mdata.Cp0;
644  auto& Vx = mdata.Vx;
645  auto& VxT = mdata.VxT;
646  auto& VxP = mdata.VxP;
647  auto& Gx = mdata.Gx;
648  auto& Hx = mdata.Hx;
649  auto& Cpx = mdata.Cpx;
650  auto& Vxi = mdata.Vxi;
651  auto& ln_g = mdata.ln_g;
652  auto& ln_a = mdata.ln_a;
653  auto& u = mdata.u;
654  auto& som = mdata.som;
655 
656  const auto& species = phase().species();
657  const auto N = species.size();
658 
659  assert( n.size() == N );
660  assert( G0.size() == N );
661  assert( H0.size() == N );
662  assert( V0.size() == N );
663  assert( VT0.size() == N );
664  assert( VP0.size() == N );
665  assert( Cp0.size() == N );
666  assert( ln_g.size() == N );
667  assert( ln_a.size() == N );
668  assert( u.size() == N );
669  assert( Vxi.size() == N );
670 
671  // Compute the standard thermodynamic properties of the species in the phase.
673  for(auto i = 0; i < N; ++i)
674  {
675  aux = species[i].standardThermoProps(T, P);
676  G0[i] = aux.G0;
677  H0[i] = aux.H0;
678  V0[i] = aux.V0;
679  VT0[i] = aux.VT0;
680  VP0[i] = aux.VP0;
681  Cp0[i] = aux.Cp0;
682  }
683 
684  // Compute the amount of the phase
685  nsum = n.sum();
686 
687  // Compute the mass of the phase
688  msum = (n * mphase.speciesMolarMasses()).sum();
689 
690  // Compute the mole fractions of the species
691  if(nsum == 0.0)
692  x = (N == 1) ? 1.0 : 0.0;
693  else x = n / nsum;
694 
695  // Ensure there are no zero mole fractions
696  error(x.minCoeff() == 0.0, "Could not compute the chemical properties of phase ",
697  phase().name(), " because it has one or more species with zero amounts.");
698 
699  // Compute the activity properties of the phase
700  ActivityPropsRef aprops{ Vx, VxT, VxP, Vxi, Gx, Hx, Cpx, ln_g, ln_a, som, extra };
701  ActivityModelArgs args{ T, P, x };
702  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.
703  phase().idealActivityModel() : phase().activityModel();
704 
705  if(nsum == 0.0) aprops = 0.0;
706  else activity_model(aprops, args);
707 
708  // Compute the chemical potentials of the species
709  u = G0 + R*T*ln_a;
710  }
711 };
712 
715 
718 
721 
722 } // 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:175
auto molarVolume() const -> real
Return the molar volume of the phase (in m³/mol).
Definition: ChemicalPropsPhase.hpp:377
auto molarVolumeP() const -> real
Return the pressure derivative of the molar volume of the phase (in m³/(mol·Pa)).
Definition: ChemicalPropsPhase.hpp:389
auto temperature() const -> real
Return the temperature of the phase (in K).
Definition: ChemicalPropsPhase.hpp:259
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:313
auto specificGibbsEnergy() const -> real
Return the specific Gibbs energy of formation of the phase (in J/kg).
Definition: ChemicalPropsPhase.hpp:465
auto pressure() const -> real
Return the pressure of the phase (in Pa).
Definition: ChemicalPropsPhase.hpp:265
auto volumeT() const -> real
Return the temperature derivative of the volume of the phase (in m³/K).
Definition: ChemicalPropsPhase.hpp:531
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:343
auto mass() const -> real
Return the sum of species masses in the phase (in kg).
Definition: ChemicalPropsPhase.hpp:519
auto speciesActivitiesLn() const -> ArrayXrConstRef
Return the ln activities of the species in the phase.
Definition: ChemicalPropsPhase.hpp:289
auto heatCapacityConstP() const -> real
Return the isobaric heat capacity of the phase (in J/K).
Definition: ChemicalPropsPhase.hpp:573
auto speciesChemicalPotentials() const -> ArrayXrConstRef
Return the chemical potentials of the species in the phase (in J/mol).
Definition: ChemicalPropsPhase.hpp:295
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:355
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:337
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:325
auto updateWithData(const ChemicalPropsPhaseBaseData< TypeOp > &data)
Update the chemical properties of the phase with given data.
Definition: ChemicalPropsPhase.hpp:235
auto entropy() const -> real
Return the entropy of the phase (in J/K).
Definition: ChemicalPropsPhase.hpp:555
ChemicalPropsPhaseBase(ChemicalPropsPhaseBase< OtherTypeOp > &other)
Construct a ChemicalPropsPhaseBase instance.
Definition: ChemicalPropsPhase.hpp:204
auto specificInternalEnergy() const -> real
Return the specific internal energy of formation of the phase (in J/kg).
Definition: ChemicalPropsPhase.hpp:483
auto speciesStandardEnthalpies() const -> ArrayXrConstRef
Return the standard partial molar enthalpies of formation of the species in the phase (in J/mol).
Definition: ChemicalPropsPhase.hpp:331
auto volume() const -> real
Return the volume of the phase (in m³).
Definition: ChemicalPropsPhase.hpp:525
auto data() const -> const ChemicalPropsPhaseBaseData< TypeOp > &
Return the primary chemical property data of the phase from which others are calculated.
Definition: ChemicalPropsPhase.hpp:247
auto molarHeatCapacityConstV() const -> real
Return the molar isochoric heat capacity of the phase (in J/(mol·K)).
Definition: ChemicalPropsPhase.hpp:437
auto speciesActivityCoefficientsLn() const -> ArrayXrConstRef
Return the ln activity coefficients of the species in the phase.
Definition: ChemicalPropsPhase.hpp:283
auto phase() const -> const Phase &
Return the underlying Phase object.
Definition: ChemicalPropsPhase.hpp:241
auto specificVolume() const -> real
Return the specific volume of the phase (in m³/kg).
Definition: ChemicalPropsPhase.hpp:447
auto speciesStandardVolumes() const -> ArrayXrConstRef
Return the standard partial molar volumes of the species in the phase (in m³/mol).
Definition: ChemicalPropsPhase.hpp:307
auto specificEnthalpy() const -> real
Return the specific enthalpy of formation of the phase (in J/kg).
Definition: ChemicalPropsPhase.hpp:471
auto speciesAmounts() const -> ArrayXrConstRef
Return the amounts of the species in the phase (in mol).
Definition: ChemicalPropsPhase.hpp:271
auto specificVolumeT() const -> real
Return the temperature derivative of the specific volume of the phase (in m³/(kg·K)).
Definition: ChemicalPropsPhase.hpp:453
auto specificHeatCapacityConstV() const -> real
Return the specific isochoric heat capacity of the phase (in J/(kg·K)).
Definition: ChemicalPropsPhase.hpp:501
auto specificHeatCapacityConstP() const -> real
Return the specific isobaric heat capacity of the phase (in J/(kg·K)).
Definition: ChemicalPropsPhase.hpp:495
auto internalEnergy() const -> real
Return the internal energy of the phase (in J).
Definition: ChemicalPropsPhase.hpp:561
auto molarGibbsEnergy() const -> real
Return the molar Gibbs energy of formation of the phase (in J/mol).
Definition: ChemicalPropsPhase.hpp:395
auto speciesPartialMolarVolumes() const -> ArrayXrConstRef
Return the partial molar volumes of the species in the phase (in m³/mol).
Definition: ChemicalPropsPhase.hpp:301
auto update(const real &T, const real &P, ArrayXrConstRef n, Map< String, Any > &extra)
Update the chemical properties of the phase.
Definition: ChemicalPropsPhase.hpp:219
auto molarHeatCapacityConstP() const -> real
Return the molar isobaric heat capacity of the phase (in J/(mol·K)).
Definition: ChemicalPropsPhase.hpp:431
auto molarHelmholtzEnergy() const -> real
Return the molar Helmholtz energy of formation of the phase (in J/mol).
Definition: ChemicalPropsPhase.hpp:423
auto specificHelmholtzEnergy() const -> real
Return the specific Helmholtz energy of formation of the phase (in J/kg).
Definition: ChemicalPropsPhase.hpp:489
auto helmholtzEnergy() const -> real
Return the Helmholtz energy of the phase (in J).
Definition: ChemicalPropsPhase.hpp:567
auto amount() const -> real
Return the sum of species amounts in the phase (in mol).
Definition: ChemicalPropsPhase.hpp:513
auto molarEntropy() const -> real
Return the molar entropy of formation of the phase (in J/(mol·K)).
Definition: ChemicalPropsPhase.hpp:407
ChemicalPropsPhaseBase(const ChemicalPropsPhaseBase< OtherTypeOp > &other)
Construct a ChemicalPropsPhaseBase instance.
Definition: ChemicalPropsPhase.hpp:210
auto speciesMoleFractions() const -> ArrayXrConstRef
Return the mole fractions of the species in the phase.
Definition: ChemicalPropsPhase.hpp:277
auto stateOfMatter() const -> StateOfMatter
Return the state of matter of the phase.
Definition: ChemicalPropsPhase.hpp:253
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:319
auto heatCapacityConstV() const -> real
Return the isochoric heat capacity of the phase (in J/K).
Definition: ChemicalPropsPhase.hpp:579
auto molarInternalEnergy() const -> real
Return the molar internal energy of formation of the phase (in J/mol).
Definition: ChemicalPropsPhase.hpp:415
auto volumeP() const -> real
Return the pressure derivative of the volume of the phase (in m³/Pa).
Definition: ChemicalPropsPhase.hpp:537
auto operator=(const ArrayStream< real > &array)
Assign the given array data to this ChemicalPropsPhaseBase object.
Definition: ChemicalPropsPhase.hpp:596
ChemicalPropsPhaseBase(const Phase &phase)
Construct a ChemicalPropsPhaseBase instance.
Definition: ChemicalPropsPhase.hpp:178
auto gibbsEnergy() const -> real
Return the Gibbs energy of the phase (in J).
Definition: ChemicalPropsPhase.hpp:543
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:361
auto molarMass() const -> real
Return the molar mass of the phase (in kg/mol).
Definition: ChemicalPropsPhase.hpp:371
auto molarVolumeT() const -> real
Return the temperature derivative of the molar volume of the phase (in m³/(mol·K)).
Definition: ChemicalPropsPhase.hpp:383
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:229
auto soundSpeed() const -> real
Return the speed of sound in the phase (in m/s).
Definition: ChemicalPropsPhase.hpp:585
ChemicalPropsPhaseBase(const Phase &phase, const ChemicalPropsPhaseBaseData< TypeOp > &data)
Construct a ChemicalPropsPhaseBase instance.
Definition: ChemicalPropsPhase.hpp:198
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:349
auto enthalpy() const -> real
Return the enthalpy of the phase (in J).
Definition: ChemicalPropsPhase.hpp:549
auto specificEntropy() const -> real
Return the specific entropy of formation of the phase (in J/(kg·K)).
Definition: ChemicalPropsPhase.hpp:477
auto specificVolumeP() const -> real
Return the pressure derivative of the specific volume of the phase (in m³/(kg·Pa)).
Definition: ChemicalPropsPhase.hpp:459
auto density() const -> real
Return the density of the phase (in kg/m³).
Definition: ChemicalPropsPhase.hpp:507
auto molarEnthalpy() const -> real
Return the molar enthalpy of formation of the phase (in J/mol).
Definition: ChemicalPropsPhase.hpp:401
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:29
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:170
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:162
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:257
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:94
TypeOp< real > Gx
The corrective molar Gibbs energy of the phase (in units of J/mol).
Definition: ChemicalPropsPhase.hpp:82
TypeOp< real > VxT
The derivative of the corrective molar volume with respect to temperature at constant pressure and sp...
Definition: ChemicalPropsPhase.hpp:73
TypeOp< ArrayXr > Vxi
The derivatives of the corrective molar volume with respect to species mole fractions at constant tem...
Definition: ChemicalPropsPhase.hpp:79
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:104
TypeOp< real > Hx
The corrective molar enthalpy of the phase (in units of J/mol).
Definition: ChemicalPropsPhase.hpp:85
TypeOp< real > Cpx
The corrective molar isobaric heat capacity of the phase (in units of J/(mol·K)).
Definition: ChemicalPropsPhase.hpp:88
TypeOp< ArrayXr > ln_g
The activity coefficients (natural log) of the species in the phase.
Definition: ChemicalPropsPhase.hpp:91
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:97
TypeOp< StateOfMatter > som
The state of matter of the phase.
Definition: ChemicalPropsPhase.hpp:100
auto operator=(const ArrayStream< real > &array)
Assign the given array data to this ChemicalPropsPhaseBaseData object.
Definition: ChemicalPropsPhase.hpp:147
TypeOp< real > Vx
The corrective molar volume of the phase (in m³/mol).
Definition: ChemicalPropsPhase.hpp:70
TypeOp< real > VxP
The derivative of the corrective molar volume with respect to pressure at constant temperature and sp...
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