Skip to content

Commit

Permalink
[test-problems] Replace legacy factory methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Mar 2, 2023
1 parent 647d849 commit 13e7d89
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 52 deletions.
8 changes: 4 additions & 4 deletions test_problems/VCSnonideal/LatticeSolid_LiSi/latsol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ void testProblem(int printLvl)
VCS_SOLVE::disableTiming();

// Create the phases
std::unique_ptr<ThermoPhase> LiSi_solid(newPhase("Li7Si3_latsol.yaml",
"Li7Si3_and_Interstitials(S)"));
std::unique_ptr<ThermoPhase> Li_liq(newPhase("Li7Si3_latsol.yaml", "Li(L)"));
std::unique_ptr<ThermoPhase> LiFixed(newPhase("Li7Si3_latsol.yaml", "LiFixed"));
auto LiSi_solid = newThermoPhase("Li7Si3_latsol.yaml",
"Li7Si3_and_Interstitials(S)");
auto Li_liq = newThermoPhase("Li7Si3_latsol.yaml", "Li(L)");
auto LiFixed = newThermoPhase("Li7Si3_latsol.yaml", "LiFixed");
MargulesVPSSTP salt("Li7Si3_latsol.yaml", "MoltenSalt_electrolyte");

// set states
Expand Down
4 changes: 2 additions & 2 deletions test_problems/VCSnonideal/NaCl_equil/nacl_equil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ int main(int argc, char** argv)
Xmol[iH2OL] = 1.0;
hmw.setState_TPX(T, pres, Xmol.data());

ThermoPhase* gas = newPhase("NaCl_gas.yaml");
auto gas = newThermoPhase("NaCl_gas.yaml", "");

kk = gas->nSpecies();
Xmol.resize(kk, 0.0);
Expand All @@ -113,7 +113,7 @@ int main(int argc, char** argv)
MultiPhase* mp = new MultiPhase();

mp->addPhase(&hmw, 2.0);
mp->addPhase(gas, 4.0);
mp->addPhase(gas.get(), 4.0);
mp->addPhase(&ss, 5.0);


Expand Down
4 changes: 1 addition & 3 deletions test_problems/cathermo/HMW_graph_CpvT/HMW_graph_CpvT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ int main(int argc, char** argv)
double Cp0_R[20], pmCp[20];

HMWSoln* HMW = new HMWSoln(iFile, "NaCl_electrolyte");
ThermoPhase* solid = newPhase("NaCl_Solid.yaml", "NaCl(S)");
auto solid = newThermoPhase("NaCl_Solid.yaml", "NaCl(S)");

size_t nsp = HMW->nSpecies();
double mf[100];
Expand Down Expand Up @@ -219,8 +219,6 @@ int main(int argc, char** argv)

delete HMW;
HMW = 0;
delete solid;
solid = 0;
Cantera::appdelete();
return retn;

Expand Down
4 changes: 1 addition & 3 deletions test_problems/cathermo/HMW_graph_GvT/HMW_graph_GvT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ int main(int argc, char** argv)
*/
string nacl_s = "NaCl_Solid.yaml";
string id = "NaCl(S)";
Cantera::ThermoPhase* solid = Cantera::newPhase(nacl_s, id);
auto solid = Cantera::newThermoPhase(nacl_s, id);

size_t nsp = HMW->nSpecies();
double acMol[100];
Expand Down Expand Up @@ -212,8 +212,6 @@ int main(int argc, char** argv)

delete HMW;
HMW = 0;
delete solid;
solid = 0;
Cantera::appdelete();

return retn;
Expand Down
4 changes: 1 addition & 3 deletions test_problems/cathermo/HMW_graph_HvT/HMW_graph_HvT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int main(int argc, char** argv)
/*
* Load in and initialize the
*/
Cantera::ThermoPhase* solid = newPhase("NaCl_Solid.yaml","NaCl(S)");
auto solid = newThermoPhase("NaCl_Solid.yaml","NaCl(S)");


size_t nsp = HMW->nSpecies();
Expand Down Expand Up @@ -218,8 +218,6 @@ int main(int argc, char** argv)

delete HMW;
HMW = 0;
delete solid;
solid = 0;
Cantera::appdelete();
return retn;

Expand Down
4 changes: 1 addition & 3 deletions test_problems/cathermo/HMW_graph_VvT/HMW_graph_VvT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int main(int argc, char** argv)
/*
* Load in and initialize the
*/
Cantera::ThermoPhase* solid = newPhase("NaCl_Solid.yaml","NaCl(S)");
auto solid = newThermoPhase("NaCl_Solid.yaml", "NaCl(S)");


size_t nsp = HMW->nSpecies();
Expand Down Expand Up @@ -222,8 +222,6 @@ int main(int argc, char** argv)

delete HMW;
HMW = 0;
delete solid;
solid = 0;
Cantera::appdelete();
return retn;

Expand Down
6 changes: 2 additions & 4 deletions test_problems/cathermo/testWaterTP/testWaterSSTP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ int main()
#endif
double pres;
try {
ThermoPhase* w = newPhase("liquidvapor.yaml", "liquid-water-IAPWS95");
(dynamic_cast<WaterSSTP*>(w))->_allowGasPhase(true);
auto w = newThermoPhase("liquidvapor.yaml", "liquid-water-IAPWS95");
(std::dynamic_pointer_cast<WaterSSTP>(w))->_allowGasPhase(true);

/*
* Print out the triple point conditions
Expand Down Expand Up @@ -302,8 +302,6 @@ int main()
printf("Critical Temp = %10.3g K\n", w->critTemperature());
printf("Critical Pressure = %10.3g atm\n", w->critPressure()/OneAtm);
printf("Critical Dens = %10.3g kg/m3\n", w->critDensity());

delete w;
} catch (CanteraError& err) {
std::cout << err.what() << std::endl;
Cantera::appdelete();
Expand Down
6 changes: 3 additions & 3 deletions test_problems/diamondSurf/runDiamond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ int main(int argc, char** argv)
int i, k;

try {
shared_ptr<ThermoPhase> gas(newPhase("diamond.yaml", "gas"));
auto gas = newThermoPhase("diamond.yaml", "gas");
size_t nsp = gas->nSpecies();
cout.precision(4);
cout << "Number of species = " << nsp << endl;

shared_ptr<ThermoPhase> diamond(newPhase("diamond.yaml", "diamond"));
auto diamond = newThermoPhase("diamond.yaml", "diamond");
size_t nsp_diamond = diamond->nSpecies();
cout << "Number of species in diamond = " << nsp_diamond << endl;

shared_ptr<ThermoPhase> diamond100(newPhase("diamond.yaml", "diamond_100"));
auto diamond100 = newThermoPhase("diamond.yaml", "diamond_100");
size_t nsp_d100 = diamond100->nSpecies();
cout << "Number of species in diamond_100 = " << nsp_d100 << endl;

Expand Down
8 changes: 3 additions & 5 deletions test_problems/dustyGasTransport/dustyGasTransportTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ using namespace Cantera;
int main(int argc, char** argv)
{
try {
int log_level = 0;

unique_ptr<ThermoPhase> g(newPhase("h2o2.yaml"));
auto trRef = newTransport(g.get(), "DustyGas");
DustyGasTransport* tranDusty = dynamic_cast<DustyGasTransport*>(tran.get());
auto g = newThermoPhase("h2o2.yaml", "");
auto tran = newTransport(g.get(), "DustyGas");
auto tranDusty = std::dynamic_pointer_cast<DustyGasTransport>(tran);

size_t nsp = g->nSpecies();
vector_fp multiD(nsp*nsp);
Expand Down
2 changes: 1 addition & 1 deletion test_problems/pureFluidTest/testPureWater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int main()
double pres;
try {

unique_ptr<ThermoPhase> w(newPhase("liquidvapor.yaml", "water"));
auto w = newThermoPhase("liquidvapor.yaml", "water");

/*
* Print out the triple point conditions
Expand Down
36 changes: 15 additions & 21 deletions test_problems/surfSolverTest/surfaceSolver2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
using namespace std;
using namespace Cantera;

void printGas(ostream& oooo, ThermoPhase* gasTP, InterfaceKinetics* iKin_ptr, double* src)
void printGas(ostream& oooo, shared_ptr<ThermoPhase> gasTP,
shared_ptr<InterfaceKinetics> iKin_ptr, double* src)
{
double x[MSSIZE];
double C[MSSIZE];
Expand Down Expand Up @@ -53,7 +54,8 @@ void printGas(ostream& oooo, ThermoPhase* gasTP, InterfaceKinetics* iKin_ptr, do

}

void printBulk(ostream& oooo,ThermoPhase* bulkPhaseTP, InterfaceKinetics* iKin_ptr, double* src)
void printBulk(ostream& oooo, shared_ptr<ThermoPhase> bulkPhaseTP,
shared_ptr<InterfaceKinetics> iKin_ptr, double* src)
{
double x[MSSIZE];
double C[MSSIZE];
Expand Down Expand Up @@ -96,8 +98,8 @@ void printBulk(ostream& oooo,ThermoPhase* bulkPhaseTP, InterfaceKinetics* iKin_p
oooo << endl;
}

void printSurf(ostream& oooo, ThermoPhase* surfPhaseTP,
InterfaceKinetics* iKin_ptr, double* src)
void printSurf(ostream& oooo, shared_ptr<ThermoPhase> surfPhaseTP,
shared_ptr<InterfaceKinetics> iKin_ptr, double* src)
{
double x[MSSIZE];
oooo.precision(3);
Expand Down Expand Up @@ -136,41 +138,41 @@ int main(int argc, char** argv)
int ioflag = 1;

try {
ThermoPhase* gasTP = newPhase(infile, gasPhaseName);
auto gasTP = newThermoPhase(infile, gasPhaseName);
size_t nspGas = gasTP->nSpecies();
cout << "Number of species = " << nspGas << endl;

ThermoPhase* bulkPhaseTP = newPhase(infile, bulkParticlePhaseName);
auto bulkPhaseTP = newThermoPhase(infile, bulkParticlePhaseName);
size_t nspBulk = bulkPhaseTP->nSpecies();
cout << "Number of species in bulk phase named " <<
bulkParticlePhaseName << " = " << nspBulk << endl;

ThermoPhase* surfPhaseTP = newPhase(infile, surfParticlePhaseName);
auto surfPhaseTP = newThermoPhase(infile, surfParticlePhaseName);
size_t nsp_d100 = surfPhaseTP->nSpecies();
cout << "Number of species in surface phase, " << surfParticlePhaseName
<< " = " << nsp_d100 << endl;

auto kin = newKinetics({gasTP, bulkPhaseTP, surfPhaseTP},
auto kin = newKinetics({gasTP.get(), bulkPhaseTP.get(), surfPhaseTP.get()},
infile, surfParticlePhaseName);
InterfaceKinetics* iKin_ptr = dynamic_cast<InterfaceKinetics*>(kin.get());
auto iKin_ptr = dynamic_pointer_cast<InterfaceKinetics>(kin);
size_t nr = iKin_ptr->nReactions();
cout << "Number of reactions = " << nr << endl;

ofstream ofile("results2.txt");

// create a second copy of the same surface phase
// (this is a made up problem btw to check the software capability)
ThermoPhase* surfPhaseTP2 = newPhase(infile, surfParticlePhaseName);
auto surfPhaseTP2 = newThermoPhase(infile, surfParticlePhaseName);
size_t nsp2 = surfPhaseTP2->nSpecies();
string pname = surfPhaseTP2->name();
cout << "Number of species in 2nd surface phase, " << pname
<< " = " << nsp2 << endl;

// create the second InterfaceKinetics object based on the
// second surface phase.
auto kin2 = newKinetics({gasTP, bulkPhaseTP, surfPhaseTP2},
auto kin2 = newKinetics({gasTP.get(), bulkPhaseTP.get(), surfPhaseTP2.get()},
infile, surfParticlePhaseName);
InterfaceKinetics* iKin2_ptr = dynamic_cast<InterfaceKinetics*>(kin2.get());
auto iKin2_ptr = dynamic_pointer_cast<InterfaceKinetics>(kin2);
nr = iKin_ptr->nReactions();
cout << "Number of reactions = " << nr << endl;

Expand All @@ -180,7 +182,7 @@ int main(int argc, char** argv)
* Set-up the Surface Problem
* This problem will consist of 2 identical InterfaceKinetics objects
*/
vector<InterfaceKinetics*> vecKinPtrs { iKin_ptr, iKin2_ptr };
vector<InterfaceKinetics*> vecKinPtrs { iKin_ptr.get(), iKin2_ptr.get() };

// Create the ImplicitSurfChem problem
// Initialize it and call the pseudo steadystate capability.
Expand Down Expand Up @@ -268,14 +270,6 @@ int main(int argc, char** argv)
surfaceProb = 0;
iKin_ptr = 0;
iKin2_ptr = 0;
delete gasTP;
gasTP = 0;
delete bulkPhaseTP;
bulkPhaseTP = 0;
delete surfPhaseTP;
surfPhaseTP = 0;
delete surfPhaseTP2;
surfPhaseTP2 = 0;
appdelete();
} catch (CanteraError& err) {
std::cout << err.what() << std::endl;
Expand Down

0 comments on commit 13e7d89

Please sign in to comment.