From e96a3a87377fa2db8926959c0adbfecf37f878c6 Mon Sep 17 00:00:00 2001 From: Toby Dixon Date: Sat, 2 Nov 2024 11:09:56 +0000 Subject: [PATCH] remove duplicate code by switching p+ and groove construction to a seperate method --- src/legendhpges/bege.py | 45 +++------------------------ src/legendhpges/invcoax.py | 45 +++------------------------ src/legendhpges/utils.py | 63 ++++++++++++++++++++++++++++++++++++++ src/legendhpges/v02160a.py | 47 ++++++++++++---------------- src/legendhpges/v02162b.py | 45 ++++++++++----------------- src/legendhpges/v07646a.py | 48 ++++++++++++----------------- 6 files changed, 128 insertions(+), 165 deletions(-) diff --git a/src/legendhpges/bege.py b/src/legendhpges/bege.py index 3f06a3c..e7654a9 100644 --- a/src/legendhpges/bege.py +++ b/src/legendhpges/bege.py @@ -3,6 +3,7 @@ import math from .base import HPGe +from .utils import make_pplus class BEGe(HPGe): @@ -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 += [ diff --git a/src/legendhpges/invcoax.py b/src/legendhpges/invcoax.py index 4ff9555..189a1e1 100644 --- a/src/legendhpges/invcoax.py +++ b/src/legendhpges/invcoax.py @@ -3,6 +3,7 @@ import math from .base import HPGe +from .utils import make_pplus class InvertedCoax(HPGe): @@ -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 += [ diff --git a/src/legendhpges/utils.py b/src/legendhpges/utils.py index 6c45b8e..b4ea319 100644 --- a/src/legendhpges/utils.py +++ b/src/legendhpges/utils.py @@ -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) diff --git a/src/legendhpges/v02160a.py b/src/legendhpges/v02160a.py index 57bcea4..5015c44 100644 --- a/src/legendhpges/v02160a.py +++ b/src/legendhpges/v02160a.py @@ -6,6 +6,7 @@ from .base import HPGe from .registry import default_units_registry as u +from .utils import make_pplus class V02160A(HPGe): @@ -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 += [ @@ -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 += [ @@ -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 += [ @@ -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 += [ @@ -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 diff --git a/src/legendhpges/v02162b.py b/src/legendhpges/v02162b.py index 3d85899..a0fe8a8 100644 --- a/src/legendhpges/v02162b.py +++ b/src/legendhpges/v02162b.py @@ -3,6 +3,7 @@ import math from .base import HPGe +from .utils import make_pplus class V02162B(HPGe): @@ -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 += [ @@ -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 += [ @@ -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] @@ -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 diff --git a/src/legendhpges/v07646a.py b/src/legendhpges/v07646a.py index f4ab64c..1444537 100644 --- a/src/legendhpges/v07646a.py +++ b/src/legendhpges/v07646a.py @@ -3,6 +3,7 @@ import math from .base import HPGe +from .utils import make_pplus class V07646A(HPGe): @@ -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 bottom_cylinder = c.extra.bottom_cylinder @@ -59,15 +37,18 @@ def _tan(a): 0, c.taper.bottom.height_in_mm, ] + surfaces += ["n+", "n+"] else: r += [bottom_cylinder.radius_in_mm] z += [0] + surfaces += ["n+"] r += [bottom_cylinder.radius_in_mm, c.radius_in_mm] z += [ bottom_cylinder.height_in_mm, bottom_cylinder.height_in_mm + bottom_cylinder.transition_in_mm, ] + surfaces += ["n+", "n+"] if c.taper.top.height_in_mm > 0: r += [ @@ -80,9 +61,11 @@ 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 += [ @@ -92,9 +75,12 @@ def _tan(a): ] z += [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 += [ @@ -106,9 +92,15 @@ 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