示例#1
0
def euler_step(torque, dt, m, hext, Jc):
    """Takes one step using the Euler method

    torque: function to calculate torque from m, hext and Jc
    dt: time step
    m: moment unit vector
    hext: external field
    Jc: current density
    """
    t = torque(m, hext, Jc)
    return normalize(m + dt * t)
示例#2
0
def rk23_step(torque, dt, m, hext, Jc):
    """ Takes one step using the Bogacki-Shampine method (Runga-Kutta RK23)

    torque: function to calculate torque from m, hext and Jc
    dt: time step
    m: moment unit vector
    hext: external field
    Jc: current density
    """
    k1 = torque(m, hext, Jc)
    k2 = torque(m + dt * k1 / 2.0, hext, Jc)
    k3 = torque(m + 3.0 * dt * k2 / 2.0, hext, Jc)
    m = m + 2.0 * dt * k1 / 9.0 + dt * k2 / 3.0 + 4 * dt * k3 / 9.0
    return normalize(m)
示例#3
0
def huen_step(torque, dt, m, hext, Jc):
    """ Takes one step using Huen's method

    torque: function to calculate torque from m, hext and Jc
    dt: time step
    m: moment unit vector
    hext: external field
    Jc: current density
    """
    k1 = torque(m)
    m1 = m + dt * k1
    k2 = torque(m1)
    m = m + dt * (k1 + k2) / 2.0
    return normalize(m)
示例#4
0
def rk4_step(torque, dt, m, hext, Jc):
    """ Takes one step using the Classic 4th order Runga-Kutta method

    torque: function to calculate torque from m, hext and Jc
    dt: time step
    m: moment unit vector
    hext: external field
    Jc: current density
    """
    k1 = torque(m, hext, Jc)
    k2 = torque(m + dt * k1 / 2.0, hext, Jc)
    k3 = torque(m + dt * k2 / 2.0, hext, Jc)
    k4 = torque(m + dt * k3, hext, Jc)
    m = m + dt * (k1 + 2.0 * k2 + 2.0 * k3 + k4) / 6.0
    return normalize(m)
示例#5
0
 def reset(self):
     """ Resets the kernel to the initial conditions
     """
     self.m = normalize(self.m0)
     self.t = 0.0