mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 22:26:08 -04:00
Add basic C++ TallyFilterMatch class
This commit is contained in:
parent
a043699d8d
commit
c387bde956
5 changed files with 89 additions and 2 deletions
|
|
@ -417,6 +417,7 @@ add_library(libopenmc SHARED
|
|||
src/state_point.cpp
|
||||
src/string_functions.cpp
|
||||
src/surface.cpp
|
||||
src/tallies/tally_filter.cpp
|
||||
src/thermal.cpp
|
||||
src/xml_interface.cpp
|
||||
src/xsdata.cpp)
|
||||
|
|
|
|||
34
include/openmc/tallies/tally_filter.h
Normal file
34
include/openmc/tallies/tally_filter.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#ifndef OPENMC_TALLY_FILTER_H
|
||||
#define OPENMC_TALLY_FILTER_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace openmc {
|
||||
|
||||
//==============================================================================
|
||||
// Global variables
|
||||
//==============================================================================
|
||||
|
||||
extern "C" int32_t n_filters;
|
||||
|
||||
class TallyFilterMatch;
|
||||
extern std::vector<TallyFilterMatch> filter_matches;
|
||||
#pragma omp threadprivate(filter_matches)
|
||||
|
||||
//==============================================================================
|
||||
//! Stores bins and weights for filtered tally events
|
||||
//==============================================================================
|
||||
|
||||
class TallyFilterMatch
|
||||
{
|
||||
public:
|
||||
int i_bin;
|
||||
std::vector<int> bins;
|
||||
std::vector<double> weights;
|
||||
bool bins_present;
|
||||
};
|
||||
|
||||
} // namespace openmc
|
||||
#endif // OPENMC_TALLY_FILTER
|
||||
|
|
@ -36,7 +36,7 @@ module simulation
|
|||
use tally, only: accumulate_tallies, setup_active_tallies, &
|
||||
init_tally_routines
|
||||
use tally_header
|
||||
use tally_filter_header, only: filter_matches, n_filters
|
||||
use tally_filter_header, only: filter_matches, n_filters, filter_match_pointer
|
||||
use tally_derivative_header, only: tally_derivs
|
||||
use timer_header
|
||||
use trigger, only: check_triggers
|
||||
|
|
@ -420,6 +420,11 @@ contains
|
|||
|
||||
integer :: i
|
||||
|
||||
interface
|
||||
subroutine openmc_simulation_init_c() bind(C)
|
||||
end subroutine openmc_simulation_init_c
|
||||
end interface
|
||||
|
||||
err = 0
|
||||
|
||||
! Skip if simulation has already been initialized
|
||||
|
|
@ -453,6 +458,9 @@ contains
|
|||
|
||||
! Allocate array for matching filter bins
|
||||
allocate(filter_matches(n_filters))
|
||||
do i = 1, n_filters
|
||||
filter_matches(i) % ptr = filter_match_pointer(i - 1)
|
||||
end do
|
||||
!$omp end parallel
|
||||
|
||||
! Reset global variables -- this is done before loading state point (as that
|
||||
|
|
@ -493,6 +501,8 @@ contains
|
|||
end if
|
||||
end if
|
||||
|
||||
call openmc_simulation_init_c()
|
||||
|
||||
! Set flag indicating initialization is done
|
||||
simulation_initialized = .true.
|
||||
|
||||
|
|
@ -520,6 +530,11 @@ contains
|
|||
#endif
|
||||
#endif
|
||||
|
||||
interface
|
||||
subroutine openmc_simulation_finalize_c() bind(C)
|
||||
end subroutine openmc_simulation_finalize_c
|
||||
end interface
|
||||
|
||||
err = 0
|
||||
|
||||
! Skip if simulation was never run
|
||||
|
|
@ -590,6 +605,8 @@ contains
|
|||
end do
|
||||
end if
|
||||
|
||||
call openmc_simulation_finalize_c()
|
||||
|
||||
! Stop timers and show timing statistics
|
||||
call time_finalize%stop()
|
||||
call time_total%stop()
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
#include "openmc/capi.h"
|
||||
#include "openmc/tallies/tally_filter.h"
|
||||
|
||||
// OPENMC_RUN encompasses all the main logic where iterations are performed
|
||||
// over the batches, generations, and histories in a fixed source or k-eigenvalue
|
||||
// calculation.
|
||||
|
||||
int openmc_run() {
|
||||
int openmc_run()
|
||||
{
|
||||
openmc_simulation_init();
|
||||
|
||||
int err = 0;
|
||||
|
|
@ -16,3 +18,25 @@ int openmc_run() {
|
|||
openmc_simulation_finalize();
|
||||
return err;
|
||||
}
|
||||
|
||||
namespace openmc {
|
||||
|
||||
extern "C" void
|
||||
openmc_simulation_init_c()
|
||||
{
|
||||
#pragma omp parallel
|
||||
{
|
||||
filter_matches.resize(n_filters);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
openmc_simulation_finalize_c()
|
||||
{
|
||||
#pragma omp parallel
|
||||
{
|
||||
filter_matches.clear();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace openmc
|
||||
|
|
|
|||
|
|
@ -20,12 +20,23 @@ module tally_filter_header
|
|||
public :: openmc_filter_set_id
|
||||
public :: openmc_get_filter_index
|
||||
public :: openmc_get_filter_next_id
|
||||
public :: filter_match_pointer
|
||||
|
||||
interface
|
||||
function filter_match_pointer(indx) bind(C) result(ptr)
|
||||
import C_PTR, C_INT
|
||||
integer(C_INT), intent(in), value :: indx
|
||||
type(C_PTR) :: ptr
|
||||
end function filter_match_pointer
|
||||
end interface
|
||||
|
||||
!===============================================================================
|
||||
! TALLYFILTERMATCH stores every valid bin and weight for a filter
|
||||
!===============================================================================
|
||||
|
||||
type, public :: TallyFilterMatch
|
||||
type(C_PTR) :: ptr
|
||||
|
||||
! Index of the bin and weight being used in the current filter combination
|
||||
integer :: i_bin
|
||||
type(VectorInt) :: bins_
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue