Files
NuFI_deal.ii/plotting.ipynb
T

138 KiB

In [33]:
import numpy as np
import matplotlib.pyplot as plt

import pyvista as pv
from pyvista.trame.jupyter import launch_server
await launch_server().ready
Out [33]:
True
In [39]:
mesh = pv.read('electric_field.vtk')
mesh2 = pv.read("density.vtk")
mesh.plot()
mesh
Out [39]:
Widget(value='<iframe src="http://localhost:39299/index.html?ui=P_0x78816c2c7c50_5&reconnect=auto" class="pyvi…
HeaderData Arrays
UnstructuredGridInformation
N Cells128
N Points256
X Bounds0.000e+00, 1.200e+01
Y Bounds0.000e+00, 0.000e+00
Z Bounds0.000e+00, 0.000e+00
N Arrays2
NameFieldTypeN CompMinMax
densityPointsfloat641-1.000e-021.000e-02
x_coordinatePointsfloat6410.000e+001.200e+01
In [44]:
arr_x = np.array(mesh.point_data["x_coordinate"])
arr_e_field = np.array(mesh.point_data["electric_field"])[:,0]
arr_potential = np.array(mesh.point_data["potential"])
arr_density = np.array(mesh2.point_data["density"])

# Electric field plot
plt.figure(figsize=(7, 4))
plt.scatter(arr_x, arr_e_field, s=15, alpha=0.7)
plt.xlabel("x")
plt.ylabel("E(x)")
plt.title("Electric Field")
plt.grid(True, linestyle="--", linewidth=0.5, alpha=0.6)
plt.tight_layout()
plt.show()

# Potential plot
plt.figure(figsize=(7, 4))
plt.scatter(arr_x, arr_potential, s=15, alpha=0.7)
plt.xlabel("x")
plt.ylabel("Potential")
plt.title("Electric Potential")
plt.grid(True, linestyle="--", linewidth=0.5, alpha=0.6)
plt.tight_layout()
plt.show()

# Potential plot
plt.figure(figsize=(7, 4))
plt.scatter(arr_x, arr_density, s=15, alpha=0.7)
plt.xlabel("x")
plt.ylabel(r"$\rho(x)$")
plt.title("Charge Density")
plt.grid(True, linestyle="--", linewidth=0.5, alpha=0.6)
plt.tight_layout()
plt.show()
In [ ]: