irfpy.util.streamline

Tracing a field to make a stream line

Code author: Yoshifumi Futaana

Any vector field, \(\mathbf{B}(x, y, z)\), is traced from a given point \((x_0, y_0, z_0)\).

See also the sample script at streamline_sample.

class irfpy.util.streamline.SimpleTracing(initpos, vector_field, dt)[source]

Bases: object

Simple tracing

The differential equations are

\[dx = Bx(x, y, z) dt dy = By(x, y, z) dt dz = Bz(x, y, z) dt \]

For numerical calculation, we use Runge-Kutta 4.

\[r_{i+1} = r_i + \frac{\Delta t}{6}(k_1 + 2k_2 + 2k_3 + k_4)\]

where r denotes (x, y, z). Each coefficients are

\[k_1 = B(r_i) k_2 = B(r_i + \frac{\Delta t}{2}k_1) k_3 = B(r_i + \frac{\Delta t}{2}k_2) k_4 = B(r_i + \Delta t k_3)\]

If one wants to backward trace, you may instance another object that gives -vector_field in the constructor.

An example is shown.

Assume a vector field as

\[Bx = x By = 0 Bz = \sqrt{x^2+z^2}\]

The vector_field should be a function that returns a vector, i.e.,

>>> vfield = lambda p: np.array((p[0], 0, np.sqrt(p[0]**2+p[2]**2)))

The vector_field should take np.array, returning np.array() object.

>>> tracer = SimpleTracing([1, 0, 1], vfield, 0.001)
>>> tracer.step_forward()
>>> print(tracer.x, tracer.y, tracer.z, tracer.tlist[-1])   
1.0010005001667084 0.0 1.0014150674450009 0.001
step_forward()[source]
irfpy.util.streamline.doctests()[source]