Skip to content

Commit

Permalink
[Examples] Fix file output issues with some flame examples
Browse files Browse the repository at this point in the history
  • Loading branch information
speth committed Dec 1, 2024
1 parent 400f481 commit 2f9f92f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
14 changes: 8 additions & 6 deletions samples/python/onedim/diffusion_flame_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def names(test):
# Save to data directory
file_name, entry = names("initial-solution")
desc = "Initial hydrogen-oxygen counterflow flame at 1 bar and low strain rate"
f.save(file_name, name=entry, description=desc)
f.save(file_name, name=entry, description=desc, overwrite=True)

# %%
# Batch Pressure Loop
Expand Down Expand Up @@ -148,7 +148,8 @@ def names(test):
# Try solving the flame
f.solve(loglevel=0)
file_name, entry = names(f"pressure-loop/{p:05.1f}")
f.save(file_name, name=entry, description=f"pressure = {p} bar")
f.save(file_name, name=entry, description=f"pressure = {p} bar",
overwrite=True)
p_previous = p
except ct.CanteraError as e:
print('Error occurred while solving:', e, 'Try next pressure level')
Expand Down Expand Up @@ -201,7 +202,7 @@ def names(test):
f.solve(loglevel=0)
file_name, entry = names(f"strain-loop/{n:02d}")
f.save(file_name, name=entry,
description=f"strain rate iteration {n}")
description=f"strain rate iteration {n}", overwrite=True)
except FlameExtinguished:
print('Flame extinguished')
break
Expand Down Expand Up @@ -238,9 +239,10 @@ def names(test):
ax2.legend(loc=0)
ax2.set_xlabel(r'$z/z_{max}$')
ax2.set_ylabel(r'$u/u_f$')
fig1.savefig(output_path / "figure_u_p.png")
fig2.savefig(output_path / "figure_u_p.png")
plt.show()

# %%
fig3 = plt.figure()
fig4 = plt.figure()
ax3 = fig3.add_subplot(1, 1, 1)
Expand All @@ -261,10 +263,10 @@ def names(test):
ax3.legend(loc=0)
ax3.set_xlabel(r'$z/z_{max}$')
ax3.set_ylabel(r'$T$ [K]')
fig1.savefig(output_path / "figure_T_a.png")
fig3.savefig(output_path / "figure_T_a.png")

ax4.legend(loc=0)
ax4.set_xlabel(r'$z/z_{max}$')
ax4.set_ylabel(r'$u/u_f$')
fig1.savefig(output_path / "figure_u_a.png")
fig4.savefig(output_path / "figure_u_a.png")
plt.show()
6 changes: 4 additions & 2 deletions samples/python/onedim/diffusion_flame_extinction.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ def names(test):
# Flame is still burning, so proceed to next strain rate
n_last_burning = n
file_name, entry = names(f"extinction/{n:04d}")
f.save(file_name, name=entry, description=f"Solution at alpha = {alpha[-1]}")
f.save(file_name, name=entry, description=f"Solution at alpha = {alpha[-1]}",
overwrite=True)

print('Flame burning at alpha = {:8.4F}. Proceeding to the next iteration, '
'with delta_alpha = {}'.format(alpha[-1], delta_alpha))
Expand All @@ -155,7 +156,8 @@ def names(test):
# strain rate increase is reached, save the last, non-burning, solution
# to the output file and break the loop
file_name, entry = names(f"extinction/{n:04d}")
f.save(file_name, name=entry, description=f"Flame extinguished at alpha={alpha[-1]}")
f.save(file_name, name=entry, overwrite=True,
description=f"Flame extinguished at alpha={alpha[-1]}")

print('Flame extinguished at alpha = {0:8.4F}.'.format(alpha[-1]),
'Abortion criterion satisfied.')
Expand Down
6 changes: 4 additions & 2 deletions samples/python/onedim/flame_initial_guess.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def describe(flame):

print("Save YAML")
yaml_filepath = output_path / "flame.yaml"
f.save(yaml_filepath, name="solution", description="Initial methane flame")
f.save(yaml_filepath, name="solution", description="Initial methane flame",
overwrite=True)

print("Save CSV")
csv_filepath = output_path / "flame.csv"
Expand All @@ -74,7 +75,8 @@ def describe(flame):
# HDF is not a required dependency
hdf_filepath = output_path / "flame.h5"
hdf_filepath.unlink(missing_ok=True)
f.save(hdf_filepath, name="freeflame", description="Initial methane flame")
f.save(hdf_filepath, name="freeflame", description="Initial methane flame",
overwrite=True)
print("Save HDF\n")
else:
print(f"Skipping HDF: Cantera compiled without HDF support\n")
Expand Down

0 comments on commit 2f9f92f

Please sign in to comment.