mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-29 06:35:48 -04:00
Get rid of n_active global, allow a few settings to be controlled from
openmc.capi
This commit is contained in:
parent
c60e4084af
commit
7f66b4694c
5 changed files with 77 additions and 11 deletions
|
|
@ -37,3 +37,4 @@ from .material import *
|
|||
from .cell import *
|
||||
from .filter import *
|
||||
from .tally import *
|
||||
from .settings import settings
|
||||
|
|
|
|||
65
openmc/capi/settings.py
Normal file
65
openmc/capi/settings.py
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
from ctypes import c_int, c_int32, c_int64, c_double, c_char_p, POINTER
|
||||
|
||||
from . import _dll
|
||||
from .error import _error_handler
|
||||
|
||||
_RUN_MODES = {1: 'fixed source',
|
||||
2: 'eigenvalue',
|
||||
3: 'plot',
|
||||
4: 'particle restart',
|
||||
5: 'volume'}
|
||||
|
||||
|
||||
class _Settings(object):
|
||||
@property
|
||||
def batches(self):
|
||||
return c_int32.in_dll(_dll, 'n_batches').value
|
||||
|
||||
@batches.setter
|
||||
def batches(self, n):
|
||||
_dll.openmc_set_batches(n)
|
||||
|
||||
@property
|
||||
def generations_per_batch(self):
|
||||
return c_int32.in_dll(_dll, 'gen_per_batch').value
|
||||
|
||||
@generations_per_batch.setter
|
||||
def generations_per_batch(self, n):
|
||||
_dll.openmc_set_generations_per_batch(n)
|
||||
|
||||
@property
|
||||
def inactive(self):
|
||||
return c_int32.in_dll(_dll, 'n_inactive').value
|
||||
|
||||
@inactive.setter
|
||||
def inactive(self, n):
|
||||
_dll.openmc_set_inactive_batches(n)
|
||||
|
||||
@property
|
||||
def particles(self):
|
||||
return c_int64.in_dll(_dll, 'n_particles').value
|
||||
|
||||
@particles.setter
|
||||
def particles(self, n):
|
||||
_dll.openmc_set_particles(n)
|
||||
|
||||
@property
|
||||
def run_mode(self):
|
||||
i = c_int.in_dll(_dll, 'run_mode').value
|
||||
try:
|
||||
return _RUN_MODES[i]
|
||||
except KeyError:
|
||||
return None
|
||||
|
||||
@run_mode.setter
|
||||
def run_mode(self, mode):
|
||||
current_idx = c_int.in_dll(_dll, 'run_mode')
|
||||
for idx, mode_value in _RUN_MODES.items():
|
||||
if mode_value == mode:
|
||||
current_idx.value = idx
|
||||
break
|
||||
else:
|
||||
raise ValueError('Invalid run mode: {}'.format(mode))
|
||||
|
||||
|
||||
settings = _Settings()
|
||||
|
|
@ -322,7 +322,7 @@ contains
|
|||
call get_run_parameters(node_mode)
|
||||
|
||||
! Check number of active batches, inactive batches, and particles
|
||||
if (n_active <= 0) then
|
||||
if (n_batches <= n_inactive) then
|
||||
call fatal_error("Number of active batches must be greater than zero.")
|
||||
elseif (n_inactive < 0) then
|
||||
call fatal_error("Number of inactive batches must be non-negative.")
|
||||
|
|
@ -891,9 +891,6 @@ contains
|
|||
end if
|
||||
end if
|
||||
|
||||
! Determine number of active batches
|
||||
n_active = n_batches - n_inactive
|
||||
|
||||
end subroutine get_run_parameters
|
||||
|
||||
!===============================================================================
|
||||
|
|
|
|||
|
|
@ -532,6 +532,7 @@ contains
|
|||
|
||||
subroutine print_runtime()
|
||||
|
||||
integer :: n_active
|
||||
real(8) :: speed_inactive ! # of neutrons/second in inactive batches
|
||||
real(8) :: speed_active ! # of neutrons/second in active batches
|
||||
character(15) :: string
|
||||
|
|
@ -564,6 +565,7 @@ contains
|
|||
write(ou,100) "Total time elapsed", time_total % elapsed
|
||||
|
||||
! Calculate particle rate in active/inactive batches
|
||||
n_active = n_batches - n_inactive
|
||||
if (restart_run) then
|
||||
if (restart_batch < n_inactive) then
|
||||
speed_inactive = real(n_particles * (n_inactive - restart_batch) * &
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
module settings
|
||||
|
||||
use, intrinsic :: ISO_C_BINDING
|
||||
|
||||
use constants
|
||||
use set_header, only: SetInt
|
||||
use source_header
|
||||
|
||||
implicit none
|
||||
|
||||
! ============================================================================
|
||||
! ============================================================================
|
||||
! ENERGY TREATMENT RELATED VARIABLES
|
||||
logical :: run_CE = .true. ! Run in CE mode?
|
||||
|
||||
|
|
@ -46,11 +48,10 @@ module settings
|
|||
! ============================================================================
|
||||
! SIMULATION VARIABLES
|
||||
|
||||
integer(8) :: n_particles = 0 ! # of particles per generation
|
||||
integer :: n_batches ! # of batches
|
||||
integer :: n_inactive ! # of inactive batches
|
||||
integer :: n_active ! # of active batches
|
||||
integer :: gen_per_batch = 1 ! # of generations per batch
|
||||
integer(C_INT64_T), bind(C) :: n_particles = 0 ! # of particles per generation
|
||||
integer(C_INT32_T), bind(C) :: n_batches ! # of batches
|
||||
integer(C_INT32_T), bind(C) :: n_inactive ! # of inactive batches
|
||||
integer(C_INT32_T), bind(C) :: gen_per_batch = 1 ! # of generations per batch
|
||||
|
||||
integer :: n_max_batches ! max # of batches
|
||||
integer :: n_batch_interval = 1 ! batch interval for triggers
|
||||
|
|
@ -75,7 +76,7 @@ module settings
|
|||
real(8) :: weight_survive = ONE
|
||||
|
||||
! Mode to run in (fixed source, eigenvalue, plotting, etc)
|
||||
integer :: run_mode = NONE
|
||||
integer(C_INT), bind(C) :: run_mode = NONE
|
||||
|
||||
! Restart run
|
||||
logical :: restart_run = .false.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue