Skip to content

Commit

Permalink
[clib] Remove deprecated clib functions
Browse files Browse the repository at this point in the history
As of Cantera 3.1, the clib interface is considered experimental, where
breakages are acceptable.
  • Loading branch information
ischoegl committed Aug 9, 2024
1 parent 75f80dd commit 0ae9066
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 102 deletions.
5 changes: 1 addition & 4 deletions include/cantera/clib/ctreactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@
extern "C" {
#endif

CANTERA_CAPI int reactor_new(const char* type); //!< @deprecated: remove after 3.1
CANTERA_CAPI int reactor_new3(const char* type, int n, const char* name);
CANTERA_CAPI int reactor_new(const char* type, int n, const char* name);
CANTERA_CAPI int reactor_del(int i);
CANTERA_CAPI int reactor_setInitialVolume(int i, double v);
CANTERA_CAPI int reactor_setChemistry(int i, int cflag);
CANTERA_CAPI int reactor_setEnergy(int i, int eflag);
CANTERA_CAPI int reactor_setThermoMgr(int i, int n); //!< @deprecated: remove after 3.1
CANTERA_CAPI int reactor_setKineticsMgr(int i, int n); //!< @deprecated: remove after 3.1
CANTERA_CAPI int reactor_insert(int i, int n);
CANTERA_CAPI double reactor_mass(int i);
CANTERA_CAPI double reactor_volume(int i);
Expand Down
4 changes: 1 addition & 3 deletions interfaces/matlab_experimental/Reactor/Reactor.m
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@
end

r.type = char(typ);
r.id = ctFunc('reactor_new3', typ, content.solnID, name);


r.id = ctFunc('reactor_new', typ, content.solnID, name);
end

%% Reactor Class Destructor
Expand Down
2 changes: 1 addition & 1 deletion samples/clib/demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ int main(int argc, char** argv)
thermo_print(thermo, 1, 1e-6);

printf("\ntime Temperature\n");
int reactor = reactor_new3("IdealGasReactor", soln, "test");
int reactor = reactor_new("IdealGasReactor", soln, "test");
int net = reactornet_new();
reactornet_addreactor(net, reactor);

Expand Down
11 changes: 1 addition & 10 deletions src/clib/ctreactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,7 @@ extern "C" {

// reactor

int reactor_new(const char* type)
{
try {
return ReactorCabinet::add(newReactor(type));
} catch (...) {
return handleAllExceptions(-1, ERR);
}
}

int reactor_new3(const char* type, int n, const char* name)
int reactor_new(const char* type, int n, const char* name)
{
try {
return ReactorCabinet::add(newReactor(type, SolutionCabinet::at(n), name));
Expand Down
86 changes: 2 additions & 84 deletions test/clib/test_ctreactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,10 @@ using namespace Cantera;
TEST(ctreactor, reactor_soln)
{
int sol = soln_newSolution("gri30.yaml", "gri30", "none");
int reactor = reactor_new3("IdealGasReactor", sol, "test");
int reactor = reactor_new("IdealGasReactor", sol, "test");
ASSERT_EQ(reactor, 0);
}

TEST(ctreactor, reactor_objects)
{
int thermo = thermo_newFromFile("gri30.yaml", "gri30");
int kin = kin_newFromFile("gri30.yaml", "", thermo, -1, -1, -1, -1);

suppress_deprecation_warnings();
int reactor = reactor_new("IdealGasReactor");
ASSERT_GE(reactor, 0);
int ret = reactor_setThermoMgr(reactor, thermo);
ASSERT_EQ(ret, 0);
ret = reactor_setKineticsMgr(reactor, kin);
ASSERT_EQ(ret, 0);
make_deprecation_warnings_fatal();
}

vector<double> T_ctreactor = {
1050.000, 1050.064, 1050.197, 1050.369, 1050.593, 1050.881, 1051.253, 1051.736,
1052.370, 1053.216, 1054.372, 1056.007, 1058.448, 1062.431, 1070.141, 1094.331,
Expand All @@ -47,81 +32,14 @@ TEST(ctreactor, reactor_simple)
thermo_setTemperature(thermo, T);
thermo_setPressure(thermo, P);

int reactor = reactor_new3("IdealGasReactor", sol, "test");
int net = reactornet_new();
int ret = reactornet_addreactor(net, reactor);
ASSERT_EQ(ret, 0);

double t = 0.0;
int count = 0;
while (t < 0.1) {
double Tref = T_ctreactor[count];
ASSERT_NEAR(reactor_temperature(reactor), Tref, 1e-2);
t = reactornet_time(net) + 5e-3;
ret = reactornet_advance(net, t);
ASSERT_EQ(ret, 0);
count++;
}
}

TEST(ctreactor, reactor_insert)
{
double T = 1050;
double P = 5 * 101325;
string X = "CH4:1.0, O2:2.0, N2:7.52";

int sol = soln_newSolution("gri30.yaml", "gri30", "none");
int thermo = soln_thermo(sol);
thermo_setMoleFractionsByName(thermo, X.c_str());
thermo_setTemperature(thermo, T);
thermo_setPressure(thermo, P);

suppress_deprecation_warnings();
int reactor = reactor_new("IdealGasReactor");
int ret = reactor_insert(reactor, sol);
make_deprecation_warnings_fatal();
ASSERT_EQ(ret, 0);
int net = reactornet_new();
ret = reactornet_addreactor(net, reactor);
ASSERT_EQ(ret, 0);

double t = 0.0;
int count = 0;
while (t < 0.1) {
double Tref = T_ctreactor[count];
ASSERT_NEAR(reactor_temperature(reactor), Tref, 1e-2);
t = reactornet_time(net) + 5e-3;
ret = reactornet_advance(net, t);
ASSERT_EQ(ret, 0);
count++;
}
}

TEST(ctreactor, reactor_from_parts)
{
double T = 1050;
double P = 5 * 101325;
string X = "CH4:1.0, O2:2.0, N2:7.52";

int thermo = thermo_newFromFile("gri30.yaml", "gri30");
int kin = kin_newFromFile("gri30.yaml", "", thermo, -1, -1, -1, -1);
thermo_setMoleFractionsByName(thermo, X.c_str());
thermo_setTemperature(thermo, T);
thermo_setPressure(thermo, P);

suppress_deprecation_warnings();
int reactor = reactor_new("IdealGasReactor");
reactor_setThermoMgr(reactor, thermo);
reactor_setKineticsMgr(reactor, kin);
make_deprecation_warnings_fatal();
int reactor = reactor_new("IdealGasReactor", sol, "test");
int net = reactornet_new();
int ret = reactornet_addreactor(net, reactor);
ASSERT_EQ(ret, 0);

double t = 0.0;
int count = 0;
while (t < 0.1) {
T = reactor_temperature(reactor);
double Tref = T_ctreactor[count];
ASSERT_NEAR(reactor_temperature(reactor), Tref, 1e-2);
t = reactornet_time(net) + 5e-3;
Expand Down

0 comments on commit 0ae9066

Please sign in to comment.