Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update channel inversion example #366

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion examples/channel_inversion/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
all: invert plot

CONTROLS = Bathymetry Manning InitialElev
STATIONS = stationA stationB stationC stationD stationE

invert:
for controls in $(CONTROLS); do \
Expand All @@ -9,7 +10,9 @@ invert:

plot:
for controls in $(CONTROLS); do \
python3 plot_elevation_progress.py -c $$controls
for station in $(STATIONS); do \
python3 plot_elevation_progress.py -c $$controls -s $$station; \
done; \
done

clean:
Expand Down
3 changes: 2 additions & 1 deletion examples/channel_inversion/inverse_problem.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from thetis import *
import firedrake as fd
from firedrake.adjoint import *
import numpy
import thetis.inversion_tools as inversion_tools
Expand Down Expand Up @@ -133,4 +134,4 @@
oc.rename(name)
print_function_value_range(oc, prefix='Optimal')
if not no_exports:
VTKFile(f'{options.output_directory}/{name}_optimised.pvd').write(oc)
fd.VTKFile(f'{options.output_directory}/{name}_optimised.pvd').write(oc)
7 changes: 4 additions & 3 deletions examples/channel_inversion/plot_elevation_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import matplotlib
import matplotlib.pyplot as plt
import argparse
from collections import Iterable
from collections.abc import Iterable

matplotlib.rc('font', size=10)

Expand All @@ -26,7 +26,7 @@

ctrl_str = '-'.join(controls)
station_str = '-'.join(station_names)
inv_dir = f'outputs_{ctrl_str}-opt'
inv_dir = f'outputs_new_{ctrl_str}-opt'

nplots = len(station_names)

Expand All @@ -45,14 +45,15 @@

g = f'{inv_dir}/diagnostic_timeseries_progress_{sta}_elev.hdf5'
with h5py.File(g, 'r') as h5file:
iter_times = h5file['time'][:].flatten()
iter_vals = h5file['elev'][:]

niter = iter_vals.shape[0] - 1

ax = next(ax_iter)
ax.plot(time, vals, 'k:', zorder=3, label='observation', lw=1.3)
for i, v in enumerate(iter_vals):
ax.plot(time, v, label=f'iteration {i}', lw=0.5)
ax.plot(iter_times, v, label=f'iteration {i}', lw=0.5)
ax.set_title(f'{sta}', size='small')
ax.set_ylabel('Elevation (m)')
ax.grid(True)
Expand Down
Loading