Exemple #1
0
def simulate(Theta, alpha, num_periods=10):
    # Dimensionless model requires the following parameters:
    from math import sin, pi

    I = Theta
    V = 0
    m = 1
    b = alpha
    s = lambda u: sin(u)
    F = lambda t: 0
    damping = 'quadratic'

    # Estimate T and dt from the small angle solution
    P = 2*pi   # One period (theta small, no drag)
    dt = P/40  # 40 intervals per period
    T = num_periods*P

    theta, t =  solver(I, V, m, b, s, F, dt, T, damping)
    omega = np.zeros(theta.size)
    omega[1:-1] = (theta[2:] - theta[:-2])/(2*dt)
    omega[0] = (theta[1] - theta[0])/dt
    omega[-1] = (theta[-1] - theta[-2])/dt

    S = omega**2 + np.cos(theta)
    D = alpha*np.abs(omega)*omega
    return t, theta, S, D
Exemple #2
0
 def solve(self, t, terminate=None):
     dt = t[1] - t[0]  # assuming constant time step
     T = t[-1]
     I, V = self.U0
     self.u, self.t = vib.solver(I,
                                 V,
                                 self.rhs.m,
                                 self.rhs.b,
                                 self.rhs.s,
                                 self.rhs.F,
                                 dt,
                                 T,
                                 damping=self.rhs.damping)
     # Must compute v=u' and pack with u
     self.v = np.zeros_like(self.u)
     self.v[1:-1] = (self.u[2:] - self.u[:-2]) / (2 * dt)
     self.v[0] = V
     self.v[-1] = (self.u[-1] - self.u[-2]) / dt
     self.r = np.zeros((self.u.size, 2))
     self.r[:, 0] = self.u
     self.r[:, 1] = self.v
     if terminate is not None:
         for i in range(len(self.t)):
             if terminate(self.r, self.t, i):
                 return self.r[:i + 1], self.t[:i + 1]
     return self.r, self.t
Exemple #3
0
def simulate_forced_vibrations2():
    # Scaling with u_c based on gamma=1
    from vib import solver, visualize
    from math import pi

    delta = 0.5
    delta = 0.99
    alpha = 1
    u, t = solver(I=alpha, V=0, m=1, b=0, s=lambda u: u, F=lambda t: cos(delta * t), dt=2 * pi / 160, T=2 * pi * 160)
    visualize(u, t)
    raw_input()
Exemple #4
0
def simulate_forced_vibrations3():
    # Scaling with u_c based on large delta
    from vib import solver, visualize
    from math import pi
    delta = 10
    alpha = 0.05*delta**2
    u, t = solver(I=alpha, V=0, m=1, b=0, s=lambda u: delta**(-2)*u,
                  F=lambda t: cos(t),
                  dt=2*pi/160, T=2*pi*20)
    visualize(u, t)
    raw_input()
Exemple #5
0
def simulate_forced_vibrations1():
    # Scaling with u_c based on resonance amplitude
    from vib import solver, visualize
    from math import pi
    delta = 0.99
    alpha = 1 - delta**2
    u, t = solver(I=alpha, V=0, m=1, b=0, s=lambda u: u,
                  F=lambda t: (1-delta**2)*cos(delta*t),
                  dt=2*pi/160, T=2*pi*160)
    visualize(u, t)
    raw_input()
Exemple #6
0
def simulate_forced_vibrations3():
    # Scaling with u_c based on large delta
    from vib import solver, visualize
    from math import pi

    delta = 10
    alpha = 0.05 * delta ** 2
    u, t = solver(
        I=alpha, V=0, m=1, b=0, s=lambda u: delta ** (-2) * u, F=lambda t: cos(t), dt=2 * pi / 160, T=2 * pi * 20
    )
    visualize(u, t)
    raw_input()
Exemple #7
0
def simulate_forced_vibrations2():
    # Scaling with u_c based on gamma=1
    from vib import solver, visualize
    from math import pi
    delta = 0.5
    delta = 0.99
    alpha = 1
    u, t = solver(I=alpha, V=0, m=1, b=0, s=lambda u: u,
                  F=lambda t: cos(delta*t),
                  dt=2*pi/160, T=2*pi*160)
    visualize(u, t)
    raw_input()
Exemple #8
0
def simulate_forced_vibrations1():
    # Scaling with u_c based on resonance amplitude
    from vib import solver, visualize
    from math import pi

    delta = 0.99
    alpha = 1 - delta ** 2
    u, t = solver(
        I=alpha,
        V=0,
        m=1,
        b=0,
        s=lambda u: u,
        F=lambda t: (1 - delta ** 2) * cos(delta * t),
        dt=2 * pi / 160,
        T=2 * pi * 160,
    )
    visualize(u, t)
    raw_input()
 def solve(self, t, terminate=None):
     dt = t[1] - t[0]  # assuming constant time step
     T = t[-1]
     I, V = self.U0
     self.u, self.t = vib.solver(
         I, V, self.rhs.m, self.rhs.b, self.rhs.s, self.rhs.F,
         dt, T, damping=self.rhs.damping)
     # Must compute v=u' and pack with u
     self.v = np.zeros_like(self.u)
     self.v[1:-1] = (self.u[2:] - self.u[:-2])/(2*dt)
     self.v[0] = V
     self.v[-1] = (self.u[-1] - self.u[-2])/dt
     self.r = np.zeros((self.u.size, 2))
     self.r[:,0] = self.u
     self.r[:,1] = self.v
     if terminate is not None:
         for i in range(len(self.t)):
             if terminate(self.r, self.t, i):
                 return self.r[:i+1], self.t[:i+1]
     return self.r, self.t
Exemple #10
0
import sys, os

sys.path.insert(0, os.path.join(os.pardir, 'src-vib'))
from vib import solver, visualize, plt
from math import pi, sin
import numpy as np

beta_values = [0.005, 0.05, 0.2]
beta_values = [0.00005]
gamma_values = [5, 1.5, 1.1, 1]
for i, beta in enumerate(beta_values):
    for gamma in gamma_values:
        u, t = solver(I=1,
                      V=0,
                      m=1,
                      b=2 * beta,
                      s=lambda u: u,
                      F=lambda t: sin(gamma * t),
                      dt=2 * pi / 60,
                      T=2 * pi * 20,
                      damping='quadratic')
        visualize(u, t, title='gamma=%g' % gamma, filename='tmp_%s' % gamma)
        print gamma, 'max u amplitude:', np.abs(u).max()
    for ext in 'png', 'pdf':
        cmd = 'doconce combine_images '
        cmd += ' '.join(['tmp_%s.' % gamma + ext for gamma in gamma_values])
        cmd += ' resonance%d.' % (i + 1) + ext
        os.system(cmd)
raw_input()
Exemple #11
0
import sys, os
sys.path.insert(0, os.path.join(os.pardir, 'src-vib'))
from vib import solver, visualize, plt
from math import pi, sin
import numpy as np

beta_values = [0.005, 0.05, 0.2]
beta_values = [0.00005]
gamma_values = [5, 1.5, 1.1, 1]
for i, beta in enumerate(beta_values):
    for gamma in gamma_values:
        u, t = solver(I=1, V=0, m=1, b=2*beta, s=lambda u: u,
                      F=lambda t: sin(gamma*t), dt=2*pi/60,
                      T=2*pi*20, damping='quadratic')
        visualize(u, t, title='gamma=%g' %
                  gamma, filename='tmp_%s' % gamma)
        print gamma, 'max u amplitude:', np.abs(u).max()
    for ext in 'png', 'pdf':
        cmd = 'doconce combine_images '
        cmd += ' '.join(['tmp_%s.' % gamma + ext for gamma in gamma_values])
        cmd += ' resonance%d.' % (i+1) + ext
        os.system(cmd)
raw_input()