irfpy.util.streamline

Tracing a field to make a stream line

Code author: Yoshifumi Futaana

Any vector field, B(x,y,z), is traced from a given point (x0,y0,z0).

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)dtdy=By(x,y,z)dtdz=Bz(x,y,z)dt

For numerical calculation, we use Runge-Kutta 4.

ri+1=ri+Δt6(k1+2k2+2k3+k4)

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

k1=B(ri)k2=B(ri+Δt2k1)k3=B(ri+Δt2k2)k4=B(ri+Δtk3)

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=xBy=0Bz=x2+z2

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]