from physmodjax.solver.generator import Gaussian
Finite element solver for the 1D wave equation
A finite-element solver for the 1D wave equation.
We use finite elements to obtain the mass \(M\) and stiffness \(K\) matrices. We use bilinear discretization for the time stepping.
\[ \begin{bmatrix} \dot{\mathbf{x}} \\ \ddot{\mathbf{x}} \end{bmatrix} = \begin{bmatrix} 0 & \mathbf{I} \\ -\mathbf{M}^{-1}\mathbf{K} & 0 \end{bmatrix} \begin{bmatrix} \mathbf{x} \\ \dot{\mathbf{x}} \end{bmatrix} + \begin{bmatrix} 0 \\ \mathbf{M}^{-1} \end{bmatrix} \mathbf{f} \]
discretize
discretize (A, step)
Jax compatible bilinear discretization from https://github.com/srush/annotated-s4
Wave1dSolverFE
Wave1dSolverFE (sampling_rate:float, final_time:float, length:float, n_gridpoints:int, wave_speed:float=1)
This class solves the 1D wave equation using finite elements and state space discretization.
Type | Default | Details | |
---|---|---|---|
sampling_rate | float | sampling rate in Hz | |
final_time | float | final time in seconds | |
length | float | length of the string in meters | |
n_gridpoints | int | number of points in the string | |
wave_speed | float | 1 | wave speed in m/s |
Test
= 200
n_gridpoints = Wave1dSolverFE(
solver =2000,
sampling_rate=1,
final_time=1,
length=n_gridpoints,
n_gridpoints=10,
wave_speed
)
= Gaussian(num_points=n_gridpoints)()
u0 = np.zeros_like(u0)
v0
= solver.solve(u0, v0) t, u, v
dx: 0.005025125628140704 in meters
dt: 0.0005 in seconds
number of points (n_gridpoints): (200,)
time in samples (nt): (2000,)
50], label="initial") plt.plot(solver.grid, u[
# show the solution viewed from above
=(5, 10))
plt.figure(figsize
plt.pcolormesh(solver.grid, t, u)"x")
plt.xlabel("t")
plt.ylabel(
plt.colorbar() plt.show()