mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 06:05:58 -04:00
Add TallyFilter::text_label
This commit is contained in:
parent
377e9fba3d
commit
64bd9af4ce
10 changed files with 55 additions and 2 deletions
|
|
@ -62,6 +62,7 @@ constexpr int MAX_SAMPLE {100000};
|
|||
|
||||
// Maximum number of words in a single line, length of line, and length of
|
||||
// single word
|
||||
constexpr int MAX_LINE_LEN {250};
|
||||
constexpr int MAX_WORD_LEN {150};
|
||||
|
||||
// Maximum number of external source spatial resamples to encounter before an
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#define OPENMC_TALLY_FILTER_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "openmc/hdf5_interface.h"
|
||||
|
|
@ -53,6 +54,8 @@ public:
|
|||
|
||||
virtual void to_statepoint(hid_t filter_group) const {}
|
||||
|
||||
virtual std::string text_label(int bin) const = 0;
|
||||
|
||||
virtual void initialize() {}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -67,6 +67,12 @@ public:
|
|||
write_dataset(filter_group, "bins", cell_ids);
|
||||
}
|
||||
|
||||
virtual std::string
|
||||
text_label(int bin) const override
|
||||
{
|
||||
return "Cell " + std::to_string(cells[cells_[bin-1]]->id_);
|
||||
}
|
||||
|
||||
protected:
|
||||
std::vector<int32_t> cells_;
|
||||
std::unordered_map<int32_t, int> map_;
|
||||
|
|
|
|||
|
|
@ -32,6 +32,12 @@ public:
|
|||
for (auto c : cells_) cell_ids.push_back(cells[c]->id_);
|
||||
write_dataset(filter_group, "bins", cell_ids);
|
||||
}
|
||||
|
||||
virtual std::string
|
||||
text_label(int bin) const override
|
||||
{
|
||||
return "Cell from " + std::to_string(cells[cells_[bin-1]]->id_);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace openmc
|
||||
|
|
|
|||
|
|
@ -49,6 +49,8 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
virtual std::string text_label(int bin) const {};
|
||||
|
||||
protected:
|
||||
int32_t mesh_;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -42,6 +42,8 @@ public:
|
|||
for (auto b : match.bins) match.weights.push_back(1.0);
|
||||
}
|
||||
|
||||
virtual std::string text_label(int bin) const {};
|
||||
|
||||
protected:
|
||||
int32_t mesh_;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include "openmc/constants.h" // for MAX_LINE_LEN;
|
||||
#include "openmc/tallies/tally_filter_cell.h"
|
||||
#include "openmc/tallies/tally_filter_cellfrom.h"
|
||||
#include "openmc/tallies/tally_filter_mesh.h"
|
||||
|
|
@ -104,6 +105,15 @@ extern "C" {
|
|||
void filter_to_statepoint(TallyFilter* filt, hid_t group)
|
||||
{filt->to_statepoint(group);}
|
||||
|
||||
void filter_text_label(TallyFilter* filt, int bin, char* label)
|
||||
{
|
||||
std::string label_str = filt->text_label(bin);
|
||||
int i = 0;
|
||||
for (; i < label_str.size() && i < MAX_LINE_LEN; i++)
|
||||
label[i] = label_str[i];
|
||||
label[i] = '\0';
|
||||
}
|
||||
|
||||
void filter_initialize(TallyFilter* filt) {filt->initialize();}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ contains
|
|||
integer, intent(in) :: bin
|
||||
character(MAX_LINE_LEN) :: label
|
||||
|
||||
label = "Cell " // to_str(cells(this % cells(bin)) % id())
|
||||
label = this % text_label_c(bin)
|
||||
end function text_label_cell
|
||||
|
||||
!===============================================================================
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ contains
|
|||
integer, intent(in) :: bin
|
||||
character(MAX_LINE_LEN) :: label
|
||||
|
||||
label = "Cell from " // to_str(cells(this % cells(bin)) % id())
|
||||
label = this % text_label_c(bin)
|
||||
end function text_label_cell_from
|
||||
|
||||
end module tally_filter_cellfrom
|
||||
|
|
|
|||
|
|
@ -133,6 +133,7 @@ module tally_filter_header
|
|||
procedure :: from_xml_c
|
||||
procedure :: get_all_bins_c
|
||||
procedure :: to_statepoint_c
|
||||
procedure :: text_label_c
|
||||
procedure :: initialize_c
|
||||
end type CppTallyFilter
|
||||
|
||||
|
|
@ -322,6 +323,28 @@ contains
|
|||
call filter_to_statepoint(this % ptr, filter_group)
|
||||
end subroutine to_statepoint_c
|
||||
|
||||
function text_label_c(this, bin) result(label)
|
||||
class(CppTallyFilter), intent(in) :: this
|
||||
integer, intent(in) :: bin
|
||||
character(MAX_LINE_LEN) :: label
|
||||
character(kind=C_CHAR) :: label_(MAX_LINE_LEN+1)
|
||||
integer :: i
|
||||
interface
|
||||
subroutine filter_text_label(filt, bin, label) bind(C)
|
||||
import C_PTR, C_INT, C_CHAR
|
||||
type(C_PTR), value :: filt
|
||||
integer(C_INT), value :: bin
|
||||
character(kind=C_CHAR) :: label(*)
|
||||
end subroutine filter_text_label
|
||||
end interface
|
||||
call filter_text_label(this % ptr, bin, label_)
|
||||
label = " "
|
||||
do i = 1, MAX_LINE_LEN
|
||||
if (label_(i) == C_NULL_CHAR) exit
|
||||
label(i:i) = label_(i)
|
||||
end do
|
||||
end function text_label_c
|
||||
|
||||
subroutine initialize_c(this)
|
||||
class(CppTallyFilter), intent(inout) :: this
|
||||
interface
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue