From 349c2a804bb43239f9806653442fa58ed7267247 Mon Sep 17 00:00:00 2001 From: Shikhar Kumar Date: Thu, 20 Sep 2018 14:00:32 -0400 Subject: [PATCH] Add CMFD helper functions to access entropy_on, is_master, current_batch, implement vector_write --- openmc/capi/core.py | 20 ++++++++++++++++++++ openmc/capi/settings.py | 4 +++- src/cmfd_data.F90 | 2 +- src/cmfd_solver.F90 | 11 ++++++++--- src/tallies/tally_header.F90 | 2 ++ src/vector_header.F90 | 17 ++++++++++++++++- 6 files changed, 50 insertions(+), 6 deletions(-) diff --git a/openmc/capi/core.py b/openmc/capi/core.py index 53c3c32bd6..7e4d29afc3 100644 --- a/openmc/capi/core.py +++ b/openmc/capi/core.py @@ -62,6 +62,16 @@ def calculate_volumes(): _dll.openmc_calculate_volumes() +def current_batch(): + """Return the current batch of the simulation. + Returns + ------- + int + Current batch of the simulation + """ + return c_int.in_dll(_dll, 'openmc_current_batch').value + + def finalize(): """Finalize simulation and free memory""" _dll.openmc_finalize() @@ -214,6 +224,16 @@ def keff(): return (mean, std_dev) +def master(): + """Return whether processor is master processor or not. + Returns + ------- + bool + Whether is master processor or not + """ + return c_bool.in_dll(_dll, 'openmc_master').value + + def next_batch(): """Run next batch. diff --git a/openmc/capi/settings.py b/openmc/capi/settings.py index 1063d6463e..af6dd7d7a2 100644 --- a/openmc/capi/settings.py +++ b/openmc/capi/settings.py @@ -1,4 +1,5 @@ -from ctypes import c_int, c_int32, c_int64, c_double, c_char_p, POINTER +from ctypes import (c_int, c_int32, c_int64, c_double, c_char_p, c_bool, + POINTER) from . import _dll from .core import _DLLGlobal @@ -17,6 +18,7 @@ _dll.openmc_get_seed.restype = c_int64 class _Settings(object): # Attributes that are accessed through a descriptor batches = _DLLGlobal(c_int32, 'n_batches') + entropy_on = _DLLGlobal(c_bool, 'entropy_on') generations_per_batch = _DLLGlobal(c_int32, 'gen_per_batch') inactive = _DLLGlobal(c_int32, 'n_inactive') particles = _DLLGlobal(c_int64, 'n_particles') diff --git a/src/cmfd_data.F90 b/src/cmfd_data.F90 index ec07a4d04c..32a85cabfd 100644 --- a/src/cmfd_data.F90 +++ b/src/cmfd_data.F90 @@ -254,7 +254,7 @@ contains ! Set the energy bin if needed if (energy_filters) then - filter_matches(i_filter_ein) % bins % data(1) = ng - h + 1 + filter_matches(i_filter_ein) % bins % data(1) = 12*(ng - h) + 1 end if score_index = 0 diff --git a/src/cmfd_solver.F90 b/src/cmfd_solver.F90 index 99d482480a..01404d9b0e 100644 --- a/src/cmfd_solver.F90 +++ b/src/cmfd_solver.F90 @@ -146,8 +146,13 @@ contains call loss % assemble() call prod % assemble() if (cmfd_write_matrices) then - call loss % write('loss.dat') - call prod % write('prod.dat') + if (adjoint) then + call loss % write('adj_loss.dat') + call prod % write('adj_prod.dat') + else + call loss % write('loss.dat') + call prod % write('prod.dat') + end if end if ! Set norms to 0 @@ -740,7 +745,7 @@ contains else filename = 'fluxvec.dat' end if - ! TODO: call phi_n % write(filename) + call phi_n % write(filename) end if end subroutine extract_results diff --git a/src/tallies/tally_header.F90 b/src/tallies/tally_header.F90 index 367214a930..db84056812 100644 --- a/src/tallies/tally_header.F90 +++ b/src/tallies/tally_header.F90 @@ -280,6 +280,7 @@ contains end subroutine tally_allocate_results + function tally_set_filters(this, filter_indices) result(err) class(TallyObject), intent(inout) :: this integer(C_INT32_T), intent(in) :: filter_indices(:) @@ -1025,6 +1026,7 @@ contains end if end function openmc_tally_set_scores + function openmc_tally_set_type(index, type) result(err) bind(C) ! Update the type of a tally that is already allocated integer(C_INT32_T), value, intent(in) :: index diff --git a/src/vector_header.F90 b/src/vector_header.F90 index 1ada0fba74..dadaaa48ca 100644 --- a/src/vector_header.F90 +++ b/src/vector_header.F90 @@ -14,7 +14,7 @@ module vector_header procedure :: destroy => vector_destroy procedure :: add_value => vector_add_value procedure :: copy => vector_copy - ! TODO: procedure :: write => vector_write + procedure :: write => vector_write end type Vector contains @@ -88,4 +88,19 @@ contains end subroutine vector_copy +!=============================================================================== +! VECTOR_WRITE writes a vector to file +!=============================================================================== + subroutine vector_write(self, filename) + class(Vector), target, intent(inout) :: self ! vector instance + character(*), intent(in) :: filename ! filename to output to + integer :: unit_ + integer :: i + open(newunit=unit_, file=filename) + do i = 1, self % n + write(unit_,*) i, self % data(i) + end do + close(unit_) + end subroutine vector_write + end module vector_header