From 5f571a5eafb545ac8e48668d902a391b93c8f358 Mon Sep 17 00:00:00 2001 From: liangjg Date: Tue, 5 Feb 2019 21:02:26 -0500 Subject: [PATCH 1/2] fix bug when loading nuclides using capi: invalid index updating --- src/nuclide_header.F90 | 8 +++----- tests/unit_tests/test_capi.py | 1 + 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/nuclide_header.F90 b/src/nuclide_header.F90 index 78d436bddb..4308bc487b 100644 --- a/src/nuclide_header.F90 +++ b/src/nuclide_header.F90 @@ -703,15 +703,13 @@ contains end function openmc_nuclide_name subroutine extend_nuclides() bind(C) - integer :: n type(Nuclide), allocatable :: new_nuclides(:) ! allocate extra space in nuclides array - n = n_nuclides - allocate(new_nuclides(n + 1)) - new_nuclides(1:n) = nuclides(:) + allocate(new_nuclides(n_nuclides + 1)) + new_nuclides(1:n_nuclides) = nuclides(:) call move_alloc(FROM=new_nuclides, TO=nuclides) - n = n + 1 + n_nuclides = n_nuclides + 1 end subroutine end module nuclide_header diff --git a/tests/unit_tests/test_capi.py b/tests/unit_tests/test_capi.py index f5185e23fa..420cffc4fc 100644 --- a/tests/unit_tests/test_capi.py +++ b/tests/unit_tests/test_capi.py @@ -131,6 +131,7 @@ def test_nuclide_mapping(capi_init): def test_load_nuclide(capi_init): + openmc.capi.load_nuclide('H3') openmc.capi.load_nuclide('Pu239') with pytest.raises(exc.DataError): openmc.capi.load_nuclide('Pu3') From 0459632e185cdddfeda1e59d0647a2f356c78ef5 Mon Sep 17 00:00:00 2001 From: Jingang Liang Date: Wed, 6 Feb 2019 12:59:29 -0800 Subject: [PATCH 2/2] update test_capi.py --- tests/unit_tests/test_capi.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/unit_tests/test_capi.py b/tests/unit_tests/test_capi.py index 420cffc4fc..e69d15a270 100644 --- a/tests/unit_tests/test_capi.py +++ b/tests/unit_tests/test_capi.py @@ -130,13 +130,6 @@ def test_nuclide_mapping(capi_init): assert name == nuc.name -def test_load_nuclide(capi_init): - openmc.capi.load_nuclide('H3') - openmc.capi.load_nuclide('Pu239') - with pytest.raises(exc.DataError): - openmc.capi.load_nuclide('Pu3') - - def test_settings(capi_init): settings = openmc.capi.settings assert settings.batches == 10 @@ -394,3 +387,10 @@ def test_restart(capi_init): # Compare the keff values. assert keff0 == pytest.approx(keff1) + + +def test_load_nuclide(capi_init): + openmc.capi.load_nuclide('H3') + openmc.capi.load_nuclide('Pu239') + with pytest.raises(exc.DataError): + openmc.capi.load_nuclide('Pu3')