Move cell filter get_all_bins to C++

This commit is contained in:
Sterling Harper 2018-09-19 11:37:06 -04:00
parent 1cc0271f4c
commit 0084ae613b
5 changed files with 49 additions and 12 deletions

View file

@ -4,6 +4,7 @@
#include <cstdint>
#include <vector>
#include "openmc/particle.h"
#include "openmc/xml_interface.h"
@ -43,6 +44,10 @@ class TallyFilter
{
public:
virtual void from_xml(pugi::xml_node node) = 0;
virtual void
get_all_bins(Particle* p, int estimator, TallyFilterMatch& match) const = 0;
virtual void initialize() = 0;
};

View file

@ -3,6 +3,7 @@
#include <cstdint>
#include <sstream>
#include <unordered_map>
#include <vector>
#include "openmc/cell.h"
@ -35,11 +36,27 @@ public:
}
}
//TODO: mapping
for (int i = 0; i < cells_.size(); i++) {
map_[cells_[i]] = i;
}
}
virtual void
get_all_bins(Particle* p, int estimator, TallyFilterMatch& match) const
{
for (int i = 0; i < p->n_coord; i++) {
auto search = map_.find(p->coord[i].cell);
if (search != map_.end()) {
// TODO: off-by-one
match.bins.push_back(search->second + 1);
match.weights.push_back(1);
}
}
}
protected:
std::vector<int32_t> cells_;
std::unordered_map<int32_t, int> map_;
};
} // namespace openmc

View file

@ -69,6 +69,13 @@ extern "C" {
void filter_from_xml(TallyFilter* filt, pugi::xml_node* node)
{filt->from_xml(*node);}
void
filter_get_all_bins(TallyFilter* filt, Particle* p, int estimator,
TallyFilterMatch* match)
{
filt->get_all_bins(p, estimator, *match);
}
void filter_initialize(TallyFilter* filt) {filt->initialize();}
}

View file

@ -56,17 +56,7 @@ contains
integer, intent(in) :: estimator
type(TallyFilterMatch), intent(inout) :: match
integer :: i
integer :: val
! Iterate over coordinate levels to see with cells match
do i = 1, p % n_coord
val = this % map % get(p % coord(i) % cell + 1)
if (val /= EMPTY) then
call match % bins_push_back(val)
call match % weights_push_back(ONE)
end if
end do
call this % get_all_bins_c(p , estimator, match)
end subroutine get_all_bins_cell

View file

@ -131,6 +131,7 @@ module tally_filter_header
type(C_PTR) :: ptr
contains
procedure :: from_xml_c
procedure :: get_all_bins_c
procedure :: initialize_c
end type CppTallyFilter
@ -290,6 +291,23 @@ contains
call filter_from_xml(this % ptr, node % ptr)
end subroutine from_xml_c
subroutine get_all_bins_c(this, p, estimator, match)
class(CppTallyFilter), intent(in) :: this
type(Particle), intent(in) :: p
integer, intent(in) :: estimator
type(TallyFilterMatch), intent(inout) :: match
interface
subroutine filter_get_all_bins(filt, p, estimator, match) bind(C)
import C_PTR, Particle, C_INT
type(C_PTR), value :: filt
type(Particle), intent(in) :: p
integer(C_INT), intent(in), value :: estimator
type(C_PTR), value :: match
end subroutine filter_get_all_bins
end interface
call filter_get_all_bins(this % ptr, p, estimator, match % ptr)
end subroutine get_all_bins_c
subroutine initialize_c(this)
class(CppTallyFilter), intent(inout) :: this
interface