Skip to content

Commit

Permalink
Use FMA in planck integration
Browse files Browse the repository at this point in the history
+ Use FMA operation in the taylor series expansion planck intergral
+ Use FMA operation in the summation when collapsing plank integral
  • Loading branch information
alexrlongne committed Jul 9, 2021
1 parent dcb5c56 commit fa900c9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/cdi/CDI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ double CDI::collapseMultigroupOpacitiesPlanck(std::vector<double> const &groupBo
for (size_t g = 1; g < groupBounds.size(); ++g) {
Check(planckSpectrum[g - 1] >= 0.0);
Check(opacity[g - 1] >= 0.0);
sig_planck_sum += planckSpectrum[g - 1] * opacity[g - 1];
sig_planck_sum = FMA(planckSpectrum[g - 1], opacity[g - 1], sig_planck_sum);
// Also collect some CDF data.
emission_group_cdf[g - 1] = sig_planck_sum;
}
Expand Down Expand Up @@ -597,7 +597,7 @@ double CDI::collapseMultigroupOpacitiesPlanck(std::vector<double> const &groupBo
for (size_t g = 1; g < groupBounds.size(); ++g) {
Check(planckSpectrum[g - 1] >= 0.0);
Check(opacity[g - 1] >= 0.0);
sig_planck_sum += planckSpectrum[g - 1] * opacity[g - 1];
sig_planck_sum = FMA(planckSpectrum[g - 1], opacity[g - 1], sig_planck_sum);
}

// int_{\nu_0}^{\nu_G}{d\nu sigma(\nu,T) * B(\nu,T)}
Expand Down
41 changes: 11 additions & 30 deletions src/cdi/CDI.hh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "GrayOpacity.hh"
#include "MultigroupOpacity.hh"
#include "ds++/Constexpr_Functions.hh"
#include "ds++/FMA.hh"
#include "ds++/Soft_Equivalence.hh"
#include <algorithm>
#include <array>
Expand Down Expand Up @@ -80,36 +81,16 @@ static inline double taylor_series_planck(double x) {

double const xsqrd = x * x;

double taylor(coeff_21 * xsqrd);

taylor += coeff_19;
taylor *= xsqrd;

taylor += coeff_17;
taylor *= xsqrd;

taylor += coeff_15;
taylor *= xsqrd;

taylor += coeff_13;
taylor *= xsqrd;

taylor += coeff_11;
taylor *= xsqrd;

taylor += coeff_9;
taylor *= xsqrd;

taylor += coeff_7;
taylor *= xsqrd;

taylor += coeff_5;
taylor *= x;

taylor += coeff_4;
taylor *= x;

taylor += coeff_3;
double taylor = FMA(xsqrd, coeff_21, coeff_19);
taylor = FMA(taylor, xsqrd, coeff_17);
taylor = FMA(taylor, xsqrd, coeff_15);
taylor = FMA(taylor, xsqrd, coeff_13);
taylor = FMA(taylor, xsqrd, coeff_11);
taylor = FMA(taylor, xsqrd, coeff_9);
taylor = FMA(taylor, xsqrd, coeff_7);
taylor = FMA(taylor, xsqrd, coeff_5);
taylor = FMA(taylor, x, coeff_4);
taylor = FMA(taylor, x, coeff_3);
taylor *= x * xsqrd * coeff;

Ensure(taylor >= 0.0);
Expand Down

0 comments on commit fa900c9

Please sign in to comment.