Skip to content

Commit

Permalink
Visualizing the sparsity pattern of the collocation matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
ddrous committed May 25, 2024
1 parent da661fe commit 319632b
Showing 1 changed file with 60 additions and 5 deletions.
65 changes: 60 additions & 5 deletions demos/Laplace/30_laplace_super_scaled.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import jax.numpy as jnp

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

import matplotlib.pyplot as plt
import seaborn as sns
Expand All @@ -21,12 +21,14 @@
DATAFOLDER = "./data/TempFolder/"

RBF = partial(polyharmonic, a=1)
# RBF = partial(gaussian, eps=1e-1)
# RBF = partial(thin_plate, a=3)
MAX_DEGREE = 0

Nx = Ny = 10
SUPPORT_SIZE = "max"
# SUPPORT_SIZE = 9*1
facet_types={"South":"n", "West":"d", "North":"d", "East":"d"}
Nx = Ny = 20
# SUPPORT_SIZE = "max"
SUPPORT_SIZE = 20*2
facet_types={"South":"d", "West":"d", "North":"d", "East":"d"}

start = time.time()
cloud = SquareCloud(Nx=Nx, Ny=Ny, facet_types=facet_types, support_size=SUPPORT_SIZE)
Expand Down Expand Up @@ -65,9 +67,62 @@ def my_rhs_operator(x, centers=None, rbf=None, fields=None):
rbf_sol = sol.vals



fig = plt.figure(figsize=(6*1,5))
ax= fig.add_subplot(1, 1, 1, projection='3d')
cloud.visualize_field(rbf_sol, cmap="jet", projection="3d", title="Laplace with RBFs", ax=ax);
plt.show()
## Savefig
fig.savefig(DATAFOLDER+"super_scaled.png", dpi=300)


# %%







# ## Observing the sparsity patten of the matrices involved

# RBF = partial(gaussian, eps=1)

# Nx = Ny = 10
# SUPPORT_SIZE = "max"
# # SUPPORT_SIZE = 5
# facet_types={"South":"n", "West":"d", "North":"d", "East":"d"}

# cloud = SquareCloud(Nx=Nx, Ny=Ny, facet_types=facet_types, support_size=SUPPORT_SIZE)




M = compute_nb_monomials(MAX_DEGREE, 2)
A = assemble_A(cloud, RBF, M)
mat1 = jnp.abs(A)

inv_A = assemble_invert_A(cloud, RBF, M)
mat2 = jnp.abs(inv_A)

## Matrix B for the linear system
mat3 = sol.mat

## 3 figures
fig, ax = plt.subplots(1, 3, figsize=(15,5))

sns.heatmap(jnp.abs(mat1), ax=ax[0], cmap="grey", cbar=True, square=True, xticklabels=False, yticklabels=False)
ax[0].set_title("Collocation Matrix")

sns.heatmap(jnp.abs(mat2), ax=ax[1], cmap="grey", cbar=True, square=True, xticklabels=False, yticklabels=False)
ax[1].set_title("Inverse of Collocation Matrix")

sns.heatmap(jnp.abs(mat3), ax=ax[2], cmap="grey", cbar=True, square=True, xticklabels=False, yticklabels=False)
ax[2].set_title("Linear System Matrix (B)")

# plt.title("Sparsity Pattern of the Collocation Matrix")
plt.show()


#%%

0 comments on commit 319632b

Please sign in to comment.