I’m reading the devito_book/fdm-jupyter-book/notebooks/01_vib/vib_undamped.ipynb and the code in it seems not compatible with devito 4.8.3.
So I tried to rewrite it as:
import numpy as np
from devito import Constant, TimeFunction, Eq, solve, Operator, Grid, TimeDimension
def solver(I, w, dt, T):
dt = float(dt)
Nt = int(round(T / dt))
t = TimeDimension('t', spacing=Constant('h_t'))
grid = Grid(shape=(Nt + 1, ), time_dimension=t)
u = TimeFunction(name='u', grid=grid, time_order=2)
u.data[:] = I
eqn = u.dt2 + w ** 2 * u
stencil = Eq(u.forward, solve(eqn, u.forward))
op = Operator(stencil)
op.apply(h_t=dt, t_M=Nt - 1)
return u.data, np.linspace(0, Nt * dt, Nt + 1)
I = 1
w = 2 * np.pi
dt = 0.05
num_periods = 5
P = 2 * np.pi / w
T = P * num_periods
u, t = solver(I, w, dt, T)
However, the data of returned u
is:
[[0.95374113 0.95374113 0.95374113 0.95374113 0.95374113 0.95374113, 0.95374113 0.95374113 0.95374113 0.95374113 0.95374113 0.95374113, 0.95374113 0.95374113 0.95374113 0.95374113 0.95374113 0.95374113, 0.95374113 0.95374113 0.95374113 0.95374113 0.95374113 0.95374113, 0.95374113 0.95374113 0.95374113 0.95374113 0.95374113 0.95374113, 0.95374113 0.95374113 0.95374113 0.95374113 0.95374113 0.95374113, 0.95374113 0.95374113 0.95374113 0.95374113 0.95374113 0.95374113, 0.95374113 0.95374113 0.95374113 0.95374113 0.95374113 0.95374113, 0.95374113 0.95374113 0.95374113 0.95374113 0.95374113 0.95374113, 0.95374113 0.95374113 0.95374113 0.95374113 0.95374113 0.95374113, 0.95374113 0.95374113 0.95374113 0.95374113 0.95374113 0.95374113, 0.95374113 0.95374113 0.95374113 0.95374113 0.95374113 0.95374113, 0.95374113 0.95374113 0.95374113 0.95374113 0.95374113 0.95374113, 0.95374113 0.95374113 0.95374113 0.95374113 0.95374113 0.95374113, 0.95374113 0.95374113 0.95374113 0.95374113 0.95374113 0.95374113, 0.95374113 0.95374113 0.95374113 0.95374113 0.95374113 0.95374113, 0.95374113 0.95374113 0.95374113 0.95374113 0.95374113], [1.0121983 1.0121983 1.0121983 1.0121983 1.0121983 1.0121983, 1.0121983 1.0121983 1.0121983 1.0121983 1.0121983 1.0121983, 1.0121983 1.0121983 1.0121983 1.0121983 1.0121983 1.0121983, 1.0121983 1.0121983 1.0121983 1.0121983 1.0121983 1.0121983, 1.0121983 1.0121983 1.0121983 1.0121983 1.0121983 1.0121983, 1.0121983 1.0121983 1.0121983 1.0121983 1.0121983 1.0121983, 1.0121983 1.0121983 1.0121983 1.0121983 1.0121983 1.0121983, 1.0121983 1.0121983 1.0121983 1.0121983 1.0121983 1.0121983, 1.0121983 1.0121983 1.0121983 1.0121983 1.0121983 1.0121983, 1.0121983 1.0121983 1.0121983 1.0121983 1.0121983 1.0121983, 1.0121983 1.0121983 1.0121983 1.0121983 1.0121983 1.0121983, 1.0121983 1.0121983 1.0121983 1.0121983 1.0121983 1.0121983, 1.0121983 1.0121983 1.0121983 1.0121983 1.0121983 1.0121983, 1.0121983 1.0121983 1.0121983 1.0121983 1.0121983 1.0121983, 1.0121983 1.0121983 1.0121983 1.0121983 1.0121983 1.0121983, 1.0121983 1.0121983 1.0121983 1.0121983 1.0121983 1.0121983, 1.0121983 1.0121983 1.0121983 1.0121983 1.0121983 ], [0.8011535 0.8011535 0.8011535 0.8011535 0.8011535 0.8011535, 0.8011535 0.8011535 0.8011535 0.8011535 0.8011535 0.8011535, 0.8011535 0.8011535 0.8011535 0.8011535 0.8011535 0.8011535, 0.8011535 0.8011535 0.8011535 0.8011535 0.8011535 0.8011535, 0.8011535 0.8011535 0.8011535 0.8011535 0.8011535 0.8011535, 0.8011535 0.8011535 0.8011535 0.8011535 0.8011535 0.8011535, 0.8011535 0.8011535 0.8011535 0.8011535 0.8011535 0.8011535, 0.8011535 0.8011535 0.8011535 0.8011535 0.8011535 0.8011535, 0.8011535 0.8011535 0.8011535 0.8011535 0.8011535 0.8011535, 0.8011535 0.8011535 0.8011535 0.8011535 0.8011535 0.8011535, 0.8011535 0.8011535 0.8011535 0.8011535 0.8011535 0.8011535, 0.8011535 0.8011535 0.8011535 0.8011535 0.8011535 0.8011535, 0.8011535 0.8011535 0.8011535 0.8011535 0.8011535 0.8011535, 0.8011535 0.8011535 0.8011535 0.8011535 0.8011535 0.8011535, 0.8011535 0.8011535 0.8011535 0.8011535 0.8011535 0.8011535, 0.8011535 0.8011535 0.8011535 0.8011535 0.8011535 0.8011535, 0.8011535 0.8011535 0.8011535 0.8011535 0.8011535 ]]
The value does not update from one time node to the next. Could anyone help me solve this issue?
Thank you in advance!
New contributor
Shanmu Jin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.