mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 21:55:41 -04:00
Move openmc_reset and openmc_hard_reset to C++
This commit is contained in:
parent
5c46d4336e
commit
6a3911c248
5 changed files with 79 additions and 147 deletions
|
|
@ -49,6 +49,12 @@ extern Timer time_tallies;
|
|||
extern Timer time_total;
|
||||
extern Timer time_transport;
|
||||
|
||||
//==============================================================================
|
||||
// Non-member functions
|
||||
//==============================================================================
|
||||
|
||||
void reset_timers();
|
||||
|
||||
} // namespace openmc
|
||||
|
||||
#endif // OPENMC_TIMER_H
|
||||
|
|
|
|||
150
src/api.F90
150
src/api.F90
|
|
@ -2,96 +2,17 @@ module openmc_api
|
|||
|
||||
use, intrinsic :: ISO_C_BINDING
|
||||
|
||||
use bank_header, only: openmc_source_bank
|
||||
use constants, only: K_BOLTZMANN
|
||||
use eigenvalue, only: openmc_get_keff
|
||||
use constants
|
||||
use error
|
||||
use geometry, only: find_cell
|
||||
use geometry_header
|
||||
use hdf5_interface
|
||||
use material_header
|
||||
use math
|
||||
use message_passing
|
||||
use nuclide_header
|
||||
use particle_header
|
||||
use plot, only: openmc_plot_geometry
|
||||
use random_lcg, only: openmc_get_seed, openmc_set_seed
|
||||
use settings
|
||||
use simulation_header
|
||||
use state_point, only: openmc_statepoint_write
|
||||
use tally_header
|
||||
use tally_filter_header
|
||||
use tally_filter
|
||||
use tally, only: openmc_tally_allocate
|
||||
use simulation
|
||||
use string, only: to_f_string
|
||||
use timer_header
|
||||
use volume_calc, only: openmc_calculate_volumes
|
||||
|
||||
use string, only: to_str
|
||||
#ifdef DAGMC
|
||||
use dagmc_header, only: free_memory_dagmc
|
||||
#endif
|
||||
|
||||
implicit none
|
||||
|
||||
private
|
||||
public :: openmc_calculate_volumes
|
||||
public :: openmc_cell_filter_get_bins
|
||||
public :: openmc_cell_get_id
|
||||
public :: openmc_cell_set_id
|
||||
public :: openmc_energy_filter_get_bins
|
||||
public :: openmc_energy_filter_set_bins
|
||||
public :: openmc_extend_filters
|
||||
public :: openmc_extend_cells
|
||||
public :: openmc_extend_materials
|
||||
public :: openmc_extend_tallies
|
||||
public :: openmc_filter_get_id
|
||||
public :: openmc_filter_get_type
|
||||
public :: openmc_filter_set_id
|
||||
public :: openmc_filter_set_type
|
||||
public :: openmc_find_cell
|
||||
public :: openmc_get_cell_index
|
||||
public :: openmc_get_keff
|
||||
public :: openmc_get_filter_index
|
||||
public :: openmc_get_filter_next_id
|
||||
public :: openmc_get_material_index
|
||||
public :: openmc_get_nuclide_index
|
||||
public :: openmc_get_seed
|
||||
public :: openmc_get_tally_index
|
||||
public :: openmc_get_tally_next_id
|
||||
public :: openmc_global_tallies
|
||||
public :: openmc_hard_reset
|
||||
public :: openmc_load_nuclide
|
||||
public :: openmc_material_add_nuclide
|
||||
public :: openmc_material_get_id
|
||||
public :: openmc_material_get_densities
|
||||
public :: openmc_material_set_density
|
||||
public :: openmc_material_set_densities
|
||||
public :: openmc_material_set_id
|
||||
public :: openmc_material_filter_get_bins
|
||||
public :: openmc_material_filter_set_bins
|
||||
public :: openmc_mesh_filter_set_mesh
|
||||
public :: openmc_meshsurface_filter_set_mesh
|
||||
public :: openmc_nuclide_name
|
||||
public :: openmc_plot_geometry
|
||||
public :: openmc_reset
|
||||
public :: openmc_set_seed
|
||||
public :: openmc_source_bank
|
||||
public :: openmc_tally_allocate
|
||||
public :: openmc_tally_get_estimator
|
||||
public :: openmc_tally_get_id
|
||||
public :: openmc_tally_get_filters
|
||||
public :: openmc_tally_get_n_realizations
|
||||
public :: openmc_tally_get_nuclides
|
||||
public :: openmc_tally_get_scores
|
||||
public :: openmc_tally_get_type
|
||||
public :: openmc_tally_results
|
||||
public :: openmc_tally_set_estimator
|
||||
public :: openmc_tally_set_filters
|
||||
public :: openmc_tally_set_id
|
||||
public :: openmc_tally_set_nuclides
|
||||
public :: openmc_tally_set_scores
|
||||
public :: openmc_tally_set_type
|
||||
|
||||
contains
|
||||
|
||||
|
|
@ -130,67 +51,6 @@ contains
|
|||
|
||||
end function openmc_find_cell
|
||||
|
||||
!===============================================================================
|
||||
! OPENMC_HARD_RESET reset tallies and timers as well as the pseudorandom
|
||||
! generator state
|
||||
!===============================================================================
|
||||
|
||||
function openmc_hard_reset() result(err) bind(C)
|
||||
integer(C_INT) :: err
|
||||
|
||||
! Reset all tallies and timers
|
||||
err = openmc_reset()
|
||||
|
||||
! Reset total generations and keff guess
|
||||
keff = ONE
|
||||
total_gen = 0
|
||||
|
||||
! Reset the random number generator state
|
||||
call openmc_set_seed(DEFAULT_SEED)
|
||||
end function openmc_hard_reset
|
||||
|
||||
!===============================================================================
|
||||
! OPENMC_RESET resets tallies and timers
|
||||
!===============================================================================
|
||||
|
||||
function openmc_reset() result(err) bind(C)
|
||||
integer(C_INT) :: err
|
||||
|
||||
integer :: i
|
||||
interface
|
||||
subroutine k_sum_reset() bind(C)
|
||||
end subroutine
|
||||
end interface
|
||||
|
||||
if (allocated(tallies)) then
|
||||
do i = 1, size(tallies)
|
||||
associate (t => tallies(i) % obj)
|
||||
t % n_realizations = 0
|
||||
if (allocated(t % results)) then
|
||||
t % results(:, :, :) = ZERO
|
||||
end if
|
||||
end associate
|
||||
end do
|
||||
end if
|
||||
|
||||
! Reset global tallies
|
||||
n_realizations = 0
|
||||
if (allocated(global_tallies)) then
|
||||
global_tallies(:, :) = ZERO
|
||||
end if
|
||||
k_col_abs = ZERO
|
||||
k_col_tra = ZERO
|
||||
k_abs_tra = ZERO
|
||||
call k_sum_reset()
|
||||
|
||||
! Reset timers
|
||||
call time_read_xs % reset()
|
||||
call time_unionize % reset()
|
||||
call reset_timers()
|
||||
|
||||
err = 0
|
||||
end function openmc_reset
|
||||
|
||||
!===============================================================================
|
||||
! FREE_MEMORY deallocates and clears all global allocatable arrays in the
|
||||
! program
|
||||
|
|
@ -198,13 +58,19 @@ contains
|
|||
|
||||
subroutine free_memory() bind(C)
|
||||
|
||||
use bank_header
|
||||
use cmfd_header
|
||||
use geometry_header
|
||||
use material_header
|
||||
use photon_header
|
||||
use plot_header
|
||||
use sab_header
|
||||
use settings
|
||||
use simulation_header
|
||||
use surface_header
|
||||
use tally_derivative_header
|
||||
use tally_filter_header
|
||||
use tally_header
|
||||
use trigger_header
|
||||
use volume_header
|
||||
|
||||
|
|
|
|||
|
|
@ -2,20 +2,24 @@
|
|||
|
||||
#include "openmc/capi.h"
|
||||
#include "openmc/constants.h"
|
||||
#include "openmc/eigenvalue.h"
|
||||
#include "openmc/geometry.h"
|
||||
#include "openmc/message_passing.h"
|
||||
#include "openmc/nuclide.h"
|
||||
#include "openmc/random_lcg.h"
|
||||
#include "openmc/settings.h"
|
||||
#include "openmc/simulation.h"
|
||||
#include "openmc/timer.h"
|
||||
#include "openmc/tallies/tally.h"
|
||||
|
||||
using namespace openmc;
|
||||
|
||||
// Functions defined in Fortran
|
||||
extern "C" void free_memory();
|
||||
extern "C" void reset_timers_f();
|
||||
|
||||
int openmc_finalize()
|
||||
{
|
||||
using namespace openmc;
|
||||
|
||||
// Clear results
|
||||
openmc_reset();
|
||||
|
||||
|
|
@ -87,3 +91,49 @@ int openmc_finalize()
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int openmc_reset()
|
||||
{
|
||||
for (int i = 1; i <= n_tallies; ++i) {
|
||||
openmc_tally_reset(i);
|
||||
}
|
||||
|
||||
// Reset global tallies (can't really use global_tallies() right now because
|
||||
// it doesn't have any information about whether the underlying buffer was
|
||||
// allocated)
|
||||
n_realizations = 0;
|
||||
double* buffer = nullptr;
|
||||
openmc_global_tallies(&buffer);
|
||||
if (buffer) {
|
||||
for (int i = 0; i < 3*N_GLOBAL_TALLIES*3; ++i) {
|
||||
buffer[i] = 0.0;
|
||||
}
|
||||
}
|
||||
// auto gt = global_tallies();
|
||||
// std::fill(gt.begin(), gt.end(), 0.0);
|
||||
|
||||
simulation::k_col_abs = 0.0;
|
||||
simulation::k_col_tra = 0.0;
|
||||
simulation::k_abs_tra = 0.0;
|
||||
k_sum = {0.0, 0.0};
|
||||
|
||||
// Reset timers
|
||||
reset_timers();
|
||||
reset_timers_f();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int openmc_hard_reset()
|
||||
{
|
||||
// Reset all tallies and timers
|
||||
openmc_reset();
|
||||
|
||||
// Reset total generations and keff guess
|
||||
simulation::keff = 1.0;
|
||||
simulation::total_gen = 0;
|
||||
|
||||
// Reset the random number generator state
|
||||
openmc_set_seed(DEFAULT_SEED);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,7 +64,11 @@ extern "C" double time_tallies_elapsed() { return time_tallies.elapsed(); }
|
|||
extern "C" double time_total_elapsed() { return time_total.elapsed(); }
|
||||
extern "C" double time_transport_elapsed() { return time_transport.elapsed(); }
|
||||
|
||||
extern "C" void reset_timers()
|
||||
//==============================================================================
|
||||
// Non-member functions
|
||||
//==============================================================================
|
||||
|
||||
void reset_timers()
|
||||
{
|
||||
time_active.reset();
|
||||
time_bank.reset();
|
||||
|
|
|
|||
|
|
@ -73,8 +73,6 @@ module timer_header
|
|||
! TIMING VARIABLES
|
||||
|
||||
type(Timer) :: time_read_xs ! timer for reading cross sections
|
||||
type(Timer) :: time_unionize ! timer for material xs-energy grid union
|
||||
type(Timer) :: time_finalize ! timer for finalization
|
||||
|
||||
contains
|
||||
|
||||
|
|
@ -139,4 +137,12 @@ contains
|
|||
self % elapsed = ZERO
|
||||
end subroutine timer_reset
|
||||
|
||||
!===============================================================================
|
||||
! RESET_TIMERS resets timers on the Fortran side
|
||||
!===============================================================================
|
||||
|
||||
subroutine reset_timers_f() bind(C)
|
||||
call time_read_xs % reset()
|
||||
end subroutine
|
||||
|
||||
end module timer_header
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue