Region facing surfaces#

For two regions, sometimes it is necessary to find whether there are any facing surfaces. If there are, along which axis and at what coordinates.

As an example let us set up two regions “stacked” in the \(z\)-direction.

[1]:
import discretisedfield as df  # df is here chosen to be an alias for discretisedfield

p11 = (0, 0, 0)
p12 = (100e-9, 50e-9, 20e-9)
region1 = df.Region(p1=p11, p2=p12)

p21 = (0, 0, 20e-9)
p22 = (100e-9, 50e-9, 30e-9)
region2 = df.Region(p1=p21, p2=p22)

To find the facing surfaces, we use the facing_surface method:

[2]:
region1.facing_surface(region2)
[2]:
('z',
 Region(pmin=[0.0, 0.0, 0.0], pmax=[1e-07, 5e-08, 2e-08], dims=['x', 'y', 'z'], units=['m', 'm', 'm']),
 Region(pmin=[0.0, 0.0, 2e-08], pmax=[1e-07, 5e-08, 3e-08], dims=['x', 'y', 'z'], units=['m', 'm', 'm']))

As a result, we get a length-3 tuple. The first element is the axis the facing surfaces are perpendicular to. In our example, it is the \(z\) axis. Now, if we start moving along the \(z\)-axis (e.g. from minus infinity) the first region we are going to enter is the region which is the second element of our tuple. When we leave that region, we enter the second region, which is the third element of our tuple.

If no facing surfaces can be identified, TypeError is raised. For instance, if we have overlapping regions:

[3]:
p11 = (0, 0, 0)
p12 = (100e-9, 50e-9, 20e-9)
region1 = df.Region(p1=p11, p2=p12)

p21 = (0, 0, 10e-9)
p22 = (100e-9, 50e-9, 30e-9)
region2 = df.Region(p1=p21, p2=p22)

try:
    region1.facing_surface(region2)
except ValueError:
    print("Exception raised.")
Exception raised.