Skip to content

Commit

Permalink
[clib] Remove _newFromFile
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Aug 12, 2024
1 parent d94f4d9 commit cad4dc8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 69 deletions.
7 changes: 0 additions & 7 deletions include/cantera/clib/ct.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ extern "C" {
CANTERA_CAPI int soln_adjacent(int n, int a);
CANTERA_CAPI int soln_adjacentName(int n, int a, int lennm, char* nm);

//! @todo remove from .NET and Fortran interfaces
CANTERA_CAPI int thermo_newFromFile(const char* filename, const char* phasename);
CANTERA_CAPI int thermo_parent(int n);
CANTERA_CAPI int thermo_size();
CANTERA_CAPI int thermo_del(int n);
Expand Down Expand Up @@ -134,11 +132,6 @@ extern "C" {
CANTERA_CAPI int thermo_setState_Psat(int n, double p, double x);
CANTERA_CAPI int thermo_setState_Tsat(int n, double t, double x);

//! @since Starting in %Cantera 3.0, the "phasename" argument should be blank
//! @todo remove from .NET and Fortran interfaces
CANTERA_CAPI int kin_newFromFile(const char* filename, const char* phasename,
int reactingPhase, int neighbor1, int neighbor2,
int neighbor3, int neighbor4);
CANTERA_CAPI int kin_parent(int n);
CANTERA_CAPI int kin_del(int n);
CANTERA_CAPI int kin_nSpecies(int n);
Expand Down
50 changes: 7 additions & 43 deletions src/clib/ct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,13 +541,13 @@ extern "C" {

//-------------- Thermo --------------------//

int thermo_newFromFile(const char* filename, const char* phasename) {
try {
return ThermoCabinet::add(newThermo(filename, phasename));
} catch (...) {
return handleAllExceptions(-1, ERR);
}
}
// int thermo_newFromFile(const char* filename, const char* phasename) {
// try {
// return ThermoCabinet::add(newThermo(filename, phasename));
// } catch (...) {
// return handleAllExceptions(-1, ERR);
// }
// }

int thermo_getEosType(int n, int leneos, char* eos)
{
Expand Down Expand Up @@ -1131,42 +1131,6 @@ extern "C" {

//-------------- Kinetics ------------------//

// @todo Define a new version of this function that does not require the
// unused 'phasename' argument.
int kin_newFromFile(const char* filename, const char* phasename,
int reactingPhase, int neighbor1, int neighbor2,
int neighbor3, int neighbor4)
{
try {
vector<shared_ptr<ThermoPhase>> phases;
phases.push_back(ThermoCabinet::at(reactingPhase));
if (neighbor1 >= 0) {
phases.push_back(ThermoCabinet::at(neighbor1));
if (neighbor2 >= 0) {
phases.push_back(ThermoCabinet::at(neighbor2));
if (neighbor3 >= 0) {
phases.push_back(ThermoCabinet::at(neighbor3));
if (neighbor4 >= 0) {
phases.push_back(ThermoCabinet::at(neighbor4));
}
}
}
}
if (phasename != nullptr) {
string phase_str(phasename);
if (!phase_str.empty() && phase_str != phases[0]->name()) {
throw CanteraError("kin_newFromFile",
"Reacting phase must be first");
}
}
shared_ptr<Kinetics> kin = newKinetics(phases, filename);
return KineticsCabinet::add(kin);
} catch (...) {
return handleAllExceptions(-1, ERR);
}
}

//-------------------------------------
int kin_getType(int n, int lennm, char* nm)
{
try {
Expand Down
26 changes: 12 additions & 14 deletions test/clib/test_clib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,18 @@ TEST(ct, soln_objects)
{
ct_resetStorage();

int thermo0 = thermo_newFromFile("gri30.yaml", "gri30");
ASSERT_EQ(thermo_size(), 1);

int ref = soln_newSolution("gri30.yaml", "gri30", "none");
ASSERT_EQ(ref, 0);
ASSERT_EQ(thermo_size(), 2);
ASSERT_EQ(thermo_size(), 1); // one ThermoPhase object

int ref2 = soln_newSolution("h2o2.yaml", "ohmech", "default");
ASSERT_EQ(ref2, 1);
ASSERT_EQ(thermo_size(), 3);

ASSERT_EQ(thermo_parent(thermo0), -1);

ASSERT_EQ(thermo_size(), 2); // two ThermoPhase objects
int thermo = soln_thermo(ref);
ASSERT_EQ(thermo_parent(thermo), ref);

int thermo2 = soln_thermo(ref2);
ASSERT_EQ(thermo2, 2);
ASSERT_EQ(thermo2, 1); // references stored object with index '1'
ASSERT_EQ(thermo_nSpecies(thermo2), 10);
ASSERT_EQ(thermo_parent(thermo2), ref2);

Expand Down Expand Up @@ -191,7 +186,8 @@ TEST(ct, new_interface_auto)
TEST(ct, thermo)
{
int ret;
int thermo = thermo_newFromFile("gri30.yaml", "gri30");
int sol = soln_newSolution("gri30.yaml", "gri30", "none");
int thermo = soln_thermo(sol);
ASSERT_GE(thermo, 0);
int nsp = thermo_nSpecies(thermo);
ASSERT_EQ(nsp, 53);
Expand All @@ -212,8 +208,9 @@ TEST(ct, thermo)

TEST(ct, kinetics)
{
int thermo = thermo_newFromFile("gri30.yaml", "gri30");
int kin = kin_newFromFile("gri30.yaml", "", thermo, -1, -1, -1, -1);
int sol0 = soln_newSolution("gri30.yaml", "gri30", "none");
int thermo = soln_thermo(sol0);
int kin = soln_kinetics(sol0);
ASSERT_GE(kin, 0);

int nr = kin_nReactions(kin);
Expand Down Expand Up @@ -243,8 +240,9 @@ TEST(ct, kinetics)

TEST(ct, transport)
{
int thermo = thermo_newFromFile("gri30.yaml", "gri30");
int tran = trans_newDefault(thermo, 0);
int sol0 = soln_newSolution("gri30.yaml", "gri30", "default");
int thermo = soln_thermo(sol0);
int tran = soln_transport(sol0);
ASSERT_GE(tran, 0);

int nsp = thermo_nSpecies(thermo);
Expand Down
3 changes: 2 additions & 1 deletion test/clib/test_ctmultiphase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ using namespace Cantera;

TEST(ctmix, new)
{
int thermo = thermo_newFromFile("gri30.yaml", "gri30");
int sol = soln_newSolution("gri30.yaml", "gri30", "none");
int thermo = soln_thermo(sol);
int mix = mix_new();
ASSERT_GE(mix, 0);
int ret = mix_addPhase(mix, thermo, 1.);
Expand Down
10 changes: 6 additions & 4 deletions test/clib/test_ctreactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ TEST(ctreactor, reactor_soln)

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

suppress_deprecation_warnings();
int reactor = reactor_new("IdealGasReactor");
Expand Down Expand Up @@ -103,8 +104,9 @@ TEST(ctreactor, reactor_from_parts)
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);
int sol = soln_newSolution("gri30.yaml", "gri30", "none");
int thermo = soln_thermo(sol);
int kin = soln_kinetics(sol);
thermo_setMoleFractionsByName(thermo, X.c_str());
thermo_setTemperature(thermo, T);
thermo_setPressure(thermo, P);
Expand Down

0 comments on commit cad4dc8

Please sign in to comment.