Exemplo n.º 1
0
                 uBoundary=dirichletBC)

"""
Note that on boundary 4 (right) no BC is explicitly applied leading to default or natural BC that are of homogeneous Neumann type 
:math:`\frac{\partial u}{\partial n}=0`
"""
              
ax = showMesh(grid, data=u, filled=True, colorBar=True,
              orientation='vertical', label='Solution $u$',
              levels=np.linspace(min(u), max(u), 14), showLater=True)[0]

"""
Instead of the grid we now want to add streamlines to the plot to show the gradients of the solution (i.e., the flow direction).
"""

drawStreamLines(ax, grid, u, nx=25, ny=25, color='Black')

ax.text(0.0, 1.02, '$u=1$',
        horizontalalignment='center' )
ax.text(-1.08, 0.0, '$\partial u/\partial n=-0.5$',
        verticalalignment='center', rotation='vertical')
ax.text(0.0, -1.08, '$\partial u/\partial n=2.5$',
        horizontalalignment='center')
ax.text(1.02, 0.0, '$\partial u/\partial n=0$',
        verticalalignment='center', rotation='vertical')


ax.set_title('$\\nabla\cdot(1\\nabla u)=0$')

ax.set_xlim([-1.1, 1.1])
ax.set_ylim([-1.1, 1.1])
Exemplo n.º 2
0
    while len(downwind) > 0:
        fastMarch(mesh, downwind, times, upTags, downTags)

    print(time.time() - tic, "s")

    # compare with analytical solution along the x axis
    x = np.arange(0., 100., 0.5)
    t = pg.interpolate(mesh, times, pg.asvector(x), x * 0., x * 0.)
    tdirect = x / v[0]  # direct wave
    alfa = asin(v[0] / v[1])  # critically refracted wave angle
    xreflec = tan(alfa) * zlay * 2.  # first critically refracted
    trefrac = (x - xreflec) / v[1] + xreflec * v[1] / v[0]**2
    tana = np.where(trefrac < tdirect, trefrac, tdirect)  # minimum of both
    print("min(dt)=",
          min(t - tana) * 1000,
          "ms max(dt)=",
          max(t - tana) * 1000,
          "ms")

    # plot traveltime field, a few lines
    fig = plt.figure()
    a = fig.add_subplot(211)
    drawMesh(a, mesh)
    drawField(a, mesh, times, True, 'Spectral')
    drawStreamLines(a, mesh, times, nx=50, ny=50)

    # plot calculated and measured travel times
    a2 = fig.add_subplot(212)
    plt.plot(x, t, 'b.-', x, tdirect, 'r-', x, trefrac, 'g-')
    plt.show()
Exemplo n.º 3
0
###############################################################################
# Then we start marching until all fields are filled.
tic = time.time()
while len(downwind) > 0:
    fastMarch(mesh, downwind, times, upTags, downTags)

print(time.time() - tic, "s")

###############################################################################
# First, we plot the traveltime field and streamlines
fig, ax = plt.subplots(figsize=(10, 5))
drawMesh(ax, mesh)
ax.set_xlabel('x [m]')
ax.set_ylabel('y [m]')
drawField(ax, mesh, times, cmap='Spectral', fillContour=True)
drawStreamLines(ax, mesh, -times, nx=50, ny=50)

###############################################################################
# We compare the result with the analytical solution along the x axis
x = np.arange(0., 140., 0.5)
tFMM = pg.interpolate(mesh, times, x, x * 0., x * 0.)
tAna = analyticalSolution2Layer(x)
print("min(dt)={} ms  max(dt)={} ms".format(
    min(tFMM - tAna) * 1000,
    max(tFMM - tAna) * 1000))

###############################################################################
# In order to use the Dijkstra, we extract the surface positions >0
mx = pg.x(mesh.positions())
my = pg.y(mesh.positions())
fi = pg.find((my == 0.0) & (mx >= 0))
Exemplo n.º 4
0
###############################################################################
# Then we start marching until all fields are filled.
tic = time.time()
while len(downwind) > 0:
    fastMarch(mesh, downwind, times, upTags, downTags)

print(time.time() - tic, "s")

###############################################################################
# First, we plot the traveltime field and streamlines
fig, ax = plt.subplots(figsize=(10, 5))
drawMesh(ax, mesh)
ax.set_xlabel('x [m]')
ax.set_ylabel('y [m]')
pg.show(mesh, times, cMap='Spectral', fillContour=True, ax=ax)
drawStreamLines(ax, mesh, -times, nx=50, ny=50)

###############################################################################
# We compare the result with the analytical solution along the x axis
x = np.arange(0., 140., 0.5)
tFMM = pg.interpolate(mesh, times, x, x * 0., x * 0.)
tAna = analyticalSolution2Layer(x, zlay, v[0], v[1])
print("min(dt)={} ms  max(dt)={} ms".format(min(tFMM - tAna) * 1000,
                                            max(tFMM - tAna) * 1000))

###############################################################################
# In order to use the Dijkstra, we extract the surface positions >0
mx = pg.x(mesh.positions())
my = pg.y(mesh.positions())
fi = pg.find((my == 0.0) & (mx >= 0))
px = np.sort(mx(fi))
Exemplo n.º 5
0
    # start fast marching
    tic = time.time()
    while len(downwind) > 0:
        fastMarch(mesh, downwind, times, upTags, downTags)

    print(time.time() - tic, "s")

    # compare with analytical solution along the x axis
    x = np.arange(0., 100., 0.5)
    t = pg.interpolate(mesh, times, x, x * 0., x * 0.)
    tdirect = x / v[0]  # direct wave
    alfa = asin(v[0] / v[1])  # critically refracted wave angle
    xreflec = tan(alfa) * zlay * 2.  # first critically refracted
    trefrac = (x - xreflec) / v[1] + xreflec * v[1] / v[0]**2
    tana = np.where(trefrac < tdirect, trefrac, tdirect)  # minimum of both
    print("min(dt)=",
          min(t - tana) * 1000, "ms max(dt)=",
          max(t - tana) * 1000, "ms")

    # plot traveltime field, a few lines
    fig = plt.figure()
    a = fig.add_subplot(211)
    drawMesh(a, mesh)
    drawField(a, mesh, times, True, 'Spectral')
    drawStreamLines(a, mesh, times, nx=50, ny=50)

    # plot calculated and measured travel times
    a2 = fig.add_subplot(212)
    plt.plot(x, t, 'b.-', x, tdirect, 'r-', x, trefrac, 'g-')
    plt.show()
Exemplo n.º 6
0
        for nn in tmpNodes:
            if not upTags[nn.id()] and not downTags[nn.id()]:
                downwind.add(nn)
                downTags[nn.id()] = 1

    # start fast marching
    tic = time.time()
    while len(downwind) > 0:
        fastMarch(mesh, downwind, times, upTags, downTags)

    print(time.time() - tic, "s")

    # compare with analytical solution along the x axis
    x = np.arange(-20., 150., 0.5)
    t = pg.interpolate(mesh, times, pg.asvector(x), x * 0., x * 0.)
    tdirect = np.abs(x) / v[0]  # direct wave
    alfa = asin(v[0] / v[1])  # critically refracted wave angle
    xreflec = tan(alfa) * zlay * 2.  # first critically refracted
    trefrac = (np.abs(x) - xreflec) / v[1] + xreflec * v[1] / v[0]**2
    tana = np.where(trefrac < tdirect, trefrac, tdirect)  # minimum of both
    print("min(dt)=", min(t-tana)*1e3, "ms max(dt)=", max(t-tana)*1e3, "ms")

    # %% plot traveltime field, a few lines
    fig, ax = plt.subplots(nrows=2, sharex=True)
    drawMesh(ax[0], mesh)
    drawField(ax[0], mesh, times, True)
    drawStreamLines(ax[0], mesh, times, color='white')
    # plot calculated and measured travel times
    ax[1].plot(x, t, 'b.-', x, tdirect, 'r-', x, trefrac, 'g-')
    plt.show()