Create the Union of Domain Instances#

import minterpy as mp
import numpy as np

This guide demonstrates how to take the union of Domain instances and the expected outcome of such an operation. The union between to instances of Domain may be obtained via the | operator.

The union is possible if and only if the two instances are partially matching. If they are, the result is a new instance equal in value to the higher-dimensional operand. If they are not partially matching, a DomainMismatchError is raised.

Example: Union of two equal domains#

The two domains below are equal:

  • \(\Omega_1 = [1, 2] \times [3, 4]\)

  • \(\Omega_2 = [1, 2] \times [3, 4]\)

dom_1 = mp.Domain(np.array([[1, 2], [3, 4]]))
dom_2 = mp.Domain(np.array([[1, 2], [3, 4]]))

Their union is a new instance equal in value to both operands

dom_union = dom_1 | dom_2
dom_1 == dom_union, dom_2 == dom_union  # (True, True)
(True, True)
dom_1 is dom_union, dom_2 is dom_union  # (False, False)
(False, False)

Exception: When an instance is unioned with itself, it returns the same object rather creating a new one:

dom_1 is dom_1 | dom_1
True

Example: Union of unequal, but partially matching domains#

The two domains below are unequal but partially matching:

  • \(\Omega_3 = [1, 2] \times [4, 5]\)

  • \(\Omega_4 = [1, 2] \times [4, 5] \times [0, 1]\)

dom_3 = mp.Domain(np.array([[1, 2], [4, 5]]))
dom_4 = mp.Domain(np.array([[1, 2], [4, 5], [0, 1]]))

Their union is a new instance equal in value to the higher-dimensional operand:

dom_3 | dom_4 == dom_4  # True
True
dom_3 | dom_4 is dom_4  # False
False

Non-partially-matching domains#

If the two instances are note partially matching, the | operator raises a DomainMismatchError. For example, a domain \([-1, 1]\) and a domain \([0, 1] \times [0, 1]\) are not partially matching because the first dimension bounds differ such that their union cannot be formed.