Skip to content

Commit

Permalink
partially done with refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jtramm committed Nov 21, 2019
1 parent 0ebfae4 commit 5502f38
Show file tree
Hide file tree
Showing 31 changed files with 301 additions and 256 deletions.
16 changes: 8 additions & 8 deletions include/openmc/distribution.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Discrete : public Distribution {

//! Sample a value from the distribution
//! \return Sampled value
double sample() const;
double sample(uint64_t * prn_seeds, int stream) const;

// Properties
const std::vector<double>& x() const { return x_; }
Expand All @@ -59,7 +59,7 @@ class Uniform : public Distribution {

//! Sample a value from the distribution
//! \return Sampled value
double sample() const;
double sample(uint64_t * prn_seeds, int stream) const;
private:
double a_; //!< Lower bound of distribution
double b_; //!< Upper bound of distribution
Expand All @@ -76,7 +76,7 @@ class Maxwell : public Distribution {

//! Sample a value from the distribution
//! \return Sampled value
double sample() const;
double sample(uint64_t * prn_seeds, int stream) const;
private:
double theta_; //!< Factor in exponential [eV]
};
Expand All @@ -92,7 +92,7 @@ class Watt : public Distribution {

//! Sample a value from the distribution
//! \return Sampled value
double sample() const;
double sample(uint64_t * prn_seeds, int stream) const;
private:
double a_; //!< Factor in exponential [eV]
double b_; //!< Factor in square root [1/eV]
Expand All @@ -109,7 +109,7 @@ class Normal : public Distribution {

//! Sample a value from the distribution
//! \return Sampled value
double sample() const;
double sample(uint64_t * prn_seeds, int stream) const;
private:
double mean_value_; //!< middle of distribution [eV]
double std_dev_; //!< standard deviation [eV]
Expand All @@ -127,7 +127,7 @@ class Muir : public Distribution {

//! Sample a value from the distribution
//! \return Sampled value
double sample() const;
double sample(uint64_t * prn_seeds, int stream) const;
private:
// example DT fusion m_rat = 5 (D = 2 + T = 3)
// ion temp = 20000 eV
Expand All @@ -149,7 +149,7 @@ class Tabular : public Distribution {

//! Sample a value from the distribution
//! \return Sampled value
double sample() const;
double sample(uint64_t * prn_seeds, int stream) const;

// x property
std::vector<double>& x() { return x_; }
Expand Down Expand Up @@ -179,7 +179,7 @@ class Equiprobable : public Distribution {

//! Sample a value from the distribution
//! \return Sampled value
double sample() const;
double sample(uint64_t * prn_seeds, int stream) const;
private:
std::vector<double> x_; //! Possible outcomes
};
Expand Down
2 changes: 1 addition & 1 deletion include/openmc/distribution_angle.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class AngleDistribution {
//! Sample an angle given an incident particle energy
//! \param[in] E Particle energy in [eV]
//! \return Cosine of the angle in the range [-1,1]
double sample(double E) const;
double sample(double E, uint64_t * prn_seeds, int stream) const;

//! Determine whether angle distribution is empty
//! \return Whether distribution is empty
Expand Down
14 changes: 7 additions & 7 deletions include/openmc/distribution_energy.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace openmc {

class EnergyDistribution {
public:
virtual double sample(double E) const = 0;
virtual double sample(double E, uint64_t * prn_seeds, int stream) const = 0;
virtual ~EnergyDistribution() = default;
};

Expand All @@ -37,7 +37,7 @@ class DiscretePhoton : public EnergyDistribution {
//! Sample energy distribution
//! \param[in] E Incident particle energy in [eV]
//! \return Sampled energy in [eV]
double sample(double E) const;
double sample(double E, uint64_t * prn_seeds, int stream) const;
private:
int primary_flag_; //!< Indicator of whether the photon is a primary or
//!< non-primary photon.
Expand All @@ -56,7 +56,7 @@ class LevelInelastic : public EnergyDistribution {
//! Sample energy distribution
//! \param[in] E Incident particle energy in [eV]
//! \return Sampled energy in [eV]
double sample(double E) const;
double sample(double E, uint64_t * prn_seeds, int stream) const;
private:
double threshold_; //!< Energy threshold in lab, (A + 1)/A * |Q|
double mass_ratio_; //!< (A/(A+1))^2
Expand All @@ -75,7 +75,7 @@ class ContinuousTabular : public EnergyDistribution {
//! Sample energy distribution
//! \param[in] E Incident particle energy in [eV]
//! \return Sampled energy in [eV]
double sample(double E) const;
double sample(double E, uint64_t * prn_seeds, int stream) const;
private:
//! Outgoing energy for a single incoming energy
struct CTTable {
Expand Down Expand Up @@ -104,7 +104,7 @@ class Evaporation : public EnergyDistribution {
//! Sample energy distribution
//! \param[in] E Incident particle energy in [eV]
//! \return Sampled energy in [eV]
double sample(double E) const;
double sample(double E, uint64_t * prn_seeds, int stream) const;
private:
Tabulated1D theta_; //!< Incoming energy dependent parameter
double u_; //!< Restriction energy
Expand All @@ -122,7 +122,7 @@ class MaxwellEnergy : public EnergyDistribution {
//! Sample energy distribution
//! \param[in] E Incident particle energy in [eV]
//! \return Sampled energy in [eV]
double sample(double E) const;
double sample(double E, uint64_t * prn_seeds, int stream) const;
private:
Tabulated1D theta_; //!< Incoming energy dependent parameter
double u_; //!< Restriction energy
Expand All @@ -140,7 +140,7 @@ class WattEnergy : public EnergyDistribution {
//! Sample energy distribution
//! \param[in] E Incident particle energy in [eV]
//! \return Sampled energy in [eV]
double sample(double E) const;
double sample(double E, uint64_t * prn_seeds, int stream) const;
private:
Tabulated1D a_; //!< Energy-dependent 'a' parameter
Tabulated1D b_; //!< Energy-dependent 'b' parameter
Expand Down
8 changes: 4 additions & 4 deletions include/openmc/distribution_multi.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class UnitSphereDistribution {

//! Sample a direction from the distribution
//! \return Direction sampled
virtual Direction sample() const = 0;
virtual Direction sample(uint64_t * prn_seeds, int stream) const = 0;

Direction u_ref_ {0.0, 0.0, 1.0}; //!< reference direction
};
Expand All @@ -40,7 +40,7 @@ class PolarAzimuthal : public UnitSphereDistribution {

//! Sample a direction from the distribution
//! \return Direction sampled
Direction sample() const;
Direction sample(uint64_t * prn_seeds, int stream) const;
private:
UPtrDist mu_; //!< Distribution of polar angle
UPtrDist phi_; //!< Distribution of azimuthal angle
Expand All @@ -56,7 +56,7 @@ class Isotropic : public UnitSphereDistribution {

//! Sample a direction from the distribution
//! \return Sampled direction
Direction sample() const;
Direction sample(uint64_t * prn_seeds, int stream) const;
};

//==============================================================================
Expand All @@ -70,7 +70,7 @@ class Monodirectional : public UnitSphereDistribution {

//! Sample a direction from the distribution
//! \return Sampled direction
Direction sample() const;
Direction sample(uint64_t * prn_seeds, int stream) const;
};

using UPtrAngle = std::unique_ptr<UnitSphereDistribution>;
Expand Down
10 changes: 5 additions & 5 deletions include/openmc/distribution_spatial.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class SpatialDistribution {
virtual ~SpatialDistribution() = default;

//! Sample a position from the distribution
virtual Position sample() const = 0;
virtual Position sample(uint64_t * prn_seeds, int stream) const = 0;
};

//==============================================================================
Expand All @@ -30,7 +30,7 @@ class CartesianIndependent : public SpatialDistribution {

//! Sample a position from the distribution
//! \return Sampled position
Position sample() const;
Position sample(uint64_t * prn_seeds, int stream) const;
private:
UPtrDist x_; //!< Distribution of x coordinates
UPtrDist y_; //!< Distribution of y coordinates
Expand All @@ -47,7 +47,7 @@ class SphericalIndependent : public SpatialDistribution {

//! Sample a position from the distribution
//! \return Sampled position
Position sample() const;
Position sample(uint64_t * prn_seeds, int stream) const;
private:
UPtrDist r_; //!< Distribution of r coordinates
UPtrDist theta_; //!< Distribution of theta coordinates
Expand All @@ -65,7 +65,7 @@ class SpatialBox : public SpatialDistribution {

//! Sample a position from the distribution
//! \return Sampled position
Position sample() const;
Position sample(uint64_t * prn_seeds, int stream) const;

// Properties
bool only_fissionable() const { return only_fissionable_; }
Expand All @@ -87,7 +87,7 @@ class SpatialPoint : public SpatialDistribution {

//! Sample a position from the distribution
//! \return Sampled position
Position sample() const;
Position sample(uint64_t * prn_seeds, int stream) const;
private:
Position r_; //!< Single position at which sites are generated
};
Expand Down
26 changes: 20 additions & 6 deletions include/openmc/math_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,15 @@ extern "C" void calc_zn_rad(int n, double rho, double zn_rad[]);
//! \param mu The cosine of angle in lab or CM
//! \param phi The azimuthal angle; will randomly chosen angle if a nullptr
//! is passed
//! \param prn_seeds A pointer to the array of pseudorandom seeds
//! \param stream The pseudorandom stream index with which to sample from
//==============================================================================

extern "C" void rotate_angle_c(double uvw[3], double mu, const double* phi);
extern "C" void rotate_angle_c(double uvw[3], double mu, const double* phi,
uint64_t * prn_seeds, int stream);

Direction rotate_angle(Direction u, double mu, const double* phi);
Direction rotate_angle(Direction u, double mu, const double* phi,
uint64_t * prn_streams, int stream);

//==============================================================================
//! Samples an energy from the Maxwell fission distribution based on a direct
Expand All @@ -144,10 +148,12 @@ Direction rotate_angle(Direction u, double mu, const double* phi);
//! rule C64 in the Monte Carlo Sampler LA-9721-MS.
//!
//! \param T The tabulated function of the incoming energy
//! \param prn_seeds A pointer to the array of pseudorandom seeds
//! \param stream The pseudorandom stream index with which to sample from
//! \return The sampled outgoing energy
//==============================================================================

extern "C" double maxwell_spectrum(double T);
extern "C" double maxwell_spectrum(double T, uint64_t * prn_seeds, int stream);

//==============================================================================
//! Samples an energy from a Watt energy-dependent fission distribution.
Expand All @@ -159,10 +165,12 @@ extern "C" double maxwell_spectrum(double T);
//!
//! \param a Watt parameter a
//! \param b Watt parameter b
//! \param prn_seeds A pointer to the array of pseudorandom seeds
//! \param stream The pseudorandom stream index with which to sample from
//! \return The sampled outgoing energy
//==============================================================================

extern "C" double watt_spectrum(double a, double b);
extern "C" double watt_spectrum(double a, double b, uint64_t * prn_seeds, int stream);

//==============================================================================
//! Samples an energy from the Gaussian energy-dependent fission distribution.
Expand All @@ -175,10 +183,13 @@ extern "C" double watt_spectrum(double a, double b);
//!
//! @param mean mean of the Gaussian distribution
//! @param std_dev standard deviation of the Gaussian distribution
//! @param prn_seeds A pointer to the array of pseudorandom seeds
//! @param stream The pseudorandom stream index with which to sample from
//! @result The sampled outgoing energy
//==============================================================================

extern "C" double normal_variate(double mean, double std_dev);
extern "C" double normal_variate(double mean, double std_dev, uint64_t * prn_seeds,
int stream);

//==============================================================================
//! Samples an energy from the Muir (Gaussian) energy-dependent distribution.
Expand All @@ -190,10 +201,13 @@ extern "C" double normal_variate(double mean, double std_dev);
//! @param e0 peak neutron energy [eV]
//! @param m_rat ratio of the fusion reactants to AMU
//! @param kt the ion temperature of the reactants [eV]
//! @param prn_seeds A pointer to the array of pseudorandom seeds
//! @param stream The pseudorandom stream index with which to sample from
//! @result The sampled outgoing energy
//==============================================================================

extern "C" double muir_spectrum(double e0, double m_rat, double kt);
extern "C" double muir_spectrum(double e0, double m_rat, double kt, uint64_t * prn_seeds,
int stream);

//==============================================================================
//! Doppler broadens the windowed multipole curvefit.
Expand Down
9 changes: 7 additions & 2 deletions include/openmc/mgxs.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,22 @@ class Mgxs {
//! @param gin Incoming energy group.
//! @param dg Sampled delayed group index.
//! @param gout Sampled outgoing energy group.
//! @param prn_seeds Pseudorandom seed array.
//! @param stream Pseudorandom stream index.
void
sample_fission_energy(int gin, int& dg, int& gout);
sample_fission_energy(int gin, int& dg, int& gout, uint64_t * prn_seeds, int stream);

//! \brief Samples the outgoing energy and angle from a scatter event.
//!
//! @param gin Incoming energy group.
//! @param gout Sampled outgoing energy group.
//! @param mu Sampled cosine of the change-in-angle.
//! @param wgt Weight of the particle to be adjusted.
//! @param prn_seeds Array of pseudorandom stream seeds
//! @param stream Pseudorandom stream index
void
sample_scatter(int gin, int& gout, double& mu, double& wgt);
sample_scatter(int gin, int& gout, double& mu, double& wgt, uint64_t * prn_seeds,
int stream);

//! \brief Calculates cross section quantities needed for tracking.
//!
Expand Down
11 changes: 6 additions & 5 deletions include/openmc/photon.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ class PhotonInteraction {
void calculate_xs(Particle& p) const;

void compton_scatter(double alpha, bool doppler, double* alpha_out,
double* mu, int* i_shell) const;
double* mu, int* i_shell, uint64_t * prn_seeds, int stream) const;

double rayleigh_scatter(double alpha) const;
double rayleigh_scatter(double alpha, uint64_t * prn_seeds, int stream) const;

void pair_production(double alpha, double* E_electron, double* E_positron,
double* mu_electron, double* mu_positron) const;
double* mu_electron, double* mu_positron, uint64_t * prn_seeds, int stream) const;

void atomic_relaxation(const ElectronSubshell& shell, Particle& p) const;

Expand Down Expand Up @@ -96,14 +96,15 @@ class PhotonInteraction {
xt::xtensor<double, 2> dcs_;

private:
void compton_doppler(double alpha, double mu, double* E_out, int* i_shell) const;
void compton_doppler(double alpha, double mu, double* E_out, int* i_shell,
uint64_t * prn_seeds, int stream) const;
};

//==============================================================================
// Non-member functions
//==============================================================================

std::pair<double, double> klein_nishina(double alpha);
std::pair<double, double> klein_nishina(double alpha, uint64_t * prn_seeds, int stream);

void free_memory_photon();

Expand Down
10 changes: 6 additions & 4 deletions include/openmc/physics.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void sample_photon_product(int i_nuclide, const Particle* p, int* i_rx, int* i_p

void absorption(Particle* p, int i_nuclide);

void scatter(Particle*, int i_nuclide);
void scatter(Particle* p, int i_nuclide);

//! Treats the elastic scattering of a neutron with a target.
void elastic_scatter(int i_nuclide, const Reaction& rx, double kT,
Expand All @@ -72,15 +72,17 @@ void sab_scatter(int i_nuclide, int i_sab, Particle* p);
//! dependence of cross sections in treating resonance elastic scattering such
//! as the DBRC and a new, accelerated scheme are also implemented here.
Direction sample_target_velocity(const Nuclide* nuc, double E, Direction u,
Direction v_neut, double xs_eff, double kT);
Direction v_neut, double xs_eff, double kT, uint64_t * prn_seeds, int stream);

//! samples a target velocity based on the free gas scattering formulation, used
//! by most Monte Carlo codes, in which cross section is assumed to be constant
//! in energy. Excellent documentation for this method can be found in
//! FRA-TM-123.
Direction sample_cxs_target_velocity(double awr, double E, Direction u, double kT);
Direction sample_cxs_target_velocity(double awr, double E, Direction u, double kT,
uint64_t * prn_seeds, int stream);

void sample_fission_neutron(int i_nuclide, const Reaction* rx, double E_in, Particle::Bank* site);
void sample_fission_neutron(int i_nuclide, const Reaction* rx, double E_in, Particle::Bank* site,
uint64_t * prn_seeds, int stream);

//! handles all reactions with a single secondary neutron (other than fission),
//! i.e. level scattering, (n,np), (n,na), etc.
Expand Down
2 changes: 1 addition & 1 deletion include/openmc/plot.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ void create_voxel(Plot pl);

//! Create a randomly generated RGB color
//! \return RGBColor with random value
RGBColor random_color();
RGBColor random_color(uint64_t * prn_seeds, int stream);


} // namespace openmc
Expand Down
Loading

0 comments on commit 5502f38

Please sign in to comment.