# magpylib.source.current package¶

This subpackage provides the current classes that are used for field computation. They include the classes Circular (a current loop) and Line (a line current running along given vertices).

class `magpylib.source.current.``Circular`(curr=0.0, dim=0.0, pos=(0.0, 0.0, 0.0), angle=0.0, axis=(0.0, 0.0, 1.0))[source]

Bases: `magpylib._lib.classes.base.LineCurrent`

A circular line current loop with diameter dim and a current curr flowing in positive orientation. In the canonical basis (position=[0,0,0], angle=0.0, axis=[0,0,1]) the loop lies in the x-y plane with the origin at its center. Scalar input is either integer or float. Vector input format can be either list, tuple or array of any data type (float, int).

Parameters: curr (scalar [A]) – Set current in loop in units of [A] dim (float [mm]) – Set diameter of current loop in units of [mm] pos=[0,0,0] (vec3 [mm]) – Set position of the center of the current loop in units of [mm]. angle=0.0 (scalar [deg]) – Set angle of orientation of current loop in units of [deg]. axis=[0,0,1] (vec3 []) – Set axis of orientation of the current loop.
`current`

Current in loop in units of [A]

Type: float [A]
`dimension`

Loop diameter in units of [mm]

Type: float [mm]
`position`

Position of center of loop in units of [mm]

Type: arr3 [mm]
`angle`

Angle of orientation of the current loop.

Type: float [deg]
`axis`

Axis of orientation of the current loop.

Type: arr3 []

Example

```>>> from magpylib import source
>>> cd = source.current.Circular(curr=10,dim=2)
>>> B = cd.getB([0,0,2])
>>> print(B)
[0.         0.         0.56198518]
```

Note

The following Methods are available to all sources objects.

`getB`(pos)[source]

This method returns the magnetic field vector generated by the source at the argument position pos in units of [mT]

Parameters: pos (vec3 [mm] Position or list of Positions where magnetic field) – should be determined. magnetic field vector – position pos generated by the source in units of [mT]. arr3 [mT] Magnetic field at the argument
`move`(displacement)

This method moves the source by the argument vector displacement. Vector input format can be either list, tuple or array of any data type (float, int).

Parameters: displacement (vec3 [mm]) – Set displacement vector None

Example

```>>> from magpylib import source
>>> pm = source.magnet.Sphere(mag=[0,0,1000],dim=1,pos=[1,2,3])
>>> print(pm.position)
[1. 2. 3.]
>>> pm.move([3,2,1])
>>> print(pm.position)
[4. 4. 4.]
```
`rotate`(angle, axis, anchor='self.position')

This method rotates the source about axis by angle. The axis passes through the center of rotation anchor. Scalar input is either integer or float. Vector input format can be either list, tuple or array of any data type (float, int).

Parameters: angle (scalar [deg]) – Set angle of rotation in units of [deg] axis (vec3 []) – Set axis of rotation anchor (vec3 [mm]) – Specify the Center of rotation which defines the position of the axis of rotation. If not specified the source will rotate about its own center. None

Example

```>>> from magpylib import source
>>> pm = source.magnet.Sphere(mag=[0,0,1000], dim=1)
>>> print(pm.position, pm.angle, pm.axis)
[0. 0. 0.] 0.0 [0. 0. 1.]
>>> pm.rotate(90, [0,1,0], anchor=[1,0,0])
>>> print(pm.position, pm.angle, pm.axis)
[1., 0., 1.] 90.0 [0., 1., 0.]
```
`setOrientation`(angle, axis)

This method sets a new source orientation given by angle and axis. Scalar input is either integer or float. Vector input format can be either list, tuple or array of any data type (float, int).

Parameters: angle (scalar [deg]) – Set new angle of source orientation. axis (vec3 []) – Set new axis of source orientation. None

Example

```>>> from magpylib import source
>>> pm = source.magnet.Sphere(mag=[0,0,1000],dim=1)
>>> print([pm.angle,pm.axis])
[0.0, array([0., 0., 1.])]
>>> pm.setOrientation(45,[0,1,0])
>>> print([pm.angle,pm.axis])
[45.0, array([0., 1., 0.])]
```
`setPosition`(newPos)

This method moves the source to the position given by the argument vector newPos. Vector input format can be either list, tuple or array of any data type (float, int)

Parameters: newPos (vec3 [mm]) – Set new position of the source. None

Example

```>>> from magpylib import source
>>> pm = source.magnet.Sphere(mag=[0,0,1000],dim=1)
>>> print(pm.position)
[0. 0. 0.]
>>> pm.setPosition([5,5,5])
>>> print(pm.position)
[5. 5. 5.]
```
class `magpylib.source.current.``Line`(curr=0.0, vertices=typing.List[typing.Tuple[~x_i, ~y_i, ~z_i]], pos=(0.0, 0.0, 0.0), angle=0.0, axis=(0.0, 0.0, 1.0))[source]

Bases: `magpylib._lib.classes.base.LineCurrent`

A line current flowing along linear segments from vertex to vertex given by a list of positions vertices in the canonical basis (position=[0,0,0], angle=0.0, axis=[0,0,1]). Scalar input is either integer or float. Vector input format can be either list, tuple or array of any data type (float, int).

Parameters: curr (scalar [A]) – Set current in loop in units of [A] vertices (vecNx3 [mm]) – N positions given in units of [mm] that make up N-1 linear segments along which the current curr flows, starting from the first position and ending with the last one. [[x,y,z], [x,y,z], …] “[pos1,pos2,…]” pos=[0,0,0] (vec3 [mm]) – Set reference position of the current distribution in units of [mm]. angle=0.0 (scalar [deg]) – Set angle of orientation of current distribution in units of [deg]. axis=[0,0,1] (vec3 []) – Set axis of orientation of the current distribution.
`current`

Current flowing along line in units of [A].

Type: float [A]
`vertices`

Positions of line current vertices in units of [mm].

Type: arrNx3 [mm]
`position`

Reference position of line current in units of [mm].

Type: arr3 [mm]
`angle`

Angle of orientation of line current in units of [deg].

Type: float [deg]
`axis`

Axis of orientation of the line current.

Type: arr3 []

Examples

```>>> from magpylib import source
>>> from numpy import sin,cos,pi,linspace
>>> vertices = [[cos(phi),sin(phi),0] for phi in linspace(0,2*pi,36)]
>>> cd = source.current.Line(curr=10,vertices=vertices)
>>> B = cd.getB([0,0,2])
>>> print(B)
[-6.24500451e-17  1.73472348e-18  5.59871233e-01]
```

Note

The following Methods are available to all sources objects.

`getB`(pos)[source]

This method returns the magnetic field vector generated by the source at the argument position pos in units of [mT]

Parameters: pos (vec3 [mm] Position or list of Positions where magnetic field) – should be determined. magnetic field vector – position pos generated by the source in units of [mT]. arr3 [mT] Magnetic field at the argument
`move`(displacement)

This method moves the source by the argument vector displacement. Vector input format can be either list, tuple or array of any data type (float, int).

Parameters: displacement (vec3 [mm]) – Set displacement vector None

Example

```>>> from magpylib import source
>>> pm = source.magnet.Sphere(mag=[0,0,1000],dim=1,pos=[1,2,3])
>>> print(pm.position)
[1. 2. 3.]
>>> pm.move([3,2,1])
>>> print(pm.position)
[4. 4. 4.]
```
`rotate`(angle, axis, anchor='self.position')

This method rotates the source about axis by angle. The axis passes through the center of rotation anchor. Scalar input is either integer or float. Vector input format can be either list, tuple or array of any data type (float, int).

Parameters: angle (scalar [deg]) – Set angle of rotation in units of [deg] axis (vec3 []) – Set axis of rotation anchor (vec3 [mm]) – Specify the Center of rotation which defines the position of the axis of rotation. If not specified the source will rotate about its own center. None

Example

```>>> from magpylib import source
>>> pm = source.magnet.Sphere(mag=[0,0,1000], dim=1)
>>> print(pm.position, pm.angle, pm.axis)
[0. 0. 0.] 0.0 [0. 0. 1.]
>>> pm.rotate(90, [0,1,0], anchor=[1,0,0])
>>> print(pm.position, pm.angle, pm.axis)
[1., 0., 1.] 90.0 [0., 1., 0.]
```
`setOrientation`(angle, axis)

This method sets a new source orientation given by angle and axis. Scalar input is either integer or float. Vector input format can be either list, tuple or array of any data type (float, int).

Parameters: angle (scalar [deg]) – Set new angle of source orientation. axis (vec3 []) – Set new axis of source orientation. None

Example

```>>> from magpylib import source
>>> pm = source.magnet.Sphere(mag=[0,0,1000],dim=1)
>>> print([pm.angle,pm.axis])
[0.0, array([0., 0., 1.])]
>>> pm.setOrientation(45,[0,1,0])
>>> print([pm.angle,pm.axis])
[45.0, array([0., 1., 0.])]
```
`setPosition`(newPos)

This method moves the source to the position given by the argument vector newPos. Vector input format can be either list, tuple or array of any data type (float, int)

Parameters: newPos (vec3 [mm]) – Set new position of the source. None

Example

```>>> from magpylib import source
>>> pm = source.magnet.Sphere(mag=[0,0,1000],dim=1)
>>> print(pm.position)
[0. 0. 0.]
>>> pm.setPosition([5,5,5])
>>> print(pm.position)
[5. 5. 5.]
```