Reaktoro  v2.13.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 correctiveMolarVolume() const -> real
396  {
397  return mdata.Vx;
398  }
400  auto correctiveMolarVolumeT() const -> real
401  {
402  return mdata.VxT;
403  }
404  // Return the corrective pressure derivative of the molar volume of the phase (in m³/(mol·Pa)).
405  auto correctiveMolarVolumeP() const -> real
406  {
407  return mdata.VxP;
408  }
409 
411  auto molarGibbsEnergy() const -> real
412  {
413  return (mdata.x * mdata.G0).sum() + mdata.Gx;
414  }
415 
418  {
419  return mdata.Gx;
420  }
421 
423  auto molarEnthalpy() const -> real
424  {
425  return (mdata.x * mdata.H0).sum() + mdata.Hx;
426  }
427 
430  {
431  return mdata.Hx;
432  }
434  auto molarEntropy() const -> real
435  {
436  const auto S0 = (mdata.H0 - mdata.G0)/mdata.T; // from G0 = H0 - T*S0
437  const auto Sx = (mdata.Hx - mdata.Gx)/mdata.T; // from Gx = Hx - T*Sx
438  return (mdata.x * S0).sum() + Sx;
439  }
440 
442  auto molarInternalEnergy() const -> real
443  {
444  const auto U0 = mdata.H0 - mdata.P * mdata.V0; // from H0 = U0 + P*V0
445  const auto Ux = mdata.Hx - mdata.P * mdata.Vx; // from Hx = U0 + P*Vx
446  return (mdata.x * U0).sum() + Ux;
447  }
448 
450  auto molarHelmholtzEnergy() const -> real
451  {
452  const auto A0 = mdata.G0 - mdata.P * mdata.V0; // from A0 = U0 - T*S0 = (H0 - P*V0) + (G0 - H0) = G0 - P*V0
453  const auto Ax = mdata.Gx - mdata.P * mdata.Vx; // from Ax = U0 - T*Sx = (Hx - P*Vx) + (Gx - Hx) = Gx - P*Vx
454  return (mdata.x * A0).sum() + Ax;
455  }
456 
459  {
460  return (mdata.x * mdata.Cp0).sum() + mdata.Cpx;
461  }
462 
465  {
466  return mdata.Cpx;
467  }
468 
469 
472  {
473  const auto Cp = molarHeatCapacityConstP();
474  const auto VT = molarVolumeT();
475  const auto VP = molarVolumeP();
476  const auto T = temperature();
477  return VP == 0.0 ? Cp : Cp + T*VT*VT/VP;
478  }
479 
481  auto specificVolume() const -> real
482  {
483  return molarVolume() / molarMass();
484  }
485 
487  auto specificVolumeT() const -> real
488  {
489  return molarVolumeT() / molarMass();
490  }
491 
493  auto specificVolumeP() const -> real
494  {
495  return molarVolumeP() / molarMass();
496  }
497 
499  auto specificGibbsEnergy() const -> real
500  {
501  return molarGibbsEnergy() / molarMass();
502  }
503 
505  auto specificEnthalpy() const -> real
506  {
507  return molarEnthalpy() / molarMass();
508  }
509 
511  auto specificEntropy() const -> real
512  {
513  return molarEntropy() / molarMass();
514  }
515 
517  auto specificInternalEnergy() const -> real
518  {
519  return molarInternalEnergy() / molarMass();
520  }
521 
524  {
525  return molarHelmholtzEnergy() / molarMass();
526  }
527 
530  {
531  return molarHeatCapacityConstP() / molarMass();
532  }
533 
536  {
537  return molarHeatCapacityConstV() / molarMass();
538  }
539 
541  auto density() const -> real
542  {
543  return molarMass() / molarVolume();
544  }
545 
547  auto amount() const -> real
548  {
549  return mdata.nsum;
550  }
551 
553  auto mass() const -> real
554  {
555  return mdata.msum;
556  }
557 
559  auto volume() const -> real
560  {
561  return molarVolume() * amount();
562  }
563 
565  auto volumeT() const -> real
566  {
567  return molarVolumeT() * amount();
568  }
569 
571  auto volumeP() const -> real
572  {
573  return molarVolumeP() * amount();
574  }
575 
577  auto gibbsEnergy() const -> real
578  {
579  return molarGibbsEnergy() * amount();
580  }
581 
583  auto enthalpy() const -> real
584  {
585  return molarEnthalpy() * amount();
586  }
587 
589  auto entropy() const -> real
590  {
591  return molarEntropy() * amount();
592  }
593 
595  auto internalEnergy() const -> real
596  {
597  return molarInternalEnergy() * amount();
598  }
599 
601  auto helmholtzEnergy() const -> real
602  {
603  return molarHelmholtzEnergy() * amount();
604  }
605 
607  auto heatCapacityConstP() const -> real
608  {
609  return molarHeatCapacityConstP() * amount();
610  }
611 
613  auto heatCapacityConstV() const -> real
614  {
615  return molarHeatCapacityConstV() * amount();
616  }
617 
619  auto soundSpeed() const -> real
620  {
621  const auto rho = density();
622  const auto Cp = molarHeatCapacityConstP();
623  const auto Cv = molarHeatCapacityConstV();
624  const auto VP = molarVolumeP();
625  const auto MM = molarMass();
626  return sqrt(-MM * Cp/Cv / VP) / rho;
627  }
628 
630  auto operator=(const ArrayStream<real>& array)
631  {
632  mdata = array;
633  return *this;
634  }
635 
637  operator ArrayStream<real>() const
638  {
639  return mdata;
640  }
641 
642  // Ensure other ChemicalPropsPhaseBase types are friend among themselves.
643  template<template<typename> typename OtherTypeOp>
644  friend class ChemicalPropsPhaseBase;
645 
646 private:
648  Phase mphase;
649 
652 
653 private:
654 
660  template<bool use_ideal_activity_model>
661  auto _update(const real& T, const real& P, ArrayXrConstRef n, Map<String, Any>& extra)
662  {
663  mdata.T = T;
664  mdata.P = P;
665  mdata.n = n;
666 
667  const auto R = universalGasConstant;
668 
669  auto& nsum = mdata.nsum;
670  auto& msum = mdata.msum;
671  auto& x = mdata.x;
672  auto& G0 = mdata.G0;
673  auto& H0 = mdata.H0;
674  auto& V0 = mdata.V0;
675  auto& VT0 = mdata.VT0;
676  auto& VP0 = mdata.VP0;
677  auto& Cp0 = mdata.Cp0;
678  auto& Vx = mdata.Vx;
679  auto& VxT = mdata.VxT;
680  auto& VxP = mdata.VxP;
681  auto& Gx = mdata.Gx;
682  auto& Hx = mdata.Hx;
683  auto& Cpx = mdata.Cpx;
684  auto& Vxi = mdata.Vxi;
685  auto& ln_g = mdata.ln_g;
686  auto& ln_a = mdata.ln_a;
687  auto& u = mdata.u;
688  auto& som = mdata.som;
689 
690  const auto& species = phase().species();
691  const auto N = species.size();
692 
693  assert( n.size() == N );
694  assert( G0.size() == N );
695  assert( H0.size() == N );
696  assert( V0.size() == N );
697  assert( VT0.size() == N );
698  assert( VP0.size() == N );
699  assert( Cp0.size() == N );
700  assert( ln_g.size() == N );
701  assert( ln_a.size() == N );
702  assert( u.size() == N );
703  assert( Vxi.size() == N );
704 
705  // Compute the standard thermodynamic properties of the species in the phase.
707  for(auto i = 0; i < N; ++i)
708  {
709  aux = species[i].standardThermoProps(T, P);
710  G0[i] = aux.G0;
711  H0[i] = aux.H0;
712  V0[i] = aux.V0;
713  VT0[i] = aux.VT0;
714  VP0[i] = aux.VP0;
715  Cp0[i] = aux.Cp0;
716  }
717 
718  // Compute the amount of the phase
719  nsum = n.sum();
720 
721  // Compute the mass of the phase
722  msum = (n * mphase.speciesMolarMasses()).sum();
723 
724  // Compute the mole fractions of the species
725  if(nsum == 0.0)
726  x = (N == 1) ? 1.0 : 0.0;
727  else x = n / nsum;
728 
729  // Ensure there are no zero mole fractions
730  error(x.minCoeff() == 0.0, "Could not compute the chemical properties of phase ",
731  phase().name(), " because it has one or more species with zero amounts.");
732 
733  // Compute the activity properties of the phase
734  ActivityPropsRef aprops{ Vx, VxT, VxP, Vxi, Gx, Hx, Cpx, ln_g, ln_a, som, extra };
735  ActivityModelArgs args{ T, P, x };
736  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.
737  phase().idealActivityModel() : phase().activityModel();
738 
739  if(nsum == 0.0) aprops = 0.0;
740  else activity_model(aprops, args);
741 
742  // Compute the chemical potentials of the species
743  u = G0 + R*T*ln_a;
744  }
745 };
746 
749 
752 
755 
756 } // 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:499
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:565
auto correctiveMolarHeatCapacityConstP() const -> real
Return the corrective molar isobaric heat capacity of the phase (in J/(mol·K)).
Definition: ChemicalPropsPhase.hpp:464
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:553
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:607
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 correctiveMolarVolume() const -> real
Return the corrective molar volume of the phase (in m³/mol).
Definition: ChemicalPropsPhase.hpp:395
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:589
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:517
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:559
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:471
auto correctiveMolarVolumeT() const -> real
Return the corrective temperature derivative of the molar volume of the phase (in m³/(mol·K)).
Definition: ChemicalPropsPhase.hpp:400
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 correctiveMolarGibbsEnergy() const -> real
Return the corrective molar Gibbs energy of formation of the phase (in J/mol).
Definition: ChemicalPropsPhase.hpp:417
auto specificVolume() const -> real
Return the specific volume of the phase (in m³/kg).
Definition: ChemicalPropsPhase.hpp:481
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:505
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:487
auto specificHeatCapacityConstV() const -> real
Return the specific isochoric heat capacity of the phase (in J/(kg·K)).
Definition: ChemicalPropsPhase.hpp:535
auto specificHeatCapacityConstP() const -> real
Return the specific isobaric heat capacity of the phase (in J/(kg·K)).
Definition: ChemicalPropsPhase.hpp:529
auto correctiveMolarEnthalpy() const -> real
Return the corrective molar molar enthalpy of formation of the phase (in J/mol).
Definition: ChemicalPropsPhase.hpp:429
auto internalEnergy() const -> real
Return the internal energy of the phase (in J).
Definition: ChemicalPropsPhase.hpp:595
auto molarGibbsEnergy() const -> real
Return the molar Gibbs energy of formation of the phase (in J/mol).
Definition: ChemicalPropsPhase.hpp:411
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:458
auto molarHelmholtzEnergy() const -> real
Return the molar Helmholtz energy of formation of the phase (in J/mol).
Definition: ChemicalPropsPhase.hpp:450
auto specificHelmholtzEnergy() const -> real
Return the specific Helmholtz energy of formation of the phase (in J/kg).
Definition: ChemicalPropsPhase.hpp:523
auto helmholtzEnergy() const -> real
Return the Helmholtz energy of the phase (in J).
Definition: ChemicalPropsPhase.hpp:601
auto amount() const -> real
Return the sum of species amounts in the phase (in mol).
Definition: ChemicalPropsPhase.hpp:547
auto molarEntropy() const -> real
Return the molar entropy of formation of the phase (in J/(mol·K)).
Definition: ChemicalPropsPhase.hpp:434
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:613
auto molarInternalEnergy() const -> real
Return the molar internal energy of formation of the phase (in J/mol).
Definition: ChemicalPropsPhase.hpp:442
auto volumeP() const -> real
Return the pressure derivative of the volume of the phase (in m³/Pa).
Definition: ChemicalPropsPhase.hpp:571
auto operator=(const ArrayStream< real > &array)
Assign the given array data to this ChemicalPropsPhaseBase object.
Definition: ChemicalPropsPhase.hpp:630
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:577
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:619
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:583
auto specificEntropy() const -> real
Return the specific entropy of formation of the phase (in J/(kg·K)).
Definition: ChemicalPropsPhase.hpp:511
auto specificVolumeP() const -> real
Return the pressure derivative of the specific volume of the phase (in m³/(kg·Pa)).
Definition: ChemicalPropsPhase.hpp:493
auto density() const -> real
Return the density of the phase (in kg/m³).
Definition: ChemicalPropsPhase.hpp:541
auto molarEnthalpy() const -> real
Return the molar enthalpy of formation of the phase (in J/mol).
Definition: ChemicalPropsPhase.hpp:423
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