Пример #1
0
# Plot the pressures
figure(); ax = gca();
ax.set_xlabel('x', fontsize=20)
ax.set_ylabel('Pressure', fontsize=20)
ax.plot(sc[2].circumcenter[:,0], pressures, 'ro', markersize=8, mec='r')
ax.hold(True)
# Draw a line of slope -1 through the known presure point
xmax = max(sc[2].circumcenter[:,0])
xmin = min(sc[2].circumcenter[:,0])
ax.plot([xmin, xmax], [xmax - xmin, 0], 'k', linewidth=2)
ax.legend(['DEC', 'Analytical'], numpoints=1)
# Plot the triangles
figure(); ax = gca()
ax.triplot(vertices[:,0], vertices[:,1], triangles)
ax.hold('on')
# Insert the computed fluxes into vector of all fluxes
all_fluxes[internal_indices] = fluxes
# Whitney interpolate flux and sample at barycenters. Then
# rotate 90 degrees in the sense opposite to triangle orientation
v_bases,v_arrows = simplex_quivers(sc, all_fluxes)
v_arrows = -s * vstack((-v_arrows[:,1], v_arrows[:,0])).T
# Plot the resulting vector field at the barycenters
ax.quiver(v_bases[:,0],v_bases[:,1],v_arrows[:,0],v_arrows[:,1],
       units='dots', width=1, scale=1./30)
ax.axis('equal')
ax.set_title('Flux interpolated using Whitney map \n' \
          ' and visualized as velocity at barycenters\n')

show()

Пример #2
0
# decompose 4 random 1-cochains
for i in range(4):
    omega = sc.get_cochain(1)
    omega.v[:] = rand(*omega.v.shape)

    (beta, gamma, h) = hodge_decomposition(omega)

    h = h.v
    for v in H:
        h -= inner(v, h) * v
    h /= norm(h)

    H.append(h)

H = ortho(vstack(H))

# plot the results
from pylab import figure, title, quiver, axis, show
from pydec import triplot, simplex_quivers

for n, h in enumerate(H):
    figure()
    title('Harmonic 1-cochain #%d' % n)
    triplot(vertices, triangles)

    bases, dirs = simplex_quivers(sc, h)
    quiver(bases[:, 0], bases[:, 1], dirs[:, 0], dirs[:, 1])
    axis('equal')

show()
Пример #3
0
# Eliminate boundary conditions
K = K[non_boundary_indices,:][:,non_boundary_indices]
M = M[non_boundary_indices,:][:,non_boundary_indices]

# Compute eigenvalues and eigenvectors
# (could use sparse eigenvalue solver instead)
eigenvalues, eigenvectors = eig(K.todense(), M.todense())

# Plot eigenvalues
NUM_EIGS = 50 # Number of eigenvalues to plot
values = sorted([x for x in real(eigenvalues) if x > 1e-10])[0:NUM_EIGS]
ax = figure().gca()
ax.set_title('First ' + str(len(values)) + ' Eigenvalues\n\n')
ax.hold(True)
ax.plot(values,'ko')

# Plot the eigenvector 1-cochain as a vector field
N = 2 # Which non-zero eigenvector to plot?
non_zero_values = real(eigenvectors[:,list(eigenvalues).index(values[N])])
all_values = zeros((sc[1].num_simplices,))
all_values[non_boundary_indices] = non_zero_values
bases, arrows = simplex_quivers(sc,all_values)
ax = figure().gca()
ax.set_title('Mode #' + str(N+1))
ax.quiver(bases[:,0],bases[:,1],arrows[:,0],arrows[:,1])
ax.triplot(sc.vertices[:,0], sc.vertices[:,1], sc.simplices)
ax.axis('equal')

show()

Пример #4
0
ax.hold(True)
# Draw a line of slope -1 through the known presure point
xmax = max(sc[2].circumcenter[:, 0])
xmin = min(sc[2].circumcenter[:, 0])
ax.plot([xmin, xmax], [xmax - xmin, 0], 'k', linewidth=2)
ax.legend(['DEC', 'Analytical'], numpoints=1)
# Plot the triangles
figure()
ax = gca()
ax.triplot(vertices[:, 0], vertices[:, 1], triangles)
ax.hold('on')
# Insert the computed fluxes into vector of all fluxes
all_fluxes[internal_indices] = fluxes
# Whitney interpolate flux and sample at barycenters. Then
# rotate 90 degrees in the sense opposite to triangle orientation
v_bases, v_arrows = simplex_quivers(sc, all_fluxes)
v_arrows = -s * vstack((-v_arrows[:, 1], v_arrows[:, 0])).T
# Plot the resulting vector field at the barycenters
ax.quiver(v_bases[:, 0],
          v_bases[:, 1],
          v_arrows[:, 0],
          v_arrows[:, 1],
          units='dots',
          width=1,
          scale=1. / 30)
ax.axis('equal')
ax.set_title('Flux interpolated using Whitney map \n' \
          ' and visualized as velocity at barycenters\n')

show()
Пример #5
0
for i in range(4):
    omega = sc.get_cochain(1)
    omega.v[:] = rand(*omega.v.shape)

    (beta,gamma,h) = hodge_decomposition(omega)

    h = h.v
    for v in H:
        h -= inner(v,h) * v
    h /= norm(h)

    H.append(h)

H = ortho(vstack(H))

# plot the results
from pylab import figure, title, quiver, axis, show
from pydec import triplot, simplex_quivers

for n,h in enumerate(H):
    figure()
    title('Harmonic 1-cochain #%d' % n)
    triplot(vertices,triangles) 
    
    bases,dirs = simplex_quivers(sc,h)
    quiver(bases[:,0],bases[:,1],dirs[:,0],dirs[:,1])
    axis('equal')

show()