Skip to content

Commit

Permalink
remove duplicate code by switching p+ and groove construction to a se…
Browse files Browse the repository at this point in the history
…perate method
  • Loading branch information
tdixon97 committed Nov 2, 2024
1 parent b8bbb80 commit e96a3a8
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 165 deletions.
45 changes: 5 additions & 40 deletions src/legendhpges/bege.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import math

from .base import HPGe
from .utils import make_pplus


class BEGe(HPGe):
Expand All @@ -18,46 +19,10 @@ def _tan(a):
z = []
surfaces = []

if c.pp_contact.depth_in_mm > 0:
r += [
0,
c.pp_contact.radius_in_mm,
c.pp_contact.radius_in_mm,
c.groove.radius_in_mm.inner,
]
z += [
c.pp_contact.depth_in_mm,
c.pp_contact.depth_in_mm,
0,
0,
]
surfaces += ["p+", "passive", "passive"]

elif c.pp_contact.radius_in_mm < c.groove.radius_in_mm.inner:
r += [
0,
c.pp_contact.radius_in_mm,
c.groove.radius_in_mm.inner,
]
z += [0, 0, 0]
surfaces += ["p+", "passive"]
else:
r += [0, c.pp_contact.radius_in_mm]
z += [0, 0]
surfaces += ["p+"]

r += [
c.groove.radius_in_mm.inner,
c.groove.radius_in_mm.outer,
c.groove.radius_in_mm.outer,
]

z += [
c.groove.depth_in_mm,
c.groove.depth_in_mm,
0,
]
surfaces += ["passive", "passive", "passive"]
r_p, z_p, surface_p = make_pplus(c)
r += r_p
z += z_p
surfaces += surface_p

if c.taper.bottom.height_in_mm > 0:
r += [
Expand Down
45 changes: 5 additions & 40 deletions src/legendhpges/invcoax.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import math

from .base import HPGe
from .utils import make_pplus


class InvertedCoax(HPGe):
Expand All @@ -18,46 +19,10 @@ def _tan(a):
z = []
surfaces = []

if c.pp_contact.depth_in_mm > 0:
r += [
0,
c.pp_contact.radius_in_mm,
c.pp_contact.radius_in_mm,
c.groove.radius_in_mm.inner,
]
z += [
c.pp_contact.depth_in_mm,
c.pp_contact.depth_in_mm,
0,
0,
]
surfaces += ["p+", "passive", "passive"]

elif c.pp_contact.radius_in_mm < c.groove.radius_in_mm.inner:
r += [
0,
c.pp_contact.radius_in_mm,
c.groove.radius_in_mm.inner,
]
z += [0, 0, 0]
surfaces += ["p+", "passive"]
else:
r += [0, c.pp_contact.radius_in_mm]
z += [0, 0]
surfaces += ["p+"]

r += [
c.groove.radius_in_mm.inner,
c.groove.radius_in_mm.outer,
c.groove.radius_in_mm.outer,
]

z += [
c.groove.depth_in_mm,
c.groove.depth_in_mm,
0,
]
surfaces += ["passive", "passive", "passive"]
r_p, z_p, surface_p = make_pplus(c)
r += r_p
z += z_p
surfaces += surface_p

if c.taper.bottom.height_in_mm > 0:
r += [
Expand Down
63 changes: 63 additions & 0 deletions src/legendhpges/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,69 @@
import numpy as np


def make_pplus(geometry: dict) -> tuple[list, list, list]:
"""Make the p+ contact for BeGe and some ICPC
Methods to avoid duplicating code.
Parameters
----------
geometry
Dictionary with the geometry information.
Returns
-------
(r,z,surfaces)
Tuple of lists of r,z coordinates and surface names.
"""
r = []
z = []
surfaces = []

if geometry.pp_contact.depth_in_mm > 0:
r += [
0,
geometry.pp_contact.radius_in_mm,
geometry.pp_contact.radius_in_mm,
geometry.groove.radius_in_mm.inner,
]
z += [
geometry.pp_contact.depth_in_mm,
geometry.pp_contact.depth_in_mm,
0,
0,
]
surfaces += ["p+", "passive", "passive"]

elif geometry.pp_contact.radius_in_mm < geometry.groove.radius_in_mm.inner:
r += [
0,
geometry.pp_contact.radius_in_mm,
geometry.groove.radius_in_mm.inner,
]
z += [0, 0, 0]
surfaces += ["p+", "passive"]
else:
r += [0, geometry.pp_contact.radius_in_mm]
z += [0, 0]
surfaces += ["p+"]

r += [
geometry.groove.radius_in_mm.inner,
geometry.groove.radius_in_mm.outer,
geometry.groove.radius_in_mm.outer,
]

z += [
geometry.groove.depth_in_mm,
geometry.groove.depth_in_mm,
0,
]
surfaces += ["passive", "passive", "passive"]

return (r, z, surfaces)


def convert_coords(coords: np.ndarray) -> np.ndarray:
"""Converts (x,y,zx) coordinates into (r,z)
Expand Down
47 changes: 19 additions & 28 deletions src/legendhpges/v02160a.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from .base import HPGe
from .registry import default_units_registry as u
from .utils import make_pplus


class V02160A(HPGe):
Expand Down Expand Up @@ -59,35 +60,12 @@ def _tan(a):

r = []
z = []
surfaces = []

if c.pp_contact.depth_in_mm > 0:
r += [
0,
c.pp_contact.radius_in_mm,
c.pp_contact.radius_in_mm,
]
z += [
c.pp_contact.depth_in_mm,
c.pp_contact.depth_in_mm,
0,
]
else:
r += [0]
z += [0]

r += [
c.groove.radius_in_mm.inner,
c.groove.radius_in_mm.inner,
c.groove.radius_in_mm.outer,
c.groove.radius_in_mm.outer,
]

z += [
0,
c.groove.depth_in_mm,
c.groove.depth_in_mm,
0,
]
r_p, z_p, surface_p = make_pplus(c)
r += r_p
z += z_p
surfaces += surface_p

if c.taper.bottom.height_in_mm > 0:
r += [
Expand All @@ -100,9 +78,12 @@ def _tan(a):
0,
c.taper.bottom.height_in_mm,
]

surfaces += ["n+", "n+"]
else:
r += [c.radius_in_mm]
z += [0]
surfaces += ["n+"]

if c.taper.top.height_in_mm > 0:
r += [
Expand All @@ -115,9 +96,12 @@ def _tan(a):
c.height_in_mm - c.taper.top.height_in_mm,
c.height_in_mm,
]
surfaces += ["n+", "n+"]

else:
r += [c.radius_in_mm]
z += [c.height_in_mm]
surfaces += ["n+"]

if c.taper.borehole.height_in_mm > 0:
r += [
Expand All @@ -130,9 +114,11 @@ def _tan(a):
c.height_in_mm,
c.height_in_mm - c.taper.borehole.height_in_mm,
]
surfaces += ["n+", "n+"]
else:
r += [c.borehole.radius_in_mm]
z += [c.height_in_mm]
surfaces += ["n+"]

if c.taper.borehole.height_in_mm != c.borehole.depth_in_mm:
r += [
Expand All @@ -144,11 +130,16 @@ def _tan(a):
c.height_in_mm - c.borehole.depth_in_mm,
c.height_in_mm - c.borehole.depth_in_mm,
]
surfaces += ["n+", "n+"]
else:
r += [0]

z += [c.height_in_mm - c.borehole.depth_in_mm]

surfaces += ["n+"]

self.surfaces = surfaces

return r, z

@property
Expand Down
45 changes: 16 additions & 29 deletions src/legendhpges/v02162b.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import math

from .base import HPGe
from .utils import make_pplus


class V02162B(HPGe):
Expand All @@ -16,35 +17,12 @@ def _tan(a):

r = []
z = []
surfaces = []

if c.pp_contact.depth_in_mm > 0:
r += [
0,
c.pp_contact.radius_in_mm,
c.pp_contact.radius_in_mm,
]
z += [
c.pp_contact.depth_in_mm,
c.pp_contact.depth_in_mm,
0,
]
else:
r += [0]
z += [0]

r += [
c.groove.radius_in_mm.inner,
c.groove.radius_in_mm.inner,
c.groove.radius_in_mm.outer,
c.groove.radius_in_mm.outer,
]

z += [
0,
c.groove.depth_in_mm,
c.groove.depth_in_mm,
0,
]
r_p, z_p, surface_p = make_pplus(c)
r += r_p
z += z_p
surfaces += surface_p

if c.taper.bottom.height_in_mm > 0:
r += [
Expand All @@ -57,9 +35,12 @@ def _tan(a):
0,
c.taper.bottom.height_in_mm,
]

surfaces += ["n+", "n+"]
else:
r += [c.radius_in_mm]
z += [0]
surfaces += ["n+"]

if c.taper.top.height_in_mm > 0:
r += [
Expand All @@ -72,15 +53,18 @@ def _tan(a):
c.height_in_mm - c.taper.top.height_in_mm,
c.height_in_mm,
]
surfaces += ["n+", "n+"]
else:
r += [c.radius_in_mm]
z += [c.height_in_mm]

surfaces += ["n+"]
# top groove
r += [c.extra.topgroove.radius_in_mm, c.extra.topgroove.radius_in_mm]

z += [c.height_in_mm, c.height_in_mm - c.extra.topgroove.depth_in_mm]

surfaces += ["n+", "n+"]

# borehole
r += [c.borehole.radius_in_mm, c.borehole.radius_in_mm, 0]

Expand All @@ -89,5 +73,8 @@ def _tan(a):
c.height_in_mm - c.borehole.depth_in_mm,
c.height_in_mm - c.borehole.depth_in_mm,
]
surfaces += ["n+", "n+", "n+"]

self.surfaces = surfaces

return r, z
Loading

0 comments on commit e96a3a8

Please sign in to comment.