Esempio n. 1
0
def plot2d01(N=25):
    meshfile = gmsh.buildmesh2d('condenser11', N)
    Th = siMesh(meshfile)
    u = Th.feval(
        lambda x, y: 5 * np.exp(-3 * (x**2 + y**2)) * np.cos(x) * np.sin(y))
    plt.rcParams['text.usetex'] = True
    plt.rcParams['text.latex.unicode'] = True
    plt.close('all')
    plt.ion()
    DisplayFigures(nfig=4)
    fig = plt.figure(1)
    siplt.plot(Th, u)
    plt.colorbar()
    set_axes_equal()
    plt.figure(2)
    siplt.plot(Th, u, labels=[20, 2, 4, 6, 8])
    siplt.plotmesh(Th, labels=10, color='LightGray')
    set_axes_equal()
    plt.axis('off')
    plt.figure(3)
    #plt.set_cmap(plt.cm.get_cmap(name='jet'))
    h = siplt.plot(Th, u, plane=False, colormap='jet')
    siplt.plotmesh(Th, d=1, color='Black', z=u)
    plt.colorbar(h)
    set_axes_equal()
    plt.figure(4)
    h = siplt.plot(Th, u, d=1, plane=False, linewidth=3)
    plt.colorbar(h)
    siplt.plotmesh(Th, labels=10, color='LightGray', z=u)
    set_axes_equal()
    plt.axis('off')
    return Th
Esempio n. 2
0
def plotmesh2d01():
    meshfile = gmsh.buildmesh2d('disk5holes.geo', 20, force=True, verbose=1)
    Th = siMesh(meshfile, dim=2)
    plt.close('all')
    plt.ion()
    DisplayFigures(nfig=2)
    plt.figure(1)
    siplt.plotmesh(Th, legend=True)
    set_axes_equal()
    plt.figure(2)
    siplt.plotmesh(Th, color='LightGray')
    siplt.plotmesh(Th, d=1, linewidth=2, legend=True)
    plt.axis('off')
    set_axes_equal()
    return Th
Esempio n. 3
0
def plotiso2d01(N=15):
    meshfile = gmsh.buildmesh2d('condenser11', N)
    Th = siMesh(meshfile)
    u = Th.feval(
        lambda x, y: 5 * np.exp(-3 * (x**2 + y**2)) * np.cos(x) * np.sin(y))
    plt.close('all')
    plt.ion()
    DisplayFigures(nfig=4)
    fig = plt.figure(1)
    siplt.plotiso(Th, u, niso=15)
    siplt.plotmesh(Th, d=1, color='Black')
    set_axes_equal()
    plt.colorbar()
    fig = plt.figure(2)
    isos = np.linspace(-1, 1, 21)
    siplt.plotiso(Th,
                  u,
                  niso=15,
                  color='LightGray',
                  isorange=isos,
                  linestyles=':')
    siplt.plotmesh(Th, d=1, color='Black')
    plt.axis('off')
    set_axes_equal()
    fig = plt.figure(3)
    siplt.plotiso(Th, u, labels=10, niso=15, linewidths=1)
    plt.colorbar()
    siplt.plotmesh(Th, labels=10, color='LightGray', linewidth=1, alpha=0.05)
    siplt.plotiso(Th,
                  u,
                  labels=[2, 4, 6, 8, 20],
                  niso=15,
                  color='Gray',
                  linewidths=1)
    siplt.plot(Th, u, labels=[2, 4, 6, 8, 20])
    siplt.plotiso(Th, u, isorange=0, color='Black', linewidths=2)
    plt.axis('off')
    set_axes_equal()
    fig = plt.figure(4)
    siplt.plotiso(Th, u, labels=10, niso=15, linewidths=1, color='White')
    siplt.plot(Th, u, labels=10)
    siplt.plotiso(Th, u, labels=[2, 4, 6, 8, 20], niso=15, linewidths=1)
    cb = plt.colorbar()
    cb.lines[0].set_linewidth(4)
    plt.axis('off')
    set_axes_equal()
    return Th
Esempio n. 4
0
def feval2D02():
    meshfile = gmsh.buildmesh2d('condenser11', 50)
    Th = siMesh(meshfile)
    f = lambda x, y: np.cos(2 * x) * np.sin(3 * y)

    def g(x, y, cx, cy):
        return np.cos(cx * x) * np.sin(cy * y)

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

    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)))
Esempio n. 5
0
def quiver2d01(N=15):
    meshfile = gmsh.buildmesh2d('condenser11', N)
    plt.close('all')
    DisplayFigures(nfig=4)
    Th = siMesh(meshfile)
    u = Th.feval(
        lambda x, y: 5 * np.exp(-3 * (x**2 + y**2)) * np.cos(x) * np.sin(y))
    w = [
        lambda x, y: y * np.cos(-(x**2 + y**2) / 10),
        lambda x, y: -x * np.cos(-(x**2 + y**2) / 10)
    ]
    W = np.array([Th.feval(w[0]), Th.feval(w[1])])
    plt.ion()
    plt.figure(1)
    siplt.quiver(Th, W, scale=50, nvec=3000)
    siplt.plotmesh(Th, d=1, color='black')
    set_axes_equal()
    plt.colorbar()
    plt.figure(2)
    siplt.quiver(Th, W, scalars=u, scale=50, nvec=3000)
    siplt.plotmesh(Th, d=1, color='black')
    plt.axis('off')
    set_axes_equal()
    plt.colorbar()
    plt.figure(3)
    siplt.quiver(Th, W, labels=[2, 4, 6, 8, 20], nvec=1000, scale=50)
    siplt.plotmesh(Th, d=1, color='black')
    plt.axis('off')
    set_axes_equal()
    plt.colorbar()
    plt.figure(4)
    siplt.quiver(Th,
                 W,
                 labels=[2, 4, 6, 8, 20],
                 scalars=u,
                 scale=50,
                 nvec=1000)
    siplt.plotmesh(Th, d=1, color='black')
    plt.axis('off')
    set_axes_equal()
    plt.colorbar()
    plt.show()
    return Th
Esempio n. 6
0
def feval2D03():
    meshfile = gmsh.buildmesh2d('condenser11', 50)
    Th = siMesh(meshfile)
    # f : R^2 -> R^3
    f = [
        lambda x, y: np.cos(2 * x) * np.sin(3 * y),
        lambda x, y: np.cos(3 * x) * np.sin(4 * y),
        lambda x, y: np.cos(4 * x) * np.sin(5 * y)
    ]

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

    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)))
Esempio n. 7
0
def feval2D01():
    meshfile = gmsh.buildmesh2d('condenser11', 50)
    Th = siMesh(meshfile)

    g1 = lambda x, y: np.cos(x) * np.sin(y)
    g2 = lambda X: np.cos(X[0]) * np.sin(X[1])

    def g3(x, y):
        return np.cos(x) * np.sin(y)

    def g4(X):
        return np.cos(X[0]) * np.sin(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)))
Esempio n. 8
0
def find2D01():
    meshfile = gmsh.buildmesh2d('condenser11', 50)
    Th = siMesh(meshfile)
    print('*** 1: print mesh')
    print(Th)
    print('*** 2: print labels of the 2-simplex elementary meshes')
    idx = Th.find(2)
    print('d=2, labels=' + str(Th.sThlab[idx]))
    print('*** 3: print labels of the 1-simplex elementary meshes')
    idx = Th.find(1)
    print('d=1, labels=' + str(Th.sThlab[idx]))
    d = 2
    lab = 6
    print('*** 4: 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 = 101
    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]))