Skip to content

Commit

Permalink
refactored matrixreal and sigp methods
Browse files Browse the repository at this point in the history
  • Loading branch information
van4elotti committed Dec 6, 2020
1 parent e87e822 commit 1fa9cdc
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 116 deletions.
18 changes: 18 additions & 0 deletions include/openbps/matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,14 @@ class DecayMatrix : public BaseMatrix<double> {
//! Form a real decay nuclide matrix
//!
//!\param[in] chain with decay information and fill the data storage
//!\param[in] material with nuclear concentration
//!\return result a matrix with all transition for the material
xt::xarray<double> get_matrix_real(Chain& chain,
const Materials& mat, std::string matrix_kind);
//! Methods
//! Form a real decay nuclide matrix
//!
//!\param[in] chain with decay information and fill the data storage
void form_matrixreal(Chain& chain);
//! Form a deviation decay nuclide matrix for unceratanties analysis
//!
Expand Down Expand Up @@ -315,6 +323,16 @@ class IterMatrix : public DecayMatrix {
//!\return result a vector with all transition for every nuclide:Dev
xt::xarray<double> dsigp(Chain& chain,
const Materials& mat);
//! Utility for functions sigp(...) and dsigp(...)
//!
//!\param[in] chain with decay information and fill the data storage
//!\param[in] material with nuclear concentration
//!\param[in] boolean var (true for dsigp, false for sigps)
//!\return result a vector with all transition for every
//!nuclide:Dev in case of d == true nuclide:Real in case d == false
xt::xarray<double> formSigp(Chain& chain,
const Materials& mat,
bool d);

}; //class IterMatrix

Expand Down
154 changes: 38 additions & 116 deletions src/matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,8 @@ void DecayMatrix::form_matrixdev(Chain& chain) {
}
}

//==============================================================================
// IterativeMatrix implementation
//==============================================================================

//! Methods
//! Form a real decay nuclide matrix
xt::xarray<double> IterMatrix::matrixreal(Chain& chain,
const Materials& mat) {
xt::xarray<double> DecayMatrix::get_matrix_real(Chain& chain,
const Materials& mat, std::string matrix_kind) {
// Variables for calculation fissiop product yields by spectrum
std::pair<std::vector<double>, std::vector<double>> pair2;
std::vector<double> weight;
Expand All @@ -94,7 +88,8 @@ xt::xarray<double> IterMatrix::matrixreal(Chain& chain,
for (size_t i = 0; i < NN; i++) {
std::copy(&this->data_[i][0], &this->data_[i][NN],
(result.begin() + i * NN));
result(i, i) = 0.0;
if (matrix_kind == "iter")
result(i, i) = 0.0;
}
int icompos {mat.numcomposition};
if (icompos > -1) {
Expand Down Expand Up @@ -147,14 +142,27 @@ xt::xarray<double> IterMatrix::matrixreal(Chain& chain,
} // fission yields
} // if reaction = chain.reaction
} // run over reaction
if (matrix_kind == "cram")
result(i, i) -= rr * PWD * mat.normpower;
} // if nuclide is in crossection data and chain
} // for xslib in composition
} // if composition is presented
} // for all nuclides

return result;
}

//==============================================================================
// IterativeMatrix implementation
//==============================================================================

//! Methods
//! Form a real decay nuclide matrix
xt::xarray<double> IterMatrix::matrixreal(Chain& chain,
const Materials& mat) {
// Variables for calculation fissiop product yields by spectrum
return DecayMatrix::get_matrix_real(chain, mat, "iter");
}

//! Form a deviation decay nuclide matrix for unceratanties analysis
xt::xarray<double> IterMatrix::matrixdev(Chain& chain,
const Materials& mat) {
Expand All @@ -169,7 +177,7 @@ xt::xarray<double> IterMatrix::matrixdev(Chain& chain,
for (size_t i = 0; i < NN; i++) {
std::copy(&this->data_[i][0], &this->data_[i][NN],
(result.begin() + i * NN));
result(i, i) = 0.0;
result(i, i) = 0.0; // ------------------
}
int icompos {mat.numcomposition};
if (icompos > -1) {
Expand All @@ -186,7 +194,7 @@ xt::xarray<double> IterMatrix::matrixdev(Chain& chain,
double rr {0.0};
// Sum reaction-rates over energy group
for (auto& r: obj.rxs)
rr += r.Dev();
rr += r.Dev();//------------------
// Iterate over chain nuclides transition
for (auto& r : nuclides[inucl]->get_reactions()) {
// If match
Expand Down Expand Up @@ -230,22 +238,23 @@ xt::xarray<double> IterMatrix::matrixdev(Chain& chain,
return result;
}

//! Form a dev decay nuclide vector for all transition from every nuclide
xt::xarray<double> IterMatrix::sigp(Chain& chain,
const Materials& mat) {

xt::xarray<double> IterMatrix::formSigp(Chain& chain,
const Materials& mat,
bool d) {
std::vector<size_t> shape {chain.name_idx.size()};
xt::xarray<double> result(shape, 0.0);
udouble decay_ {0.0, 0.0};
//Run over all nuclides
if (configure::verbose)
if (configure::verbose && !d)
std::cout << "SIGP: "<<std::endl;
for (auto it = chain.name_idx.begin(); it != chain.name_idx.end(); it++) {
size_t inucl = it->second; // from nuclide

size_t i = chain.get_nuclide_index(it->first);
if (nuclides[inucl]->half_life.Real() > 0) {
decay_ = (log(2.0) / nuclides[inucl]->half_life);
result(i) = decay_.Real();
result(i) = d ? decay_.Dev() : decay_.Real();
}
int icompos {mat.numcomposition};
if (icompos > -1) {
Expand All @@ -256,51 +265,31 @@ xt::xarray<double> IterMatrix::sigp(Chain& chain,
double rr {0.0};
// Sum reaction-rates over energy group
for (auto& r: obj.rxs)
rr += r.Real();
rr += d ? r.Dev() : r.Real() ;
result(i) += rr * PWD * mat.normpower;
}
}
}
if (configure::verbose)
if (configure::verbose && !d)
std::cout << "sigp: " << it->first << " " << result(i)<<std::endl;
}

return result;
}

//! Form a dev decay nuclide vector for all transition from every nuclide
xt::xarray<double> IterMatrix::dsigp(Chain& chain,
const Materials& mat) {
std::vector<size_t> shape {chain.name_idx.size()};
xt::xarray<double> result(shape, 0.0);
udouble decay_ {0.0, 0.0};
//Run over all nuclides
for (auto it = chain.name_idx.begin(); it != chain.name_idx.end(); it++) {
size_t inucl = it->second; // from nuclide
xt::xarray<double> IterMatrix::sigp(Chain& chain,
const Materials& mat) {
return formSigp(chain, mat, false);
}

size_t i = chain.get_nuclide_index(it->first);
if (nuclides[inucl]->half_life.Real() > 0) {
decay_ = (log(2.0) / nuclides[inucl]->half_life);
result(i) = decay_.Dev();
}
int icompos {mat.numcomposition};
if (icompos > -1) {
// For xslib
for (auto& obj : compositions[icompos]->xslib) {
// If cross section presented for nuclides
if (obj.xsname == it->first) {
double rr {0.0};
// Sum reaction-rates over energy group
for (auto& r: obj.rxs)
rr += r.Dev();
result(i) += rr * PWD * mat.normpower;
}
}
}
}
return result;
//! Form a dev decay nuclide vector for all transition from every nuclide
xt::xarray<double> IterMatrix::dsigp(Chain& chain,
const Materials& mat) {
return formSigp(chain, mat, true);
}


//==============================================================================
// ChebyshevMatrix implementation
//==============================================================================
Expand All @@ -309,74 +298,7 @@ xt::xarray<double> IterMatrix::dsigp(Chain& chain,
xt::xarray<double> CramMatrix::matrixreal(Chain& chain,
const Materials& mat) {
// Variables for calculation fissiop product yields by spectrum
std::pair<std::vector<double>, std::vector<double>> pair2;
std::vector<double> weight;
size_t k {0};
//
size_t NN {chain.name_idx.size()}; //!< Nuclide number
std::vector<std::size_t> shape = { NN, NN };
xt::xarray<double> result(shape, 0.0);
for (size_t i = 0; i < NN; i++)
std::copy(&this->data_[i][0], &this->data_[i][NN],
(result.begin() + i * NN));
int icompos {mat.numcomposition};
if (icompos > -1) {
// Get neutron flux - energy value descretization
pair2 = compositions[icompos]->get_fluxenergy();
for (auto it = chain.name_idx.begin();
it != chain.name_idx.end(); it++) {
size_t inucl = it->second; // from nuclide
size_t i = chain.get_nuclide_index(it->first);
// For xslib
for (auto& obj : compositions[icompos]->xslib) {
// If cross section presented for nuclides
if (obj.xsname == it->first) {
double rr {0.0};
// Sum reaction-rates over energy group
for (auto& r: obj.rxs)
rr += r.Real();
// Iterate over chain nuclides transition
for (auto& r : nuclides[inucl]->get_reactions()) {
// If match
if (r.first == obj.xstype) {
if (obj.xstype != "fission") {
// And non-fission then add
size_t k = chain.get_nuclide_index(r.second);
result(k, i) += rr * PWD * mat.normpower;
} else {
// Considering fission reaction by energy separately
std::vector<double> energies =
nuclides[inucl]->get_nfy_energies();
// Fission yields by product
for (auto& item: nuclides[inucl]->
get_yield_product()) {
k = chain.get_nuclide_index(item.first);
double br {0.0};
double norm {0.0};
if (weight.empty())
weight = transition(pair2.first,
pair2.second,
energies);
for (int l = 0; l < weight.size(); l++) {
br += weight[l] * item.second[l];
norm += weight[l];
} // for weight

result(k, i) += br / norm * rr * PWD *
mat.normpower;
norm = 1.0;
} // for product
weight.clear();
} // fission yields
} // if reaction = chain.reaction
} // run over reaction
result(i, i) -= rr * PWD * mat.normpower;
} // if nuclide is in crossection data and chain
} // for xslib in composition
} // if composition is presented
} // for all nuclides

return result;
return DecayMatrix::get_matrix_real(chain, mat, "cram");
}

//==============================================================================
Expand Down

0 comments on commit 1fa9cdc

Please sign in to comment.