Skip to content

Commit

Permalink
bench: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
georgebisbas committed Jul 19, 2023
1 parent 446b397 commit 416f1ec
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 46 deletions.
41 changes: 11 additions & 30 deletions fast/diffusion_2D_wBCs.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,49 +42,30 @@
u = TimeFunction(name='u', grid=grid, space_order=so)

# Reset our data field and ICs
# u.data[:, :, :] = 0.1
init_hat(field=u.data[0], dx=dx, dy=dy, value=1.)


# u.data[0, :, int(ny/2)] = 2

a = Constant(name='a')
# Create an equation with second-order derivatives
eq = Eq(u.dt, a * u.laplace, subdomain=grid.interior)
# eq = Eq(u.dt, a * u.laplace, subdomain=grid.interior)
eq = Eq(u.dt, a * u.laplace)
stencil = solve(eq, u.forward)
eq_stencil = Eq(u.forward, stencil)

# Create boundary condition expressions
x, y = grid.dimensions
t = grid.stepping_dim

# Add boundary conditions
# bc = [Eq(u[t+1, x, y, 0], 2.)] # bottom
# bc += [Eq(u[t+1, x, y, nz-1], 2.)] # top
# bc += [Eq(u[t+1, 0, y, z], 2.)] # left
# bc += [Eq(u[t+1, nx-1, y, z], 2.)] # right

# bc += [Eq(u[t+1, x, 0, z], 2.)] # front
# bc += [Eq(u[t+1, x, ny-1, z], 2.)] # back

print(eq_stencil)

# Create an operator that updates the forward stencil point
# plus adding boundary conditions
# op = Operator([eq_stencil] + bc, subdomain=grid.interior)

# No BCs
# op = XDSLOperator([eq_stencil])
initdata = u.data[:]
op = Operator([eq_stencil])
# print(op.ccode)
# dt = 0.00002
# import pdb;pdb.set_trace()
# Apply the operator for a number of timesteps
print(dt)
op.apply(time=nt, dt=dt, a=nu)

print("Field norm is:", norm(u))
print("Devito Field norm is:", norm(u))

plot_image(u.data[0], cmap="seismic")
# plot_image(u.data[0], cmap="seismic")

# Reset data and run XDSLOperator
init_hat(field=u.data[0], dx=dx, dy=dy, value=1.)
xdslop = XDSLOperator([eq_stencil])
xdslop.apply(time=nt, dt=dt, a=nu)

# import pdb;pdb.set_trace()
print("XDSL Field norm is:", norm(u))
14 changes: 3 additions & 11 deletions fast/diffusion_3D_wBCs.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,15 @@ def plot_3dfunc(u):
x, y, z = grid.dimensions
t = grid.stepping_dim

# Add boundary conditions
# bc = [Eq(u[t+1, x, y, 0], 2.)] # bottom
# bc += [Eq(u[t+1, x, y, nz-1], 2.)] # top
# bc += [Eq(u[t+1, 0, y, z], 2.)] # left
# bc += [Eq(u[t+1, nx-1, y, z], 2.)] # right

# bc += [Eq(u[t+1, x, 0, z], 2.)] # front
# bc += [Eq(u[t+1, x, ny-1, z], 2.)] # back

print(eq_stencil)

# Create an operator that updates the forward stencil point
# plus adding boundary conditions
# op = Operator([eq_stencil] + bc, subdomain=grid.interior)

# No BCs
# op = XDSLOperator([eq_stencil])
op = Operator([eq_stencil])
op = XDSLOperator([eq_stencil])
# op = Operator([eq_stencil])
# print(op.ccode)

# Apply the operator for a number of timesteps
Expand All @@ -100,4 +91,5 @@ def plot_3dfunc(u):
plot_3dfunc(u)

print("Field norm is:", norm(u))

# import pdb;pdb.set_trace()
14 changes: 9 additions & 5 deletions fast/nd_nwave_devito_nodamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,22 @@ def plot_3dfunc(u):
if args.plot:
plot_3dfunc(u)

# Run more with no sources now (Not supported in xdsl)
# op = XDSLOperator([stencil])

# op.apply(time=time_range.num-1, dt=model.critical_dt)
initdata = u.data[:]

# Run more with no sources now (Not supported in xdsl)
xdslop = XDSLOperator([stencil])
xdslop.apply(time=time_range.num-1, dt=model.critical_dt)

if len(shape) == 3:
if args.plot:
plot_3dfunc(u)

# print(norm(u))
print(norm(u))


u.data[:] = initdata

# todo edit data

# Run more with no sources now (Not supported in xdsl)
xdslop = XDSLOperator([stencil])
Expand Down
15 changes: 15 additions & 0 deletions fast/nd_wave_devito_nodamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ def plot_3dfunc(u):
if args.plot:
plot_3dfunc(u)

init_data = u.data[:]

# Run more with no sources now (Not supported in xdsl)
op = Operator([stencil])
op.apply(time=time_range.num-1, dt=model.critical_dt)
Expand All @@ -122,3 +124,16 @@ def plot_3dfunc(u):
plot_3dfunc(u)

print(norm(u))


u.data[:] = init_data

# Run more with no sources now (Not supported in xdsl)
xdslop = XDSLOperator([stencil])
xdslop.apply(time=time_range.num-1, dt=model.critical_dt)

if len(shape) == 3:
if args.plot:
plot_3dfunc(u)

print(norm(u))

0 comments on commit 416f1ec

Please sign in to comment.