Skip to content

Commit

Permalink
[unittest] Update test-oneD and test-clib
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Mar 12, 2023
1 parent aa619a0 commit d78871b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 19 deletions.
53 changes: 48 additions & 5 deletions test/clib/test_ctonedim.cpp
Expand Up @@ -12,6 +12,34 @@ TEST(ctonedim, freeflow)
{
ct_resetStorage();

int sol = soln_newSolution("h2o2.yaml", "ohmech", "Mix");
int ph = soln_thermo(sol);
ASSERT_GE(ph, 0);

double T = 1050;
double P = 5 * 101325;
string X = "CH4:1.0, O2:2.0, N2:7.52";
thermo_setMoleFractionsByName(ph, X.c_str());
thermo_setTemperature(ph, T);
thermo_setPressure(ph, P);

int flow = domain_new("free-flow", sol, "flow");
ASSERT_GE(flow, 0);
domain_setID(flow, "flow");
ASSERT_NEAR(stflow_pressure(flow), P, 1e-5);

int buflen = domain_type3(flow, 0, 0);
char* buf = new char[buflen];
domain_type3(flow, buflen, buf);
string domName = buf;
ASSERT_EQ(domName, "free-flow");
delete[] buf;
}

TEST(ctonedim, freeflow_from_parts)
{
ct_resetStorage();

int sol = soln_newSolution("h2o2.yaml", "ohmech", "Mix");
int ph = soln_thermo(sol);
ASSERT_GE(ph, 0);
Expand All @@ -30,8 +58,15 @@ TEST(ctonedim, freeflow)
int itype = 2; // free flow
int flow = stflow_new(ph, kin, tr, itype);
ASSERT_GE(flow, 0);

domain_setID(flow, "flow");
ASSERT_NEAR(stflow_pressure(flow), P, 1e-5);

int buflen = domain_type3(flow, 0, 0);
char* buf = new char[buflen];
domain_type3(flow, buflen, buf);
string domName = buf;
ASSERT_EQ(domName, "free-flow");
delete[] buf;
}

TEST(ctonedim, inlet)
Expand All @@ -54,6 +89,13 @@ TEST(ctonedim, outlet)
}

TEST(ctonedim, reacting_surface)
{
int surf = soln_newInterface("ptcombust.yaml", "Pt_surf", 0, 0);
int index = domain_new("reacting-surface", surf, "surface");
ASSERT_GE(index, 0);
}

TEST(ctonedim, reacting_surface_from_parts)
{
int index = reactingsurf_new();
ASSERT_GE(index, 0);
Expand Down Expand Up @@ -161,14 +203,15 @@ TEST(ctonedim, freeflame_from_parts)
std::vector<int> doms{reac, flow, prod};
int flame = sim1D_new(3, doms.data());
int dom = sim1D_domainIndex(flame, "flow");
ASSERT_EQ(dom, 1);

// set up initial guess
vector<double> locs{0.0, 0.3, 0.7, 1.0};
vector<double> value{uin, uin, uout, uout};
int comp = domain_componentIndex(dom, "velocity");
int comp = domain_componentIndex(flow, "velocity");
sim1D_setProfile(flame, dom, comp, 4, locs.data(), 4, value.data());
value = {T, T, Tad, Tad};
comp = domain_componentIndex(dom, "T");
comp = domain_componentIndex(flow, "T");
sim1D_setProfile(flame, dom, comp, 4, locs.data(), 4, value.data());
for (size_t i = 0; i < nsp; i++) {
value = {yin[i], yin[i], yout[i], yout[i]};
Expand All @@ -177,7 +220,7 @@ TEST(ctonedim, freeflame_from_parts)
thermo_getSpeciesName(ph, i, buflen, buf);
string name = buf;
ASSERT_EQ(name, gas->speciesName(i));
comp = domain_componentIndex(dom, buf);
comp = domain_componentIndex(flow, buf);
sim1D_setProfile(flame, dom, comp, 4, locs.data(), 4, value.data());
}

Expand All @@ -202,7 +245,7 @@ TEST(ctonedim, freeflame_from_parts)
ASSERT_GE(ret, 0);
}

ASSERT_EQ(domain_nPoints(flow),nz + 1);
ASSERT_EQ(domain_nPoints(flow), nz + 1);
comp = domain_componentIndex(dom, "T");
double Tprev = sim1D_value(flame, dom, comp, 0);
for (size_t n = 0; n < domain_nPoints(flow); n++) {
Expand Down
29 changes: 15 additions & 14 deletions test/oneD/test_oneD.cpp
Expand Up @@ -4,6 +4,7 @@

#include "cantera/core.h"
#include "cantera/onedim.h"
#include "cantera/oneD/DomainFactory.h"

using namespace Cantera;

Expand Down Expand Up @@ -33,8 +34,8 @@ TEST(onedim, freeflame)
double Tad = gas->temperature();

// flow
StFlow flow(sol, "flow");
flow.setFreeFlow();
auto flow = newDomain<StFlow>("gas-flow", sol, "flow");
flow->setFreeFlow();

// grid
int nz = 21;
Expand All @@ -45,20 +46,20 @@ TEST(onedim, freeflame)
for (int iz = 0; iz < nz; iz++) {
z[iz] = iz * dz;
}
flow.setupGrid(nz, &z[0]);
flow->setupGrid(nz, &z[0]);

// inlet
Inlet1D inlet(sol, "inlet");
inlet.setMoleFractions(X);
inlet.setMdot(uin * rho_in);
inlet.setTemperature(T);
auto inlet = newDomain<Inlet1D>("inlet", sol);
inlet->setMoleFractions(X);
inlet->setMdot(uin * rho_in);
inlet->setTemperature(T);

// outlet
Outlet1D outlet(sol, "outlet");
double uout = inlet.mdot() / rho_out;
auto outlet = newDomain<Outlet1D>("outlet", sol);
double uout = inlet->mdot() / rho_out;

// set up simulation
std::vector<Domain1D*> domains { &inlet, &flow, &outlet };
vector<shared_ptr<Domain1D>> domains { inlet, flow, outlet };
Sim1D flame(domains);
int dom = flame.domainIndex("flow");
ASSERT_EQ(dom, 1);
Expand All @@ -82,7 +83,7 @@ TEST(onedim, freeflame)
flame.setFixedTemperature(0.85 * T + .15 * Tad);

// solve
flow.solveEnergyEqn();
flow->solveEnergyEqn();
bool refine_grid = false;
int loglevel = 0;
flame.solve(loglevel, refine_grid);
Expand All @@ -91,10 +92,10 @@ TEST(onedim, freeflame)
flame.save("gtest-freeflame.h5", "cpp", "Solution from C++ interface", 1);
}

ASSERT_EQ(flow.nPoints(), nz + 1);
size_t comp = flow.componentIndex("T");
ASSERT_EQ(flow->nPoints(), nz + 1);
size_t comp = flow->componentIndex("T");
double Tprev = flame.value(dom, comp, 0);
for (size_t n = 0; n < flow.nPoints(); n++) {
for (size_t n = 0; n < flow->nPoints(); n++) {
T = flame.value(dom, comp, n);
ASSERT_GE(T, Tprev);
Tprev = T;
Expand Down

0 comments on commit d78871b

Please sign in to comment.