Skip to content

Commit

Permalink
improve Symmetry search
Browse files Browse the repository at this point in the history
  • Loading branch information
hob committed Jan 19, 2025
1 parent 6e31723 commit 9efba73
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 25 deletions.
5 changes: 4 additions & 1 deletion src/femagtools/dxfsl/area.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,10 @@ def get_nearest_point(self, center, radius, angle):
def get_alpha(self, center):
if self.center_is_inside(center):
return np.pi*2.0
return alpha_angle(self.min_angle, self.max_angle)
return alpha_angle(self.min_angle,
self.max_angle,
rtol=0.0,
atol=0.0)

def get_mid_angle(self, center):
if self.center_is_inside(center):
Expand Down
4 changes: 2 additions & 2 deletions src/femagtools/dxfsl/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ def alpha_triangle(a, b, c):
return rslt


def alpha_angle(startangle, endangle):
if less_equal(endangle, startangle):
def alpha_angle(startangle, endangle, rtol=1e-3, atol=1e-8):
if less_equal(endangle, startangle, rtol=rtol, atol=atol):
endangle += 2.0*np.pi
angle = endangle - startangle
if less_equal(angle, 2.0*np.pi):
Expand Down
10 changes: 7 additions & 3 deletions src/femagtools/dxfsl/machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,9 +645,13 @@ def find_symmetry(self, sym_tolerance, is_inner, is_outer, plt):
parts = symmetry.find_symmetry() # temp solution
logger.debug(">>> Symmetry parts = %s <<<", parts)

if parts > 1:
found = True
else:
if parts == 1:
# no slices, but ok
return False

found = (parts > 1)

if not found:
found = self.geom.find_symmetry(self.radius,
self.startangle,
self.endangle,
Expand Down
48 changes: 29 additions & 19 deletions src/femagtools/dxfsl/symmetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,15 @@ def build_area_list(self, types=()):
areas.sort(reverse=True)
return areas

def get_equal_areas(self, areas):
return

def build_results(self, areas):
logger.debug("begin of build_results with %s areas", len(areas))
[logger.debug("#%s: alpha=%s, min=%s, max=%s",
a.get_id(), alpha, a.min_angle, a.max_angle) for
alpha, dist, h, mid, a in areas]

a0_alpha, a0_min_dist, a0_height, a0_mid_angle, a0 = areas[0]
equal_areas = [(a0_mid_angle, a0)]
check_rslt = []
Expand Down Expand Up @@ -164,6 +172,7 @@ def build_results(self, areas):
rslt['area'] = a0
rslt['areasize'] = areasize
check_rslt.append((areasize, rslt))
logger.debug("end of build_results")
return check_rslt

def get_winding_symmetry(self, inside=False):
Expand Down Expand Up @@ -246,7 +255,6 @@ def find_symmetry(self):

check_rslt = self.build_results(areas)
logger.debug("%s results available", len(check_rslt))
[logger.debug("Result: %s", rslt) for rslt in check_rslt]

parts, start_delta = self.get_symmetry_parts(check_rslt)
if parts < 2:
Expand Down Expand Up @@ -743,31 +751,33 @@ def get_symmetry_parts(self, check_rslt):
for size, n, rslt in check_rslt:
areas = rslt['areas']
slices = rslt['slices']
if slices is None:
continue

size = rslt['areasize']
angle_corr = rslt.get('delta_corr', 0.0)

if rslt.get('halfslice', 0) == 1:
halfslice.append(rslt)

if slices is not None:
if slices > 0:
max_size = max(max_size, size)
max_areas = max(max_areas, areas)
max_slices = max(max_slices, slices)
missing_middles += rslt.get('missing_middles', [])
area = rslt['area']
if not (np.isclose(area.min_dist,
self.geom.min_radius,
rtol=1e-4, atol=1e-3) and \
np.isclose(area.max_dist,
self.geom.max_radius,
rtol=1e-4, atol=1e-3)):
if rslt.get('delta_corr', 0.0) == 0.0:
without_angle_corr += areas * size
else:
with_angle_corr += areas * size
if slices > 0:
max_size = max(max_size, size)
max_areas = max(max_areas, areas)
max_slices = max(max_slices, slices)
missing_middles += rslt.get('missing_middles', [])
area = rslt['area']
if not (np.isclose(area.min_dist,
self.geom.min_radius,
rtol=1e-4, atol=1e-3) and \
np.isclose(area.max_dist,
self.geom.max_radius,
rtol=1e-4, atol=1e-3)):
if rslt.get('delta_corr', 0.0) == 0.0:
without_angle_corr += areas * size
else:
maybe_angle_korr += areas * size
with_angle_corr += areas * size
else:
maybe_angle_korr += areas * size
logger.debug("max size: %s, max areas: %s", max_size, max_areas)

logger.debug("Angle-Corrections: %s Yes, %s No",
Expand Down

0 comments on commit 9efba73

Please sign in to comment.