|
| 1 | +#ifndef OPENMC_IFP_H |
| 2 | +#define OPENMC_IFP_H |
| 3 | + |
| 4 | +#include "openmc/message_passing.h" |
| 5 | +#include "openmc/particle.h" |
| 6 | +#include "openmc/particle_data.h" |
| 7 | +#include "openmc/settings.h" |
| 8 | + |
| 9 | +namespace openmc { |
| 10 | + |
| 11 | +//! Check the value of the IFP parameter for beta effective or both. |
| 12 | +//! |
| 13 | +//! \return true if "BetaEffective" or "Both", false otherwise. |
| 14 | +bool is_beta_effective_or_both(); |
| 15 | + |
| 16 | +//! Check the value of the IFP parameter for generation time or both. |
| 17 | +//! |
| 18 | +//! \return true if "GenerationTime" or "Both", false otherwise. |
| 19 | +bool is_generation_time_or_both(); |
| 20 | + |
| 21 | +//! Resize IFP vectors |
| 22 | +//! |
| 23 | +//! \param[in,out] delayed_groups List of delayed group numbers |
| 24 | +//! \param[in,out] lifetimes List of lifetimes |
| 25 | +//! \param[in] n Dimension to resize vectors |
| 26 | +template<typename T, typename U> |
| 27 | +void resize_ifp_data(vector<T>& delayed_groups, vector<U>& lifetimes, int64_t n) |
| 28 | +{ |
| 29 | + if (is_beta_effective_or_both()) { |
| 30 | + delayed_groups.resize(n); |
| 31 | + } |
| 32 | + if (is_generation_time_or_both()) { |
| 33 | + lifetimes.resize(n); |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +//! Update a list of values by adding a new value if the size |
| 38 | +//! of the list can accomodate the new value or by shifting all |
| 39 | +//! values to the left (removing the first value of the list |
| 40 | +//! and adding the new value at the end of the list). |
| 41 | +//! |
| 42 | +//! \param[in] value Value to add to the list |
| 43 | +//! \param[in] data Initial version of the list |
| 44 | +//! \return Updated list |
| 45 | +template<typename T> |
| 46 | +vector<T> _ifp(const T& value, const vector<T>& data) |
| 47 | +{ |
| 48 | + vector<T> updated; |
| 49 | + size_t source_idx = data.size(); |
| 50 | + |
| 51 | + if (source_idx < settings::ifp_n_generation) { |
| 52 | + updated.resize(source_idx + 1); |
| 53 | + for (size_t i = 0; i < source_idx; i++) { |
| 54 | + updated[i] = data[i]; |
| 55 | + } |
| 56 | + updated[source_idx] = value; |
| 57 | + } else if (source_idx == settings::ifp_n_generation) { |
| 58 | + updated.resize(source_idx); |
| 59 | + for (size_t i = 0; i < source_idx - 1; i++) { |
| 60 | + updated[i] = data[i + 1]; |
| 61 | + } |
| 62 | + updated[source_idx - 1] = value; |
| 63 | + } |
| 64 | + return updated; |
| 65 | +} |
| 66 | + |
| 67 | +//! \brief Iterated Fission Probability (IFP) method. |
| 68 | +//! |
| 69 | +//! Add the IFP information in the IFP banks using the same index |
| 70 | +//! as the one used to append the fission site to the fission bank. |
| 71 | +//! Multithreading protection is guaranteed by the index returned by the |
| 72 | +//! thread_safe_append call in physics.cpp. |
| 73 | +//! |
| 74 | +//! Needs to be done after the delayed group is found. |
| 75 | +//! |
| 76 | +//! \param[in] p Particle |
| 77 | +//! \param[in] site Fission site |
| 78 | +//! \param[in] idx Bank index from the thread_safe_append call in physics.cpp |
| 79 | +void ifp(const Particle& p, const SourceSite& site, int64_t idx); |
| 80 | + |
| 81 | +//! Resize the IFP banks used in the simulation |
| 82 | +void resize_simulation_ifp_banks(); |
| 83 | + |
| 84 | +//! Retrieve IFP data from the IFP fission banks. |
| 85 | +//! |
| 86 | +//! \param[in] i_bank Index in the fission banks |
| 87 | +//! \param[in,out] delayed_groups Delayed group numbers |
| 88 | +//! \param[in,out] lifetimes Lifetimes lists |
| 89 | +void copy_ifp_data_from_fission_banks( |
| 90 | + int i_bank, vector<int>& delayed_groups, vector<double>& lifetimes); |
| 91 | + |
| 92 | +#ifdef OPENMC_MPI |
| 93 | + |
| 94 | +//! Deserialization information for transfer of IFP data using MPI |
| 95 | +struct DeserializationInfo { |
| 96 | + int64_t index_local; //!< local index |
| 97 | + int64_t n; //!< number of sites sent |
| 98 | +}; |
| 99 | + |
| 100 | +//! Broadcast the number of generation determined by the size of the first |
| 101 | +//! element on the first processor. |
| 102 | +//! |
| 103 | +//! \param[in] n_generation Number of generations |
| 104 | +//! \param[in] delayed_groups List of delayed group numbers lists |
| 105 | +//! \param[in] lifetimes List of lifetimes lists |
| 106 | +void broadcast_ifp_n_generation(int& n_generation, |
| 107 | + const vector<vector<int>>& delayed_groups, |
| 108 | + const vector<vector<double>>& lifetimes); |
| 109 | + |
| 110 | +//! Send IFP data using MPI. |
| 111 | +//! |
| 112 | +//! \param[in] idx Index of the first site |
| 113 | +//! \param[in] n Number of sites to send |
| 114 | +//! \param[in] n_generation Number of generations |
| 115 | +//! \param[in] neighbor Index of the neighboring processor |
| 116 | +//! \param[in] requests MPI requests |
| 117 | +//! \param[in] delayed_groups List of delayed group numbers lists |
| 118 | +//! \param[out] send_delayed_groups Delayed group numbers buffer |
| 119 | +//! \param[in] lifetimes List of lifetimes lists |
| 120 | +//! \param[out] send_lifetimes Lifetimes buffer |
| 121 | +void send_ifp_info(int64_t idx, int64_t n, int n_generation, int neighbor, |
| 122 | + vector<MPI_Request>& requests, const vector<vector<int>>& delayed_groups, |
| 123 | + vector<int>& send_delayed_groups, const vector<vector<double>>& lifetimes, |
| 124 | + vector<double>& send_lifetimes); |
| 125 | + |
| 126 | +//! Receive IFP data using MPI. |
| 127 | +//! |
| 128 | +//! \param[in] idx Index of the first site |
| 129 | +//! \param[in] n Number of sites to receive |
| 130 | +//! \param[in] n_generation Number of generations |
| 131 | +//! \param[in] neighbor Index of the neighboring processor |
| 132 | +//! \param[in] requests MPI requests |
| 133 | +//! \param[in] delayed_groups List of delayed group numbers |
| 134 | +//! \param[in] lifetimes List of lifetimes |
| 135 | +//! \param[out] deserialization Information to deserialize the received data |
| 136 | +void receive_ifp_data(int64_t idx, int64_t n, int n_generation, int neighbor, |
| 137 | + vector<MPI_Request>& requests, vector<int>& delayed_groups, |
| 138 | + vector<double>& lifetimes, vector<DeserializationInfo>& deserialization); |
| 139 | + |
| 140 | +//! Copy partial IFP data from local lists to source banks. |
| 141 | +//! |
| 142 | +//! \param[in] idx Index of the first site |
| 143 | +//! \param[in] n Number of sites to copy |
| 144 | +//! \param[in] i_bank Index in the IFP source banks |
| 145 | +//! \param[in] delayed_groups List of delayed group numbers lists |
| 146 | +//! \param[in] lifetimes List of lifetimes lists |
| 147 | +void copy_partial_ifp_data_to_source_banks(int64_t idx, int n, int64_t i_bank, |
| 148 | + const vector<vector<int>>& delayed_groups, |
| 149 | + const vector<vector<double>>& lifetimes); |
| 150 | + |
| 151 | +//! Deserialize IFP information received using MPI and store it in |
| 152 | +//! the IFP source banks. |
| 153 | +//! |
| 154 | +//! \param[in] n_generation Number of generations |
| 155 | +//! \param[out] deserialization Information to deserialize the received data |
| 156 | +//! \param[in] delayed_groups List of delayed group numbers |
| 157 | +//! \param[in] lifetimes List of lifetimes |
| 158 | +void deserialize_ifp_info(int n_generation, |
| 159 | + const vector<DeserializationInfo>& deserialization, |
| 160 | + const vector<int>& delayed_groups, const vector<double>& lifetimes); |
| 161 | + |
| 162 | +#endif |
| 163 | + |
| 164 | +//! Copy IFP temporary vectors to source banks. |
| 165 | +//! |
| 166 | +//! \param[in] delayed_groups List of delayed group numbers lists |
| 167 | +//! \param[in] lifetimes List of lifetimes lists |
| 168 | +void copy_complete_ifp_data_to_source_banks( |
| 169 | + const vector<vector<int>>& delayed_groups, |
| 170 | + const vector<vector<double>>& lifetimes); |
| 171 | + |
| 172 | +//! Allocate temporary vectors for IFP data. |
| 173 | +//! |
| 174 | +//! \param[in,out] delayed_groups List of delayed group numbers lists |
| 175 | +//! \param[in,out] lifetimes List of delayed group numbers lists |
| 176 | +void allocate_temporary_vector_ifp( |
| 177 | + vector<vector<int>>& delayed_groups, vector<vector<double>>& lifetimes); |
| 178 | + |
| 179 | +//! Copy local IFP data to IFP fission banks. |
| 180 | +//! |
| 181 | +//! \param[in] delayed_groups_ptr Pointer to delayed group numbers |
| 182 | +//! \param[in] lifetimes_ptr Pointer to lifetimes |
| 183 | +void copy_ifp_data_to_fission_banks( |
| 184 | + const vector<int>* delayed_groups_ptr, const vector<double>* lifetimes_ptr); |
| 185 | + |
| 186 | +} // namespace openmc |
| 187 | + |
| 188 | +#endif // OPENMC_IFP_H |
0 commit comments