diff --git a/src/DEPENDENCIES b/src/DEPENDENCIES
index 7934825cc6..514be1d029 100644
--- a/src/DEPENDENCIES
+++ b/src/DEPENDENCIES
@@ -69,6 +69,7 @@ fixed_source.o: output.o
fixed_source.o: physics.o
fixed_source.o: random_lcg.o
fixed_source.o: source.o
+fixed_source.o: state_point.o
fixed_source.o: string.o
fixed_source.o: tally.o
fixed_source.o: timing.o
@@ -233,7 +234,7 @@ source.o: random_lcg.o
source.o: string.o
state_point.o: global.o
-state_point.o: source.o
+state_point.o: output.o
state_point.o: string.o
string.o: constants.o
diff --git a/src/OBJECTS b/src/OBJECTS
index 0daf0f16fe..7b369d3dba 100644
--- a/src/OBJECTS
+++ b/src/OBJECTS
@@ -36,6 +36,7 @@ random_lcg.o \
search.o \
source.o \
source_header.o \
+state_point.o \
string.o \
tally.o \
tally_header.o \
diff --git a/src/criticality.F90 b/src/criticality.F90
index 23402b7aa9..686c36153c 100644
--- a/src/criticality.F90
+++ b/src/criticality.F90
@@ -6,7 +6,7 @@ module criticality
count_source_for_ufs
use output, only: write_message, header, print_columns
use physics, only: transport
- use source, only: get_source_particle
+ use source, only: get_source_particle, write_source_binary
use state_point, only: create_state_point
use string, only: to_str
use tally, only: synchronize_tallies
@@ -120,6 +120,8 @@ contains
subroutine finalize_batch()
+ integer :: i ! loop index for state point batches
+
! Collect tallies
if (tallies_on) then
call timer_start(time_ic_tallies)
@@ -133,6 +135,19 @@ contains
! Collect results and statistics
call calculate_keff()
+ ! Write out state point if it's been specified for this batch
+ do i = 1, n_state_points
+ if (current_batch == statepoint_batch(i)) then
+ ! Create state point file
+ if (master) call create_state_point()
+
+ ! Create binary source file
+ call write_source_binary('source.' // &
+ trim(to_str(current_batch)) // '.binary')
+ exit
+ end if
+ end do
+
! Turn tallies on once inactive cycles are complete
if (current_batch == n_inactive) then
tallies_on = .true.
@@ -140,8 +155,6 @@ contains
call timer_start(time_active)
end if
- ! TODO: Write out state point if requested
-
end subroutine finalize_batch
end module criticality
diff --git a/src/fixed_source.F90 b/src/fixed_source.F90
index faeec35c51..a650aa384c 100644
--- a/src/fixed_source.F90
+++ b/src/fixed_source.F90
@@ -1,15 +1,16 @@
module fixed_source
- use constants, only: ZERO
+ use constants, only: ZERO
use global
- use output, only: write_message, header
- use physics, only: transport
- use random_lcg, only: set_particle_seed
- use source, only: initialize_particle, sample_external_source, &
- copy_source_attributes
- use string, only: to_str
- use tally, only: synchronize_tallies
- use timing, only: timer_start, timer_stop
+ use output, only: write_message, header
+ use physics, only: transport
+ use random_lcg, only: set_particle_seed
+ use source, only: initialize_particle, sample_external_source, &
+ copy_source_attributes
+ use state_point, only: create_state_point
+ use string, only: to_str
+ use tally, only: synchronize_tallies
+ use timing, only: timer_start, timer_stop
type(Bank), pointer :: source_site => null()
@@ -97,10 +98,23 @@ contains
subroutine finalize_batch()
+ integer :: i ! loop index for state point batches
+
+ ! Collect and accumulate tallies
call timer_start(time_ic_tallies)
call synchronize_tallies()
call timer_stop(time_ic_tallies)
+ ! Write out state point if it's been specified for this batch
+ if (master) then
+ do i = 1, n_state_points
+ if (current_batch == statepoint_batch(i)) then
+ call create_state_point()
+ exit
+ end if
+ end do
+ end if
+
end subroutine finalize_batch
!===============================================================================
diff --git a/src/global.F90 b/src/global.F90
index ae2f726342..c2bf819bba 100644
--- a/src/global.F90
+++ b/src/global.F90
@@ -243,6 +243,10 @@ module global
integer :: trace_gen
integer(8) :: trace_particle
+ ! Information about state points to be written
+ integer :: n_state_points = 0
+ integer, allocatable :: statepoint_batch(:)
+
contains
!===============================================================================
diff --git a/src/input_xml.F90 b/src/input_xml.F90
index 72a64a7758..8be4080fdd 100644
--- a/src/input_xml.F90
+++ b/src/input_xml.F90
@@ -144,6 +144,7 @@ contains
! Copy batch information
n_batches = fixed_source_ % batches
n_active = fixed_source_ % batches
+ n_inactive = 0
gen_per_batch = 1
end if
@@ -457,6 +458,16 @@ contains
! Check if the user has specified to write binary source file
if (trim(write_source_) == 'on') write_source = .true.
+ ! Check if the user has specified to write state points
+ if (associated(write_state_point_)) then
+ ! Determine number of batches at which to store state points
+ n_state_points = size(write_state_point_)
+
+ ! Allocate and store batches
+ allocate(statepoint_batch(n_state_points))
+ statepoint_batch = write_state_point_
+ end if
+
! Check if the user has specified to not reduce tallies at the end of every
! batch
if (trim(no_reduce_) == 'on') reduce_tallies = .false.
diff --git a/src/source.F90 b/src/source.F90
index 418172c053..f5e68d93d8 100644
--- a/src/source.F90
+++ b/src/source.F90
@@ -239,17 +239,28 @@ contains
! can be used as a starting source in a new simulation
!===============================================================================
- subroutine write_source_binary()
-
+ subroutine write_source_binary(path)
+
+ character(*), optional :: path
+
#ifdef MPI
integer :: fh ! file handle
integer(MPI_OFFSET_KIND) :: offset ! offset in memory (0=beginning of file)
+#endif
+ ! Determine path to binary source file to write
+ if (present(path)) then
+ path_source = path
+ else
+ path_source = 'source.binary'
+ end if
+
+#ifdef MPI
! ==========================================================================
! PARALLEL I/O USING MPI-2 ROUTINES
! Open binary source file for reading
- call MPI_FILE_OPEN(MPI_COMM_WORLD, 'source.binary', MPI_MODE_CREATE + &
+ call MPI_FILE_OPEN(MPI_COMM_WORLD, path_source, MPI_MODE_CREATE + &
MPI_MODE_WRONLY, MPI_INFO_NULL, fh, mpi_err)
if (master) then
@@ -273,7 +284,7 @@ contains
! SERIAL I/O USING FORTRAN INTRINSIC ROUTINES
! Open binary source file for writing
- open(UNIT=UNIT_SOURCE, FILE='source.binary', STATUS='replace', &
+ open(UNIT=UNIT_SOURCE, FILE=path_source, STATUS='replace', &
ACCESS='stream')
! Write the number of particles
diff --git a/src/state_point.F90 b/src/state_point.F90
index 343bad419b..88ec1e409f 100644
--- a/src/state_point.F90
+++ b/src/state_point.F90
@@ -1,7 +1,7 @@
module state_point
use global
- use source, only: write_source_binary
+ use output, only: write_message
use string, only: to_str
implicit none
@@ -20,6 +20,10 @@ contains
! Set filename for binary state point
path_state_point = 'restart.' // trim(to_str(current_batch)) // '.binary'
+ ! Write message
+ message = "Creating state point " // trim(path_state_point) // "..."
+ call write_message()
+
! Open binary state point file for writing
open(UNIT=UNIT_STATE, FILE=path_state_point, STATUS='replace', &
ACCESS='stream')
@@ -37,26 +41,28 @@ contains
! Write out current batch number
write(UNIT_STATE) current_batch
+ ! Write out random number seed
+ write(UNIT_STATE) seed
+
! Write out global tallies sum and sum_sq
write(UNIT_STATE) N_GLOBAL_TALLIES
write(UNIT_STATE) global_tallies(:) % sum
write(UNIT_STATE) global_tallies(:) % sum_sq
! Write out tallies sum and sum_sq
- write(UNIT_STATE) n_tallies
- do i = 1, n_tallies
- write(UNIT_STATE) size(tallies(i) % scores, 1)
- write(UNIT_STATE) size(tallies(i) % scores, 2)
- write(UNIT_STATE) tallies(i) % scores(:,:) % sum
- write(UNIT_STATE) tallies(i) % scores(:,:) % sum_sq
- end do
+ if (tallies_on) then
+ write(UNIT_STATE) n_tallies
+ do i = 1, n_tallies
+ write(UNIT_STATE) size(tallies(i) % scores, 1)
+ write(UNIT_STATE) size(tallies(i) % scores, 2)
+ write(UNIT_STATE) tallies(i) % scores(:,:) % sum
+ write(UNIT_STATE) tallies(i) % scores(:,:) % sum_sq
+ end do
+ end if
! Close binary state point file
close(UNIT_STATE)
- ! For a criticality simulation, write the source file
- if (run_mode == MODE_CRITICALITY) call write_source_binary()
-
end subroutine create_state_point
end module state_point
diff --git a/src/xml-fortran/templates/settings_t.xml b/src/xml-fortran/templates/settings_t.xml
index 2d97a9494f..cc7a2ac839 100644
--- a/src/xml-fortran/templates/settings_t.xml
+++ b/src/xml-fortran/templates/settings_t.xml
@@ -50,5 +50,6 @@
+