Linear Source Random Ray (#3072)

Co-authored-by: John Tramm <john.tramm@gmail.com>
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
This commit is contained in:
Rufus 2024-07-17 01:53:40 +01:00 committed by GitHub
parent 58f9092a68
commit fd47df4bb2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 2235 additions and 63 deletions

View file

@ -342,6 +342,8 @@ enum class RunMode {
enum class SolverType { MONTE_CARLO, RANDOM_RAY };
enum class RandomRaySourceShape { FLAT, LINEAR, LINEAR_XY };
//==============================================================================
// Geometry Constants

View file

@ -89,25 +89,28 @@ struct TallyTask {
class FlatSourceDomain {
public:
//----------------------------------------------------------------------------
// Constructors
// Constructors and Destructors
FlatSourceDomain();
virtual ~FlatSourceDomain() = default;
//----------------------------------------------------------------------------
// Methods
void update_neutron_source(double k_eff);
virtual void update_neutron_source(double k_eff);
double compute_k_eff(double k_eff_old) const;
void normalize_scalar_flux_and_volumes(
virtual void normalize_scalar_flux_and_volumes(
double total_active_distance_per_iteration);
int64_t add_source_to_scalar_flux();
void batch_reset();
virtual int64_t add_source_to_scalar_flux();
virtual void batch_reset();
void convert_source_regions_to_tallies();
void reset_tally_volumes();
void random_ray_tally();
void accumulate_iteration_flux();
virtual void accumulate_iteration_flux();
void output_to_vtk() const;
void all_reduce_replicated_source_regions();
virtual void all_reduce_replicated_source_regions();
void convert_external_sources();
void count_external_source_regions();
virtual void flux_swap();
virtual double evaluate_flux_at_point(Position r, int64_t sr, int g) const;
double compute_fixed_source_normalization_factor() const;
//----------------------------------------------------------------------------
@ -131,6 +134,7 @@ public:
vector<OpenMPMutex> lock_;
vector<int> was_hit_;
vector<double> volume_;
vector<double> volume_t_;
vector<int> position_recorded_;
vector<Position> position_;
@ -141,7 +145,7 @@ public:
vector<float> source_;
vector<float> external_source_;
private:
protected:
//----------------------------------------------------------------------------
// Methods
void apply_external_source_to_source_region(
@ -174,7 +178,6 @@ private:
// 1D arrays representing values for all source regions
vector<int> material_;
vector<double> volume_t_;
// 2D arrays stored in 1D representing values for all source regions x energy
// groups

View file

@ -0,0 +1,61 @@
#ifndef OPENMC_RANDOM_RAY_LINEAR_SOURCE_DOMAIN_H
#define OPENMC_RANDOM_RAY_LINEAR_SOURCE_DOMAIN_H
#include "openmc/random_ray/flat_source_domain.h"
#include "openmc/random_ray/moment_matrix.h"
#include "openmc/openmp_interface.h"
#include "openmc/position.h"
#include "openmc/source.h"
namespace openmc {
/*
* The LinearSourceDomain class encompasses data and methods for storing
* scalar flux and source region for all linear source regions in a
* random ray simulation domain.
*/
class LinearSourceDomain : public FlatSourceDomain {
public:
//----------------------------------------------------------------------------
// Constructors
LinearSourceDomain();
//----------------------------------------------------------------------------
// Methods
void update_neutron_source(double k_eff) override;
double compute_k_eff(double k_eff_old) const;
void normalize_scalar_flux_and_volumes(
double total_active_distance_per_iteration) override;
int64_t add_source_to_scalar_flux() override;
void batch_reset() override;
void convert_source_regions_to_tallies();
void reset_tally_volumes();
void random_ray_tally();
void accumulate_iteration_flux() override;
void output_to_vtk() const;
void all_reduce_replicated_source_regions() override;
void convert_external_sources();
void count_external_source_regions();
void flux_swap() override;
double evaluate_flux_at_point(Position r, int64_t sr, int g) const override;
//----------------------------------------------------------------------------
// Public Data members
vector<MomentArray> source_gradients_;
vector<MomentArray> flux_moments_old_;
vector<MomentArray> flux_moments_new_;
vector<MomentArray> flux_moments_t_;
vector<Position> centroid_;
vector<Position> centroid_iteration_;
vector<Position> centroid_t_;
vector<MomentMatrix> mom_matrix_;
vector<MomentMatrix> mom_matrix_t_;
}; // class LinearSourceDomain
} // namespace openmc
#endif // OPENMC_RANDOM_RAY_LINEAR_SOURCE_DOMAIN_H

View file

@ -0,0 +1,90 @@
#ifndef OPENMC_MOMENT_MATRIX_H
#define OPENMC_MOMENT_MATRIX_H
#include <array>
#include "openmc/position.h"
namespace openmc {
// The MomentArray class is a 3-element array representing the x, y, and z
// moments. It is defined as an alias for the Position class to allow for
// dot products and other operations with Position objects.
// TODO: This class could in theory have 32-bit instead of 64-bit FP values.
using MomentArray = Position;
// The MomentMatrix class is a sparse representation a 3x3 symmetric
// matrix, with elements labeled as follows:
//
// | a b c |
// | b d e |
// | c e f |
//
// This class uses FP64 values as objects that are accumulated to over many
// iterations.
class MomentMatrix {
public:
//----------------------------------------------------------------------------
// Public data members
double a;
double b;
double c;
double d;
double e;
double f;
//----------------------------------------------------------------------------
// Constructors
MomentMatrix() = default;
MomentMatrix(double a, double b, double c, double d, double e, double f)
: a {a}, b {b}, c {c}, d {d}, e {e}, f {f}
{}
//----------------------------------------------------------------------------
// Methods
MomentMatrix inverse() const;
double determinant() const;
void compute_spatial_moments_matrix(
const Position& r, const Direction& u, const double& distance);
inline void set_to_zero() { a = b = c = d = e = f = 0; }
inline MomentMatrix& operator*=(double x)
{
a *= x;
b *= x;
c *= x;
d *= x;
e *= x;
f *= x;
return *this;
}
inline MomentMatrix operator*(double x) const
{
MomentMatrix m_copy = *this;
m_copy *= x;
return m_copy;
}
inline MomentMatrix& operator+=(const MomentMatrix& rhs)
{
a += rhs.a;
b += rhs.b;
c += rhs.c;
d += rhs.d;
e += rhs.e;
f += rhs.f;
return *this;
}
MomentArray operator*(const MomentArray& rhs) const
{
return {a * rhs.x + b * rhs.y + c * rhs.z,
b * rhs.x + d * rhs.y + e * rhs.z, c * rhs.x + e * rhs.y + f * rhs.z};
}
};
} // namespace openmc
#endif // OPENMC_MOMENT_MATRIX_H

View file

@ -4,6 +4,7 @@
#include "openmc/memory.h"
#include "openmc/particle.h"
#include "openmc/random_ray/flat_source_domain.h"
#include "openmc/random_ray/moment_matrix.h"
#include "openmc/source.h"
namespace openmc {
@ -25,14 +26,18 @@ public:
// Methods
void event_advance_ray();
void attenuate_flux(double distance, bool is_active);
void attenuate_flux_flat_source(double distance, bool is_active);
void attenuate_flux_linear_source(double distance, bool is_active);
void initialize_ray(uint64_t ray_id, FlatSourceDomain* domain);
uint64_t transport_history_based_single_ray();
//----------------------------------------------------------------------------
// Static data members
static double distance_inactive_; // Inactive (dead zone) ray length
static double distance_active_; // Active ray length
static unique_ptr<Source> ray_source_; // Starting source for ray sampling
static double distance_inactive_; // Inactive (dead zone) ray length
static double distance_active_; // Active ray length
static unique_ptr<Source> ray_source_; // Starting source for ray sampling
static RandomRaySourceShape source_shape_; // Flag for linear source
//----------------------------------------------------------------------------
// Public data members
@ -42,6 +47,8 @@ private:
//----------------------------------------------------------------------------
// Private data members
vector<float> delta_psi_;
vector<MomentArray> delta_moments_;
int negroups_;
FlatSourceDomain* domain_ {nullptr}; // pointer to domain that has flat source
// data needed for ray transport

View file

@ -2,6 +2,7 @@
#define OPENMC_RANDOM_RAY_SIMULATION_H
#include "openmc/random_ray/flat_source_domain.h"
#include "openmc/random_ray/linear_source_domain.h"
namespace openmc {
@ -31,7 +32,7 @@ public:
// Data members
private:
// Contains all flat source region data
FlatSourceDomain domain_;
unique_ptr<FlatSourceDomain> domain_;
// Random ray eigenvalue
double k_eff_ {1.0};