示例#1
0
from fenicstools.miscfenics import createMixedFS
from fenicstools.plotfenics import PlotFenics
from fenicstools.jointregularization import crossgradient, normalizedcrossgradient
from fenicstools.linalg.miscroutines import compute_eigfenics

N = 40
mesh = dl.UnitSquareMesh(N,N)
V = dl.FunctionSpace(mesh, 'CG', 1)
mpirank = dl.MPI.rank(mesh.mpi_comm())

VV = createMixedFS(V, V)
cg = crossgradient(VV)
ncg = normalizedcrossgradient(VV)

outdir = 'Output-CGvsNCG-' + str(N) + 'x' + str(N) + '/'
plotfenics = PlotFenics(mesh.mpi_comm(), outdir)

a1true = [
dl.interpolate(dl.Expression('log(10 - ' + 
'(x[0]>0.25)*(x[0]<0.75)*(x[1]>0.25)*(x[1]<0.75) * 8 )'), V),
dl.interpolate(dl.Expression('log(10 - ' + 
'(x[0]>0.25)*(x[0]<0.75)*(x[1]>0.25)*(x[1]<0.75) * (' + 
'4*(x[0]<=0.5) + 8*(x[0]>0.5) ))'), V),
dl.interpolate(dl.Expression('log(10 - ' + 
'(x[0]>0.25)*(x[0]<0.75)*(x[1]>0.25)*(x[1]<0.75) * (' + 
'4*(x[0]<=0.5) + 8*(x[0]>0.5) ))'), V),
dl.interpolate(dl.Expression('log(10 - ' + 
'(x[0]>0.25)*(x[0]<0.75)*(x[1]>0.25)*(x[1]<0.75) * (' + 
'4*(x[0]<=0.5) + 8*(x[0]>0.5) ))'), V)]
a2true = [
dl.interpolate(dl.Expression('log(10 - ' + 
示例#2
0
        print 'MAP: min(a)={}, max(a)={}'.format(mina, maxa)
        print 'med_misfit={:.4e}, err={:.1f}%'.format(norm_mmfa, erra)

        print '\ntarget: min(b)={}, max(b)={}'.format(minbt, maxbt)
        print 'init: min(b)={}, max(b)={}'.format(minb0, maxb0)
        print 'MAP: min(b)={}, max(b)={}'.format(minb, maxb)
        print 'med_misfit={:.4e}, err={:.1f}%'.format(norm_mmfb, errb)

        print '\ntarget: min(c)={}, max(c)={}'.format(minct, maxct)
        print 'MAP: min(c)={}, max(c)={}'.format(minc, maxc)
        print 'med_misfit={:.4e}, err={:.1f}%'.format(norm_mmfc, errc)

        # WARNING: only makes sense if mpicomm_local == mpi_comm_self
        # otherwise, can't be restricted to PRINT processor only
        plotfolder = PARAM + '_k' + str(k) + '_e' + str(eps)
        myplot = PlotFenics(Outputfolder='output_transmission/plots/' + plotfolder, \
        comm = mesh.mpi_comm())
        waveobj._plotab(
            myplot,
            '-map_' + PARAM + '-VTV_' + amg + '_k' + str(k) + '_e' + str(eps))

        myplot.set_varname('c-map_' + PARAM + '-VTV_' + amg + '_k' + str(k) +
                           '_e' + str(eps))
        myplot.plot_vtk(cf)
    """
    # Test gradient and Hessian after several steps of Newton method
    waveobj.GN = False
    waveobj.regularization = ZeroRegularization(Vl)
    if ALL and (PARAM == 'a' or PARAM == 'b') and PRINT:
        print '*** Warning: Single inversion but changing both parameters'
    MPa = [
    dl.Constant('1.0'), 
示例#3
0
"""
Plot selected medium parameters
"""
import sys
from os.path import splitext, isdir
from shutil import rmtree
import dolfin as dl
from dolfin import MPI
from fenicstools.plotfenics import PlotFenics
from mediumparameters1 import \
targetmediumparameters, initmediumparameters, loadparameters

LARGE = True
Nxy, Dt, fpeak, _, _, _, tf = loadparameters(LARGE)

X, Y = 1, 1
mesh = dl.UnitSquareMesh(Nxy, Nxy)
Vl = dl.FunctionSpace(mesh, 'Lagrange', 1)

mpicomm = mesh.mpi_comm()
mpirank = MPI.rank(mpicomm)
filename, ext = splitext(sys.argv[0])
if mpirank == 0:
    if isdir(filename + '/'): rmtree(filename + '/')
MPI.barrier(mpicomm)
myplot = PlotFenics(mpicomm, filename)

at, bt, c, lam, rho = targetmediumparameters(Vl, X, myplot)
a0, b0, _, _, _ = initmediumparameters(Vl, X, myplot)
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)
Pt = PointSources(Vex, [[.5, .5]])
mydelta = Pt[0].array()


def mysrc(tt):
    return Ricker(tt) * mydelta
    # define pde operator:
    wavepde = AcousticWave({'V': V, 'Vm': Vm})
    wavepde.timestepper = 'backward'
    wavepde.lump = True
    wavepde.update({'a':a_target_fn, 'b':b_target_fn, \
    't0':t0, 'tf':tf, 'Dt':Dt, 'u0init':dl.Function(V), 'utinit':dl.Function(V)})

    # parameters
    Vm = wavepde.Vm
    V = wavepde.V
    lenobspts = obsop.PtwiseObs.nbPts

    # set up plots:
    filename, ext = splitext(sys.argv[0])
    if isdir(filename + '/'): rmtree(filename + '/')
    myplot = PlotFenics(filename + str(Nxy))
    myplot.set_varname('a_target')
    myplot.plot_vtk(a_target_fn)

    # define objective function:
    regul = LaplacianPrior({
        'Vm': Vm,
        'gamma': 5e-4,
        'beta': 5e-4,
        'm0': a_target_fn
    })
    waveobj = ObjectiveAcoustic(wavepde, mysrc, 'a', regul)
    waveobj.obsop = obsop

    # noisy data
    print 'generate noisy data'
示例#6
0
import dolfin as dl
from fenicstools.plotfenics import PlotFenics
from fenicstools.miscfenics import setfct

mesh = dl.UnitSquareMesh(40, 40)
V = dl.FunctionSpace(mesh, 'Lagrange', 1)
myplot = PlotFenics()
myplot.set_varname('u')
u = dl.Function(V)
for ii in range(10):
    setfct(u, dl.interpolate(dl.Constant(ii), V))
    myplot.plot_vtk(u, ii)
myplot.gather_vtkplots()
        print 'MAP: min(a)={}, max(a)={}'.format(mina, maxa)
        print 'med_misfit={:.4e}, err={:.1f}%'.format(norm_mmfa, erra)

        print '\ntarget: min(b)={}, max(b)={}'.format(minbt, maxbt)
        print 'init: min(b)={}, max(b)={}'.format(minb0, maxb0)
        print 'MAP: min(b)={}, max(b)={}'.format(minb, maxb)
        print 'med_misfit={:.4e}, err={:.1f}%'.format(norm_mmfb, errb)

        print '\ntarget: min(c)={}, max(c)={}'.format(minct, maxct)
        print 'MAP: min(c)={}, max(c)={}'.format(minc, maxc)
        print 'med_misfit={:.4e}, err={:.1f}%'.format(norm_mmfc, errc)

        # WARNING: only makes sense if mpicomm_local == mpi_comm_self
        # otherwise, can't be restricted to PRINT processor only
        plotfolder = PARAM + '_k' + str(k) + '_e' + str(eps)
        myplot = PlotFenics(Outputfolder='output/plots/' + plotfolder, \
        comm = mesh.mpi_comm())
        waveobj._plotab(myplot,
                        '-map_' + PARAM + '_k' + str(k) + '_e' + str(eps))

        myplot.set_varname('c-map_' + PARAM + '_k' + str(k) + '_e' + str(eps))
        myplot.plot_vtk(cf)
    """
    # Test gradient and Hessian after several steps of Newton method
    waveobj.GN = False
    waveobj.regularization = ZeroRegularization(Vl)
    if ALL and (PARAM == 'a' or PARAM == 'b') and PRINT:
        print '*** Warning: Single inversion but changing both parameters'
    MPa = [
    dl.Constant('1.0'), 
    dl. Expression('sin(pi*x[0])*sin(pi*x[1])', degree=10),
    dl.Expression('x[0]', degree=10), dl.Expression('x[1]', degree=10), 
示例#8
0
# mesh
if mpirank == 0: print 'meshing'
mesh = dl.UnitSquareMesh(Nxy, Nxy)
Vm = dl.FunctionSpace(mesh, 'Lagrange', 1)
V = dl.FunctionSpace(mesh, 'Lagrange', 2)

# 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)

# set up plots:
filename, ext = splitext(sys.argv[0])
myplot = PlotFenics(outputdirectory + filename + str(freq))
MPI.barrier(mpicomm)
if PLOT:
    myplot.set_varname('b_target')
    myplot.plot_vtk(b_target_fn)
else:
    myplot = None

# observations:
obspts = [[0.0, ii/10.] for ii in range(1,10)] + \
[[1.0, ii/10.] for ii in range(1,10)] + \
[[ii/10., 0.0] for ii in range(1,10)]
#obspts = [[0.9, 0.1]]

# define pde operator:
if mpirank == 0: print 'define wave pde'