コード例 #1
0
def plot_twisting_errors(nodes, n=3):
    print "\nEvaluating Twisting errors for {0} first modes:".format(n)
    plt.figure("twisting_errors")
    freqs_i = [[] for _ in range(n)]
    for N in nodes:
        beam = TwistingBeam(L, S, mat, BCs=[0], nodes=N)
        for i, (freq, mode) in enumerate(beam.get_modes()[:n]):
            freqs_i[i].append(freq)

    modes = cantilever_twisting_modes(beam, n)
    freqs = map(lambda x: x[0], modes)

    for i, (f, f_i) in enumerate(zip(freqs, freqs_i)):
        plt.plot(nodes, abs(f-f_i)/f*100, bstyles[i])

    plt.legend(["$f = %.2f Hz$" % f for f in freqs])
    plt.xlabel(r'Number of nodes')
    plt.ylabel(r'Relative error $\epsilon = |f_n - f|/f*100$ (%)')
    plt.grid()
コード例 #2
0
def plot_twisting_modes(nodes, n=3):
    print "\nPloting {0} first twisting modes:".format(n)
    fig, axarr = plt.subplots(n, sharex=True)
    fs = []
    for j, N in enumerate(nodes):
        beam = TwistingBeam(L, S, mat, BCs=[0], nodes=N)
        modes = beam.get_modes()[:n]

        print "\nN:", N
        for i, (freq, mode) in enumerate(modes):
            print "mode {0}, f = {1:.2f} Hz".format(i+1, freq)

            axarr[i].plot(np.linspace(0, L, len(mode)), mode, styles[j % 3])
        fs.append(map(lambda x: x[0], modes))

    axarr[n-1].set_xlabel(r"Length of the beam ($y$ axis) in meters")
    axarr[n/2].set_ylabel("Normalized angular deflection")
    fi = []
    modes = cantilever_twisting_modes(beam, n, points=20)
    print "\nStatic:"
    for i, (freq, mode) in enumerate(modes):
        print "mode {0}, f = {1:.2f} Hz".format(i+1, freq)
        fi.append(freq)
        x = mode.T[0]
        y = mode.T[1]
        axarr[i].plot(x, y, styles[2])
        axarr[i].grid()
    axarr[n/2].legend(["N = 8", "N = 20", "static"],
                      loc='center right',
                      bbox_to_anchor=(1.3, 0.5))
    plt.subplots_adjust(right=0.8)
    fs = [fi] + fs
    fs = np.array(fs).T
    f0 = fs[:, 0:1] * np.ones((1, 2))
    errs = np.abs(fs[:, 1:] - f0) / f0 * 100
    with open("twisting.out", "w") as outfile:
        for a, b in zip(fs, errs):
            line = "\t".join(["%.2f" % p for p in np.hstack((a, b))])
            outfile.writelines(line + "\n")