Skip to content

Commit

Permalink
[Equil] Replace PropertyCalculator with simple lambdas
Browse files Browse the repository at this point in the history
  • Loading branch information
speth committed Apr 19, 2016
1 parent f4ad150 commit 3566542
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 129 deletions.
6 changes: 2 additions & 4 deletions include/cantera/equil/ChemEquil.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "cantera/base/ct_defs.h"
#include "cantera/base/ctexceptions.h"
#include "cantera/thermo/ThermoPhase.h"
#include <functional>

namespace Cantera
{
Expand Down Expand Up @@ -55,9 +56,6 @@ class EquilOpt
bool contin;
};

template<class M>
class PropertyCalculator;

/**
* @defgroup equil Chemical Equilibrium
*/
Expand Down Expand Up @@ -266,7 +264,7 @@ class ChemEquil
//! it is computed. It's initialized to #m_mm.
size_t m_nComponents;

std::unique_ptr<PropertyCalculator<thermo_t> > m_p1, m_p2;
std::function<double(ThermoPhase&)> m_p1, m_p2;

//! Current value of the mole fractions in the single phase. length = #m_kk.
vector_fp m_molefractions;
Expand Down
44 changes: 21 additions & 23 deletions src/equil/ChemEquil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
// Copyright 2001 California Institute of Technology

#include "cantera/equil/ChemEquil.h"

#include "PropertyCalculator.h"
#include "cantera/base/stringUtils.h"
#include "cantera/equil/MultiPhaseEquil.h"

Expand Down Expand Up @@ -339,37 +337,37 @@ int ChemEquil::equilibrate(thermo_t& s, const char* XYstr,
switch (XY) {
case TP:
case PT:
m_p1.reset(new TemperatureCalculator<thermo_t>);
m_p2.reset(new PressureCalculator<thermo_t>);
m_p1 = [](ThermoPhase& s) { return s.temperature(); };
m_p2 = [](ThermoPhase& s) { return s.pressure(); };
break;
case HP:
case PH:
tempFixed = false;
m_p1.reset(new EnthalpyCalculator<thermo_t>);
m_p2.reset(new PressureCalculator<thermo_t>);
m_p1 = [](ThermoPhase& s) { return s.enthalpy_mass(); };
m_p2 = [](ThermoPhase& s) { return s.pressure(); };
break;
case SP:
case PS:
tempFixed = false;
m_p1.reset(new EntropyCalculator<thermo_t>);
m_p2.reset(new PressureCalculator<thermo_t>);
m_p1 = [](ThermoPhase& s) { return s.entropy_mass(); };
m_p2 = [](ThermoPhase& s) { return s.pressure(); };
break;
case SV:
case VS:
tempFixed = false;
m_p1.reset(new EntropyCalculator<thermo_t>);
m_p2.reset(new DensityCalculator<thermo_t>);
m_p1 = [](ThermoPhase& s) { return s.entropy_mass(); };
m_p2 = [](ThermoPhase& s) { return s.density(); };
break;
case TV:
case VT:
m_p1.reset(new TemperatureCalculator<thermo_t>);
m_p2.reset(new DensityCalculator<thermo_t>);
m_p1 = [](ThermoPhase& s) { return s.temperature(); };
m_p2 = [](ThermoPhase& s) { return s.density(); };
break;
case UV:
case VU:
tempFixed = false;
m_p1.reset(new IntEnergyCalculator<thermo_t>);
m_p2.reset(new DensityCalculator<thermo_t>);
m_p1 = [](ThermoPhase& s) { return s.intEnergy_mass(); };
m_p2 = [](ThermoPhase& s) { return s.density(); };
break;
default:
throw CanteraError("equilibrate","illegal property pair.");
Expand All @@ -387,8 +385,8 @@ int ChemEquil::equilibrate(thermo_t& s, const char* XYstr,

// Before we do anything to change the ThermoPhase object, we calculate and
// store the two specified thermodynamic properties that we are after.
double xval = m_p1->value(s);
double yval = m_p2->value(s);
double xval = m_p1(s);
double yval = m_p2(s);

size_t mm = m_mm;
size_t nvar = mm + 1;
Expand Down Expand Up @@ -447,11 +445,11 @@ int ChemEquil::equilibrate(thermo_t& s, const char* XYstr,

s.setTemperature(tmax);
setInitialMoles(s, elMolesGoal, loglevel - 1);
phigh = m_p1->value(s);
phigh = m_p1(s);

s.setTemperature(tmin);
setInitialMoles(s, elMolesGoal, loglevel - 1);
plow = m_p1->value(s);
plow = m_p1(s);

// start with T at the midpoint of the range
doublereal t0 = 0.5*(tmin + tmax);
Expand All @@ -461,7 +459,7 @@ int ChemEquil::equilibrate(thermo_t& s, const char* XYstr,
for (int it = 0; it < 10; it++) {
// set the composition and get p1
setInitialMoles(s, elMolesGoal, loglevel - 1);
pval = m_p1->value(s);
pval = m_p1(s);

// If this value of p1 is greater than the specified property value,
// then the current temperature is too high. Use it as the new upper
Expand Down Expand Up @@ -566,8 +564,8 @@ int ChemEquil::equilibrate(thermo_t& s, const char* XYstr,
// check for convergence.
equilResidual(s, x, elMolesGoal, res_trial, xval, yval);
double f = 0.5*dot(res_trial.begin(), res_trial.end(), res_trial.begin());
double xx = m_p1->value(s);
double yy = m_p2->value(s);
double xx = m_p1(s);
double yy = m_p2(s);
double deltax = (xx - xval)/xval;
double deltay = (yy - yval)/yval;
bool passThis = true;
Expand Down Expand Up @@ -785,8 +783,8 @@ void ChemEquil::equilResidual(thermo_t& s, const vector_fp& x,
}
}

double xx = m_p1->value(s);
double yy = m_p2->value(s);
double xx = m_p1(s);
double yy = m_p2(s);
resid[m_mm] = xx/xval - 1.0;
resid[m_skip] = yy/yval - 1.0;

Expand Down
102 changes: 0 additions & 102 deletions src/equil/PropertyCalculator.h

This file was deleted.

0 comments on commit 3566542

Please sign in to comment.