diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8e9bf6e1..fab46788 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,18 +53,24 @@ jobs: geouned_cadtocsg --help python -c 'import geouned' python -c 'from geouned import CadToCsg' - python -c 'from geouned.GEOReverse import reverse' + python -c 'from geouned import CsgToCad' python -m pip install .[tests] - name: testing package version run: | python -m pytest -v tests/test_version.py - - name: testing GEOUNED functionality + - name: testing GEOUNED CadToCsg functionality run: | - python -m pytest -v tests/test_convert.py - geouned_cadtocsg -i tests/config_complete_defaults.json - geouned_cadtocsg -i tests/config_non_defaults.json + python -m pytest -v tests/test_cadtocsg.py + geouned_cadtocsg -i tests/config_cadtocsg_complete_defaults.json + geouned_cadtocsg -i tests/config_cadtocsg_non_defaults.json + + - name: testing GEOUNED CsgToCad functionality + run: | + python -m pytest -v tests/test_csgtocad.py + geouned_csgtocad -i tests/config_csgtocad_complete.json + geouned_csgtocad -i tests/config_csgtocad_minimal.json - name: install openmc if: ${{ matrix.os == 'ubuntu-latest'}} diff --git a/docs/developer_guide.rst b/docs/developer_guide.rst index eeea924e..4442c148 100644 --- a/docs/developer_guide.rst +++ b/docs/developer_guide.rst @@ -138,16 +138,19 @@ However we need one more dependency to run the tests. Then we can run the tests with the following command from the root of the repository. .. code-block:: sh + python -m pytest We can run individual test files by specifying the file path .. code-block:: sh + python -m pytest tests/test_convert.py We can run individual test functions by specifying the file path and function name .. code-block:: sh + python -m pytest tests/test_convert.py -k 'test_conversion' Additional pytest options that might be useful are including -s for standard output and -vv for very verbose output. diff --git a/docs/python_api.rst b/docs/python_api.rst index 12fa2c9e..72e5f834 100644 --- a/docs/python_api.rst +++ b/docs/python_api.rst @@ -4,6 +4,10 @@ Python API reference .. currentmodule:: geouned +.. autoclass:: CsgToCad + :members: + :show-inheritance: + .. autoclass:: CadToCsg :members: :show-inheritance: @@ -22,4 +26,4 @@ Python API reference .. autoclass:: Tolerances :members: - :show-inheritance: + :show-inheritance: \ No newline at end of file diff --git a/docs/usage/index.rst b/docs/usage/index.rst index 97282c13..157a09ab 100644 --- a/docs/usage/index.rst +++ b/docs/usage/index.rst @@ -10,5 +10,7 @@ GEOUNED can be used as a Python package with the API or as a command line tool w :numbered: :maxdepth: 1 - python_api_usage - python_cli_usage \ No newline at end of file + python_cadtocsg_api_usage + python_cadtocsg_cli_usage + python_csgtocad_api_usage + python_csgtocad_cli_usage diff --git a/docs/usage/python_api_usage.rst b/docs/usage/python_cadtocsg_api_usage.rst similarity index 97% rename from docs/usage/python_api_usage.rst rename to docs/usage/python_cadtocsg_api_usage.rst index 43462eaf..eefc973e 100644 --- a/docs/usage/python_api_usage.rst +++ b/docs/usage/python_cadtocsg_api_usage.rst @@ -1,5 +1,5 @@ -Python Package Usage -==================== +Python Package Usage, CAD to CSG conversion +=========================================== 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_cli_usage.rst b/docs/usage/python_cadtocsg_cli_usage.rst similarity index 95% rename from docs/usage/python_cli_usage.rst rename to docs/usage/python_cadtocsg_cli_usage.rst index 1cf983f0..ffdd2c83 100644 --- a/docs/usage/python_cli_usage.rst +++ b/docs/usage/python_cadtocsg_cli_usage.rst @@ -1,7 +1,7 @@ -Command Line Tool Usage -======================= +Command Line Tool Usage, CAD to CSG conversion +============================================== -GEOUNED can be used in the command line. +GEOUNED CAD to CSG conversion can be performed in the command line. These examples assumes you have a CAD STEP file in the current working directory of the terminal called "cuboid.stp" @@ -112,6 +112,7 @@ Here is a complete JSON file specification "cellSummaryFile": true } } + Note that JSON requires ```null``` to be passed in which gets translated to ```None``` in Python. This is converted in the same way as the minimal JSON config file diff --git a/docs/usage/python_csgtocad_api_usage.rst b/docs/usage/python_csgtocad_api_usage.rst new file mode 100644 index 00000000..1c9b2987 --- /dev/null +++ b/docs/usage/python_csgtocad_api_usage.rst @@ -0,0 +1,41 @@ +Python Package Usage, CSG to CAD conversion +=========================================== + +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. + + +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 CsgToCad being used to convert a CSG geometry into a STEP CAD file. +The example makes use of default attributes. + +.. code-block:: python + + import geouned + + geo = geouned.CsgToCad() + + geo.export_cad( + csg_format='openmc_xml', + input_filename='cylinder_box.xml', + ) + + +Users can change the default arguments to suit the conversion desired. +The following example shows a usage with every attributes specified. +Remember that the arguments are described in the `Python API reference section <../python_api.html>`_ of the documentation. + +.. code-block:: python + + import geouned + + geo = geouned.CsgToCad() + + geo.export_cad( + input_filename='cylinder_box.xml', + csg_format='openmc_xml', + bounding_box=[-1000.0, -500.0, -1000.0, 0,0,0.0 ], + cell_range_type='exclude', + cell_range=(2,3,4), + output_filename='openmc_xml', + ) diff --git a/docs/usage/python_csgtocad_cli_usage.rst b/docs/usage/python_csgtocad_cli_usage.rst new file mode 100644 index 00000000..83d955e7 --- /dev/null +++ b/docs/usage/python_csgtocad_cli_usage.rst @@ -0,0 +1,78 @@ +Command Line Tool Usage, CSG to CAD conversion +============================================== + +GEOUNED CSG to CAD conversion can be performed in the command line. + +Both OpenMC XML CSG and MCNP CSG formats are supported. + +The first example assumes you have an OpenMC XML CSG file in the current working directory of the terminal called "cylinder_box.xml". + +The most minimal use case below shows a minimal config_openmc.json file being used. + +First create a JSON file called "config_openmc.json" containing the following. + +.. code-block:: json + + { + "export_cad":{ + "input_filename": "cylinder_box.xml", + "csg_format": "openmc_xml" + } + } + + +Then execute the command line interface tool to convert your OpenMC XML CSG file to a STEP CAD file with the default configuration. + +.. code-block:: bash + + geouned_csgtocad -i config_openmc.json + +MCNP CSG files can also be converted, this example assumes you have a MCNP CSG file in te current working directory called "cylinder_box.mcnp". + +For MCNP CSG files, the JSON config file should be as follows and is assumed to be named "config_mcnp.json". + + +.. code-block:: json + + { + "export_cad":{ + "input_filename": "cylinder_box.mcnp", + "csg_format": "mcnp" + } + } + +Then execute the command line interface tool to convert your MCNP CSG file to a STEP CAD file with the default configuration. + +.. code-block:: bash + + geouned_csgtocad -i config_mcnp.json + + +The following example shows a usage with every attributes specified in the config.json file. + +The contents of the JSON file closely matches the Class arguments and method arguments when using the Python package. + +For a full description of each keyword see the `Python API reference section <../python_api.html>`_ of the documentation. + +Here is a complete JSON file specification + +.. code-block:: json + + { + "export_cad":{ + "input_filename": "tests/csg_files/cylinder_box.xml", + "csg_format": "openmc_xml", + "output_filename" : "cad_from_csg", + "bounding_box": [-1000, -1000, -1000, 1000, 1000, 1000], + "universe_start": 0, + "level_max": "all", + "cell_range_type": "all", + "cell_range": [], + "mat_range_type": "all", + "mat_range": [] + } + } + +.. code-block:: bash + + geouned_csgtocad -i config.json diff --git a/pyproject.toml b/pyproject.toml index f8fcb9f1..949329ff 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,6 +49,7 @@ docs = [ [project.scripts] geouned_cadtocsg = "geouned.GEOUNED.scripts.geouned_cadtocsg:main" +geouned_csgtocad = "geouned.GEOReverse.scripts.geouned_csgtocad:main" [tool.black] line-length = 128 diff --git a/src/geouned/GEOReverse/__init__.py b/src/geouned/GEOReverse/__init__.py index e69de29b..09671254 100644 --- a/src/geouned/GEOReverse/__init__.py +++ b/src/geouned/GEOReverse/__init__.py @@ -0,0 +1 @@ +from .core import CsgToCad diff --git a/src/geouned/GEOReverse/core.py b/src/geouned/GEOReverse/core.py new file mode 100644 index 00000000..6bf59b62 --- /dev/null +++ b/src/geouned/GEOReverse/core.py @@ -0,0 +1,113 @@ +import typing +import FreeCAD +import Import + +from pathlib import Path + +from .Modules.buildCAD import buildCAD, makeTree +from .Modules.MCNPinput import McnpInput +from .Modules.Objects import CadCell +from .Modules.XMLinput import XmlInput + + +class CsgToCad: + """Base class for the conversion of CSG to CAD models""" + + def __init__(self): + pass + + def export_cad( + self, + input_filename: str, + csg_format: str, + output_filename: str = "cad_from_csg", + bounding_box: typing.Tuple[int, int, int, int, int, int] = (-1000, -1000, -1000, 1000, 1000, 1000), + universe_start: int = 0, + level_max: str = "all", + cell_range_type: str = "all", + cell_range: typing.Tuple[int] = (), + mat_range_type: str = "all", + mat_range: typing.Tuple[int] = (), + # TODO add these to the method signature + # splitTolerance in the Options class + # mat = this is in the CADselection dictionary but not in the docs https://github.com/GEOUNED-org/GEOUNED/blob/76ef697c7dca6a828c7498996ff3313859c872f2/docs/User_Guide_GEOUNED_v2.0.pdf + ): + """export the CSG geometry in OpenMC or MCNP format to a CAD model. + + Args: + input_filename (str): The filename and path of the input CSG text file. + csg_format (str): The format of the CSG input file, options are 'openmc_xml' or 'mcnp' + output_filename (str, optional): The filename stem and path of the output file created. + Two files will be created with the '.step' suffix and one with the 'FCStd' suffix. + Defaults to 'cad_from_csg'. + bounding_box (typing.Tuple[int, int, int, int, int, int], optional): The bounding box + coordinates of the CSG geometry. This should encompass the entire CSG geometry. + Format is (xmin, ymin, zmin, xmax, ymax, zmax) Defaults to (-1000, -1000, -1000, + 1000, 1000, 1000). + universe_start (int, optional): The Universe ID to be converted to CAD. If universe_start + is left as 0 then all the universes and any nested universes are converted. If set + then the universe and all its nested universes are converted. Defaults to 0. + level_max (str, optional): Level maximum of nested universe to be translated. If + level_max < highest nested universe level, cells inside the container cell whose + level is level_max will not be translated. This container cell will be the CAD + solid written in the CAD file. Defaults to "all". + cell_range_type (str, optional): Define how to consider the range values. + setting to 'all' results in all the cells with any cell ID being converted (range a no effect). + setting to 'include' results in only cells defined in 'range' being converted. + setting to 'exclude' results in exclude all cells defined in range. Defaults to "all". + cell_range (typing.Tuple[int], optional): list of cells to be included/excluded for the conversion. + Defaults to (). + mat_range_type (str, optional): Define how to consider the range values. + setting to 'all' results in all the materials with any cell ID being converted (range a no effect). + setting to 'include' results in only materials defined in 'range' being converted. + setting to 'exclude' results in exclude all materials defined in range. Defaults to "all". + mat_range (typing.Tuple[int], optional): list of materials to be included/excluded for the conversion. + Defaults to (). + + Raises: + ValueError: If the csg_format is not 'openmc_xml' or 'mcnp' then a ValueError is raised. + """ + + # TODO check file extensions are correct + # if Path(output_filename).suffix not in ['.stp', '.step']: + # raise ValueError(f"output file must have a .stp or .step extension, not {universe_start.suffix}") + + # get geometry definition from OpenMC XML or MCNP input + if csg_format == "mcnp": + geo = McnpInput(input_filename) + elif csg_format == "openmc_xml": + geo = XmlInput(input_filename) + else: + msg = f"input format type {csg_format} is not supported. Supported options are 'openmc_xml' or 'mcnp'" + raise ValueError(msg) + + Path(output_filename).parent.mkdir(parents=True, exist_ok=True) + + UnivCell = CadCell() + UnivCell.shape = UnivCell.makeBox(FreeCAD.BoundBox(*bounding_box)) + + # TODO make these variable names lower case in the downstream code + + CADselection = { + "Ustart": universe_start, + "levelMax": level_max, + "cell": [cell_range_type, cell_range], + "mat": [mat_range_type, mat_range], + "format": csg_format, + "cell_range_type": cell_range_type, + "cell_range": cell_range, + "mat_range_type": mat_range_type, + "mat_range": mat_range, + } + + # TODO don't return fails variable, just fail in the method and raise the error there + CADCells, fails = buildCAD(UnivCell, geo, CADselection) + + if fails: + print("failed in conversion", fails) + + CADdoc = FreeCAD.newDocument("converted_with_geouned") + + makeTree(CADdoc, CADCells) + Import.export(CADdoc.Objects[0:1], f"{output_filename}.step") + CADdoc.saveAs(f"{output_filename}.FCStd") diff --git a/src/geouned/GEOReverse/reverse.py b/src/geouned/GEOReverse/reverse.py deleted file mode 100644 index faaf432a..00000000 --- a/src/geouned/GEOReverse/reverse.py +++ /dev/null @@ -1,71 +0,0 @@ -import FreeCAD -import Import - -from .CodeVersion import * -from .Modules.buildCAD import buildCAD, makeTree -from .Modules.MCNPinput import McnpInput -from .Modules.Objects import CadCell -from .Modules.processInp import setOptions -from .Modules.XMLinput import XmlInput - - -def reverse(optFile="configRevese.ini"): - - printCodeVersion() - - setting = setOptions(optFile) - - geomfile = setting["fileIn"] - outname = setting["fileOut"] - outBox = setting["outBox"] - inFormat = setting["inFormat"] - - CADselection = { - "Ustart": setting["UStart"], - "levelMax": setting["levelMax"], - "cell": setting["cell"], - "mat": setting["mat"], - "format": setting["inFormat"], - } - - UnivCell = CadCell() - UnivCell.shape = UnivCell.makeBox(FreeCAD.BoundBox(*outBox)) - - # get geometry definition from MCNP input - if inFormat == "mcnp": - geom = McnpInput(geomfile) - elif inFormat == "openmc_xml": - geom = XmlInput(geomfile) - else: - msg = f"input format type {inFormat} is not supported." 'Supported options are "mcnp" or "openmc_xml"' - raise ValueError(msg) - - CADCells, fails = buildCAD(UnivCell, geom, CADselection) - - if fails: - print("failed in conversion", fails) - - CADdoc = FreeCAD.newDocument("WorkingDoc") - - makeTree(CADdoc, CADCells) - Import.export(CADdoc.Objects[0:1], outname + ".stp") - CADdoc.saveAs(outname + ".FCStd") - - -def printCodeVersion(): - - FreeCAD_Version = "{V[0]:}.{V[1]:}.{V[2]:}".format(V=FreeCAD.Version()) - title = """\ -######################################################################### -# # -# GEOReverse version {:<11}{}{:>26} -# FreeCAD version {:<11}{:>36} -# # -#########################################################################""".format( - GEOReverse_Version, GEOReverse_ReleaseDate, "#", FreeCAD_Version, "#" - ) - print(title) - - -if __name__ == "__main__": - reverse() diff --git a/src/geouned/GEOReverse/scripts/__init__.py b/src/geouned/GEOReverse/scripts/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/geouned/GEOReverse/scripts/geouned_csgtocad.py b/src/geouned/GEOReverse/scripts/geouned_csgtocad.py new file mode 100644 index 00000000..1288d9f6 --- /dev/null +++ b/src/geouned/GEOReverse/scripts/geouned_csgtocad.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 + +""" +Convert Cad geometry to CSG format for use in Monte Carlo Codes +""" + +import argparse +import json + +from pathlib import Path + +import geouned + +parser = argparse.ArgumentParser(description=__doc__) +parser.add_argument( + "-i", + "--input", + type=str, + default="config.json", + help="The path to the config JSON file", +) +args = parser.parse_args() + + +def main(): + + if not Path(args.input).exists(): + raise FileNotFoundError(f"config file {args.input} not found") + + with open(args.input) as f: + config = json.load(f) + + geo = geouned.CsgToCad() + geo.export_cad(**config["export_cad"]) + + +if __name__ == "__main__": + main() diff --git a/tests/config_complete_defaults.json b/tests/config_cadtocsg_complete_defaults.json similarity index 100% rename from tests/config_complete_defaults.json rename to tests/config_cadtocsg_complete_defaults.json diff --git a/tests/config_minimal.json b/tests/config_cadtocsg_minimal.json similarity index 100% rename from tests/config_minimal.json rename to tests/config_cadtocsg_minimal.json diff --git a/tests/config_non_defaults.json b/tests/config_cadtocsg_non_defaults.json similarity index 100% rename from tests/config_non_defaults.json rename to tests/config_cadtocsg_non_defaults.json diff --git a/tests/config_csgtocad_complete.json b/tests/config_csgtocad_complete.json new file mode 100644 index 00000000..33798df9 --- /dev/null +++ b/tests/config_csgtocad_complete.json @@ -0,0 +1,13 @@ +{ + "export_cad": { + "input_filename": "tests/csg_files/cylinder_box.xml", + "csg_format": "openmc_xml", + "output_filename": "cad_from_csg", + "bounding_box": [-1000, -1000, -1000, 1000, 1000, 1000], + "universe_start": 0, + "level_max": "all", + "cell_range_type": "all", + "cell_range": [1,2], + "mat_range_type": "all" + } +} \ No newline at end of file diff --git a/tests/config_csgtocad_minimal.json b/tests/config_csgtocad_minimal.json new file mode 100644 index 00000000..7b195bcb --- /dev/null +++ b/tests/config_csgtocad_minimal.json @@ -0,0 +1,6 @@ +{ + "export_cad":{ + "input_filename": "tests/csg_files/cylinder_box.xml", + "csg_format": "openmc_xml" + } +} \ No newline at end of file diff --git a/tests/csg_files/cylinder_box.mcnp b/tests/csg_files/cylinder_box.mcnp new file mode 100644 index 00000000..098038a3 --- /dev/null +++ b/tests/csg_files/cylinder_box.mcnp @@ -0,0 +1,87 @@ +Converted with GEOUNED +C ______ _______ _____ _ _ __ _ _______ ______ +C | ____ |______ | | ___ | | | \ | |______ | \ +C |_____| |______ |_____| |_____| | \_| |______ |_____/ +C Version : 1.0.2.dev38+ga3fd78f.d20240613 +C FreeCAD Version : 0.21.2 +C +C ************************************************************* +C Original Step file : /home/j/GEOUNED/testing/inputSTEP/cylBox.stp +C +C Creation Date : 2024-06-13 14:01:29.607259 +C Solid Cells : 1 +C Total Cells : 4 +C Surfaces : 23 +C Materials : 0 +C +C ************************************************************** +1 0 -14 -6 5:2 6 7 8 9 -1:3 10 11 12 15 16 -4:-15 -13 -10:-15 10 11: + -15 -11 -9 + imp:n=1.0 imp:p=1.0 +C +C ########################################################## +C VOID CELLS +C ########################################################## +C +2 0 17 -18 19 -20 21 -22 (15:-10:-11) (15:11:9) (-8:-7:-2:1:-6:-9) (13: + 15:10) (14:-5:6) (-16:-12:4:-3:-10:-11:-15) + imp:n=1.0 imp:p=1.0 + $Automatic Generated Void Cell. Enclosure(-76.966, -47.115, -22.500, -11.500, -56.992, -40.592) + $Enclosed cells : (1) +3 0 -23 (-17:18:-19:20:-21:22) + imp:n=1.0 imp:p=1.0 + $Graveyard_in +4 0 23 + imp:n=0 imp:p=0 + $Graveyard + +C ########################################################## +C SURFACE DEFINITION +C ########################################################## +1 PY -1.2500035e+01 +2 PY -2.1500035e+01 +3 PY -1.9500035e+01 +4 PY -1.4500035e+01 +5 P 9.4664926e-01 9.5825876e-09 3.2226569e-01 -8.8839591e+01 +6 P 9.4664926e-01 9.5825876e-09 3.2226569e-01 -8.1689591e+01 +7 P -3.2226569e-01 -5.6149002e-11 9.4664926e-01 -3.1338638e+01 +8 P 3.2226569e-01 5.6149002e-11 -9.4664926e-01 2.2338638e+01 +9 P -9.4664926e-01 -9.5825876e-09 -3.2226569e-01 7.0239591e+01 +10 P -9.4664926e-01 -9.5825876e-09 -3.2226569e-01 6.3039591e+01 +11 P 9.4664926e-01 9.5825876e-09 3.2226569e-01 -7.0039591e+01 +12 P -3.2226569e-01 -5.6149002e-11 9.4664926e-01 -3.4238638e+01 +13 P 9.4664926e-01 9.5825876e-09 3.2226569e-01 -6.1239591e+01 +14 GQ 0.103855177195422 0.999999999999999 0.896144822804578 + -0.000000018142699 -0.000000006176279 -0.610145160974434 + -17.298344774043834 34.000069238333026 50.813553217939962 + 1006.753657691386934 +15 GQ 0.103855177195422 0.999999999999999 0.896144822804578 + -0.000000018142699 -0.000000006176279 -0.610145160974434 + -17.298344774043830 34.000069238333033 50.813553217939955 + 995.251157691386766 +16 P 3.2226569e-01 5.6276909e-11 -9.4664926e-01 2.9633723e+01 +17 PX -7.6966386e+01 +18 PX -4.7114745e+01 +19 PY -2.2500035e+01 +20 PY -1.1500035e+01 +21 PZ -5.6992451e+01 +22 PZ -4.0592261e+01 +23 S -6.2040565e+01 -1.7000035e+01 -4.8792356e+01 1.8254058e+01 + +C +MODE P +VOID +NPS 1e6 +PRDMP 2J -1 +C SDEF PAR=P X=D1 Y=D2 Z=D3 +C SI1 -7.6966386e+01 -4.7114745e+01 +C SI2 -2.2500035e+01 -1.1500035e+01 +C SI3 -5.6992451e+01 -4.0592261e+01 +C SP1 0 1 +C SP2 0 1 +C SP3 0 1 +SDEF PAR=P NRM=-1 SUR=23 WGT=1.0468121e+03 DIR=d1 +SI1 0 1 +SP1 -21 1 +F4:P 1 +SD4 1.5208150e+03 \ No newline at end of file diff --git a/tests/csg_files/cylinder_box.xml b/tests/csg_files/cylinder_box.xml new file mode 100644 index 00000000..f62c11f0 --- /dev/null +++ b/tests/csg_files/cylinder_box.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/test_convert.py b/tests/test_cadtocsg.py similarity index 97% rename from tests/test_convert.py rename to tests/test_cadtocsg.py index a84be0ad..26137237 100644 --- a/tests/test_convert.py +++ b/tests/test_cadtocsg.py @@ -129,7 +129,7 @@ def test_conversion(input_step_file): @pytest.mark.parametrize( "input_json_file", - ["tests/config_complete_defaults.json", "tests/config_minimal.json"], + ["tests/config_cadtocsg_complete_defaults.json", "tests/config_cadtocsg_minimal.json"], ) def test_cad_to_csg_from_json_with_defaults(input_json_file): @@ -156,7 +156,7 @@ def test_cad_to_csg_from_json_with_non_defaults(): for suffix in suffixes: Path("csg").with_suffix(suffix).unlink(missing_ok=True) - my_cad_to_csg = geouned.CadToCsg.from_json("tests/config_non_defaults.json") + my_cad_to_csg = geouned.CadToCsg.from_json("tests/config_cadtocsg_non_defaults.json") assert isinstance(my_cad_to_csg, geouned.CadToCsg) assert my_cad_to_csg.filename == "testing/inputSTEP/BC.stp" diff --git a/tests/test_csgtocad.py b/tests/test_csgtocad.py new file mode 100644 index 00000000..79ae59d1 --- /dev/null +++ b/tests/test_csgtocad.py @@ -0,0 +1,28 @@ +from pathlib import Path +import pytest +import geouned + + +@pytest.mark.parametrize("csg_format", ["mcnp", "openmc_xml"]) +def test_cylbox_convertion(csg_format): + + if csg_format == "openmc_xml": + suffix = ".xml" + elif csg_format == "mcnp": + suffix = ".mcnp" + + geo = geouned.CsgToCad() + + geo.export_cad( + # csg file was made from testing/inputSTEP/cylBox.stp + input_filename=f"tests/csg_files/cylinder_box{suffix}", + csg_format=csg_format, + bounding_box=[-1000.0, -500.0, -1000.0, 0, 0, 0.0], + # TODO add tests for these args that counts volumes in cad file + # cell_range_type='exclude', + # cell_range=(2,3,4), + output_filename=f"tests_outputs/csgtocad/{csg_format}", + ) + + assert Path(f"tests_outputs/csgtocad/{csg_format}.step").exists() + assert Path(f"tests_outputs/csgtocad/{csg_format}.FCStd").exists()