Пример #1
0
# 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):
        return on_boundary and (x[1] < Y)


Wave = AcousticWave({
    'V': V,
    'Vm': Vl
}, {
    'print': False,
    'lumpM': True,
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)')
    a_target_fn = dl.interpolate(a_target, Vm)

    checkdt(Dt, 1. / Nxy, r, np.sqrt(2.0), False)

    # observation operator:
Пример #3
0
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)
Pt = PointSources(Vex, [[.5, .5]])
mydelta = Pt[0].array()


def mysrc(tt):
    return Ricker(tt) * mydelta


Waveex = AcousticWave({'V': Vex, 'Vm': Vl})
Waveex.timestepper = 'backward'
Waveex.lump = True
Waveex.update({'a':1.0, 'b':1.0, 't0':0.0, 'tf':tf, 'Dt':Dt,\
'u0init':dl.Function(Vex), 'utinit':dl.Function(Vex)})
Waveex.ftime = mysrc
sol, _ = Waveex.solve()
Waveex.exact = dl.Function(Vex)
Пример #4
0
NOISE = True

Nxy, Dt, fpeak, t0, t1, t2, tf = loadparameters(False)

# Define PDE:
h = 1./Nxy
# dist is in [km]
X, Y = 1, 1
mesh = dl.UnitSquareMesh(Nxy, Nxy)
mpicomm = mesh.mpi_comm()
mpirank = MPI.rank(mpicomm)
Vl = dl.FunctionSpace(mesh, 'Lagrange', 1)
Ricker = RickerWavelet(fpeak, 1e-6)
r = 2   # polynomial degree for state and adj
V = dl.FunctionSpace(mesh, 'Lagrange', r)
Pt = PointSources(V, [[0.5*X,Y]])
srcv = dl.Function(V).vector()
# Boundary conditions:
class ABCdom(dl.SubDomain):
    def inside(self, x, on_boundary):
        return on_boundary and (x[1] < Y)
# Computation:
Wave = AcousticWave({'V':V, 'Vm':Vl}, 
{'print':False, 'lumpM':True, 'timestepper':'backward'})
#Wave.set_abc(mesh, ABCdom(), lumpD=False)
#
at, bt,_,_,_ = targetmediumparameters(Vl, X)
a0, b0,_,_,_ = initmediumparameters(Vl, X)
#
Wave.update({'b':bt, 'a':at, 't0':0.0, 'tf':tf, 'Dt':Dt,\
'u0init':dl.Function(V), 'utinit':dl.Function(V)})
mesh = UnitSquareMesh(Nxy, Nxy)
h = 1. / Nxy
Vl = FunctionSpace(mesh, 'Lagrange', 1)
r = 2
checkdt(Dt, h, r, 2.0, False)
# Source term:
Ricker = RickerWavelet(fpeak, 1e-10)

# Boundary conditions:
#class AllFour(SubDomain):
#    def inside(self, x, on_boundary):
#        return on_boundary

V = FunctionSpace(mesh, 'Lagrange', r)
Pt = PointSources(V, [[.5, 1.]])
mydelta = Pt[0]
src = Function(V)
srcv = src.vector()


def mysrc(tt):
    srcv.zero()
    srcv.axpy(Ricker(tt), mydelta)
    return srcv


# Computation:
if myrank == 0: print '\n\th = {}, Dt = {}'.format(h, Dt)
Wave = AcousticWave({'V': V, 'Vm': Vl})
#Wave.verbose = True
Пример #6
0
myplot = PlotFenics(mpicomm, filename)

# Source term:
Ricker = RickerWavelet(fpeak, 1e-6, 1.0)


# Boundary conditions:
class ABCdom(dl.SubDomain):
    def inside(self, x, on_boundary):
        return on_boundary and (x[1] < Y)


r = 2
V = dl.FunctionSpace(mesh, 'Lagrange', r)
y_src = 1.0  # 0.1->transmission, 1.0->reflection
Pt = PointSources(V, [[0.5 * X, y_src]])
mydelta = Pt[0]


def mysrc(tt):
    return mydelta * Ricker(tt)


# Computation:
if mpirank == 0: print '\n\th = {}, Dt = {}'.format(h, Dt)
Wave = AcousticWave({
    'V': V,
    'Vm': Vl
}, {
    'print': (not mpirank),
    'lumpM': True,
Пример #7
0
def u0_boundary(x, on_boundary):
    return on_boundary


u0 = dl.Constant("0.0")
bc = dl.DirichletBC(V, u0, u0_boundary)
#bc = None

#mtrue_exp = dl.Expression('2 + 7*(pow(pow(x[0] - 0.5,2) + pow(x[1] - 0.5,2),0.5) > 0.25)')
mtrue_exp = dl.Expression('1.0')
mtrue = dl.interpolate(mtrue_exp, Vme)  # target medium
mtrueVm = dl.interpolate(mtrue_exp, Vm)  # target medium
minit_exp = dl.Expression('1.0')
minit = dl.interpolate(minit_exp, Vm)
#f = [dl.Expression("1.0")]   # source term
f = PointSources(V, [[0.5, 0.5]]).PtSrc

if PLOT:
    filename, ext = splitext(sys.argv[0])
    if mpirank == 0 and isdir(filename + '/'):
        rmtree(filename + '/')
    MPI.barrier(mpicomm)
    myplot = PlotFenics(filename)
    MPI.barrier(mpicomm)
    myplot.set_varname('m_target')
    myplot.plot_vtk(mtrue)
    myplot.set_varname('m_targetVm')
    myplot.plot_vtk(mtrueVm)
else:
    myplot = None
from dolfin import UnitSquareMesh, FunctionSpace, TestFunction, TrialFunction,\
Constant, Expression, assemble, dx, Point, PointSource, plot, interactive,\
inner, nabla_grad, Function, solve, MPI, mpi_comm_world
import numpy as np

from fenicstools.sourceterms import PointSources

mycomm = mpi_comm_world()
myrank = MPI.rank(mycomm)

mesh = UnitSquareMesh(2, 2)
V = FunctionSpace(mesh, 'Lagrange', 1)
trial = TrialFunction(V)
test = TestFunction(V)
f0 = Constant('0')
L0 = f0 * test * dx
b = assemble(L0)
P = Point(0.1, 0.5)
delta = PointSource(V, P, 1.0)
delta.apply(b)

myown = PointSources(V, [[0.1, 0.5], [0.9, 0.5]])

print 'p{}: max(PointSource)={}, max(PointSources[0])={}, max(PointSources[1])={}'.format(\
myrank, max(abs(b.array())), max(abs(myown[0].array())), max(abs(myown[1].array())))