Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meshborn filter #2925

Merged
merged 3 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ list(APPEND libopenmc_SOURCES
src/tallies/filter_material.cpp
src/tallies/filter_materialfrom.cpp
src/tallies/filter_mesh.cpp
src/tallies/filter_meshborn.cpp
src/tallies/filter_meshsurface.cpp
src/tallies/filter_mu.cpp
src/tallies/filter_particle.cpp
Expand Down
102 changes: 102 additions & 0 deletions docs/source/capi/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,16 @@ Functions
:return: Return status (negative if an error occurred)
:rtype: int

.. c:function:: int openmc_mesh_filter_get_mesh(int32_t index, int32_t* index_mesh)

Get the mesh for a mesh filter

:param int32_t index: Index in the filters array
:param index_mesh: Index in the meshes array
:type index_mesh: int32_t*
:return: Return status (negative if an error occurred)
:rtype: int

.. c:function:: int openmc_mesh_filter_set_mesh(int32_t index, int32_t index_mesh)

Set the mesh for a mesh filter
Expand All @@ -429,6 +439,98 @@ Functions
:return: Return status (negative if an error occurred)
:rtype: int

.. c:function:: int openmc_mesh_filter_get_translation(int32_t index, double translation[3])

Get the 3-D translation coordinates for a mesh filter

:param int32_t index: Index in the filters array
:param double[3] translation: 3-D translation coordinates
:return: Return status (negative if an error occurred)
:rtype: int

.. c:function:: int openmc_mesh_filter_set_translation(int32_t index, double translation[3])

Set the 3-D translation coordinates for a mesh filter

:param int32_t index: Index in the filters array
:param double[3] translation: 3-D translation coordinates
:return: Return status (negative if an error occurred)
:rtype: int

.. c:function:: int openmc_meshborn_filter_get_mesh(int32_t index, int32_t* index_mesh)

Get the mesh for a meshborn filter

:param int32_t index: Index in the filters array
:param index_mesh: Index in the meshes array
:type index_mesh: int32_t*
:return: Return status (negative if an error occurred)
:rtype: int

.. c:function:: int openmc_meshborn_filter_set_mesh(int32_t index, int32_t index_mesh)

Set the mesh for a meshborn filter

:param int32_t index: Index in the filters array
:param int32_t index_mesh: Index in the meshes array
:return: Return status (negative if an error occurred)
:rtype: int

.. c:function:: int openmc_meshborn_filter_get_translation(int32_t index, double translation[3])

Get the 3-D translation coordinates for a meshborn filter

:param int32_t index: Index in the filters array
:param double[3] translation: 3-D translation coordinates
:return: Return status (negative if an error occurred)
:rtype: int

.. c:function:: int openmc_meshborn_filter_set_translation(int32_t index, double translation[3])

Set the 3-D translation coordinates for a meshborn filter

:param int32_t index: Index in the filters array
:param double[3] translation: 3-D translation coordinates
:return: Return status (negative if an error occurred)
:rtype: int

.. c:function:: int openmc_meshsurface_filter_get_mesh(int32_t index, int32_t* index_mesh)

Get the mesh for a mesh surface filter

:param int32_t index: Index in the filters array
:param index_mesh: Index in the meshes array
:type index_mesh: int32_t*
:return: Return status (negative if an error occurred)
:rtype: int

.. c:function:: int openmc_meshsurface_filter_set_mesh(int32_t index, int32_t index_mesh)

Set the mesh for a mesh surface filter

:param int32_t index: Index in the filters array
:param int32_t index_mesh: Index in the meshes array
:return: Return status (negative if an error occurred)
:rtype: int

.. c:function:: int openmc_meshsurface_filter_get_translation(int32_t index, double translation[3])

Get the 3-D translation coordinates for a mesh surface filter

:param int32_t index: Index in the filters array
:param double[3] translation: 3-D translation coordinates
:return: Return status (negative if an error occurred)
:rtype: int

.. c:function:: int openmc_meshsurface_filter_set_translation(int32_t index, double translation[3])

Set the 3-D translation coordinates for a mesh surface filter

:param int32_t index: Index in the filters array
:param double[3] translation: 3-D translation coordinates
:return: Return status (negative if an error occurred)
:rtype: int

.. c:function:: int openmc_next_batch()

Simulate next batch of particles. Must be called after openmc_simulation_init().
Expand Down
1 change: 1 addition & 0 deletions docs/source/pythonapi/base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ Constructing Tallies
openmc.CollisionFilter
openmc.SurfaceFilter
openmc.MeshFilter
openmc.MeshBornFilter
openmc.MeshSurfaceFilter
openmc.EnergyFilter
openmc.EnergyoutFilter
Expand Down
1 change: 1 addition & 0 deletions docs/source/pythonapi/capi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Classes
MaterialFilter
Material
MeshFilter
MeshBornFilter
MeshSurfaceFilter
Nuclide
RectilinearMesh
Expand Down
5 changes: 5 additions & 0 deletions include/openmc/particle_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ class GeometryState {
int& cell_last(int i) { return cell_last_[i]; }
const int& cell_last(int i) const { return cell_last_[i]; }

// Coordinates at birth
Position& r_born() { return r_born_; }
const Position& r_born() const { return r_born_; }

// Coordinates of last collision or reflective/periodic surface
// crossing for current tallies
Position& r_last_current() { return r_last_current_; }
Expand Down Expand Up @@ -323,6 +327,7 @@ class GeometryState {
int n_coord_last_ {1}; //!< number of current coordinates
vector<int> cell_last_; //!< coordinates for all levels

Position r_born_; //!< coordinates at birth
Position r_last_current_; //!< coordinates of the last collision or
//!< reflective/periodic surface crossing for
//!< current tallies
Expand Down
1 change: 1 addition & 0 deletions include/openmc/tallies/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ enum class FilterType {
MATERIAL,
MATERIALFROM,
MESH,
MESHBORN,
MESH_SURFACE,
MU,
PARTICLE,
Expand Down
26 changes: 26 additions & 0 deletions include/openmc/tallies/filter_meshborn.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef OPENMC_TALLIES_FILTER_MESHBORN_H
#define OPENMC_TALLIES_FILTER_MESHBORN_H

#include <cstdint>

#include "openmc/position.h"
#include "openmc/tallies/filter_mesh.h"

namespace openmc {

class MeshBornFilter : public MeshFilter {
public:
//----------------------------------------------------------------------------
// Methods

std::string type_str() const override { return "meshborn"; }
FilterType type() const override { return FilterType::MESHBORN; }

void get_all_bins(const Particle& p, TallyEstimator estimator,
FilterMatch& match) const override;

std::string text_label(int bin) const override;
};

} // namespace openmc
#endif // OPENMC_TALLIES_FILTER_MESHBORN_H
28 changes: 28 additions & 0 deletions openmc/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,34 @@ def from_xml_element(cls, elem, **kwargs):
if translation:
out.translation = [float(x) for x in translation.split()]
return out


class MeshBornFilter(MeshFilter):
"""Filter events by the mesh cell a particle originated from.

Parameters
----------
mesh : openmc.MeshBase
The mesh object that events will be tallied onto
filter_id : int
Unique identifier for the filter

Attributes
----------
mesh : openmc.MeshBase
The mesh object that events will be tallied onto
id : int
Unique identifier for the filter
translation : Iterable of float
This array specifies a vector that is used to translate (shift)
the mesh for this filter
bins : list of tuple
A list of mesh indices for each filter bin, e.g. [(1, 1, 1), (2, 1, 1),
...]
num_bins : Integral
The number of filter bins

"""


class MeshSurfaceFilter(MeshFilter):
Expand Down
Loading