mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 06:05:58 -04:00
Reset global variables on openmc_finalize
This commit is contained in:
parent
7bc61c1f41
commit
09d1dd7f3c
5 changed files with 107 additions and 60 deletions
|
|
@ -320,7 +320,6 @@ set(LIBOPENMC_FORTRAN_SRC
|
|||
src/endf_header.F90
|
||||
src/energy_distribution.F90
|
||||
src/error.F90
|
||||
src/finalize.F90
|
||||
src/geometry.F90
|
||||
src/geometry_header.F90
|
||||
src/global.F90
|
||||
|
|
|
|||
104
src/api.F90
104
src/api.F90
|
|
@ -2,19 +2,20 @@ module openmc_api
|
|||
|
||||
use, intrinsic :: ISO_C_BINDING
|
||||
|
||||
use hdf5, only: HID_T
|
||||
use hdf5, only: HID_T, h5tclose_f, h5close_f
|
||||
|
||||
use constants, only: K_BOLTZMANN
|
||||
use eigenvalue, only: k_sum, openmc_get_keff
|
||||
use finalize, only: openmc_finalize
|
||||
use geometry, only: find_cell
|
||||
use geometry_header, only: root_universe
|
||||
use global
|
||||
use hdf5_interface
|
||||
use message_passing, only: master
|
||||
use message_passing
|
||||
use initialize, only: openmc_init
|
||||
use input_xml, only: assign_0K_elastic_scattering, check_data_version
|
||||
use particle_header, only: Particle
|
||||
use plot, only: openmc_plot_geometry
|
||||
use random_lcg, only: seed
|
||||
use simulation, only: openmc_run
|
||||
use volume_calc, only: openmc_calculate_volumes
|
||||
|
||||
|
|
@ -70,6 +71,89 @@ contains
|
|||
end if
|
||||
end function openmc_cell_set_temperature
|
||||
|
||||
!===============================================================================
|
||||
! OPENMC_FINALIZE frees up memory by deallocating arrays and resetting global
|
||||
! variables
|
||||
!===============================================================================
|
||||
|
||||
subroutine openmc_finalize() bind(C)
|
||||
|
||||
integer :: hdf5_err
|
||||
|
||||
! Clear results
|
||||
call openmc_reset()
|
||||
|
||||
! Reset global variables
|
||||
assume_separate = .false.
|
||||
check_overlaps = .false.
|
||||
confidence_intervals = .false.
|
||||
create_fission_neutrons = .true.
|
||||
current_batch = 0
|
||||
current_gen = 0
|
||||
energy_cutoff = ZERO
|
||||
energy_max_neutron = INFINITY
|
||||
energy_min_neutron = ZERO
|
||||
entropy_on = .false.
|
||||
gen_per_batch = 1
|
||||
i_user_tallies = -1
|
||||
i_cmfd_tallies = -1
|
||||
keff = ONE
|
||||
legendre_to_tabular = .true.
|
||||
legendre_to_tabular_points = 33
|
||||
n_batch_interval = 1
|
||||
n_particles = 0
|
||||
n_source_points = 0
|
||||
n_state_points = 0
|
||||
output_summary = .true.
|
||||
output_tallies = .true.
|
||||
particle_restart_run = .false.
|
||||
pred_batches = .false.
|
||||
reduce_tallies = .true.
|
||||
res_scat_on = .false.
|
||||
res_scat_method = RES_SCAT_ARES
|
||||
res_scat_energy_min = 0.01_8
|
||||
res_scat_energy_max = 1000.0_8
|
||||
restart_run = .false.
|
||||
root_universe = -1
|
||||
run_CE = .true.
|
||||
run_mode = NONE
|
||||
satisfy_triggers = .false.
|
||||
seed = 1_8
|
||||
source_latest = .false.
|
||||
source_separate = .false.
|
||||
source_write = .true.
|
||||
survival_biasing = .false.
|
||||
temperature_default = 293.6_8
|
||||
temperature_method = TEMPERATURE_NEAREST
|
||||
temperature_multipole = .false.
|
||||
temperature_range = [ZERO, ZERO]
|
||||
temperature_tolerance = 10.0_8
|
||||
total_gen = 0
|
||||
trigger_on = .false.
|
||||
ufs = .false.
|
||||
urr_ptables_on = .true.
|
||||
verbosity = 7
|
||||
weight_cutoff = 0.25_8
|
||||
weight_survive = ONE
|
||||
write_all_tracks = .false.
|
||||
write_initial_source = .false.
|
||||
|
||||
! Deallocate arrays
|
||||
call free_memory()
|
||||
|
||||
! Release compound datatypes
|
||||
call h5tclose_f(hdf5_bank_t, hdf5_err)
|
||||
|
||||
! Close FORTRAN interface.
|
||||
call h5close_f(hdf5_err)
|
||||
|
||||
#ifdef MPI
|
||||
! Free all MPI types
|
||||
call MPI_TYPE_FREE(MPI_BANK, mpi_err)
|
||||
#endif
|
||||
|
||||
end subroutine openmc_finalize
|
||||
|
||||
!===============================================================================
|
||||
! OPENMC_FIND determines the ID or a cell or material at a given point in space
|
||||
!===============================================================================
|
||||
|
|
@ -291,12 +375,14 @@ contains
|
|||
subroutine openmc_reset() bind(C)
|
||||
integer :: i
|
||||
|
||||
do i = 1, size(tallies)
|
||||
tallies(i) % n_realizations = 0
|
||||
if (allocated(tallies(i) % results)) then
|
||||
tallies(i) % results(:, :, :) = ZERO
|
||||
end if
|
||||
end do
|
||||
if (allocated(tallies)) then
|
||||
do i = 1, size(tallies)
|
||||
tallies(i) % n_realizations = 0
|
||||
if (allocated(tallies(i) % results)) then
|
||||
tallies(i) % results(:, :, :) = ZERO
|
||||
end if
|
||||
end do
|
||||
end if
|
||||
|
||||
! Reset global tallies
|
||||
n_realizations = 0
|
||||
|
|
|
|||
|
|
@ -1,40 +0,0 @@
|
|||
module finalize
|
||||
|
||||
use, intrinsic :: ISO_C_BINDING
|
||||
|
||||
use hdf5, only: h5tclose_f, h5close_f
|
||||
|
||||
use global
|
||||
use hdf5_interface, only: hdf5_bank_t
|
||||
use message_passing
|
||||
|
||||
implicit none
|
||||
|
||||
contains
|
||||
|
||||
!===============================================================================
|
||||
! FINALIZE_RUN does all post-simulation tasks such as calculating tally
|
||||
! statistics and writing out tallies
|
||||
!===============================================================================
|
||||
|
||||
subroutine openmc_finalize() bind(C)
|
||||
|
||||
integer :: hdf5_err
|
||||
|
||||
! Deallocate arrays
|
||||
call free_memory()
|
||||
|
||||
! Release compound datatypes
|
||||
call h5tclose_f(hdf5_bank_t, hdf5_err)
|
||||
|
||||
! Close FORTRAN interface.
|
||||
call h5close_f(hdf5_err)
|
||||
|
||||
#ifdef MPI
|
||||
! Free all MPI types
|
||||
call MPI_TYPE_FREE(MPI_BANK, mpi_err)
|
||||
#endif
|
||||
|
||||
end subroutine openmc_finalize
|
||||
|
||||
end module finalize
|
||||
|
|
@ -140,7 +140,7 @@ module global
|
|||
integer :: max_order
|
||||
|
||||
! Whether or not to convert Legendres to tabulars
|
||||
logical :: legendre_to_tabular = .True.
|
||||
logical :: legendre_to_tabular = .true.
|
||||
|
||||
! Number of points to use in the Legendre to tabular conversion
|
||||
integer :: legendre_to_tabular_points = 33
|
||||
|
|
@ -466,6 +466,7 @@ contains
|
|||
if (allocated(surfaces)) deallocate(surfaces)
|
||||
if (allocated(materials)) deallocate(materials)
|
||||
if (allocated(plots)) deallocate(plots)
|
||||
if (allocated(volume_calcs)) deallocate(volume_calcs)
|
||||
|
||||
! Deallocate geometry debugging information
|
||||
if (allocated(overlap_check_cnt)) deallocate(overlap_check_cnt)
|
||||
|
|
@ -478,6 +479,7 @@ contains
|
|||
end do
|
||||
deallocate(nuclides)
|
||||
end if
|
||||
if (allocated(libraries)) deallocate(libraries)
|
||||
|
||||
if (allocated(res_scat_nuclides)) deallocate(res_scat_nuclides)
|
||||
|
||||
|
|
@ -486,7 +488,6 @@ contains
|
|||
if (allocated(macro_xs)) deallocate(macro_xs)
|
||||
|
||||
if (allocated(sab_tables)) deallocate(sab_tables)
|
||||
if (allocated(micro_xs)) deallocate(micro_xs)
|
||||
|
||||
! Deallocate external source
|
||||
if (allocated(external_source)) deallocate(external_source)
|
||||
|
|
@ -501,21 +502,24 @@ contains
|
|||
if (allocated(meshes)) deallocate(meshes)
|
||||
if (allocated(filters)) deallocate(filters)
|
||||
if (allocated(tallies)) deallocate(tallies)
|
||||
if (allocated(filter_matches)) deallocate(filter_matches)
|
||||
|
||||
! Deallocate fission and source bank and entropy
|
||||
!$omp parallel
|
||||
if (allocated(fission_bank)) deallocate(fission_bank)
|
||||
if (allocated(filter_matches)) deallocate(filter_matches)
|
||||
if (allocated(tally_derivs)) deallocate(tally_derivs)
|
||||
!$omp end parallel
|
||||
#ifdef _OPENMP
|
||||
if (allocated(master_fission_bank)) deallocate(master_fission_bank)
|
||||
#endif
|
||||
if (allocated(source_bank)) deallocate(source_bank)
|
||||
if (allocated(entropy_p)) deallocate(entropy_p)
|
||||
|
||||
! Deallocate array of work indices
|
||||
if (allocated(work_index)) deallocate(work_index)
|
||||
|
||||
if (allocated(energy_bins)) deallocate(energy_bins)
|
||||
if (allocated(energy_bin_avg)) deallocate(energy_bin_avg)
|
||||
|
||||
! Deallocate CMFD
|
||||
call deallocate_cmfd(cmfd)
|
||||
|
||||
|
|
@ -541,6 +545,7 @@ contains
|
|||
call plot_dict % clear()
|
||||
call nuclide_dict % clear()
|
||||
call sab_dict % clear()
|
||||
call library_dict % clear()
|
||||
|
||||
! Clear statepoint and sourcepoint batch set
|
||||
call statepoint_batch % clear()
|
||||
|
|
|
|||
|
|
@ -1,14 +1,11 @@
|
|||
program main
|
||||
|
||||
use constants
|
||||
use finalize, only: openmc_finalize
|
||||
use global
|
||||
use initialize, only: openmc_init
|
||||
use message_passing
|
||||
use particle_restart, only: run_particle_restart
|
||||
use plot, only: openmc_plot_geometry
|
||||
use simulation, only: openmc_run
|
||||
use volume_calc, only: openmc_calculate_volumes
|
||||
use openmc_api, only: openmc_init, openmc_finalize, openmc_run, &
|
||||
openmc_plot_geometry, openmc_calculate_volumes
|
||||
use particle_restart, only: run_particle_restart
|
||||
|
||||
implicit none
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue