16
16
from ..types import MatrixReal4x4 , Shapely
17
17
from ...log import log
18
18
from ...exceptions import SetupError , ValidationError
19
- from ...constants import MICROMETER , fp_eps
19
+ from ...constants import MICROMETER , fp_eps , LARGE_NUMBER
20
20
from ...packaging import verify_packages_import
21
21
22
22
from . import base
@@ -353,6 +353,8 @@ def center_axis(self) -> float:
353
353
zmin , zmax = self .slab_bounds
354
354
if np .isneginf (zmin ) and np .isposinf (zmax ):
355
355
return 0.0
356
+ zmin = max (zmin , - LARGE_NUMBER )
357
+ zmax = min (zmax , LARGE_NUMBER )
356
358
return (zmax + zmin ) / 2.0
357
359
358
360
@property
@@ -386,7 +388,7 @@ def middle_polygon(self) -> np.ndarray:
386
388
The vertices of the polygon at the middle.
387
389
"""
388
390
389
- dist = self ._extrusion_length_to_offset_distance (self .length_axis / 2 )
391
+ dist = self ._extrusion_length_to_offset_distance (self .finite_length_axis / 2 )
390
392
if self .reference_plane == "bottom" :
391
393
return self ._shift_vertices (self .reference_polygon , dist )[0 ]
392
394
if self .reference_plane == "top" :
@@ -405,7 +407,7 @@ def base_polygon(self) -> np.ndarray:
405
407
"""
406
408
if self .reference_plane == "bottom" :
407
409
return self .reference_polygon
408
- dist = self ._extrusion_length_to_offset_distance (- self .length_axis / 2 )
410
+ dist = self ._extrusion_length_to_offset_distance (- self .finite_length_axis / 2 )
409
411
return self ._shift_vertices (self .middle_polygon , dist )[0 ]
410
412
411
413
@cached_property
@@ -419,7 +421,7 @@ def top_polygon(self) -> np.ndarray:
419
421
"""
420
422
if self .reference_plane == "top" :
421
423
return self .reference_polygon
422
- dist = self ._extrusion_length_to_offset_distance (self .length_axis / 2 )
424
+ dist = self ._extrusion_length_to_offset_distance (self .finite_length_axis / 2 )
423
425
return self ._shift_vertices (self .middle_polygon , dist )[0 ]
424
426
425
427
@cached_property
@@ -461,7 +463,7 @@ def inside(
461
463
462
464
z0 = self .center_axis
463
465
dist_z = np .abs (z - z0 )
464
- inside_height = dist_z <= (self .length_axis / 2 )
466
+ inside_height = dist_z <= (self .finite_length_axis / 2 )
465
467
466
468
# avoid going into face checking if no points are inside slab bounds
467
469
if not np .any (inside_height ):
@@ -646,14 +648,14 @@ def _intersections_side(self, position, axis) -> list:
646
648
647
649
# find out all z_i where the plane will intersect the vertex
648
650
z0 = self .center_axis
649
- z_base = z0 - self .length_axis / 2
651
+ z_base = z0 - self .finite_length_axis / 2
650
652
651
653
axis_ordered = self ._order_axis (axis )
652
654
height_list = self ._find_intersecting_height (position , axis_ordered )
653
655
polys = []
654
656
655
657
# looping through z_i to assemble the polygons
656
- height_list = np .append (height_list , self .length_axis )
658
+ height_list = np .append (height_list , self .finite_length_axis )
657
659
h_base = 0.0
658
660
for h_top in height_list :
659
661
# length within between top and bottom
@@ -670,7 +672,7 @@ def _intersections_side(self, position, axis) -> list:
670
672
)
671
673
else :
672
674
# for slanted sidewall, move up by `fp_eps` in case vertices are degenerate at the base.
673
- dist = - (h_base - self .length_axis / 2 + fp_eps ) * self ._tanq
675
+ dist = - (h_base - self .finite_length_axis / 2 + fp_eps ) * self ._tanq
674
676
vertices = self ._shift_vertices (self .middle_polygon , dist )[0 ]
675
677
ints_y , ints_angle = self ._find_intersecting_ys_angle_slant (
676
678
vertices , position , axis_ordered
@@ -744,14 +746,14 @@ def _find_intersecting_height(self, position: float, axis: int) -> np.ndarray:
744
746
745
747
# distance to the plane in the direction of vertex shifting
746
748
distance = self .middle_polygon [:, axis ] - position
747
- height = distance / self ._tanq / shift_val + self .length_axis / 2
749
+ height = distance / self ._tanq / shift_val + self .finite_length_axis / 2
748
750
height = np .unique (height )
749
751
# further filter very close ones
750
752
is_not_too_close = np .insert ((np .diff (height ) > fp_eps ), 0 , True )
751
753
height = height [is_not_too_close ]
752
754
753
755
height = height [height > fp_eps ]
754
- height = height [height < self .length_axis - fp_eps ]
756
+ height = height [height < self .finite_length_axis - fp_eps ]
755
757
return height
756
758
757
759
def _find_intersecting_ys_angle_vertical (
@@ -955,11 +957,11 @@ def bounds(self) -> Bound:
955
957
max_offset = self .dilation
956
958
if not isclose (self .sidewall_angle , 0 ):
957
959
if self .reference_plane == "bottom" :
958
- max_offset += max (0 , - self ._tanq * self .length_axis )
960
+ max_offset += max (0 , - self ._tanq * self .finite_length_axis )
959
961
elif self .reference_plane == "top" :
960
- max_offset += max (0 , self ._tanq * self .length_axis )
962
+ max_offset += max (0 , self ._tanq * self .finite_length_axis )
961
963
elif self .reference_plane == "middle" :
962
- max_offset += max (0 , abs (self ._tanq ) * self .length_axis / 2 )
964
+ max_offset += max (0 , abs (self ._tanq ) * self .finite_length_axis / 2 )
963
965
964
966
# special care when dilated
965
967
if max_offset > 0 :
@@ -1513,7 +1515,7 @@ def _dilation_length(self) -> List[float]:
1513
1515
"""dilation length from reference plane to the top/bottom of the polyslab."""
1514
1516
1515
1517
# for "bottom", only needs to compute the offset length to the top
1516
- dist = [self ._extrusion_length_to_offset_distance (self .length_axis )]
1518
+ dist = [self ._extrusion_length_to_offset_distance (self .finite_length_axis )]
1517
1519
# reverse the dilation value if the reference plane is on the top
1518
1520
if self .reference_plane == "top" :
1519
1521
dist = [- dist [0 ]]
@@ -1527,9 +1529,9 @@ def _dilation_value_at_reference_to_coord(self, dilation: float) -> float:
1527
1529
1528
1530
z_coord = - dilation / self ._tanq + self .slab_bounds [0 ]
1529
1531
if self .reference_plane == "middle" :
1530
- return z_coord + self .length_axis / 2
1532
+ return z_coord + self .finite_length_axis / 2
1531
1533
if self .reference_plane == "top" :
1532
- return z_coord + self .length_axis
1534
+ return z_coord + self .finite_length_axis
1533
1535
# bottom case
1534
1536
return z_coord
1535
1537
0 commit comments