Skip to content
Extraits de code Groupes Projets
Valider 171c8cec rédigé par Simon Collignon's avatar Simon Collignon
Parcourir les fichiers

fixing periodization issue

parent cd9c16ba
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -26,11 +26,15 @@ def cahn_hilliard_fdiff(it, c):
cp[:, -1] = cp[:, 1]
f[1:-1, 1:-1] = cp[1:-1, 1:-1]**3 - cp[1:-1, 1:-1] - (a / dx)**2 * (cp[0:-2, 1:-1] + cp[2:, 1:-1] + cp[1:-1, 0:-2] + cp[1:-1, 2:] - 4 * cp[1:-1, 1:-1])
cp[1:-1, 1:-1] = cp[1:-1, 1:-1] + (dt / dx**2) * (f[0:-2, 1:-1] + f[2:, 1:-1] + f[1:-1, 0:-2] + f[1:-1, 2:] - 4 * f[1:-1, 1:-1])
c = cp[1:-1, 1:-1]
f[0, :] = f[-2, :]
f[-1, :] = f[1, :]
f[:, 0] = f[:, -2]
f[:, -1] = f[:, 1]
return c
cp[1:-1, 1:-1] = cp[1:-1, 1:-1] + (dt / dx**2) * (f[0:-2, 1:-1] + f[2:, 1:-1] + f[1:-1, 0:-2] + f[1:-1, 2:] - 4 * f[1:-1, 1:-1])
return cp[1:-1, 1:-1]
def cahn_hilliard_spectral(it, c):
......@@ -56,13 +60,13 @@ if __name__ == "__main__":
c2 = cahn_hilliard_spectral(it, c)
toc = time.time() - tic
print(f"Elapsed time is {toc} seconds.")
fig, (ax1, ax2) = plt.subplots(1, 2)
fig.suptitle(f"Cahn-Hilliard integration for {it} iterations ")
ax1.imshow(c1, cmap="jet", vmin=-1, vmax=1)
ax1.contourf(xy, xy, c1, cmap="jet", vmin=-1, vmax=1)
ax1.set_title("Finite differences method")
ax2.imshow(c2, cmap="jet", vmin=-1, vmax=1)
ax2.contourf(xy, xy, c2, cmap="jet", vmin=-1, vmax=1)
ax2.set_title("Spectral method")
plt.show()
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter