From 854c86aa429d8c99612cec8ada56896fa3ada60a Mon Sep 17 00:00:00 2001 From: Bryan Herman Date: Fri, 31 Jan 2014 10:35:23 -0500 Subject: [PATCH 01/11] a custom source can now be read in from file --- src/source.F90 | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/source.F90 b/src/source.F90 index 231a23cc5..4ec358776 100644 --- a/src/source.F90 +++ b/src/source.F90 @@ -1,16 +1,17 @@ module source - use bank_header, only: Bank + use bank_header, only: Bank use constants - use error, only: fatal_error - use geometry, only: find_cell - use geometry_header, only: BASE_UNIVERSE + use error, only: fatal_error + use geometry, only: find_cell + use geometry_header, only: BASE_UNIVERSE use global - use math, only: maxwell_spectrum, watt_spectrum - use output, only: write_message - use particle_header, only: Particle - use random_lcg, only: prn, set_particle_seed - use string, only: to_str + use math, only: maxwell_spectrum, watt_spectrum + use output, only: write_message + use output_interface, only: BinaryOutput + use particle_header, only: Particle + use random_lcg, only: prn, set_particle_seed + use string, only: to_str #ifdef MPI use mpi @@ -28,8 +29,9 @@ contains integer(8) :: i ! loop index over bank sites integer(8) :: id ! particle id - + integer(8) :: itmp ! temporary integer type(Bank), pointer :: src => null() ! source bank site + type(BinaryOutput) :: sp ! statepoint/source binary file message = "Initializing source particles..." call write_message(6) @@ -38,8 +40,17 @@ contains ! Read the source from a binary file instead of sampling from some ! assumed source distribution - message = 'This feature is currently disabled and will be added back in.' - call fatal_error() + ! Open the binary file + call sp % file_open(path_source, 'r', serial = .false.) + + ! Read the file type + call sp % read_data(itmp, "filetype") + + ! Read in the source bank + call sp % read_source_bank() + + ! Close file + call sp % file_close() else ! Generation source sites from specified distribution in user input From cbe6560ba1d6e85d47f35a5645dfa0fac928ec8d Mon Sep 17 00:00:00 2001 From: Bryan Herman Date: Fri, 31 Jan 2014 11:34:07 -0500 Subject: [PATCH 02/11] message written when reading in source --- src/source.F90 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/source.F90 b/src/source.F90 index 4ec358776..85ef87d65 100644 --- a/src/source.F90 +++ b/src/source.F90 @@ -40,6 +40,9 @@ contains ! Read the source from a binary file instead of sampling from some ! assumed source distribution + message = 'Reading source file from ' // trim(path_source) // '...' + call write_message(6) + ! Open the binary file call sp % file_open(path_source, 'r', serial = .false.) From 1c8eb1920db91a590f1cc533ed8cfa5ec41b41dc Mon Sep 17 00:00:00 2001 From: Bryan Herman Date: Sat, 22 Feb 2014 15:14:26 -0500 Subject: [PATCH 03/11] fixed integer type for filetype during read source --- src/source.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/source.F90 b/src/source.F90 index 85ef87d65..8e83b2ee9 100644 --- a/src/source.F90 +++ b/src/source.F90 @@ -29,7 +29,7 @@ contains integer(8) :: i ! loop index over bank sites integer(8) :: id ! particle id - integer(8) :: itmp ! temporary integer + integer(4) :: itmp ! temporary integer type(Bank), pointer :: src => null() ! source bank site type(BinaryOutput) :: sp ! statepoint/source binary file From f247f0c7cd0f5cb7fb22ef98598fea9f9090d50e Mon Sep 17 00:00:00 2001 From: Bryan Herman Date: Sat, 22 Feb 2014 17:26:31 -0500 Subject: [PATCH 04/11] added test for read source --- tests/test_source_file/geometry.xml | 8 ++ tests/test_source_file/materials.xml | 9 ++ tests/test_source_file/results.py | 25 +++++ tests/test_source_file/results_true.dat | 2 + tests/test_source_file/settings.xml | 19 ++++ tests/test_source_file/test_source_file.py | 103 +++++++++++++++++++++ 6 files changed, 166 insertions(+) create mode 100644 tests/test_source_file/geometry.xml create mode 100644 tests/test_source_file/materials.xml create mode 100644 tests/test_source_file/results.py create mode 100644 tests/test_source_file/results_true.dat create mode 100644 tests/test_source_file/settings.xml create mode 100644 tests/test_source_file/test_source_file.py diff --git a/tests/test_source_file/geometry.xml b/tests/test_source_file/geometry.xml new file mode 100644 index 000000000..612e46132 --- /dev/null +++ b/tests/test_source_file/geometry.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/tests/test_source_file/materials.xml b/tests/test_source_file/materials.xml new file mode 100644 index 000000000..1f85510e0 --- /dev/null +++ b/tests/test_source_file/materials.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/tests/test_source_file/results.py b/tests/test_source_file/results.py new file mode 100644 index 000000000..8ff10971c --- /dev/null +++ b/tests/test_source_file/results.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python + +import sys + +# import statepoint +sys.path.append('../../src/utils') +import statepoint + +# read in statepoint file +if len(sys.argv) > 1: + sp = statepoint.StatePoint(sys.argv[1]) +else: + sp = statepoint.StatePoint('statepoint.10.binary') +sp.read_results() + +# set up output string +outstr = '' + +# write out k-combined +outstr += 'k-combined:\n' +outstr += "{0:12.6E} {1:12.6E}\n".format(sp.k_combined[0], sp.k_combined[1]) + +# write results to file +with open('results_test.dat','w') as fh: + fh.write(outstr) diff --git a/tests/test_source_file/results_true.dat b/tests/test_source_file/results_true.dat new file mode 100644 index 000000000..ae37050f7 --- /dev/null +++ b/tests/test_source_file/results_true.dat @@ -0,0 +1,2 @@ +k-combined: +2.977307E-01 2.848670E-03 diff --git a/tests/test_source_file/settings.xml b/tests/test_source_file/settings.xml new file mode 100644 index 000000000..98abc5acf --- /dev/null +++ b/tests/test_source_file/settings.xml @@ -0,0 +1,19 @@ + + + + + + + + 10 + 5 + 1000 + + + + + -4 -4 -4 4 4 4 + + + + diff --git a/tests/test_source_file/test_source_file.py b/tests/test_source_file/test_source_file.py new file mode 100644 index 000000000..ede988be5 --- /dev/null +++ b/tests/test_source_file/test_source_file.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python + +import os +from subprocess import Popen, STDOUT, PIPE, call +import filecmp +#from nose_mpi import NoseMPI +import glob + +pwd = os.path.dirname(__file__) + +settings1=""" + + + + + + + 10 + 5 + 1000 + + + + + -4 -4 -4 4 4 4 + + + + +""" + +settings2 = """ + + + + 10 + 5 + 1000 + + + + source.10.{0} + + + +""" + +def setup(): + os.putenv('PWD', pwd) + os.chdir(pwd) + +def test_run1(): + openmc_path = pwd + '/../../src/openmc' +# if int(NoseMPI.mpi_np) > 0: + if False: + proc = Popen([NoseMPI.mpi_exec, '-np', NoseMPI.mpi_np, openmc_path], + stderr=STDOUT, stdout=PIPE) + else: + proc = Popen([openmc_path], stderr=STDOUT, stdout=PIPE) + print(proc.communicate()[0]) + returncode = proc.returncode + assert returncode == 0 + +def test_statepoint_exists(): + statepoint = glob.glob(pwd + '/statepoint.10.*') + assert len(statepoint) == 1 + assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5') + source = glob.glob(pwd + '/source.10.*') + assert len(statepoint) == 1 + assert source[0].endswith('binary') or source[0].endswith('h5') + +def test_run2(): + openmc_path = pwd + '/../../src/openmc' + source = glob.glob(pwd + '/source.10.*') + with open('settings.xml','w') as fh: + fh.write(settings2.format(source[0].split('.')[2])) +# if int(NoseMPI.mpi_np) > 0: + if False: + proc = Popen([NoseMPI.mpi_exec, '-np', NoseMPI.mpi_np, openmc_path], + stderr=STDOUT, stdout=PIPE) + else: + proc = Popen([openmc_path], stderr=STDOUT, stdout=PIPE) + print(proc.communicate()[0]) + returncode = proc.returncode + assert returncode == 0 + +def test_results(): + statepoint = glob.glob(pwd + '/statepoint.10.*') + call(['python', 'results.py', statepoint[0]]) + compare = filecmp.cmp('results_test.dat', 'results_true.dat') + if not compare: + os.rename('results_test.dat', 'results_error.dat') + assert compare + +def teardown(): + with open('settings.xml','w') as fh: + fh.write(settings1) + output = glob.glob(pwd + '/statepoint.10.*') + output += glob.glob(pwd + '/source.10.*') + output.append(pwd + '/results_test.dat') + for f in output: + if os.path.exists(f): + os.remove(f) From dcc40c0b7d14f7034dba13719d490223c4c0300c Mon Sep 17 00:00:00 2001 From: Bryan Herman Date: Sat, 22 Feb 2014 17:33:13 -0500 Subject: [PATCH 05/11] updated documentation of read source from file --- docs/source/usersguide/input.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/source/usersguide/input.rst b/docs/source/usersguide/input.rst index 362197439..6aac10613 100644 --- a/docs/source/usersguide/input.rst +++ b/docs/source/usersguide/input.rst @@ -264,7 +264,9 @@ attributes/sub-elements: :file: If this attribute is given, it indicates that the source is to be read from - a binary source file whose path is given by the value of this element + a binary source file whose path is given by the value of this element. Note, + the number of source sites needs to be the same as the number of particles + simulated in a fission source generation. *Default*: None From 17793dfdcfdbbe97ecc2320876898b425c622782 Mon Sep 17 00:00:00 2001 From: Bryan Herman Date: Wed, 5 Mar 2014 17:42:45 -0500 Subject: [PATCH 06/11] check filetype before reading in source --- src/source.F90 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/source.F90 b/src/source.F90 index 8e83b2ee9..2d3f74ec9 100644 --- a/src/source.F90 +++ b/src/source.F90 @@ -49,6 +49,12 @@ contains ! Read the file type call sp % read_data(itmp, "filetype") + ! Check to make sure this is a source file + if (itmp /= FILETYPE_SOURCE) then + message = "Specified starting source file not a source file type." + call fatal_error() + end if + ! Read in the source bank call sp % read_source_bank() From 0ea86d60d0bfe44dae47597d26dc5e95db139419 Mon Sep 17 00:00:00 2001 From: Bryan Herman Date: Wed, 5 Mar 2014 17:44:39 -0500 Subject: [PATCH 07/11] converted source_separate to new separate tag --- tests/test_source_file/settings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_source_file/settings.xml b/tests/test_source_file/settings.xml index 98abc5acf..17d4ee2e2 100644 --- a/tests/test_source_file/settings.xml +++ b/tests/test_source_file/settings.xml @@ -2,7 +2,7 @@ - + 10 From 83ac6bc92530c8abb6d57fc8ec4492261505b9be Mon Sep 17 00:00:00 2001 From: Bryan Herman Date: Wed, 5 Mar 2014 17:54:25 -0500 Subject: [PATCH 08/11] noseMPI uncommented --- tests/test_source_file/test_source_file.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_source_file/test_source_file.py b/tests/test_source_file/test_source_file.py index ede988be5..a4b2a4e2d 100644 --- a/tests/test_source_file/test_source_file.py +++ b/tests/test_source_file/test_source_file.py @@ -3,7 +3,7 @@ import os from subprocess import Popen, STDOUT, PIPE, call import filecmp -#from nose_mpi import NoseMPI +from nose_mpi import NoseMPI import glob pwd = os.path.dirname(__file__) From f357e370bc951717088fddd992891334baf524a9 Mon Sep 17 00:00:00 2001 From: Bryan Herman Date: Wed, 5 Mar 2014 17:55:44 -0500 Subject: [PATCH 09/11] uncommented mpi capability --- tests/test_source_file/test_source_file.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_source_file/test_source_file.py b/tests/test_source_file/test_source_file.py index a4b2a4e2d..9752d89b4 100644 --- a/tests/test_source_file/test_source_file.py +++ b/tests/test_source_file/test_source_file.py @@ -51,8 +51,7 @@ def setup(): def test_run1(): openmc_path = pwd + '/../../src/openmc' -# if int(NoseMPI.mpi_np) > 0: - if False: + if int(NoseMPI.mpi_np) > 0: proc = Popen([NoseMPI.mpi_exec, '-np', NoseMPI.mpi_np, openmc_path], stderr=STDOUT, stdout=PIPE) else: From 604abf205c9c0b4602813e09abe18cadb29c7bf3 Mon Sep 17 00:00:00 2001 From: Bryan Herman Date: Wed, 5 Mar 2014 17:56:01 -0500 Subject: [PATCH 10/11] uncommented mpi capability in run 2 --- tests/test_source_file/test_source_file.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_source_file/test_source_file.py b/tests/test_source_file/test_source_file.py index 9752d89b4..a1b4986e5 100644 --- a/tests/test_source_file/test_source_file.py +++ b/tests/test_source_file/test_source_file.py @@ -73,8 +73,7 @@ def test_run2(): source = glob.glob(pwd + '/source.10.*') with open('settings.xml','w') as fh: fh.write(settings2.format(source[0].split('.')[2])) -# if int(NoseMPI.mpi_np) > 0: - if False: + if int(NoseMPI.mpi_np) > 0: proc = Popen([NoseMPI.mpi_exec, '-np', NoseMPI.mpi_np, openmc_path], stderr=STDOUT, stdout=PIPE) else: From 7def6a881a1d2ab6d152f8c1cc241184db0da22f Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Thu, 6 Mar 2014 17:02:04 -0500 Subject: [PATCH 11/11] Change source_separate to separate in test_source_file.py. --- tests/test_source_file/test_source_file.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_source_file/test_source_file.py b/tests/test_source_file/test_source_file.py index a1b4986e5..85a33c031 100644 --- a/tests/test_source_file/test_source_file.py +++ b/tests/test_source_file/test_source_file.py @@ -12,7 +12,7 @@ settings1=""" - + 10