Skip to content

Commit

Permalink
Rerun of the advection-diffusion case
Browse files Browse the repository at this point in the history
  • Loading branch information
rdes committed Mar 2, 2024
1 parent bd9f4cc commit fa0d04a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 4 additions & 4 deletions demos/Advection/00_advection_with_rbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import jax
import jax.numpy as jnp

jax.config.update('jax_platform_name', 'cpu')
# jax.config.update('jax_platform_name', 'cpu')
jax.config.update("jax_enable_x64", True)

from updec import *
Expand Down Expand Up @@ -65,7 +65,7 @@ def my_rhs_operator(x, centers=None, rbf=None, fields=None):
## u0 is zero everywhere except at a point in the middle
u0 = jnp.zeros(cloud.N)
source_id = int(cloud.N*0.01)
source_neighbors = jnp.array(cloud.local_supports[source_id][:cloud.N//60])
source_neighbors = jnp.array(cloud.local_supports[source_id][:cloud.N//40])
u0 = u0.at[source_neighbors].set(0.95)

## Begin timestepping for 100 steps
Expand Down Expand Up @@ -111,9 +111,9 @@ def my_rhs_operator(x, centers=None, rbf=None, fields=None):

# %%

ax = plt.gca()
# ax = plt.gca()
filename = DATAFOLDER + "advection_diffusion_rbf.gif"
cloud.animate_fields([ulist], cmaps="jet", filename=filename, figsize=(6,3),colorbar=False, titles=["Implicit scheme for Advection-Diffusion with RBFs"])
cloud.animate_fields([ulist], cmaps="jet", filename=filename, figsize=(7,3), titles=["Advection-Diffusion with RBFs"])



Expand Down
8 changes: 5 additions & 3 deletions updec/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def visualize_field(self, field, projection="2d", title="Field", xlabel=r'$x$',
return ax, img


def animate_fields(self, fields, filename=None, titles="Field", xlabel=r'$x$', ylabel=r'$y$', levels=50, figsize=(6,5), cmaps="jet", cbarsplit=7, duration=5, **kwargs):
def animate_fields(self, fields, filename=None, titles="Field", xlabel=r'$x$', ylabel=r'$y$', levels=50, figsize=(6,5), cmaps="jet", cbarsplit=50, duration=5, **kwargs):
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
import os
Expand Down Expand Up @@ -281,6 +281,7 @@ def animate_fields(self, fields, filename=None, titles="Field", xlabel=r'$x$', y
m = plt.cm.ScalarMappable(cmap=cmaps[i])
m.set_array(signals[i])
m.set_clim(minmax[0], minmax[1])
# m.set_norm(plt.Normalize(vmin=minmax[0], vmax=minmax[1]))
plt.colorbar(m, boundaries=boundaries, shrink=1.0, aspect=10, ax=ax[i])

try:
Expand All @@ -295,7 +296,7 @@ def animate_fields(self, fields, filename=None, titles="Field", xlabel=r'$x$', y

## ANimation function
def animate(frame):
imgs = [ax[i].tricontourf(x, y, signals[i][frame], levels=levels, vmin=minmaxs[i][0], vmax=minmaxs[i][1], cmap=cmaps[i], extend='min', **kwargs) for i in range(nb_signals)]
imgs = [ax[i].tricontour(x, y, signals[i][frame], levels=levels, vmin=minmaxs[i][0], vmax=minmaxs[i][1], cmap=cmaps[i], extend='min', **kwargs) for i in range(nb_signals)]
# plt.suptitle("iter = "+str(i), size="large", y=0.95) ## TODO doesn't work well with tight layout
return imgs

Expand All @@ -308,7 +309,8 @@ def animate(frame):
fps = step_count / duration
# anim.save(filename, writer='ffmpeg', fps=fps)
anim.save(filename, writer='pillow', fps=fps)
os.system("open "+filename)
# os.system("open "+filename)
print("Animation saved as", filename)

return ax

Expand Down

0 comments on commit fa0d04a

Please sign in to comment.