Skip to content

Commit

Permalink
Plots pointwise error instead of resolutions
Browse files Browse the repository at this point in the history
  • Loading branch information
aadi-bh committed Nov 28, 2023
1 parent 7f18900 commit 0e16536
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
27 changes: 16 additions & 11 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,36 +140,41 @@ def run(args):

# PLOT!
nn = 2048
fig, ax = plt.subplots(nrows=1, ncols=2, figsize = (14, 8), width_ratios=[3,1])
# Exact
if args.exact != None:
exact = np.loadtxt(args.exact).transpose()
exact[0] *= 2 * pi
ax[0].plot(exact[0], exact[1], 'ko', markersize=0.8, label="Exact")
fig, ax = plt.subplots(nrows=1, ncols=2, figsize = (14, 8), width_ratios=[2.5,1])
# Initial
x = np.linspace(xmin, xmax, 1000)
ax[0].plot(x, initial_condition(x), linewidth=1, color='k', label="Init")
# Exact
exact = None
if args.exact != None:
if args.exact == "init":
exact = np.vstack((x,initial_condition(x)))
else:
exact = np.loadtxt(args.exact).transpose()
exact[0] *= 2 * pi
ax[0].plot(exact[0], exact[1], 'ko', markersize=0.8, label="Exact")
# All the modes
for (t, uhinit, uf, v) in sols:
n = len(uf)
x = cgrid(n)
label = str(n) + f", t={np.round(t, 3)}"
# plots.smoothplot(uf, ax[0], label=label)
if args.ggb:
label += ",ggb"
if args.filter != 'no_filter':
label += "," + args.filter
ax[0].plot(cgrid(n), v, label=label)
plots.plot_and_error(ax[0], ax[1], x, v, exact, label=label)
elif args.filter != 'no_filter':
label += "," + args.filter
plots.smoothplot(uf, ax[0], label=label)
plots.smooth_and_error(ax[0], ax[1], uf, exact, label=label)
else:
# So no filter, no ggb
plots.smoothplot(uf, ax[0], label=label)
# plots.smoothplot(uf, ax[0], label=label)
plots.smooth_and_error(ax[0], ax[1], uf, exact, label=label)
if args.show_markers:
ax[0].plot(cgrid(n), ifft(uf), "+", color= "red", markersize=5)

ax[0].grid(visible=True)
ax[0].legend()
ax[1].legend()
fig.tight_layout()
fig.savefig(plotname)
print("Saved plot to "+plotname)
21 changes: 21 additions & 0 deletions plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,27 @@ def smoothplot(v, ax,nn=2048, **plotargs):
ax.plot(z, ifft(w).real, **plotargs)
return z, ifft(w)

def smooth_and_error(solax, errax, v, exact, nn=2048, **plotargs):
if np.any(exact == None):
print("Exact not found.")
return smoothplot(v, solax, **plotargs)
plot_and_error(solax, errax, exact[0], ifft_at(exact[0], v).real, exact, **plotargs)

def plot_and_error(solax, errax, x, u, exact, **plotargs):
solax.plot(x, u, **plotargs)
if np.any(exact == None):
print("Exact not found.")
return
if len(x) > len(exact[0]):
ei = np.interp(x, exact[0], exact[1])
errax.plot(x, np.abs(u-ei), **plotargs)
elif (len(x) < len(exact[0])):
ui = np.interp(exact[0], x, u)
errax.plot(exact[0], np.abs(u-ei), **plotargs)
else:
errax.plot(x, np.abs(u-exact[1]), **plotargs)


def convergence_plot(exactfile, filenames, saveas, **kwargs):
for fn in filenames:
if not os.path.isfile(fn):
Expand Down

0 comments on commit 0e16536

Please sign in to comment.