Skip to content

Commit

Permalink
[clib] Eliminate SharedCabinet::get
Browse files Browse the repository at this point in the history
Replaced by SharedCabinet::as
  • Loading branch information
ischoegl authored and speth committed Aug 19, 2024
1 parent d04ec3e commit 5009d1f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 50 deletions.
12 changes: 0 additions & 12 deletions src/clib/Cabinet.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,6 @@ class SharedCabinet
throw CanteraError("SharedCabinet::as", "Item is not of the correct type.");
}

/**
* Return a reference to object n, cast to a reference of the specified type.
*/
template <class T>
static T& get(int n) {
auto obj = std::dynamic_pointer_cast<T>(at(n));
if (obj) {
return *obj;
}
throw CanteraError("SharedCabinet::get", "Item is not of the correct type.");
}

/**
* Return the index in the SharedCabinet to the specified object, or -1 if the
* object is not in the SharedCabinet. If multiple indices reference the same
Expand Down
8 changes: 4 additions & 4 deletions src/clib/ct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ extern "C" {
double thermo_vaporFraction(int n)
{
try {
return ThermoCabinet::get<PureFluidPhase>(n).vaporFraction();
return ThermoCabinet::as<PureFluidPhase>(n)->vaporFraction();
} catch (...) {
return handleAllExceptions(DERR, DERR);
}
Expand All @@ -1102,7 +1102,7 @@ extern "C" {
int thermo_setState_Psat(int n, double p, double x)
{
try {
ThermoCabinet::get<PureFluidPhase>(n).setState_Psat(p, x);
ThermoCabinet::as<PureFluidPhase>(n)->setState_Psat(p, x);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
Expand All @@ -1112,7 +1112,7 @@ extern "C" {
int thermo_setState_Tsat(int n, double t, double x)
{
try {
ThermoCabinet::get<PureFluidPhase>(n).setState_Tsat(t, x);
ThermoCabinet::as<PureFluidPhase>(n)->setState_Tsat(t, x);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
Expand Down Expand Up @@ -1459,7 +1459,7 @@ extern "C" {
int kin_advanceCoverages(int n, double tstep)
{
try {
KineticsCabinet::get<InterfaceKinetics>(n).advanceCoverages(tstep);
KineticsCabinet::as<InterfaceKinetics>(n)->advanceCoverages(tstep);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
Expand Down
20 changes: 10 additions & 10 deletions src/clib/ctonedim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ extern "C" {
double bdry_massFraction(int i, int k)
{
try {
return DomainCabinet::get<Boundary1D>(i).massFraction(k);
return DomainCabinet::as<Boundary1D>(i)->massFraction(k);
} catch (...) {
return handleAllExceptions(DERR, DERR);
}
Expand All @@ -307,7 +307,7 @@ extern "C" {
double bdry_mdot(int i)
{
try {
return DomainCabinet::get<Boundary1D>(i).mdot();
return DomainCabinet::as<Boundary1D>(i)->mdot();
} catch (...) {
return handleAllExceptions(DERR, DERR);
}
Expand All @@ -316,7 +316,7 @@ extern "C" {
int reactingsurf_enableCoverageEqs(int i, int onoff)
{
try {
DomainCabinet::get<ReactingSurf1D>(i).enableCoverageEquations(onoff != 0);
DomainCabinet::as<ReactingSurf1D>(i)->enableCoverageEquations(onoff != 0);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
Expand Down Expand Up @@ -348,7 +348,7 @@ extern "C" {
int flow1D_setTransport(int i, int itr)
{
try {
DomainCabinet::get<Flow1D>(i).setTransport(TransportCabinet::at(itr));
DomainCabinet::as<Flow1D>(i)->setTransport(TransportCabinet::at(itr));
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
Expand All @@ -359,7 +359,7 @@ extern "C" {
{
try {
bool withSoret = (iSoret > 0);
DomainCabinet::get<Flow1D>(i).enableSoret(withSoret);
DomainCabinet::as<Flow1D>(i)->enableSoret(withSoret);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
Expand All @@ -369,7 +369,7 @@ extern "C" {
int flow1D_setPressure(int i, double p)
{
try {
DomainCabinet::get<Flow1D>(i).setPressure(p);
DomainCabinet::as<Flow1D>(i)->setPressure(p);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
Expand All @@ -379,7 +379,7 @@ extern "C" {
double flow1D_pressure(int i)
{
try {
return DomainCabinet::get<Flow1D>(i).pressure();
return DomainCabinet::as<Flow1D>(i)->pressure();
} catch (...) {
return handleAllExceptions(DERR, DERR);
}
Expand All @@ -394,7 +394,7 @@ extern "C" {
vpos[j] = pos[j];
vtemp[j] = temp[j];
}
DomainCabinet::get<Flow1D>(i).setFixedTempProfile(vpos, vtemp);
DomainCabinet::as<Flow1D>(i)->setFixedTempProfile(vpos, vtemp);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
Expand All @@ -405,9 +405,9 @@ extern "C" {
{
try {
if (flag > 0) {
DomainCabinet::get<Flow1D>(i).solveEnergyEqn(npos);
DomainCabinet::as<Flow1D>(i)->solveEnergyEqn(npos);
} else {
DomainCabinet::get<Flow1D>(i).fixTemperature(npos);
DomainCabinet::as<Flow1D>(i)->fixTemperature(npos);
}
return 0;
} catch (...) {
Expand Down
32 changes: 16 additions & 16 deletions src/clib/ctreactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ extern "C" {
int reactor_insert(int i, int n)
{
try {
ReactorCabinet::get<Reactor>(i).insert(SolutionCabinet::at(n));
ReactorCabinet::as<Reactor>(i)->insert(SolutionCabinet::at(n));
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
Expand Down Expand Up @@ -174,7 +174,7 @@ extern "C" {
int reactor_setChemistry(int i, int cflag)
{
try {
ReactorCabinet::get<Reactor>(i).setChemistry(cflag != 0);
ReactorCabinet::as<Reactor>(i)->setChemistry(cflag != 0);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
Expand All @@ -184,7 +184,7 @@ extern "C" {
int reactor_setEnergy(int i, int eflag)
{
try {
ReactorCabinet::get<Reactor>(i).setEnergy(eflag);
ReactorCabinet::as<Reactor>(i)->setEnergy(eflag);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
Expand All @@ -194,7 +194,7 @@ extern "C" {
int reactor_setMassFlowRate(int i, double mdot)
{
try {
ReactorCabinet::get<FlowReactor>(i).setMassFlowRate(mdot);
ReactorCabinet::as<FlowReactor>(i)->setMassFlowRate(mdot);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
Expand All @@ -204,7 +204,7 @@ extern "C" {
size_t reactor_nSensParams(int i)
{
try {
return ReactorCabinet::get<Reactor>(i).nSensParams();
return ReactorCabinet::as<Reactor>(i)->nSensParams();
} catch (...) {
return handleAllExceptions(npos, npos);
}
Expand All @@ -213,7 +213,7 @@ extern "C" {
int reactor_addSensitivityReaction(int i, int rxn)
{
try {
ReactorCabinet::get<Reactor>(i).addSensitivityReaction(rxn);
ReactorCabinet::as<Reactor>(i)->addSensitivityReaction(rxn);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
Expand Down Expand Up @@ -386,7 +386,7 @@ extern "C" {
int flowdev_setPrimary(int i, int n)
{
try {
FlowDeviceCabinet::get<PressureController>(i).setPrimary(
FlowDeviceCabinet::as<PressureController>(i)->setPrimary(
FlowDeviceCabinet::at(n).get());
return 0;
} catch (...) {
Expand All @@ -406,7 +406,7 @@ extern "C" {
int flowdev_setMassFlowCoeff(int i, double v)
{
try {
FlowDeviceCabinet::get<MassFlowController>(i).setMassFlowCoeff(v);
FlowDeviceCabinet::as<MassFlowController>(i)->setMassFlowCoeff(v);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
Expand All @@ -416,7 +416,7 @@ extern "C" {
int flowdev_setValveCoeff(int i, double v)
{
try {
FlowDeviceCabinet::get<Valve>(i).setValveCoeff(v);
FlowDeviceCabinet::as<Valve>(i)->setValveCoeff(v);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
Expand All @@ -426,7 +426,7 @@ extern "C" {
int flowdev_setPressureCoeff(int i, double v)
{
try {
FlowDeviceCabinet::get<PressureController>(i).setPressureCoeff(v);
FlowDeviceCabinet::as<PressureController>(i)->setPressureCoeff(v);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
Expand Down Expand Up @@ -525,7 +525,7 @@ extern "C" {
int wall_setThermalResistance(int i, double rth)
{
try {
WallCabinet::get<Wall>(i).setThermalResistance(rth);
WallCabinet::as<Wall>(i)->setThermalResistance(rth);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
Expand All @@ -535,7 +535,7 @@ extern "C" {
int wall_setHeatTransferCoeff(int i, double u)
{
try {
WallCabinet::get<Wall>(i).setHeatTransferCoeff(u);
WallCabinet::as<Wall>(i)->setHeatTransferCoeff(u);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
Expand All @@ -545,7 +545,7 @@ extern "C" {
int wall_setHeatFlux(int i, int n)
{
try {
WallCabinet::get<Wall>(i).setHeatFlux(FuncCabinet::at(n).get());
WallCabinet::as<Wall>(i)->setHeatFlux(FuncCabinet::at(n).get());
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
Expand All @@ -555,7 +555,7 @@ extern "C" {
int wall_setExpansionRateCoeff(int i, double k)
{
try {
WallCabinet::get<Wall>(i).setExpansionRateCoeff(k);
WallCabinet::as<Wall>(i)->setExpansionRateCoeff(k);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
Expand All @@ -565,7 +565,7 @@ extern "C" {
int wall_setVelocity(int i, int n)
{
try {
WallCabinet::get<Wall>(i).setVelocity(FuncCabinet::at(n).get());
WallCabinet::as<Wall>(i)->setVelocity(FuncCabinet::at(n).get());
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
Expand All @@ -575,7 +575,7 @@ extern "C" {
int wall_setEmissivity(int i, double epsilon)
{
try {
WallCabinet::get<Wall>(i).setEmissivity(epsilon);
WallCabinet::as<Wall>(i)->setEmissivity(epsilon);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
Expand Down
16 changes: 8 additions & 8 deletions src/clib/ctsurf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extern "C" {
int surf_setSiteDensity(int i, double s0)
{
try {
ThermoCabinet::get<SurfPhase>(i).setSiteDensity(s0);
ThermoCabinet::as<SurfPhase>(i)->setSiteDensity(s0);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
Expand All @@ -33,7 +33,7 @@ extern "C" {
double surf_siteDensity(int i)
{
try {
return ThermoCabinet::get<SurfPhase>(i).siteDensity();
return ThermoCabinet::as<SurfPhase>(i)->siteDensity();
} catch (...) {
return handleAllExceptions(DERR, DERR);
}
Expand All @@ -43,9 +43,9 @@ extern "C" {
{
try {
if(norm){
ThermoCabinet::get<SurfPhase>(i).setCoverages(c);
ThermoCabinet::as<SurfPhase>(i)->setCoverages(c);
} else {
ThermoCabinet::get<SurfPhase>(i).setCoveragesNoNorm(c);
ThermoCabinet::as<SurfPhase>(i)->setCoveragesNoNorm(c);
}
return 0;
} catch (...) {
Expand All @@ -56,7 +56,7 @@ extern "C" {
int surf_setCoveragesByName(int i, const char* c)
{
try {
ThermoCabinet::get<SurfPhase>(i).setCoveragesByName(c);
ThermoCabinet::as<SurfPhase>(i)->setCoveragesByName(c);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
Expand All @@ -66,7 +66,7 @@ extern "C" {
int surf_getCoverages(int i, double* c)
{
try {
ThermoCabinet::get<SurfPhase>(i).getCoverages(c);
ThermoCabinet::as<SurfPhase>(i)->getCoverages(c);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
Expand All @@ -76,7 +76,7 @@ extern "C" {
int surf_setConcentrations(int i, const double* c)
{
try {
ThermoCabinet::get<SurfPhase>(i).setConcentrations(c);
ThermoCabinet::as<SurfPhase>(i)->setConcentrations(c);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
Expand All @@ -86,7 +86,7 @@ extern "C" {
int surf_getConcentrations(int i, double* c)
{
try {
ThermoCabinet::get<SurfPhase>(i).getConcentrations(c);
ThermoCabinet::as<SurfPhase>(i)->getConcentrations(c);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
Expand Down

0 comments on commit 5009d1f

Please sign in to comment.