From 71522fd31024fe6b5d45189740b8560c2af3ca63 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 16 Jul 2019 11:16:16 -0500 Subject: [PATCH 01/16] Check for material temp and use if cell temp is not set on the .h5m file. --- src/dagmc.cpp | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/dagmc.cpp b/src/dagmc.cpp index 78d8bc4fb..29e89b4bc 100644 --- a/src/dagmc.cpp +++ b/src/dagmc.cpp @@ -215,17 +215,6 @@ void load_dagmc_geometry() model::universes[it->second]->cells_.push_back(i); } - // check for temperature assignment - std::string temp_value; - if (model::DAG->has_prop(vol_handle, "temp")) { - rval = model::DAG->prop_value(vol_handle, "temp", temp_value); - MB_CHK_ERR_CONT(rval); - double temp = std::stod(temp_value); - c->sqrtkT_.push_back(std::sqrt(K_BOLTZMANN * temp)); - } else { - c->sqrtkT_.push_back(std::sqrt(K_BOLTZMANN * settings::temperature_default)); - } - // MATERIALS if (model::DAG->is_implicit_complement(vol_handle)) { @@ -295,6 +284,24 @@ void load_dagmc_geometry() legacy_assign_material(mat_value, c); } } + + // check for temperature assignment + std::string temp_value; + + if (c->material_[0] == MATERIAL_VOID) { continue; } + + auto& mat = model::materials[c->material_[0]]; + if (model::DAG->has_prop(vol_handle, "temp")) { + rval = model::DAG->prop_value(vol_handle, "temp", temp_value); + MB_CHK_ERR_CONT(rval); + double temp = std::stod(temp_value); + c->sqrtkT_.push_back(std::sqrt(K_BOLTZMANN * temp)); + } else if (mat->temperature_ > 0.0) { + c->sqrtkT_.push_back(std::sqrt(K_BOLTZMANN * mat->temperature_)); + } else { + c->sqrtkT_.push_back(std::sqrt(K_BOLTZMANN * settings::temperature_default)); + } + } // allocate the cell overlap count if necessary From da152b9b0f31cb81f25d4781025e77a401aef044 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 16 Jul 2019 16:30:01 -0500 Subject: [PATCH 02/16] Updating DagMC s.t. their temperatures can be set using material temps. Also addressig a bug in closing an hdf5 dataset and adding tests. --- src/dagmc.cpp | 2 +- src/summary.cpp | 1 + tests/regression_tests/dagmc/legacy/dagmc.h5m | Bin 1233372 -> 1233364 bytes .../dagmc/legacy/inputs_true.dat | 4 ++- tests/regression_tests/dagmc/legacy/test.py | 28 ++++++++++++++++++ 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/dagmc.cpp b/src/dagmc.cpp index 29e89b4bc..1e6f3d02a 100644 --- a/src/dagmc.cpp +++ b/src/dagmc.cpp @@ -290,7 +290,7 @@ void load_dagmc_geometry() if (c->material_[0] == MATERIAL_VOID) { continue; } - auto& mat = model::materials[c->material_[0]]; + auto& mat = model::materials[model::material_map[c->material_[0]]]; if (model::DAG->has_prop(vol_handle, "temp")) { rval = model::DAG->prop_value(vol_handle, "temp", temp_value); MB_CHK_ERR_CONT(rval); diff --git a/src/summary.cpp b/src/summary.cpp index 500a5c15c..d2721f97e 100644 --- a/src/summary.cpp +++ b/src/summary.cpp @@ -92,6 +92,7 @@ void write_geometry(hid_t file) #ifdef DAGMC if (settings::dagmc) { write_attribute(geom_group, "dagmc", 1); + close_group(geom_group); return; } #endif diff --git a/tests/regression_tests/dagmc/legacy/dagmc.h5m b/tests/regression_tests/dagmc/legacy/dagmc.h5m index c90b6d674d9b016aba5b8614d952d90205c355f2..fbbe9a34a8c01b245375acaffc5e3f2f33fd60aa 100644 GIT binary patch delta 769 zcmcb!*!#+2?+F@=S2k)MmSH(-s24l=gUmyDbA3ZIeM3to1_8i9G_fMs{rxzg4#oqSCwlp zy*WO)rw%H%p>E;knH3LN7W`I^jWbnhD@%W0yBQfE2cjuCihH*IAQaKsY+~2 zKBp%CSqycP!je}^Hm4DMgQbTipPH+|sdGjM5@VCAqa-0#KX9C|dBwaSRz{u4zZXNz z2Wgi%kF5O_(09_ypx$vh&Am#vKP9Ww2Vs0Sj0b*Vt=G%T_9sh><=?a?s9NTB;2{>?Z c@+m-k(lh;`xqx{44+{Yx7To^BLg>j10QS=u!vFvP delta 774 zcmcbz*!#|6?+F@=cQ$GsmSOq)r6*?c2bqWR#`=b4`i7QF3=qHpr41~s49u)dEjNFV zjS&E=-W;G8!wF$+Fqh$gm~g@V72}M_yB!oE+y@RbI0Y0SMhHx9baZ5HU|^hF8zm0W z_rQ^d5yJZ51Z8byES6a*U?faD~wYJqg1 z>I;)sXFye7$gpB(l$p$30Ckf=!7Ii!lcfux(hh}9tW0l?Pp+v|fcSbr?V-u5$~Bn2 z9G~1%2Nl~;w{Y{!iia$WB9p6Yq2?^8eFZeOyAEp3hPq2^lP9$)!3;S(IlE1LGFLBD zz@c!#=7{!9tdphspdtpnuNXt%#%*@!vtnb6nOr>uX8e>_Oe`lS_e_O2Ve^KmN^DFa zrzZbd40V&jl2=SFrxARErH3Y;nybNSaz+RoFbtEcqa-1&dEhu<^NM*vtc)g;e=mlb z57Mr39$EV<}B5$VG@z8VvAgoBRM6r5DyZaoIrS79hz1J=uI?UHgr7 zj6lo;#LPg<0>rF9%m&2lK+FNeoIuP4#N0s41H`;Q%(wl - + @@ -22,6 +22,8 @@ -4 -4 -4 4 4 4 + 7 + 50.0 true diff --git a/tests/regression_tests/dagmc/legacy/test.py b/tests/regression_tests/dagmc/legacy/test.py index b6f2f55e2..38c3c4267 100644 --- a/tests/regression_tests/dagmc/legacy/test.py +++ b/tests/regression_tests/dagmc/legacy/test.py @@ -5,10 +5,19 @@ from openmc.stats import Box import pytest from tests.testing_harness import PyAPITestHarness +import numpy as np + pytestmark = pytest.mark.skipif( not openmc.capi._dagmc_enabled(), reason="DAGMC CAD geometry is not enabled.") + +class DAGMCPyAPITestHarness(PyAPITestHarness): + + def _compare_inputs(self): + super()._compare_inputs() + + def test_dagmc(): model = openmc.model.Model() @@ -16,6 +25,7 @@ def test_dagmc(): model.settings.batches = 5 model.settings.inactive = 0 model.settings.particles = 100 + model.settings.temperature = {'tolerance': 50.0} source = openmc.Source(space=Box([-4, -4, -4], [ 4, 4, 4])) @@ -34,6 +44,7 @@ def test_dagmc(): u235.add_nuclide('U235', 1.0, 'ao') u235.set_density('g/cc', 11) u235.id = 40 + u235.temperature = 320 water = openmc.Material(name="water") water.add_nuclide('H1', 2.0, 'ao') @@ -46,4 +57,21 @@ def test_dagmc(): model.materials = mats harness = PyAPITestHarness('statepoint.5.h5', model=model) + model.settings.verbosity = 1 + harness._build_inputs() + + # check cell temps as well here + openmc.capi.init([]) + + expected_temps = { 1 : 320.0, # assigned by material + 2 : 300.0, # assigned in dagmc file + 3 : 293.6 } # assigned by default + + for cell_id, temp in expected_temps.items(): + capi_cell = openmc.capi.cells[cell_id] + assert np.isclose(capi_cell.get_temperature(), temp) + + openmc.capi.finalize() + + model.settings.verbosity = 7 harness.main() From 89c75a7b8242dfc794fb1073ad58f0dabcd06c73 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 16 Jul 2019 20:56:11 -0500 Subject: [PATCH 03/16] Sharing model between tests. --- .../dagmc/legacy/inputs_true.dat | 1 - tests/regression_tests/dagmc/legacy/test.py | 20 ++++++++----------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/tests/regression_tests/dagmc/legacy/inputs_true.dat b/tests/regression_tests/dagmc/legacy/inputs_true.dat index 056a7eb9d..b2b092cff 100644 --- a/tests/regression_tests/dagmc/legacy/inputs_true.dat +++ b/tests/regression_tests/dagmc/legacy/inputs_true.dat @@ -22,7 +22,6 @@ -4 -4 -4 4 4 4 - 7 50.0 true diff --git a/tests/regression_tests/dagmc/legacy/test.py b/tests/regression_tests/dagmc/legacy/test.py index 38c3c4267..1e4107cfb 100644 --- a/tests/regression_tests/dagmc/legacy/test.py +++ b/tests/regression_tests/dagmc/legacy/test.py @@ -11,14 +11,8 @@ pytestmark = pytest.mark.skipif( not openmc.capi._dagmc_enabled(), reason="DAGMC CAD geometry is not enabled.") - -class DAGMCPyAPITestHarness(PyAPITestHarness): - - def _compare_inputs(self): - super()._compare_inputs() - - -def test_dagmc(): +@pytest.fixture(scope="module") +def dagmc_model(): model = openmc.model.Model() # settings @@ -56,9 +50,10 @@ def test_dagmc(): mats = openmc.Materials([u235, water]) model.materials = mats - harness = PyAPITestHarness('statepoint.5.h5', model=model) - model.settings.verbosity = 1 - harness._build_inputs() + yield model + +def test_dagmc_temps(dagmc_model): + dagmc_model.export_to_xml() # check cell temps as well here openmc.capi.init([]) @@ -73,5 +68,6 @@ def test_dagmc(): openmc.capi.finalize() - model.settings.verbosity = 7 +def test_dagmc(dagmc_model): + harness = PyAPITestHarness('statepoint.5.h5', model=dagmc_model) harness.main() From 347f4d7dd5ce36285206f3717d70ed26e01c5ddd Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 18 Jul 2019 11:30:32 -0500 Subject: [PATCH 04/16] Separating dagmc cell temperature checks into unit tests. --- src/dagmc.cpp | 19 +++-- .../dagmc/legacy/inputs_true.dat | 3 +- tests/regression_tests/dagmc/legacy/test.py | 35 ++------- tests/unit_tests/dagmc/__init__.py | 0 tests/unit_tests/dagmc/conftest.py | 12 +++ tests/unit_tests/dagmc/dagmc.h5m | 1 + tests/unit_tests/dagmc/test.py | 75 +++++++++++++++++++ 7 files changed, 106 insertions(+), 39 deletions(-) create mode 100644 tests/unit_tests/dagmc/__init__.py create mode 100644 tests/unit_tests/dagmc/conftest.py create mode 120000 tests/unit_tests/dagmc/dagmc.h5m create mode 100644 tests/unit_tests/dagmc/test.py diff --git a/src/dagmc.cpp b/src/dagmc.cpp index 1e6f3d02a..a4ca81fbe 100644 --- a/src/dagmc.cpp +++ b/src/dagmc.cpp @@ -35,10 +35,9 @@ const bool dagmc_enabled = false; #ifdef DAGMC -const std::string DAGMC_FILENAME = "dagmc.h5m"; - namespace openmc { +const std::string DAGMC_FILENAME = settings::path_input + "dagmc.h5m"; namespace simulation { @@ -54,8 +53,16 @@ moab::DagMC* DAG; } // namespace model +void check_dagmc_file() { + if (!file_exists(DAGMC_FILENAME)) { + fatal_error("Geometry DAGMC file '" + DAGMC_FILENAME + "' does not exist!"); + } +} + bool get_uwuw_materials_xml(std::string& s) { - UWUW uwuw(DAGMC_FILENAME.c_str()); + check_dagmc_file(); + + UWUW uwuw((settings::path_input + DAGMC_FILENAME).c_str()); std::stringstream ss; bool uwuw_mats_present = false; @@ -376,11 +383,7 @@ void load_dagmc_geometry() void read_geometry_dagmc() { // Check if dagmc.h5m exists - std::string filename = settings::path_input + "dagmc.h5m"; - if (!file_exists(filename)) { - fatal_error("Geometry DAGMC file '" + filename + "' does not exist!"); - } - + check_dagmc_file(); write_message("Reading DAGMC geometry...", 5); load_dagmc_geometry(); diff --git a/tests/regression_tests/dagmc/legacy/inputs_true.dat b/tests/regression_tests/dagmc/legacy/inputs_true.dat index b2b092cff..8ca49c324 100644 --- a/tests/regression_tests/dagmc/legacy/inputs_true.dat +++ b/tests/regression_tests/dagmc/legacy/inputs_true.dat @@ -1,6 +1,6 @@ - + @@ -22,7 +22,6 @@ -4 -4 -4 4 4 4 - 50.0 true diff --git a/tests/regression_tests/dagmc/legacy/test.py b/tests/regression_tests/dagmc/legacy/test.py index 1e4107cfb..73a3babe6 100644 --- a/tests/regression_tests/dagmc/legacy/test.py +++ b/tests/regression_tests/dagmc/legacy/test.py @@ -1,28 +1,25 @@ import openmc import openmc.capi -from openmc.stats import Box import pytest from tests.testing_harness import PyAPITestHarness -import numpy as np - pytestmark = pytest.mark.skipif( not openmc.capi._dagmc_enabled(), reason="DAGMC CAD geometry is not enabled.") -@pytest.fixture(scope="module") -def dagmc_model(): +def test_dagmc(): model = openmc.model.Model() # settings model.settings.batches = 5 model.settings.inactive = 0 model.settings.particles = 100 - model.settings.temperature = {'tolerance': 50.0} - source = openmc.Source(space=Box([-4, -4, -4], - [ 4, 4, 4])) + source_box = openmc.stats.Box([-4, -4, -4], + [ 4, 4, 4]) + source = openmc.Source(space=source_box) + model.settings.source = source model.settings.dagmc = True @@ -38,7 +35,6 @@ def dagmc_model(): u235.add_nuclide('U235', 1.0, 'ao') u235.set_density('g/cc', 11) u235.id = 40 - u235.temperature = 320 water = openmc.Material(name="water") water.add_nuclide('H1', 2.0, 'ao') @@ -50,24 +46,5 @@ def dagmc_model(): mats = openmc.Materials([u235, water]) model.materials = mats - yield model - -def test_dagmc_temps(dagmc_model): - dagmc_model.export_to_xml() - - # check cell temps as well here - openmc.capi.init([]) - - expected_temps = { 1 : 320.0, # assigned by material - 2 : 300.0, # assigned in dagmc file - 3 : 293.6 } # assigned by default - - for cell_id, temp in expected_temps.items(): - capi_cell = openmc.capi.cells[cell_id] - assert np.isclose(capi_cell.get_temperature(), temp) - - openmc.capi.finalize() - -def test_dagmc(dagmc_model): - harness = PyAPITestHarness('statepoint.5.h5', model=dagmc_model) + harness = PyAPITestHarness('statepoint.5.h5', model=model) harness.main() diff --git a/tests/unit_tests/dagmc/__init__.py b/tests/unit_tests/dagmc/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/unit_tests/dagmc/conftest.py b/tests/unit_tests/dagmc/conftest.py new file mode 100644 index 000000000..621532231 --- /dev/null +++ b/tests/unit_tests/dagmc/conftest.py @@ -0,0 +1,12 @@ + +import pytest + +@pytest.fixture(scope='module', autouse=True) +def setup_dagmc_unit_test(request): + + # Change to test directory + olddir = request.fspath.dirpath().chdir() + try: + yield + finally: + olddir.chdir() diff --git a/tests/unit_tests/dagmc/dagmc.h5m b/tests/unit_tests/dagmc/dagmc.h5m new file mode 120000 index 000000000..0c5ab5da8 --- /dev/null +++ b/tests/unit_tests/dagmc/dagmc.h5m @@ -0,0 +1 @@ +../../regression_tests/dagmc/legacy/dagmc.h5m \ No newline at end of file diff --git a/tests/unit_tests/dagmc/test.py b/tests/unit_tests/dagmc/test.py new file mode 100644 index 000000000..2302ab7e4 --- /dev/null +++ b/tests/unit_tests/dagmc/test.py @@ -0,0 +1,75 @@ +import glob +import os + +import numpy as np +import pytest + +import openmc +import openmc.capi + +from tests import cdtemp + +pytestmark = pytest.mark.skipif( + not openmc.capi._dagmc_enabled(), + reason="DAGMC CAD geometry is not enabled.") + +def test_dagmc_temperatures(): + model = openmc.model.Model() + + # settings + model.settings.batches = 5 + model.settings.inactive = 0 + model.settings.particles = 100 + model.settings.temperature = {'tolerance': 50.0} + model.settings.verbosity = 1 + source_box = openmc.stats.Box([-4, -4, -4], + [ 4, 4, 4]) + source = openmc.Source(space=source_box) + model.settings.source = source + + model.settings.dagmc = True + + # tally + tally = openmc.Tally() + tally.scores = ['total'] + tally.filters = [openmc.CellFilter(1)] + model.tallies = [tally] + + # materials + u235 = openmc.Material(name="fuel") + u235.add_nuclide('U235', 1.0, 'ao') + u235.set_density('g/cc', 11) + u235.id = 40 + u235.temperature = 320 + + water = openmc.Material(name="water") + water.add_nuclide('H1', 2.0, 'ao') + water.add_nuclide('O16', 1.0, 'ao') + water.set_density('g/cc', 1.0) + water.add_s_alpha_beta('c_H_in_H2O') + water.id = 41 + + mats = openmc.Materials([u235, water]) + model.materials = mats + + model.export_to_xml() + + # check cell temps as well here + openmc.capi.init() + + expected_temps = { 1 : 320.0, # assigned by material + 2 : 300.0, # assigned in dagmc file + 3 : 293.6 } # assigned by default + + for cell_id, temp in expected_temps.items(): + capi_cell = openmc.capi.cells[cell_id] + assert np.isclose(capi_cell.get_temperature(), temp) + + openmc.capi.finalize() + + # cleanup + input_files = glob.glob("*.xml") + input_files += glob.glob("*.h5") + for f in input_files: + if os.path.exists(f): + os.remove(f) From 978e7ba94a5da37f54bd4d09914193d0ab72f317 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 19 Jul 2019 08:41:30 -0500 Subject: [PATCH 05/16] Adding a note about setting up tallies for DagMC models. --- examples/jupyter/cad-based-geometry.ipynb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/examples/jupyter/cad-based-geometry.ipynb b/examples/jupyter/cad-based-geometry.ipynb index 6ff79d27c..5c449cd00 100644 --- a/examples/jupyter/cad-based-geometry.ipynb +++ b/examples/jupyter/cad-based-geometry.ipynb @@ -236,6 +236,13 @@ "tallies.export_to_xml()" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Note:** Applying tally filters in DagMC models requires prior knowledge of the model. Here, we know that the fuel cell's volume ID in the CAD sofware is 1. To identify cells without use of CAD software, we recommend loading them into the [OpenMC plotter](https://github.com/openmc/plotter) where cell, material, and volume IDs can be identified for native OpenMC and DagMC geometries." + ] + }, { "cell_type": "markdown", "metadata": {}, From d8f9bfdc30983e7f6e988b15561c8ba54904a57d Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 19 Jul 2019 15:10:50 -0500 Subject: [PATCH 06/16] Using map::at() for safety. --- src/dagmc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dagmc.cpp b/src/dagmc.cpp index a4ca81fbe..06d93fc47 100644 --- a/src/dagmc.cpp +++ b/src/dagmc.cpp @@ -140,7 +140,7 @@ void legacy_assign_material(const std::string& mat_string, DAGCell* c) } if (settings::verbosity >= 10) { - Material* m = model::materials[model::material_map[c->material_[0]]].get(); + const auto& m = model::materials[model::material_map.at(c->material_[0])]; std::stringstream msg; msg << "DAGMC material " << mat_string << " was assigned"; if (mat_found_by_name) { @@ -297,7 +297,7 @@ void load_dagmc_geometry() if (c->material_[0] == MATERIAL_VOID) { continue; } - auto& mat = model::materials[model::material_map[c->material_[0]]]; + const auto& mat = model::materials[model::material_map.at(c->material_[0])]; if (model::DAG->has_prop(vol_handle, "temp")) { rval = model::DAG->prop_value(vol_handle, "temp", temp_value); MB_CHK_ERR_CONT(rval); From 98804f957ac01a7a51953baf183e5d336a8ea1c0 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 19 Jul 2019 15:11:12 -0500 Subject: [PATCH 07/16] Parametrizing cell temperature test. --- tests/unit_tests/dagmc/conftest.py | 1 - tests/unit_tests/dagmc/test.py | 19 ++++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/unit_tests/dagmc/conftest.py b/tests/unit_tests/dagmc/conftest.py index 621532231..9f012b5fa 100644 --- a/tests/unit_tests/dagmc/conftest.py +++ b/tests/unit_tests/dagmc/conftest.py @@ -3,7 +3,6 @@ import pytest @pytest.fixture(scope='module', autouse=True) def setup_dagmc_unit_test(request): - # Change to test directory olddir = request.fspath.dirpath().chdir() try: diff --git a/tests/unit_tests/dagmc/test.py b/tests/unit_tests/dagmc/test.py index 2302ab7e4..7698119fc 100644 --- a/tests/unit_tests/dagmc/test.py +++ b/tests/unit_tests/dagmc/test.py @@ -13,7 +13,8 @@ pytestmark = pytest.mark.skipif( not openmc.capi._dagmc_enabled(), reason="DAGMC CAD geometry is not enabled.") -def test_dagmc_temperatures(): +@pytest.fixture(scope="module", autouse=True) +def dagmc_model(): model = openmc.model.Model() # settings @@ -54,16 +55,9 @@ def test_dagmc_temperatures(): model.export_to_xml() - # check cell temps as well here openmc.capi.init() - expected_temps = { 1 : 320.0, # assigned by material - 2 : 300.0, # assigned in dagmc file - 3 : 293.6 } # assigned by default - - for cell_id, temp in expected_temps.items(): - capi_cell = openmc.capi.cells[cell_id] - assert np.isclose(capi_cell.get_temperature(), temp) + yield openmc.capi.finalize() @@ -73,3 +67,10 @@ def test_dagmc_temperatures(): for f in input_files: if os.path.exists(f): os.remove(f) + +@pytest.mark.parametrize("cell_id,exp_temp", ((1, 320.0), # assigned by material + (2, 300.0), # assigned in dagmc file + (3, 293.6))) # assigned by default +def test_dagmc_temperatures(cell_id, exp_temp): + cell = openmc.capi.cells[cell_id] + assert np.isclose(cell.get_temperature(), exp_temp) From 51efa1ef7117486c9d6e4f0345ce4b65516c21fd Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 19 Jul 2019 16:13:27 -0500 Subject: [PATCH 08/16] Some self review. --- src/dagmc.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dagmc.cpp b/src/dagmc.cpp index 06d93fc47..829af002c 100644 --- a/src/dagmc.cpp +++ b/src/dagmc.cpp @@ -61,7 +61,6 @@ void check_dagmc_file() { bool get_uwuw_materials_xml(std::string& s) { check_dagmc_file(); - UWUW uwuw((settings::path_input + DAGMC_FILENAME).c_str()); std::stringstream ss; @@ -295,8 +294,10 @@ void load_dagmc_geometry() // check for temperature assignment std::string temp_value; + // no temperature if void if (c->material_[0] == MATERIAL_VOID) { continue; } + // assign cell temperature const auto& mat = model::materials[model::material_map.at(c->material_[0])]; if (model::DAG->has_prop(vol_handle, "temp")) { rval = model::DAG->prop_value(vol_handle, "temp", temp_value); From 8af82192524ab99281c9a591c83f2f8ea0b21d7c Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 19 Jul 2019 16:14:57 -0500 Subject: [PATCH 09/16] Small change to wording in cad notebook. --- examples/jupyter/cad-based-geometry.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/jupyter/cad-based-geometry.ipynb b/examples/jupyter/cad-based-geometry.ipynb index 5c449cd00..b13c010cb 100644 --- a/examples/jupyter/cad-based-geometry.ipynb +++ b/examples/jupyter/cad-based-geometry.ipynb @@ -240,7 +240,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "**Note:** Applying tally filters in DagMC models requires prior knowledge of the model. Here, we know that the fuel cell's volume ID in the CAD sofware is 1. To identify cells without use of CAD software, we recommend loading them into the [OpenMC plotter](https://github.com/openmc/plotter) where cell, material, and volume IDs can be identified for native OpenMC and DagMC geometries." + "**Note:** Applying tally filters in DagMC models requires prior knowledge of the model. Here, we know that the fuel cell's volume ID in the CAD sofware is 1. To identify cells without use of CAD software, load them into the [OpenMC plotter](https://github.com/openmc/plotter) where cell, material, and volume IDs can be identified for native both OpenMC and DagMC geometries." ] }, { From 20d5f4d9c0b7dc59d51cd0e2763ed2b411de5f8a Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 23 Jul 2019 03:04:12 -0500 Subject: [PATCH 10/16] Updating DAGMC filename. --- src/dagmc.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/dagmc.cpp b/src/dagmc.cpp index 829af002c..8618470b2 100644 --- a/src/dagmc.cpp +++ b/src/dagmc.cpp @@ -37,7 +37,7 @@ const bool dagmc_enabled = false; namespace openmc { -const std::string DAGMC_FILENAME = settings::path_input + "dagmc.h5m"; +const std::string DAGMC_FILENAME = "dagmc.h5m"; namespace simulation { @@ -54,8 +54,9 @@ moab::DagMC* DAG; void check_dagmc_file() { - if (!file_exists(DAGMC_FILENAME)) { - fatal_error("Geometry DAGMC file '" + DAGMC_FILENAME + "' does not exist!"); + std::string filename = settings::path_input + DAGMC_FILENAME; + if (!file_exists(filename)) { + fatal_error("Geometry DAGMC file '" + filename + "' does not exist!"); } } @@ -153,14 +154,18 @@ void legacy_assign_material(const std::string& mat_string, DAGCell* c) void load_dagmc_geometry() { + check_dagmc_file(); + if (!model::DAG) { model::DAG = new moab::DagMC(); } + + std::string filename = settings::path_input + DAGMC_FILENAME; // --- Materials --- // create uwuw instance - UWUW uwuw(DAGMC_FILENAME.c_str()); + UWUW uwuw(filename.c_str()); // check for uwuw material definitions bool using_uwuw = !uwuw.material_library.empty(); @@ -173,7 +178,7 @@ void load_dagmc_geometry() int32_t dagmc_univ_id = 0; // universe is always 0 for DAGMC runs // load the DAGMC geometry - moab::ErrorCode rval = model::DAG->load_file(DAGMC_FILENAME.c_str()); + moab::ErrorCode rval = model::DAG->load_file(filename.c_str()); MB_CHK_ERR_CONT(rval); // initialize acceleration data structures From 2287d3f418d63e920d5e0a555aeeff8750675e40 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 23 Jul 2019 03:04:34 -0500 Subject: [PATCH 11/16] Update src/dagmc.cpp Co-Authored-By: Paul Romano --- src/dagmc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dagmc.cpp b/src/dagmc.cpp index 8618470b2..3f7c170ce 100644 --- a/src/dagmc.cpp +++ b/src/dagmc.cpp @@ -300,7 +300,7 @@ void load_dagmc_geometry() std::string temp_value; // no temperature if void - if (c->material_[0] == MATERIAL_VOID) { continue; } + if (c->material_[0] == MATERIAL_VOID) continue; // assign cell temperature const auto& mat = model::materials[model::material_map.at(c->material_[0])]; From cc3c51627258399aa98883061035d4c29850e014 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 23 Jul 2019 03:10:26 -0500 Subject: [PATCH 12/16] Moving local fixture into test file. --- tests/unit_tests/dagmc/conftest.py | 11 ----------- tests/unit_tests/dagmc/test.py | 11 ++++++++++- 2 files changed, 10 insertions(+), 12 deletions(-) delete mode 100644 tests/unit_tests/dagmc/conftest.py diff --git a/tests/unit_tests/dagmc/conftest.py b/tests/unit_tests/dagmc/conftest.py deleted file mode 100644 index 9f012b5fa..000000000 --- a/tests/unit_tests/dagmc/conftest.py +++ /dev/null @@ -1,11 +0,0 @@ - -import pytest - -@pytest.fixture(scope='module', autouse=True) -def setup_dagmc_unit_test(request): - # Change to test directory - olddir = request.fspath.dirpath().chdir() - try: - yield - finally: - olddir.chdir() diff --git a/tests/unit_tests/dagmc/test.py b/tests/unit_tests/dagmc/test.py index 7698119fc..a07bb0297 100644 --- a/tests/unit_tests/dagmc/test.py +++ b/tests/unit_tests/dagmc/test.py @@ -13,8 +13,17 @@ pytestmark = pytest.mark.skipif( not openmc.capi._dagmc_enabled(), reason="DAGMC CAD geometry is not enabled.") +@pytest.fixture(scope='module', autouse=True) +def setup_dagmc_unit_test(request): + # Change to test directory + olddir = request.fspath.dirpath().chdir() + try: + yield + finally: + olddir.chdir() + @pytest.fixture(scope="module", autouse=True) -def dagmc_model(): +def dagmc_model(setup_dagmc_unit_test): model = openmc.model.Model() # settings From dc4646c241d1f136c2abd200d6cda83a422bc89b Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 23 Jul 2019 03:35:40 -0500 Subject: [PATCH 13/16] Using existing function to run dagmc tests in a temporary directory. --- tests/unit_tests/dagmc/test.py | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/tests/unit_tests/dagmc/test.py b/tests/unit_tests/dagmc/test.py index a07bb0297..fb5bb584e 100644 --- a/tests/unit_tests/dagmc/test.py +++ b/tests/unit_tests/dagmc/test.py @@ -1,5 +1,5 @@ import glob -import os +import shutil import numpy as np import pytest @@ -13,17 +13,9 @@ pytestmark = pytest.mark.skipif( not openmc.capi._dagmc_enabled(), reason="DAGMC CAD geometry is not enabled.") -@pytest.fixture(scope='module', autouse=True) -def setup_dagmc_unit_test(request): - # Change to test directory - olddir = request.fspath.dirpath().chdir() - try: - yield - finally: - olddir.chdir() - @pytest.fixture(scope="module", autouse=True) -def dagmc_model(setup_dagmc_unit_test): +def dagmc_model(request): + model = openmc.model.Model() # settings @@ -62,21 +54,17 @@ def dagmc_model(setup_dagmc_unit_test): mats = openmc.Materials([u235, water]) model.materials = mats - model.export_to_xml() - - openmc.capi.init() - - yield + # location of dagmc file in test directory + dagmc_file = request.fspath.dirpath() + "/dagmc.h5m" + # move to a temporary directory + with cdtemp(): + shutil.copyfile(dagmc_file, "./dagmc.h5m") + model.export_to_xml() + openmc.capi.init() + yield openmc.capi.finalize() - # cleanup - input_files = glob.glob("*.xml") - input_files += glob.glob("*.h5") - for f in input_files: - if os.path.exists(f): - os.remove(f) - @pytest.mark.parametrize("cell_id,exp_temp", ((1, 320.0), # assigned by material (2, 300.0), # assigned in dagmc file (3, 293.6))) # assigned by default From 173bea707280f6f110b616db9148b324e6d52320 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 23 Jul 2019 11:43:42 -0500 Subject: [PATCH 14/16] No longer run MOAB tests in CI. --- tools/ci/travis-install-dagmc.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/ci/travis-install-dagmc.sh b/tools/ci/travis-install-dagmc.sh index ca3e8b3c7..1797e9dba 100755 --- a/tools/ci/travis-install-dagmc.sh +++ b/tools/ci/travis-install-dagmc.sh @@ -20,7 +20,7 @@ mkdir MOAB && cd MOAB git clone -b $MOAB_BRANCH $MOAB_REPO mkdir build && cd build cmake ../moab -DENABLE_HDF5=ON -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=$MOAB_INSTALL_DIR -make -j && make -j test install +make -j && make -j install cmake ../moab -DBUILD_SHARED_LIBS=OFF make -j install rm -rf $HOME/MOAB/moab From 67575b336920f1ad2153f0bb04b3a07d557fe305 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 23 Jul 2019 14:25:33 -0500 Subject: [PATCH 15/16] Limit number of jobs in MOAB build. --- tools/ci/travis-install-dagmc.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/ci/travis-install-dagmc.sh b/tools/ci/travis-install-dagmc.sh index 1797e9dba..30b55dd89 100755 --- a/tools/ci/travis-install-dagmc.sh +++ b/tools/ci/travis-install-dagmc.sh @@ -20,7 +20,7 @@ mkdir MOAB && cd MOAB git clone -b $MOAB_BRANCH $MOAB_REPO mkdir build && cd build cmake ../moab -DENABLE_HDF5=ON -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=$MOAB_INSTALL_DIR -make -j && make -j install +make -j2 && make -j install cmake ../moab -DBUILD_SHARED_LIBS=OFF make -j install rm -rf $HOME/MOAB/moab From 90db1ab38a3328a3b47d4d6f21161f7987bc396d Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 24 Jul 2019 13:17:13 -0500 Subject: [PATCH 16/16] Removing limit on number of jobs for MOAB CI build. Updates to dagmc unit test file. --- tests/unit_tests/dagmc/test.py | 13 +++++++------ tools/ci/travis-install-dagmc.sh | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/unit_tests/dagmc/test.py b/tests/unit_tests/dagmc/test.py index fb5bb584e..bfe054dd8 100644 --- a/tests/unit_tests/dagmc/test.py +++ b/tests/unit_tests/dagmc/test.py @@ -1,4 +1,3 @@ -import glob import shutil import numpy as np @@ -13,6 +12,7 @@ pytestmark = pytest.mark.skipif( not openmc.capi._dagmc_enabled(), reason="DAGMC CAD geometry is not enabled.") + @pytest.fixture(scope="module", autouse=True) def dagmc_model(request): @@ -24,8 +24,8 @@ def dagmc_model(request): model.settings.particles = 100 model.settings.temperature = {'tolerance': 50.0} model.settings.verbosity = 1 - source_box = openmc.stats.Box([-4, -4, -4], - [ 4, 4, 4]) + source_box = openmc.stats.Box([ -4, -4, -4 ], + [ 4, 4, 4 ]) source = openmc.Source(space=source_box) model.settings.source = source @@ -65,9 +65,10 @@ def dagmc_model(request): openmc.capi.finalize() -@pytest.mark.parametrize("cell_id,exp_temp", ((1, 320.0), # assigned by material - (2, 300.0), # assigned in dagmc file - (3, 293.6))) # assigned by default + +@pytest.mark.parametrize("cell_id,exp_temp", ((1, 320.0), # assigned by material + (2, 300.0), # assigned in dagmc file + (3, 293.6))) # assigned by default def test_dagmc_temperatures(cell_id, exp_temp): cell = openmc.capi.cells[cell_id] assert np.isclose(cell.get_temperature(), exp_temp) diff --git a/tools/ci/travis-install-dagmc.sh b/tools/ci/travis-install-dagmc.sh index 30b55dd89..1797e9dba 100755 --- a/tools/ci/travis-install-dagmc.sh +++ b/tools/ci/travis-install-dagmc.sh @@ -20,7 +20,7 @@ mkdir MOAB && cd MOAB git clone -b $MOAB_BRANCH $MOAB_REPO mkdir build && cd build cmake ../moab -DENABLE_HDF5=ON -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=$MOAB_INSTALL_DIR -make -j2 && make -j install +make -j && make -j install cmake ../moab -DBUILD_SHARED_LIBS=OFF make -j install rm -rf $HOME/MOAB/moab