Skip to content
Draft
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 @@ -421,6 +421,7 @@ list(APPEND libopenmc_SOURCES
src/tallies/filter_material.cpp
src/tallies/filter_materialfrom.cpp
src/tallies/filter_mesh.cpp
src/tallies/filter_meshangular.cpp
src/tallies/filter_meshborn.cpp
src/tallies/filter_meshmaterial.cpp
src/tallies/filter_meshsurface.cpp
Expand Down
2 changes: 2 additions & 0 deletions include/openmc/capi.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ int openmc_mesh_get_n_elements(int32_t index, size_t* n);
int openmc_mesh_get_volumes(int32_t index, double* volumes);
int openmc_mesh_material_volumes(int32_t index, int nx, int ny, int nz,
int max_mats, int32_t* materials, double* volumes, double* bboxes);
int openmc_meshangular_filter_get_mesh(int32_t index, int32_t* index_mesh);
int openmc_meshangular_filter_set_mesh(int32_t index, int32_t index_mesh);
int openmc_meshsurface_filter_get_mesh(int32_t index, int32_t* index_mesh);
int openmc_meshsurface_filter_set_mesh(int32_t index, int32_t index_mesh);
int openmc_cylindrical_mesh_get_origin(int32_t index, double origin[3]);
Expand Down
93 changes: 91 additions & 2 deletions include/openmc/mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ class Mesh {
//! element
//! \param[inout] materials Array storing material indices
//! \param[inout] volumes Array storing volumes
void material_volumes(int nx, int ny, int nz, int max_materials,
virtual void material_volumes(int nx, int ny, int nz, int max_materials,
int32_t* materials, double* volumes) const;

//! Determine volume and bounding boxes of materials within each mesh element
Expand All @@ -302,7 +302,7 @@ class Mesh {
//! \param[inout] materials Array storing material indices
//! \param[inout] volumes Array storing volumes
//! \param[inout] bboxes Array storing bounding boxes (n_elems, table_size, 6)
void material_volumes(int nx, int ny, int nz, int max_materials,
virtual void material_volumes(int nx, int ny, int nz, int max_materials,
int32_t* materials, double* volumes, double* bboxes) const;

//! Determine bounding box of mesh
Expand Down Expand Up @@ -906,6 +906,95 @@ class UnstructuredMesh : public Mesh {
virtual void initialize() = 0;
};

// Abstract class for meshes over directions (points on the unit sphere),
// as opposed to meshes over volumes.
class AngularMesh : public Mesh {
public:
AngularMesh() { n_dimension_ = 2; }
AngularMesh(pugi::xml_node node) : Mesh(node) { n_dimension_ = 2; }
AngularMesh(hid_t group) : Mesh(group) { n_dimension_ = 2; }

// Angular meshes partition direction space, not a volume.
// Therefore, "bin crossing" methods are not used; only the "get_bin" method.
void bins_crossed(Position r0, Position r1, const Direction& u,
vector<int>& bins, vector<double>& lengths) const override
{
fatal_error("Angular meshes do not support spatial tracklength tallies.");
}

MeshCrossing next_mesh_crossing(
int current_bin, Position r, Direction u) const override
{
fatal_error("Angular meshes do not support spatial mesh crossings.");
return {INFTY, C_NONE};
}

void surface_bins_crossed(Position r0, Position r1, const Direction& u,
vector<int>& bins) const override
{
fatal_error("Angular meshes do not support surface-crossing tallies.");
}

int n_surface_bins() const override { return 0; }

std::pair<vector<double>, vector<double>> plot(
Position plot_ll, Position plot_ur) const override
{
return {{}, {}};
}

void material_volumes(int nx, int ny, int nz, int max_materials,
int32_t* materials, double* volumes) const override
{
fatal_error("material_volumes() is not supported for angular meshes");
}

void material_volumes(int nx, int ny, int nz, int max_materials,
int32_t* materials, double* volumes, double* bboxes) const override
{
fatal_error("material_volumes() is not supported for angular meshes");
}

std::string bin_label(int bin) const override
{
return fmt::format("Element Index ({})", bin);
}

Position lower_left() const override { return {-1., -1., -1.}; }
Position upper_right() const override { return {1., 1., 1.}; }
};

class UnitSpherePointset : public AngularMesh {
public:
UnitSpherePointset() = default;
explicit UnitSpherePointset(vector<Direction> points);
UnitSpherePointset(pugi::xml_node node);
UnitSpherePointset(hid_t group);

//! TODO: add sampling from within a spherical Voronoi cell
Position sample_element(int32_t bin, uint64_t* seed) const override
{
fatal_error(
"Sampling over a UnitSpherePointset angular mesh is not supported");
}

int get_bin(Direction u) const override;

int n_bins() const override { return static_cast<int>(points_.size()); }

double volume(int bin) const override
{
fatal_error("Volume calculation over UnitSpherePointset is not supported");
}

std::string get_mesh_type() const override { return mesh_type; }
static const std::string mesh_type;

void to_hdf5_inner(hid_t group) const override;

vector<Position> points_;
};

#ifdef OPENMC_DAGMC_ENABLED

class MOABMesh : public UnstructuredMesh {
Expand Down
4 changes: 4 additions & 0 deletions include/openmc/particle.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ class Particle : public ParticleData {
void cross_periodic_bc(
const Surface& surf, Position new_r, Direction new_u, int new_surface);

//! Reset angular flux tally bin if in RandomRay mode
//! (does nothing for MC particles)
virtual void direction_changed() {}

//! mark a particle as lost and create a particle restart file
//! \param message A warning message to display
virtual void mark_as_lost(const char* message) override;
Expand Down
1 change: 1 addition & 0 deletions include/openmc/random_ray/decomposition_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class DecompositionMap {
// Miscellaneous
uint64_t n_base_sr_;
int negroups_;
int nangles_ {1};
double max_domain_length_;
bool is_linear_;
bool is_adaptive_;
Expand Down
18 changes: 17 additions & 1 deletion include/openmc/random_ray/flat_source_domain.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define OPENMC_RANDOM_RAY_FLAT_SOURCE_DOMAIN_H

#include "openmc/constants.h"
#include "openmc/mesh.h"
#include "openmc/openmp_interface.h"
#include "openmc/position.h"
#include "openmc/random_ray/parallel_map.h"
Expand Down Expand Up @@ -74,13 +75,14 @@ class FlatSourceDomain {
virtual void update_single_neutron_source(SourceRegionHandle& srh);
virtual void update_all_neutron_sources();
void compute_k_eff();
virtual void normalize_scalar_flux_and_volumes(
virtual void normalize_flux_and_volumes(
double total_active_distance_per_iteration);
bool is_geometry_3D();

int64_t add_source_to_scalar_flux();
virtual void batch_reset();
void convert_source_regions_to_tallies(int64_t start_sr_id);
void initialize_angular_quadrature();
void reset_tally_volumes();
void random_ray_tally();
virtual void accumulate_iteration_flux();
Expand Down Expand Up @@ -118,6 +120,10 @@ class FlatSourceDomain {
SourceRegionKey lookup_source_region_key(const GeometryState& p) const;
int64_t lookup_mesh_bin(int64_t sr, Position r) const;
int lookup_mesh_idx(int64_t sr) const;
int lookup_angular_bin(Direction u) const;
Direction angular_quadrature_direction(int a) const;
bool tally_angular_flux_applies(
int cell_idx, int material, int mesh_idx) const;

//----------------------------------------------------------------------------
// Static Data members
Expand All @@ -133,6 +139,8 @@ class FlatSourceDomain {
static double
diagonal_stabilization_rho_; // Adjusts strength of diagonal stabilization
// for transport corrected MGXS data
// Number of bins for any angular tallies
static int nangles_;

// Static variables to store source region meshes and domains
static std::unordered_map<int, vector<std::pair<Source::DomainType, int>>>
Expand Down Expand Up @@ -249,6 +257,7 @@ class FlatSourceDomain {
void set_flux_to_source(int64_t sr, int g);
virtual void set_flux_to_old_flux(int64_t sr, int g);
virtual double flux_additive_term(int64_t sr, int g, bool batch_volume) const;
double angular_flux_additive_term(int64_t sr, int g, bool batch_volume) const;
double stabilized_flux(int64_t sr, int g, double phi_new) const;

//! Adaptive-estimator "strong source" test. Returns true if, in any group,
Expand All @@ -266,6 +275,13 @@ class FlatSourceDomain {
//----------------------------------------------------------------------------
// Private data members
int negroups_; // Number of energy groups in simulation
const UnitSpherePointset* angular_mesh_ {nullptr};

vector<bool> tally_is_angular_;
std::unordered_set<int32_t> angular_target_cells_;
std::unordered_set<int32_t> angular_target_materials_;
std::unordered_set<int32_t> angular_target_spatial_meshes_;
bool tally_angular_flux_everywhere_ {false};

double
simulation_volume_; // Total physical volume of the simulation domain, as
Expand Down
2 changes: 1 addition & 1 deletion include/openmc/random_ray/linear_source_domain.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class LinearSourceDomain : public FlatSourceDomain {
//----------------------------------------------------------------------------
// Methods
void update_single_neutron_source(SourceRegionHandle& srh) override;
void normalize_scalar_flux_and_volumes(
void normalize_flux_and_volumes(
double total_active_distance_per_iteration) override;

void batch_reset() override;
Expand Down
5 changes: 5 additions & 0 deletions include/openmc/random_ray/random_ray.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct RayBufferContainer {
// early-return in attenuate_flux_inner() happens before n_event() is
// incremented, so max_particle_events cannot bound a forwarding loop.
int n_transfers;
int angular_bin;
vector<float> angular_flux;
int surface;
bool is_active;
Expand Down Expand Up @@ -61,6 +62,7 @@ struct RayBufferContainer {
struct RayExchangeData {
Position position;
Direction direction;
int angular_bin;
double distance_travelled;
double advance_distance;
int n_transfers;
Expand Down Expand Up @@ -117,6 +119,7 @@ class RandomRay : public Particle {
SourceRegionHandle& srh, double distance, bool is_active, Position r);
void attenuate_flux_linear_source_void(
SourceRegionHandle& srh, double distance, bool is_active, Position r);
void direction_changed() override { angular_bin_ = C_NONE; }

void initialize_ray(uint64_t ray_id, FlatSourceDomain* domain);
void restart_ray(FlatSourceDomain* domain, RayExchangeData& data,
Expand All @@ -125,6 +128,7 @@ class RandomRay : public Particle {
SourceSite sample_prng();
SourceSite sample_halton();
SourceSite sample_s2();
int angular_bin(); // accessor for current angular quadrature bin index

bool has_left_subdomain();
void pack_ray_for_buffer(double distance_buffer, double advance_distance);
Expand Down Expand Up @@ -157,6 +161,7 @@ class RandomRay : public Particle {

int negroups_;
int ntemperature_;
int angular_bin_ {C_NONE};
FlatSourceDomain* domain_ {nullptr}; // pointer to domain that has flat source
// data needed for ray transport
double distance_travelled_ {0};
Expand Down
Loading
Loading