Implementation of C++ Sum1D function

This commit is contained in:
Paul Romano 2021-10-13 07:26:43 -05:00
parent 925a5f6bb6
commit d024a3e008
2 changed files with 46 additions and 0 deletions

View file

@ -126,6 +126,26 @@ private:
debye_waller_; //!< Debye-Waller integral divided by atomic mass in [eV^-1]
};
//==============================================================================
//! Sum of multiple 1D functions
//==============================================================================
class Sum1D : public Function1D {
public:
// Constructors
explicit Sum1D(hid_t group);
//! Evaluate each function and sum results
//! \param[in] x independent variable
//! \return Function evaluated at x
double operator()(double E) const override;
const unique_ptr<Function1D>& functions(int i) const { return functions_[i]; }
private:
vector<unique_ptr<Function1D>> functions_; //!< individual functions
};
//! Read 1D function from HDF5 dataset
//! \param[in] group HDF5 group containing dataset
//! \param[in] name Name of dataset

View file

@ -271,4 +271,30 @@ double IncoherentElasticXS::operator()(double E) const
return bound_xs_ / 2.0 * ((1 - std::exp(-4.0 * E * W)) / (2.0 * E * W));
}
//==============================================================================
// Sum1D implementation
//==============================================================================
Sum1D::Sum1D(hid_t group)
{
// Get number of functions
int n;
read_attribute(group, "n", n);
// Get each function
for (int i = 0; i < n; ++i) {
auto dset_name = fmt::format("func_{}", i + 1);
functions_.push_back(read_function(group, dset_name.c_str()));
}
}
double Sum1D::operator()(double x) const
{
double result = 0.0;
for (auto& func : functions_) {
result += (*func)(x);
}
return result;
}
} // namespace openmc