mirror of
https://github.com/Cantera/cantera.git
synced 2025-02-25 18:55:29 -06:00
[samples] Update file IO
This commit is contained in:
parent
b7717ac464
commit
3ea251020c
@ -17,7 +17,6 @@
|
||||
#include "cantera/onedim.h"
|
||||
#include "cantera/oneD/DomainFactory.h"
|
||||
#include "cantera/base/stringUtils.h"
|
||||
#include <fstream>
|
||||
|
||||
using namespace Cantera;
|
||||
using fmt::print;
|
||||
@ -125,10 +124,7 @@ int flamespeed(double phi, bool refine_grid, int loglevel)
|
||||
} else {
|
||||
fileName = "flamespeed.yaml";
|
||||
}
|
||||
if (std::ifstream(fileName).good()) {
|
||||
std::remove(fileName.c_str());
|
||||
}
|
||||
flame.save(fileName, "initial-guess", "Initial guess", 0);
|
||||
flame.save(fileName, "initial-guess", "Initial guess", true);
|
||||
|
||||
// Solve freely propagating flame
|
||||
|
||||
@ -141,18 +137,16 @@ int flamespeed(double phi, bool refine_grid, int loglevel)
|
||||
flame.solve(loglevel,refine_grid);
|
||||
double flameSpeed_mix = flame.value(flowdomain,
|
||||
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);
|
||||
print("Flame speed with mixture-averaged transport: {} m/s\n", flameSpeed_mix);
|
||||
flame.save(fileName, "mix", "Solution with mixture-averaged transport", true);
|
||||
|
||||
// now switch to multicomponent transport
|
||||
flow->setTransportModel("multicomponent");
|
||||
flame.solve(loglevel, refine_grid);
|
||||
double flameSpeed_multi = flame.value(flowdomain,
|
||||
flow->componentIndex("velocity"),0);
|
||||
print("Flame speed with multicomponent transport: {} m/s\n",
|
||||
flameSpeed_multi);
|
||||
flame.save(fileName, "multi", "Solution with multicomponent transport", 0);
|
||||
print("Flame speed with multicomponent transport: {} m/s\n", flameSpeed_multi);
|
||||
flame.save(fileName, "multi", "Solution with multicomponent transport", true);
|
||||
|
||||
// now enable Soret diffusion
|
||||
flow->enableSoret(true);
|
||||
@ -162,7 +156,7 @@ int flamespeed(double phi, bool refine_grid, int loglevel)
|
||||
print("Flame speed with multicomponent transport + Soret: {} m/s\n",
|
||||
flameSpeed_full);
|
||||
flame.save(fileName, "soret",
|
||||
"Solution with mixture-averaged transport and Soret", 0);
|
||||
"Solution with mixture-averaged transport and Soret", true);
|
||||
|
||||
vector_fp zvec,Tvec,COvec,CO2vec,Uvec;
|
||||
|
||||
|
@ -137,12 +137,12 @@ for p in p_range:
|
||||
# Try solving the flame
|
||||
f.solve(loglevel=0)
|
||||
file_name, entry = names(f"pressure-loop/{p:05.1f}")
|
||||
f.save(file_name, name=entry, loglevel=1, description=f"pressure = {p} bar")
|
||||
f.save(file_name, name=entry, description=f"pressure = {p} bar")
|
||||
p_previous = p
|
||||
except ct.CanteraError as e:
|
||||
print('Error occurred while solving:', e, 'Try next pressure level')
|
||||
# If solution failed: Restore the last successful solution and continue
|
||||
f.restore(file_name, name=entry, loglevel=0)
|
||||
f.restore(file_name, name=entry)
|
||||
|
||||
|
||||
# PART 3: STRAIN RATE LOOP
|
||||
@ -162,7 +162,7 @@ exp_mdot_a = 1. / 2.
|
||||
|
||||
# Restore initial solution
|
||||
file_name, entry = names("initial-solution")
|
||||
f.restore(file_name, name=entry, loglevel=0)
|
||||
f.restore(file_name, name=entry)
|
||||
|
||||
# Counter to identify the loop
|
||||
n = 0
|
||||
@ -188,7 +188,7 @@ while np.max(f.T) > temperature_limit_extinction:
|
||||
# Try solving the flame
|
||||
f.solve(loglevel=0)
|
||||
file_name, entry = names(f"strain-loop/{n:02d}")
|
||||
f.save(file_name, name=entry, loglevel=1,
|
||||
f.save(file_name, name=entry,
|
||||
description=f"strain rate iteration {n}")
|
||||
except FlameExtinguished:
|
||||
print('Flame extinguished')
|
||||
@ -234,7 +234,7 @@ ax4 = fig4.add_subplot(1, 1, 1)
|
||||
n_selected = range(1, n, 5)
|
||||
for n in n_selected:
|
||||
file_name, entry = names(f"strain-loop/{n:02d}")
|
||||
f.restore(file_name, name=entry, loglevel=0)
|
||||
f.restore(file_name, name=entry)
|
||||
a_max = f.strain_rate('max') # the maximum axial strain rate
|
||||
|
||||
# Plot the temperature profiles for the strain rate loop (selected)
|
||||
|
@ -165,13 +165,13 @@ while True:
|
||||
|
||||
# Restore last burning solution
|
||||
file_name, entry = names(f"extinction/{n_last_burning:04d}")
|
||||
f.restore(file_name, entry, loglevel=0)
|
||||
f.restore(file_name, entry)
|
||||
|
||||
|
||||
# Print some parameters at the extinction point, after restoring the last burning
|
||||
# solution
|
||||
file_name, entry = names(f"extinction/{n_last_burning:04d}")
|
||||
f.restore(file_name, entry, loglevel=0)
|
||||
f.restore(file_name, entry)
|
||||
|
||||
print('----------------------------------------------------------------------')
|
||||
print('Parameters at the extinction point:')
|
||||
|
@ -76,14 +76,14 @@ else:
|
||||
print("Restore solution from YAML")
|
||||
gas.TPX = Tin, p, reactants
|
||||
f2 = ct.FreeFlame(gas, width=width)
|
||||
f2.restore(yaml_filepath, name="solution", loglevel=0)
|
||||
f2.restore(yaml_filepath, name="solution")
|
||||
describe(f2)
|
||||
|
||||
if hdf_filepath:
|
||||
print("Restore solution from HDF")
|
||||
gas.TPX = Tin, p, reactants
|
||||
f2 = ct.FreeFlame(gas, width=width)
|
||||
f2.restore(hdf_filepath, name="freeflame", loglevel=0)
|
||||
f2.restore(hdf_filepath, name="freeflame")
|
||||
describe(f2)
|
||||
|
||||
# Restore the flame via initial guess
|
||||
|
Loading…
Reference in New Issue
Block a user