nbtest = 5 ############## Nxy, Dt, fpeak, t0, t1, t2, tf = loadparameters(TRANSMISSION) h = 1. / Nxy if PRINT: print 'Nxy={} (h={}), Dt={}, fpeak={}, t0,t1,t2,tf={}'.format(\ Nxy, h, Dt, fpeak, [t0,t1,t2,tf]) # Define PDE: # dist is in [km] mesh = dl.UnitSquareMesh(mpicomm_local, Nxy, Nxy) X, Y = 1, 1 # shall not be changed Vl = dl.FunctionSpace(mesh, 'Lagrange', 1) # Source term: Ricker = RickerWavelet(fpeak, 1e-6) r = 2 # polynomial degree for state and adj V = dl.FunctionSpace(mesh, 'Lagrange', r) if TRANSMISSION: y_src = 0.1 else: y_src = 1.0 #Pt = PointSources(V, [[0.1,y_src], [0.25,y_src], [0.4,y_src],\ #[0.6,y_src], [0.75,y_src], [0.9,y_src]]) Pt = PointSources(V, [[0.1, y_src], [0.4, y_src], [0.6, y_src], [0.9, y_src]]) srcv = dl.Function(V).vector() # Boundary conditions: class ABCdom(dl.SubDomain): def inside(self, x, on_boundary):
import sys from os.path import splitext, isdir from shutil import rmtree import dolfin as dl from fenicstools.sourceterms import PointSources, RickerWavelet from fenicstools.acousticwave import AcousticWave from fenicstools.plotfenics import PlotFenics from fenicstools.miscfenics import setfct r = 2 # polynomial order c = 1.0 # wave velocity freq = 4.0 # Hz maxfreq = 10.0 cmin = c / maxfreq Ricker = RickerWavelet(freq, 1e-10) Dt = 1e-4 tf = 0.5 filename, ext = splitext(sys.argv[0]) if isdir(filename + '/'): rmtree(filename + '/') myplot = PlotFenics(filename) boolplot = 100 print 'Compute most accurate solution as reference' qq = 20 N = int(qq / cmin) h = 1. / N mesh = dl.UnitSquareMesh(N, N) Vl = dl.FunctionSpace(mesh, 'Lagrange', 1) Vex = dl.FunctionSpace(mesh, 'Lagrange', r)
from fenicstools.acousticwave import AcousticWave from fenicstools.sourceterms import PointSources, RickerWavelet from fenicstools.observationoperator import TimeObsPtwise NNxy = [20, 60] for Nxy in NNxy: mesh = dl.UnitSquareMesh(Nxy, Nxy) Vm = dl.FunctionSpace(mesh, 'Lagrange', 1) r = 2 V = dl.FunctionSpace(mesh, 'Lagrange', r) Dt = 5.0e-4 t0, t1, t2, tf = 0.0, 1.0, 5.0, 6.0 # source: Ricker = RickerWavelet(0.5, 1e-10) #srcloc = [[0.5,1.0]] srcloc = [[ii / 10., 1.0] for ii in range(1, 10)] + [[ii / 10., 0.0] for ii in range(1, 10)] Pt = PointSources(V, srcloc) src = dl.Function(V) srcv = src.vector() mysrc = [Ricker, Pt, srcv] # target medium: b_target = dl.Expression(\ '1.0 + 1.0*(x[0]<=0.7)*(x[0]>=0.3)*(x[1]<=0.7)*(x[1]>=0.3)') b_target_fn = dl.interpolate(b_target, Vm) a_target = dl.Expression(\ '1.0 + 0.4*(x[0]<=0.7)*(x[0]>=0.3)*(x[1]<=0.7)*(x[1]>=0.3)')
import numpy as np import matplotlib.pyplot as plt from fenicstools.sourceterms import RickerWavelet #cut_off = 1e-10 cut_off = 1e-6 Rnb = 1 R1 = RickerWavelet(0.4, cut_off) T = 10. fig = R1.plot(np.linspace(0.0, T, 1000), np.linspace(-2.5, 2.5, 1000)) fig.savefig('Plots/Ricker' + str(Rnb) + '.eps') Rnb += 1 print R1(0.0), R1(T) R2 = RickerWavelet(1.0, cut_off) T = 5.0 fig = R2.plot(np.linspace(0.0, T, 1000), np.linspace(-5.0, 5.0, 1000)) fig.savefig('Plots/Ricker' + str(Rnb) + '.eps') Rnb += 1 print R2(0.0), R2(T) R2 = RickerWavelet(2.0, cut_off) T = 2.0 fig = R2.plot(np.linspace(0.0, T, 1000), np.linspace(-10.0, 10.0, 1000)) fig.savefig('Plots/Ricker' + str(Rnb) + '.eps') Rnb += 1 print R2(0.0), R2(T) R2 = RickerWavelet(4.0, cut_off)
import numpy as np import matplotlib.pyplot as plt from fenicstools.sourceterms import RickerWavelet # cut_off = 1e-10 cut_off = 1e-6 Rnb = 1 R1 = RickerWavelet(0.4, cut_off) T = 10.0 fig = R1.plot(np.linspace(0.0, T, 1000), np.linspace(-2.5, 2.5, 1000)) fig.savefig("Plots/Ricker" + str(Rnb) + ".eps") Rnb += 1 print R1(0.0), R1(T) R2 = RickerWavelet(1.0, cut_off) T = 5.0 fig = R2.plot(np.linspace(0.0, T, 1000), np.linspace(-5.0, 5.0, 1000)) fig.savefig("Plots/Ricker" + str(Rnb) + ".eps") Rnb += 1 print R2(0.0), R2(T) R2 = RickerWavelet(2.0, cut_off) T = 2.0 fig = R2.plot(np.linspace(0.0, T, 1000), np.linspace(-10.0, 10.0, 1000)) fig.savefig("Plots/Ricker" + str(Rnb) + ".eps") Rnb += 1 print R2(0.0), R2(T) R2 = RickerWavelet(4.0, cut_off)
mpirank = MPI.rank(mpicomm) NNxy = [100] for Nxy in NNxy: if mpirank == 0: print 'meshing' mesh = dl.UnitSquareMesh(Nxy, Nxy) Vm = dl.FunctionSpace(mesh, 'Lagrange', 1) r = 2 V = dl.FunctionSpace(mesh, 'Lagrange', r) Dt = 5.0e-4 t0, t1, t2, tf = 0.0, 0.02, 0.98, 1.0 # source: if mpirank == 0: print 'sources' Ricker = RickerWavelet(6.0, 1e-10) #srcloc = [[0.5,1.0]] #srcloc = [[ii/10., 1.0] for ii in range(1,10)] + [[ii/10., 0.0] for ii in range(1,10)] srcloc = [[ii / 10., 1.0] for ii in range(3, 8, 2)] Pt = PointSources(V, srcloc) src = dl.Function(V) srcv = src.vector() mysrc = [Ricker, Pt, srcv] # target medium: b_target = dl.Expression(\ '1.0 + 1.0*(x[0]<=0.7)*(x[0]>=0.3)*(x[1]<=0.7)*(x[1]>=0.3)') b_target_fn = dl.interpolate(b_target, Vm) a_target = dl.Expression('1.0') a_target_fn = dl.interpolate(a_target, Vm)