From 0ddbaac369a421b02c91184fc5a2852f924665ff Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 9 May 2024 19:13:51 +0100 Subject: [PATCH 01/10] passing tolerance as arg not global var --- .github/workflows/documentation.yml | 1 + docs/python_api.rst | 4 + .../GEOUNED/Conversion/CellDefinition.py | 163 +++++++++--------- src/geouned/GEOUNED/Cuboid/translate.py | 23 ++- src/geouned/GEOUNED/Decompose/Decom_one.py | 128 +++++++------- .../GEOUNED/Utils/BasicFunctions_part2.py | 24 +-- src/geouned/GEOUNED/Utils/Functions.py | 78 +++++---- src/geouned/GEOUNED/Utils/Geometry_GU.py | 20 +-- src/geouned/GEOUNED/Utils/Options/Classes.py | 14 -- .../Utils/Options/tolerancesDefault.py | 53 ------ src/geouned/GEOUNED/Utils/data_classes.py | 57 ++++++ src/geouned/GEOUNED/Void/Void.py | 22 +-- src/geouned/GEOUNED/Void/VoidBoxClass.py | 4 +- src/geouned/GEOUNED/Write/Functions.py | 127 +++++++------- src/geouned/GEOUNED/Write/MCNPFormat.py | 5 +- src/geouned/GEOUNED/Write/OpenMCFormat.py | 7 +- src/geouned/GEOUNED/Write/PHITSFormat.py | 5 +- src/geouned/GEOUNED/Write/SerpentFormat.py | 12 +- src/geouned/GEOUNED/Write/WriteFiles.py | 10 +- src/geouned/GEOUNED/__init__.py | 52 +++--- tests/test_convert.py | 9 +- 21 files changed, 413 insertions(+), 405 deletions(-) delete mode 100644 src/geouned/GEOUNED/Utils/Options/tolerancesDefault.py diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 02852e02..41934563 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -8,6 +8,7 @@ on: push: branches: - main + - dev permissions: contents: write diff --git a/docs/python_api.rst b/docs/python_api.rst index 2b0a6f32..ec184e4e 100644 --- a/docs/python_api.rst +++ b/docs/python_api.rst @@ -9,5 +9,9 @@ Python API reference :show-inheritance: .. autoclass:: Options + :members: + :show-inheritance: + +.. autoclass:: Tolerances :members: :show-inheritance: \ No newline at end of file diff --git a/src/geouned/GEOUNED/Conversion/CellDefinition.py b/src/geouned/GEOUNED/Conversion/CellDefinition.py index 23a91855..f141d9e1 100644 --- a/src/geouned/GEOUNED/Conversion/CellDefinition.py +++ b/src/geouned/GEOUNED/Conversion/CellDefinition.py @@ -20,20 +20,19 @@ from ..Utils.booleanFunction import BoolSequence, insert_in_sequence from ..Utils.BooleanSolids import build_c_table_from_solids, remove_extra_surfaces from ..Utils.Functions import GeounedSurface -from ..Utils.Options.Classes import Tolerances as tol logger = logging.getLogger(__name__) -def get_id(facein, surfaces): +def get_id(facein, surfaces, tolerances): surfin = str(facein) if surfin == "": - if is_parallel(facein.Axis, FreeCAD.Vector(1, 0, 0), tol.pln_angle): + if is_parallel(facein.Axis, FreeCAD.Vector(1, 0, 0), tolerances.pln_angle): p = "PX" - elif is_parallel(facein.Axis, FreeCAD.Vector(0, 1, 0), tol.pln_angle): + elif is_parallel(facein.Axis, FreeCAD.Vector(0, 1, 0), tolerances.pln_angle): p = "PY" - elif is_parallel(facein.Axis, FreeCAD.Vector(0, 0, 1), tol.pln_angle): + elif is_parallel(facein.Axis, FreeCAD.Vector(0, 0, 1), tolerances.pln_angle): p = "PZ" else: p = "P" @@ -42,9 +41,10 @@ def get_id(facein, surfaces): if BF.is_same_plane( facein, s.Surf, - dtol=tol.pln_distance, - atol=tol.pln_angle, - rel_tol=tol.relativeTol, + tolerances=tolerances, + dtol=tolerances.pln_distance, + atol=tolerances.pln_angle, + rel_tol=tolerances.relativeTol, ): return s.Index @@ -53,9 +53,10 @@ def get_id(facein, surfaces): if BF.is_same_cylinder( facein, s.Surf, - dtol=tol.cyl_distance, - atol=tol.cyl_angle, - rel_tol=tol.relativeTol, + tolerances=tolerances, + dtol=tolerances.cyl_distance, + atol=tolerances.cyl_angle, + rel_tol=tolerances.relativeTol, ): return s.Index @@ -64,16 +65,16 @@ def get_id(facein, surfaces): if BF.is_same_cone( facein, s.Surf, - dtol=tol.kne_distance, - atol=tol.kne_angle, - rel_tol=tol.relativeTol, + dtol=tolerances.kne_distance, + atol=tolerances.kne_angle, + rel_tol=tolerances.relativeTol, ): return s.Index elif surfin[0:6] == "Sphere": for s in surfaces["Sph"]: if BF.is_same_sphere( - facein, s.Surf, tol.sph_distance, rel_tol=tol.relativeTol + facein, s.Surf, tolerances.sph_distance, rel_tol=tolerances.relativeTol ): return s.Index @@ -82,9 +83,9 @@ def get_id(facein, surfaces): if BF.is_same_torus( facein, s.Surf, - dtol=tol.tor_distance, - atol=tol.tor_angle, - rel_tol=tol.relativeTol, + dtol=tolerances.tor_distance, + atol=tolerances.tor_angle, + rel_tol=tolerances.relativeTol, ): return s.Index @@ -286,7 +287,7 @@ def gen_plane_sphere(face, solid): return Part.Plane(face.Surface.Center, normal).toShape() -def gen_plane_cylinder(face, solid): +def gen_plane_cylinder(face, solid, tolerances): surf = face.Surface rad = surf.Radius @@ -298,9 +299,9 @@ def gen_plane_cylinder(face, solid): face_index = [my_index] for i, face2 in enumerate(solid.Faces): - if face2.Area < tol.min_area: + if face2.Area < tolerances.min_area: logger.warning( - f"surface {str(surf)} removed from cell definition. Face area < Min area ({face2.Area} < {tol.min_area})" + f"surface {str(surf)} removed from cell definition. Face area < Min area ({face2.Area} < {tolerances.min_area})" ) continue if str(face2.Surface) == "" and not (face2.isEqual(face)): @@ -337,7 +338,7 @@ def gen_plane_cylinder(face, solid): return plane -def gen_plane_cylinder_old(face, solid): +def gen_plane_cylinder_old(face, solid, tolerances): surf = face.Surface rad = surf.Radius @@ -348,9 +349,9 @@ def gen_plane_cylinder_old(face, solid): face_index = [solid.Faces.index(face)] for i, face2 in enumerate(solid.Faces): - if face2.Area < tol.min_area: + if face2.Area < tolerances.min_area: logger.warning( - f"surface {str(surf)} removed from cell definition. Face area < Min area ({face2.Area} < {tol.min_area})" + f"surface {str(surf)} removed from cell definition. Face area < Min area ({face2.Area} < {tolerances.min_area})" ) continue if str(face2.Surface) == "" and not (face2.isEqual(face)): @@ -427,7 +428,7 @@ def gen_plane_cylinder_old(face, solid): return plane -def gen_plane_cone(face, solid): +def gen_plane_cone(face, solid, tolerances): Surf = face.Surface if str(Surf) != "": @@ -437,9 +438,9 @@ def gen_plane_cone(face, solid): face_index = [myIndex] for i, face2 in enumerate(solid.Faces): - if face2.Area < tol.min_area: + if face2.Area < tolerances.min_area: logger.warning( - f"{str(Surf)} surface removed from cell definition. Face area < Min area ({face2.Area} < {tol.min_area})" + f"{str(Surf)} surface removed from cell definition. Face area < Min area ({face2.Area} < {tolerances.min_area})" ) continue if str(face2.Surface) == "" and not (face2.isEqual(face)): @@ -472,7 +473,7 @@ def gen_plane_cone(face, solid): return plane -def gen_plane_cone_old(face, solid): +def gen_plane_cone_old(face, solid, tolerances): surf = face.Surface if str(surf) != "": @@ -481,9 +482,9 @@ def gen_plane_cone_old(face, solid): face_index = [solid.Faces.index(face)] for i, face2 in enumerate(solid.Faces): - if face2.Area < tol.min_area: + if face2.Area < tolerances.min_area: logger.warning( - f"{str(surf)} surface removed from cell definition. Face area < Min area ({face2.Area} < {tol.min_area})" + f"{str(surf)} surface removed from cell definition. Face area < Min area ({face2.Area} < {tolerances.min_area})" ) continue if str(face2.Surface) == "" and not (face2.isEqual(face)): @@ -556,13 +557,13 @@ def gen_plane_cone_old(face, solid): return plane -def gen_torus_annex_u_planes(face, u_params): +def gen_torus_annex_u_planes(face, u_params, tolerances): - if is_parallel(face.Surface.Axis, FreeCAD.Vector(1, 0, 0), tol.tor_angle): + if is_parallel(face.Surface.Axis, FreeCAD.Vector(1, 0, 0), tolerances.tor_angle): axis = FreeCAD.Vector(1, 0, 0) - elif is_parallel(face.Surface.Axis, FreeCAD.Vector(0, 1, 0), tol.tor_angle): + elif is_parallel(face.Surface.Axis, FreeCAD.Vector(0, 1, 0), tolerances.tor_angle): axis = FreeCAD.Vector(0, 1, 0) - elif is_parallel(face.Surface.Axis, FreeCAD.Vector(0, 0, 1), tol.tor_angle): + elif is_parallel(face.Surface.Axis, FreeCAD.Vector(0, 0, 1), tolerances.tor_angle): axis = FreeCAD.Vector(0, 0, 1) center = face.Surface.Center @@ -570,7 +571,7 @@ def gen_torus_annex_u_planes(face, u_params): p2 = face.valueAt(u_params[1], 0.0) pmid = face.valueAt(0.5 * (u_params[0] + u_params[1]), 0.0) - if is_same_value(abs(u_params[1] - u_params[0]), math.pi, tol.value): + if is_same_value(abs(u_params[1] - u_params[0]), math.pi, tolerances.value): d = axis.cross(p2 - p1) d.normalize() if d.dot(pmid - center) < 0: @@ -607,13 +608,13 @@ def gen_torus_annex_u_planes(face, u_params): ), True # (d1 : d2) -def gen_torus_annex_u_planes_org(face, u_params): +def gen_torus_annex_u_planes_org(face, u_params, tolerances): - if is_parallel(face.Surface.Axis, FreeCAD.Vector(1, 0, 0), tol.tor_angle): + if is_parallel(face.Surface.Axis, FreeCAD.Vector(1, 0, 0), tolerances.tor_angle): axis = FreeCAD.Vector(1, 0, 0) - elif is_parallel(face.Surface.Axis, FreeCAD.Vector(0, 1, 0), tol.tor_angle): + elif is_parallel(face.Surface.Axis, FreeCAD.Vector(0, 1, 0), tolerances.tor_angle): axis = FreeCAD.Vector(0, 1, 0) - elif is_parallel(face.Surface.Axis, FreeCAD.Vector(0, 0, 1), tol.tor_angle): + elif is_parallel(face.Surface.Axis, FreeCAD.Vector(0, 0, 1), tolerances.tor_angle): axis = FreeCAD.Vector(0, 0, 1) center = face.Surface.Center @@ -621,7 +622,7 @@ def gen_torus_annex_u_planes_org(face, u_params): p2 = face.valueAt(u_params[1], 0.0) pmid = face.valueAt(0.5 * (u_params[0] + u_params[1]), 0.0) - if is_same_value(abs(u_params[1] - u_params[0]), math.pi, tol.value): + if is_same_value(abs(u_params[1] - u_params[0]), math.pi, tolerances.value): d = axis.cross(p2 - p1) d.normalize() if pmid.dot(d) < 0: @@ -651,12 +652,12 @@ def gen_torus_annex_u_planes_org(face, u_params): ), True # (d1 : d2) -def gen_torus_annex_v_surface(face, v_params, force_cylinder=False): - if is_parallel(face.Surface.Axis, FreeCAD.Vector(1, 0, 0), tol.tor_angle): +def gen_torus_annex_v_surface(face, v_params, tolerances, force_cylinder=False): + if is_parallel(face.Surface.Axis, FreeCAD.Vector(1, 0, 0), tolerances.tor_angle): axis = FreeCAD.Vector(1, 0, 0) - elif is_parallel(face.Surface.Axis, FreeCAD.Vector(0, 1, 0), tol.tor_angle): + elif is_parallel(face.Surface.Axis, FreeCAD.Vector(0, 1, 0), tolerances.tor_angle): axis = FreeCAD.Vector(0, 1, 0) - elif is_parallel(face.Surface.Axis, FreeCAD.Vector(0, 0, 1), tol.tor_angle): + elif is_parallel(face.Surface.Axis, FreeCAD.Vector(0, 0, 1), tolerances.tor_angle): axis = FreeCAD.Vector(0, 0, 1) p1 = face.valueAt(0.0, v_params[0]) - face.Surface.Center @@ -667,7 +668,7 @@ def gen_torus_annex_v_surface(face, v_params, force_cylinder=False): z2 = p2.dot(axis) d2 = p2.cross(axis).Length - if is_same_value(z1, z2, tol.distance): + if is_same_value(z1, z2, tolerances.distance): surf_type = "Plane" center = face.Surface.Center + z1 * axis v_mid = (v_params[0] + v_params[1]) * 0.5 @@ -682,11 +683,11 @@ def gen_torus_annex_v_surface(face, v_params, force_cylinder=False): in_surf, ) - elif is_same_value(d1, d2, tol.distance) or force_cylinder: + elif is_same_value(d1, d2, tolerances.distance) or force_cylinder: surf_type = "Cylinder" radius = min(d1, d2) center = face.Surface.Center - if is_same_value(d1, face.Surface.MajorRadius, tol.distance): + if is_same_value(d1, face.Surface.MajorRadius, tolerances.distance): v_mid = (v_params[0] + v_params[1]) * 0.5 p_mid = face.valueAt(0, v_mid) - center if p_mid.cross(axis).Length < face.Surface.MajorRadius: @@ -735,7 +736,7 @@ def gen_torus_annex_v_surface(face, v_params, force_cylinder=False): ) -def cellDef(meta_obj, surfaces, universe_box, options): +def cellDef(meta_obj, surfaces, universe_box, options, tolerances): solids = meta_obj.Solids del_list = [] @@ -749,13 +750,13 @@ def cellDef(meta_obj, surfaces, universe_box, options): extra_plane_reverse = dict() flag_inv = is_inverted(solid) - solid_gu = GU.SolidGu(solid) + solid_gu = GU.SolidGu(solid, tolerances=tolerances) last_torus = -1 for iface, face in enumerate(solid_gu.Faces): surface_type = str(face.Surface) - if abs(face.Area) < tol.min_area: + if abs(face.Area) < tolerances.min_area: logger.warning( - f"{surface_type} surface removed from cell definition. Face area < Min area ({face.Area} < {tol.min_area})" + f"{surface_type} surface removed from cell definition. Face area < Min area ({face.Area} < {tolerances.min_area})" ) continue if face.Area < 0: @@ -780,7 +781,7 @@ def cellDef(meta_obj, surfaces, universe_box, options): and orient == "Reversed" ): # cone additional plane is added afterward - id_face = get_id(face.Surface, surfaces) + id_face = get_id(face.Surface, surfaces, tolerances) if surface_type == "": cones.add(id_face) if str(id_face) not in surf_piece: @@ -802,11 +803,11 @@ def cellDef(meta_obj, surfaces, universe_box, options): Face="Build", ) - id, exist = surfaces.add_plane(p) + id, exist = surfaces.add_plane(p, tolerances, False) sign = sign_plane(face.CenterOfMass, p) if exist: pp = surfaces.get_surface(id) - if is_opposite(p.Surf.Axis, pp.Surf.Axis, tol.angle): + if is_opposite(p.Surf.Axis, pp.Surf.Axis, tolerances.angle): id = -id id *= sign @@ -821,16 +822,16 @@ def cellDef(meta_obj, surfaces, universe_box, options): elif surface_type == "": if ( - is_parallel(face.Surface.Axis, FreeCAD.Vector(1, 0, 0), tol.angle) + is_parallel(face.Surface.Axis, FreeCAD.Vector(1, 0, 0), tolerances.angle) or is_parallel( - face.Surface.Axis, FreeCAD.Vector(0, 1, 0), tol.angle + face.Surface.Axis, FreeCAD.Vector(0, 1, 0), tolerances.angle ) or is_parallel( - face.Surface.Axis, FreeCAD.Vector(0, 0, 1), tol.angle + face.Surface.Axis, FreeCAD.Vector(0, 0, 1), tolerances.angle ) ): - idT = get_id(face.Surface, surfaces) + idT = get_id(face.Surface, surfaces, tolerances) index, u_params = solid_gu.TorusUParams[iface] if index == last_torus: @@ -841,15 +842,15 @@ def cellDef(meta_obj, surfaces, universe_box, options): u_closed, u_minMax = u_params # u_closed = True if not u_closed: - planes, ORop = gen_torus_annex_u_planes(face, u_minMax) + planes, ORop = gen_torus_annex_u_planes(face, u_minMax, tolerances) plane1, plane2 = planes plane = GeounedSurface( ("Plane", plane1), universe_box, Face="Build" ) - id1, exist = surfaces.add_plane(plane) + id1, exist = surfaces.add_plane(plane, tolerances, False) if exist: p = surfaces.get_surface(id1) - if is_opposite(plane.Surf.Axis, p.Surf.Axis, tol.pln_angle): + if is_opposite(plane.Surf.Axis, p.Surf.Axis, tolerances.pln_angle): id1 = -id1 if plane2 is None: @@ -858,11 +859,11 @@ def cellDef(meta_obj, surfaces, universe_box, options): plane = GeounedSurface( ("Plane", plane2), universe_box, Face="Build" ) - id2, exist = surfaces.add_plane(plane) + id2, exist = surfaces.add_plane(plane, tolerances, False) if exist: p = surfaces.get_surface(id2) if is_opposite( - plane.Surf.Axis, p.Surf.Axis, tol.pln_angle + plane.Surf.Axis, p.Surf.Axis, tolerances.pln_angle ): id2 = -id2 @@ -886,14 +887,14 @@ def cellDef(meta_obj, surfaces, universe_box, options): v_var = "%i" % idT else: surf_params, surf_type, in_surf = gen_torus_annex_v_surface( - face, VminMax, options.forceCylinder + face, VminMax, tolerances, options.forceCylinder ) if surf_type == "Cone": cone = GeounedSurface( ("Cone", surf_params), universe_box, Face="Build" ) - id2, exist = surfaces.add_cone(cone) + id2, exist = surfaces.add_cone(cone, tolerances) elif surf_type == "Cylinder": cyl = GeounedSurface( @@ -901,17 +902,17 @@ def cellDef(meta_obj, surfaces, universe_box, options): universe_box, Face="Build", ) - id2, exist = surfaces.add_cylinder(cyl) + id2, exist = surfaces.add_cylinder(cyl, tolerances) elif surf_type == "Plane": plane = GeounedSurface( ("Plane", surf_params), universe_box, Face="Build" ) - id2, exist = surfaces.add_plane(plane) + id2, exist = surfaces.add_plane(plane, tolerances, False) if exist: p = surfaces.get_surface(id2) if is_opposite( - plane.Surf.Axis, p.Surf.Axis, tol.pln_angle + plane.Surf.Axis, p.Surf.Axis, tolerances.pln_angle ): id2 = -id2 @@ -926,7 +927,7 @@ def cellDef(meta_obj, surfaces, universe_box, options): "Only Torus with axis along X, Y, Z axis can be reproduced" ) else: - id = get_id(face.Surface, surfaces) + id = get_id(face.Surface, surfaces, tolerances) if surface_type == "": cones.add(-id) @@ -944,7 +945,7 @@ def cellDef(meta_obj, surfaces, universe_box, options): universe_box, Face="Build", ) - id, exist = surfaces.add_plane(plane) + id, exist = surfaces.add_plane(plane, tolerances, False) surf = plane.shape elif surface_type == "": dim_l = face.ParameterRange[3] - face.ParameterRange[2] @@ -961,7 +962,7 @@ def cellDef(meta_obj, surfaces, universe_box, options): universe_box, Face="Build", ) - id, exist = surfaces.add_cylinder(cylinder) + id, exist = surfaces.add_cylinder(cylinder, tolerances) surf = cylinder.shape if orient == "Reversed": @@ -971,7 +972,7 @@ def cellDef(meta_obj, surfaces, universe_box, options): if surface_type == "": s = surfaces.get_surface(id) - if is_opposite(face.Surface.Axis, s.Surf.Axis, tol.pln_angle): + if is_opposite(face.Surface.Axis, s.Surf.Axis, tolerances.pln_angle): var = -var if str(var) in surf_piece: @@ -1146,7 +1147,7 @@ def no_overlapping_cell(metaList, surfaces, options): # TODO this function looks like it is not used in the code. -def extra_plane_cyl_face(face, box, surfaces): +def extra_plane_cyl_face(face, box, surfaces, tolerances): wire = face.OuterWire planes_id = [] for e in wire.OrderedEdges: @@ -1163,16 +1164,16 @@ def extra_plane_cyl_face(face, box, surfaces): plane = GeounedSurface( ("Plane", (center, dir, dim1, dim2)), box, Face="Build" ) - id, exist = surfaces.add_plane(plane) + id, exist = surfaces.add_plane(plane, tolerances, False) if exist: pp = surfaces.get_surface(id) - if is_opposite(plane.Surf.Axis, pp.Surf.Axis, tol.pln_angle): + if is_opposite(plane.Surf.Axis, pp.Surf.Axis, tolerances.pln_angle): id = -id planes_id.append(id) return planes_id -def add_cone_plane(definition, cones_list, surfaces, universe_box): +def add_cone_plane(definition, cones_list, surfaces, universe_box, tolerances): x_axis = FreeCAD.Vector(1, 0, 0) y_axis = FreeCAD.Vector(0, 1, 0) z_axis = FreeCAD.Vector(0, 0, 1) @@ -1180,9 +1181,9 @@ def add_cone_plane(definition, cones_list, surfaces, universe_box): for cid in cones_list: cone = surfaces.get_surface(abs(cid)) if ( - is_parallel(cone.Surf.Axis, x_axis, tol.angle) - or is_parallel(cone.Surf.Axis, y_axis, tol.angle) - or is_parallel(cone.Surf.Axis, z_axis, tol.angle) + is_parallel(cone.Surf.Axis, x_axis, tolerances.angle) + or is_parallel(cone.Surf.Axis, y_axis, tolerances.angle) + or is_parallel(cone.Surf.Axis, z_axis, tolerances.angle) ): continue @@ -1191,11 +1192,11 @@ def add_cone_plane(definition, cones_list, surfaces, universe_box): universe_box, Face="Build", ) - pid, exist = surfaces.add_plane(plane) + pid, exist = surfaces.add_plane(plane, tolerances, False) if exist: p = surfaces.get_surface(pid) - if is_opposite(plane.Surf.Axis, p.Surf.Axis, tol.pln_angle): + if is_opposite(plane.Surf.Axis, p.Surf.Axis, tolerances.pln_angle): pid = -pid if cid > 0: diff --git a/src/geouned/GEOUNED/Cuboid/translate.py b/src/geouned/GEOUNED/Cuboid/translate.py index 23417380..962901bd 100644 --- a/src/geouned/GEOUNED/Cuboid/translate.py +++ b/src/geouned/GEOUNED/Cuboid/translate.py @@ -9,8 +9,6 @@ from ..Utils.BasicFunctions_part1 import is_opposite, is_parallel from ..Utils.booleanFunction import BoolSequence -from ..Utils.Options.Classes import Tolerances as tol - logger = logging.getLogger(__name__) @@ -64,13 +62,13 @@ def is_inverted(solid): return False -def get_id(face_in, Surfaces): +def get_id(face_in, Surfaces, tolerances): - if is_parallel(face_in.Axis, FreeCAD.Vector(1, 0, 0), tol.pln_angle): + if is_parallel(face_in.Axis, FreeCAD.Vector(1, 0, 0), tolerances.pln_angle): plane = "PX" - elif is_parallel(face_in.Axis, FreeCAD.Vector(0, 1, 0), tol.pln_angle): + elif is_parallel(face_in.Axis, FreeCAD.Vector(0, 1, 0), tolerances.pln_angle): plane = "PY" - elif is_parallel(face_in.Axis, FreeCAD.Vector(0, 0, 1), tol.pln_angle): + elif is_parallel(face_in.Axis, FreeCAD.Vector(0, 0, 1), tolerances.pln_angle): plane = "PZ" else: plane = "P" @@ -79,9 +77,10 @@ def get_id(face_in, Surfaces): if BF.is_same_plane( face_in, s.Surf, - dtol=tol.pln_distance, - atol=tol.pln_angle, - rel_tol=tol.relativeTol, + tolerances=tolerances, + dtol=tolerances.pln_distance, + atol=tolerances.pln_angle, + rel_tol=tolerances.relativeTol, ): return s.Index @@ -110,14 +109,14 @@ def translate(meta_list, surfaces, universe_box, setting): # TODO rename this, but be careful as there are other functions in the code with the same name -def set_definition(meta_obj, surfaces): +def set_definition(meta_obj, surfaces, tolerances): solids = meta_obj.Solids s_def = BoolSequence(operator="OR") for sol in solids: subSol = BoolSequence(operator="AND") flag_inv = is_inverted(sol) - solid_gu = GU.SolidGu(sol, plane3Pts=True) + solid_gu = GU.SolidGu(sol, tolerances=tolerances, plane3Pts=True) faces = [] for face in solid_gu.Faces: @@ -133,7 +132,7 @@ def set_definition(meta_obj, surfaces): id = get_id(face.Surface, surfaces) s = surfaces.get_surface(id) - if is_opposite(face.Surface.Axis, s.Surf.Axis, tol.pln_angle): + if is_opposite(face.Surface.Axis, s.Surf.Axis, tolerances.pln_angle): id = -id if face.Orientation == "Forward": id = -id diff --git a/src/geouned/GEOUNED/Decompose/Decom_one.py b/src/geouned/GEOUNED/Decompose/Decom_one.py index f9656242..ccd2992a 100644 --- a/src/geouned/GEOUNED/Decompose/Decom_one.py +++ b/src/geouned/GEOUNED/Decompose/Decom_one.py @@ -20,20 +20,18 @@ ) from ..Utils.BasicFunctions_part2 import is_duplicate_in_list -from ..Utils.Options.Classes import Tolerances as tol - logger = logging.getLogger(__name__) twoPi = math.pi * 2 -def split_full_cylinder(solid, options): +def split_full_cylinder(solid, options, tolerances): explode = [] bases = [solid] while True: new_bases = [] for base in bases: - cut_solids = cut_full_cylinder(base, options) + cut_solids = cut_full_cylinder(base, options, tolerances) if len(cut_solids) == 1: explode.extend(cut_solids) else: @@ -46,8 +44,8 @@ def split_full_cylinder(solid, options): return Part.makeCompound(explode) -def cut_full_cylinder(solid, options): - solid_gu = GU.SolidGu(solid) +def cut_full_cylinder(solid, options, tolerances): + solid_gu = GU.SolidGu(solid, tolerances=tolerances) surfaces = UF.SurfacesDict() flag_inv = CD.is_inverted(solid_gu.solid) universe_box = solid.BoundBox @@ -78,7 +76,7 @@ def cut_full_cylinder(solid, options): # add planes if cylinder axis is cut by a plane (plane quasi perpedicular to axis) for p in cyl_bound_planes(face, universe_box): p.build_surface() - surfaces.add_plane(p, False) + surfaces.add_plane(p, tolerances, False) break planes = [] @@ -163,10 +161,10 @@ def cyl_bound_planes(face, boundBox): return planes -def torus_bound_planes(face, boundBox): +def torus_bound_planes(face, boundBox, tolerances): params = face.ParameterRange planes = [] - if is_same_value(params[1] - params[0], twoPi, tol.value): + if is_same_value(params[1] - params[0], twoPi, tolerances.value): return planes Edges = face.OuterWire.Edges @@ -179,7 +177,7 @@ def torus_bound_planes(face, boundBox): if curve[0:6] == "Circle": dir = e.Curve.Axis - if not is_parallel(dir, face.Surface.Axis, tol.angle): + if not is_parallel(dir, face.Surface.Axis, tolerances.angle): center = e.Curve.Center dim1 = e.Curve.Radius dim2 = e.Curve.Radius @@ -197,7 +195,7 @@ def torus_bound_planes(face, boundBox): planes.append(plane) elif curve == "": - planeParams = plane_spline_curve(e) + planeParams = plane_spline_curve(e, tolerances) if planeParams is not None: plane = UF.GeounedSurface(("Plane", planeParams), boundBox) planes.append(plane) @@ -205,14 +203,14 @@ def torus_bound_planes(face, boundBox): return planes -def plane_spline_curve(edge): +def plane_spline_curve(edge, tolerances): normal = edge.derivative1At(0).cross(edge.derivative1At(0.5)) normal.normalize() curve_2d = True for p in (0.25, 0.75, 1): # check if derivative orthogonal to curve normal vector - if abs(normal.dot(edge.derivative1At(p))) > tol.value: + if abs(normal.dot(edge.derivative1At(p))) > tolerances.value: curve_2d = False break @@ -223,19 +221,19 @@ def plane_spline_curve(edge): return None -def extract_surfaces(solid, kind, universe_box, MakeObj=False): +def extract_surfaces(solid, kind, universe_box, tolerances, MakeObj): if kind == "All": fuzzy = True solid_parts = [] for s in solid.Solids: - solid_parts.append(GU.SolidGu(s)) + solid_parts.append(GU.SolidGu(s, tolerances=tolerances)) else: fuzzy = False if kind == "Plane3Pts": P3P = True else: P3P = False - solid_parts = [GU.SolidGu(solid, P3P)] + solid_parts = [GU.SolidGu(solid, tolerances=tolerances, plane3Pts=P3P)] surfaces = UF.SurfacesDict() @@ -255,7 +253,7 @@ def extract_surfaces(solid, kind, universe_box, MakeObj=False): ) if MakeObj: plane.build_surface() - surfaces.add_plane(plane, fuzzy) + surfaces.add_plane(plane, tolerances, fuzzy) elif surf == "": dir = face.Surface.Axis @@ -268,14 +266,14 @@ def extract_surfaces(solid, kind, universe_box, MakeObj=False): ) if MakeObj: cylinder.build_surface() - surfaces.add_cylinder(cylinder, fuzzy) + surfaces.add_cylinder(cylinder, tolerances, fuzzy) if kind in ["Planes", "All"]: # add planes if cylinder axis is cut by a plane (plane quasi perpedicular to axis) for p in cyl_bound_planes(face, universe_box): if MakeObj: p.build_surface() - surfaces.add_plane(p) + surfaces.add_plane(p, tolerances, False) elif surf == "": dir = face.Surface.Axis @@ -289,13 +287,13 @@ def extract_surfaces(solid, kind, universe_box, MakeObj=False): ) if MakeObj: cone.build_surface() - surfaces.add_cone(cone) + surfaces.add_cone(cone, tolerances) if kind in ["Planes", "All"]: for p in cyl_bound_planes(face, universe_box): if MakeObj: p.build_surface() - surfaces.add_plane(p) + surfaces.add_plane(p, tolerances, False) elif surf[0:6] == "Sphere" and kind in ["Sph", "All"]: rad = face.Surface.Radius @@ -303,13 +301,13 @@ def extract_surfaces(solid, kind, universe_box, MakeObj=False): sphere = UF.GeounedSurface(("Sphere", (pnt, rad)), universe_box) if MakeObj: sphere.build_surface() - surfaces.add_sphere(sphere) + surfaces.add_sphere(sphere, tolerances) if kind in ["Planes", "All"]: for p in cyl_bound_planes(face, universe_box): if MakeObj: p.build_surface() - surfaces.add_plane(p) + surfaces.add_plane(p, tolerances, False) elif surf == "": if kind in ["Tor", "All"]: @@ -322,13 +320,13 @@ def extract_surfaces(solid, kind, universe_box, MakeObj=False): ) if MakeObj: torus.build_surface() - surfaces.add_torus(torus) + surfaces.add_torus(torus, tolerances) if kind in ["Planes", "All"]: - for p in torus_bound_planes(face, universe_box): + for p in torus_bound_planes(face, universe_box, tolerances): if MakeObj: p.build_surface() - surfaces.add_plane(p) + surfaces.add_plane(p, tolerances, False) elif surf == "" and kind == "Plane3Pts": pos = face.CenterOfMass @@ -342,7 +340,7 @@ def extract_surfaces(solid, kind, universe_box, MakeObj=False): ) if MakeObj: plane.build_surface() - surfaces.add_plane(plane, fuzzy) + surfaces.add_plane(plane, tolerances, fuzzy) return surfaces @@ -363,11 +361,11 @@ def is_already_in_planes(plane, Array): # # Check if to faces are joint # -def contiguous_face(face1, face2): - return face1.distToShape(face2)[0] < tol.distance +def contiguous_face(face1, face2, tolerances): + return face1.distToShape(face2)[0] < tolerances.distance -def same_faces(Faces): +def same_faces(Faces, tolerances): Connection = OrderedDict() if len(Faces) == 1: return [] @@ -377,7 +375,7 @@ def same_faces(Faces): if not Faces[i + 1 :]: continue for j, face2 in enumerate(Faces[i + 1 :]): - if contiguous_face(face1, face2): + if contiguous_face(face1, face2, tolerances): Couples.append(i + 1 + j) @@ -407,7 +405,7 @@ def same_faces(Faces): # Tolerance in this function are not the general once # function should be reviewed -def gen_plane_cylinder(face, solid): +def gen_plane_cylinder(face, solid, tolerances): Surf = face.Surface rad = Surf.Radius if face.Area < 1e-2: @@ -444,7 +442,7 @@ def gen_plane_cylinder(face, solid): face_index = [face_index_0[0]] # la face de entrada - for k in same_faces(Faces_p): + for k in same_faces(Faces_p, tolerances): face_index.append(face_index_0[k]) # commented to let plane cut rounded corner @@ -533,7 +531,7 @@ def gen_plane_cylinder(face, solid): # Tolerance in this function are not the general once # function should be reviewed -def gen_plane_cone(face, solid): +def gen_plane_cone(face, solid, tolerances): if face.Area < 1e-2: return None @@ -568,7 +566,7 @@ def gen_plane_cone(face, solid): face_index = [face_index_0[0]] # la face de entrada - for k in same_faces(Faces_p): + for k in same_faces(Faces_p, tolerances): face_index.append(face_index_0[k]) # same as cylinder commennt @@ -651,7 +649,7 @@ def gen_plane_cone(face, solid): return plane -def plane_2nd_order(solid_GU, face, flag_inv, convex=True): +def plane_2nd_order(solid_GU, face, flag_inv, tolerances, convex=True): planes = [] if face is None: @@ -668,9 +666,9 @@ def plane_2nd_order(solid_GU, face, flag_inv, convex=True): if convex and orient == "Reversed": # convex face condition pp = None if str(face.Surface) == "": - pp = gen_plane_cylinder(face, solid_GU) + pp = gen_plane_cylinder(face, solid_GU, tolerances) elif str(face.Surface) == "": - pp = gen_plane_cone(face, solid_GU) + pp = gen_plane_cone(face, solid_GU, tolerances) if pp is not None: planes.append(pp) # elif str(face.Surface)[0:6] == 'Sphere': @@ -688,23 +686,23 @@ def plane_2nd_order(solid_GU, face, flag_inv, convex=True): if not convex and orient == "Forward": if str(face.Surface) == "": - pp = gen_plane_cylinder(face, solid_GU) + pp = gen_plane_cylinder(face, solid_GU, tolerances) elif str(face.Surface) == "": - pp = gen_plane_cone(face, solid_GU) + pp = gen_plane_cone(face, solid_GU, tolerances) if pp is not None: planes.append(pp) return planes -def split_planes(Solids, universe_box, options, newVersion=True): +def split_planes(Solids, universe_box, options, tolerances, newVersion=True): if newVersion: - return split_planes_new(Solids, universe_box, options) + return split_planes_new(Solids, universe_box, options, tolerances) else: return split_planes_org(Solids, universe_box) -def split_planes_new(Solids, universe_box, options): +def split_planes_new(Solids, universe_box, options, tolerances): Bases = Solids[:] simpleSolid = [] @@ -712,7 +710,7 @@ def split_planes_new(Solids, universe_box, options): while True: newBases = [] for base in Bases: - cut_solids = split_p_planes_new(base, universe_box, options) + cut_solids = split_p_planes_new(base, universe_box, options, tolerances) if len(cut_solids) == 1: simpleSolid.extend(cut_solids) else: @@ -725,7 +723,7 @@ def split_planes_new(Solids, universe_box, options): return simpleSolid, 0 -def split_planes_org(Solids, universe_box, options): +def split_planes_org(Solids, universe_box, options, tolerances): Bases = [] err = 0 for sol in Solids: @@ -742,7 +740,7 @@ def split_planes_org(Solids, universe_box, options): base = item[0] index = item[1] - SPlanes = extract_surfaces(base, "Planes", universe_box, MakeObj=True) + SPlanes = extract_surfaces(base, "Planes", universe_box, tolerances, MakeObj=True) Planes = [SPlanes["PX"], SPlanes["PY"], SPlanes["PZ"]] for i in index: del Planes[i] @@ -762,7 +760,7 @@ def split_planes_org(Solids, universe_box, options): if len(comsolid.Solids) == 1: if ( abs(comsolid.Solids[0].Volume - base.Volume) / base.Volume - > tol.relativePrecision + > tolerances.relativePrecision ): logger.warning( f"Part of the split object is missing original base is used instead {abs(comsolid.Solids[0].Volume - base.Volume) / base.Volume} {comsolid.Solids[0].Volume} {base.Volume}" @@ -864,8 +862,8 @@ def sort_planes(PlaneList, sortElements=False): return sortedPlanes -def split_p_planes_new(solid, universe_box, options): - SPlanes = extract_surfaces(solid, "Planes", universe_box) +def split_p_planes_new(solid, universe_box, options, tolerances): + SPlanes = extract_surfaces(solid, "Planes", universe_box, tolerances, False) Planes = [] for P in ("PX", "PY", "PZ", "P"): @@ -890,8 +888,8 @@ def split_p_planes_new(solid, universe_box, options): return out_solid -def split_p_planes_org(solid, universe_box, options): - SPlanes = extract_surfaces(solid, "Planes", universe_box) +def split_p_planes_org(solid, universe_box, options, tolerances): + SPlanes = extract_surfaces(solid, "Planes", universe_box, tolerances, False) if len(SPlanes["P"]) == 0: return [solid] @@ -905,7 +903,7 @@ def split_p_planes_org(solid, universe_box, options): return out_solid -def split_2nd_order(Solids, universe_box, options): +def split_2nd_order(Solids, universe_box, options, tolerances): err = 0 Base = Solids for kind in ["Cyl", "Cone", "Sph", "Tor"]: @@ -913,7 +911,7 @@ def split_2nd_order(Solids, universe_box, options): while True: cutBase = [] for solid in Base: - Surfaces = extract_surfaces(solid, kind, universe_box) + Surfaces = extract_surfaces(solid, kind, universe_box, tolerances, False) if len(Surfaces[kind]) == 0: kindBase.append(solid) else: @@ -951,14 +949,14 @@ def split_2nd_order(Solids, universe_box, options): return Base, err -def split_2nd_order_planes(Solids, options): +def split_2nd_order_planes(Solids, options, tolerances): err = 0 simpleSolid = [] Bases = Solids while True: newBases = [] for base in Bases: - cut_solids, err = split_2nd_o_plane(base, options) + cut_solids, err = split_2nd_o_plane(base, options, tolerances) if len(cut_solids) == 1: simpleSolid.extend(cut_solids) else: @@ -971,12 +969,12 @@ def split_2nd_order_planes(Solids, options): return simpleSolid, err -def split_2nd_o_plane(solid, options): +def split_2nd_o_plane(solid, options, tolerances): err = 0 flag_inv = CD.is_inverted(solid) - solid_GU = GU.SolidGu(solid) - planes = plane_2nd_order(solid_GU, None, flag_inv, convex=True) + solid_GU = GU.SolidGu(solid, tolerances=tolerances) + planes = plane_2nd_order(solid_GU, None, flag_inv, tolerances, convex=True) if not planes: return [solid], err @@ -1010,7 +1008,7 @@ def remove_solids(Solids): return Solids_Clean, err -def split_component(solidShape, universe_box, options): +def split_component(solidShape, universe_box, options, tolerances): err = 0 err2 = 0 @@ -1018,13 +1016,13 @@ def split_component(solidShape, universe_box, options): Solids = solidShape.Solids # Split with explicit planes bounding the solid and # implicit planes interface of two 2nd order surfaces - split0, err = split_planes(Solids, universe_box, options) + split0, err = split_planes(Solids, universe_box, options, tolerances) # Split with explicit 2nd order surfaces bounding the solid - split1, err1 = split_2nd_order(split0, universe_box, options) + split1, err1 = split_2nd_order(split0, universe_box, options, tolerances) err += err1 - split, err2 = split_2nd_order_planes(split1, options) + split, err2 = split_2nd_order_planes(split1, options, tolerances) err += err2 Pieces = [] for part in split: @@ -1049,14 +1047,14 @@ def split_component(solidShape, universe_box, options): # TODO rename function but be careful as there are functions with the same name elsewhere in the code -def SplitSolid(solidShape, universe_box, options): +def SplitSolid(solidShape, universe_box, options, tolerances): solid_parts = [] for solid in solidShape.Solids: - explode = split_full_cylinder(solid, options) - piece, err = split_component(explode, universe_box, options) + explode = split_full_cylinder(solid, options, tolerances) + piece, err = split_component(explode, universe_box, options, tolerances) solid_parts.append(piece) return Part.makeCompound(solid_parts), err diff --git a/src/geouned/GEOUNED/Utils/BasicFunctions_part2.py b/src/geouned/GEOUNED/Utils/BasicFunctions_part2.py index 3f891dbf..aeef622c 100644 --- a/src/geouned/GEOUNED/Utils/BasicFunctions_part2.py +++ b/src/geouned/GEOUNED/Utils/BasicFunctions_part2.py @@ -18,36 +18,36 @@ same_surf_fic = open("fuzzySurfaces", "w") -def Fuzzy(index, dtype, surf1, surf2, val, tol): +def Fuzzy(index, dtype, surf1, surf2, val, tol, tolerances): same = val <= tol if dtype == "plane": - p1str = mcnp_surface(index, "Plane", surf1) - p2str = mcnp_surface(0, "Plane", surf2) + p1str = mcnp_surface(index, "Plane", surf1, tolerances) + p2str = mcnp_surface(0, "Plane", surf2, tolerances) line = "Same surface : {}\nPlane distance / Tolerance : {} {}\n {}\n {}\n\n".format( same, val, tol, p1str, p2str ) same_surf_fic.write(line) elif dtype == "cylRad": - cyl1str = mcnp_surface(index, "Cylinder", surf1) - cyl2str = mcnp_surface(0, "Cylinder", surf2) + cyl1str = mcnp_surface(index, "Cylinder", surf1, tolerances) + cyl2str = mcnp_surface(0, "Cylinder", surf2, tolerances) line = "Same surface : {}\nDiff Radius / Tolerance: {} {}\n {}\n {}\n\n".format( same, val, tol, cyl1str, cyl2str ) same_surf_fic.write(line) elif dtype == "cylAxs": - cyl1str = mcnp_surface(index, "Cylinder", surf1) - cyl2str = mcnp_surface(0, "Cylinder", surf2) + cyl1str = mcnp_surface(index, "Cylinder", surf1, tolerances) + cyl2str = mcnp_surface(0, "Cylinder", surf2, tolerances) line = "Same surface : {}\nDist Axis / Tolerance: {} {}\n {}\n {}\n\n".format( same, val, tol, cyl1str, cyl2str ) same_surf_fic.write(line) -def is_same_plane(p1, p2, dtol=1e-6, atol=1e-6, rel_tol=True, fuzzy=(False, 0)): +def is_same_plane(p1, p2, tolerances, dtol=1e-6, atol=1e-6, rel_tol=True, fuzzy=(False, 0)): if is_parallel(p1.Axis, p2.Axis, atol): d1 = p1.Axis.dot(p1.Position) d2 = p2.Axis.dot(p2.Position) @@ -61,12 +61,12 @@ def is_same_plane(p1, p2, dtol=1e-6, atol=1e-6, rel_tol=True, fuzzy=(False, 0)): isSame, is_fuzzy = is_in_tolerance(d, tol, 0.5 * tol, 2 * tol) if is_fuzzy and fuzzy[0]: - Fuzzy(fuzzy[1], "plane", p2, p1, d, tol) + Fuzzy(fuzzy[1], "plane", p2, p1, d, tol, tolerances) return isSame return False -def is_same_cylinder(cyl1, cyl2, dtol=1e-6, atol=1e-6, rel_tol=True, fuzzy=(False, 0)): +def is_same_cylinder(cyl1, cyl2, tolerances, dtol=1e-6, atol=1e-6, rel_tol=True, fuzzy=(False, 0)): if rel_tol: rtol = dtol * max(cyl2.Radius, cyl1.Radius) else: @@ -76,7 +76,7 @@ def is_same_cylinder(cyl1, cyl2, dtol=1e-6, atol=1e-6, rel_tol=True, fuzzy=(Fals cyl2.Radius - cyl1.Radius, rtol, 0.5 * rtol, 2 * rtol ) if is_fuzzy and fuzzy[0]: - Fuzzy(fuzzy[1], "cylRad", cyl2, cyl1, abs(cyl2.Radius - cyl1.Radius), rtol) + Fuzzy(fuzzy[1], "cylRad", cyl2, cyl1, abs(cyl2.Radius - cyl1.Radius), rtol, tolerances) if is_same_rad: if is_parallel(cyl1.Axis, cyl2.Axis, atol): @@ -90,7 +90,7 @@ def is_same_cylinder(cyl1, cyl2, dtol=1e-6, atol=1e-6, rel_tol=True, fuzzy=(Fals is_same_center, is_fuzzy = is_in_tolerance(d, tol, 0.5 * tol, 2 * tol) if is_fuzzy and fuzzy[0]: - Fuzzy(fuzzy[1], "cylAxs", cyl1, cyl2, d, tol) + Fuzzy(fuzzy[1], "cylAxs", cyl1, cyl2, d, tol, tolerances) return is_same_center return False diff --git a/src/geouned/GEOUNED/Utils/Functions.py b/src/geouned/GEOUNED/Utils/Functions.py index beacfafb..9b51a732 100644 --- a/src/geouned/GEOUNED/Utils/Functions.py +++ b/src/geouned/GEOUNED/Utils/Functions.py @@ -20,7 +20,6 @@ TorusParams, is_parallel, ) -from ..Utils.Options.Classes import Tolerances as tol from . import BasicFunctions_part2 as BF @@ -429,33 +428,34 @@ def del_surface(self, index): del self[self.__last_obj__[0]][self.__last_obj__[1]] return - def extend(self, surface): + def extend(self, surface, tolerances): for Pkey in ["PX", "PY", "PZ", "P"]: for s in surface[Pkey]: - self.add_plane(s) + self.add_plane(s, tolerances, False) for s in surface["Cyl"]: - self.add_cylinder(s) + self.add_cylinder(s, tolerances, False) for s in surface["Cone"]: - self.add_cone(s) + self.add_cone(s, tolerances) for s in surface["Sph"]: - self.add_sphere(s) + self.add_sphere(s, tolerances) for s in surface["Tor"]: - self.add_torus(s) + self.add_torus(s, tolerances) - def add_plane(self, plane, fuzzy=False): + def add_plane(self, plane, tolerances, fuzzy): ex = FreeCAD.Vector(1, 0, 0) ey = FreeCAD.Vector(0, 1, 0) ez = FreeCAD.Vector(0, 0, 1) - if is_parallel(plane.Surf.Axis, ex, tol.pln_angle): + if is_parallel(plane.Surf.Axis, ex, tolerances.pln_angle): add_plane = True for i, p in enumerate(self["PX"]): if BF.is_same_plane( plane.Surf, p.Surf, - dtol=tol.pln_distance, - atol=tol.pln_angle, - rel_tol=tol.relativeTol, + tolerances=tolerances, + dtol=tolerances.pln_distance, + atol=tolerances.pln_angle, + rel_tol=tolerances.relativeTol, fuzzy=(fuzzy, p.Index), ): add_plane = False @@ -469,15 +469,16 @@ def add_plane(self, plane, fuzzy=False): self["PX"].append(plane) self.__surfIndex__["PX"].append(plane.Index) - elif is_parallel(plane.Surf.Axis, ey, tol.pln_angle): + elif is_parallel(plane.Surf.Axis, ey, tolerances.pln_angle): add_plane = True for i, p in enumerate(self["PY"]): if BF.is_same_plane( plane.Surf, p.Surf, - dtol=tol.pln_distance, - atol=tol.pln_angle, - rel_tol=tol.relativeTol, + tolerances=tolerances, + dtol=tolerances.pln_distance, + atol=tolerances.pln_angle, + rel_tol=tolerances.relativeTol, fuzzy=(fuzzy, p.Index), ): add_plane = False @@ -491,15 +492,16 @@ def add_plane(self, plane, fuzzy=False): self["PY"].append(plane) self.__surfIndex__["PY"].append(plane.Index) - elif is_parallel(plane.Surf.Axis, ez, tol.pln_angle): + elif is_parallel(plane.Surf.Axis, ez, tolerances.pln_angle): add_plane = True for i, p in enumerate(self["PZ"]): if BF.is_same_plane( plane.Surf, p.Surf, - dtol=tol.pln_distance, - atol=tol.pln_angle, - rel_tol=tol.relativeTol, + tolerances=tolerances, + dtol=tolerances.pln_distance, + atol=tolerances.pln_angle, + rel_tol=tolerances.relativeTol, fuzzy=(fuzzy, p.Index), ): add_plane = False @@ -519,9 +521,10 @@ def add_plane(self, plane, fuzzy=False): if BF.is_same_plane( plane.Surf, p.Surf, - dtol=tol.pln_distance, - atol=tol.pln_angle, - rel_tol=tol.relativeTol, + tolerances=tolerances, + dtol=tolerances.pln_distance, + atol=tolerances.pln_angle, + rel_tol=tolerances.relativeTol, fuzzy=(fuzzy, p.Index), ): add_plane = False @@ -540,15 +543,16 @@ def add_plane(self, plane, fuzzy=False): else: return index, True - def add_cylinder(self, cyl, fuzzy=False): + def add_cylinder(self, cyl, tolerances, fuzzy=False): addCyl = True for i, c in enumerate(self["Cyl"]): if BF.is_same_cylinder( cyl.Surf, c.Surf, - dtol=tol.cyl_distance, - atol=tol.cyl_angle, - rel_tol=tol.relativeTol, + tolerances=tolerances, + dtol=tolerances.cyl_distance, + atol=tolerances.cyl_angle, + rel_tol=tolerances.relativeTol, fuzzy=(fuzzy, c.Index), ): addCyl = False @@ -566,15 +570,15 @@ def add_cylinder(self, cyl, fuzzy=False): else: return index, True - def add_cone(self, cone): + def add_cone(self, cone, tolerances): cone_added = True for i, c in enumerate(self["Cone"]): if BF.is_same_cone( cone.Surf, c.Surf, - dtol=tol.kne_distance, - atol=tol.kne_angle, - rel_tol=tol.relativeTol, + dtol=tolerances.kne_distance, + atol=tolerances.kne_angle, + rel_tol=tolerances.relativeTol, ): cone_added = False index = c.Index @@ -590,11 +594,11 @@ def add_cone(self, cone): else: return index, True - def add_sphere(self, sph): + def add_sphere(self, sph, tolerances): sphere_added = True for i, s in enumerate(self["Sph"]): if BF.is_same_sphere( - sph.Surf, s.Surf, tol.sph_distance, rel_tol=tol.relativeTol + sph.Surf, s.Surf, tolerances.sph_distance, rel_tol=tolerances.relativeTol ): sphere_added = False index = s.Index @@ -610,15 +614,15 @@ def add_sphere(self, sph): else: return index, True - def add_torus(self, tor): + def add_torus(self, tor, tolerances): add_torus = True for i, s in enumerate(self["Tor"]): if BF.is_same_torus( tor.Surf, s.Surf, - dtol=tol.tor_distance, - atol=tol.tor_angle, - rel_tol=tol.relativeTol, + dtol=tolerances.tor_distance, + atol=tolerances.tor_angle, + rel_tol=tolerances.relativeTol, ): add_torus = False index = s.Index diff --git a/src/geouned/GEOUNED/Utils/Geometry_GU.py b/src/geouned/GEOUNED/Utils/Geometry_GU.py index c01cd635..276b02ae 100644 --- a/src/geouned/GEOUNED/Utils/Geometry_GU.py +++ b/src/geouned/GEOUNED/Utils/Geometry_GU.py @@ -10,7 +10,6 @@ import Part -from ..Utils.Options.Classes import Tolerances as tol from .BasicFunctions_part1 import is_same_value from .BasicFunctions_part2 import is_same_torus @@ -100,10 +99,11 @@ def __init__(self, face): class SolidGu: """GEOUNED Solid Class""" - def __init__(self, solid, plane3Pts=False): + def __init__(self, solid, tolerances, plane3Pts=False): self.solid = solid faces = define_list_face_gu(solid.Faces, plane3Pts) self.Faces = faces + self.tolerances = tolerances self.Solids = solid.Solids self.BoundBox = solid.BoundBox self.Edges = solid.Edges @@ -136,9 +136,9 @@ def __same_torus_surf__(self, torusList): if is_same_torus( self.Faces[i].Surface, self.Faces[j].Surface, - dtol=tol.tor_distance, - atol=tol.tor_angle, - rel_tol=tol.relativeTol, + dtol=self.tolerances.tor_distance, + atol=self.tolerances.tor_angle, + rel_tol=self.tolerances.relativeTol, ): current.append(j) for c in current: @@ -160,7 +160,7 @@ def __separate_surfaces__(self, faceList): for tindex in temp: if ( self.Faces[current[i]].distToShape(self.Faces[tindex])[0] - < tol.distance + < self.tolerances.distance ): if tindex not in current: current.append(tindex) @@ -210,15 +210,15 @@ def __merge_periodic_uv__(self, parameter, faceList): params.sort() V0 = params[0][0] V1 = params[-1][1] - if arcLength >= two_pi * (1.0 - tol.relativePrecision): + if arcLength >= two_pi * (1.0 - self.tolerances.relativePrecision): mergedParams = (True, (V0, V0 + two_pi)) else: - if is_same_value(V0, 0.0, tol.relativePrecision) and is_same_value( - V1, two_pi, tol.relativePrecision + if is_same_value(V0, 0.0, self.tolerances.relativePrecision) and is_same_value( + V1, two_pi, self.tolerances.relativePrecision ): for i in range(len(params) - 1): if not is_same_value( - params[i][1], params[i + 1][0], tol.relativePrecision + params[i][1], params[i + 1][0], self.tolerances.relativePrecision ): break v_min = params[i + 1][0] - two_pi diff --git a/src/geouned/GEOUNED/Utils/Options/Classes.py b/src/geouned/GEOUNED/Utils/Options/Classes.py index 90f6198d..7dd1d5e1 100644 --- a/src/geouned/GEOUNED/Utils/Options/Classes.py +++ b/src/geouned/GEOUNED/Utils/Options/Classes.py @@ -1,17 +1,3 @@ -class Tolerances: - from .tolerancesDefault import KwrdEquiv, default_values, type_dict - - @classmethod - def set_default_attribute(cls): - for key, value in cls.default_values.items(): - setattr(cls, key, value) - - @classmethod - def set_attribute(cls, key, value): - if key in cls.default_values.keys(): - setattr(cls, key, value) - - class McnpNumericFormat: from .mcnpNumericDefault import default_values diff --git a/src/geouned/GEOUNED/Utils/Options/tolerancesDefault.py b/src/geouned/GEOUNED/Utils/Options/tolerancesDefault.py deleted file mode 100644 index 78dc4370..00000000 --- a/src/geouned/GEOUNED/Utils/Options/tolerancesDefault.py +++ /dev/null @@ -1,53 +0,0 @@ -default_values = { - "relativeTol": False, - "relativePrecision": 1.0e-6, # relative precision - "value": 1.0e-6, # Tolerance in single value comparison - "distance": 1.0e-4, # General Distance Tolerance - "angle": 1.0e-4, # General Angle Tolerance - "pln_distance": 1.0e-4, # distance between planes equal planes if distance between parallel planes < 1e-4 cm - "pln_angle": 1.0e-4, # angle between axis. 1e-4 : planes separate each other 0.1mm each 1m - "cyl_distance": 1.0e-4, # distance between radius/center - "cyl_angle": 1.0e-4, # angle between axis - "sph_distance": 1.0e-4, # distance between radius/center - "kne_distance": 1.0e-4, # distance between apex - "kne_angle": 1.0e-4, # angle between semiangles/axis - "tor_distance": 1.0e-4, # distance between Major/Minor radii/center - "tor_angle": 1.0e-4, # angle between axis - "min_area": 1.0e-2, # minimun face area to consider in cell definition -} - -type_dict = { - "relativeTol": bool, - "relativePrecision": float, # relative precision - "value": float, # Tolerance in single value comparison - "distance": float, # General Distance Tolerance - "angle": float, # General Angle Tolerance - "pln_distance": float, # distance between planes equal planes if distance between parallel planes < 1e-4 cm - "pln_angle": float, # angle between axis. 1e-4 : planes separate each other 0.1mm each 1m - "cyl_distance": float, # distance between radius/center - "cyl_angle": float, # angle between axis - "sph_distance": float, # distance between radius/center - "kne_distance": float, # distance between apex - "kne_angle": float, # angle between semiangles/axis - "tor_distance": float, # distance between Major/Minor radii/center - "tor_angle": float, # angle between axis - "min_area": float, # minimun face area to consider in cell definition -} - -KwrdEquiv = { - "relativeTolerance": "relativeTol", - "relativePrecision": "relativePrecision", - "singleValue": "value", - "generalDistance": "distance", - "generalAngle": "angle", - "planeDistance": "pln_distance", - "planeAngle": "pln_angle", - "cylinderDistance": "cyl_distance", - "cylinderAngle": "cyl_angle", - "sphereDistance": "sph_distance", - "coneDistance": "kne_distance", - "coneAngle": "kne_angle", - "torusDistance": "tor_distance", - "torusAngle": "tor_angle", - "minArea": "min_area", -} diff --git a/src/geouned/GEOUNED/Utils/data_classes.py b/src/geouned/GEOUNED/Utils/data_classes.py index 438ee0bd..d152c769 100644 --- a/src/geouned/GEOUNED/Utils/data_classes.py +++ b/src/geouned/GEOUNED/Utils/data_classes.py @@ -69,3 +69,60 @@ def __init__( self.Facets = Facets self.prnt3PPlane = prnt3PPlane self.forceNoOverlap = forceNoOverlap + + +class Tolerances: + """_summary_ + + Args: + relativeTol (bool, optional): _description_. Defaults to False. + relativePrecision (float, optional): relative precision. Defaults to 1.0e-6. + value (float, optional): Tolerance in single value comparison. Defaults to 1.0e-6. + distance (float, optional): General Distance Tolerance. Defaults to 1.0e-4. + angle (float, optional): General Angle Tolerance. Defaults to 1.0e-4. + pln_distance (float, optional): distance between planes equal planes if distance between parallel planes < 1e-4 cm. Defaults to 1.0e-4. + pln_angle (float, optional): angle between axis. 1e-4 : planes separate each other 0.1mm each 1m. Defaults to 1.0e-4. + cyl_distance (float, optional): distance between radius/center. Defaults to 1.0e-4. + cyl_angle (float, optional): angle between axis. Defaults to 1.0e-4. + sph_distance (float, optional): distance between radius/center. Defaults to 1.0e-4. + kne_distance (float, optional): distance between apex. Defaults to 1.0e-4. + kne_angle (float, optional): angle between semiangles/axis. Defaults to 1.0e-4. + tor_distance (float, optional): distance between Major/Minor radii/center. Defaults to 1.0e-4. + tor_angle (float, optional): angle between axis. Defaults to 1.0e-4. + min_area (float, optional): minimum face area to consider in cell definition. Defaults to 1.0e-2. + """ + + def __init__( + self, + relativeTol: bool = False, + relativePrecision: float = 1.0e-6, + value: float = 1.0e-6, + distance: float = 1.0e-4, + angle: float = 1.0e-4, + pln_distance: float = 1.0e-4, + pln_angle: float = 1.0e-4, + cyl_distance: float = 1.0e-4, + cyl_angle: float = 1.0e-4, + sph_distance: float = 1.0e-4, + kne_distance: float = 1.0e-4, + kne_angle: float = 1.0e-4, + tor_distance: float = 1.0e-4, + tor_angle: float = 1.0e-4, + min_area: float = 1.0e-2, + ): + + self.relativeTol = relativeTol + self.relativePrecision = relativePrecision + self.value = value + self.distance = distance + self.angle = angle + self.pln_distance = pln_distance + self.pln_angle = pln_angle + self.cyl_distance = cyl_distance + self.cyl_angle = cyl_angle + self.sph_distance = sph_distance + self.kne_distance = kne_distance + self.kne_angle = kne_angle + self.tor_distance = tor_distance + self.tor_angle = tor_angle + self.min_area = min_area diff --git a/src/geouned/GEOUNED/Void/Void.py b/src/geouned/GEOUNED/Void/Void.py index 8be14dbf..fa3e3a55 100644 --- a/src/geouned/GEOUNED/Void/Void.py +++ b/src/geouned/GEOUNED/Void/Void.py @@ -15,7 +15,7 @@ def void_generation( - MetaList, EnclosureList, Surfaces, UniverseBox, setting, init, options + MetaList, EnclosureList, Surfaces, UniverseBox, setting, init, options, tolerances ): voidList = [] @@ -47,7 +47,7 @@ def void_generation( logger.info("Build Void highest enclosure") voids = get_void_def( - newMetaList, Surfaces, EnclosureBox, setting, options, Lev0=True + newMetaList, Surfaces, EnclosureBox, setting, options, tolerances, Lev0=True ) voidList.append(voids) @@ -63,17 +63,17 @@ def void_generation( newMetaList = VF.select_solids(MetaList, encl.SonEnclosures, encl) logger.info(f"Build Void enclosure {j} in enclosure level {i + 1}") # select solids overlapping current enclosure "encl", and lower level enclosures - voids = get_void_def(newMetaList, Surfaces, encl, setting, options) + voids = get_void_def(newMetaList, Surfaces, encl, setting, options, tolerances) voidList.append(voids) - voidList.append(set_graveyard_cell(Surfaces, UniverseBox)) + voidList.append(set_graveyard_cell(Surfaces, UniverseBox, tolerances)) return VF.update_void_list( init, voidList, NestedEnclosure, setting["sort_enclosure"] ) -def get_void_def(MetaList, Surfaces, Enclosure, setting, options, Lev0=False): +def get_void_def(MetaList, Surfaces, Enclosure, setting, options, tolerances, Lev0=False): maxsurf = setting["maxSurf"] maxbracket = setting["maxBracket"] @@ -125,7 +125,7 @@ def get_void_def(MetaList, Surfaces, Enclosure, setting, options, Lev0=False): logger.info(f"build complementary {iloop} {iz}") cell, CellIn = z.get_void_complementary( - Surfaces, options, simplify=simplifyVoid + Surfaces, options, tolerances, simplify=simplifyVoid ) if cell is not None: VoidCell = (cell, (boxDim, CellIn)) @@ -151,14 +151,14 @@ def get_void_def(MetaList, Surfaces, Enclosure, setting, options, Lev0=False): return voidList -def set_graveyard_cell(Surfaces, UniverseBox): +def set_graveyard_cell(Surfaces, UniverseBox, tolerances): Universe = VoidBox([], UniverseBox) - externalBox = get_universe_complementary(Universe, Surfaces) + externalBox = get_universe_complementary(Universe, Surfaces, tolerances) center = UniverseBox.Center radius = 0.51 * UniverseBox.DiagonalLength sphere = GeounedSurface(("Sphere", (center, radius)), UniverseBox) - id, exist = Surfaces.add_sphere(sphere) + id, exist = Surfaces.add_sphere(sphere, tolerances) sphdef = BoolSequence(str(-id)) sphdef.operator = "AND" @@ -184,10 +184,10 @@ def set_graveyard_cell(Surfaces, UniverseBox): # TODO check this is being used -def get_universe_complementary(Universe, Surfaces): +def get_universe_complementary(Universe, Surfaces, tolerances): Def = BoolSequence(operator="OR") for p in Universe.get_bound_planes(): - id, exist = Surfaces.add_plane(p) + id, exist = Surfaces.add_plane(p, tolerances, False) if not exist: Def.elements.append(-id) else: diff --git a/src/geouned/GEOUNED/Void/VoidBoxClass.py b/src/geouned/GEOUNED/Void/VoidBoxClass.py index e25150a2..3a26b62c 100644 --- a/src/geouned/GEOUNED/Void/VoidBoxClass.py +++ b/src/geouned/GEOUNED/Void/VoidBoxClass.py @@ -164,13 +164,13 @@ def refine(self): self.__remove_extra_comp__(m, Cube, mode="dist") return - def get_void_complementary(self, Surfaces, options, simplify="no"): + def get_void_complementary(self, Surfaces, options, tolerances, simplify="no"): if self.PieceEnclosure is None: boxDef = BoolSequence(operator="AND") center = self.BoundBox.Center bBox = self.BoundBox for p in self.get_bound_planes(): - id, exist = Surfaces.add_plane(p) + id, exist = Surfaces.add_plane(p, tolerances, False) if exist: s = Surfaces.get_surface(id) if is_opposite(p.Surf.Axis, s.Surf.Axis): diff --git a/src/geouned/GEOUNED/Write/Functions.py b/src/geouned/GEOUNED/Write/Functions.py index 7a8eb8da..cdf7219c 100644 --- a/src/geouned/GEOUNED/Write/Functions.py +++ b/src/geouned/GEOUNED/Write/Functions.py @@ -6,7 +6,6 @@ from ..Utils import Qform as Qform from ..Utils.BasicFunctions_part1 import is_opposite, is_parallel from ..Utils.Options.Classes import McnpNumericFormat as nf -from ..Utils.Options.Classes import Tolerances as tol from .StringFunctions import remove_redundant @@ -245,7 +244,7 @@ def write_sequence_omc_py(seq, options, prefix="S"): return line -def mcnp_surface(id, Type, surf): +def mcnp_surface(id, Type, surf, tolerances): mcnp_def = "" if Type == "Plane": @@ -263,11 +262,11 @@ def mcnp_surface(id, Type, surf): B = surf.Axis.y C = surf.Axis.z D = surf.Axis.dot(surf.Position) - if surf.Axis.isEqual(FreeCAD.Vector(1, 0, 0), tol.pln_angle): + if surf.Axis.isEqual(FreeCAD.Vector(1, 0, 0), tolerances.pln_angle): mcnp_def = "{:<6d} PX {:{x}}".format(id, D / 10.0, x=nf.P_xyz) - elif surf.Axis.isEqual(FreeCAD.Vector(0, 1, 0), tol.pln_angle): + elif surf.Axis.isEqual(FreeCAD.Vector(0, 1, 0), tolerances.pln_angle): mcnp_def = "{:<6d} PY {:{y}}".format(id, D / 10.0, y=nf.P_xyz) - elif surf.Axis.isEqual(FreeCAD.Vector(0, 0, 1), tol.pln_angle): + elif surf.Axis.isEqual(FreeCAD.Vector(0, 0, 1), tolerances.pln_angle): mcnp_def = "{:<6d} PZ {:{z}}".format(id, D / 10.0, z=nf.P_xyz) else: mcnp_def = "{:<6d} P {:{abc}} {:{abc}} {:{abc}} {:{d}}".format( @@ -279,21 +278,21 @@ def mcnp_surface(id, Type, surf): Dir.normalize() Pos = surf.Center * 0.1 rad = surf.Radius * 0.1 - if is_parallel(Dir, FreeCAD.Vector(1, 0, 0), tol.angle): + if is_parallel(Dir, FreeCAD.Vector(1, 0, 0), tolerances.angle): if Pos.y == 0.0 and Pos.z == 0.0: mcnp_def = "{:<6d} CX {:{r}}".format(id, rad, r=nf.C_r) else: mcnp_def = "{:<6d} C/X {:{yz}} {:{yz}} {:{r}}".format( id, Pos.y, Pos.z, rad, yz=nf.C_xyz, r=nf.C_r ) - elif is_parallel(Dir, FreeCAD.Vector(0, 1, 0), tol.angle): + elif is_parallel(Dir, FreeCAD.Vector(0, 1, 0), tolerances.angle): if Pos.x == 0.0 and Pos.z == 0.0: mcnp_def = "{:<6d} CY {:{r}}".format(id, rad, r=nf.C_r) else: mcnp_def = "{:<6d} C/Y {:{xz}} {:{xz}} {:{r}}".format( id, Pos.x, Pos.z, rad, xz=nf.C_xyz, r=nf.C_r ) - elif is_parallel(Dir, FreeCAD.Vector(0, 0, 1), tol.angle): + elif is_parallel(Dir, FreeCAD.Vector(0, 0, 1), tolerances.angle): if Pos.y == 0.0 and Pos.x == 0.0: mcnp_def = "{:<6d} CZ {:{r}}".format(id, rad, r=nf.C_r) else: @@ -330,9 +329,9 @@ def mcnp_surface(id, Type, surf): X_dir = FreeCAD.Vector(1, 0, 0) Y_dir = FreeCAD.Vector(0, 1, 0) Z_dir = FreeCAD.Vector(0, 0, 1) - if is_parallel(Dir, X_dir, tol.angle): + if is_parallel(Dir, X_dir, tolerances.angle): sheet = 1 - if is_opposite(Dir, X_dir, tol.angle): + if is_opposite(Dir, X_dir, tolerances.angle): sheet = -1 if Apex.y == 0.0 and Apex.z == 0.0: mcnp_def = "{:<6d} KX {:{x}} {:{t2}} {}".format( @@ -349,9 +348,9 @@ def mcnp_surface(id, Type, surf): xyz=nf.K_xyz, t2=nf.K_tan2, ) - elif is_parallel(Dir, Y_dir, tol.angle): + elif is_parallel(Dir, Y_dir, tolerances.angle): sheet = 1 - if is_opposite(Dir, Y_dir, tol.angle): + if is_opposite(Dir, Y_dir, tolerances.angle): sheet = -1 if Apex.x == 0.0 and Apex.z == 0.0: mcnp_def = "{:<6d} KY {:{y}} {:{t2}} {}".format( @@ -368,9 +367,9 @@ def mcnp_surface(id, Type, surf): xyz=nf.K_xyz, t2=nf.K_tan2, ) - elif is_parallel(Dir, Z_dir, tol.angle): + elif is_parallel(Dir, Z_dir, tolerances.angle): sheet = 1 - if is_opposite(Dir, Z_dir, tol.angle): + if is_opposite(Dir, Z_dir, tolerances.angle): sheet = -1 if Apex.x == 0.0 and Apex.y == 0.0: mcnp_def = "{:<6d} KZ {:{z}} {:{t2}} {}".format( @@ -401,7 +400,7 @@ def mcnp_surface(id, Type, surf): # corresponding logic rad = surf.Radius * 0.1 pnt = surf.Center * 0.1 - if pnt.isEqual(FreeCAD.Vector(0, 0, 0), tol.sph_distance): + if pnt.isEqual(FreeCAD.Vector(0, 0, 0), tolerances.sph_distance): mcnp_def = "{:<6d} SO {:{r}}".format(id, rad, r=nf.S_r) else: mcnp_def = "{:<6d} S {:{xyz}} {:{xyz}} {:{xyz}} {:{r}}".format( @@ -414,19 +413,19 @@ def mcnp_surface(id, Type, surf): Pos = surf.Center * 0.1 radMaj = surf.MajorRadius * 0.1 radMin = surf.MinorRadius * 0.1 - if is_parallel(Dir, FreeCAD.Vector(1, 0, 0), tol.angle): + if is_parallel(Dir, FreeCAD.Vector(1, 0, 0), tolerances.angle): mcnp_def = """\ {:<6d} TX {:{xyz}} {:{xyz}} {:{xyz}} {:{r}} {:{r}} {:{r}}""".format( id, Pos.x, Pos.y, Pos.z, radMaj, radMin, radMin, xyz=nf.T_xyz, r=nf.T_r ) - elif is_parallel(Dir, FreeCAD.Vector(0, 1, 0), tol.angle): + elif is_parallel(Dir, FreeCAD.Vector(0, 1, 0), tolerances.angle): mcnp_def = """\ {:<6d} TY {:{xyz}} {:{xyz}} {:{xyz}} {:{r}} {:{r}} {:{r}}""".format( id, Pos.x, Pos.y, Pos.z, radMaj, radMin, radMin, xyz=nf.T_xyz, r=nf.T_r ) - elif is_parallel(Dir, FreeCAD.Vector(0, 0, 1), tol.angle): + elif is_parallel(Dir, FreeCAD.Vector(0, 0, 1), tolerances.angle): mcnp_def = """\ {:<6d} TZ {:{xyz}} {:{xyz}} {:{xyz}} {:{r}} {:{r}} {:{r}}""".format( @@ -436,13 +435,13 @@ def mcnp_surface(id, Type, surf): return trim(mcnp_def, 80) -def open_mc_surface(Type, surf, options, out_xml=True, quadricForm=False): +def open_mc_surface(Type, surf, tolerances, out_xml=True, quadricForm=False): if Type == "Plane": A = surf.Axis.x B = surf.Axis.y C = surf.Axis.z D = surf.Axis.dot(surf.Position) * 0.1 - if surf.Axis.isEqual(FreeCAD.Vector(1, 0, 0), tol.pln_angle): + if surf.Axis.isEqual(FreeCAD.Vector(1, 0, 0), tolerances.pln_angle): if out_xml: omc_surf = "x-plane" coeffs = "{:{x}}".format(D, x=nf.P_xyz) @@ -450,7 +449,7 @@ def open_mc_surface(Type, surf, options, out_xml=True, quadricForm=False): omc_surf = "XPlane" coeffs = f"x0={D}" - elif surf.Axis.isEqual(FreeCAD.Vector(0, 1, 0), tol.pln_angle): + elif surf.Axis.isEqual(FreeCAD.Vector(0, 1, 0), tolerances.pln_angle): if out_xml: omc_surf = "y-plane" coeffs = "{:{x}}".format(D, x=nf.P_xyz) @@ -458,7 +457,7 @@ def open_mc_surface(Type, surf, options, out_xml=True, quadricForm=False): omc_surf = "YPlane" coeffs = f"y0={D}" - elif surf.Axis.isEqual(FreeCAD.Vector(0, 0, 1), tol.pln_angle): + elif surf.Axis.isEqual(FreeCAD.Vector(0, 0, 1), tolerances.pln_angle): if out_xml: omc_surf = "z-plane" coeffs = "{:{x}}".format(D, x=nf.P_xyz) @@ -482,7 +481,7 @@ def open_mc_surface(Type, surf, options, out_xml=True, quadricForm=False): Dir = FreeCAD.Vector(surf.Axis) Dir.normalize() - if is_parallel(Dir, FreeCAD.Vector(1, 0, 0), tol.angle): + if is_parallel(Dir, FreeCAD.Vector(1, 0, 0), tolerances.angle): if out_xml: omc_surf = "x-cylinder" coeffs = "{:{xy}} {:{xy}} {:{r}}".format( @@ -492,7 +491,7 @@ def open_mc_surface(Type, surf, options, out_xml=True, quadricForm=False): omc_surf = "XCylinder" coeffs = f"y0={pos.y},z0={pos.z},r={Rad}" - elif is_parallel(Dir, FreeCAD.Vector(0, 1, 0), tol.angle): + elif is_parallel(Dir, FreeCAD.Vector(0, 1, 0), tolerances.angle): if out_xml: omc_surf = "y-cylinder" coeffs = "{:{xy}} {:{xy}} {:{r}}".format( @@ -502,7 +501,7 @@ def open_mc_surface(Type, surf, options, out_xml=True, quadricForm=False): omc_surf = "YCylinder" coeffs = f"x0={pos.x},z0={pos.z},r={Rad}" - elif is_parallel(Dir, FreeCAD.Vector(0, 0, 1), tol.angle): + elif is_parallel(Dir, FreeCAD.Vector(0, 0, 1), tolerances.angle): if out_xml: omc_surf = "z-cylinder" coeffs = "{:{xy}} {:{xy}} {:{r}}".format( @@ -543,7 +542,7 @@ def open_mc_surface(Type, surf, options, out_xml=True, quadricForm=False): Y_dir = FreeCAD.Vector(0, 1, 0) Z_dir = FreeCAD.Vector(0, 0, 1) - if is_parallel(Dir, X_dir, tol.angle): + if is_parallel(Dir, X_dir, tolerances.angle): if out_xml: omc_surf = "x-cone" coeffs = "{:{xyz}} {:{xyz}} {:{xyz}} {:{t2}}".format( @@ -553,7 +552,7 @@ def open_mc_surface(Type, surf, options, out_xml=True, quadricForm=False): omc_surf = "XCone" coeffs = f"x0={Apex.x},y0={Apex.y},z0={Apex.z},r2={tan2}" - elif is_parallel(Dir, Y_dir, tol.angle): + elif is_parallel(Dir, Y_dir, tolerances.angle): if out_xml: omc_surf = "y-cone" coeffs = "{:{xyz}} {:{xyz}} {:{xyz}} {:{t2}}".format( @@ -563,7 +562,7 @@ def open_mc_surface(Type, surf, options, out_xml=True, quadricForm=False): omc_surf = "YCone" coeffs = f"x0={Apex.x},y0={Apex.y},z0={Apex.z},r2={tan2}" - elif is_parallel(Dir, Z_dir, tol.angle): + elif is_parallel(Dir, Z_dir, tolerances.angle): if out_xml: omc_surf = "z-cone" coeffs = "{:{xyz}} {:{xyz}} {:{xyz}} {:{t2}}".format( @@ -627,11 +626,11 @@ def open_mc_surface(Type, surf, options, out_xml=True, quadricForm=False): Center.x, Center.y, Center.z, majRad, minRad, minRad ) - if is_parallel(Dir, FreeCAD.Vector(1, 0, 0), tol.angle): + if is_parallel(Dir, FreeCAD.Vector(1, 0, 0), tolerances.angle): omc_surf = "x-torus" if out_xml else "XTorus" - elif is_parallel(Dir, FreeCAD.Vector(0, 1, 0), tol.angle): + elif is_parallel(Dir, FreeCAD.Vector(0, 1, 0), tolerances.angle): omc_surf = "y-torus" if out_xml else "YTorus" - elif is_parallel(Dir, FreeCAD.Vector(0, 0, 1), tol.angle): + elif is_parallel(Dir, FreeCAD.Vector(0, 0, 1), tolerances.angle): omc_surf = "z-torus" if out_xml else "ZTorus" else: omc_surf = None @@ -641,7 +640,7 @@ def open_mc_surface(Type, surf, options, out_xml=True, quadricForm=False): return omc_surf, coeffs -def serpent_surface(id, Type, surf): +def serpent_surface(id, Type, surf, options, tolerance): serpent_def = "" if Type == "Plane": @@ -662,11 +661,11 @@ def serpent_surface(id, Type, surf): B = surf.Axis.y C = surf.Axis.z D = surf.Axis.dot(surf.Position) - if surf.Axis.isEqual(FreeCAD.Vector(1, 0, 0), tol.pln_angle): + if surf.Axis.isEqual(FreeCAD.Vector(1, 0, 0), tolerance.pln_angle): serpent_def = f"surf {id} px {D/10:{nf.P_xyz}}" - elif surf.Axis.isEqual(FreeCAD.Vector(0, 1, 0), tol.pln_angle): + elif surf.Axis.isEqual(FreeCAD.Vector(0, 1, 0), tolerance.pln_angle): serpent_def = f"surf {id} py {D/10:{nf.P_xyz}}" - elif surf.Axis.isEqual(FreeCAD.Vector(0, 0, 1), tol.pln_angle): + elif surf.Axis.isEqual(FreeCAD.Vector(0, 0, 1), tolerance.pln_angle): serpent_def = f"surf {id} pz {D/10:{nf.P_xyz}}" else: serpent_def = f"surf {id} plane {A:{nf.P_d}} {B:{nf.P_d}} {C:{nf.P_d}} {D/10:{nf.P_d}}" @@ -676,15 +675,15 @@ def serpent_surface(id, Type, surf): Dir.normalize() Pos = surf.Center * 0.1 rad = surf.Radius * 0.1 - if is_parallel(Dir, FreeCAD.Vector(1, 0, 0), tol.angle): + if is_parallel(Dir, FreeCAD.Vector(1, 0, 0), tolerance.angle): serpent_def = ( f"surf {id} cylx {Pos.y:{nf.C_xyz}} {Pos.z:{nf.C_xyz}} {rad:{nf.C_r}}" ) - elif is_parallel(Dir, FreeCAD.Vector(0, 1, 0), tol.angle): + elif is_parallel(Dir, FreeCAD.Vector(0, 1, 0), tolerance.angle): serpent_def = ( f"surf {id} cyly {Pos.x:{nf.C_xyz}} {Pos.z:{nf.C_xyz}} {rad:{nf.C_r}}" ) - elif is_parallel(Dir, FreeCAD.Vector(0, 0, 1), tol.angle): + elif is_parallel(Dir, FreeCAD.Vector(0, 0, 1), tolerance.angle): serpent_def = f"surf {id} cylz {rad:{nf.C_r}}" else: # Is not still working fine @@ -708,23 +707,23 @@ def serpent_surface(id, Type, surf): # Need to check this # Serpent has no specific card for cone at origin, explicit origin only - if is_parallel(Dir, X_dir, tol.angle): + if is_parallel(Dir, X_dir, tolerance.angle): sheet = 1 - if is_opposite(Dir, X_dir, tol.angle): + if is_opposite(Dir, X_dir, tolerance.angle): sheet = -1 serpent_def = "surf ckx {:{xyz}} {:{xyz}} {:{xyz}} {:{t2}} {}".format( id, Apex.x, Apex.y, Apex.z, tan**2, sheet, xyz=nf.K_xyz, t2=nf.K_tan2 ) - elif is_parallel(Dir, Y_dir, tol.angle): + elif is_parallel(Dir, Y_dir, tolerance.angle): sheet = 1 - if is_opposite(Dir, Y_dir, tol.angle): + if is_opposite(Dir, Y_dir, tolerance.angle): sheet = -1 serpent_def = "surf cky {:{xyz}} {:{xyz}} {:{xyz}} {:{t2}} {}".format( id, Apex.x, Apex.y, Apex.z, tan**2, sheet, xyz=nf.K_xyz, t2=nf.K_tan2 ) - elif is_parallel(Dir, Z_dir, tol.angle): + elif is_parallel(Dir, Z_dir, tolerance.angle): sheet = 1 - if is_opposite(Dir, Z_dir, tol.angle): + if is_opposite(Dir, Z_dir, tolerance.angle): sheet = -1 serpent_def = "surf ckz {:{xyz}} {:{xyz}} {:{xyz}} {:{t2}} {}".format( id, Apex.x, Apex.y, Apex.z, tan**2, sheet, xyz=nf.K_xyz, t2=nf.K_tan2 @@ -744,17 +743,17 @@ def serpent_surface(id, Type, surf): Pos = surf.Center * 0.1 radMaj = surf.MajorRadius * 0.1 radMin = surf.MinorRadius * 0.1 - if is_parallel(Dir, FreeCAD.Vector(1, 0, 0), tol.angle): + if is_parallel(Dir, FreeCAD.Vector(1, 0, 0), tolerance.angle): serpent_def = f"surf {id} torx {Pos.x:{nf.T_xyz}} {Pos.y:{nf.T_xyz}} {Pos.z:{nf.T_xyz}}\n" serpent_def += ( f" {radMaj:{nf.T_r}} {radMin:{nf.T_r}} {radMin:{nf.T_r}}" ) - elif is_parallel(Dir, FreeCAD.Vector(0, 1, 0), tol.angle): + elif is_parallel(Dir, FreeCAD.Vector(0, 1, 0), tolerance.angle): serpent_def = f"surf {id} tory {Pos.x:{nf.T_xyz}} {Pos.y:{nf.T_xyz}} {Pos.z:{nf.T_xyz}}\n" serpent_def += ( f" {radMaj:{nf.T_r}} {radMin:{nf.T_r}} {radMin:{nf.T_r}}" ) - elif is_parallel(Dir, FreeCAD.Vector(0, 0, 1), tol.angle): + elif is_parallel(Dir, FreeCAD.Vector(0, 0, 1), tolerance.angle): serpent_def = f"surf {id} torz {Pos.x:{nf.T_xyz}} {Pos.y:{nf.T_xyz}} {Pos.z:{nf.T_xyz}}\n" serpent_def += ( f" {radMaj:{nf.T_r}} {radMin:{nf.T_r}} {radMin:{nf.T_r}}" @@ -763,7 +762,7 @@ def serpent_surface(id, Type, surf): return serpent_def -def phits_surface(id, Type, surf, options): +def phits_surface(id, Type, surf, options, tolerance): phits_def = "" if Type == "Plane": @@ -781,11 +780,11 @@ def phits_surface(id, Type, surf, options): B = surf.Axis.y C = surf.Axis.z D = surf.Axis.dot(surf.Position) - if surf.Axis.isEqual(FreeCAD.Vector(1, 0, 0), tol.pln_angle): + if surf.Axis.isEqual(FreeCAD.Vector(1, 0, 0), tolerance.pln_angle): phits_def = "{:<6d} PX {:{x}}".format(id, D / 10.0, x=nf.P_xyz) - elif surf.Axis.isEqual(FreeCAD.Vector(0, 1, 0), tol.pln_angle): + elif surf.Axis.isEqual(FreeCAD.Vector(0, 1, 0), tolerance.pln_angle): phits_def = "{:<6d} PY {:{y}}".format(id, D / 10.0, y=nf.P_xyz) - elif surf.Axis.isEqual(FreeCAD.Vector(0, 0, 1), tol.pln_angle): + elif surf.Axis.isEqual(FreeCAD.Vector(0, 0, 1), tolerance.pln_angle): phits_def = "{:<6d} PZ {:{z}}".format(id, D / 10.0, z=nf.P_xyz) else: phits_def = "{:<6d} P {:{abc}} {:{abc}} {:{abc}} {:{d}}".format( @@ -797,21 +796,21 @@ def phits_surface(id, Type, surf, options): Dir.normalize() Pos = surf.Center * 0.1 rad = surf.Radius * 0.1 - if is_parallel(Dir, FreeCAD.Vector(1, 0, 0), tol.angle): + if is_parallel(Dir, FreeCAD.Vector(1, 0, 0), tolerance.angle): if Pos.y == 0.0 and Pos.z == 0.0: phits_def = "{:<6d} CX {:{r}}".format(id, rad, r=nf.C_r) else: phits_def = "{:<6d} C/X {:{yz}} {:{yz}} {:{r}}".format( id, Pos.y, Pos.z, rad, yz=nf.C_xyz, r=nf.C_r ) - elif is_parallel(Dir, FreeCAD.Vector(0, 1, 0), tol.angle): + elif is_parallel(Dir, FreeCAD.Vector(0, 1, 0), tolerance.angle): if Pos.x == 0.0 and Pos.z == 0.0: phits_def = "{:<6d} CY {:{r}}".format(id, rad, r=nf.C_r) else: phits_def = "{:<6d} C/Y {:{xz}} {:{xz}} {:{r}}".format( id, Pos.x, Pos.z, rad, xz=nf.C_xyz, r=nf.C_r ) - elif is_parallel(Dir, FreeCAD.Vector(0, 0, 1), tol.angle): + elif is_parallel(Dir, FreeCAD.Vector(0, 0, 1), tolerance.angle): if Pos.y == 0.0 and Pos.x == 0.0: phits_def = "{:<6d} CZ {:{r}}".format(id, rad, r=nf.C_r) else: @@ -848,9 +847,9 @@ def phits_surface(id, Type, surf, options): X_dir = FreeCAD.Vector(1, 0, 0) Y_dir = FreeCAD.Vector(0, 1, 0) Z_dir = FreeCAD.Vector(0, 0, 1) - if is_parallel(Dir, X_dir, tol.angle): + if is_parallel(Dir, X_dir, tolerance.angle): sheet = 1 - if is_opposite(Dir, X_dir, tol.angle): + if is_opposite(Dir, X_dir, tolerance.angle): sheet = -1 if Apex.y == 0.0 and Apex.z == 0.0: phits_def = "{:<6d} KX {:{x}} {:{t2}} {}".format( @@ -867,9 +866,9 @@ def phits_surface(id, Type, surf, options): xyz=nf.K_xyz, t2=nf.K_tan2, ) - elif is_parallel(Dir, Y_dir, tol.angle): + elif is_parallel(Dir, Y_dir, tolerance.angle): sheet = 1 - if is_opposite(Dir, Y_dir, tol.angle): + if is_opposite(Dir, Y_dir, tolerance.angle): sheet = -1 if Apex.x == 0.0 and Apex.z == 0.0: phits_def = "{:<6d} KY {:{y}} {:{t2}} {}".format( @@ -886,9 +885,9 @@ def phits_surface(id, Type, surf, options): xyz=nf.K_xyz, t2=nf.K_tan2, ) - elif is_parallel(Dir, Z_dir, tol.angle): + elif is_parallel(Dir, Z_dir, tolerance.angle): sheet = 1 - if is_opposite(Dir, Z_dir, tol.angle): + if is_opposite(Dir, Z_dir, tolerance.angle): sheet = -1 if Apex.x == 0.0 and Apex.y == 0.0: phits_def = "{:<6d} KZ {:{z}} {:{t2}} {}".format( @@ -919,7 +918,7 @@ def phits_surface(id, Type, surf, options): # corresponding logic rad = surf.Radius * 0.1 pnt = surf.Center * 0.1 - if pnt.isEqual(FreeCAD.Vector(0, 0, 0), tol.sph_distance): + if pnt.isEqual(FreeCAD.Vector(0, 0, 0), tolerance.sph_distance): phits_def = "{:<6d} SO {:{r}}".format(id, rad, r=nf.S_r) else: phits_def = "{:<6d} S {:{xyz}} {:{xyz}} {:{xyz}} {:{r}}".format( @@ -932,19 +931,19 @@ def phits_surface(id, Type, surf, options): Pos = surf.Center * 0.1 radMaj = surf.MajorRadius * 0.1 radMin = surf.MinorRadius * 0.1 - if is_parallel(Dir, FreeCAD.Vector(1, 0, 0), tol.angle): + if is_parallel(Dir, FreeCAD.Vector(1, 0, 0), tolerance.angle): phits_def = """\ {:<6d} TX {:{xyz}} {:{xyz}} {:{xyz}} {:{r}} {:{r}} {:{r}}""".format( id, Pos.x, Pos.y, Pos.z, radMaj, radMin, radMin, xyz=nf.T_xyz, r=nf.T_r ) - elif is_parallel(Dir, FreeCAD.Vector(0, 1, 0), tol.angle): + elif is_parallel(Dir, FreeCAD.Vector(0, 1, 0), tolerance.angle): phits_def = """\ {:<6d} TY {:{xyz}} {:{xyz}} {:{xyz}} {:{r}} {:{r}} {:{r}}""".format( id, Pos.x, Pos.y, Pos.z, radMaj, radMin, radMin, xyz=nf.T_xyz, r=nf.T_r ) - elif is_parallel(Dir, FreeCAD.Vector(0, 0, 1), tol.angle): + elif is_parallel(Dir, FreeCAD.Vector(0, 0, 1), tolerance.angle): phits_def = """\ {:<6d} TZ {:{xyz}} {:{xyz}} {:{xyz}} {:{r}} {:{r}} {:{r}}""".format( diff --git a/src/geouned/GEOUNED/Write/MCNPFormat.py b/src/geouned/GEOUNED/Write/MCNPFormat.py index e43cc918..63ca7bd5 100644 --- a/src/geouned/GEOUNED/Write/MCNPFormat.py +++ b/src/geouned/GEOUNED/Write/MCNPFormat.py @@ -16,7 +16,7 @@ class McnpInput: - def __init__(self, Meta, Surfaces, setting, options): + def __init__(self, Meta, Surfaces, setting, options, tolerances): self.Title = setting["title"] self.VolSDEF = setting["volSDEF"] self.VolCARD = setting["volCARD"] @@ -24,6 +24,7 @@ def __init__(self, Meta, Surfaces, setting, options): self.dummyMat = setting["dummyMat"] self.Cells = Meta self.options = options + self.tolerances = tolerances self.Options = { "Volume": self.VolCARD, "Particle": ("n", "p"), @@ -165,7 +166,7 @@ def __write_cells__(self, cell): def __write_surfaces__(self, surface): """Write the surfaces in MCNP format""" - MCNP_def = mcnp_surface(surface.Index, surface.Type, surface.Surf) + MCNP_def = mcnp_surface(surface.Index, surface.Type, surface.Surf, self.tolerances) if MCNP_def: MCNP_def += "\n" self.inpfile.write(MCNP_def) diff --git a/src/geouned/GEOUNED/Write/OpenMCFormat.py b/src/geouned/GEOUNED/Write/OpenMCFormat.py index a713a6be..1d2ac60f 100644 --- a/src/geouned/GEOUNED/Write/OpenMCFormat.py +++ b/src/geouned/GEOUNED/Write/OpenMCFormat.py @@ -14,10 +14,11 @@ class OpenmcInput: - def __init__(self, Meta, Surfaces, options): + def __init__(self, Meta, Surfaces, options, tolerances): self.Cells = Meta self.options = options + self.tolerances = tolerances self.__get_surface_table__() self.__simplify_planes__(Surfaces) @@ -80,7 +81,7 @@ def __write_xml_cells__(self, cell): def __write_xml_surfaces__(self, surface, boundary=False): """Write the surfaces in xml OpenMC format""" - surfType, coeffs = open_mc_surface(surface.Type, surface.Surf, self.options) + surfType, coeffs = open_mc_surface(surface.Type, surface.Surf, self.tolerances) if not boundary: OMCsurf = ' \n'.format( @@ -158,7 +159,7 @@ def __write_py_surfaces__(self, surface, boundary=False): surfType, coeffs = open_mc_surface( surface.Type, surface.Surf, - self.options, + self.tolerances, out_xml=False, quadricForm=self.options.quadricPY, ) diff --git a/src/geouned/GEOUNED/Write/PHITSFormat.py b/src/geouned/GEOUNED/Write/PHITSFormat.py index 012f202b..f47e9436 100644 --- a/src/geouned/GEOUNED/Write/PHITSFormat.py +++ b/src/geouned/GEOUNED/Write/PHITSFormat.py @@ -31,7 +31,7 @@ class PhitsInput: - def __init__(self, Meta, Surfaces, setting, options): + def __init__(self, Meta, Surfaces, setting, options, tolerances): self.Title = setting["title"] self.VolSDEF = setting["volSDEF"] self.VolCARD = setting["volCARD"] @@ -41,6 +41,7 @@ def __init__(self, Meta, Surfaces, setting, options): self.voidMat = setting["voidMat"] self.startCell = setting["startCell"] self.Cells = Meta + self.tolerances = tolerances self.options = options self.Options = {"Volume": self.VolCARD, "Universe": self.U0CARD} @@ -370,7 +371,7 @@ def __write_phits_surfaces__(self, surface): """Write the surfaces in PHITS format""" PHITS_def = phits_surface( - surface.Index, surface.Type, surface.Surf, self.options + surface.Index, surface.Type, surface.Surf, self.options, self.tolerances ) if PHITS_def: PHITS_def += "\n" diff --git a/src/geouned/GEOUNED/Write/SerpentFormat.py b/src/geouned/GEOUNED/Write/SerpentFormat.py index 687ec8d9..a899df77 100644 --- a/src/geouned/GEOUNED/Write/SerpentFormat.py +++ b/src/geouned/GEOUNED/Write/SerpentFormat.py @@ -15,7 +15,9 @@ class SerpentInput: - def __init__(self, Meta, Surfaces, setting, options): + def __init__(self, Meta, Surfaces, setting, options, tolerances): + self.options = options + self.tolerances = tolerances self.Title = setting["title"] self.VolSDEF = setting["volSDEF"] self.VolCARD = setting["volCARD"] @@ -37,7 +39,7 @@ def __init__(self, Meta, Surfaces, setting, options): self.Title = self.StepFile self.__get_surface_table__() - self.__simplify_planes__(Surfaces, options) + self.__simplify_planes__(Surfaces) self.Surfaces = self.__sorted_surfaces__(Surfaces) self.Materials = set() @@ -173,7 +175,7 @@ def __write_cells__(self, cell): def __write_surfaces__(self, surface): """Write the surfaces in Serpent format""" - Serpent_def = serpent_surface(surface.Index, surface.Type, surface.Surf) + Serpent_def = serpent_surface(surface.Index, surface.Type, surface.Surf, self.options, self.tolerances) if Serpent_def: Serpent_def += "\n" self.inpfile.write(Serpent_def) @@ -301,7 +303,7 @@ def __get_surface_table__(self): self.surfaceTable[index] = {i} return - def __simplify_planes__(self, Surfaces, options): + def __simplify_planes__(self, Surfaces): for p in Surfaces["PX"]: if p.Surf.Axis[0] < 0: @@ -318,7 +320,7 @@ def __simplify_planes__(self, Surfaces, options): p.Surf.Axis = FreeCAD.Vector(0, 0, 1) self.__change_surf_sign__(p) - if options.prnt3PPlane: + if self.options.prnt3PPlane: for p in Surfaces["P"]: if p.Surf.pointDef: axis, d = points_to_coeffs(p.Surf.Points) diff --git a/src/geouned/GEOUNED/Write/WriteFiles.py b/src/geouned/GEOUNED/Write/WriteFiles.py index dc4a6c53..62dacd07 100644 --- a/src/geouned/GEOUNED/Write/WriteFiles.py +++ b/src/geouned/GEOUNED/Write/WriteFiles.py @@ -5,7 +5,7 @@ from .SerpentFormat import SerpentInput -def write_geometry(UniverseBox, MetaList, Surfaces, code_setting, options): +def write_geometry(UniverseBox, MetaList, Surfaces, code_setting, options, tolerances): baseName = code_setting["geometryName"] @@ -39,7 +39,7 @@ def write_geometry(UniverseBox, MetaList, Surfaces, code_setting, options): else: outSphere = None - MCNPfile = McnpInput(MetaList, Surfaces, code_setting, options) + MCNPfile = McnpInput(MetaList, Surfaces, code_setting, options, tolerances) MCNPfile.set_sdef((outSphere, outBox)) MCNPfile.write_input(mcnpFilename) @@ -47,7 +47,7 @@ def write_geometry(UniverseBox, MetaList, Surfaces, code_setting, options): "openMC_XML" in code_setting["outFormat"] or "openMC_PY" in code_setting["outFormat"] ): - OMCFile = OpenmcInput(MetaList, Surfaces, options) + OMCFile = OpenmcInput(MetaList, Surfaces, options, tolerances) if "openMC_XML" in code_setting["outFormat"]: omcFilename = baseName + ".xml" @@ -72,7 +72,7 @@ def write_geometry(UniverseBox, MetaList, Surfaces, code_setting, options): else: outSphere = None - Serpentfile = SerpentInput(MetaList, Surfaces, code_setting, options) + Serpentfile = SerpentInput(MetaList, Surfaces, code_setting, options, tolerances) # Serpentfile.set_sdef((outSphere,outBox)) Serpentfile.write_input(serpentFilename) @@ -94,6 +94,6 @@ def write_geometry(UniverseBox, MetaList, Surfaces, code_setting, options): else: PHITS_outSphere = None - PHITSfile = PhitsInput(MetaList, Surfaces, code_setting, options) + PHITSfile = PhitsInput(MetaList, Surfaces, code_setting, options, tolerances) # PHITSfile.setSDEF_PHITS((PHITS_outSphere,PHITS_outBox)) PHITSfile.write_phits(phitsFilename) diff --git a/src/geouned/GEOUNED/__init__.py b/src/geouned/GEOUNED/__init__.py index c2c40a7e..4b36ffc9 100644 --- a/src/geouned/GEOUNED/__init__.py +++ b/src/geouned/GEOUNED/__init__.py @@ -21,11 +21,11 @@ from .LoadFile import LoadSTEP as Load from .Utils import Functions as UF from .Utils.BooleanSolids import build_c_table_from_solids -from .Utils.Options.Classes import McnpNumericFormat, Tolerances +from .Utils.Options.Classes import McnpNumericFormat from .Void import Void as Void from .Write.Functions import write_mcnp_cell_def from .Write.WriteFiles import write_geometry -from .Utils.data_classes import Options +from .Utils.data_classes import Options, Tolerances logger = logging.getLogger(__name__) @@ -132,6 +132,7 @@ def __init__( cellSummaryFile: bool = True, sort_enclosure: bool = False, options: Options = Options(), + tolerances: Tolerances = Tolerances(), ): self.title = title @@ -160,9 +161,9 @@ def __init__( self.cellSummaryFile = cellSummaryFile self.sort_enclosure = sort_enclosure self.options = options + self.tolerances = tolerances McnpNumericFormat.set_default_attribute() - Tolerances.set_default_attribute() def set_configuration(self, configFile=None): @@ -255,16 +256,15 @@ def set_configuration(self, configFile=None): elif section == "Tolerances": for key in config["Tolerances"].keys(): - eqvKey = Tolerances.KwrdEquiv[key] - if eqvKey in Tolerances.default_values.keys(): - if Tolerances.type_dict[eqvKey] is bool: - Tolerances.set_attribute( - eqvKey, config.getboolean("Tolerances", key) - ) - elif Tolerances.type_dict[eqvKey] is float: - Tolerances.set_attribute( - eqvKey, config.getfloat("Tolerances", key) - ) + attributes_and_types = get_type_hints(Tolerances()) + if key in attributes_and_types.keys(): + if attributes_and_types[key] is bool: + value = config.getboolean("Tolerances", key) + elif ( + attributes_and_types[key] is float + ): + value = config.getfloat("Tolerances", key) + setattr(self.tolerances, key, value) elif section == "MCNP_Numeric_Format": PdEntry = False @@ -292,9 +292,6 @@ def set(self, kwrd, value): if kwrd in McnpNumericFormat.default_values.keys(): McnpNumericFormat.set_attribute(kwrd, value) return - elif kwrd in Tolerances.default_values.keys(): - Tolerances.set_attribute(kwrd, value) - return elif kwrd not in self.__dict__.keys(): logger.info(f"Bad entry : {kwrd}") return @@ -435,7 +432,7 @@ def start(self): # decompose all solids in elementary solids (convex ones) warningSolidList = decompose_solids( - MetaList, Surfaces, UniverseBox, code_setting, True, self.options + MetaList, Surfaces, UniverseBox, code_setting, True, self.options, self.tolerances ) # decompose Enclosure solids @@ -447,6 +444,7 @@ def start(self): code_setting, False, self.options, + self.tolerances ) logger.info("End of decomposition phase") @@ -457,7 +455,7 @@ def start(self): if m.IsEnclosure: continue logger.info(f"Building cell: {j+1}") - cones = Conv.cellDef(m, Surfaces, UniverseBox, self.options) + cones = Conv.cellDef(m, Surfaces, UniverseBox, self.options, self.tolerances) if cones: coneInfo[m.__id__] = cones if j in warningSolidList: @@ -480,6 +478,7 @@ def start(self): code_setting, False, self.options, + self.tolerances ) tempstr2 = str(datetime.now() - tempTime) @@ -520,6 +519,7 @@ def start(self): code_setting, init, self.options, + self.tolerances, ) # if code_setting['simplify'] == 'full' and not self.options.forceNoOverlap: @@ -595,10 +595,10 @@ def start(self): print_warning_solids(warnSolids, warnEnclosures) # add plane definition to cone - process_cones(MetaList, coneInfo, Surfaces, UniverseBox) + process_cones(MetaList, coneInfo, Surfaces, UniverseBox, self.tolerances) # write outputformat input - write_geometry(UniverseBox, MetaList, Surfaces, code_setting, self.options) + write_geometry(UniverseBox, MetaList, Surfaces, code_setting, self.options, self.tolerances) logger.info("End of MCNP, OpenMC, Serpent and PHITS translation phase") @@ -609,7 +609,7 @@ def start(self): logger.info(f"Translation time of void cells {tempTime2} - {tempTime1}") -def decompose_solids(MetaList, Surfaces, UniverseBox, setting, meta, options): +def decompose_solids(MetaList, Surfaces, UniverseBox, setting, meta, options, tolerances): totsolid = len(MetaList) warningSolids = [] for i, m in enumerate(tqdm(MetaList, desc="Decomposing solids")): @@ -626,7 +626,7 @@ def decompose_solids(MetaList, Surfaces, UniverseBox, setting, meta, options): m.Solids[0].exportStep(f"debug/origSolid_{i}.stp") comsolid, err = Decom.SplitSolid( - Part.makeCompound(m.Solids), UniverseBox, options + Part.makeCompound(m.Solids), UniverseBox, options, tolerances ) if err != 0: @@ -651,7 +651,7 @@ def decompose_solids(MetaList, Surfaces, UniverseBox, setting, meta, options): else: comsolid.exportStep(f"debug/compSolid_{i}.stp") Surfaces.extend( - Decom.extract_surfaces(comsolid, "All", UniverseBox, MakeObj=True) + Decom.extract_surfaces(comsolid, "All", UniverseBox, tolerances, MakeObj=True), tolerances ) m.set_cad_solid() m.update_solids(comsolid.Solids) @@ -668,7 +668,7 @@ def update_comment(meta, idLabel): meta.set_comments(Void.void_comment_line((meta.__commentInfo__[0], newLabel))) -def process_cones(MetaList, coneInfo, Surfaces, UniverseBox): +def process_cones(MetaList, coneInfo, Surfaces, UniverseBox, tolerances): cellId = tuple(coneInfo.keys()) for m in MetaList: if m.__id__ not in cellId and not m.Void: @@ -681,9 +681,9 @@ def process_cones(MetaList, coneInfo, Surfaces, UniverseBox): for Id in m.__commentInfo__[1]: if Id in cellId: cones.update(-x for x in coneInfo[Id]) - Conv.add_cone_plane(m.Definition, cones, Surfaces, UniverseBox) + Conv.add_cone_plane(m.Definition, cones, Surfaces, UniverseBox, tolerances) elif not m.Void: - Conv.add_cone_plane(m.Definition, coneInfo[m.__id__], Surfaces, UniverseBox) + Conv.add_cone_plane(m.Definition, coneInfo[m.__id__], Surfaces, UniverseBox, tolerances) def get_universe(MetaList): diff --git a/tests/test_convert.py b/tests/test_convert.py index 7d673762..2b651318 100644 --- a/tests/test_convert.py +++ b/tests/test_convert.py @@ -53,7 +53,14 @@ def test_conversion(input_step_file): nPlaneReverse=0, ) - geo = geouned.CadToCsg(title="Input Test", options=my_options) + # default values used, just checking it can be passed in + my_tolerances = geouned.Tolerances() + + geo = geouned.CadToCsg( + title="Input Test", + options=my_options, + tolerances=my_tolerances + ) # set parameters values stored in template dictionary for key, value in template.items(): From f4f8aad6ae68492ca903bc1e0c282cf9398fbeef Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 9 May 2024 19:34:05 +0100 Subject: [PATCH 02/10] added tolerance example to usage section --- docs/usage.rst | 21 +++++++++++++-------- src/geouned/GEOUNED/Utils/data_classes.py | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/docs/usage.rst b/docs/usage.rst index 2954dc5f..65734d6e 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -8,12 +8,12 @@ Python package usage The Python API has two main classes. The first main class is ``CadToCsg()`` which converts CAD geometry to Constructive Solid Geometry (CSG). -There are many arguments that can be passed into the ``CadToCsg()`` class which are documented in the Python API section. +There are many arguments that can be passed into the ``CadToCsg()`` class which are documented in the `Python API section `_ of the documentation. -The most minimal use case below shows GEOUNED being imported and the CadToCsg being used to convert a STEP CAD file called 'cuboid.stp' into a varity of CSG format. -If you have install GEOUNED and FreeCAD into your system PYthon then you can simply run a .py script with python. - +If you have install GEOUNED and FreeCAD into your system Python then you can simply run a .py script with Python. +The most minimal use case below shows GEOUNED being imported and the CadToCsg being used to convert a STEP CAD file called 'cuboid.stp' into a vanity of CSG format. +The example makes use of default attributes. .. code-block:: python @@ -22,9 +22,8 @@ If you have install GEOUNED and FreeCAD into your system PYthon then you can sim geo.start() geo.export_csg() -The above examples makes use of default :meth:`geouned.Options`, :meth:`geouned.Tolerances` and :meth:`geouned.NumericFormat` -Users can change any of these to suit the conversion desired. -The following example changes several default values of the conversion. +Users can change :meth:`geouned.Options`, :meth:`geouned.Tolerances` and :meth:`geouned.NumericFormat` to suit the conversion desired. +The following example shows a more complete usage with several default attributes changed. .. code-block:: python @@ -37,8 +36,14 @@ The following example changes several default values of the conversion. nPlaneReverse=0, ) + my_tolerances = geouned.Tolerances( + min_area=0.011 + ) + geo = geouned.CadToCsg( - stepFile='cuboid.stp', options=my_options + stepFile='cuboid.stp', + options=my_options, + tolerances=my_tolerances ) geo.start() diff --git a/src/geouned/GEOUNED/Utils/data_classes.py b/src/geouned/GEOUNED/Utils/data_classes.py index d152c769..18a7658a 100644 --- a/src/geouned/GEOUNED/Utils/data_classes.py +++ b/src/geouned/GEOUNED/Utils/data_classes.py @@ -72,7 +72,7 @@ def __init__( class Tolerances: - """_summary_ + """A class for containing tolerances values Args: relativeTol (bool, optional): _description_. Defaults to False. From 395bd802d47f48178b9c3115d6c9d7200691b2b1 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 9 May 2024 20:14:56 +0100 Subject: [PATCH 03/10] one set of argument names --- scripts/config.ini | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/config.ini b/scripts/config.ini index c8a2625f..ee88790d 100644 --- a/scripts/config.ini +++ b/scripts/config.ini @@ -67,16 +67,16 @@ cellCommentFile = True [Tolerances] # change default tolerance values -relativeTolerance = False +relativeTol = False # define the general tolerance is the geouned conversion process -generalDistance = 1e-4 -generalAngle = 1e-4 +distance = 1e-4 +angle = 1e-4 # define the tolerance when comparing surfaces to check if there are the same surface -# keywords are : planeDistance, cylinderDistance, coneDistance, torusDistance, sphereDistance -# planeAngle, cylinderAngle, coneAngle, torusAngle -#planeDistance = 1e-2 -#planeAngle = 1e-2 +# keywords are : pln_distance, cyl_distance, kne_distance, tor_distance, sph_distance +# pln_angle, cyl_angle, kne_angle, tor_angle +#pln_distance = 1e-2 +#pln_angle = 1e-2 [MCNP_Numeric_Format] From 62ac77d3ea04df53021e16505d8ae4e576a74bc7 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 9 May 2024 20:33:50 +0100 Subject: [PATCH 04/10] moved atr and types getting out of loop --- src/geouned/GEOUNED/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/geouned/GEOUNED/__init__.py b/src/geouned/GEOUNED/__init__.py index 4b36ffc9..863a9ab6 100644 --- a/src/geouned/GEOUNED/__init__.py +++ b/src/geouned/GEOUNED/__init__.py @@ -242,8 +242,8 @@ def set_configuration(self, configFile=None): self.set(key, tuple(map(int, data))) elif section == "Options": + attributes_and_types = get_type_hints(Options()) for key in config["Options"].keys(): - attributes_and_types = get_type_hints(Options()) if key in attributes_and_types.keys(): if attributes_and_types[key] is bool: value = config.getboolean("Options", key) @@ -255,8 +255,8 @@ def set_configuration(self, configFile=None): setattr(self.options, key, value) elif section == "Tolerances": + attributes_and_types = get_type_hints(Tolerances()) for key in config["Tolerances"].keys(): - attributes_and_types = get_type_hints(Tolerances()) if key in attributes_and_types.keys(): if attributes_and_types[key] is bool: value = config.getboolean("Tolerances", key) From 8afff209cb2d17c7f6d476ff62ba5dd046cb4431 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 9 May 2024 21:14:45 +0100 Subject: [PATCH 05/10] format --- .../GEOUNED/Conversion/CellDefinition.py | 24 +++++++++--- src/geouned/GEOUNED/Decompose/Decom_one.py | 8 +++- .../GEOUNED/Utils/BasicFunctions_part2.py | 18 +++++++-- src/geouned/GEOUNED/Utils/Functions.py | 7 +++- src/geouned/GEOUNED/Utils/Geometry_GU.py | 10 +++-- src/geouned/GEOUNED/Void/Void.py | 8 +++- src/geouned/GEOUNED/Write/MCNPFormat.py | 4 +- src/geouned/GEOUNED/Write/SerpentFormat.py | 4 +- src/geouned/GEOUNED/Write/WriteFiles.py | 4 +- src/geouned/GEOUNED/__init__.py | 37 +++++++++++++------ tests/test_convert.py | 4 +- 11 files changed, 92 insertions(+), 36 deletions(-) diff --git a/src/geouned/GEOUNED/Conversion/CellDefinition.py b/src/geouned/GEOUNED/Conversion/CellDefinition.py index f141d9e1..59abf949 100644 --- a/src/geouned/GEOUNED/Conversion/CellDefinition.py +++ b/src/geouned/GEOUNED/Conversion/CellDefinition.py @@ -822,7 +822,9 @@ def cellDef(meta_obj, surfaces, universe_box, options, tolerances): elif surface_type == "": if ( - is_parallel(face.Surface.Axis, FreeCAD.Vector(1, 0, 0), tolerances.angle) + is_parallel( + face.Surface.Axis, FreeCAD.Vector(1, 0, 0), tolerances.angle + ) or is_parallel( face.Surface.Axis, FreeCAD.Vector(0, 1, 0), tolerances.angle ) @@ -842,7 +844,9 @@ def cellDef(meta_obj, surfaces, universe_box, options, tolerances): u_closed, u_minMax = u_params # u_closed = True if not u_closed: - planes, ORop = gen_torus_annex_u_planes(face, u_minMax, tolerances) + planes, ORop = gen_torus_annex_u_planes( + face, u_minMax, tolerances + ) plane1, plane2 = planes plane = GeounedSurface( ("Plane", plane1), universe_box, Face="Build" @@ -850,7 +854,9 @@ def cellDef(meta_obj, surfaces, universe_box, options, tolerances): id1, exist = surfaces.add_plane(plane, tolerances, False) if exist: p = surfaces.get_surface(id1) - if is_opposite(plane.Surf.Axis, p.Surf.Axis, tolerances.pln_angle): + if is_opposite( + plane.Surf.Axis, p.Surf.Axis, tolerances.pln_angle + ): id1 = -id1 if plane2 is None: @@ -908,11 +914,15 @@ def cellDef(meta_obj, surfaces, universe_box, options, tolerances): plane = GeounedSurface( ("Plane", surf_params), universe_box, Face="Build" ) - id2, exist = surfaces.add_plane(plane, tolerances, False) + id2, exist = surfaces.add_plane( + plane, tolerances, False + ) if exist: p = surfaces.get_surface(id2) if is_opposite( - plane.Surf.Axis, p.Surf.Axis, tolerances.pln_angle + plane.Surf.Axis, + p.Surf.Axis, + tolerances.pln_angle, ): id2 = -id2 @@ -972,7 +982,9 @@ def cellDef(meta_obj, surfaces, universe_box, options, tolerances): if surface_type == "": s = surfaces.get_surface(id) - if is_opposite(face.Surface.Axis, s.Surf.Axis, tolerances.pln_angle): + if is_opposite( + face.Surface.Axis, s.Surf.Axis, tolerances.pln_angle + ): var = -var if str(var) in surf_piece: diff --git a/src/geouned/GEOUNED/Decompose/Decom_one.py b/src/geouned/GEOUNED/Decompose/Decom_one.py index ccd2992a..a7a14ba7 100644 --- a/src/geouned/GEOUNED/Decompose/Decom_one.py +++ b/src/geouned/GEOUNED/Decompose/Decom_one.py @@ -740,7 +740,9 @@ def split_planes_org(Solids, universe_box, options, tolerances): base = item[0] index = item[1] - SPlanes = extract_surfaces(base, "Planes", universe_box, tolerances, MakeObj=True) + SPlanes = extract_surfaces( + base, "Planes", universe_box, tolerances, MakeObj=True + ) Planes = [SPlanes["PX"], SPlanes["PY"], SPlanes["PZ"]] for i in index: del Planes[i] @@ -911,7 +913,9 @@ def split_2nd_order(Solids, universe_box, options, tolerances): while True: cutBase = [] for solid in Base: - Surfaces = extract_surfaces(solid, kind, universe_box, tolerances, False) + Surfaces = extract_surfaces( + solid, kind, universe_box, tolerances, False + ) if len(Surfaces[kind]) == 0: kindBase.append(solid) else: diff --git a/src/geouned/GEOUNED/Utils/BasicFunctions_part2.py b/src/geouned/GEOUNED/Utils/BasicFunctions_part2.py index aeef622c..7f24d2e5 100644 --- a/src/geouned/GEOUNED/Utils/BasicFunctions_part2.py +++ b/src/geouned/GEOUNED/Utils/BasicFunctions_part2.py @@ -47,7 +47,9 @@ def Fuzzy(index, dtype, surf1, surf2, val, tol, tolerances): same_surf_fic.write(line) -def is_same_plane(p1, p2, tolerances, dtol=1e-6, atol=1e-6, rel_tol=True, fuzzy=(False, 0)): +def is_same_plane( + p1, p2, tolerances, dtol=1e-6, atol=1e-6, rel_tol=True, fuzzy=(False, 0) +): if is_parallel(p1.Axis, p2.Axis, atol): d1 = p1.Axis.dot(p1.Position) d2 = p2.Axis.dot(p2.Position) @@ -66,7 +68,9 @@ def is_same_plane(p1, p2, tolerances, dtol=1e-6, atol=1e-6, rel_tol=True, fuzzy= return False -def is_same_cylinder(cyl1, cyl2, tolerances, dtol=1e-6, atol=1e-6, rel_tol=True, fuzzy=(False, 0)): +def is_same_cylinder( + cyl1, cyl2, tolerances, dtol=1e-6, atol=1e-6, rel_tol=True, fuzzy=(False, 0) +): if rel_tol: rtol = dtol * max(cyl2.Radius, cyl1.Radius) else: @@ -76,7 +80,15 @@ def is_same_cylinder(cyl1, cyl2, tolerances, dtol=1e-6, atol=1e-6, rel_tol=True, cyl2.Radius - cyl1.Radius, rtol, 0.5 * rtol, 2 * rtol ) if is_fuzzy and fuzzy[0]: - Fuzzy(fuzzy[1], "cylRad", cyl2, cyl1, abs(cyl2.Radius - cyl1.Radius), rtol, tolerances) + Fuzzy( + fuzzy[1], + "cylRad", + cyl2, + cyl1, + abs(cyl2.Radius - cyl1.Radius), + rtol, + tolerances, + ) if is_same_rad: if is_parallel(cyl1.Axis, cyl2.Axis, atol): diff --git a/src/geouned/GEOUNED/Utils/Functions.py b/src/geouned/GEOUNED/Utils/Functions.py index 9b51a732..5c0a4e39 100644 --- a/src/geouned/GEOUNED/Utils/Functions.py +++ b/src/geouned/GEOUNED/Utils/Functions.py @@ -598,7 +598,10 @@ def add_sphere(self, sph, tolerances): sphere_added = True for i, s in enumerate(self["Sph"]): if BF.is_same_sphere( - sph.Surf, s.Surf, tolerances.sph_distance, rel_tol=tolerances.relativeTol + sph.Surf, + s.Surf, + tolerances.sph_distance, + rel_tol=tolerances.relativeTol, ): sphere_added = False index = s.Index @@ -614,7 +617,7 @@ def add_sphere(self, sph, tolerances): else: return index, True - def add_torus(self, tor, tolerances): + def add_torus(self, tor, tolerances): add_torus = True for i, s in enumerate(self["Tor"]): if BF.is_same_torus( diff --git a/src/geouned/GEOUNED/Utils/Geometry_GU.py b/src/geouned/GEOUNED/Utils/Geometry_GU.py index 276b02ae..14213674 100644 --- a/src/geouned/GEOUNED/Utils/Geometry_GU.py +++ b/src/geouned/GEOUNED/Utils/Geometry_GU.py @@ -213,12 +213,14 @@ def __merge_periodic_uv__(self, parameter, faceList): if arcLength >= two_pi * (1.0 - self.tolerances.relativePrecision): mergedParams = (True, (V0, V0 + two_pi)) else: - if is_same_value(V0, 0.0, self.tolerances.relativePrecision) and is_same_value( - V1, two_pi, self.tolerances.relativePrecision - ): + if is_same_value( + V0, 0.0, self.tolerances.relativePrecision + ) and is_same_value(V1, two_pi, self.tolerances.relativePrecision): for i in range(len(params) - 1): if not is_same_value( - params[i][1], params[i + 1][0], self.tolerances.relativePrecision + params[i][1], + params[i + 1][0], + self.tolerances.relativePrecision, ): break v_min = params[i + 1][0] - two_pi diff --git a/src/geouned/GEOUNED/Void/Void.py b/src/geouned/GEOUNED/Void/Void.py index fa3e3a55..b170a681 100644 --- a/src/geouned/GEOUNED/Void/Void.py +++ b/src/geouned/GEOUNED/Void/Void.py @@ -63,7 +63,9 @@ def void_generation( newMetaList = VF.select_solids(MetaList, encl.SonEnclosures, encl) logger.info(f"Build Void enclosure {j} in enclosure level {i + 1}") # select solids overlapping current enclosure "encl", and lower level enclosures - voids = get_void_def(newMetaList, Surfaces, encl, setting, options, tolerances) + voids = get_void_def( + newMetaList, Surfaces, encl, setting, options, tolerances + ) voidList.append(voids) voidList.append(set_graveyard_cell(Surfaces, UniverseBox, tolerances)) @@ -73,7 +75,9 @@ def void_generation( ) -def get_void_def(MetaList, Surfaces, Enclosure, setting, options, tolerances, Lev0=False): +def get_void_def( + MetaList, Surfaces, Enclosure, setting, options, tolerances, Lev0=False +): maxsurf = setting["maxSurf"] maxbracket = setting["maxBracket"] diff --git a/src/geouned/GEOUNED/Write/MCNPFormat.py b/src/geouned/GEOUNED/Write/MCNPFormat.py index 63ca7bd5..7d75fe2c 100644 --- a/src/geouned/GEOUNED/Write/MCNPFormat.py +++ b/src/geouned/GEOUNED/Write/MCNPFormat.py @@ -166,7 +166,9 @@ def __write_cells__(self, cell): def __write_surfaces__(self, surface): """Write the surfaces in MCNP format""" - MCNP_def = mcnp_surface(surface.Index, surface.Type, surface.Surf, self.tolerances) + MCNP_def = mcnp_surface( + surface.Index, surface.Type, surface.Surf, self.tolerances + ) if MCNP_def: MCNP_def += "\n" self.inpfile.write(MCNP_def) diff --git a/src/geouned/GEOUNED/Write/SerpentFormat.py b/src/geouned/GEOUNED/Write/SerpentFormat.py index a899df77..d8dd20b4 100644 --- a/src/geouned/GEOUNED/Write/SerpentFormat.py +++ b/src/geouned/GEOUNED/Write/SerpentFormat.py @@ -175,7 +175,9 @@ def __write_cells__(self, cell): def __write_surfaces__(self, surface): """Write the surfaces in Serpent format""" - Serpent_def = serpent_surface(surface.Index, surface.Type, surface.Surf, self.options, self.tolerances) + Serpent_def = serpent_surface( + surface.Index, surface.Type, surface.Surf, self.options, self.tolerances + ) if Serpent_def: Serpent_def += "\n" self.inpfile.write(Serpent_def) diff --git a/src/geouned/GEOUNED/Write/WriteFiles.py b/src/geouned/GEOUNED/Write/WriteFiles.py index 62dacd07..ce7109bf 100644 --- a/src/geouned/GEOUNED/Write/WriteFiles.py +++ b/src/geouned/GEOUNED/Write/WriteFiles.py @@ -72,7 +72,9 @@ def write_geometry(UniverseBox, MetaList, Surfaces, code_setting, options, toler else: outSphere = None - Serpentfile = SerpentInput(MetaList, Surfaces, code_setting, options, tolerances) + Serpentfile = SerpentInput( + MetaList, Surfaces, code_setting, options, tolerances + ) # Serpentfile.set_sdef((outSphere,outBox)) Serpentfile.write_input(serpentFilename) diff --git a/src/geouned/GEOUNED/__init__.py b/src/geouned/GEOUNED/__init__.py index 863a9ab6..71e2d035 100644 --- a/src/geouned/GEOUNED/__init__.py +++ b/src/geouned/GEOUNED/__init__.py @@ -260,9 +260,7 @@ def set_configuration(self, configFile=None): if key in attributes_and_types.keys(): if attributes_and_types[key] is bool: value = config.getboolean("Tolerances", key) - elif ( - attributes_and_types[key] is float - ): + elif attributes_and_types[key] is float: value = config.getfloat("Tolerances", key) setattr(self.tolerances, key, value) @@ -432,7 +430,13 @@ def start(self): # decompose all solids in elementary solids (convex ones) warningSolidList = decompose_solids( - MetaList, Surfaces, UniverseBox, code_setting, True, self.options, self.tolerances + MetaList, + Surfaces, + UniverseBox, + code_setting, + True, + self.options, + self.tolerances, ) # decompose Enclosure solids @@ -444,7 +448,7 @@ def start(self): code_setting, False, self.options, - self.tolerances + self.tolerances, ) logger.info("End of decomposition phase") @@ -455,7 +459,9 @@ def start(self): if m.IsEnclosure: continue logger.info(f"Building cell: {j+1}") - cones = Conv.cellDef(m, Surfaces, UniverseBox, self.options, self.tolerances) + cones = Conv.cellDef( + m, Surfaces, UniverseBox, self.options, self.tolerances + ) if cones: coneInfo[m.__id__] = cones if j in warningSolidList: @@ -478,7 +484,7 @@ def start(self): code_setting, False, self.options, - self.tolerances + self.tolerances, ) tempstr2 = str(datetime.now() - tempTime) @@ -598,7 +604,9 @@ def start(self): process_cones(MetaList, coneInfo, Surfaces, UniverseBox, self.tolerances) # write outputformat input - write_geometry(UniverseBox, MetaList, Surfaces, code_setting, self.options, self.tolerances) + write_geometry( + UniverseBox, MetaList, Surfaces, code_setting, self.options, self.tolerances + ) logger.info("End of MCNP, OpenMC, Serpent and PHITS translation phase") @@ -609,7 +617,9 @@ def start(self): logger.info(f"Translation time of void cells {tempTime2} - {tempTime1}") -def decompose_solids(MetaList, Surfaces, UniverseBox, setting, meta, options, tolerances): +def decompose_solids( + MetaList, Surfaces, UniverseBox, setting, meta, options, tolerances +): totsolid = len(MetaList) warningSolids = [] for i, m in enumerate(tqdm(MetaList, desc="Decomposing solids")): @@ -651,7 +661,10 @@ def decompose_solids(MetaList, Surfaces, UniverseBox, setting, meta, options, to else: comsolid.exportStep(f"debug/compSolid_{i}.stp") Surfaces.extend( - Decom.extract_surfaces(comsolid, "All", UniverseBox, tolerances, MakeObj=True), tolerances + Decom.extract_surfaces( + comsolid, "All", UniverseBox, tolerances, MakeObj=True + ), + tolerances, ) m.set_cad_solid() m.update_solids(comsolid.Solids) @@ -683,7 +696,9 @@ def process_cones(MetaList, coneInfo, Surfaces, UniverseBox, tolerances): cones.update(-x for x in coneInfo[Id]) Conv.add_cone_plane(m.Definition, cones, Surfaces, UniverseBox, tolerances) elif not m.Void: - Conv.add_cone_plane(m.Definition, coneInfo[m.__id__], Surfaces, UniverseBox, tolerances) + Conv.add_cone_plane( + m.Definition, coneInfo[m.__id__], Surfaces, UniverseBox, tolerances + ) def get_universe(MetaList): diff --git a/tests/test_convert.py b/tests/test_convert.py index 2b651318..52883127 100644 --- a/tests/test_convert.py +++ b/tests/test_convert.py @@ -57,9 +57,7 @@ def test_conversion(input_step_file): my_tolerances = geouned.Tolerances() geo = geouned.CadToCsg( - title="Input Test", - options=my_options, - tolerances=my_tolerances + title="Input Test", options=my_options, tolerances=my_tolerances ) # set parameters values stored in template dictionary From 3578a8191c1fc551fb75a3240402f2919c598d05 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 9 May 2024 22:43:51 +0100 Subject: [PATCH 06/10] passing missing options and tolerances --- .../GEOUNED/Conversion/CellDefinition.py | 32 ++++++++++--------- src/geouned/GEOUNED/Cuboid/translate.py | 7 ++-- src/geouned/GEOUNED/Decompose/Decom_one.py | 28 ++++++++-------- .../GEOUNED/Utils/BasicFunctions_part2.py | 21 ++++++------ src/geouned/GEOUNED/Utils/Functions.py | 15 ++++++--- src/geouned/GEOUNED/Void/Void.py | 10 +++--- src/geouned/GEOUNED/Void/VoidBoxClass.py | 4 +-- src/geouned/GEOUNED/Write/Functions.py | 2 +- src/geouned/GEOUNED/Write/MCNPFormat.py | 2 +- src/geouned/GEOUNED/__init__.py | 14 ++++---- 10 files changed, 72 insertions(+), 63 deletions(-) diff --git a/src/geouned/GEOUNED/Conversion/CellDefinition.py b/src/geouned/GEOUNED/Conversion/CellDefinition.py index 59abf949..c4a28cb1 100644 --- a/src/geouned/GEOUNED/Conversion/CellDefinition.py +++ b/src/geouned/GEOUNED/Conversion/CellDefinition.py @@ -24,7 +24,7 @@ logger = logging.getLogger(__name__) -def get_id(facein, surfaces, tolerances): +def get_id(facein, surfaces, options, tolerances): surfin = str(facein) if surfin == "": @@ -41,6 +41,7 @@ def get_id(facein, surfaces, tolerances): if BF.is_same_plane( facein, s.Surf, + options=options, tolerances=tolerances, dtol=tolerances.pln_distance, atol=tolerances.pln_angle, @@ -53,6 +54,7 @@ def get_id(facein, surfaces, tolerances): if BF.is_same_cylinder( facein, s.Surf, + options=options, tolerances=tolerances, dtol=tolerances.cyl_distance, atol=tolerances.cyl_angle, @@ -781,7 +783,7 @@ def cellDef(meta_obj, surfaces, universe_box, options, tolerances): and orient == "Reversed" ): # cone additional plane is added afterward - id_face = get_id(face.Surface, surfaces, tolerances) + id_face = get_id(face.Surface, surfaces, options, tolerances) if surface_type == "": cones.add(id_face) if str(id_face) not in surf_piece: @@ -803,7 +805,7 @@ def cellDef(meta_obj, surfaces, universe_box, options, tolerances): Face="Build", ) - id, exist = surfaces.add_plane(p, tolerances, False) + id, exist = surfaces.add_plane(p, options, tolerances, False) sign = sign_plane(face.CenterOfMass, p) if exist: pp = surfaces.get_surface(id) @@ -833,7 +835,7 @@ def cellDef(meta_obj, surfaces, universe_box, options, tolerances): ) ): - idT = get_id(face.Surface, surfaces, tolerances) + idT = get_id(face.Surface, surfaces, options, tolerances) index, u_params = solid_gu.TorusUParams[iface] if index == last_torus: @@ -851,7 +853,7 @@ def cellDef(meta_obj, surfaces, universe_box, options, tolerances): plane = GeounedSurface( ("Plane", plane1), universe_box, Face="Build" ) - id1, exist = surfaces.add_plane(plane, tolerances, False) + id1, exist = surfaces.add_plane(plane, options, tolerances, False) if exist: p = surfaces.get_surface(id1) if is_opposite( @@ -865,7 +867,7 @@ def cellDef(meta_obj, surfaces, universe_box, options, tolerances): plane = GeounedSurface( ("Plane", plane2), universe_box, Face="Build" ) - id2, exist = surfaces.add_plane(plane, tolerances, False) + id2, exist = surfaces.add_plane(plane, options, tolerances, False) if exist: p = surfaces.get_surface(id2) if is_opposite( @@ -908,14 +910,14 @@ def cellDef(meta_obj, surfaces, universe_box, options, tolerances): universe_box, Face="Build", ) - id2, exist = surfaces.add_cylinder(cyl, tolerances) + id2, exist = surfaces.add_cylinder(cyl, options, tolerances) elif surf_type == "Plane": plane = GeounedSurface( ("Plane", surf_params), universe_box, Face="Build" ) id2, exist = surfaces.add_plane( - plane, tolerances, False + plane, options, tolerances, False ) if exist: p = surfaces.get_surface(id2) @@ -937,7 +939,7 @@ def cellDef(meta_obj, surfaces, universe_box, options, tolerances): "Only Torus with axis along X, Y, Z axis can be reproduced" ) else: - id = get_id(face.Surface, surfaces, tolerances) + id = get_id(face.Surface, surfaces, options, tolerances) if surface_type == "": cones.add(-id) @@ -955,7 +957,7 @@ def cellDef(meta_obj, surfaces, universe_box, options, tolerances): universe_box, Face="Build", ) - id, exist = surfaces.add_plane(plane, tolerances, False) + id, exist = surfaces.add_plane(plane, options, tolerances, False) surf = plane.shape elif surface_type == "": dim_l = face.ParameterRange[3] - face.ParameterRange[2] @@ -972,7 +974,7 @@ def cellDef(meta_obj, surfaces, universe_box, options, tolerances): universe_box, Face="Build", ) - id, exist = surfaces.add_cylinder(cylinder, tolerances) + id, exist = surfaces.add_cylinder(cylinder, options, tolerances) surf = cylinder.shape if orient == "Reversed": @@ -1159,7 +1161,7 @@ def no_overlapping_cell(metaList, surfaces, options): # TODO this function looks like it is not used in the code. -def extra_plane_cyl_face(face, box, surfaces, tolerances): +def extra_plane_cyl_face(face, box, surfaces, options, tolerances): wire = face.OuterWire planes_id = [] for e in wire.OrderedEdges: @@ -1176,7 +1178,7 @@ def extra_plane_cyl_face(face, box, surfaces, tolerances): plane = GeounedSurface( ("Plane", (center, dir, dim1, dim2)), box, Face="Build" ) - id, exist = surfaces.add_plane(plane, tolerances, False) + id, exist = surfaces.add_plane(plane, options, tolerances, False) if exist: pp = surfaces.get_surface(id) if is_opposite(plane.Surf.Axis, pp.Surf.Axis, tolerances.pln_angle): @@ -1185,7 +1187,7 @@ def extra_plane_cyl_face(face, box, surfaces, tolerances): return planes_id -def add_cone_plane(definition, cones_list, surfaces, universe_box, tolerances): +def add_cone_plane(definition, cones_list, surfaces, universe_box, options, tolerances): x_axis = FreeCAD.Vector(1, 0, 0) y_axis = FreeCAD.Vector(0, 1, 0) z_axis = FreeCAD.Vector(0, 0, 1) @@ -1204,7 +1206,7 @@ def add_cone_plane(definition, cones_list, surfaces, universe_box, tolerances): universe_box, Face="Build", ) - pid, exist = surfaces.add_plane(plane, tolerances, False) + pid, exist = surfaces.add_plane(plane, options, tolerances, False) if exist: p = surfaces.get_surface(pid) diff --git a/src/geouned/GEOUNED/Cuboid/translate.py b/src/geouned/GEOUNED/Cuboid/translate.py index 962901bd..f9bb687d 100644 --- a/src/geouned/GEOUNED/Cuboid/translate.py +++ b/src/geouned/GEOUNED/Cuboid/translate.py @@ -62,7 +62,7 @@ def is_inverted(solid): return False -def get_id(face_in, Surfaces, tolerances): +def get_id(face_in, Surfaces, options, tolerances): if is_parallel(face_in.Axis, FreeCAD.Vector(1, 0, 0), tolerances.pln_angle): plane = "PX" @@ -77,6 +77,7 @@ def get_id(face_in, Surfaces, tolerances): if BF.is_same_plane( face_in, s.Surf, + options=options, tolerances=tolerances, dtol=tolerances.pln_distance, atol=tolerances.pln_angle, @@ -87,7 +88,7 @@ def get_id(face_in, Surfaces, tolerances): return 0 -def translate(meta_list, surfaces, universe_box, setting): +def translate(meta_list, surfaces, universe_box, setting, options, tolerances,): tot_solid = len(meta_list) for i, m in enumerate(meta_list): if m.IsEnclosure: @@ -102,7 +103,7 @@ def translate(meta_list, surfaces, universe_box, setting): surfaces.extend( Decom.extract_surfaces( - Part.makeCompound(m.Solids), "Plane3Pts", universe_box, MakeObj=False + Part.makeCompound(m.Solids), "Plane3Pts", universe_box, options, tolerances, MakeObj=False ) ) set_definition(m, surfaces) diff --git a/src/geouned/GEOUNED/Decompose/Decom_one.py b/src/geouned/GEOUNED/Decompose/Decom_one.py index a7a14ba7..b65b247a 100644 --- a/src/geouned/GEOUNED/Decompose/Decom_one.py +++ b/src/geouned/GEOUNED/Decompose/Decom_one.py @@ -71,12 +71,12 @@ def cut_full_cylinder(solid, options, tolerances): ("Cylinder", (orig, dir, rad, dim_l)), universe_box ) cylinder.build_surface() - surfaces.add_cylinder(cylinder, False) + surfaces.add_cylinder(cylinder, options, tolerances, False) # add planes if cylinder axis is cut by a plane (plane quasi perpedicular to axis) for p in cyl_bound_planes(face, universe_box): p.build_surface() - surfaces.add_plane(p, tolerances, False) + surfaces.add_plane(p, options, tolerances, False) break planes = [] @@ -221,7 +221,7 @@ def plane_spline_curve(edge, tolerances): return None -def extract_surfaces(solid, kind, universe_box, tolerances, MakeObj): +def extract_surfaces(solid, kind, universe_box, options, tolerances, MakeObj): if kind == "All": fuzzy = True solid_parts = [] @@ -253,7 +253,7 @@ def extract_surfaces(solid, kind, universe_box, tolerances, MakeObj): ) if MakeObj: plane.build_surface() - surfaces.add_plane(plane, tolerances, fuzzy) + surfaces.add_plane(plane, options, tolerances, fuzzy) elif surf == "": dir = face.Surface.Axis @@ -266,14 +266,14 @@ def extract_surfaces(solid, kind, universe_box, tolerances, MakeObj): ) if MakeObj: cylinder.build_surface() - surfaces.add_cylinder(cylinder, tolerances, fuzzy) + surfaces.add_cylinder(cylinder, options, tolerances, fuzzy) if kind in ["Planes", "All"]: # add planes if cylinder axis is cut by a plane (plane quasi perpedicular to axis) for p in cyl_bound_planes(face, universe_box): if MakeObj: p.build_surface() - surfaces.add_plane(p, tolerances, False) + surfaces.add_plane(p, options, tolerances, False) elif surf == "": dir = face.Surface.Axis @@ -293,7 +293,7 @@ def extract_surfaces(solid, kind, universe_box, tolerances, MakeObj): for p in cyl_bound_planes(face, universe_box): if MakeObj: p.build_surface() - surfaces.add_plane(p, tolerances, False) + surfaces.add_plane(p, options, tolerances, False) elif surf[0:6] == "Sphere" and kind in ["Sph", "All"]: rad = face.Surface.Radius @@ -307,7 +307,7 @@ def extract_surfaces(solid, kind, universe_box, tolerances, MakeObj): for p in cyl_bound_planes(face, universe_box): if MakeObj: p.build_surface() - surfaces.add_plane(p, tolerances, False) + surfaces.add_plane(p, options, tolerances, False) elif surf == "": if kind in ["Tor", "All"]: @@ -326,7 +326,7 @@ def extract_surfaces(solid, kind, universe_box, tolerances, MakeObj): for p in torus_bound_planes(face, universe_box, tolerances): if MakeObj: p.build_surface() - surfaces.add_plane(p, tolerances, False) + surfaces.add_plane(p, options, tolerances, False) elif surf == "" and kind == "Plane3Pts": pos = face.CenterOfMass @@ -340,7 +340,7 @@ def extract_surfaces(solid, kind, universe_box, tolerances, MakeObj): ) if MakeObj: plane.build_surface() - surfaces.add_plane(plane, tolerances, fuzzy) + surfaces.add_plane(plane, options, tolerances, fuzzy) return surfaces @@ -741,7 +741,7 @@ def split_planes_org(Solids, universe_box, options, tolerances): base = item[0] index = item[1] SPlanes = extract_surfaces( - base, "Planes", universe_box, tolerances, MakeObj=True + base, "Planes", universe_box, options, tolerances, MakeObj=True ) Planes = [SPlanes["PX"], SPlanes["PY"], SPlanes["PZ"]] for i in index: @@ -865,7 +865,7 @@ def sort_planes(PlaneList, sortElements=False): def split_p_planes_new(solid, universe_box, options, tolerances): - SPlanes = extract_surfaces(solid, "Planes", universe_box, tolerances, False) + SPlanes = extract_surfaces(solid, "Planes", universe_box, options, tolerances, False) Planes = [] for P in ("PX", "PY", "PZ", "P"): @@ -891,7 +891,7 @@ def split_p_planes_new(solid, universe_box, options, tolerances): def split_p_planes_org(solid, universe_box, options, tolerances): - SPlanes = extract_surfaces(solid, "Planes", universe_box, tolerances, False) + SPlanes = extract_surfaces(solid, "Planes", universe_box, options, tolerances, False) if len(SPlanes["P"]) == 0: return [solid] @@ -914,7 +914,7 @@ def split_2nd_order(Solids, universe_box, options, tolerances): cutBase = [] for solid in Base: Surfaces = extract_surfaces( - solid, kind, universe_box, tolerances, False + solid, kind, universe_box, options, tolerances, False ) if len(Surfaces[kind]) == 0: kindBase.append(solid) diff --git a/src/geouned/GEOUNED/Utils/BasicFunctions_part2.py b/src/geouned/GEOUNED/Utils/BasicFunctions_part2.py index 7f24d2e5..20e7b9c9 100644 --- a/src/geouned/GEOUNED/Utils/BasicFunctions_part2.py +++ b/src/geouned/GEOUNED/Utils/BasicFunctions_part2.py @@ -18,29 +18,29 @@ same_surf_fic = open("fuzzySurfaces", "w") -def Fuzzy(index, dtype, surf1, surf2, val, tol, tolerances): +def Fuzzy(index, dtype, surf1, surf2, val, tol, options, tolerances): same = val <= tol if dtype == "plane": - p1str = mcnp_surface(index, "Plane", surf1, tolerances) - p2str = mcnp_surface(0, "Plane", surf2, tolerances) + p1str = mcnp_surface(index, "Plane", surf1, options, tolerances) + p2str = mcnp_surface(0, "Plane", surf2, options, tolerances) line = "Same surface : {}\nPlane distance / Tolerance : {} {}\n {}\n {}\n\n".format( same, val, tol, p1str, p2str ) same_surf_fic.write(line) elif dtype == "cylRad": - cyl1str = mcnp_surface(index, "Cylinder", surf1, tolerances) - cyl2str = mcnp_surface(0, "Cylinder", surf2, tolerances) + cyl1str = mcnp_surface(index, "Cylinder", surf1, options, tolerances) + cyl2str = mcnp_surface(0, "Cylinder", surf2, options, tolerances) line = "Same surface : {}\nDiff Radius / Tolerance: {} {}\n {}\n {}\n\n".format( same, val, tol, cyl1str, cyl2str ) same_surf_fic.write(line) elif dtype == "cylAxs": - cyl1str = mcnp_surface(index, "Cylinder", surf1, tolerances) - cyl2str = mcnp_surface(0, "Cylinder", surf2, tolerances) + cyl1str = mcnp_surface(index, "Cylinder", surf1, options, tolerances) + cyl2str = mcnp_surface(0, "Cylinder", surf2, options, tolerances) line = "Same surface : {}\nDist Axis / Tolerance: {} {}\n {}\n {}\n\n".format( same, val, tol, cyl1str, cyl2str ) @@ -48,7 +48,7 @@ def Fuzzy(index, dtype, surf1, surf2, val, tol, tolerances): def is_same_plane( - p1, p2, tolerances, dtol=1e-6, atol=1e-6, rel_tol=True, fuzzy=(False, 0) + p1, p2, options, tolerances, dtol=1e-6, atol=1e-6, rel_tol=True, fuzzy=(False, 0) ): if is_parallel(p1.Axis, p2.Axis, atol): d1 = p1.Axis.dot(p1.Position) @@ -63,13 +63,13 @@ def is_same_plane( isSame, is_fuzzy = is_in_tolerance(d, tol, 0.5 * tol, 2 * tol) if is_fuzzy and fuzzy[0]: - Fuzzy(fuzzy[1], "plane", p2, p1, d, tol, tolerances) + Fuzzy(fuzzy[1], "plane", p2, p1, d, tol, options, tolerances) return isSame return False def is_same_cylinder( - cyl1, cyl2, tolerances, dtol=1e-6, atol=1e-6, rel_tol=True, fuzzy=(False, 0) + cyl1, cyl2, options, tolerances, dtol=1e-6, atol=1e-6, rel_tol=True, fuzzy=(False, 0) ): if rel_tol: rtol = dtol * max(cyl2.Radius, cyl1.Radius) @@ -87,6 +87,7 @@ def is_same_cylinder( cyl1, abs(cyl2.Radius - cyl1.Radius), rtol, + options, tolerances, ) diff --git a/src/geouned/GEOUNED/Utils/Functions.py b/src/geouned/GEOUNED/Utils/Functions.py index 5c0a4e39..d84615ad 100644 --- a/src/geouned/GEOUNED/Utils/Functions.py +++ b/src/geouned/GEOUNED/Utils/Functions.py @@ -428,12 +428,12 @@ def del_surface(self, index): del self[self.__last_obj__[0]][self.__last_obj__[1]] return - def extend(self, surface, tolerances): + def extend(self, surface, options, tolerances): for Pkey in ["PX", "PY", "PZ", "P"]: for s in surface[Pkey]: - self.add_plane(s, tolerances, False) + self.add_plane(s, options, tolerances, False) for s in surface["Cyl"]: - self.add_cylinder(s, tolerances, False) + self.add_cylinder(s, options, tolerances, False) for s in surface["Cone"]: self.add_cone(s, tolerances) for s in surface["Sph"]: @@ -441,7 +441,7 @@ def extend(self, surface, tolerances): for s in surface["Tor"]: self.add_torus(s, tolerances) - def add_plane(self, plane, tolerances, fuzzy): + def add_plane(self, plane, options, tolerances, fuzzy): ex = FreeCAD.Vector(1, 0, 0) ey = FreeCAD.Vector(0, 1, 0) ez = FreeCAD.Vector(0, 0, 1) @@ -452,6 +452,7 @@ def add_plane(self, plane, tolerances, fuzzy): if BF.is_same_plane( plane.Surf, p.Surf, + options=options, tolerances=tolerances, dtol=tolerances.pln_distance, atol=tolerances.pln_angle, @@ -475,6 +476,7 @@ def add_plane(self, plane, tolerances, fuzzy): if BF.is_same_plane( plane.Surf, p.Surf, + options=options, tolerances=tolerances, dtol=tolerances.pln_distance, atol=tolerances.pln_angle, @@ -498,6 +500,7 @@ def add_plane(self, plane, tolerances, fuzzy): if BF.is_same_plane( plane.Surf, p.Surf, + options=options, tolerances=tolerances, dtol=tolerances.pln_distance, atol=tolerances.pln_angle, @@ -521,6 +524,7 @@ def add_plane(self, plane, tolerances, fuzzy): if BF.is_same_plane( plane.Surf, p.Surf, + options=options, tolerances=tolerances, dtol=tolerances.pln_distance, atol=tolerances.pln_angle, @@ -543,12 +547,13 @@ def add_plane(self, plane, tolerances, fuzzy): else: return index, True - def add_cylinder(self, cyl, tolerances, fuzzy=False): + def add_cylinder(self, cyl, options, tolerances, fuzzy=False): addCyl = True for i, c in enumerate(self["Cyl"]): if BF.is_same_cylinder( cyl.Surf, c.Surf, + options=options, tolerances=tolerances, dtol=tolerances.cyl_distance, atol=tolerances.cyl_angle, diff --git a/src/geouned/GEOUNED/Void/Void.py b/src/geouned/GEOUNED/Void/Void.py index b170a681..6bdcb756 100644 --- a/src/geouned/GEOUNED/Void/Void.py +++ b/src/geouned/GEOUNED/Void/Void.py @@ -68,7 +68,7 @@ def void_generation( ) voidList.append(voids) - voidList.append(set_graveyard_cell(Surfaces, UniverseBox, tolerances)) + voidList.append(set_graveyard_cell(Surfaces, UniverseBox, options, tolerances)) return VF.update_void_list( init, voidList, NestedEnclosure, setting["sort_enclosure"] @@ -155,10 +155,10 @@ def get_void_def( return voidList -def set_graveyard_cell(Surfaces, UniverseBox, tolerances): +def set_graveyard_cell(Surfaces, UniverseBox, options, tolerances): Universe = VoidBox([], UniverseBox) - externalBox = get_universe_complementary(Universe, Surfaces, tolerances) + externalBox = get_universe_complementary(Universe, Surfaces, options, tolerances) center = UniverseBox.Center radius = 0.51 * UniverseBox.DiagonalLength sphere = GeounedSurface(("Sphere", (center, radius)), UniverseBox) @@ -188,10 +188,10 @@ def set_graveyard_cell(Surfaces, UniverseBox, tolerances): # TODO check this is being used -def get_universe_complementary(Universe, Surfaces, tolerances): +def get_universe_complementary(Universe, Surfaces, options, tolerances): Def = BoolSequence(operator="OR") for p in Universe.get_bound_planes(): - id, exist = Surfaces.add_plane(p, tolerances, False) + id, exist = Surfaces.add_plane(p, options, tolerances, False) if not exist: Def.elements.append(-id) else: diff --git a/src/geouned/GEOUNED/Void/VoidBoxClass.py b/src/geouned/GEOUNED/Void/VoidBoxClass.py index 3a26b62c..776c4d10 100644 --- a/src/geouned/GEOUNED/Void/VoidBoxClass.py +++ b/src/geouned/GEOUNED/Void/VoidBoxClass.py @@ -170,7 +170,7 @@ def get_void_complementary(self, Surfaces, options, tolerances, simplify="no"): center = self.BoundBox.Center bBox = self.BoundBox for p in self.get_bound_planes(): - id, exist = Surfaces.add_plane(p, tolerances, False) + id, exist = Surfaces.add_plane(p, options, tolerances, False) if exist: s = Surfaces.get_surface(id) if is_opposite(p.Surf.Axis, s.Surf.Axis): @@ -189,7 +189,7 @@ def get_void_complementary(self, Surfaces, options, tolerances, simplify="no"): Part.makeCompound(TempPieceEnclosure.Solids), UniverseBox ) Surfaces.extend( - Decom.extract_surfaces(comsolid, "All", UniverseBox, MakeObj=True) + Decom.extract_surfaces(comsolid, "All", UniverseBox, options, tolerances, MakeObj=True) ) TempPieceEnclosure.update_solids(comsolid.Solids) Conv.cellDef(TempPieceEnclosure, Surfaces, UniverseBox) diff --git a/src/geouned/GEOUNED/Write/Functions.py b/src/geouned/GEOUNED/Write/Functions.py index cdf7219c..152ed353 100644 --- a/src/geouned/GEOUNED/Write/Functions.py +++ b/src/geouned/GEOUNED/Write/Functions.py @@ -244,7 +244,7 @@ def write_sequence_omc_py(seq, options, prefix="S"): return line -def mcnp_surface(id, Type, surf, tolerances): +def mcnp_surface(id, Type, surf, options, tolerances): mcnp_def = "" if Type == "Plane": diff --git a/src/geouned/GEOUNED/Write/MCNPFormat.py b/src/geouned/GEOUNED/Write/MCNPFormat.py index 7d75fe2c..4a547005 100644 --- a/src/geouned/GEOUNED/Write/MCNPFormat.py +++ b/src/geouned/GEOUNED/Write/MCNPFormat.py @@ -167,7 +167,7 @@ def __write_surfaces__(self, surface): """Write the surfaces in MCNP format""" MCNP_def = mcnp_surface( - surface.Index, surface.Type, surface.Surf, self.tolerances + surface.Index, surface.Type, surface.Surf, self.options, self.tolerances ) if MCNP_def: MCNP_def += "\n" diff --git a/src/geouned/GEOUNED/__init__.py b/src/geouned/GEOUNED/__init__.py index 71e2d035..9d893e67 100644 --- a/src/geouned/GEOUNED/__init__.py +++ b/src/geouned/GEOUNED/__init__.py @@ -474,7 +474,7 @@ def start(self): Conv.no_overlapping_cell(MetaList, Surfaces, self.options) else: - translate(MetaList, Surfaces, UniverseBox, code_setting) + translate(MetaList, Surfaces, UniverseBox, code_setting, self.options, self.tolerances) # decompose Enclosure solids if self.voidGen and EnclosureList: warningEnclosureList = decompose_solids( @@ -601,7 +601,7 @@ def start(self): print_warning_solids(warnSolids, warnEnclosures) # add plane definition to cone - process_cones(MetaList, coneInfo, Surfaces, UniverseBox, self.tolerances) + process_cones(MetaList, coneInfo, Surfaces, UniverseBox, self.options, self.tolerances) # write outputformat input write_geometry( @@ -662,9 +662,9 @@ def decompose_solids( comsolid.exportStep(f"debug/compSolid_{i}.stp") Surfaces.extend( Decom.extract_surfaces( - comsolid, "All", UniverseBox, tolerances, MakeObj=True + comsolid, "All", UniverseBox, options, tolerances, MakeObj=True ), - tolerances, + options, tolerances, ) m.set_cad_solid() m.update_solids(comsolid.Solids) @@ -681,7 +681,7 @@ def update_comment(meta, idLabel): meta.set_comments(Void.void_comment_line((meta.__commentInfo__[0], newLabel))) -def process_cones(MetaList, coneInfo, Surfaces, UniverseBox, tolerances): +def process_cones(MetaList, coneInfo, Surfaces, UniverseBox, options, tolerances): cellId = tuple(coneInfo.keys()) for m in MetaList: if m.__id__ not in cellId and not m.Void: @@ -694,10 +694,10 @@ def process_cones(MetaList, coneInfo, Surfaces, UniverseBox, tolerances): for Id in m.__commentInfo__[1]: if Id in cellId: cones.update(-x for x in coneInfo[Id]) - Conv.add_cone_plane(m.Definition, cones, Surfaces, UniverseBox, tolerances) + Conv.add_cone_plane(m.Definition, cones, Surfaces, UniverseBox, options, tolerances) elif not m.Void: Conv.add_cone_plane( - m.Definition, coneInfo[m.__id__], Surfaces, UniverseBox, tolerances + m.Definition, coneInfo[m.__id__], Surfaces, UniverseBox, options, tolerances ) From bda2a4d8ccb30e678ab6a10624f955da4b3c993e Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 9 May 2024 22:45:20 +0100 Subject: [PATCH 07/10] format --- .../GEOUNED/Conversion/CellDefinition.py | 16 ++++++++--- src/geouned/GEOUNED/Cuboid/translate.py | 16 +++++++++-- src/geouned/GEOUNED/Decompose/Decom_one.py | 8 ++++-- .../GEOUNED/Utils/BasicFunctions_part2.py | 9 ++++++- src/geouned/GEOUNED/Void/VoidBoxClass.py | 4 ++- src/geouned/GEOUNED/__init__.py | 27 +++++++++++++++---- 6 files changed, 65 insertions(+), 15 deletions(-) diff --git a/src/geouned/GEOUNED/Conversion/CellDefinition.py b/src/geouned/GEOUNED/Conversion/CellDefinition.py index c4a28cb1..e0270de6 100644 --- a/src/geouned/GEOUNED/Conversion/CellDefinition.py +++ b/src/geouned/GEOUNED/Conversion/CellDefinition.py @@ -853,7 +853,9 @@ def cellDef(meta_obj, surfaces, universe_box, options, tolerances): plane = GeounedSurface( ("Plane", plane1), universe_box, Face="Build" ) - id1, exist = surfaces.add_plane(plane, options, tolerances, False) + id1, exist = surfaces.add_plane( + plane, options, tolerances, False + ) if exist: p = surfaces.get_surface(id1) if is_opposite( @@ -867,7 +869,9 @@ def cellDef(meta_obj, surfaces, universe_box, options, tolerances): plane = GeounedSurface( ("Plane", plane2), universe_box, Face="Build" ) - id2, exist = surfaces.add_plane(plane, options, tolerances, False) + id2, exist = surfaces.add_plane( + plane, options, tolerances, False + ) if exist: p = surfaces.get_surface(id2) if is_opposite( @@ -910,7 +914,9 @@ def cellDef(meta_obj, surfaces, universe_box, options, tolerances): universe_box, Face="Build", ) - id2, exist = surfaces.add_cylinder(cyl, options, tolerances) + id2, exist = surfaces.add_cylinder( + cyl, options, tolerances + ) elif surf_type == "Plane": plane = GeounedSurface( @@ -957,7 +963,9 @@ def cellDef(meta_obj, surfaces, universe_box, options, tolerances): universe_box, Face="Build", ) - id, exist = surfaces.add_plane(plane, options, tolerances, False) + id, exist = surfaces.add_plane( + plane, options, tolerances, False + ) surf = plane.shape elif surface_type == "": dim_l = face.ParameterRange[3] - face.ParameterRange[2] diff --git a/src/geouned/GEOUNED/Cuboid/translate.py b/src/geouned/GEOUNED/Cuboid/translate.py index f9bb687d..99a05ffb 100644 --- a/src/geouned/GEOUNED/Cuboid/translate.py +++ b/src/geouned/GEOUNED/Cuboid/translate.py @@ -88,7 +88,14 @@ def get_id(face_in, Surfaces, options, tolerances): return 0 -def translate(meta_list, surfaces, universe_box, setting, options, tolerances,): +def translate( + meta_list, + surfaces, + universe_box, + setting, + options, + tolerances, +): tot_solid = len(meta_list) for i, m in enumerate(meta_list): if m.IsEnclosure: @@ -103,7 +110,12 @@ def translate(meta_list, surfaces, universe_box, setting, options, tolerances,): surfaces.extend( Decom.extract_surfaces( - Part.makeCompound(m.Solids), "Plane3Pts", universe_box, options, tolerances, MakeObj=False + Part.makeCompound(m.Solids), + "Plane3Pts", + universe_box, + options, + tolerances, + MakeObj=False, ) ) set_definition(m, surfaces) diff --git a/src/geouned/GEOUNED/Decompose/Decom_one.py b/src/geouned/GEOUNED/Decompose/Decom_one.py index b65b247a..e0bffb93 100644 --- a/src/geouned/GEOUNED/Decompose/Decom_one.py +++ b/src/geouned/GEOUNED/Decompose/Decom_one.py @@ -865,7 +865,9 @@ def sort_planes(PlaneList, sortElements=False): def split_p_planes_new(solid, universe_box, options, tolerances): - SPlanes = extract_surfaces(solid, "Planes", universe_box, options, tolerances, False) + SPlanes = extract_surfaces( + solid, "Planes", universe_box, options, tolerances, False + ) Planes = [] for P in ("PX", "PY", "PZ", "P"): @@ -891,7 +893,9 @@ def split_p_planes_new(solid, universe_box, options, tolerances): def split_p_planes_org(solid, universe_box, options, tolerances): - SPlanes = extract_surfaces(solid, "Planes", universe_box, options, tolerances, False) + SPlanes = extract_surfaces( + solid, "Planes", universe_box, options, tolerances, False + ) if len(SPlanes["P"]) == 0: return [solid] diff --git a/src/geouned/GEOUNED/Utils/BasicFunctions_part2.py b/src/geouned/GEOUNED/Utils/BasicFunctions_part2.py index 20e7b9c9..9ead0f7a 100644 --- a/src/geouned/GEOUNED/Utils/BasicFunctions_part2.py +++ b/src/geouned/GEOUNED/Utils/BasicFunctions_part2.py @@ -69,7 +69,14 @@ def is_same_plane( def is_same_cylinder( - cyl1, cyl2, options, tolerances, dtol=1e-6, atol=1e-6, rel_tol=True, fuzzy=(False, 0) + cyl1, + cyl2, + options, + tolerances, + dtol=1e-6, + atol=1e-6, + rel_tol=True, + fuzzy=(False, 0), ): if rel_tol: rtol = dtol * max(cyl2.Radius, cyl1.Radius) diff --git a/src/geouned/GEOUNED/Void/VoidBoxClass.py b/src/geouned/GEOUNED/Void/VoidBoxClass.py index 776c4d10..789a2e72 100644 --- a/src/geouned/GEOUNED/Void/VoidBoxClass.py +++ b/src/geouned/GEOUNED/Void/VoidBoxClass.py @@ -189,7 +189,9 @@ def get_void_complementary(self, Surfaces, options, tolerances, simplify="no"): Part.makeCompound(TempPieceEnclosure.Solids), UniverseBox ) Surfaces.extend( - Decom.extract_surfaces(comsolid, "All", UniverseBox, options, tolerances, MakeObj=True) + Decom.extract_surfaces( + comsolid, "All", UniverseBox, options, tolerances, MakeObj=True + ) ) TempPieceEnclosure.update_solids(comsolid.Solids) Conv.cellDef(TempPieceEnclosure, Surfaces, UniverseBox) diff --git a/src/geouned/GEOUNED/__init__.py b/src/geouned/GEOUNED/__init__.py index 9d893e67..1698c494 100644 --- a/src/geouned/GEOUNED/__init__.py +++ b/src/geouned/GEOUNED/__init__.py @@ -474,7 +474,14 @@ def start(self): Conv.no_overlapping_cell(MetaList, Surfaces, self.options) else: - translate(MetaList, Surfaces, UniverseBox, code_setting, self.options, self.tolerances) + translate( + MetaList, + Surfaces, + UniverseBox, + code_setting, + self.options, + self.tolerances, + ) # decompose Enclosure solids if self.voidGen and EnclosureList: warningEnclosureList = decompose_solids( @@ -601,7 +608,9 @@ def start(self): print_warning_solids(warnSolids, warnEnclosures) # add plane definition to cone - process_cones(MetaList, coneInfo, Surfaces, UniverseBox, self.options, self.tolerances) + process_cones( + MetaList, coneInfo, Surfaces, UniverseBox, self.options, self.tolerances + ) # write outputformat input write_geometry( @@ -664,7 +673,8 @@ def decompose_solids( Decom.extract_surfaces( comsolid, "All", UniverseBox, options, tolerances, MakeObj=True ), - options, tolerances, + options, + tolerances, ) m.set_cad_solid() m.update_solids(comsolid.Solids) @@ -694,10 +704,17 @@ def process_cones(MetaList, coneInfo, Surfaces, UniverseBox, options, tolerances for Id in m.__commentInfo__[1]: if Id in cellId: cones.update(-x for x in coneInfo[Id]) - Conv.add_cone_plane(m.Definition, cones, Surfaces, UniverseBox, options, tolerances) + Conv.add_cone_plane( + m.Definition, cones, Surfaces, UniverseBox, options, tolerances + ) elif not m.Void: Conv.add_cone_plane( - m.Definition, coneInfo[m.__id__], Surfaces, UniverseBox, options, tolerances + m.Definition, + coneInfo[m.__id__], + Surfaces, + UniverseBox, + options, + tolerances, ) From fd3bcaaff1ce6d6734dfcc741234edb243e1bcce Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Thu, 9 May 2024 23:08:05 +0100 Subject: [PATCH 08/10] found bug hidden in try: except statement --- src/geouned/GEOUNED/Conversion/CellDefinition.py | 8 ++++---- src/geouned/GEOUNED/Utils/BooleanSolids.py | 2 +- src/geouned/GEOUNED/Void/VoidBoxClass.py | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/geouned/GEOUNED/Conversion/CellDefinition.py b/src/geouned/GEOUNED/Conversion/CellDefinition.py index e0270de6..357bc6c3 100644 --- a/src/geouned/GEOUNED/Conversion/CellDefinition.py +++ b/src/geouned/GEOUNED/Conversion/CellDefinition.py @@ -154,14 +154,14 @@ def is_inverted(solid): return False -def gen_plane(face, solid): +def gen_plane(face, solid, tolerances): """Generate an additional plane when convex surfaces of second order are presented as a face of the solid""" surf = face.Surface if str(surf) == "": - return gen_plane_cylinder(face, solid) + return gen_plane_cylinder(face, solid, tolerances) if str(surf) == "": - return gen_plane_cone(face, solid) + return gen_plane_cone(face, solid, tolerances) if str(surf) == "Sphere": return gen_plane_sphere(face, solid) @@ -791,7 +791,7 @@ def cellDef(meta_obj, surfaces, universe_box, options, tolerances): surf_obj.append(face) try: - plane = gen_plane(face, solid_gu) + plane = gen_plane(face, solid_gu, tolerances) if plane is not None: plane = GU.PlaneGu(plane) except: diff --git a/src/geouned/GEOUNED/Utils/BooleanSolids.py b/src/geouned/GEOUNED/Utils/BooleanSolids.py index f0cf093a..4c36a14d 100644 --- a/src/geouned/GEOUNED/Utils/BooleanSolids.py +++ b/src/geouned/GEOUNED/Utils/BooleanSolids.py @@ -349,7 +349,7 @@ def remove_extra_surfaces(CellSeq, CTable): # if subcell has finite volume check it intersection with the box if not nullcell: res = CTable.solid_in_box(subCell) - if res == None: + if res is None: # subcell intersect the box # get the surfaces of the solids out of the box # get reduced definition diff --git a/src/geouned/GEOUNED/Void/VoidBoxClass.py b/src/geouned/GEOUNED/Void/VoidBoxClass.py index 789a2e72..9e85c1b4 100644 --- a/src/geouned/GEOUNED/Void/VoidBoxClass.py +++ b/src/geouned/GEOUNED/Void/VoidBoxClass.py @@ -102,7 +102,7 @@ def split(self, minSize=200): box1 = FreeCAD.BoundBox(VMin1, VMax1) box2 = FreeCAD.BoundBox(VMin2, VMax2) - if self.PieceEnclosure == None: + if self.PieceEnclosure is None: Space1 = VoidBox(self.Objects, box1) Space2 = VoidBox(self.Objects, box2) VoidBoxTuple = (Space1, Space2) @@ -110,11 +110,11 @@ def split(self, minSize=200): Space1 = self.piece_enclosure_split(box1) Space2 = self.piece_enclosure_split(box2) VoidBoxTuple = (Space1, Space2) - if Space1 == None: + if Space1 is None: VoidBoxTuple = (Space2,) - if Space2 == None: + if Space2 is None: VoidBoxTuple = (Space1,) - if Space1 == None and Space2 == None: + if Space1 is None and Space2 is None: VoidBoxTuple = () return VoidBoxTuple From 9c5345249a9d4c7e0f686fef6f38c4e7a39905c4 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 10 May 2024 10:30:13 +0100 Subject: [PATCH 09/10] using tolerance for more local varibles --- .../GEOUNED/Conversion/CellDefinition.py | 6 ---- src/geouned/GEOUNED/Cuboid/translate.py | 3 -- .../GEOUNED/Utils/BasicFunctions_part2.py | 29 +++++++++---------- src/geouned/GEOUNED/Utils/Functions.py | 15 ---------- 4 files changed, 13 insertions(+), 40 deletions(-) diff --git a/src/geouned/GEOUNED/Conversion/CellDefinition.py b/src/geouned/GEOUNED/Conversion/CellDefinition.py index 357bc6c3..c0702653 100644 --- a/src/geouned/GEOUNED/Conversion/CellDefinition.py +++ b/src/geouned/GEOUNED/Conversion/CellDefinition.py @@ -43,9 +43,6 @@ def get_id(facein, surfaces, options, tolerances): s.Surf, options=options, tolerances=tolerances, - dtol=tolerances.pln_distance, - atol=tolerances.pln_angle, - rel_tol=tolerances.relativeTol, ): return s.Index @@ -56,9 +53,6 @@ def get_id(facein, surfaces, options, tolerances): s.Surf, options=options, tolerances=tolerances, - dtol=tolerances.cyl_distance, - atol=tolerances.cyl_angle, - rel_tol=tolerances.relativeTol, ): return s.Index diff --git a/src/geouned/GEOUNED/Cuboid/translate.py b/src/geouned/GEOUNED/Cuboid/translate.py index 99a05ffb..e17a2909 100644 --- a/src/geouned/GEOUNED/Cuboid/translate.py +++ b/src/geouned/GEOUNED/Cuboid/translate.py @@ -79,9 +79,6 @@ def get_id(face_in, Surfaces, options, tolerances): s.Surf, options=options, tolerances=tolerances, - dtol=tolerances.pln_distance, - atol=tolerances.pln_angle, - rel_tol=tolerances.relativeTol, ): return s.Index diff --git a/src/geouned/GEOUNED/Utils/BasicFunctions_part2.py b/src/geouned/GEOUNED/Utils/BasicFunctions_part2.py index 9ead0f7a..3e5940f3 100644 --- a/src/geouned/GEOUNED/Utils/BasicFunctions_part2.py +++ b/src/geouned/GEOUNED/Utils/BasicFunctions_part2.py @@ -48,18 +48,18 @@ def Fuzzy(index, dtype, surf1, surf2, val, tol, options, tolerances): def is_same_plane( - p1, p2, options, tolerances, dtol=1e-6, atol=1e-6, rel_tol=True, fuzzy=(False, 0) + p1, p2, options, tolerances, fuzzy=(False, 0) ): - if is_parallel(p1.Axis, p2.Axis, atol): + if is_parallel(p1.Axis, p2.Axis, tolerances.pln_angle): d1 = p1.Axis.dot(p1.Position) d2 = p2.Axis.dot(p2.Position) - if is_opposite(p1.Axis, p2.Axis, atol): + if is_opposite(p1.Axis, p2.Axis, tolerances.pln_angle): d2 = -d2 d = abs(d1 - d2) - if rel_tol: - tol = dtol * max(p2.dim1, p2.dim2) + if tolerances.relativeTol: + tol = tolerances.pln_distance * max(p2.dim1, p2.dim2) else: - tol = dtol + tol = tolerances.pln_distance isSame, is_fuzzy = is_in_tolerance(d, tol, 0.5 * tol, 2 * tol) if is_fuzzy and fuzzy[0]: @@ -73,15 +73,12 @@ def is_same_cylinder( cyl2, options, tolerances, - dtol=1e-6, - atol=1e-6, - rel_tol=True, fuzzy=(False, 0), ): - if rel_tol: - rtol = dtol * max(cyl2.Radius, cyl1.Radius) + if tolerances.relativeTol: + rtol = tolerances.cyl_distance * max(cyl2.Radius, cyl1.Radius) else: - rtol = dtol + rtol = tolerances.cyl_distance is_same_rad, is_fuzzy = is_in_tolerance( cyl2.Radius - cyl1.Radius, rtol, 0.5 * rtol, 2 * rtol @@ -99,14 +96,14 @@ def is_same_cylinder( ) if is_same_rad: - if is_parallel(cyl1.Axis, cyl2.Axis, atol): + if is_parallel(cyl1.Axis, cyl2.Axis, tolerances.cyl_angle): c12 = cyl1.Center - cyl2.Center d = cyl1.Axis.cross(c12).Length - if rel_tol: - tol = dtol * max(cyl1.Center.Length, cyl2.Center.Length) + if tolerances.relativeTol: + tol = tolerances.cyl_distance * max(cyl1.Center.Length, cyl2.Center.Length) else: - tol = dtol + tol = tolerances.cyl_distance is_same_center, is_fuzzy = is_in_tolerance(d, tol, 0.5 * tol, 2 * tol) if is_fuzzy and fuzzy[0]: diff --git a/src/geouned/GEOUNED/Utils/Functions.py b/src/geouned/GEOUNED/Utils/Functions.py index d84615ad..41cb6a3e 100644 --- a/src/geouned/GEOUNED/Utils/Functions.py +++ b/src/geouned/GEOUNED/Utils/Functions.py @@ -454,9 +454,6 @@ def add_plane(self, plane, options, tolerances, fuzzy): p.Surf, options=options, tolerances=tolerances, - dtol=tolerances.pln_distance, - atol=tolerances.pln_angle, - rel_tol=tolerances.relativeTol, fuzzy=(fuzzy, p.Index), ): add_plane = False @@ -478,9 +475,6 @@ def add_plane(self, plane, options, tolerances, fuzzy): p.Surf, options=options, tolerances=tolerances, - dtol=tolerances.pln_distance, - atol=tolerances.pln_angle, - rel_tol=tolerances.relativeTol, fuzzy=(fuzzy, p.Index), ): add_plane = False @@ -502,9 +496,6 @@ def add_plane(self, plane, options, tolerances, fuzzy): p.Surf, options=options, tolerances=tolerances, - dtol=tolerances.pln_distance, - atol=tolerances.pln_angle, - rel_tol=tolerances.relativeTol, fuzzy=(fuzzy, p.Index), ): add_plane = False @@ -526,9 +517,6 @@ def add_plane(self, plane, options, tolerances, fuzzy): p.Surf, options=options, tolerances=tolerances, - dtol=tolerances.pln_distance, - atol=tolerances.pln_angle, - rel_tol=tolerances.relativeTol, fuzzy=(fuzzy, p.Index), ): add_plane = False @@ -555,9 +543,6 @@ def add_cylinder(self, cyl, options, tolerances, fuzzy=False): c.Surf, options=options, tolerances=tolerances, - dtol=tolerances.cyl_distance, - atol=tolerances.cyl_angle, - rel_tol=tolerances.relativeTol, fuzzy=(fuzzy, c.Index), ): addCyl = False From e9dde1ace98cffa656318f868139e362c89f7888 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 10 May 2024 10:31:17 +0100 Subject: [PATCH 10/10] formatting --- src/geouned/GEOUNED/Utils/BasicFunctions_part2.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/geouned/GEOUNED/Utils/BasicFunctions_part2.py b/src/geouned/GEOUNED/Utils/BasicFunctions_part2.py index 3e5940f3..cd536c2f 100644 --- a/src/geouned/GEOUNED/Utils/BasicFunctions_part2.py +++ b/src/geouned/GEOUNED/Utils/BasicFunctions_part2.py @@ -47,9 +47,7 @@ def Fuzzy(index, dtype, surf1, surf2, val, tol, options, tolerances): same_surf_fic.write(line) -def is_same_plane( - p1, p2, options, tolerances, fuzzy=(False, 0) -): +def is_same_plane(p1, p2, options, tolerances, fuzzy=(False, 0)): if is_parallel(p1.Axis, p2.Axis, tolerances.pln_angle): d1 = p1.Axis.dot(p1.Position) d2 = p2.Axis.dot(p2.Position) @@ -101,7 +99,9 @@ def is_same_cylinder( d = cyl1.Axis.cross(c12).Length if tolerances.relativeTol: - tol = tolerances.cyl_distance * max(cyl1.Center.Length, cyl2.Center.Length) + tol = tolerances.cyl_distance * max( + cyl1.Center.Length, cyl2.Center.Length + ) else: tol = tolerances.cyl_distance