예제 #1
0
def calcSeismics(meshIn, vP):
    """Do seismic computations."""
    meshSeis = meshIn.createH2()
    meshSeis = mt.appendTriangleBoundary(meshSeis,
                                         xbound=25,
                                         ybound=22.0,
                                         marker=1,
                                         quality=32.0,
                                         area=0.3,
                                         smooth=True,
                                         markerBoundary=1,
                                         isSubSurface=False,
                                         verbose=False)
    print(meshSeis)
    meshSeis = meshSeis.createH2()
    meshSeis = meshSeis.createH2()
    # meshSeis = meshSeis.createP2()

    meshSeis.smooth(1, 1, 1, 4)
    vP = pg.interpolate(meshIn, vP, meshSeis.cellCenters())

    mesh = meshSeis
    vP = pg.solver.fillEmptyToCellArray(mesh, vP)

    print(mesh)
    # ax, cbar = pg.show(mesh, data=vP)
    # pg.show(mesh, axes=ax)

    geophPointsX = np.arange(-19, 19.1, 1)
    geophPoints = np.vstack((geophPointsX, np.zeros(len(geophPointsX)))).T
    sourcePos = geophPoints[4]

    c = mesh.findCell(sourcePos)
    h1 = pg.findBoundary(c.boundaryNodes(0)).size()
    h2 = pg.findBoundary(c.boundaryNodes(1)).size()
    h3 = pg.findBoundary(c.boundaryNodes(2)).size()
    print([h1, h2, h3])
    h = pg.math.median([h1, h2, h3])

    # h = pg.math.median(mesh.boundarySizes())
    f0scale = 0.25
    cfl = 0.5
    dt = cfl * h / max(vP)
    print("Courant-Friedrich-Lewy number:", cfl)

    tmax = 40. / min(vP)
    times = np.arange(0.0, tmax, dt)

    solutionName = createCacheName('seis', mesh, times) + "cfl-" + str(cfl)
    try:
        # u = pg.load(solutionName + '.bmat')
        uI = pg.load(solutionName + 'I.bmat')
    except Exception as e:
        print(e)
        f0 = f0scale * 1. / dt
        print("h:", round(h, 2), "dt:", round(dt, 5), "1/dt:",
              round(1 / dt, 1), "f0", round(f0, 2), "Wavelength: ",
              round(max(vP) / f0, 2), " m")

        uSource = ricker(times, f0, t0=1. / f0)

        plt.figure()
        plt.plot(times, uSource, '-*')
        plt.show(block=0)
        plt.pause(0.01)
        u = solvePressureWave(mesh,
                              vP,
                              times,
                              sourcePos=sourcePos,
                              uSource=uSource,
                              verbose=10)

        u.save(solutionName)
        uI = pg.Matrix()
        print("interpolate node to cell data ... ")
        pg.interpolate(mesh, u, mesh.cellCenters(), uI)
        print("... done")
        uI.save(solutionName + 'I')

#    nodes = [mesh.findNearestNode(p) for p in geophPoints]
#    fig = plt.figure()
#    axs = fig.add_subplot(1,1,1)
#    drawSeismogramm(axs, mesh, u, nodes, dt, i=None)
#    plt.show()

    dpi = 92
    scale = 1
    fig = plt.figure(facecolor='white',
                     figsize=(scale * 800 / dpi, scale * 490 / dpi),
                     dpi=dpi)
    ax = fig.add_subplot(1, 1, 1)
    gci = pg.viewer.mpl.drawModel(ax,
                                  mesh,
                                  data=uI[0],
                                  cMin=-1,
                                  cMax=1,
                                  cmap='bwr')
    pg.viewer.mpl.drawMeshBoundaries(ax, meshIn, hideMesh=1)
    ax.set_xlim((-20, 20))
    ax.set_ylim((-15, 0))
    ax.set_ylabel('Depth [m]')
    ax.set_xlabel('$x$ [m]')

    ticks = ax.yaxis.get_majorticklocs()
    tickLabels = []
    for t in ticks:
        tickLabels.append(str(int(abs(t))))

    ax.set_yticklabels(tickLabels)

    plt.tight_layout()

    #    ax, cbar = pg.show(mesh, data=vP)
    #    pg.showNow()
    #    ax = fig.add_subplot(1,1,1)

    def animate(i):
        i = i * 5
        if i > len(uI) - 1:
            return
        print("Frame:", i, "/", len(uI))
        ui = uI[i]
        ui = ui / max(pg.abs(ui))
        ui = pg.logDropTol(ui, 1e-2)
        cMax = max(pg.abs(ui))

        pg.viewer.mpl.setMappableData(gci,
                                      ui,
                                      cMin=-cMax,
                                      cMax=cMax,
                                      logScale=False)
        # plt.pause(0.001)

    anim = animation.FuncAnimation(fig,
                                   animate,
                                   frames=int(len(uI) / 5),
                                   interval=0.001,
                                   repeat=0)  # , blit=True)
    out = 'seis' + str(f0scale) + "cfl-" + str(cfl)
    anim.save(out + ".mp4",
              writer=None,
              fps=20,
              dpi=dpi,
              codec=None,
              bitrate=24 * 1024,
              extra_args=None,
              metadata=None,
              extra_anim=None,
              savefig_kwargs=None)
    try:
        print("create frames ... ")
        os.system('mkdir -p anim-' + out)
        os.system('ffmpeg -i ' + out + '.mp4 anim-' + out + '/movie%d.jpg')
    except:
        pass
예제 #2
0
def calcSeismics(meshIn, vP):
    
    meshSeis = meshIn.createH2()
    #meshSeis = meshIn
    meshSeis = appendTriangleBoundary(meshSeis, 
                                      xbound=25, ybound=22.0, marker=1,
                                      quality=32.0, area=0.3, smooth=True, 
                                      markerBoundary=1,
                                      isSubSurface=False, verbose=False)
    print(meshSeis)
    meshSeis = meshSeis.createH2()
    meshSeis = meshSeis.createH2()
    #meshSeis = meshSeis.createH2()
    #meshSeis = meshSeis.createP2()
    
    meshSeis.smooth(1, 1, 1, 4)
    vP = pg.interpolate(meshIn, vP, meshSeis.cellCenters())
    
    mesh = meshSeis
    vP = pg.solver.fillEmptyToCellArray(mesh, vP)

    print(mesh)
    #ax, cbar = pg.show(mesh, data=vP)
    #pg.show(mesh, axes=ax)
     
    geophPointsX = np.arange(-19, 19.1, 1)
    geophPoints = np.vstack((geophPointsX, np.zeros(len(geophPointsX)))).T
    sourcePos=geophPoints[4]
     
    c = mesh.findCell(sourcePos)
    h1 = pg.findBoundary(c.boundaryNodes(0)).size()
    h2 = pg.findBoundary(c.boundaryNodes(1)).size()
    h3 = pg.findBoundary(c.boundaryNodes(2)).size()
    print([h1, h2, h3])
    h = pg.median([h1, h2, h3])
    
    #h = pg.median(mesh.boundarySizes())
    f0scale = 0.25
    cfl = 0.5
    dt = cfl * h /max(vP)
    print("Courant-Friedrich-Lewy-Zahl:", cfl)
    
    tmax = 40./min(vP)
    times = np.arange(0.0, tmax, dt)
    
    solutionName = createCacheName('seis', mesh, times) + "cfl-" + str(cfl)
    try:   
        U = None
        #u = pg.load(solutionName + '.bmat')
        uI = pg.load(solutionName + 'I.bmat')
    except Exception as e:
        print(e)
        f0 = f0scale * 1./dt
        print("h:", round(h,2),
              "dt:", round(dt,5),
              "1/dt:", round(1/dt,1),
              "f0", round(f0,2),
              "Wavelength: ", round(max(vP)/f0, 2), " m")
        
        uSource = ricker(times, f0, t0=1./f0)
    
        plt.figure()
        plt.plot(times, uSource, '-*')
        plt.show(block=0)
        plt.pause(0.01)
        u = solvePressureWave(mesh, vP, times, sourcePos=sourcePos,
                            uSource=uSource, verbose=10)
        
        u.save(solutionName)
        uI = pg.RMatrix()
        print("interpolate node to cell data ... ")
        pg.interpolate(mesh, u, mesh.cellCenters(), uI)
        print("... done")
        uI.save(solutionName+'I')
    
    #nodes = [mesh.findNearestNode(p) for p in geophPoints]
    
    #fig = plt.figure()
    #axs = fig.add_subplot(1,1,1)
    #drawSeismogramm(axs, mesh, u, nodes, dt, i=None)
    #plt.show()
    
    dpi=92
    scale=1
    fig = plt.figure(facecolor='white',
                     figsize=(scale*800/dpi, scale*490/dpi), dpi=dpi)  
    ax = fig.add_subplot(1,1,1)
    gci = pg.mplviewer.drawModel(ax, mesh, data=uI[0],
                                 cMin=-1, cMax=1, cmap='bwr')
    pg.mplviewer.drawMeshBoundaries(ax, meshIn, hideMesh=1)
    ax.set_xlim((-20, 20))
    ax.set_ylim((-15, 0))
    ax.set_ylabel('Depth [m]')
    ax.set_xlabel('$x$ [m]')
        
    ticks = ax.yaxis.get_majorticklocs()
    tickLabels = []
    for t in ticks:
        tickLabels.append(str(int(abs(t))))

    ax.set_yticklabels(tickLabels)
    
    
    plt.tight_layout()
    #ax, cbar = pg.show(mesh, data=vP)
    #pg.showNow()
    #ax = fig.add_subplot(1,1,1)
    def animate(i):
        i=i*5
        if i >len(uI)-1:
            return
        print("Frame:", i, "/", len(uI))
        ui = uI[i]
        ui = ui / max(pg.abs(ui))
        ui = pg.logDropTol(ui, 1e-2)
        cMax = max(pg.abs(ui))
        
        pg.mplviewer.setMappableData(gci, 
                                    ui,
                                    cMin=-cMax, cMax=cMax,
                                    logScale=False
                                    )
        
        #plt.pause(0.001)
    
    anim = animation.FuncAnimation(fig, animate,
                                   frames=int(len(uI)/5),
                                   interval=0.001, repeat=0)#, blit=True)
    out = 'seis' + str(f0scale) + "cfl-" + str(cfl)
    anim.save(out + ".mp4", writer=None, fps=20, dpi=dpi, codec=None,
              bitrate=24*1024, extra_args=None, metadata=None,
              extra_anim=None, savefig_kwargs=None)
    try:
        print("create frames ... ")
        os.system('mkdir -p anim-' + out)
        os.system('ffmpeg -i ' + out + '.mp4 anim-' + out + '/movie%d.jpg')
    except:
        pass   
예제 #3
0
z = 2.
f0 = 1000.0 # A low wavelength of 50 Hz

velocities = pg.RVector(mesh.cellCount(), v1)

for c in mesh.cells():
    velocities[c.id()] = v1
    if c.center()[1] < -z:
        velocities[c.id()] = v2

dt = h * 0.5/max(velocities)
times = np.arange(0.0, tmax, dt)
print(mesh, "h:", h, "dt:", dt, "n_t", len(times))

uSource = ricker(f0, times, t0=1./f0)

solutionName = 'uGridBig-'+ str(dt) + '-' + str(h)

nx = len(x)
ny = len(y)
dt = times[1] - times[0]

try:
    print("load:", solutionName)
    u = pg.load(solutionName + '.bmat')
except Exception as e:
    print(e)
    u = solvePressureWave(mesh, velocities, times, sourcePos=(0.0, 0.0),
                          uSource=uSource, verbose=10)
    u.save(solutionName + '.bmat')
예제 #4
0
z = 2.
f0 = 1000.0  # A low wavelength of 50 Hz

velocities = pg.Vector(mesh.cellCount(), v1)

for c in mesh.cells():
    velocities[c.id()] = v1
    if c.center()[1] < -z:
        velocities[c.id()] = v2

dt = h * 0.5 / max(velocities)
times = np.arange(0.0, tmax, dt)
print(mesh, "h:", h, "dt:", dt, "n_t", len(times))

uSource = ricker(f0, times, t0=1. / f0)

solutionName = 'uGridBig-' + str(dt) + '-' + str(h)

nx = len(x)
ny = len(y)
dt = times[1] - times[0]

try:
    print("load:", solutionName)
    u = pg.load(solutionName + '.bmat')
except Exception as e:
    print(e)
    u = solvePressureWave(mesh,
                          velocities,
                          times,
예제 #5
0
파일: seismics.py 프로젝트: zhangwise/gimli
        t1 = swatch.duration(True)

        if verbose and (n % verbose == 0):
            print(str(n) + "/" + str(len(times)), times[n], dt, t1, min(u[n]), max(u[n]))

    plt.figure()
    plt.plot(timeIter1, label="Ass:1")
    plt.plot(timeIter2, label="Sol:1")
    plt.plot(timeIter3, label="Ass:2")
    plt.plot(timeIter4, label="Sol:2")
    plt.legend()
    plt.figure()
    return u


if __name__ == "__main__":
    from pygimli.physics.seismics import ricker, wiggle
    import matplotlib.pyplot as plt
    import numpy as np

    t = np.arange(0, 0.02, 1.0 / 5000)
    r = ricker(t, 100.0, 1.0 / 100)
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)

    wiggle(ax, r, t, xoffset=0, posColor="red", negColor="blue", alpha=0.2)
    wiggle(ax, r, t, xoffset=1)
    wiggle(ax, r, t, xoffset=2, posColor="black", negColor="white", alpha=1.0)
    plt.show()