Пример #1
0
def plotmesh3d02():
    meshfile = gmsh.buildmesh3d('cylinderkey', 5)
    Th = siMesh(meshfile)
    plt.close('all')
    plt.ion()
    DisplayFigures(nfig=4)
    plt.figure(1)
    siplt.plotmesh(Th, legend=True)
    #siplt.plotmesh(Th,d=1,color='black',linewidth=3)
    set_axes_equal()
    plt.figure(2)
    siplt.plotmesh(Th, d=2, legend=True)
    plt.axis('off')
    set_axes_equal()
    plt.figure(3)
    siplt.plotmesh(Th,
                   d=2,
                   labels=[1, 1000, 1020, 1021],
                   color='LightGray',
                   alpha=0.05)
    siplt.plotmesh(Th,
                   d=2,
                   labels=[10, 11, 31, 2000, 2020, 2021],
                   legend=True,
                   alpha=1)
    plt.axis('off')
    set_axes_equal()
    plt.figure(4)
    siplt.plotmesh(Th, d=2, color='LightGray', alpha=0.05)
    siplt.plotmesh(Th, d=1, legend=True, linewidth=3)
    plt.axis('off')
    set_axes_equal()
    return Th
Пример #2
0
def find3D01():
    meshfile = gmsh.buildmesh3d('cylinder3dom', 15)
    Th = siMesh(meshfile)
    print('*** 1: print mesh')
    print(Th)
    d = 3
    print('*** 2: print labels of the %d-simplex elementary meshes' % d)
    idx = Th.find(d)
    print('d=%d, labels=' % d + str(Th.sThlab[idx]))
    d = 2
    print('*** 3: print labels of the %d-simplex elementary meshes' % d)
    idx = Th.find(d)
    print('d=%d, labels=' % d + str(Th.sThlab[idx]))
    d = 1
    print('*** 4: print labels of the %d-simplex elementary meshes' % d)
    idx = Th.find(d)
    print('d=%d, labels=' % d + str(Th.sThlab[idx]))
    d = 3
    lab = 10
    print('*** 5: print %d-simplex elementary meshes with label %d' % (d, lab))
    idx = Th.find(d, labels=lab)
    print('Th.sThlab[%d]=%s' % (idx, Th.sThlab[idx]))
    print('Th.sTh[%d] is the ' % idx + str(Th.sTh[idx]))
    d = 2
    lab = 112
    print('*** 6: print %d-simplex elementary meshes with label %d' % (d, lab))
    idx = Th.find(d, labels=lab)
    print('Th.sThlab[%d]=%s' % (idx, Th.sThlab[idx]))
    print('Th.sTh[%d] is the ' % idx + str(Th.sTh[idx]))
    d = 1
    lab = 120
    print('*** 7: print %d-simplex elementary meshes with label %d' % (d, lab))
    idx = Th.find(d, labels=lab)
    print('Th.sThlab[%d]=%s' % (idx, Th.sThlab[idx]))
    print('Th.sTh[%d] is the ' % idx + str(Th.sTh[idx]))
Пример #3
0
def plotmesh3d01():
    meshfile = gmsh.buildmesh3d('cylinder3holes', 10, force=True, verbose=1)
    Th = siMesh(meshfile, dim=3)
    plt.close('all')
    plt.ion()
    DisplayFigures(nfig=2)
    plt.figure(1)
    siplt.plotmesh(Th, legend=True)
    siplt.plotmesh(Th, d=1, color='black')
    set_axes_equal()
    plt.figure(2)
    siplt.plotmesh(Th, d=2, labels=[10, 20, 21, 100, 101], legend=True)
    set_axes_equal()
    plt.axis('off')
    return Th
Пример #4
0
def feval3D02():
    meshfile = gmsh.buildmesh3d('cylinderkey', 15)
    Th = siMesh(meshfile)
    f = lambda x, y, z: 3 * x**2 - 2 * y**3 + 4 * z**2 - x * y

    def g(x, y, z, a, b, c, d):
        return a * x**2 + b * y**3 + c * z**2 + d * x * y

    g1 = lambda x, y, z: g(x, y, z, 3, -2, 4, -1)
    g2 = lambda X: g(X[0], X[1], X[2], 3, -2, 4, -1)

    z = Th.feval(f)
    z1 = Th.feval(g1)
    z2 = Th.feval(g2)

    print('max(abs(z1-z))=%e' % max(abs(z1 - z)))
    print('max(abs(z2-z))=%e' % max(abs(z2 - z)))
Пример #5
0
def feval3D03():
    meshfile = gmsh.buildmesh3d('cylinderkey', 15)
    Th = siMesh(meshfile)
    # f : R^3 -> R^2
    f = [
        lambda x, y, z: np.cos(2 * x) * np.sin(3 * y) - z,
        lambda x, y, z: np.cos(3 * x) * np.sin(4 * y) + z
    ]

    g = [
        lambda X: np.cos(2 * X[0]) * np.sin(3 * X[1]) - X[2],
        lambda x, y, z: np.cos(3 * x) * np.sin(4 * y) + z
    ]

    V1 = Th.feval(f)
    V2 = Th.feval(f)
    print('V1.shape=' + str(V1.shape) + ' V2.shape=' + str(V2.shape))
    print('max(abs(V1-V2))=%e' % np.max(np.abs(V1 - V2)))
Пример #6
0
def quiver3d01(N=10):
    meshfile = gmsh.buildmesh3d('cylinder3dom', N, force=True)
    plt.close('all')
    Th = siMesh(meshfile)
    u = Th.feval(lambda x, y, z: 3 * x**2 - y**3 + z**2 + x * y)
    w = [
        lambda x, y, z: y * np.cos(-(x**2 + y**2) / 10),
        lambda x, y, z: -x * np.cos(-(x**2 + y**2) / 10), lambda x, y, z: z / 5
    ]
    W = np.array([Th.feval(w[0]), Th.feval(w[1]), Th.feval(w[2])])
    scale = 20
    plt.ion()
    DisplayFigures(nfig=4)
    plt.figure(1)
    sq = siplt.quiver(Th, W, nvec=3000, scale=scale)
    siplt.plotmesh(Th, d=2, color='LightGray', alpha=0.05)
    plt.colorbar(sq)
    set_axes_equal()
    plt.figure(2)
    sq = siplt.quiver(Th, W, scalars=u, nvec=3000, scale=scale)
    siplt.plotmesh(Th, d=2, color='LightGray', alpha=0.05)
    plt.colorbar(sq)
    plt.axis('off')
    set_axes_equal()
    plt.figure(3)
    sq = siplt.quiver(Th, W, labels=[10, 11], nvec=3000, scale=scale)
    siplt.plotmesh(Th, d=2, color='LightGray', alpha=0.05)
    plt.axis('off')
    set_axes_equal()
    plt.colorbar(sq)
    plt.figure(4)
    sq = siplt.quiver(Th,
                      W,
                      scalars=u,
                      labels=[10, 11],
                      nvec=3000,
                      scale=scale)
    siplt.plotmesh(Th, d=2, color='LightGray', alpha=0.05)
    plt.axis('off')
    set_axes_equal()
    plt.colorbar(sq)
    plt.show()
    return Th
Пример #7
0
def feval3D01():
    meshfile = gmsh.buildmesh3d('cylinderkey', 15)
    Th = siMesh(meshfile)
    g1 = lambda x, y, z: 3 * x**2 - y**3 + z**2 + x * y
    g2 = lambda X: 3 * X[0]**2 - X[1]**3 + X[2]**2 + X[0] * X[1]

    def g3(x, y, z):
        return 3 * x**2 - y**3 + z**2 + x * y

    def g4(X):
        return 3 * X[0]**2 - X[1]**3 + X[2]**2 + X[0] * X[1]

    z1 = Th.feval(g1)
    z2 = Th.feval(g2)
    z3 = Th.feval(g3)
    z4 = Th.feval(g4)

    print('max(abs(z2-z1))=%e' % max(abs(z2 - z1)))
    print('max(abs(z3-z1))=%e' % max(abs(z3 - z1)))
    print('max(abs(z4-z1))=%e' % max(abs(z4 - z1)))
Пример #8
0
def plot3d01(N=15):
    meshfile = gmsh.buildmesh3d('cylinderkey', N)
    Th = siMesh(meshfile)
    plt.close('all')
    plt.ion()
    DisplayFigures(nfig=4)
    u = Th.feval(lambda x, y, z: 3 * x**2 - y**3 + z**2 + x * y)
    plt.figure(1)
    h = siplt.plot(Th, u, s=2)
    plt.colorbar(h)
    plt.axis('off')
    set_axes_equal()
    plt.figure(2)
    h2 = siplt.plot(Th, u, d=2, labels=[1000, 1020, 1021, 2000, 2020, 2021])
    siplt.plot(Th,
               u,
               d=2,
               labels=[10, 11, 31],
               edgecolor='black',
               linewidth=0.5)
    plt.colorbar(h2)
    plt.axis('off')
    set_axes_equal()
    plt.figure(3)
    h2 = siplt.plot(Th, u, d=2, labels=[2000, 2020, 2021])
    h1 = siplt.plot(Th, u, d=1, labels=[1075, 1077, 1078, 1081], linewidth=3)
    siplt.plotmesh(Th, d=2, labels=[10, 11, 31], color='LightGray', alpha=0.2)
    plt.colorbar(h1)
    plt.axis('off')
    set_axes_equal()
    plt.figure(4)
    siplt.plot(Th, u, d=2, labels=[1], alpha=0.1)
    siplt.plot(Th, u, d=2, labels=[2000, 2020, 2021])
    siplt.plot(Th, u, d=1, labels=[1075, 1077, 1078, 1081], linewidth=3)
    siplt.plotmesh(Th, d=2, labels=[10, 11, 31], color='LightGray', alpha=0.2)
    siplt.plotmesh(Th, d=1, labels=[1080, 1079], color='black', linewidth=2)
    plt.axis('off')
    set_axes_equal()
    return Th