From b73489a48caed6275e085b87b952a22558463b21 Mon Sep 17 00:00:00 2001 From: George Bisbas Date: Thu, 3 Aug 2023 12:03:14 +0300 Subject: [PATCH] wave2d: cleanup --- fast/wave2d.py | 52 ++++++++++++++++++++------------------------------ fast/wave3d.py | 5 ----- 2 files changed, 21 insertions(+), 36 deletions(-) diff --git a/fast/wave2d.py b/fast/wave2d.py index 9fb0758f9b..40bfb41020 100644 --- a/fast/wave2d.py +++ b/fast/wave2d.py @@ -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, @@ -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) @@ -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[:] @@ -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() @@ -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])) diff --git a/fast/wave3d.py b/fast/wave3d.py index d094a0982b..d7db2ebeba 100644 --- a/fast/wave3d.py +++ b/fast/wave3d.py @@ -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