Skip to content

Commit

Permalink
wave2d: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
georgebisbas committed Aug 3, 2023
1 parent 625e976 commit b73489a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 36 deletions.
52 changes: 21 additions & 31 deletions fast/wave2d.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Based on the implementation of the Devito acoustic example implementation
# Not using Devito's source injection abstraction
import sys

import numpy as np

from devito import (TimeFunction, Eq, Operator, solve, norm,
Expand Down Expand Up @@ -97,21 +96,19 @@ def plot_2dfunc(u):
u = TimeFunction(name="u", grid=model.grid, time_order=to, space_order=so)
# Another one to clone data
u2 = TimeFunction(name="u", grid=model.grid, time_order=to, space_order=so)
ub = TimeFunction(name="ub", grid=model.grid, time_order=to, space_order=so)

# We can now write the PDE
# pde = model.m * u.dt2 - u.laplace + model.damp * u.dt
# import pdb;pdb.set_trace()
pde = u.dt2 - u.laplace

# The PDE representation is as on paper
# pde

stencil = Eq(u.forward, solve(pde, u.forward))
# stencil

# Finally we define the source injection and receiver read function to generate
# the corresponding code
print(time_range)
# print(time_range)

print("Init norm:", np.linalg.norm(u.data[:]))
src_term = src.inject(field=u.forward, expr=src * dt**2 / model.m)
Expand All @@ -124,11 +121,10 @@ def plot_2dfunc(u):
if args.plot:
plot_2dfunc(u)

print("Init Devito linalg norm 0 :", np.linalg.norm(u.data[0]))
print("Init Devito linalg norm 1 :", np.linalg.norm(u.data[1]))
print("Init Devito linalg norm 2 :", np.linalg.norm(u.data[2]))

print("Norm of initial data:", norm(u))
#print("Init Devito linalg norm 0 :", np.linalg.norm(u.data[0]))
#print("Init Devito linalg norm 1 :", np.linalg.norm(u.data[1]))
#print("Init Devito linalg norm 2 :", np.linalg.norm(u.data[2]))
# print("Norm of initial data:", norm(u))

configuration['mpi'] = 0
u2.data[:] = u.data[:]
Expand All @@ -138,14 +134,14 @@ def plot_2dfunc(u):
op1 = Operator([stencil], name='DevitoOperator')
op1.apply(time=time_range.num-1, dt=model.critical_dt)

if len(shape) == 2:
if args.plot:
plot_3dfunc(u)
configuration['mpi'] = 0
ub.data[:] = u.data[:]
configuration['mpi'] = 'basic'

print("After Operator 1: Devito norm:", norm(u))
print("Devito linalg norm 0:", np.linalg.norm(u.data[0]))
print("Devito linalg norm 1:", np.linalg.norm(u.data[1]))
print("Devito linalg norm 2:", np.linalg.norm(u.data[2]))
#print("After Operator 1: Devito norm:", norm(u))
#print("Devito linalg norm 0:", np.linalg.norm(u.data[0]))
#print("Devito linalg norm 1:", np.linalg.norm(u.data[1]))
#print("Devito linalg norm 2:", np.linalg.norm(u.data[2]))

# import pdb;pdb.set_trace()

Expand All @@ -157,21 +153,15 @@ def plot_2dfunc(u):
#v[:, ..., :] = 1


print("Reinitialise data: Devito norm:", norm(u))
print("Init XDSL linalg norm:", np.linalg.norm(u.data[0]))
print("Init XDSL linalg norm:", np.linalg.norm(u.data[1]))
print("Init XDSL linalg norm:", np.linalg.norm(u.data[2]))
#print("Reinitialise data: Devito norm:", norm(u))
#print("Init XDSL linalg norm:", np.linalg.norm(u.data[0]))
#print("Init XDSL linalg norm:", np.linalg.norm(u.data[1]))
#print("Init XDSL linalg norm:", np.linalg.norm(u.data[2]))

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

xdsl_output = u.copy()
print("XDSL norm:", norm(u))
print(f"xdsl output norm: {norm(xdsl_output)}")

print("XDSL output linalg norm:", np.linalg.norm(u.data[0]))
print("XDSL output linalg norm:", np.linalg.norm(u.data[1]))
print("XDSL output linalg norm:", np.linalg.norm(u.data[2]))


print("XDSL output norm 0:", np.linalg.norm(u.data[0]), "vs:", np.linalg.norm(ub.data[0]))
print("XDSL output norm 1:", np.linalg.norm(u.data[1]), "vs:", np.linalg.norm(ub.data[1]))
print("XDSL output norm 2:", np.linalg.norm(u.data[2]), "vs:", np.linalg.norm(ub.data[2]))
5 changes: 0 additions & 5 deletions fast/wave3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,6 @@ def plot_3dfunc(u):

stencil = Eq(u.forward, solve(pde, u.forward))

# Finally we define the source injection and receiver read function to generate
# the corresponding code
# print(time_range)

# print("Init norm:", np.linalg.norm(u.data[:]))
src_term = src.inject(field=u.forward, expr=src * dt**2 / model.m)
op0 = Operator([stencil] + src_term, subs=model.spacing_map, name='SourceDevitoOperator')
# Run with source and plot
Expand Down

0 comments on commit b73489a

Please sign in to comment.