diff --git a/.circleci/config.yml b/.circleci/config.yml index 7f9ed82..cffc35d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -18,13 +18,7 @@ jobs: - run: name: run utils tests command: - pytest tests/test_python_api.py -v --cov=cad_to_h5m --cov-append --cov-report term --cov-report xml --junitxml=test-reports/junit.xml - - - store_test_results: - path: test-reports - - - run: bash <(curl -s https://codecov.io/bash) - + pytest tests/test_python_api.py -v workflows: version: 2 diff --git a/.github/workflows/ci_with_docker_build.yml b/.github/workflows/ci_with_docker_build.yml index 15a5838..f0fc4f7 100644 --- a/.github/workflows/ci_with_docker_build.yml +++ b/.github/workflows/ci_with_docker_build.yml @@ -10,19 +10,12 @@ on: jobs: build: runs-on: ubuntu-latest - - # ports: - # # Opens ports needed for Cubit license server communication on the host - # - 5053:5053 - # - 5119:5119 - + steps: - name: Checkout repository uses: actions/checkout@v2 - name: Build and test with Docker run: | - printf '${{ github.license_file }}' >> license.lic - cat license.lic docker build -t cad_to_h5m . docker run --rm --network host cad_to_h5m /bin/bash -c "bash run_tests.sh" diff --git a/.github/workflows/ci_with_install.yml b/.github/workflows/ci_with_install.yml index d34a831..2730673 100644 --- a/.github/workflows/ci_with_install.yml +++ b/.github/workflows/ci_with_install.yml @@ -26,7 +26,4 @@ jobs: - name: Run test_utils run: | - pytest tests/test_python_api.py -v --cov=cad_to_h5m --cov-append --cov-report term --cov-report xml --junitxml=test-reports/junit.xml - - - name: Upload to codecov - uses: codecov/codecov-action@v2 + pytest tests/test_python_api.py -v diff --git a/Dockerfile b/Dockerfile index c1a97f8..a1f91fa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -63,9 +63,6 @@ RUN apt-get install -y wget RUN wget https://github.com/svalinn/Cubit-plugin/releases/download/0.2.1/svalinn-plugin_debian-10.10_cubit_2021.5.tgz RUN tar -xzvf svalinn-plugin_debian-10.10_cubit_2021.5.tgz -C /opt/Coreform-Cubit-2021.5 -# makes a python file and trys to import cubit -RUN printf 'import sys\nsys.path.append("/opt/Coreform-Cubit-2021.5/bin/")\nimport cubit\ncubit.init([])\n' >> test_cubit_import.py - # writes a non commercial license file # RUN printf 'Fri May 28 2021' >> /opt/Coreform-Cubit-2021.5/bin/licenses/cubit-learn.lic RUN mkdir -p /root/.config/Coreform/licenses diff --git a/README.md b/README.md index 480475d..190db6c 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ a material tag to the volume. from cad_to_h5m import cad_to_h5m cad_to_h5m( - files_with_tags=[{'filename':'part1.stp', 'material_tags':'m1'}], + files_with_tags=[{'cad_filename':'part1.stp', 'material_tags':'m1'}], h5m_filename='dagmc.h5m', cubit_path='/opt/Coreform-Cubit-2021.5/bin/' ) @@ -73,8 +73,8 @@ from cad_to_h5m import cad_to_h5m cad_to_h5m( files_with_tags=[ - {'filename':'part1.stp', 'material_tags':'m1'}, - {'filename':'part2.stp', 'material_tags':'m2'} + {'cad_filename':'part1.stp', 'material_tags':'m1'}, + {'cad_filename':'part2.stp', 'material_tags':'m2'} ], h5m_filename='dagmc.h5m', cubit_path='/opt/Coreform-Cubit-2021.5/bin/' @@ -88,7 +88,7 @@ extension. from cad_to_h5m import cad_to_h5m cad_to_h5m( - files_with_tags=[{'filename':'part1.sat', 'material_tags':'m1'}], + files_with_tags=[{'cad_filename':'part1.sat', 'material_tags':'m1'}], h5m_filename='dagmc.h5m', cubit_path='/opt/Coreform-Cubit-2021.5/bin/' ) @@ -106,7 +106,7 @@ for the use of unstructured meshes in OpenMC. from cad_to_h5m import cad_to_h5m cad_to_h5m( - files_with_tags=[{'filename':'part1.sat', 'material_tags':'m1', 'tet_mesh': 'size 0.5'}], + files_with_tags=[{'cad_filename':'part1.sat', 'material_tags':'m1', 'tet_mesh': 'size 0.5'}], h5m_filename='dagmc.h5m', cubit_path='/opt/Coreform-Cubit-2021.5/bin/' exo_filename='unstructured_mesh_file.exo' diff --git a/cad_to_h5m/core.py b/cad_to_h5m/core.py index 136a7a5..63c6862 100644 --- a/cad_to_h5m/core.py +++ b/cad_to_h5m/core.py @@ -30,10 +30,10 @@ def cad_to_h5m( files_with_tags: The file names of the input CAD files with associated materials tags in the form of a list of dictionaries were each - dictionary has a "filename" and "material_tag" key. For example - [{"material_tag": "mat1", "filename": "part1.stp"}, {"material_tag": - "mat2", "filename": "part2.stp"}]. There is also an option to create a - tet mesh of entries by including a "tet_mesh" key in the dictionary. + dictionary has a "cad_filename" and "material_tag" key. For example + [{"material_tag": "mat1", "cad_filename": "part1.stp"}, {"material_tag": + "mat2", "cad_filename": "part2.stp"}]. There is also an option to create + a tet mesh of entries by including a "tet_mesh" key in the dictionary. The value is passed to the Cubit mesh command. An example entry would be "tet_mesh": "size 0.5" h5m_filename: the file name of the output h5m file @@ -71,14 +71,15 @@ def cad_to_h5m( cubit.init([]) - geometry_details = find_number_of_volumes_in_each_step_file( + geometry_details, total_number_of_volumes = find_number_of_volumes_in_each_step_file( files_with_tags, cubit) print(geometry_details) tag_geometry_with_mats(geometry_details, cubit) - if imprint: + if imprint and total_number_of_volumes > 1: imprint_geometry(cubit) - merge_geometry(merge_tolerance, cubit) + if total_number_of_volumes > 1: + merge_geometry(merge_tolerance, cubit) find_reflecting_surfaces_of_reflecting_wedge( geometry_details, surface_reflectivity_name, cubit ) @@ -269,27 +270,27 @@ def find_number_of_volumes_in_each_step_file(files_with_tags, cubit): print(entry) # starting_group_id = starting_group_id +1 current_vols = cubit.parse_cubit_list("volume", "all") - # print(os.path.join(basefolder, entry['filename'])) - if entry["filename"].endswith( - ".stp") or entry["filename"].endswith(".step"): + # print(os.path.join(basefolder, entry['cad_filename'])) + if entry["cad_filename"].endswith( + ".stp") or entry["cad_filename"].endswith(".step"): import_type = "step" - elif entry["filename"].endswith(".sat"): + elif entry["cad_filename"].endswith(".sat"): import_type = "acis" else: - msg = (f'File format for {entry["filename"]} is not supported.' + msg = (f'File format for {entry["cad_filename"]} is not supported.' 'Try step files or sat files') raise ValueError(msg) - if not Path(entry["filename"]).is_file(): - msg = f'File with filename {entry["filename"]} could not be found' + if not Path(entry["cad_filename"]).is_file(): + msg = f'File with filename {entry["cad_filename"]} could not be found' raise FileNotFoundError(msg) - short_file_name = os.path.split(entry["filename"])[-1] + short_file_name = os.path.split(entry["cad_filename"])[-1] # print('short_file_name',short_file_name) # cubit.cmd('import '+import_type+' "' + entry['stp_filename'] + '" separate_bodies no_surfaces no_curves no_vertices group "'+str(short_file_name)+'"') cubit.cmd( "import " + import_type + ' "' - + entry["filename"] + + entry["cad_filename"] + '" separate_bodies no_surfaces no_curves no_vertices ' ) all_vols = cubit.parse_cubit_list("volume", "all") @@ -324,4 +325,5 @@ def find_number_of_volumes_in_each_step_file(files_with_tags, cubit): "entry['surface_reflectivity']", entry["surface_reflectivity"]) cubit.cmd("separate body all") - return files_with_tags + + return files_with_tags, sum(all_vols) diff --git a/examples/create_h5m_from_download_stp_files.py b/examples/create_h5m_from_download_stp_files.py index 8eee979..1a5c9a1 100644 --- a/examples/create_h5m_from_download_stp_files.py +++ b/examples/create_h5m_from_download_stp_files.py @@ -14,37 +14,37 @@ cad_to_h5m(h5m_filename='dagmc.h5m', cubit_path="/opt/Coreform-Cubit-2021.5/bin/", files_with_tags=[{"material_tag": "pf_coil_mat", - "filename": "fusion_example_for_openmc_using_paramak-0.0.1/stp_files/pf_coils.stp", + "cad_filename": "fusion_example_for_openmc_using_paramak-0.0.1/stp_files/pf_coils.stp", }, {"material_tag": "pf_coil_case_mat", - "filename": "fusion_example_for_openmc_using_paramak-0.0.1/stp_files/pf_coil_cases.stp", + "cad_filename": "fusion_example_for_openmc_using_paramak-0.0.1/stp_files/pf_coil_cases.stp", }, {"material_tag": "center_column_shield_mat", - "filename": "fusion_example_for_openmc_using_paramak-0.0.1/stp_files/center_column_shield.stp", + "cad_filename": "fusion_example_for_openmc_using_paramak-0.0.1/stp_files/center_column_shield.stp", }, {"material_tag": "firstwall_mat", - "filename": "fusion_example_for_openmc_using_paramak-0.0.1/stp_files/outboard_firstwall.stp", + "cad_filename": "fusion_example_for_openmc_using_paramak-0.0.1/stp_files/outboard_firstwall.stp", }, {"material_tag": "blanket_mat", - "filename": "fusion_example_for_openmc_using_paramak-0.0.1/stp_files/blanket.stp", + "cad_filename": "fusion_example_for_openmc_using_paramak-0.0.1/stp_files/blanket.stp", }, {"material_tag": "divertor_mat", - "filename": "fusion_example_for_openmc_using_paramak-0.0.1/stp_files/divertor.stp", + "cad_filename": "fusion_example_for_openmc_using_paramak-0.0.1/stp_files/divertor.stp", }, {"material_tag": "supports_mat", - "filename": "fusion_example_for_openmc_using_paramak-0.0.1/stp_files/supports.stp", + "cad_filename": "fusion_example_for_openmc_using_paramak-0.0.1/stp_files/supports.stp", }, {"material_tag": "blanket_rear_wall_mat", - "filename": "fusion_example_for_openmc_using_paramak-0.0.1/stp_files/outboard_rear_blanket_wall.stp", + "cad_filename": "fusion_example_for_openmc_using_paramak-0.0.1/stp_files/outboard_rear_blanket_wall.stp", }, {"material_tag": "inboard_tf_coils_mat", - "filename": "fusion_example_for_openmc_using_paramak-0.0.1/stp_files/inboard_tf_coils.stp", + "cad_filename": "fusion_example_for_openmc_using_paramak-0.0.1/stp_files/inboard_tf_coils.stp", }, {"material_tag": "outer_tf_coil_mat", - "filename": "fusion_example_for_openmc_using_paramak-0.0.1/stp_files/outboard_tf_coil.stp", + "cad_filename": "fusion_example_for_openmc_using_paramak-0.0.1/stp_files/outboard_tf_coil.stp", }, {"material_tag": "graveyard", - "filename": "fusion_example_for_openmc_using_paramak-0.0.1/stp_files/graveyard.stp", + "cad_filename": "fusion_example_for_openmc_using_paramak-0.0.1/stp_files/graveyard.stp", }, ], ) diff --git a/examples/create_h5m_from_paramak_reactor.py b/examples/create_h5m_from_paramak_reactor.py index 887eaf8..b9e38c5 100644 --- a/examples/create_h5m_from_paramak_reactor.py +++ b/examples/create_h5m_from_paramak_reactor.py @@ -1,29 +1,40 @@ import paramak +from cad_to_h5m import cad_to_h5m -my_reactor = paramak.BallReactor( - inner_bore_radial_thickness=10, + +my_reactor = paramak.SubmersionTokamak( + inner_bore_radial_thickness=30, inboard_tf_leg_radial_thickness=30, - center_column_shield_radial_thickness=60, - divertor_radial_thickness=150, - inner_plasma_gap_radial_thickness=30, - plasma_radial_thickness=300, - outer_plasma_gap_radial_thickness=30, + center_column_shield_radial_thickness=30, + divertor_radial_thickness=80, + inner_plasma_gap_radial_thickness=50, + plasma_radial_thickness=200, + outer_plasma_gap_radial_thickness=50, firstwall_radial_thickness=30, - blanket_radial_thickness=50, blanket_rear_wall_radial_thickness=30, - elongation=2, - triangularity=0.55, number_of_tf_coils=16, - rotation_angle=90, + rotation_angle=360, + support_radial_thickness=90, + inboard_blanket_radial_thickness=30, + outboard_blanket_radial_thickness=30, + elongation=2.00, + triangularity=0.50, pf_coil_case_thicknesses=[10, 10, 10, 10], pf_coil_radial_thicknesses=[20, 50, 50, 20], pf_coil_vertical_thicknesses=[20, 50, 50, 20], - pf_coil_radial_position=[500, 575, 575, 500], - pf_coil_vertical_position=[300, 100, -100, -300], + pf_coil_radial_position=[500, 550, 550, 500], + pf_coil_vertical_position=[270, 100, -100, -270], rear_blanket_to_tf_gap=50, - outboard_tf_coil_radial_thickness=100, - outboard_tf_coil_poloidal_thickness=50, + outboard_tf_coil_radial_thickness=30, + outboard_tf_coil_poloidal_thickness=30, ) -# this function makes up of cad_to_h5m within the paramak -my_reactor.export_h5m_with_cubit() +my_reactor.export_stp() + +files_with_tags = my_reactor.neutronics_description() + +cad_to_h5m( + h5m_filename=' "dagmc.h5m', + cubit_path="/opt/Coreform-Cubit-2021.5/bin/", + files_with_tags=files_with_tags +) diff --git a/examples/create_h5m_from_paramak_shape.py b/examples/create_h5m_from_paramak_shape.py index 51775f3..a3fc25b 100644 --- a/examples/create_h5m_from_paramak_shape.py +++ b/examples/create_h5m_from_paramak_shape.py @@ -1,4 +1,5 @@ import paramak +from cad_to_h5m import cad_to_h5m my_shape = paramak.Plasma( major_radius=620, @@ -8,5 +9,12 @@ rotation_angle=90, ) -# this function makes up of cad_to_h5m within the paramak -my_shape.export_h5m_with_cubit() +my_shape.export_stp() + +files_with_tags = my_shape.neutronics_description() + +cad_to_h5m( + h5m_filename=' "dagmc.h5m', + cubit_path="/opt/Coreform-Cubit-2021.5/bin/", + files_with_tags=files_with_tags +) diff --git a/examples/create_h5m_from_paramak_stp_files.py b/examples/create_h5m_from_paramak_stp_files.py deleted file mode 100644 index 6b4329f..0000000 --- a/examples/create_h5m_from_paramak_stp_files.py +++ /dev/null @@ -1,83 +0,0 @@ -import paramak -from cad_to_h5m import cad_to_h5m - - -my_reactor = paramak.SubmersionTokamak( - inner_bore_radial_thickness=30, - inboard_tf_leg_radial_thickness=30, - center_column_shield_radial_thickness=30, - divertor_radial_thickness=80, - inner_plasma_gap_radial_thickness=50, - plasma_radial_thickness=200, - outer_plasma_gap_radial_thickness=50, - firstwall_radial_thickness=30, - blanket_rear_wall_radial_thickness=30, - number_of_tf_coils=16, - rotation_angle=90, - support_radial_thickness=90, - inboard_blanket_radial_thickness=30, - outboard_blanket_radial_thickness=30, - elongation=2.00, - triangularity=0.50, - pf_coil_case_thicknesses=[10, 10, 10, 10], - pf_coil_radial_thicknesses=[20, 50, 50, 20], - pf_coil_vertical_thicknesses=[20, 50, 50, 20], - pf_coil_radial_position=[500, 550, 550, 500], - pf_coil_vertical_position=[270, 100, -100, -270], - rear_blanket_to_tf_gap=50, - outboard_tf_coil_radial_thickness=30, - outboard_tf_coil_poloidal_thickness=30, -) - -my_reactor.export_stp() - -cad_to_h5m( - h5m_filename=' "dagmc.h5m', - cubit_path="/opt/Coreform-Cubit-2021.5/bin/", - files_with_tags=[ - { - "material_tag": "pf_coil_mat", - "filename": "pf_coils.stp", - }, - { - "material_tag": "pf_coil_case_mat", - "filename": "pf_coil_cases.stp", - }, - { - "material_tag": "center_column_shield_mat", - "filename": "center_column_shield.stp", - }, - { - "material_tag": "firstwall_mat", - "filename": "outboard_firstwall.stp", - }, - { - "material_tag": "blanket_mat", - "filename": "blanket.stp", - }, - { - "material_tag": "divertor_mat", - "filename": "divertor.stp", - }, - { - "material_tag": "supports_mat", - "filename": "supports.stp", - }, - { - "material_tag": "blanket_rear_wall_mat", - "filename": "outboard_rear_blanket_wall.stp", - }, - { - "material_tag": "inboard_tf_coils_mat", - "filename": "inboard_tf_coils.stp", - }, - { - "material_tag": "outer_tf_coil_mat", - "filename": "outboard_tf_coil.stp", - }, - { - "material_tag": "graveyard", - "filename": "graveyard.stp", - }, - ], -) diff --git a/run_tests.sh b/run_tests.sh index 85b3f87..ab8e763 100644 --- a/run_tests.sh +++ b/run_tests.sh @@ -1,3 +1,3 @@ #!/bin/bash -pytest tests -v --cov=cad_to_h5m --cov-append --cov-report term --cov-report xml +pytest tests -v diff --git a/setup.py b/setup.py index c9c88e0..5b418a9 100644 --- a/setup.py +++ b/setup.py @@ -25,8 +25,8 @@ 'Operating System :: OS Independent', ], tests_require=[ - "pytest-cov", + "pytest", ], python_requires='>=3.6', - install_requires=["pytest-cov"], + install_requires=["pytest"], ) diff --git a/tests/test_python_api.py b/tests/test_python_api.py index c0a1ef8..b607bdf 100644 --- a/tests/test_python_api.py +++ b/tests/test_python_api.py @@ -30,7 +30,7 @@ def test_h5m_file_creation(self): returned_filename = cad_to_h5m( files_with_tags=[ { - "filename": "tests/fusion_example_for_openmc_using_paramak-0.0.1/stp_files/blanket.stp", + "cad_filename": "tests/fusion_example_for_openmc_using_paramak-0.0.1/stp_files/blanket.stp", "material_tag": "mat1", } ], @@ -56,7 +56,7 @@ def test_watertight_h5m_file_creation(self): cad_to_h5m( files_with_tags=[ { - "filename": "tests/fusion_example_for_openmc_using_paramak-0.0.1/stp_files/blanket.stp", + "cad_filename": "tests/fusion_example_for_openmc_using_paramak-0.0.1/stp_files/blanket.stp", "material_tag": "mat1", }], h5m_filename="dagmc.h5m", @@ -73,7 +73,7 @@ def test_cub_file_creation(self): cad_to_h5m( files_with_tags=[ { - "filename": "tests/fusion_example_for_openmc_using_paramak-0.0.1/stp_files/blanket.stp", + "cad_filename": "tests/fusion_example_for_openmc_using_paramak-0.0.1/stp_files/blanket.stp", "material_tag": "mat1", }], cubit_filename="dagmc.cub", @@ -89,7 +89,7 @@ def test_faceting_tolerance_increases_file_size(self): cad_to_h5m( files_with_tags=[ { - "filename": "tests/fusion_example_for_openmc_using_paramak-0.0.1/stp_files/blanket.stp", + "cad_filename": "tests/fusion_example_for_openmc_using_paramak-0.0.1/stp_files/blanket.stp", "material_tag": "mat1", }], h5m_filename="dagmc_default_faceting_tolerance.h5m", @@ -101,7 +101,7 @@ def test_faceting_tolerance_increases_file_size(self): cad_to_h5m( files_with_tags=[ { - "filename": "tests/fusion_example_for_openmc_using_paramak-0.0.1/stp_files/blanket.stp", + "cad_filename": "tests/fusion_example_for_openmc_using_paramak-0.0.1/stp_files/blanket.stp", "material_tag": "mat1", }], h5m_filename="dagmc_small_faceting_tolerance.h5m", @@ -123,7 +123,7 @@ def test_exo_file_creation_with_different_sizes(self): cad_to_h5m( files_with_tags=[ { - "filename": "tests/fusion_example_for_openmc_using_paramak-0.0.1/stp_files/pf_coils.stp", + "cad_filename": "tests/fusion_example_for_openmc_using_paramak-0.0.1/stp_files/pf_coils.stp", "material_tag": "mat1", "tet_mesh": "size 3"}], exo_filename="umesh_3.exo", @@ -136,7 +136,7 @@ def test_exo_file_creation_with_different_sizes(self): cad_to_h5m( files_with_tags=[ { - "filename": "tests/fusion_example_for_openmc_using_paramak-0.0.1/stp_files/pf_coils.stp", + "cad_filename": "tests/fusion_example_for_openmc_using_paramak-0.0.1/stp_files/pf_coils.stp", "material_tag": "mat1", "tet_mesh": "size 10"}], exo_filename="umesh_10.exo", @@ -155,7 +155,7 @@ def test_exo_file_creation_with_default_size(self): cad_to_h5m( files_with_tags=[ { - "filename": "tests/fusion_example_for_openmc_using_paramak-0.0.1/stp_files/pf_coils.stp", + "cad_filename": "tests/fusion_example_for_openmc_using_paramak-0.0.1/stp_files/pf_coils.stp", "material_tag": "mat1", "tet_mesh": ""}], exo_filename="umesh_default.exo",