diff --git a/Dockerfile b/Dockerfile index 2c67f4ec..95e4ffa3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -164,7 +164,7 @@ RUN if [ "$include_neutronics" = "true" ] ; \ # Clone and install OpenMC with DAGMC RUN if [ "$include_neutronics" = "true" ] ; \ - then git clone --recurse-submodules https://github.com/openmc-dev/openmc.git /opt/openmc ; \ + then git clone --single-branch --branch v0.12.1 --depth 1 --recurse-submodules https://github.com/openmc-dev/openmc.git /opt/openmc ; \ cd /opt/openmc ; \ mkdir build ; \ cd build ; \ @@ -186,6 +186,22 @@ RUN if [ "$include_neutronics" = "true" ] ; \ pip install openmc_data_downloader ; \ fi +RUN if [ "$include_neutronics" = "true" ] ; \ + then wget https://f002.backblazeb2.com/file/cubit-downloads/Coreform-Cubit/master/Linux/Coreform-Cubit-master-60a5c1c2-Lin64.deb ; \ + apt-get --yes install libx11-6 ; \ + apt-get --yes install libgl1 ; \ + apt-get --yes install libglu1-mesa ; \ + apt-get --yes install libgl1-mesa-glx ; \ + apt-get --yes install libxcb-icccm4 ; \ + apt-get --yes install libxcb-image0 ; \ + apt-get --yes install libxcb-keysyms1 ; \ + apt-get --yes install libxcb-render-util0 ; \ + apt-get --yes install libxkbcommon-x11-0 ; \ + apt-get --yes install libxcb-randr0 ; \ + apt-get --yes install libxcb-xinerama0 ; \ + dpkg -i Coreform-Cubit-master-60a5c1c2-Lin64.deb ; \ + fi + COPY requirements.txt requirements.txt RUN pip install -r requirements.txt diff --git a/paramak/neutronics_utils.py b/paramak/neutronics_utils.py index d2115d16..0258fcab 100644 --- a/paramak/neutronics_utils.py +++ b/paramak/neutronics_utils.py @@ -136,7 +136,8 @@ def trelis_command_to_create_dagmc_h5m( os.system('rm dagmc_not_watertight.h5m') if batch: - trelis_cmd = 'trelis -batch -nographics' + # trelis_cmd = 'trelis -batch -nographics' + trelis_cmd = 'coreform_cubit -batch -nographics' else: trelis_cmd = 'trelis' diff --git a/tests/test_neutronics_utils.py b/tests/test_neutronics_utils.py index 0f0178ea..0e52a864 100644 --- a/tests/test_neutronics_utils.py +++ b/tests/test_neutronics_utils.py @@ -199,185 +199,186 @@ def test_make_watertight_cmd_with_example_dagmc_file(self): assert Path("watertight_dagmc.h5m").exists() is True # these tests only work if trelis is avaialbe - # def test_make_watertight_cmd(self): - # """exports a h5m and makes it watertight, checks the the watertight - # file is produced.""" - - # os.system('rm *.stl *.h5m') - - # https://github.com/Shimwell/fusion_example_for_openmc_using_paramak/raw/main/dagmc.h5m - - # pf_coil = paramak.PoloidalFieldCoil( - # height=10, - # width=10, - # center_point=(100, 0), - # rotation_angle=180, - # material_tag='copper', - # method='trelis' - # ) - - # pf_coil.export_h5m_with_trelis( - # filename='not_watertight_dagmc.h5m', - # include_graveyard=True, - # ) - - # assert Path('not_watertight_dagmc.h5m').is_file - - # output_filename = paramak.neutronics_utils.make_watertight( - # input_filename="not_watertight_dagmc.h5m", - # output_filename="watertight_dagmc.h5m" - # ) - - # assert Path("not_watertight_dagmc.h5").exists() is True - # assert output_filename == "watertight_dagmc.h5m" - # assert Path("watertight_dagmc.h5").exists() is True - - # def test_trelis_command_to_create_dagmc_h5m_with_default_mat_name(self): - # """Creats a h5m file with trelis and forms groups using the material_tag - # key in the manifest.json file. Then checks the groups in the resulting - # h5 file match those in the original dictionary""" - - # pf_coil = paramak.PoloidalFieldCoil( - # height=10, - # width=10, - # center_point=(100, 0), - # rotation_angle=180, - # ) - - # pf_coil_case = paramak.PoloidalFieldCoilCaseFC( - # pf_coil=pf_coil, - # casing_thickness=5 - # ) - - # pf_coil.export_stp('pf_coil.stp') - # pf_coil_case.export_stp('pf_coil_case.stp') - - # manifest_with_material_tags = [ - # { - # "material_tag": "copper", - # "stp_filename": "pf_coil_case.stp" - # }, - # { - # "material_tag": "tungsten_carbide", - # "stp_filename": "pf_coil.stp" - # } - # ] - # with open('manifest.json', 'w') as outfile: - # json.dump(manifest_with_material_tags, outfile) - - # paramak.neutronics_utils.trelis_command_to_create_dagmc_h5m( - # faceting_tolerance=1e-2, - # merge_tolerance=1e-4, - # material_key_name='material_tag', - # batch=True - # ) - - # list_of_mats = paramak.neutronics_utils.find_material_groups_in_h5m( - # filename="dagmc_not_watertight.h5m" - # ) - - # assert len(list_of_mats) == 2 - # assert 'mat:copper' in list_of_mats - # assert 'mat:tungsten_carbide' in list_of_mats - # # assert 'mat:graveyard' in list_of_mats - - # def test_trelis_command_to_create_dagmc_h5m_with_user_mat_name(self): - # """Creats a h5m file with trelis and forms groups using the material_id - # key in the manifest.json file. Then checks the groups in the resulting - # h5 file match those in the original dictionary""" - - # os.system('rm *.stp *.h5m *.json') - - # pf_coil = paramak.PoloidalFieldCoil( - # height=10, - # width=10, - # center_point=(100, 0), - # rotation_angle=180, - # ) - - # pf_coil_case = paramak.PoloidalFieldCoilCaseFC( - # pf_coil=pf_coil, - # casing_thickness=5 - # ) - - # pf_coil.export_stp('pf_coil.stp') - # pf_coil_case.export_stp('pf_coil_case.stp') - - # manifest_with_material_tags = [ - # { - # "material_id": "42", - # "stp_filename": "pf_coil_case.stp" - # }, - # { - # "material_id": 12, # this is an int to check the str() works - # "stp_filename": "pf_coil.stp" - # } - # ] - # with open('manifest.json', 'w') as outfile: - # json.dump(manifest_with_material_tags, outfile) - - # paramak.neutronics_utils.trelis_command_to_create_dagmc_h5m( - # faceting_tolerance=1e-2, - # merge_tolerance=1e-4, - # material_key_name='material_id', - # batch=True, - # ) - - # list_of_mats = paramak.neutronics_utils.find_material_groups_in_h5m( - # filename="dagmc_not_watertight.h5m" - # ) - - # assert len(list_of_mats) == 2 - # assert 'mat:42' in list_of_mats - # assert 'mat:12' in list_of_mats - # # assert 'mat:graveyard' in list_of_mats - - # def test_trelis_command_to_create_dagmc_h5m_with_custom_geometry_key(self): - # """Creats a h5m file with trelis and loads stp files using a custom - # key in the manifest.json file. Then checks the groups in the resulting - # h5 file match those in the original dictionary""" - - # os.system('rm *.stp *.h5m *.json') - - # pf_coil = paramak.PoloidalFieldCoil( - # height=10, - # width=10, - # center_point=(100, 0), - # rotation_angle=180, - # ) - - # pf_coil_case = paramak.PoloidalFieldCoilCaseFC( - # pf_coil=pf_coil, - # casing_thickness=5 - # ) - - # pf_coil.export_stp('pf_coil_custom_key.stp') - # pf_coil_case.export_stp('pf_coil_case_custom_key.stp') - - # manifest_with_material_tags = [ - # { - # "material_tag": "copper", - # "geometry_filename": "pf_coil_custom_key.stp" - # }, - # { - # "material_tag": "tungsten_carbide", - # "geometry_filename": "pf_coil_case_custom_key.stp" - # } - # ] - # with open('manifest.json', 'w') as outfile: - # json.dump(manifest_with_material_tags, outfile) - - # paramak.neutronics_utils.trelis_command_to_create_dagmc_h5m( - # faceting_tolerance=1e-2, - # merge_tolerance=1e-4, - # geometry_key_name='geometry_filename', - # batch=True - # ) - - # list_of_mats = paramak.neutronics_utils.find_material_groups_in_h5m( - # filename="dagmc_not_watertight.h5m" - # ) - - # assert len(list_of_mats) == 2 - # assert 'mat:copper' in list_of_mats - # assert 'mat:tungsten_carbide' in list_of_mats + def test_make_watertight_cmd(self): + """exports a h5m and makes it watertight, checks the the watertight + file is produced.""" + + os.system('rm *.stl *.h5m') + + # https: // github.com / Shimwell / + # fusion_example_for_openmc_using_paramak / raw / main / dagmc.h5m + + pf_coil = paramak.PoloidalFieldCoil( + height=10, + width=10, + center_point=(100, 0), + rotation_angle=180, + material_tag='copper', + method='trelis' + ) + + pf_coil.export_h5m_with_trelis( + filename='not_watertight_dagmc.h5m', + include_graveyard=True, + ) + + assert Path('not_watertight_dagmc.h5m').is_file + + output_filename = paramak.neutronics_utils.make_watertight( + input_filename="not_watertight_dagmc.h5m", + output_filename="watertight_dagmc.h5m" + ) + + assert Path("not_watertight_dagmc.h5").exists() is True + assert output_filename == "watertight_dagmc.h5m" + assert Path("watertight_dagmc.h5").exists() is True + + def test_trelis_command_to_create_dagmc_h5m_with_default_mat_name(self): + """Creats a h5m file with trelis and forms groups using the material_tag + key in the manifest.json file. Then checks the groups in the resulting + h5 file match those in the original dictionary""" + + pf_coil = paramak.PoloidalFieldCoil( + height=10, + width=10, + center_point=(100, 0), + rotation_angle=180, + ) + + pf_coil_case = paramak.PoloidalFieldCoilCaseFC( + pf_coil=pf_coil, + casing_thickness=5 + ) + + pf_coil.export_stp('pf_coil.stp') + pf_coil_case.export_stp('pf_coil_case.stp') + + manifest_with_material_tags = [ + { + "material_tag": "copper", + "stp_filename": "pf_coil_case.stp" + }, + { + "material_tag": "tungsten_carbide", + "stp_filename": "pf_coil.stp" + } + ] + with open('manifest.json', 'w') as outfile: + json.dump(manifest_with_material_tags, outfile) + + paramak.neutronics_utils.trelis_command_to_create_dagmc_h5m( + faceting_tolerance=1e-2, + merge_tolerance=1e-4, + material_key_name='material_tag', + batch=True + ) + + list_of_mats = paramak.neutronics_utils.find_material_groups_in_h5m( + filename="dagmc_not_watertight.h5m" + ) + + assert len(list_of_mats) == 2 + assert 'mat:copper' in list_of_mats + assert 'mat:tungsten_carbide' in list_of_mats + # assert 'mat:graveyard' in list_of_mats + + def test_trelis_command_to_create_dagmc_h5m_with_user_mat_name(self): + """Creats a h5m file with trelis and forms groups using the material_id + key in the manifest.json file. Then checks the groups in the resulting + h5 file match those in the original dictionary""" + + os.system('rm *.stp *.h5m *.json') + + pf_coil = paramak.PoloidalFieldCoil( + height=10, + width=10, + center_point=(100, 0), + rotation_angle=180, + ) + + pf_coil_case = paramak.PoloidalFieldCoilCaseFC( + pf_coil=pf_coil, + casing_thickness=5 + ) + + pf_coil.export_stp('pf_coil.stp') + pf_coil_case.export_stp('pf_coil_case.stp') + + manifest_with_material_tags = [ + { + "material_id": "42", + "stp_filename": "pf_coil_case.stp" + }, + { + "material_id": 12, # this is an int to check the str() works + "stp_filename": "pf_coil.stp" + } + ] + with open('manifest.json', 'w') as outfile: + json.dump(manifest_with_material_tags, outfile) + + paramak.neutronics_utils.trelis_command_to_create_dagmc_h5m( + faceting_tolerance=1e-2, + merge_tolerance=1e-4, + material_key_name='material_id', + batch=True, + ) + + list_of_mats = paramak.neutronics_utils.find_material_groups_in_h5m( + filename="dagmc_not_watertight.h5m" + ) + + assert len(list_of_mats) == 2 + assert 'mat:42' in list_of_mats + assert 'mat:12' in list_of_mats + # assert 'mat:graveyard' in list_of_mats + + def test_trelis_command_to_create_dagmc_h5m_with_custom_geometry_key(self): + """Creats a h5m file with trelis and loads stp files using a custom + key in the manifest.json file. Then checks the groups in the resulting + h5 file match those in the original dictionary""" + + os.system('rm *.stp *.h5m *.json') + + pf_coil = paramak.PoloidalFieldCoil( + height=10, + width=10, + center_point=(100, 0), + rotation_angle=180, + ) + + pf_coil_case = paramak.PoloidalFieldCoilCaseFC( + pf_coil=pf_coil, + casing_thickness=5 + ) + + pf_coil.export_stp('pf_coil_custom_key.stp') + pf_coil_case.export_stp('pf_coil_case_custom_key.stp') + + manifest_with_material_tags = [ + { + "material_tag": "copper", + "geometry_filename": "pf_coil_custom_key.stp" + }, + { + "material_tag": "tungsten_carbide", + "geometry_filename": "pf_coil_case_custom_key.stp" + } + ] + with open('manifest.json', 'w') as outfile: + json.dump(manifest_with_material_tags, outfile) + + paramak.neutronics_utils.trelis_command_to_create_dagmc_h5m( + faceting_tolerance=1e-2, + merge_tolerance=1e-4, + geometry_key_name='geometry_filename', + batch=True + ) + + list_of_mats = paramak.neutronics_utils.find_material_groups_in_h5m( + filename="dagmc_not_watertight.h5m" + ) + + assert len(list_of_mats) == 2 + assert 'mat:copper' in list_of_mats + assert 'mat:tungsten_carbide' in list_of_mats