# Fields¶

Fields are the distribution of quantities (scaler or vector) defined at any positions. For example, magnetic field, B, is a vector quantity defined at any position, x.

$\vec{B} = \vec{B}(\vec{x})$

## Module and classes¶

Implementation is in irfpy.util.fields module.

## A sample scalar field¶

A gravity potential is a first sample. The gravity potential produced by a mass of M at the origin is defined by

$\phi(x, y, z) = -\frac{GM}{r}$

with $$r=\sqrt{x^2+y^2+z^2}$$. G here is the gravity constant.

The gravity potential is implemented as irfpy.util.fields.GravityPotential class.

>>> from irfpy.util import fields
>>> phi_field = fields.GravityPotential(5.972e24)   # 5.972e24 kg for Earth mass
>>> phi_surface = phi_field([6378e3, 0, 0])     # 6378e3 is the earth radius in meter
>>> print(phi_surface)
-6.249233e+07


## A sample vector field¶

The example of a vector field is introduced here. A dipole magnetic field is a good example.

The implementation is available irfpy.util.fields.DipoleField.

Example below is for the Earth’s magnetic dipole, namely, the dipole moment of 8x10^22 A/m^2.

>>> from irfpy.util import fields
>>> geomag_field = fields.DipoleField([0, 0, -8e22], coefficient=DipoleField.MagneticCoefficient)
>>> geomag_surface = geomag([6378e3, 0, 0])     # Get the equator magnetic field at surface
>>> print(geomag_surface)
3.0834e-05


## Creating field¶

One can make the own field.

### Scalar field from function¶

irfpy.util.fields.FunctionScalarField3D class. Prepare a function. here f(x, y, z) = x + y + z

>>> import irfpy.util.fields
>>> fun = lambda x, y, z: x + y + z
>>> fun(1,2,3)
6
>>> field = irfpy.util.fields.FunctionScalarField(fun)
>>> field([1, 2, 3])
6


### Scalar field from gridded data¶

>>> xlist = np.array([0, 1, 2, 3, 4])
>>> ylist = np.array([0, 1, 2, 3])
>>> zlist = np.array([0, 1, 2])
>>> vallist = np.arange(60).reshape([5, 4, 3])
>>> gsf = GridScalarField3D(xlist, ylist, zlist, vallist)
>>> print(gsf.get(1, 2, 0))
18.0


## Operation¶

### Normal operations¶

• neg

• sub

• mul

• div

• power

• cross

For gridded scalar or vector field, derivatin operations are defined.

### Integral¶

Integral along a segment (line or zig-zag line or …) is done wilt irfpy.util.fields.IntegrateScalarField for scalar field.

### Conversion from function to grid¶

irfpy.util.fields.rebin_scalarfield() will produce a new field object fro the given points.

## Classes¶

(Draw class diagram)

digraph class_scalar_fields { GridScalarField3D -> ScalarField3D; FunctionScalarField3D -> ScalarField3D; GravityPotential -> FunctionScalarField3D; } digraph class_vector_fields { FunctionVactor3dField3D -> Vector3dField3D; GridVector3dField3D -> Vector3dField3D; UniformVector3dField -> FunctionVactor3dField3D; DipoleField -> FunctionVactor3dField3D; }