22 double integrate(std::function<
double(
double)>& func,
double low,
double high) {
31 wi[0] = 0.16105444984878362;
32 xi[1] = 0.16035862813102394;
33 wi[1] = 0.15896882598519965;
36 xi[3] = 0.3165642266117781;
37 wi[3] = 0.1527663007284602;
40 xi[5] = 0.46457038687717755;
41 wi[5] = 0.1426055640976579;
44 xi[7] = 0.6005459122435153;
45 wi[7] = 0.1287567549009922;
48 xi[9] = 0.7209655043062628;
49 wi[9] = 0.11156236184219351;
52 xi[11] = 0.8227150489105877;
53 wi[11] = 0.09149349482553046;
56 xi[13] = 0.9031559802279142;
57 wi[13] = 0.06904552773838758;
60 xi[15] = 0.9602078316107117;
61 wi[15] = 0.044807508218039215;
64 xi[17] = 0.9924070086164836;
65 wi[17] = 0.019469784466159833;
69 for (
int i = 0; i < n; ++i) {
70 double yi = (high - low) * xi[i] / 2.0 + (high + low) / 2.0;
71 double dGi = func(yi);
75 value *= (high - low) / 2.0;
80 Integrator::Integrator() {
91 _baseWeights = {0.16105444984878362, 0.15896882598519965, 0.1527663007284602, 0.1426055640976579,
92 0.1287567549009922, 0.11156236184219351, 0.09149349482553046, 0.06904552773838758,
93 0.044807508218039215, 0.019469784466159833};
94 for (
size_t j = 1; j < 10; ++j) {
95 _basePoints.push_back(-_basePoints[j]);
96 _baseWeights.push_back(_baseWeights[j]);
100 Integrator::~Integrator() {
101 _evaluationPoints.clear();
102 _evaluationWeights.clear();
104 _baseWeights.clear();
108 return _evaluationPoints;
112 return _evaluationWeights;
116 auto tmpboundaries = move(boundaries);
117 applyRange(tmpboundaries);
121 size_t totN =
static_cast<size_t>(pow(_basePoints.size(), boundaries.size()));
122 ASSERT(totN < numeric_limits<uint16_t>::max() && totN > 0);
123 ASSERT(boundaries.size() > 0);
124 vector<double> tmp(boundaries.size(), 0.);
125 _evaluationPoints.clear();
126 _evaluationPoints.reserve(totN);
127 _evaluationPoints.insert(_evaluationPoints.end(), totN, tmp);
129 size_t outerStride = _evaluationPoints.size();
130 for (
size_t i = 0; i < boundaries.size(); ++i) {
131 outerStride /= (i == 0) ? 1 : _basePoints.size();
132 size_t currentStride = outerStride / _basePoints.size();
133 for (
size_t jOut = 0; jOut < _evaluationPoints.size(); jOut += outerStride) {
134 auto coords = _evaluationPoints[jOut];
136 auto range = boundaries[i](coords);
137 double sum = (range.second + range.first) / 2.;
138 double diff = (range.second - range.first) / 2.;
139 for (
size_t k = 0; k < _basePoints.size(); ++k) {
140 size_t delta = k * currentStride;
141 for (
size_t jIn = 0; jIn < currentStride; ++jIn) {
142 size_t pos = jOut + delta + jIn;
143 _evaluationWeights[pos] *= _baseWeights[k] * diff;
144 _evaluationPoints[pos][i] = sum + diff * _basePoints[k];
151 uint16_t Integrator::getPointsNumber()
const {
152 return static_cast<uint16_t
>(_basePoints.size());
double integrate(std::function< double(double)> &func, double low, double high)
integration function based on gaussian method
std::vector< BoundaryFunction > IntegrationBoundaries
Hammer exception definitions.
Hammer numerical integration classes.
std::vector< double > EvaluationWeights
TensorData sum(TensorData origin, const IContainer &other)
std::vector< std::vector< double >> EvaluationGrid