diff --git a/.gitignore b/.gitignore index c5cb4161..103a2684 100644 --- a/.gitignore +++ b/.gitignore @@ -166,6 +166,9 @@ cython_debug/ # testing folder tests_outputs/ +# work folder +work/ + # debug output folders fuzzySurfaces Suspicious_solids/ diff --git a/docs/Training_on_GEOUNED_tool.pdf b/docs/Training_on_GEOUNED_tool.pdf deleted file mode 100644 index 6e80849f..00000000 Binary files a/docs/Training_on_GEOUNED_tool.pdf and /dev/null differ diff --git a/docs/User_Guide_GEOUNED_v2.0.pdf b/docs/User_Guide_GEOUNED_v2.0.pdf deleted file mode 100644 index 23a3c843..00000000 Binary files a/docs/User_Guide_GEOUNED_v2.0.pdf and /dev/null differ diff --git a/docs/conf.py b/docs/conf.py index 8ab45740..e92c7e13 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -20,7 +20,6 @@ project = "GEOUNED" copyright = "2024, UNED" -author = "Juan-Pablo Catalan and Patrick Sauvan" # The full version, including alpha/beta/rc tags import geouned @@ -83,6 +82,6 @@ "json_url": "https://raw.githubusercontent.com/GEOUNED-org/GEOUNED/dev/docs/version_switcher.json", "version_match": version_match, }, - "nav_title": "Geouned", + "nav_title": "GEOUNED", "navbar_start": ["version-switcher", "navbar-icon-links"], } diff --git a/docs/developer_guide.rst b/docs/developers_guide.rst similarity index 99% rename from docs/developer_guide.rst rename to docs/developers_guide.rst index 56bc9d22..0e801357 100644 --- a/docs/developer_guide.rst +++ b/docs/developers_guide.rst @@ -1,4 +1,4 @@ -Developer guide +Developers guide =============== Developer install with Mamba diff --git a/docs/images/mat_list.png b/docs/images/mat_list.png new file mode 100644 index 00000000..4a5e0b4a Binary files /dev/null and b/docs/images/mat_list.png differ diff --git a/docs/images/mat_tag.png b/docs/images/mat_tag.png new file mode 100644 index 00000000..08e71efa Binary files /dev/null and b/docs/images/mat_tag.png differ diff --git a/docs/index.rst b/docs/index.rst index b63c7c50..56f281ec 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,9 +1,4 @@ -.. GEOUNED documentation master file, created by - sphinx-quickstart on Tue Apr 30 09:47:11 2024. - You can adapt this file completely to your liking, but it should at least - contain the root `toctree` directive. - -Geouned Documentation +GEOUNED Documentation ===================== **Version**: |version| @@ -13,10 +8,9 @@ Monte Carlo transport codes. Supported codes include OpenMC, PHITS, Serpent and MCNP. .. toctree:: - :maxdepth: 3 + :maxdepth: 2 - install/index - usage/index + quick_install_guide + users_guide/index python_api - methodology - developer_guide + developers_guide diff --git a/docs/methodology.rst b/docs/methodology.rst deleted file mode 100644 index 78fc03f8..00000000 --- a/docs/methodology.rst +++ /dev/null @@ -1,13 +0,0 @@ -Methodology -=========== - - -There are several documents on the methodology of GEOUNED - -`Publication `_ - -`User_Guide_GEOUNED_v2.0.pdf `_ - -`Training_on_GEOUNED_tool `_ - -TODO convert various data sources to rst format for these docs diff --git a/docs/quick_install_guide.rst b/docs/quick_install_guide.rst new file mode 100644 index 00000000..fcb3046b --- /dev/null +++ b/docs/quick_install_guide.rst @@ -0,0 +1,112 @@ +Quick Install Guide +=================== + +Linux +~~~~~ + +First we need to install a Conda distribution. There are a few options but we here we opt for `MiniConda3 `_ as it downloads quicker than the fuller `Anaconda `_. + +You can follow the install instructions for `MiniConda3 `_ or follow the commands below. +Download. + +.. code-block:: sh + + mkdir -p ~/miniconda3 + wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh + +Install MiniConda3 + +.. code-block:: sh + + bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3 + + +Activate the base environment in your current terminal + +.. code-block:: sh + + ~/miniconda3/bin/conda init bash + + +It is recommended to create a new environment + +.. code-block:: sh + + conda create --name new_env python=3.11 + + +Activate the new environment + +.. code-block:: sh + + conda activate new_env + +Install GEOUNED from conda-forge + +.. code-block:: sh + + conda install -c conda-forge geouned -y + +Then you will be able to run import GEOUNED from within Python + +.. code-block:: python + + import geouned + +You will also be able to use the GEOUNED command line tool + +.. code-block:: bash + + geouned_cadtocsg --help + + +Windows +~~~~~~~ + +First we need to install a Conda distribution. There are a few options but we here we opt for `MiniConda3 `_ as it downloads quicker than the fuller `Anaconda `_. + +You can follow the install instructions for `MiniConda3 `_ + +Download and execute the Miniforge3 Windows installer + +You can get it from the `Miniforge3 GitHub repository here `_ or from the link below + +`https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe `_ + +Open "Anaconda Prompt (miniconda3)" which will now be available on your start menu. + +It is recommended to create a new environment + +.. code-block:: sh + + conda create --name new_env python=3.11 + +Activate the new environment + +.. code-block:: sh + + conda activate new_env + +Since one of the GEOUNED dependencies is FreeCAD, classic conda solver of dependencies may significantly slow down the installation. For this reason, it is recommended to install and use conda-libmamba-solver + +.. code-block:: sh + + conda install conda-libmamba-solver + +Install GEOUNED from conda-forge, forcing the use of libmamba solver + +.. code-block:: sh + + conda install -c conda-forge geouned -y --solver=libmamba + +Then you will be able to run import GEOUNED from within Python + +.. code-block:: python + + import geouned + +You will also be able to use the GEOUNED command line tool + +.. code-block:: bash + + geouned_cadtocsg --help diff --git a/docs/usage/index.rst b/docs/users_guide/execution_settings/cad2csg/index.rst similarity index 66% rename from docs/usage/index.rst rename to docs/users_guide/execution_settings/cad2csg/index.rst index 157a09ab..49592413 100644 --- a/docs/usage/index.rst +++ b/docs/users_guide/execution_settings/cad2csg/index.rst @@ -1,16 +1,11 @@ -.. usage - -Usage -===== +CAD to CSG Translation +====================== GEOUNED can be used as a Python package with the API or as a command line tool with the CLI. .. toctree:: - :numbered: :maxdepth: 1 python_cadtocsg_api_usage python_cadtocsg_cli_usage - python_csgtocad_api_usage - python_csgtocad_cli_usage diff --git a/docs/usage/python_cadtocsg_api_usage.rst b/docs/users_guide/execution_settings/cad2csg/python_cadtocsg_api_usage.rst similarity index 97% rename from docs/usage/python_cadtocsg_api_usage.rst rename to docs/users_guide/execution_settings/cad2csg/python_cadtocsg_api_usage.rst index 7d3942f2..cabdc7e7 100644 --- a/docs/usage/python_cadtocsg_api_usage.rst +++ b/docs/users_guide/execution_settings/cad2csg/python_cadtocsg_api_usage.rst @@ -1,5 +1,5 @@ -Python Package Usage, CAD to CSG conversion -=========================================== +Python Package Usage +==================== The 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 reference section <../python_api.html>`_ of the documentation. diff --git a/docs/usage/python_cadtocsg_cli_usage.rst b/docs/users_guide/execution_settings/cad2csg/python_cadtocsg_cli_usage.rst similarity index 97% rename from docs/usage/python_cadtocsg_cli_usage.rst rename to docs/users_guide/execution_settings/cad2csg/python_cadtocsg_cli_usage.rst index ec00218d..ddcceeca 100644 --- a/docs/usage/python_cadtocsg_cli_usage.rst +++ b/docs/users_guide/execution_settings/cad2csg/python_cadtocsg_cli_usage.rst @@ -1,5 +1,5 @@ -Command Line Tool Usage, CAD to CSG conversion -============================================== +Command Line Tool Usage +======================= GEOUNED CAD to CSG conversion can be performed in the command line. diff --git a/docs/users_guide/execution_settings/csg2cad/index.rst b/docs/users_guide/execution_settings/csg2cad/index.rst new file mode 100644 index 00000000..78ebd892 --- /dev/null +++ b/docs/users_guide/execution_settings/csg2cad/index.rst @@ -0,0 +1,11 @@ +CSG to CAD Translation +====================== + +GEOUNED can be used as a Python package with the API or as a command line tool with the CLI. + + +.. toctree:: + :maxdepth: 1 + + python_csgtocad_api_usage + python_csgtocad_cli_usage diff --git a/docs/usage/python_csgtocad_api_usage.rst b/docs/users_guide/execution_settings/csg2cad/python_csgtocad_api_usage.rst similarity index 93% rename from docs/usage/python_csgtocad_api_usage.rst rename to docs/users_guide/execution_settings/csg2cad/python_csgtocad_api_usage.rst index 1c9b2987..1ce5984c 100644 --- a/docs/usage/python_csgtocad_api_usage.rst +++ b/docs/users_guide/execution_settings/csg2cad/python_csgtocad_api_usage.rst @@ -1,5 +1,5 @@ -Python Package Usage, CSG to CAD conversion -=========================================== +Python Package Usage +==================== The main class is ``CsgToCad()`` which converts Constructive Solid Geometry (CSG) to CAD. There are a few arguments that can be passed into the ``CsgToCad().export_cad()`` method which are documented in the `Python API reference section <../python_api.html>`_ of the documentation. diff --git a/docs/usage/python_csgtocad_cli_usage.rst b/docs/users_guide/execution_settings/csg2cad/python_csgtocad_cli_usage.rst similarity index 96% rename from docs/usage/python_csgtocad_cli_usage.rst rename to docs/users_guide/execution_settings/csg2cad/python_csgtocad_cli_usage.rst index 83d955e7..0792ac3e 100644 --- a/docs/usage/python_csgtocad_cli_usage.rst +++ b/docs/users_guide/execution_settings/csg2cad/python_csgtocad_cli_usage.rst @@ -1,5 +1,5 @@ -Command Line Tool Usage, CSG to CAD conversion -============================================== +Command Line Tool Usage +======================= GEOUNED CSG to CAD conversion can be performed in the command line. diff --git a/docs/users_guide/execution_settings/index.rst b/docs/users_guide/execution_settings/index.rst new file mode 100644 index 00000000..1952dde3 --- /dev/null +++ b/docs/users_guide/execution_settings/index.rst @@ -0,0 +1,11 @@ +Execution Settings +================== + +GEOUNED can be used as a Python package with the API or as a command line tool with the CLI. + + +.. toctree:: + :maxdepth: 2 + + cad2csg/index + csg2cad/index diff --git a/docs/users_guide/index.rst b/docs/users_guide/index.rst new file mode 100644 index 00000000..c57144da --- /dev/null +++ b/docs/users_guide/index.rst @@ -0,0 +1,14 @@ +Users Guide +=========== + +GEOUNED can be used as a Python package with the API or as a command line tool with the CLI. + + +.. toctree:: + :maxdepth: 2 + + installation/index + execution_settings/index + simplification + material_allocation + void_generation diff --git a/docs/install/index.rst b/docs/users_guide/installation/index.rst similarity index 94% rename from docs/install/index.rst rename to docs/users_guide/installation/index.rst index be94dbe8..56cfa8cd 100644 --- a/docs/install/index.rst +++ b/docs/users_guide/installation/index.rst @@ -1,7 +1,5 @@ -.. usage - -Install -======= +Installation +============ There are several options for installing GEOUNED package. The installation selected has implications for how you run GEOUNED Python scripts. @@ -12,7 +10,6 @@ Users have also had success installing FreeCAD and making use of the Python vers .. toctree:: - :numbered: :maxdepth: 1 install_linux diff --git a/docs/install/install_linux.rst b/docs/users_guide/installation/install_linux.rst similarity index 98% rename from docs/install/install_linux.rst rename to docs/users_guide/installation/install_linux.rst index c7b6f62b..09d94005 100644 --- a/docs/install/install_linux.rst +++ b/docs/users_guide/installation/install_linux.rst @@ -62,7 +62,7 @@ You will also be able to use the GEOUNED command line tool User install with Conda ~~~~~~~~~~~~~~~~~~~~~~~ -First we need to install a Conda distribution. There are a few options but we here we opt for `MiniConda3 `_ as it downloads quicker than the fuller `AnaConda `_. +First we need to install a Conda distribution. There are a few options but we here we opt for `MiniConda3 `_ as it downloads quicker than the fuller `Anaconda `_. You can follow the install instructions for `MiniConda3 `_ or follow the commands below. Download. diff --git a/docs/install/install_windows.rst b/docs/users_guide/installation/install_windows.rst similarity index 85% rename from docs/install/install_windows.rst rename to docs/users_guide/installation/install_windows.rst index fae852d7..41c663e1 100644 --- a/docs/install/install_windows.rst +++ b/docs/users_guide/installation/install_windows.rst @@ -52,7 +52,7 @@ You will also be able to use the GEOUNED command line tool User install with Conda ~~~~~~~~~~~~~~~~~~~~~~~ -First we need to install a Conda distribution. There are a few options but we here we opt for `MiniConda3 `_ as it downloads quicker than the fuller `AnaConda `_. +First we need to install a Conda distribution. There are a few options but we here we opt for `MiniConda3 `_ as it downloads quicker than the fuller `Anaconda `_. You can follow the install instructions for `MiniConda3 `_ @@ -76,11 +76,17 @@ Activate the new environment conda activate new_env -Install GEOUNED from conda-forge +Since one of the GEOUNED dependencies is FreeCAD, classic conda solver of dependencies may significantly slow down the installation. For this reason, it is recommended to install and use conda-libmamba-solver + +.. code-block:: sh + + conda install conda-libmamba-solver + +Install GEOUNED from conda-forge, forcing the use of libmamba solver .. code-block:: sh - conda install -c conda-forge geouned -y + conda install -c conda-forge geouned -y --solver=libmamba Then you will be able to run import GEOUNED from within Python diff --git a/docs/users_guide/material_allocation.rst b/docs/users_guide/material_allocation.rst new file mode 100644 index 00000000..25538799 --- /dev/null +++ b/docs/users_guide/material_allocation.rst @@ -0,0 +1,22 @@ +Material Allocation +=================== + +The material of the components can be assigned directly in the tree CAD by including a text with _mXX_ within the component name. + +.. image:: /images/mat_tag.png + :alt: Example of a CAD tree with a _mXX_ tag. + :align: center + :width: 50% + +The material assigned to the corresponding cell should be defined in the material definition file whose name is provided by the matFile keyword. +This file has the following format: + +.. image:: /images/mat_list.png + :alt: Example of a material list. + :align: center + :width: 50% + +Where # is used for comments and the rest of the lines specifies the id of the material, the nominal density and the text to be included as a comment. +The nominal density value is multiplied by -1 so the criterium is inverted with respect to MCNP one (i.e. g/cm3 positive and atm/b/cm negative). +The nominal density can be changed by the inclusion of a multiplication factor using the following text in the CAD tree _mXX_dXX.XX_. +For example, in our case _m01_d2.0_ will produce a cell with material 1 and density 2.0. diff --git a/docs/users_guide/simplification.rst b/docs/users_guide/simplification.rst new file mode 100644 index 00000000..245a406f --- /dev/null +++ b/docs/users_guide/simplification.rst @@ -0,0 +1,4 @@ +Simplification of Geometry +=========================== + +To be added. \ No newline at end of file diff --git a/docs/users_guide/void_generation.rst b/docs/users_guide/void_generation.rst new file mode 100644 index 00000000..d4f62c43 --- /dev/null +++ b/docs/users_guide/void_generation.rst @@ -0,0 +1,4 @@ +Void Generation +=============== + +To be added. \ No newline at end of file diff --git a/docs/version_switcher.json b/docs/version_switcher.json index 67e78c7c..62ec9d99 100644 --- a/docs/version_switcher.json +++ b/docs/version_switcher.json @@ -13,5 +13,15 @@ "name": "1.2.0", "version": "1.2.0", "url": "https://geouned-org.github.io/GEOUNED/1.2.0" + }, + { + "name": "1.3.0", + "version": "1.3.0", + "url": "https://geouned-org.github.io/GEOUNED/1.3.0" + }, + { + "name": "1.4.0", + "version": "1.4.0", + "url": "https://geouned-org.github.io/GEOUNED/1.4.0" } -] \ No newline at end of file +] diff --git a/src/geouned/GEOUNED/conversion/cell_definition.py b/src/geouned/GEOUNED/conversion/cell_definition.py index 91ed386e..10b07d20 100644 --- a/src/geouned/GEOUNED/conversion/cell_definition.py +++ b/src/geouned/GEOUNED/conversion/cell_definition.py @@ -256,7 +256,7 @@ def gen_plane_sphere(face, solid): if f.Surface.Center == face.Surface.Center and f.Surface.Radius == face.Surface.Radius: # print 'Warning: coincident sphere faces are the same' for f2 in same_faces: - if f.distToShape(f2)[0] < 1e-6: + if f.__face__.distToShape(f2.__face__)[0] < 1e-6: same_faces.append(f) break @@ -264,8 +264,20 @@ def gen_plane_sphere(face, solid): normal = FreeCAD.Vector(0, 0, 0) for f in same_faces: normal += f.Area * (f.CenterOfMass - face.Surface.Center) + normal.normalize() + tmp_plane = Part.Plane(face.Surface.Center, normal).toShape() - return Part.Plane(face.Surface.Center, normal).toShape() + dmin = 2 * face.Surface.Radius + for f in same_faces: + dist = tmp_plane.distToShape(f.__face__)[0] + dmin = min(dmin, dist) + + if dmin > 1e-6: + center = face.Surface.Center + 0.95 * dmin * normal + plane = Part.Plane(center, normal).toShape() + else: + plane = None + return plane def gen_plane_cylinder(face, solid, tolerances): diff --git a/src/geouned/GEOUNED/core.py b/src/geouned/GEOUNED/core.py index 94987fc5..f7b84034 100644 --- a/src/geouned/GEOUNED/core.py +++ b/src/geouned/GEOUNED/core.py @@ -352,7 +352,7 @@ def _get_geometry_bounding_box(self, padding: float = 10.0): # set up Universe meta_list = self.meta_list - Box = meta_list[0].BoundBox + Box = meta_list[0].optimalBoundingBox() xmin = Box.XMin xmax = Box.XMax ymin = Box.YMin @@ -362,12 +362,13 @@ def _get_geometry_bounding_box(self, padding: float = 10.0): for m in meta_list[1:]: # MIO. This was removed since in HELIAS the enclosure cell is the biggest one # if m.IsEnclosure: continue - xmin = min(m.BoundBox.XMin, xmin) - xmax = max(m.BoundBox.XMax, xmax) - ymin = min(m.BoundBox.YMin, ymin) - ymax = max(m.BoundBox.YMax, ymax) - zmin = min(m.BoundBox.ZMin, zmin) - zmax = max(m.BoundBox.ZMax, zmax) + optBox = m.optimalBoundingBox() + xmin = min(optBox.XMin, xmin) + xmax = max(optBox.XMax, xmax) + ymin = min(optBox.YMin, ymin) + ymax = max(optBox.YMax, ymax) + zmin = min(optBox.ZMin, zmin) + zmax = max(optBox.ZMax, zmax) self.geometry_bounding_box = FreeCAD.BoundBox( FreeCAD.Vector(xmin - padding, ymin - padding, zmin - padding), diff --git a/src/geouned/GEOUNED/decompose/decom_one.py b/src/geouned/GEOUNED/decompose/decom_one.py index 6853b5d5..e8351c22 100644 --- a/src/geouned/GEOUNED/decompose/decom_one.py +++ b/src/geouned/GEOUNED/decompose/decom_one.py @@ -72,7 +72,7 @@ def cut_full_cylinder(solid, options, tolerances, numeric_format): surfaces.add_cylinder(cylinder, options, tolerances, numeric_format, 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): + for p in cyl_bound_planes(solid_gu, face, universe_box): p.build_surface() surfaces.add_plane(p, options, tolerances, numeric_format, False) break @@ -131,7 +131,16 @@ def gen_plane(pos, normal, diag): return plane_center -def cyl_bound_planes(face, boundBox): +def other_face_edge(current_edge, current_face, solid): + for face in solid.Faces: + if face.isSame(current_face): + continue + for edge in face.Edges: + if current_edge.isSame(edge): + return face + + +def cyl_bound_planes(solid, face, boundBox): Edges = face.OuterWire.Edges planes = [] for e in Edges: @@ -140,6 +149,13 @@ def cyl_bound_planes(face, boundBox): except: curve = "none" + adjacent_face = other_face_edge(e, face, solid) + if adjacent_face is not None: + if type(adjacent_face.Surface) is GU.TorusGu: + continue # doesn't create plane if other face is a torus + if face.Surface.isSameSurface(adjacent_face.Surface): + continue # doesn't create plane if other face has same surface + if curve[0:6] == "Circle": dir = e.Curve.Axis center = e.Curve.Center @@ -159,7 +175,7 @@ def cyl_bound_planes(face, boundBox): return planes -def torus_bound_planes(face, boundBox, tolerances): +def torus_bound_planes(solid, face, boundBox, tolerances): params = face.ParameterRange planes = [] if is_same_value(params[1] - params[0], twoPi, tolerances.value): @@ -173,6 +189,11 @@ def torus_bound_planes(face, boundBox, tolerances): except: curve = "none" + adjacent_face = other_face_edge(e, face, solid) + if adjacent_face is not None: + if face.Surface.isSameSurface(adjacent_face.Surface): + continue # doesn't create plane if other face has same surface + if curve[0:6] == "Circle": dir = e.Curve.Axis if not is_parallel(dir, face.Surface.Axis, tolerances.angle): @@ -262,7 +283,7 @@ def extract_surfaces(solid, kind, universe_box, options, tolerances, numeric_for 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): + for p in cyl_bound_planes(solid_GU, face, universe_box): if MakeObj: p.build_surface() surfaces.add_plane(p, options, tolerances, numeric_format, False) @@ -280,7 +301,7 @@ def extract_surfaces(solid, kind, universe_box, options, tolerances, numeric_for surfaces.add_cone(cone, tolerances) if kind in ["Planes", "All"]: - for p in cyl_bound_planes(face, universe_box): + for p in cyl_bound_planes(solid_GU, face, universe_box): if MakeObj: p.build_surface() surfaces.add_plane(p, options, tolerances, numeric_format, False) @@ -294,7 +315,7 @@ def extract_surfaces(solid, kind, universe_box, options, tolerances, numeric_for surfaces.add_sphere(sphere, tolerances) if kind in ["Planes", "All"]: - for p in cyl_bound_planes(face, universe_box): + for p in cyl_bound_planes(solid_GU, face, universe_box): if MakeObj: p.build_surface() surfaces.add_plane(p, options, tolerances, numeric_format, False) @@ -311,7 +332,7 @@ def extract_surfaces(solid, kind, universe_box, options, tolerances, numeric_for surfaces.add_torus(torus, tolerances) if kind in ["Planes", "All"]: - for p in torus_bound_planes(face, universe_box, tolerances): + for p in torus_bound_planes(solid_GU, face, universe_box, tolerances): if MakeObj: p.build_surface() surfaces.add_plane(p, options, tolerances, numeric_format, False) diff --git a/src/geouned/GEOUNED/utils/data_classes.py b/src/geouned/GEOUNED/utils/data_classes.py index 1c5fd15f..1c305938 100644 --- a/src/geouned/GEOUNED/utils/data_classes.py +++ b/src/geouned/GEOUNED/utils/data_classes.py @@ -408,7 +408,7 @@ class NumericFormat: C_r (str, optional): Cylinder radius. Defaults to "12f". C_xyz (str, optional): Cylinder center. Defaults to "12f". K_xyz (str, optional): Cone apex. Defaults to "13.6e". - K_tan2 (str, optional): Cone tan^2 value. Defaults to "12f". + K_tan2 (str, optional): Cone tan^2 value. Defaults to "13.6e". T_r (str, optional): Torus radii. Defaults to "14.7e". T_xyz (str, optional): Torus center. Defaults to "14.7e". GQ_1to6 (str, optional): GQ 1 to 6 coefficients (order 2 x2,y2,z2,xy,...). Defaults to "18.15f". @@ -426,7 +426,7 @@ def __init__( C_r: str = "12f", C_xyz: str = "12f", K_xyz: str = "13.6e", - K_tan2: str = "12f", + K_tan2: str = "13.6e", T_r: str = "14.7e", T_xyz: str = "14.7e", GQ_1to6: str = "18.15f", diff --git a/src/geouned/GEOUNED/utils/functions.py b/src/geouned/GEOUNED/utils/functions.py index b5d251b0..678547d3 100644 --- a/src/geouned/GEOUNED/utils/functions.py +++ b/src/geouned/GEOUNED/utils/functions.py @@ -105,6 +105,11 @@ def set_cad_solid(self): self.Volume = self.CADSolid.Volume self.BoundBox = self.CADSolid.BoundBox + def optimalBoundingBox(self): + if self.CADSolid is None: + self.set_cad_solid() + return self.CADSolid.optimalBoundingBox() + def set_definition(self, definition, simplify=False): if definition is None: diff --git a/src/geouned/GEOUNED/utils/geometry_gu.py b/src/geouned/GEOUNED/utils/geometry_gu.py index 4011cbe5..6af3f4bb 100644 --- a/src/geouned/GEOUNED/utils/geometry_gu.py +++ b/src/geouned/GEOUNED/utils/geometry_gu.py @@ -50,6 +50,15 @@ def __init__(self, face, plane3Pts=False): self.dim1 = face.ParameterRange[1] - face.ParameterRange[0] self.dim2 = face.ParameterRange[3] - face.ParameterRange[2] + def isSameSurface(self, surface): + if type(surface) is not PlaneGu: + return False + if abs(self.Axis.dot(surface.Axis)) < 0.99999: + return False + if abs(self.Axis.dot(self.Position) - surface.Axis.dot(surface.Position)) > 1e-5: + return False + return True + class CylinderGu(SurfacesGu): """GEOUNED Cylinder Class""" @@ -61,6 +70,18 @@ def __init__(self, face): self.Center = face.Surface.Center self.dimL = face.ParameterRange[3] - face.ParameterRange[2] + def isSameSurface(self, surface): + if type(surface) is not CylinderGu: + return False + if abs(self.Radius - surface.Radius) > 1e-5: + return False + d = self.Center - surface.Center + if d.Length > 1e-5: + return False + if abs(self.Axis.dot(surface.Axis)) < 0.99999: + return False + return True + class ConeGu(SurfacesGu): """GEOUNED Cone Class""" @@ -74,6 +95,18 @@ def __init__(self, face): self.dimR = face.Surface.Radius self.Radius = face.Surface.Radius + def isSameSurface(self, surface): + if type(surface) is not ConeGu: + return False + if abs(self.SemiAngle - surface.SemiAngle) > 1e-5: + return False + d = self.Apex - surface.Apex + if d.Length > 1e-5: + return False + if abs(self.Axis.dot(surface.Axis)) < 0.99999: + return False + return True + class SphereGu(SurfacesGu): """GEOUNED Sphere Class""" @@ -84,6 +117,16 @@ def __init__(self, face): self.Center = face.Surface.Center self.Radius = face.Surface.Radius + def isSameSurface(self, surface): + if type(surface) is not SphereGu: + return False + if abs(self.Radius - surface.Radius) > 1e-5: + return False + d = self.Center - surface.Center + if d.Length > 1e-5: + return False + return True + class TorusGu(SurfacesGu): """GEOUNED Torus Class""" @@ -95,6 +138,20 @@ def __init__(self, face): self.MajorRadius = face.Surface.MajorRadius self.MinorRadius = face.Surface.MinorRadius + def isSameSurface(self, surface): + if type(surface) is not TorusGu: + return False + if abs(self.MajorRadius - surface.MajorRadius) > 1e-5: + return False + if abs(self.MinorRadius - surface.MinorRadius) > 1e-5: + return False + d = self.Center - surface.Center + if d.Length > 1e-5: + return False + if abs(self.Axis.dot(surface.Axis)) < 0.99999: + return False + return True + class SolidGu: """GEOUNED Solid Class""" @@ -112,9 +169,8 @@ def __init__(self, solid, tolerances, plane3Pts=False): toroidIndex = [] for i, face in enumerate(self.Faces): - if str(face.Surface) != "": - continue - toroidIndex.append(i) + if type(face.Surface) is TorusGu: + toroidIndex.append(i) if len(toroidIndex) != 0: tFaces = self.same_torus_surf(toroidIndex) @@ -259,6 +315,9 @@ def getUVNodes(self): def isEqual(self, face): return self.__face__.isEqual(face.__face__) + def isSame(self, face): + return self.__face__.isSame(face.__face__) + def valueAt(self, u, v): return self.__face__.valueAt(u, v) @@ -286,16 +345,16 @@ def define_list_face_gu(face_list, plane3Pts=False): def define_surface(face, plane3Pts): - kind_surf = str(face.Surface) - if kind_surf == "": + kind_surf = type(face.Surface) + if kind_surf is Part.Plane: Surf_GU = PlaneGu(face, plane3Pts) - elif kind_surf == "": + elif kind_surf is Part.Cylinder: Surf_GU = CylinderGu(face) - elif kind_surf == "": + elif kind_surf is Part.Cone: Surf_GU = ConeGu(face) - elif kind_surf[0:6] == "Sphere": + elif kind_surf is Part.Sphere: Surf_GU = SphereGu(face) - elif kind_surf == "": + elif kind_surf is Part.Toroid: Surf_GU = TorusGu(face) else: logger.info(f"bad Surface type {kind_surf}")