10.1.2. pyopencl_scripts.rk4_functions

This module provides functions for simulating networks or particles using python.

10.1.2.1. Overview

10.1.2.2. Classes and Functions

ilpm.pyopencl_scripts.rk4_functions.rk4_damp(xy, v, NL, KL, BM, Mm, beta, h)[source]

Performs Runge-Kutta 4th order time step increment for spring system with damping.

Parameters:

x : array NP x nd

initial position (extension of spring)

v : array NP x nd

initial velocity

NL : array NP x nn

ith row contains indices of neighbors for ith particle

KL : array NP x nn

bond strength for each bond (same format as NL)

BM : array NP x nn

unstretched (reference) bond length matrix

beta : float

damping coefficient

h : float

time step

Returns

———-

xout,vout : arrays NP x nd

output positions and velocities

ilpm.pyopencl_scripts.rk4_functions.rk4_damp_constvBC(xy, v, NL, KL, BM, Mm, beta, h, BND)[source]

Performs Runge-Kutta 4th order time step increment for spring system with damping, while moving boundary particles (BND index particles) at a prescribed velocity (prescribed in v, by v[BND])

Parameters:

x : array NP x nd

initial position (extension of spring)

v : array NP x nd

initial velocity

NL : array NP x nn

ith row contains indices of neighbors for ith particle

KL : array NP x nn

bond strength for each bond (same format as NL)

BM : array NP x nn

unstretched (reference) bond length matrix

beta : float

damping coefficient

h : float

time step

Returns

———-

xout, vout : arrays NP x nd

output positions and velocities

ilpm.pyopencl_scripts.rk4_functions.fdspring(xy, v, NL, KL, BM, Mm, beta)[source]

Computes dv/dt for massive particles connected by damped springs (in 2D or 3D).

Parameters:

xy : matrix of dimensions Nx2 (N = number of masses/gyros)

Current positions of the masses/gyroscopes

v : array NP x spatial dimensions

velocity

NL : matrix of dimension N x (max number of neighbors)

Each row corresponds to a gyroscope. The entries tell the numbers of the neighboring gyroscopes

KL : matrix of dimension N x (max number of neighbors)

Spring constant – like NL matrix, with spring const values (k) corresponding to a true connection while 0 signifies that there is not a connection

BM : NP x NN array or float

Rest bond lengths, arranged like KL

Mm : matrix of dimension Nx1

Masses of each particle

beta : float

damping coefficient

Returns:

ftx : martix of dimension N x 2

dv/dt for all particles

ilpm.pyopencl_scripts.rk4_functions.fspring(xy, NL, KL, BM, Mm)[source]

Computes dv/dt for massive particles connected by undamped springs (in 2D or 3D).

Parameters:

t : float

simulation time

xy : matrix of dimensions Nx2 (N = number of masses/gyros)

Current positions of the masses/gyroscopes

f : function

function which calculates the right hand side of the differential equation. Equation of motion

NL : matrix of dimension N x (max number of neighbors)

Each row corresponds to a gyroscope. The entries tell the numbers of the neighboring gyroscopes

KL : matrix of dimension N x (max number of neighbors)

Spring constant – like NL matrix, with spring const values (k) corresponding to a true connection while 0 signifies that there is not a connection

BM : NP x NN array or float

Rest bond lengths, arranged like KL

Mm : matrix of dimension Nx1

Masses of each particle

Returns:

ftx : martix of dimension N x 2

dv/dt for all particles

ilpm.pyopencl_scripts.rk4_functions.rk4_1stO(Xn, R, dt, f, Ni, Nk, spring, pin, b_l=1)[source]

Calculates the change in position for a lattice of gyroscopes according to 1st order eqn (‘Nash evolution’). calc_forces_and_cross(X,R, NL, KL, k=1., pin=1., bond_length = 1. )

Parameters:

Xn : nx3 array (where n = number of gyros)

Current positions of the gyroscopes

R : n x 2 array

Rest positions of the gyroscopes

dt : float

simulation time step

f : function

function which calculates the right hand side of the differential equation. Equation of motion

Ni : matrix of dimension n x (max number of neighbors)

Each row corresponds to a gyroscope. The entries tell the numbers of the neighboring gyroscopes

Nk : matrix of dimension n x (max number of neighbors)

Correponds to Ni matrix. 1 corresponds to a true connection while 0 signifies that there is not a connection

spring : float

spring constant

pin : float

gravitational spring constant

R : matrix of dimension nx3

Equilibrium positions of all the gyroscopes

Returns:

dx1,dx2,dx3,dx4,xout : arrays of dimension nx3

displacements in this time step

ilpm.pyopencl_scripts.rk4_functions.fglidingHST_exact(xy, v, NL, KL, BM, Mm, params)[source]

Increment velocity for lattice of gliding Heavy Symmetric Tops (HSTs)

ilpm.pyopencl_scripts.rk4_functions.rk4_glidingHST_exact(xy, v, NL, KL, BM, Mm, params)[source]

Performs Runge-Kutta 4th order time step increment for gliding heavy symmetric top (Rutstam-like evolution)

Parameters:

xy : array NP x 5

current position of COM of gyroscopes: x, y, theta, phi, psi

v : array NP x 5

current velocity of the pivot points: vx, vy, dtheta/dt, dphi/dt, dpsi/dt

NL : array NP x nn

ith row contains indices of neighbors for ith particle

KL : array NP x nn

bond strength for each bond (same format as NL)

BM : array NP x nn

unstretched (reference) bond length matrix

h : float

time step

Returns:

dx1,dv1,dx2,dv2,dx3,dv3,dx4,dv4,xout,vout : arrays NP x nd

all parameters for integration

ilpm.pyopencl_scripts.rk4_functions.fglidingHST_PL(xy, v, NL, KL, BM, Mm, params)[source]

Increment velocity for lattice of gliding Heavy Symmetric Tops (HSTs) in Planar Limit

ilpm.pyopencl_scripts.rk4_functions.rk4_glidingHST_PL(xy, v, NL, KL, BM, Mm, params)[source]

Performs Runge-Kutta 4th order time step increment for gliding heavy symmetric top in Planar Limit (hanging gyros only) Note that b=0 here (hanging gyros)!

Parameters:

xy : array NP x 4

current position of COM of gyroscopes: X, Y, deltaX, deltaY

v : array NP x 4

current velocity of the pivot points: vX, vY, vdeltaX, vdeltaY

NL : array NP x nn

ith row contains indices of neighbors for ith particle

KL : array NP x nn

bond strength for each bond (same format as NL)

BM : array NP x nn

unstretched (reference) bond length matrix

h : float

time step

Returns

———-

dx1,dv1,dx2,dv2,dx3,dv3,dx4,dv4,xout,vout : arrays NP x nd

all parameters for integration

ilpm.pyopencl_scripts.rk4_functions.calc_forces_and_cross(X, R, NL, KL, k=1.0, pin=1.0, bond_length=1.0)[source]

Calculates the forces on gyroscopes from springs and pinning and does a cross product for EOM . Currently CANNOT handle inhomogeneous bond_lengths or spring constants. FIX THIS. CANNOT handle correctly the case when bond_length !=1 either. FIX THIS TOO.

Parameters:

X : matrix of dimensions nx3 (n = number of gyros)

Current positions of the gyroscopes

R : matrix of dimension nx3

Equilibrium positions of all the gyroscopes

NL : matrix of dimension n x (max number of neighbors)

Each row corresponds to a gyroscope. The entries tell the numbers of the neighboring gyroscopes

KL : matrix of dimension n x (max number of neighbors)

Correponds to Ni matrix. 1 corresponds to a true connection while 0 signifies that there is not a connection

k : float or NP x 1 array

spring constant array. Default value = 1

pin : float or NP array

gravitational spring constant = lmg/Iw. Default value = 1

bond_length : float

Length of unstretched springs. Default value = 1

Returns:

crossed : matrix of dimension nx3

cross product of forces and zhat

ilpm.pyopencl_scripts.rk4_functions.calc_forces_and_cross_magnetic(X, Ni, Nk, spring, pin, R, bond_length=1, out_index=1)[source]

Calculates the forces on gyroscopes from magnetic interactions and pinning and does a cross product for EOM .

Parameters:

X : matrix of dimensions 2nx3 (n = number of gyros)

Current positions of the gyroscopes

Ni : matrix of dimension n x (max number of neighbors)

Each row corresponds to a gyroscope. The entries tell the numbers of the neighboring gyroscopes

Nk : matrix of dimension n x (max number of neighbors)

Correponds to Ni matrix. 1 corresponds to a true connection while 0 signifies that there is not a connection

spring : float

spring constant

pin : float

gravitational spring constant

R : matrix of dimension 2nx3

Equilibrium positions of all the gyroscopes

bond_length : float

Length of unstretched springs. Default value = 1

Returns:

crossed : matrix of dimension nx3

cross product of forces and zhat

ilpm.pyopencl_scripts.rk4_functions.fspring_perp(xy, NL, KL, KGdivKL, Mm, NP, nn)[source]

Computes dv/dt for all particles in 2D at time t, with a perpendicular force between particles.

Parameters:

t : float

simulation time

xy : matrix of dimensions Nx2 (N = number of masses/gyros)

Current positions of the masses/gyroscopes

f : function

function which calculates the right hand side of the differential equation. Equation of motion

NL : matrix of dimension N x (max number of neighbors)

Each row corresponds to a gyroscope. The entries tell the numbers of the neighboring gyroscopes

KL : matrix of dimension N x (max number of neighbors)

Spring constant – like NL matrix, with spring const values (k) corresponding to a true connection while 0 signifies that there is not a connection

Mm : matrix of dimension Nx1

Masses of each particle

Returns:

ftx : martix of dimension N x 2

dv/dt for all particles, in 2D

ilpm.pyopencl_scripts.rk4_functions.rk4_perp(xy, v, NL, KL, KGdivKL, Mm, NP, nn, h)[source]

Performs Runge-Kutta 4th order time step increment for spring system with perpendicular force btwn particles.

Parameters:

x : array NP x nd

initial position (extension of spring)

v : array NP x nd

initial velocity

NL : array NP x nn

ith row contains indices of neighbors for ith particle

KL : array NP x nn

bond strength for each bond (same format as NL)

h : float

time step

Returns

———-

dx1,dv1,dx2,dv2,dx3,dv3,dx4,dv4,xout,vout : arrays NP x nd

all parameters for integration

ilpm.pyopencl_scripts.rk4_functions.fgyro_Nash(xy, xy0, NL, theta, OmK, Omg, Mm, NP, nn)[source]

Computes dx/dt for gyros in 2D with linearized approximation (Schrodinger-like).

Parameters:

xy : matrix of dimensions Nx2 (N = number of masses/gyros)

Current positions of the masses/gyroscopes

xy0 : array NP x nd

initial position (extension of spring)

NL : matrix of dimension N x (max number of neighbors)

Each row corresponds to a gyroscope. The entries tell the numbers of the neighboring gyroscopes

theta : array NP x nn

matrix of angles between particles

OmK : matrix of dimension N x (max number of neighbors)

Spring constant – like NL matrix, with spring const values (k l^2 /I omega) corresponding to a true connection while 0 signifies that there is not a connection

Mm : matrix of dimension Nx1

Masses of each particle

Returns:

ftx : martix of dimension N x 2

dv/dt for all particles, in 2D

ilpm.pyopencl_scripts.rk4_functions.fBrunGyro(xy, xy0, NL, KL, KG, Mm, NP, nn)[source]

Computes dv/dt for all gyros in 2D at time t in steady state frequency determined by KG=I omega^2/l^2, according to the model of Brun et al 2012.

Parameters:

t : float

simulation time

xy : matrix of dimensions Nx2 (N = number of masses/gyros)

Current positions of the masses/gyroscopes

f : function

function which calculates the right hand side of the differential equation. Equation of motion

NL : matrix of dimension N x (max number of neighbors)

Each row corresponds to a gyroscope. The entries tell the numbers of the neighboring gyroscopes

KL : matrix of dimension N x (max number of neighbors)

Spring constant – like NL matrix, with spring const values (k) corresponding to a true connection while 0 signifies that there is not a connection

KG : array of dimension N x 1

Gyro constant ‘rotational force’

Mm : matrix of dimension Nx1

Masses of each particle

Returns:

ftx : martix of dimension N x 2

dv/dt for all particles, in 2D

ilpm.pyopencl_scripts.rk4_functions.rk4_BrunGyro(xy, xy0, v, NL, KL, KG, Mm, NP, nn, h)[source]

Performs Runge-Kutta 4th order time step increment for spring-gyro system in steady state frequency determined by KG=I omega^2/l^2, according to the model of Brun et al 2012.

Parameters:

x : array NP x nd

initial position (extension of spring)

v : array NP x nd

initial velocity

NL : array NP x nn

ith row contains indices of neighbors for ith particle

KL : array NP x nn

bond strength for each bond (same format as NL)

h : float

time step

Returns

———-

dx1,dv1,dx2,dv2,dx3,dv3,dx4,dv4,xout,vout : arrays NP x nd

all parameters for integration

ilpm.pyopencl_scripts.rk4_functions.print_output_1stO(dx1, dx2, dx3, dx4, xyout)[source]

Print the output of a 1st order Runge-Kutta 4th order evaluation.

ilpm.pyopencl_scripts.rk4_functions.print_output_test_actual_1stO(dx1t, dx1, dx2t, dx2, dx3t, dx3, dx4t, dx4, xyoutt, xyout)[source]

Print the test (numpy) and actual (OpenCL) output of a 1st order Runge-Kutta 4th order evaluation.