24 #ifndef __LEGENDRE_PROSHADE__ 25 #define __LEGENDRE_PROSHADE__ 33 #include <rvapi_interface.h> 61 double prevPoly = 1.0;
62 double prevPrevPoly = 0.0;
63 double prevDeri = 0.0;
64 double prevPrevDeri = 0.0;
66 for (
unsigned int ordIt = 0; ordIt < order; ordIt++ )
68 hlpVal =
static_cast<double> ( ordIt );
69 *polyValue = -hlpVal * prevPrevPoly / ( hlpVal + 1.0 );
70 *deriValue = ( ( 2.0 * hlpVal + 1.0 ) * prevPoly - hlpVal * prevPrevDeri ) / ( hlpVal + 1.0 );
71 prevPrevPoly = prevPoly;
72 prevPoly = *polyValue;
73 prevPrevDeri = prevDeri;
74 prevDeri = *deriValue;
98 unsigned int noSteps )
102 double stepSize = 0.0;
103 double valChange = 0.0;
104 double valSecChange = 0.0;
105 double squareSteps = 0.0;
107 unsigned int taylorSeriesCap = 10;
109 stepSize = ( to - from ) / static_cast<double> ( taylorSeriesCap );
110 squareSteps = sqrt ( static_cast<double> ( noSteps * ( noSteps + 1 ) ) );
113 for (
unsigned int iter = 0; iter < taylorSeriesCap; iter++ )
115 hlpVal = ( 1.0 - valAtFrom ) * ( 1.0 + valAtFrom );
116 valChange = - stepSize * hlpVal / ( squareSteps * sqrt ( hlpVal ) - 0.5 * valAtFrom * sin ( 2.0 * curVal ) );
117 valAtFrom = valAtFrom + valChange;
119 curVal = curVal + stepSize;
121 hlpVal = ( 1.0 - valAtFrom ) * ( 1.0 + valAtFrom );
122 valSecChange = - stepSize * hlpVal / ( squareSteps * sqrt ( hlpVal ) - 0.5 * valAtFrom * sin ( 2.0 * curVal ) );
123 valAtFrom = valAtFrom + 0.5 * ( valSecChange - valChange );
149 double factorialValue = 1.0;
152 for (
unsigned int iter = 1; iter <= terms; iter++ )
154 value = value + series[iter] * factorialValue;
155 factorialValue = factorialValue * target;
179 double *weighAtZero )
184 double hlpVal =
static_cast<double> ( order );
185 unsigned int taylorSeriesCap = 30;
190 abscSteps =
new double [taylorSeriesCap+2];
191 weightSteps =
new double [taylorSeriesCap+1];
195 abscSteps[1] = polyAtZero;
196 weightSteps[0] = 0.0;
199 for (
unsigned int iter = 0; iter <= taylorSeriesCap - 2; iter = iter + 2 )
201 hlp =
static_cast<double> ( iter );
203 abscSteps[iter+2] = 0.0;
204 abscSteps[iter+3] = ( hlp * ( hlp + 1.0 ) - hlpVal * ( hlpVal + 1.0 ) ) * abscSteps[iter+1] / (hlp + 1.0) / (hlp + 2.0 );
206 weightSteps[iter+1] = 0.0;
207 weightSteps[iter+2] = ( hlp + 2.0 ) * abscSteps[iter+3];
211 for (
unsigned int iter = 0; iter < 5; iter++ )
213 *abscAtZero = *abscAtZero -
evaluateSeries ( abscSteps, *abscAtZero, taylorSeriesCap ) /
evaluateSeries ( weightSteps, *abscAtZero, taylorSeriesCap-1 );
240 std::vector<double>* abscissa,
241 std::vector<double>* weights )
244 double hlpTaylorVal = 0.0;
245 double hlpOrderVal =
static_cast<double> ( order );
246 double abscValueChange = 0.0;
247 double prevAbsc = 0.0;
248 double *hlpAbscSeries;
249 double *hlpWeightSeries;
250 unsigned int taylorSeriesCap = 30;
251 unsigned int noSeriesElems = 0;
252 unsigned int oddEvenSwitch = 0;
255 if ( order % 2 == 1 )
257 noSeriesElems = ( order - 1 ) / 2 - 1;
262 noSeriesElems = order / 2 - 1;
267 hlpAbscSeries =
new double[taylorSeriesCap+2];
268 hlpWeightSeries =
new double[taylorSeriesCap+1];
271 for (
unsigned int serIt = noSeriesElems + 1; serIt < order - 1; serIt++ )
274 prevAbsc = abscissa->at(serIt);
275 abscValueChange =
advancePolyValue ( M_PI/2.0, -M_PI/2.0, prevAbsc, order ) - prevAbsc;
278 hlpAbscSeries[0] = 0.0;
279 hlpAbscSeries[1] = 0.0;
280 hlpAbscSeries[2] = weights->at(serIt);
283 hlpWeightSeries[0] = 0.0;
284 hlpWeightSeries[1] = hlpAbscSeries[2];
287 for (
unsigned int tayIt = 0; tayIt <= taylorSeriesCap - 2; tayIt++ )
289 hlpTaylorVal =
static_cast<double> ( tayIt );
291 hlpAbscSeries[tayIt+3] = ( 2.0 * prevAbsc * ( hlpTaylorVal + 1.0 ) * hlpAbscSeries[tayIt+2]
292 + ( hlpTaylorVal * ( hlpTaylorVal + 1.0 ) - hlpOrderVal * ( hlpOrderVal + 1.0 ) ) * hlpAbscSeries[tayIt+1] /
293 ( hlpTaylorVal + 1.0 ) ) / ( 1.0 - prevAbsc ) / ( 1.0 + prevAbsc ) / ( hlpTaylorVal + 2.0 );
295 hlpWeightSeries[tayIt+2] = ( hlpTaylorVal + 2.0 ) * hlpAbscSeries[tayIt+3];
299 for (
unsigned int iter = 0; iter < 5; iter++ )
301 abscValueChange = abscValueChange -
evaluateSeries ( hlpAbscSeries, abscValueChange, taylorSeriesCap ) /
302 evaluateSeries ( hlpWeightSeries, abscValueChange, taylorSeriesCap-1 );
306 abscissa->at(serIt+1) = prevAbsc + abscValueChange;
307 weights->at(serIt+1) =
evaluateSeries ( hlpWeightSeries, abscValueChange, taylorSeriesCap - 1 );
310 for (
unsigned int serIt = 0; serIt <= noSeriesElems + oddEvenSwitch; serIt++ )
312 abscissa->at(serIt) = - abscissa->at(order-serIt-1);
313 weights->at(serIt) = weights->at(order-serIt-1);
317 delete hlpAbscSeries;
318 delete hlpWeightSeries;
338 std::vector<double>* abscissa,
339 std::vector<double>* weights,
345 std::cerr <<
"!!! ProSHADE ERROR !!! Trying to compute legendre quadrature with order " << order <<
" which seems too low!" << std::endl;
349 std::stringstream hlpSS;
350 hlpSS <<
"<font color=\"red\">" <<
"The automatic determination of the Gauss-Legendre integration order has determined the optimal order to be less than 1. This may happen for very small maps, if this is the case, please manually set the integration value to 10-ish and re-run. If the map is reasonably large, please report this as a bug." <<
"</font>";
351 rvapi_set_text ( hlpSS.str().c_str(),
365 double polyValue = 0.0;
366 double deriValue = 0.0;
367 double weightSum = 0.0;
375 if ( order % 2 == 1 )
377 abscissa->at((order-1)/2) = polyValue;
378 weights->at((order-1)/2) = deriValue;
383 getFirstEvenRoot ( polyValue, order, &abscissa->at(order/2), &weights->at(order/2) );
392 for (
unsigned int iter = 0; iter < order; iter++ )
394 weights->at(iter) = 2.0 / ( 1.0 - abscissa->at(iter) ) / ( 1.0 + abscissa->at(iter) ) / weights->at(iter) / weights->at(iter);
395 weightSum = weightSum + weights->at(iter);
399 for (
unsigned int iter = 0; iter < order; iter++ )
401 weights->at(iter) = 2.0 * weights->at(iter) / weightSum;
double advancePolyValue(double from, double to, double valAtFrom, unsigned int noSteps)
This function finds the next value of the polynomial.
bool htmlReport
Should HTML report for the run be created?
int htmlReportLineProgress
Iterator for current HTML line in the progress bar.
void completeLegendreSeries(unsigned int order, std::vector< double > *abscissa, std::vector< double > *weights)
This function completes the Legendre polynomial series assuming you have obtained the first values...
void getPolyAtZero(unsigned int order, double *polyValue, double *deriValue)
This function obtains the Legendre polynomial values and its derivative at zero for any positive inte...
void getFirstEvenRoot(double polyAtZero, unsigned int order, double *abscAtZero, double *weighAtZero)
This function finds the first root for Legendre polynomials of odd order.
This class stores all the settings and is passed to the executive classes instead of multitude of par...
void getLegendreAbscAndWeights(unsigned int order, std::vector< double > *abscissa, std::vector< double > *weights, ProSHADE::ProSHADE_settings *settings)
This function takes everytging together and computes the abscissas and weights for the Gauss-Legendre...
double evaluateSeries(double *series, double target, unsigned int terms)
This function evaluates the Taylor expansion.