Skip to content

Commit 43d0ccc

Browse files
committed
SA before merge upstream
1 parent 1bf5e12 commit 43d0ccc

8 files changed

Lines changed: 450 additions & 257 deletions

File tree

include/openmc/particle_data.h

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ struct SourceSite {
4848
double time {0.0};
4949
double wgt {1.0};
5050
int delayed_group {0};
51-
int surf_id {0};
5251
int fission_nuclide;
5352
int surf_id {SURFACE_NONE};
5453
ParticleType particle;
@@ -434,11 +433,13 @@ class ParticleData : public GeometryState {
434433
double E_;
435434
double E_last_;
436435
double E_parent_; //!< energy of parent neutron in eV
436+
double E_pprod_;
437437
int g_ {0};
438438
int g_last_;
439439

440440
// Other birth data
441441
int fission_nuclide_; //!< this particle was born as a result of this nuclide fissioning
442+
int pprod_nuclide_;
442443
// a double for fission cross section at birth? if so, I need to also add it to the bank...
443444

444445
double wgt_ {1.0};
@@ -480,6 +481,9 @@ class ParticleData : public GeometryState {
480481
vector<double> flux_derivs_;
481482

482483
std::vector<std::vector<double>> cumulative_sensitivities_; // for sensitivities for this particle
484+
std::vector<std::vector<double>> cum_sens_;
485+
std::vector<std::vector<double>> pprod_sens_;
486+
double neutron_flux_last_ = 0.0;
483487

484488
vector<FilterMatch> filter_matches_;
485489

@@ -544,6 +548,8 @@ class ParticleData : public GeometryState {
544548
const double& E_last() const { return E_last_; }
545549
double& E_parent() { return E_parent_; } // for sensitivity analysis
546550
const double& E_parent() const { return E_parent_; } // for SA
551+
double& E_pprod() { return E_pprod_; }
552+
const double& E_pprod() const { return E_pprod_; }
547553
int& g() { return g_; }
548554
const int& g() const { return g_; }
549555
int& g_last() { return g_last_; }
@@ -645,8 +651,17 @@ class ParticleData : public GeometryState {
645651
// Used in sensitivity analysis
646652
std::vector<double>& cumulative_sensitivities(int i) { return cumulative_sensitivities_[i]; }
647653
const std::vector<double>& cumulative_sensitivities(int i) const { return cumulative_sensitivities_[i]; }
654+
std::vector<double>& cum_sens(int i) { return cum_sens_[i]; }
655+
const std::vector<double>& cum_sens(int i) const { return cum_sens_[i]; }
656+
std::vector<double>& pprod_sens(int i) { return pprod_sens_[i]; }
657+
const std::vector<double>& pprod_sens(int i) const { return pprod_sens_[i]; }
658+
double neutron_flux_last() const { return neutron_flux_last_; }
659+
648660
int& fission_nuclide() { return fission_nuclide_; }
649661
const int& fission_nuclide() const { return fission_nuclide_; }
662+
663+
int& pprod_nuclide() { return pprod_nuclide_; }
664+
const int& pprod_nuclide() const { return pprod_nuclide_; }
650665

651666
// Matches of tallies
652667
decltype(filter_matches_)& filter_matches() { return filter_matches_; }
@@ -732,6 +747,26 @@ class ParticleData : public GeometryState {
732747
cumulative_sensitivities_[indx].resize(newSize, 0.0);
733748
}
734749

750+
void resize_init_cum_sens(int newSize)
751+
{
752+
cum_sens_.resize(newSize, {0.0});
753+
}
754+
755+
void resize_init_cum_sens_vec(int indx, int newSize)
756+
{
757+
cum_sens_[indx].resize(newSize, 0.0);
758+
}
759+
760+
void resize_init_pprod_sens(int newSize)
761+
{
762+
pprod_sens_.resize(newSize, {0.0});
763+
}
764+
765+
void resize_init_pprod_sens_vec(int indx, int newSize)
766+
{
767+
pprod_sens_[indx].resize(newSize, 0.0);
768+
}
769+
735770
void resize_alloc_filter_matches(int newSize)
736771
{
737772
filter_matches_.resize(newSize);
@@ -749,6 +784,25 @@ class ParticleData : public GeometryState {
749784
std::fill(it.begin(), it.end(), 0.0);
750785
}
751786
}
787+
788+
void initialize_cum_sens()
789+
{
790+
for (auto& it : cum_sens_){
791+
std::fill(it.begin(), it.end(), 0.0);
792+
}
793+
}
794+
795+
void initialize_pprod_sens()
796+
{
797+
for (auto& it : pprod_sens_){
798+
std::fill(it.begin(), it.end(), 0.0);
799+
}
800+
}
801+
802+
void set_neutron_flux_last(double v)
803+
{
804+
neutron_flux_last_ = v;
805+
}
752806
};
753807

754808
} // namespace openmc

include/openmc/simulation.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ void initialize_history(Particle& p, int64_t index_source);
7575
//! Helper function for initialize_history() that is called independently elsewhere
7676
void initialize_history_partial(Particle& p);
7777

78+
void initialize_history_in_part(Particle& p);
79+
7880
//! Finalize a batch
7981
//!
8082
//! Handles synchronization and accumulation of tallies, calculation of Shannon

include/openmc/tallies/sensitivity.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ struct TallySensitivity {
7474
int sens_reaction; //!< Need something to specify reaction, use ReactionType?
7575
int sens_material; //!< Material the sensitivity is calculated in
7676
int sens_cell; //!< Cell the sensitivity is calculated in
77-
std::vector<double> energy_bins_; //!< Energy bins on which to discretize the cross section
77+
std::vector<double> energy_bins_; //!< Energy bins on which to tally the sensitivity
7878
int n_bins_; //!< something to indicate the size of the vector
7979

8080
TallySensitivity() {}
@@ -112,7 +112,7 @@ void score_collision_sensitivity(Particle& p);
112112
//! \param distance The distance in [cm] traveled by the particle
113113
void score_track_sensitivity(Particle& p, double distance);
114114

115-
void score_source_sensitivity(Particle& p);
115+
void score_pprod_sensitivity(Particle& p);
116116

117117
} // namespace openmc
118118

include/openmc/tallies/tally_scoring.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void score_surface_tally(Particle& p, const vector<int>& tallies);
9999

100100
//! Function to handle the special case when the tally is a sensitivity tally.
101101
void score_collision_sensitivity_tally(Particle& p, int i_tally, int start_index, int filter_index,
102-
double filter_weight, int i_nuclide, double atom_density, double flux);
102+
double filter_weight, int i_nuclide, double atom_density, double flux, double neutron_flux);
103103

104104
//! Score the pulse-height tally
105105
//! This is triggered at the end of every particle history

src/particle.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ bool Particle::create_secondary(
9696
}
9797
bank.time = time();
9898
bank_second_E() += bank.E;
99-
// if (!model::active_tallies.empty()) score_source_sensitivity(*this);
10099
return true;
101100
}
102101

@@ -130,7 +129,7 @@ void Particle::from_source(const SourceSite* src)
130129
fission() = false;
131130
zero_flux_derivs();
132131

133-
initialize_cumulative_sensitivities();
132+
initialize_cumulative_sensitivities();
134133
lifetime() = 0.0;
135134

136135
// Copy attributes from source bank site
@@ -163,6 +162,12 @@ void Particle::from_source(const SourceSite* src)
163162
int index_plus_one = model::surface_map[std::abs(src->surf_id)] + 1;
164163
surface() = (src->surf_id > 0) ? index_plus_one : -index_plus_one;
165164
}
165+
166+
if (src->particle == ParticleType::neutron) {
167+
initialize_cum_sens();
168+
initialize_pprod_sens();
169+
}
170+
166171
}
167172

168173
void Particle::event_calculate_xs()
@@ -418,7 +423,7 @@ void Particle::event_collide()
418423
if (!model::active_tallies.empty()) {
419424
score_collision_derivative(*this);
420425
score_collision_sensitivity(*this); // Score cumulative sensitivity for sensitivity tallies.
421-
// score_source_sensitivity(*this);
426+
// score_pprod_sensitivity(*this);
422427
}
423428

424429
#ifdef DAGMC
@@ -476,7 +481,7 @@ void Particle::event_revive_from_secondary()
476481
n_coord_last() = n_coord();
477482
}
478483
pht_secondary_particles();
479-
}
484+
}
480485

481486
// Enter new particle in particle track file
482487
if (write_track())

src/simulation.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ void initialize_history(Particle& p, int64_t index_source)
641641
add_particle_track(p);
642642

643643
initialize_history_partial(p);
644+
initialize_history_in_part(p);
644645
}
645646

646647
void initialize_history_partial(Particle& p)
@@ -664,6 +665,33 @@ void initialize_history_partial(Particle& p)
664665
p.resize_alloc_filter_matches(model::tally_filters.size());
665666
}
666667

668+
void initialize_history_in_part(Particle& p)
669+
{
670+
671+
if (p.type() == ParticleType::photon) return;
672+
673+
// for n-p coupled simulation
674+
// and sensitivity of photon responses (heating, dose) to neutron cross-sections
675+
// initialized variable to store derivatives of neutron transport operator
676+
// needed for photon transport sensitivity to neutron data
677+
if (!model::active_tallies.empty())
678+
{
679+
680+
p.resize_init_cum_sens(model::tally_sens.size());
681+
for (int idx=0; idx< model::tally_sens.size();idx++){
682+
p.resize_init_cum_sens_vec(idx, model::tally_sens[idx].n_bins_);
683+
}
684+
685+
p.resize_init_pprod_sens(model::tally_sens.size());
686+
for (int idx=0; idx< model::tally_sens.size();idx++){
687+
p.resize_init_pprod_sens_vec(idx, model::tally_sens[idx].n_bins_);
688+
}
689+
}
690+
691+
// Allocate space for tally filter matches
692+
// p.resize_alloc_filter_matches(model::tally_filters.size());
693+
}
694+
667695
int overall_generation()
668696
{
669697
using namespace simulation;

0 commit comments

Comments
 (0)