# irfpy.util.domain¶

Represents the domain (the region) in 3D.

The domain is the region where some functionalities are defined (in math) or the region of the same property (in space physics).

For example, any numerical simulations are conducted in a limited region, e.g. R<10Re. This is a spherical domain (SphericalDomain). Other implementation is the Martian Induced magnetosphere, which is variable in time, but can be considered as a domain.

class irfpy.util.domain.BaseStaticDomain[source]

Bases: object

A base class of a domain without time variation.

abstract contains(xyz)[source]

Determine the given coordinate is inside of the region.

Parameters:

xyz – x, y, z position. (3,) shaped list, tuple or array.

Returns:

True if inside, False if outside.

The method returns True if the given point is inside the region.

Note: Whether or not the boundary is inside or outside is fully reposinible to the developer of this method.

evaluates(xcoords, ycoords, zcoords)[source]

Vectorized version of the contains().

The evaluation done in contains() can be done for (N, 3) shaped array. The developer can override this method for optimized vectorization. Without the override, the method contains() is called N times.

Parameters:
• xarr – Array of x-coordinates

• yarr – Array of y-coordinates

• zarr – Array of z-coordinates

Returns:

(N,) shaped boolean array.

>>> x = [0, 1, 2, 3]
>>> y = [0, 1, 2, 3]
>>> z = [0, 1, 2, 3]
>>> cartDomain = CartesianDomain([0, 1], [0, 1], [0, 1])   # Cartesian domain.
>>> print(cartDomain.evaluates(x, y, z))
[ True  True False False]

class irfpy.util.domain.InfiniteDomain[source]

Domain extending to the inifinity.

Infinitely-extending domain (indicating that the contains() always returns True). Usually, you can use the pre-defined variable infinite_domain.

>>> infinite_domain.contains((3, 5, 10))
True

contains(xyz)[source]

Determine the given coordinate is inside of the region.

Parameters:

xyz – x, y, z position. (3,) shaped list, tuple or array.

Returns:

True if inside, False if outside.

The method returns True if the given point is inside the region.

Note: Whether or not the boundary is inside or outside is fully reposinible to the developer of this method.

irfpy.util.domain.infinite_domain = <irfpy.util.domain.InfiniteDomain object>

An instance of InfiniteDomain.

class irfpy.util.domain.CartesianDomain(xrange, yrange, zrange)[source]

Domain with a bound defined by x, y, and z ranges.

The x-, y-, and z-ranged cuboid is considered as a domain.

The following statement will create a domain between -10 and 10 for all three directions.

>>> cartDomain = CartesianDomain([-10, 10], [-10, 10], [-10, 10])


To evaluate if the given point is in (or out) of the domain, you can use “in” statement, or contains() method.

>>> print([0, 0, 0] in cartDomain)
True
>>> print(cartDomain.contains([5, 7, -12]))
False


Note that the edges are inside the domain.

>>> print(cartDomain.contains([10, 10, 10]))
True


To evauate multiple points by one call, use evaluate() method.

>>> print(cartDomain.evaluates([0, 10, 20, 30], [0, 10, 20, 30], [0, 10, 20, 30]))
[ True  True False False]


Define the domain

Parameters:
• xrange – (xmin, xmax)

• yrange – (ymin, ymax)

• zrange – (zmin, zmax)

contains(xyz)[source]

Determine the given coordinate is inside of the region.

Parameters:

xyz – x, y, z position. (3,) shaped list, tuple or array.

Returns:

True if inside, False if outside.

The method returns True if the given point is inside the region.

Note: Whether or not the boundary is inside or outside is fully reposinible to the developer of this method.

class irfpy.util.domain.SphereDomain(r_outer, r_inner=0, center=[0, 0, 0])[source]

Domain with a spherical shape.

>>> sphDomain = SphereDomain(10)   # Sphere with radius of 10.

>>> print([0, 0, 0] in sphDomain)
True
>>> print([0, 10, 0] in sphDomain)
True
>>> print([-20, 0, 0] in sphDomain)
False

>>> sphDomain2 = SphereDomain(10, center=[10, 10, 10])  # Given the center location.
>>> print([0, 0, 0] in sphDomain2)
False
>>> print([10, 10, 0] in sphDomain2)
True

>>> sphDomain3 = SphereDomain(10, r_inner=5)   # Shell-like: Radius between 5 and 10.
>>> print([0, 0, 0] in sphDomain3)
False
>>> print([0, 5, 0] in sphDomain3)
True
>>> print([0, 0, -10] in sphDomain3)
True

contains(xyz)[source]

Determine the given coordinate is inside of the region.

Parameters:

xyz – x, y, z position. (3,) shaped list, tuple or array.

Returns:

True if inside, False if outside.

The method returns True if the given point is inside the region.

Note: Whether or not the boundary is inside or outside is fully reposinible to the developer of this method.

evaluates(xcoords, ycoords, zcoords)[source]

Multiple points are evaluated

For this SphereDomain class, use evaluate() method if you want to evaluate multiple point for better performance.

Parameters:
• xcoords – X coordinates

• ycoords – Y coordinates

• zcoords – Z coordinates

Returns:

Bool array (True for in domain, False for out of domain)

>>> x = [0, 0, -20, 0]
>>> y = [0, 10, 0, 0]
>>> z = [0, 0, 0, 8]

>>> sphDomain = SphereDomain(10, r_inner=5)
>>> print(sphDomain.evaluates(x, y, z))
[False  True False  True]

class irfpy.util.domain.IntersectDomain(dom1, dom2)[source]

Create a domain intersected with two domains.

>>> dom1 = SphereDomain(10, center=(-5, 0, 0))
>>> dom2 = SphereDomain(10, center=(5, 0, 0))
>>> idom = IntersectDomain(dom1, dom2)


Here two spherical shaped domains are intersected to idom.

The origin is both in dom1 and dom2 and thus in idom.

>>> print([0, 0, 0] in idom)
True


[-15, 0, 0] is only for dom1, so that idom returns false.

>>> print([-15, 0, 0] in dom1)
True
>>> print([-15, 0, 0] in dom2)
False
>>> print([-15, 0, 0] in idom)
False

Parameters:
• dom1 – A domain

• dom2 – Another domain

Returns:

New domain intersecting dom1 and dom2.

contains(xyz)[source]

Determine the given coordinate is inside of the region.

Parameters:

xyz – x, y, z position. (3,) shaped list, tuple or array.

Returns:

True if inside, False if outside.

The method returns True if the given point is inside the region.

Note: Whether or not the boundary is inside or outside is fully reposinible to the developer of this method.

evaluates(xcoords, ycoords, zcoords)[source]

Vectorized version of the contains().

The evaluation done in contains() can be done for (N, 3) shaped array. The developer can override this method for optimized vectorization. Without the override, the method contains() is called N times.

Parameters:
• xarr – Array of x-coordinates

• yarr – Array of y-coordinates

• zarr – Array of z-coordinates

Returns:

(N,) shaped boolean array.

>>> x = [0, 1, 2, 3]
>>> y = [0, 1, 2, 3]
>>> z = [0, 1, 2, 3]
>>> cartDomain = CartesianDomain([0, 1], [0, 1], [0, 1])   # Cartesian domain.
>>> print(cartDomain.evaluates(x, y, z))
[ True  True False False]