Skip to content

Commit a4ddaf9

Browse files
committed
Move finalize_batch and write_source_point to C++
1 parent 8c64139 commit a4ddaf9

21 files changed

Lines changed: 211 additions & 223 deletions

‎include/openmc/capi.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ extern "C" {
9595
int openmc_sphharm_filter_get_cosine(int32_t index, char cosine[]);
9696
int openmc_sphharm_filter_set_order(int32_t index, int order);
9797
int openmc_sphharm_filter_set_cosine(int32_t index, const char cosine[]);
98-
int openmc_statepoint_write(const char filename[]);
98+
int openmc_statepoint_write(const char filename[], bool* write_source);
9999
int openmc_tally_allocate(int32_t index, const char* type);
100100
int openmc_tally_get_active(int32_t index, bool* active);
101101
int openmc_tally_get_estimator(int32_t index, int32_t* estimator);

‎include/openmc/container_util.h‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef OPENMC_CONTAINER_UTIL_H
2+
#define OPENMC_CONTAINER_UTIL_H
3+
4+
#include <algorithm> // for find
5+
#include <iterator> // for begin, end
6+
7+
namespace openmc {
8+
9+
template<class C, class T>
10+
inline bool contains(const C& v, const T& x)
11+
{
12+
return std::end(v) != std::find(std::begin(v), std::end(v), x);
13+
}
14+
15+
}
16+
17+
#endif // OPENMC_CONTAINER_UTIL_H

‎include/openmc/settings.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <array>
88
#include <cstdint>
99
#include <string>
10+
#include <unordered_set>
1011
#include <vector>
1112

1213
#include "pugixml.hpp"
@@ -76,6 +77,8 @@ extern "C" int res_scat_method; //!< resonance upscattering method
7677
extern "C" double res_scat_energy_min; //!< Min energy in [eV] for res. upscattering
7778
extern "C" double res_scat_energy_max; //!< Max energy in [eV] for res. upscattering
7879
extern "C" int run_mode; //!< Run mode (eigenvalue, fixed src, etc.)
80+
extern std::unordered_set<int> sourcepoint_batch; //!< Batches when source should be written
81+
extern std::unordered_set<int> statepoint_batch; //!< Batches when state should be written
7982
extern "C" int temperature_method; //!< method for choosing temperatures
8083
extern "C" double temperature_tolerance; //!< Tolerance in [K] on choosing temperatures
8184
extern "C" double temperature_default; //!< Default T in [K]

‎include/openmc/simulation.h‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ extern "C" void initialize_generation();
6666

6767
extern "C" void initialize_history(Particle* p, int64_t index_source);
6868

69+
//! Finalize a batch
70+
//!
71+
//! Handles synchronization and accumulation of tallies, calculation of Shannon
72+
//! entropy, getting single-batch estimate of keff, and turning on tallies when
73+
//! appropriate
74+
extern "C" void finalize_batch();
75+
6976
//! Finalize a fission generation
7077
extern "C" void finalize_generation();
7178

@@ -74,7 +81,6 @@ extern "C" int overall_generation();
7481

7582
#ifdef OPENMC_MPI
7683
extern "C" void broadcast_results();
77-
extern "C" void broadcast_triggers();
7884
#endif
7985

8086
} // namespace openmc

‎include/openmc/state_point.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace openmc {
1111

12+
void write_source_point(const char* filename);
1213
extern "C" void write_source_bank(hid_t group_id, Bank* source_bank);
1314
extern "C" void read_source_bank(hid_t group_id, Bank* source_bank);
1415
extern "C" void write_tally_results_nr(hid_t file_id);

‎include/openmc/timer.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ extern Timer time_bank_sendrecv;
4545
extern Timer time_finalize;
4646
extern Timer time_inactive;
4747
extern Timer time_initialize;
48+
extern Timer time_tallies;
4849
extern Timer time_total;
4950

5051
} // namespace openmc

‎src/api.F90‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@ end subroutine openmc_free_bank
132132
n_batch_interval = 1
133133
n_lost_particles = 0
134134
n_particles = -1
135-
n_source_points = 0
136-
n_state_points = 0
137135
n_tallies = 0
138136
output_summary = .true.
139137
output_tallies = .true.

‎src/cmfd_execute.F90‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ subroutine cmfd_broadcast(n, buffer) bind(C)
2929
! EXECUTE_CMFD runs the CMFD calculation
3030
!==============================================================================
3131

32-
subroutine execute_cmfd()
32+
subroutine execute_cmfd() bind(C)
3333

3434
use cmfd_data, only: set_up_cmfd
3535
use cmfd_solver, only: cmfd_solver_execute

‎src/cmfd_header.F90‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ module cmfd_header
143143
logical, public :: cmfd_run_adjoint = .false.
144144

145145
! CMFD run logicals
146-
logical, public :: cmfd_on = .false.
146+
logical(C_BOOL), public, bind(C) :: cmfd_on = .false.
147147

148148
! CMFD display info
149149
character(len=25), public :: cmfd_display = 'balance'

‎src/input_xml.F90‎

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -210,99 +210,14 @@ subroutine read_settings_xml_f(root_ptr) bind(C)
210210

211211
integer :: i
212212
integer :: n
213-
integer, allocatable :: temp_int_array(:)
214213
type(XMLNode) :: root
215-
type(XMLNode) :: node_sp
216214
type(XMLNode) :: node_res_scat
217215
type(XMLNode) :: node_vol
218216
type(XMLNode), allocatable :: node_vol_list(:)
219217

220218
! Get proper XMLNode type given pointer
221219
root % ptr = root_ptr
222220

223-
! Check if the user has specified to write state points
224-
if (check_for_node(root, "state_point")) then
225-
226-
! Get pointer to state_point node
227-
node_sp = root % child("state_point")
228-
229-
! Determine number of batches at which to store state points
230-
if (check_for_node(node_sp, "batches")) then
231-
n_state_points = node_word_count(node_sp, "batches")
232-
else
233-
n_state_points = 0
234-
end if
235-
236-
if (n_state_points > 0) then
237-
! User gave specific batches to write state points
238-
allocate(temp_int_array(n_state_points))
239-
call get_node_array(node_sp, "batches", temp_int_array)
240-
do i = 1, n_state_points
241-
call statepoint_batch % add(temp_int_array(i))
242-
end do
243-
deallocate(temp_int_array)
244-
else
245-
! If neither were specified, write state point at last batch
246-
n_state_points = 1
247-
call statepoint_batch % add(n_batches)
248-
end if
249-
else
250-
! If no <state_point> tag was present, by default write state point at
251-
! last batch only
252-
n_state_points = 1
253-
call statepoint_batch % add(n_batches)
254-
end if
255-
256-
! Check if the user has specified to write source points
257-
if (check_for_node(root, "source_point")) then
258-
259-
! Get pointer to source_point node
260-
node_sp = root % child("source_point")
261-
262-
! Determine number of batches at which to store source points
263-
if (check_for_node(node_sp, "batches")) then
264-
n_source_points = node_word_count(node_sp, "batches")
265-
else
266-
n_source_points = 0
267-
end if
268-
269-
if (n_source_points > 0) then
270-
! User gave specific batches to write source points
271-
allocate(temp_int_array(n_source_points))
272-
call get_node_array(node_sp, "batches", temp_int_array)
273-
do i = 1, n_source_points
274-
call sourcepoint_batch % add(temp_int_array(i))
275-
end do
276-
deallocate(temp_int_array)
277-
else
278-
! If neither were specified, write source points with state points
279-
n_source_points = n_state_points
280-
do i = 1, n_state_points
281-
call sourcepoint_batch % add(statepoint_batch % get_item(i))
282-
end do
283-
end if
284-
else
285-
! If no <source_point> tag was present, by default we keep source bank in
286-
! statepoint file and write it out at statepoints intervals
287-
n_source_points = n_state_points
288-
do i = 1, n_state_points
289-
call sourcepoint_batch % add(statepoint_batch % get_item(i))
290-
end do
291-
end if
292-
293-
! If source is not seperate and is to be written out in the statepoint file,
294-
! make sure that the sourcepoint batch numbers are contained in the
295-
! statepoint list
296-
if (.not. source_separate) then
297-
do i = 1, n_source_points
298-
if (.not. statepoint_batch % contains(sourcepoint_batch % &
299-
get_item(i))) then
300-
call fatal_error('Sourcepoint batches are not a subset&
301-
& of statepoint batches.')
302-
end if
303-
end do
304-
end if
305-
306221
! Resonance scattering parameters
307222
if (check_for_node(root, "resonance_scattering")) then
308223
node_res_scat = root % child("resonance_scattering")

0 commit comments

Comments
 (0)