Skip to content

Commit

Permalink
[samples] Add Sim1D::save to cxx flamespeed sample
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Jan 5, 2023
1 parent 8abe7f7 commit b412c0e
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 100 deletions.
28 changes: 24 additions & 4 deletions samples/cxx/flamespeed/flamespeed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
*
* Usage: flamespeed [equivalence_ratio] [refine_grid] [loglevel]
*
* Keywords: combustion, 1D flow, premixed flame, flame speed
* Requires: cantera >= 3.0
* Keywords: combustion, 1D flow, premixed flame, flame speed, saving output
*/

// This file is part of Cantera. See License.txt in the top-level directory or
Expand Down Expand Up @@ -52,7 +53,7 @@ int flamespeed(double phi, bool refine_grid, int loglevel)

//-------- step 1: create the flow -------------

StFlow flow(sol);
StFlow flow(sol, "flow");
flow.setFreeFlow();

// create an initial grid
Expand All @@ -68,7 +69,7 @@ int flamespeed(double phi, bool refine_grid, int loglevel)

//------- step 2: create the inlet -----------------------

Inlet1D inlet;
Inlet1D inlet(sol, "inlet");

inlet.setMoleFractions(x.data());
double mdot=uin*rho_in;
Expand All @@ -77,7 +78,7 @@ int flamespeed(double phi, bool refine_grid, int loglevel)

//------- step 3: create the outlet ---------------------

Outlet1D outlet;
Outlet1D outlet(sol, "outlet");

//=================== create the container and insert the domains =====

Expand Down Expand Up @@ -113,6 +114,21 @@ int flamespeed(double phi, bool refine_grid, int loglevel)

flame.setRefineCriteria(flowdomain,ratio,slope,curve);

// Save initial guess to container file

// Solution is saved in HDF5 or YAML file format
std::string fileName;
if (usesHDF5()) {
// Cantera is compiled with native HDF5 support
fileName = "flamespeed.h5";
} else {
fileName = "flamespeed.yaml";
}
if (std::ifstream(fileName).good()) {
std::remove(fileName.c_str());
}
flame.save(fileName, "initial-guess", "Initial guess", 0);

// Solve freely propagating flame

// Linearly interpolate to find location where this temperature would
Expand All @@ -126,6 +142,7 @@ int flamespeed(double phi, bool refine_grid, int loglevel)
flow.componentIndex("velocity"),0);
print("Flame speed with mixture-averaged transport: {} m/s\n",
flameSpeed_mix);
flame.save(fileName, "mix", "Solution with mixture-averaged transport", 0);

// now switch to multicomponent transport
flow.setTransportModel("multicomponent");
Expand All @@ -134,6 +151,7 @@ int flamespeed(double phi, bool refine_grid, int loglevel)
flow.componentIndex("velocity"),0);
print("Flame speed with multicomponent transport: {} m/s\n",
flameSpeed_multi);
flame.save(fileName, "multi", "Solution with multicomponent transport", 0);

// now enable Soret diffusion
flow.enableSoret(true);
Expand All @@ -142,6 +160,8 @@ int flamespeed(double phi, bool refine_grid, int loglevel)
flow.componentIndex("velocity"),0);
print("Flame speed with multicomponent transport + Soret: {} m/s\n",
flameSpeed_full);
flame.save(fileName, "soret",
"Solution with mixture-averaged transport and Soret", 0);

vector_fp zvec,Tvec,COvec,CO2vec,Uvec;

Expand Down
192 changes: 96 additions & 96 deletions test_problems/cxx_samples/cxx_flamespeed_blessed.txt
Original file line number Diff line number Diff line change
@@ -1,154 +1,154 @@
phi = 0.9, Tad = 2133.7925650475245


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> domain 0 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> inlet <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Mass Flux: 0.3381 kg/m^2/s
Temperature: 300 K
Mass Fractions:
O2 0.2213
CH4 0.04993
N2 0.7288
Mass Flux: 0.3381 kg/m^2/s
Temperature: 300 K
Mass Fractions:
O2 0.2213
CH4 0.04993
N2 0.7288



>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> domain 1 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> flow <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Pressure: 1.013e+05 Pa

-------------------------------------------------------------------------------
z velocity spread_rate T lambda eField
z velocity spread_rate T lambda eField
-------------------------------------------------------------------------------
0 0.3 0 300 0 0
0.02 0.3 0 300 0 0
0.04 0.7598 0 758.4 0 0
0.06 1.679 0 1675 0 0
0.08 2.139 0 2134 0 0
0.1 2.139 0 2134 0 0
0 0.3 0 300 0 0
0.02 0.3 0 300 0 0
0.04 0.7598 0 758.4 0 0
0.06 1.679 0 1675 0 0
0.08 2.139 0 2134 0 0
0.1 2.139 0 2134 0 0

-------------------------------------------------------------------------------
z H2 H O O2 OH
z H2 H O O2 OH
-------------------------------------------------------------------------------
0 0 0 0 0.2213 0
0.02 0 0 0 0.2213 0
0.04 1.696e-05 1.065e-06 3.44e-05 0.1713 0.0004119
0.06 5.087e-05 3.194e-06 0.0001032 0.07133 0.001236
0.08 6.782e-05 4.259e-06 0.0001376 0.02135 0.001648
0.1 6.782e-05 4.259e-06 0.0001376 0.02135 0.001648
0 0 0 0 0.2213 0
0.02 0 0 0 0.2213 0
0.04 1.696e-05 1.065e-06 3.44e-05 0.1713 0.0004119
0.06 5.087e-05 3.194e-06 0.0001032 0.07133 0.001236
0.08 6.782e-05 4.259e-06 0.0001376 0.02135 0.001648
0.1 6.782e-05 4.259e-06 0.0001376 0.02135 0.001648

-------------------------------------------------------------------------------
z H2O HO2 H2O2 C CH
z H2O HO2 H2O2 C CH
-------------------------------------------------------------------------------
0 0 0 0 0 0
0.02 0 0 0 0 0
0.04 0.02765 2.96e-07 2.011e-08 4.454e-20 4.963e-21
0.06 0.08296 8.88e-07 6.033e-08 1.336e-19 1.489e-20
0.08 0.1106 1.184e-06 8.044e-08 1.782e-19 1.985e-20
0.1 0.1106 1.184e-06 8.044e-08 1.782e-19 1.985e-20
0 0 0 0 0 0
0.02 0 0 0 0 0
0.04 0.02765 2.96e-07 2.011e-08 4.454e-20 4.963e-21
0.06 0.08296 8.88e-07 6.033e-08 1.336e-19 1.489e-20
0.08 0.1106 1.184e-06 8.044e-08 1.782e-19 1.985e-20
0.1 0.1106 1.184e-06 8.044e-08 1.782e-19 1.985e-20

-------------------------------------------------------------------------------
z CH2 CH2(S) CH3 CH4 CO
z CH2 CH2(S) CH3 CH4 CO
-------------------------------------------------------------------------------
0 0 0 0 0.04993 0
0.02 0 0 0 0.04993 0
0.04 1.299e-20 7.228e-22 7.945e-20 0.03744 0.000587
0.06 3.897e-20 2.168e-21 2.384e-19 0.01248 0.001761
0.08 5.196e-20 2.891e-21 3.178e-19 1.401e-19 0.002348
0.1 5.196e-20 2.891e-21 3.178e-19 1.401e-19 0.002348
0 0 0 0 0.04993 0
0.02 0 0 0 0.04993 0
0.04 1.299e-20 7.228e-22 7.945e-20 0.03744 0.000587
0.06 3.897e-20 2.168e-21 2.384e-19 0.01248 0.001761
0.08 5.196e-20 2.891e-21 3.178e-19 1.401e-19 0.002348
0.1 5.196e-20 2.891e-21 3.178e-19 1.401e-19 0.002348

-------------------------------------------------------------------------------
z CO2 HCO CH2O CH2OH CH3O
z CO2 HCO CH2O CH2OH CH3O
-------------------------------------------------------------------------------
0 0 0 0 0 0
0.02 0 0 0 0 0
0.04 0.03332 1.924e-11 2.395e-13 3.147e-19 4.683e-21
0.06 0.09995 5.772e-11 7.185e-13 9.441e-19 1.405e-20
0.08 0.1333 7.696e-11 9.58e-13 1.259e-18 1.873e-20
0.1 0.1333 7.696e-11 9.58e-13 1.259e-18 1.873e-20
0 0 0 0 0 0
0.02 0 0 0 0 0
0.04 0.03332 1.924e-11 2.395e-13 3.147e-19 4.683e-21
0.06 0.09995 5.772e-11 7.185e-13 9.441e-19 1.405e-20
0.08 0.1333 7.696e-11 9.58e-13 1.259e-18 1.873e-20
0.1 0.1333 7.696e-11 9.58e-13 1.259e-18 1.873e-20

-------------------------------------------------------------------------------
z CH3OH C2H C2H2 C2H3 C2H4
z CH3OH C2H C2H2 C2H3 C2H4
-------------------------------------------------------------------------------
0 0 0 0 0 0
0.02 0 0 0 0 0
0.04 2.19e-20 1.096e-27 3.177e-25 1.094e-30 1.075e-30
0.06 6.569e-20 3.287e-27 9.531e-25 3.283e-30 3.224e-30
0.08 8.758e-20 4.383e-27 1.271e-24 4.377e-30 4.298e-30
0.1 8.758e-20 4.383e-27 1.271e-24 4.377e-30 4.298e-30
0 0 0 0 0 0
0.02 0 0 0 0 0
0.04 2.19e-20 1.096e-27 3.177e-25 1.094e-30 1.075e-30
0.06 6.569e-20 3.287e-27 9.531e-25 3.283e-30 3.224e-30
0.08 8.758e-20 4.383e-27 1.271e-24 4.377e-30 4.298e-30
0.1 8.758e-20 4.383e-27 1.271e-24 4.377e-30 4.298e-30

-------------------------------------------------------------------------------
z C2H5 C2H6 HCCO CH2CO HCCOH
z C2H5 C2H6 HCCO CH2CO HCCOH
-------------------------------------------------------------------------------
0 0 0 0 0 0
0.02 0 0 0 0 0
0.04 5.292e-36 3.24e-37 1.308e-22 1.521e-22 1.095e-25
0.06 1.588e-35 9.719e-37 3.923e-22 4.563e-22 3.285e-25
0.08 2.117e-35 1.296e-36 5.23e-22 6.084e-22 4.381e-25
0.1 2.117e-35 1.296e-36 5.23e-22 6.084e-22 4.381e-25
0 0 0 0 0 0
0.02 0 0 0 0 0
0.04 5.292e-36 3.24e-37 1.308e-22 1.521e-22 1.095e-25
0.06 1.588e-35 9.719e-37 3.923e-22 4.563e-22 3.285e-25
0.08 2.117e-35 1.296e-36 5.23e-22 6.084e-22 4.381e-25
0.1 2.117e-35 1.296e-36 5.23e-22 6.084e-22 4.381e-25

-------------------------------------------------------------------------------
z N NH NH2 NH3 NNH
z N NH NH2 NH3 NNH
-------------------------------------------------------------------------------
0 0 0 0 0 0
0.02 0 0 0 0 0
0.04 5.944e-10 7.145e-11 2.291e-11 6.197e-11 5.73e-11
0.06 1.783e-09 2.144e-10 6.873e-11 1.859e-10 1.719e-10
0.08 2.378e-09 2.858e-10 9.164e-11 2.479e-10 2.292e-10
0.1 2.378e-09 2.858e-10 9.164e-11 2.479e-10 2.292e-10
0 0 0 0 0 0
0.02 0 0 0 0 0
0.04 5.944e-10 7.145e-11 2.291e-11 6.197e-11 5.73e-11
0.06 1.783e-09 2.144e-10 6.873e-11 1.859e-10 1.719e-10
0.08 2.378e-09 2.858e-10 9.164e-11 2.479e-10 2.292e-10
0.1 2.378e-09 2.858e-10 9.164e-11 2.479e-10 2.292e-10

-------------------------------------------------------------------------------
z NO NO2 N2O HNO CN
z NO NO2 N2O HNO CN
-------------------------------------------------------------------------------
0 0 0 0 0 0
0.02 0 0 0 0 0
0.04 0.000833 5.323e-07 6.55e-08 7.525e-09 5.744e-16
0.06 0.002499 1.597e-06 1.965e-07 2.257e-08 1.723e-15
0.08 0.003332 2.129e-06 2.62e-07 3.01e-08 2.297e-15
0.1 0.003332 2.129e-06 2.62e-07 3.01e-08 2.297e-15
0 0 0 0 0 0
0.02 0 0 0 0 0
0.04 0.000833 5.323e-07 6.55e-08 7.525e-09 5.744e-16
0.06 0.002499 1.597e-06 1.965e-07 2.257e-08 1.723e-15
0.08 0.003332 2.129e-06 2.62e-07 3.01e-08 2.297e-15
0.1 0.003332 2.129e-06 2.62e-07 3.01e-08 2.297e-15

-------------------------------------------------------------------------------
z HCN H2CN HCNN HCNO HOCN
z HCN H2CN HCNN HCNO HOCN
-------------------------------------------------------------------------------
0 0 0 0 0 0
0.02 0 0 0 0 0
0.04 1.756e-13 2.02e-20 8.356e-24 2.661e-18 4.599e-14
0.06 5.268e-13 6.061e-20 2.507e-23 7.983e-18 1.38e-13
0.08 7.024e-13 8.082e-20 3.342e-23 1.064e-17 1.84e-13
0.1 7.024e-13 8.082e-20 3.342e-23 1.064e-17 1.84e-13
0 0 0 0 0 0
0.02 0 0 0 0 0
0.04 1.756e-13 2.02e-20 8.356e-24 2.661e-18 4.599e-14
0.06 5.268e-13 6.061e-20 2.507e-23 7.983e-18 1.38e-13
0.08 7.024e-13 8.082e-20 3.342e-23 1.064e-17 1.84e-13
0.1 7.024e-13 8.082e-20 3.342e-23 1.064e-17 1.84e-13

-------------------------------------------------------------------------------
z HNCO NCO N2 AR C3H7
z HNCO NCO N2 AR C3H7
-------------------------------------------------------------------------------
0 0 0 0.7288 0 0
0.02 0 0 0.7288 0 0
0.04 1.988e-11 8.476e-13 0.7284 0 9.35e-53
0.06 5.963e-11 2.543e-12 0.7276 0 2.805e-52
0.08 7.95e-11 3.391e-12 0.7272 0 3.74e-52
0.1 7.95e-11 3.391e-12 0.7272 0 3.74e-52
0 0 0 0.7288 0 0
0.02 0 0 0.7288 0 0
0.04 1.988e-11 8.476e-13 0.7284 0 9.35e-53
0.06 5.963e-11 2.543e-12 0.7276 0 2.805e-52
0.08 7.95e-11 3.391e-12 0.7272 0 3.74e-52
0.1 7.95e-11 3.391e-12 0.7272 0 3.74e-52

-------------------------------------------------------------------------------
z C3H8 CH2CHO CH3CHO
z C3H8 CH2CHO CH3CHO
-------------------------------------------------------------------------------
0 0 0 0
0.02 0 0 0
0.04 5.365e-54 2.809e-28 4.525e-29
0.06 1.61e-53 8.426e-28 1.358e-28
0.08 2.146e-53 1.123e-27 1.81e-28
0.1 2.146e-53 1.123e-27 1.81e-28
0 0 0 0
0.02 0 0 0
0.04 5.365e-54 2.809e-28 4.525e-29
0.06 1.61e-53 8.426e-28 1.358e-28
0.08 2.146e-53 1.123e-27 1.81e-28
0.1 2.146e-53 1.123e-27 1.81e-28


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> domain 2 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> outlet <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


-------------------------------------------------------------------------------
z
z
-------------------------------------------------------------------------------
0
0
Flame speed with mixture-averaged transport: 0.3158995218368368 m/s
Flame speed with multicomponent transport: 0.318579363934684 m/s
Flame speed with multicomponent transport + Soret: 0.3183709757821478 m/s

z (m) T (K) U (m/s) Y(CO)
z (m) T (K) U (m/s) Y(CO)
0.000000 300.000 0.318 0.00000
0.020000 300.070 0.318 0.00000
0.040000 319.350 0.339 0.00074
Expand Down

0 comments on commit b412c0e

Please sign in to comment.