Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #30 from fusion-energy/develop
Browse files Browse the repository at this point in the history
changed filename tag to cad_filename
  • Loading branch information
shimwell authored Aug 26, 2021
2 parents db17a15 + 79cfb66 commit ffb731f
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 168 deletions.
8 changes: 1 addition & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 1 addition & 8 deletions .github/workflows/ci_with_docker_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
5 changes: 1 addition & 4 deletions .github/workflows/ci_with_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 0 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/'
)
Expand All @@ -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/'
Expand All @@ -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/'
)
Expand All @@ -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'
Expand Down
36 changes: 19 additions & 17 deletions cad_to_h5m/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
22 changes: 11 additions & 11 deletions examples/create_h5m_from_download_stp_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
],
)
45 changes: 28 additions & 17 deletions examples/create_h5m_from_paramak_reactor.py
Original file line number Diff line number Diff line change
@@ -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
)
12 changes: 10 additions & 2 deletions examples/create_h5m_from_paramak_shape.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import paramak
from cad_to_h5m import cad_to_h5m

my_shape = paramak.Plasma(
major_radius=620,
Expand All @@ -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
)
83 changes: 0 additions & 83 deletions examples/create_h5m_from_paramak_stp_files.py

This file was deleted.

2 changes: 1 addition & 1 deletion run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

pytest tests -v --cov=cad_to_h5m --cov-append --cov-report term --cov-report xml
pytest tests -v
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
'Operating System :: OS Independent',
],
tests_require=[
"pytest-cov",
"pytest",
],
python_requires='>=3.6',
install_requires=["pytest-cov"],
install_requires=["pytest"],
)
Loading

0 comments on commit ffb731f

Please sign in to comment.