Simplified some casting operations in clib

This commit is contained in:
Ray Speth 2012-08-02 15:48:09 +00:00
parent cd706b355f
commit 38fbe6781e
3 changed files with 21 additions and 48 deletions

View file

@ -38,16 +38,6 @@ template<> ThermoCabinet* ThermoCabinet::__storage = 0;
template<> KineticsCabinet* KineticsCabinet::__storage = 0;
template<> TransportCabinet* TransportCabinet::__storage = 0;
static PureFluidPhase* purefluid(int n)
{
PureFluidPhase* p = dynamic_cast<PureFluidPhase*>(&ThermoCabinet::item(n));
if (p) {
return p;
} else {
throw CanteraError("purefluid","object is not a PureFluidPhase object");
}
}
/**
* Exported functions.
*/
@ -729,7 +719,7 @@ extern "C" {
double th_critTemperature(int n)
{
try {
return purefluid(n)->critTemperature();
return ThermoCabinet::get<PureFluidPhase>(n).critTemperature();
} catch (...) {
return handleAllExceptions(DERR, DERR);
}
@ -738,7 +728,7 @@ extern "C" {
double th_critPressure(int n)
{
try {
return purefluid(n)->critPressure();
return ThermoCabinet::get<PureFluidPhase>(n).critPressure();
} catch (...) {
return handleAllExceptions(DERR, DERR);
}
@ -747,7 +737,7 @@ extern "C" {
double th_critDensity(int n)
{
try {
return purefluid(n)->critDensity();
return ThermoCabinet::get<PureFluidPhase>(n).critDensity();
} catch (...) {
return handleAllExceptions(DERR, DERR);
}
@ -756,7 +746,7 @@ extern "C" {
double th_vaporFraction(int n)
{
try {
return purefluid(n)->vaporFraction();
return ThermoCabinet::get<PureFluidPhase>(n).vaporFraction();
} catch (...) {
return handleAllExceptions(DERR, DERR);
}
@ -765,7 +755,7 @@ extern "C" {
double th_satTemperature(int n, double p)
{
try {
return purefluid(n)->satTemperature(p);
return ThermoCabinet::get<PureFluidPhase>(n).satTemperature(p);
} catch (...) {
return handleAllExceptions(DERR, DERR);
}
@ -774,7 +764,7 @@ extern "C" {
double th_satPressure(int n, double t)
{
try {
return purefluid(n)->satPressure(t);
return ThermoCabinet::get<PureFluidPhase>(n).satPressure(t);
} catch (...) {
return handleAllExceptions(DERR, DERR);
}
@ -783,7 +773,7 @@ extern "C" {
int th_setState_Psat(int n, double p, double x)
{
try {
purefluid(n)->setState_Psat(p, x);
ThermoCabinet::get<PureFluidPhase>(n).setState_Psat(p, x);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -793,7 +783,7 @@ extern "C" {
int th_setState_Tsat(int n, double t, double x)
{
try {
purefluid(n)->setState_Tsat(t, x);
ThermoCabinet::get<PureFluidPhase>(n).setState_Tsat(t, x);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -1202,13 +1192,7 @@ extern "C" {
int kin_advanceCoverages(int n, double tstep)
{
try {
Kinetics& k = KineticsCabinet::item(n);
if (k.type() == cInterfaceKinetics) {
dynamic_cast<InterfaceKinetics*>(&k)->advanceCoverages(tstep);
} else {
throw CanteraError("kin_advanceCoverages",
"wrong kinetics manager type");
}
KineticsCabinet::get<InterfaceKinetics>(n).advanceCoverages(tstep);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);

View file

@ -77,7 +77,7 @@ extern "C" {
double bndry_spreadrate(int i)
{
try {
return dynamic_cast<Inlet1D&>(BoundaryCabinet::item(i)).spreadRate();
return BoundaryCabinet::get<Inlet1D>(i).spreadRate();
} catch (...) {
return Cantera::handleAllExceptions(-1, ERR);
}
@ -87,7 +87,7 @@ extern "C" {
int bndry_setSpreadRate(int i, double v)
{
try {
dynamic_cast<Inlet1D&>(BoundaryCabinet::item(i)).setSpreadRate(v);
BoundaryCabinet::get<Inlet1D>(i).setSpreadRate(v);
} catch (...) {
return Cantera::handleAllExceptions(-1, ERR);
}
@ -136,11 +136,8 @@ extern "C" {
int surf_setkinetics(int i, int j)
{
try {
ReactingSurf1D& srf =
dynamic_cast<ReactingSurf1D&>(BoundaryCabinet::item(i));
InterfaceKinetics& k =
dynamic_cast<InterfaceKinetics&>(Cabinet<Kinetics>::item(j));
srf.setKineticsMgr(&k);
InterfaceKinetics& k = Cabinet<Kinetics>::get<InterfaceKinetics>(j);
BoundaryCabinet::get<ReactingSurf1D>(i).setKineticsMgr(&k);
} catch (...) {
return Cantera::handleAllExceptions(-1, ERR);
}

View file

@ -14,22 +14,14 @@
using namespace std;
using namespace Cantera;
inline SurfPhase& _surfphase(int n)
{
return dynamic_cast<SurfPhase&>(Cabinet<ThermoPhase>::item(n));
}
inline InterfaceKinetics& _surfkin(int n)
{
return dynamic_cast<InterfaceKinetics&>(Cabinet<Kinetics>::item(n));
}
typedef Cabinet<ThermoPhase> ThermoCabinet;
extern "C" {
int surf_setsitedensity(int i, double s0)
{
try {
_surfphase(i).setSiteDensity(s0);
ThermoCabinet::get<SurfPhase>(i).setSiteDensity(s0);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -39,7 +31,7 @@ extern "C" {
double surf_sitedensity(int i)
{
try {
return _surfphase(i).siteDensity();
return ThermoCabinet::get<SurfPhase>(i).siteDensity();
} catch (...) {
return handleAllExceptions(DERR, DERR);
}
@ -48,7 +40,7 @@ extern "C" {
int surf_setcoverages(int i, double* c)
{
try {
_surfphase(i).setCoverages(c);
ThermoCabinet::get<SurfPhase>(i).setCoverages(c);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -58,7 +50,7 @@ extern "C" {
int surf_setcoveragesbyname(int i, char* c)
{
try {
_surfphase(i).setCoveragesByName(string(c));
ThermoCabinet::get<SurfPhase>(i).setCoveragesByName(string(c));
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -68,7 +60,7 @@ extern "C" {
int surf_getcoverages(int i, double* c)
{
try {
_surfphase(i).getCoverages(c);
ThermoCabinet::get<SurfPhase>(i).getCoverages(c);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -78,7 +70,7 @@ extern "C" {
int surf_setconcentrations(int i, double* c)
{
try {
_surfphase(i).setConcentrations(c);
ThermoCabinet::get<SurfPhase>(i).setConcentrations(c);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
@ -88,7 +80,7 @@ extern "C" {
int surf_getconcentrations(int i, double* c)
{
try {
_surfphase(i).getConcentrations(c);
ThermoCabinet::get<SurfPhase>(i).getConcentrations(c);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);