From 38fbe6781eb2036f6e70861a52efbc74097a6fd6 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Thu, 2 Aug 2012 15:48:09 +0000 Subject: [PATCH] Simplified some casting operations in clib --- src/clib/ct.cpp | 34 +++++++++------------------------- src/clib/ctbdry.cpp | 11 ++++------- src/clib/ctsurf.cpp | 24 ++++++++---------------- 3 files changed, 21 insertions(+), 48 deletions(-) diff --git a/src/clib/ct.cpp b/src/clib/ct.cpp index 70dbc11fe..fee8f9b38 100644 --- a/src/clib/ct.cpp +++ b/src/clib/ct.cpp @@ -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(&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(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(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(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(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(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(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(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(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(&k)->advanceCoverages(tstep); - } else { - throw CanteraError("kin_advanceCoverages", - "wrong kinetics manager type"); - } + KineticsCabinet::get(n).advanceCoverages(tstep); return 0; } catch (...) { return handleAllExceptions(-1, ERR); diff --git a/src/clib/ctbdry.cpp b/src/clib/ctbdry.cpp index b2878afe9..1868841db 100644 --- a/src/clib/ctbdry.cpp +++ b/src/clib/ctbdry.cpp @@ -77,7 +77,7 @@ extern "C" { double bndry_spreadrate(int i) { try { - return dynamic_cast(BoundaryCabinet::item(i)).spreadRate(); + return BoundaryCabinet::get(i).spreadRate(); } catch (...) { return Cantera::handleAllExceptions(-1, ERR); } @@ -87,7 +87,7 @@ extern "C" { int bndry_setSpreadRate(int i, double v) { try { - dynamic_cast(BoundaryCabinet::item(i)).setSpreadRate(v); + BoundaryCabinet::get(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(BoundaryCabinet::item(i)); - InterfaceKinetics& k = - dynamic_cast(Cabinet::item(j)); - srf.setKineticsMgr(&k); + InterfaceKinetics& k = Cabinet::get(j); + BoundaryCabinet::get(i).setKineticsMgr(&k); } catch (...) { return Cantera::handleAllExceptions(-1, ERR); } diff --git a/src/clib/ctsurf.cpp b/src/clib/ctsurf.cpp index a1b00e83a..3288b5f4a 100644 --- a/src/clib/ctsurf.cpp +++ b/src/clib/ctsurf.cpp @@ -14,22 +14,14 @@ using namespace std; using namespace Cantera; -inline SurfPhase& _surfphase(int n) -{ - return dynamic_cast(Cabinet::item(n)); -} - -inline InterfaceKinetics& _surfkin(int n) -{ - return dynamic_cast(Cabinet::item(n)); -} +typedef Cabinet ThermoCabinet; extern "C" { int surf_setsitedensity(int i, double s0) { try { - _surfphase(i).setSiteDensity(s0); + ThermoCabinet::get(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(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(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(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(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(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(i).getConcentrations(c); return 0; } catch (...) { return handleAllExceptions(-1, ERR);