def plot_bending_modes(nodes, n=3): print "\nPloting {0} first bending modes:".format(n) f, axarr = plt.subplots(n, sharex=True) for j, N in enumerate(nodes): beam = BendingBeam(L, S, mat, BCs=[0, 1], nodes=N) eigs = beam.get_modes() for i, (eigval, eigvec) in enumerate(eigs[:n]): print "N:", N, ", f=", eigval, "Hz" y = eigvec[::2] / eigvec[-2] x = np.linspace(0, L, len(y)) axarr[i].plot(x, y, styles[j]) axarr[n-1].set_xlabel(r"Length of the beam ($y$ axis) in meters") axarr[n/2].set_ylabel("Normalized vertical deflection") for i, (f, mode) in enumerate(cantilever_bending_modes(beam, n, points=20)): print f, "Hz" 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)
sys.path.append(os.path.abspath("../")) # noqa from beam import BendingBeam, TwistingBeam from materials import IsotropicMaterial, aluminum from analytical_beam_modes import cantilever_bending_modes from analytical_beam_modes import cantilever_twisting_modes from hermes_section import section as S mat = IsotropicMaterial(**aluminum['6061-T6']) L = 1. styles = ['r*-', 'g.-', 'bo-'] bstyles = ['k+-', 'r.-', 'g^-', 'b*-', 'cd-', 'mo-'] bending_beam = BendingBeam(L, S, mat) def style_gen(token, color=0, line=0): colors = 'brkgmc' tokens = 'o.+vds*' lines = ['-', '-.', '--', ':'] color = colors[color % len(colors)] token = tokens[token % len(tokens)] line = lines[line % len(lines)] return "{0}{1}{2}".format(color, token, line) def subplot_modes(modes): """ modes is a list of lists (one for each natural frequency)