36const G4double G4JTPolynomialSolver::base = 2;
47 G4double t = 0.0, aa = 0.0, bb = 0.0, cc = 0.0, factor = 1.0;
48 G4double max = 0.0, min = infin, xxx = 0.0, x = 0.0, sc = 0.0, bnd = 0.0;
49 G4double xm = 0.0, ff = 0.0, df = 0.0, dx = 0.0;
50 G4int cnt = 0, nz = 0, i = 0, j = 0, jj = 0, l = 0, nm1 = 0, zerok = 0;
55 static const G4double xx = std::sqrt(0.5);
56 static const G4double rot = 94.0 * deg;
57 static const G4double cosr = std::cos(rot), sinr = std::sin(rot);
70 while(!(op[n] != 0.0))
84 std::vector<G4double> temp(degr + 1);
85 std::vector<G4double> pt(degr + 1);
87 p.assign(degr + 1, 0);
88 qp.assign(degr + 1, 0);
89 k.assign(degr + 1, 0);
90 qk.assign(degr + 1, 0);
91 svk.assign(degr + 1, 0);
95 for(i = 0; i <= n; ++i)
104 zeror[degr - 1] = -p[1] / p[0];
105 zeroi[degr - 1] = 0.0;
111 Quadratic(p[0], p[1], p[2], &zeror[degr - 2], &zeroi[degr - 2],
112 &zeror[degr - 1], &zeroi[degr - 1]);
121 for(i = 0; i <= n; ++i)
128 if(x != 0.0 && x < min)
142 if(((sc <= 1.0) && (max >= 10.0)) || ((sc > 1.0) && (infin / sc >= max)) ||
143 ((infin / sc >= max) && (max >= 10)))
150 factor = power->
powN(base, l);
153 for(i = 0; i <= n; ++i)
155 p[i] = factor * p[i];
162 for(i = 0; i <= n; ++i)
164 pt[i] = (std::fabs(p[i]));
176 xm = -pt[n] / pt[n - 1];
189 for(i = 1; i <= n; ++i)
191 ff = ff * xm + pt[i];
203 while(std::fabs(dx / x) > 0.005)
207 for(i = 1; i < n; ++i)
222 for(i = 1; i < n; ++i)
229 zerok =
static_cast<G4int>(k[n - 1] == 0);
230 for(jj = 0; jj < 5; ++jj)
238 for(i = 0; i < nm1; ++i)
241 k[j] = t * k[j - 1] + p[j];
245 static_cast<G4int>(std::fabs(k[n - 1]) <= std::fabs(bb) * eta * 10.0);
249 for(i = 0; i < nm1; ++i)
255 zerok =
static_cast<G4int>(!(k[n - 1] != 0.0));
261 for(i = 0; i < n; ++i)
268 for(cnt = 0; cnt < 20; ++cnt)
275 xxx = cosr * xo - sinr * yo;
276 yo = sinr * xo + cosr * yo;
282 ComputeFixedShiftPolynomial(20 * (cnt + 1), &nz);
294 for(i = 0; i <= n; ++i)
309 for(i = 0; i < n; ++i)
322void G4JTPolynomialSolver::ComputeFixedShiftPolynomial(
G4int l2,
G4int* nz)
328 G4double svu = 0.0, svv = 0.0, ui = 0.0, vi = 0.0, xs = 0.0;
329 G4double betas = 0.25, betav = 0.25, oss = sr, ovv = v, ss = 0.0, vv = 0.0,
333 G4int type = 0, i = 0, j = 0, iflag = 0, vpass = 0, spass = 0, vtry = 0,
340 QuadraticSyntheticDivision(n, &u, &v, p, qp, &a, &b);
341 ComputeScalarFactors(&type);
342 for(j = 0; j < l2; ++j)
346 ComputeNextPolynomial(&type);
347 ComputeScalarFactors(&type);
348 ComputeNewEstimate(type, &ui, &vi);
356 ss = -p[n] / k[n - 1];
360 if(j == 0 || type == 3)
373 tv = std::fabs((vv - ovv) / vv);
377 ts = std::fabs((ss - oss) / ss);
393 vpass =
static_cast<G4int>(tvv < betav);
394 spass =
static_cast<G4int>(tss < betas);
395 if(!((spass != 0) || (vpass != 0)))
409 for(i = 0; i < n; ++i)
419 if(((spass != 0) && (vpass == 0)) || (tss < tvv))
421 RealPolynomialIteration(&xs, nz, &iflag);
434 goto _restore_variables;
444 _quadratic_iteration:
448 QuadraticPolynomialIteration(&ui, &vi, nz);
463 if((stry != 0) || (spass == 0))
467 for(i = 0; i <
n; ++i)
471 RealPolynomialIteration(&xs, nz, &iflag);
500 for(i = 0; i <
n; ++i)
508 if((vpass != 0) && (vtry == 0))
510 goto _quadratic_iteration;
516 QuadraticSyntheticDivision(n, &u, &v, p, qp, &a, &b);
517 ComputeScalarFactors(&type);
526void G4JTPolynomialSolver::QuadraticPolynomialIteration(
G4double* uu,
538 G4double mp = 0.0, ee = 0.0, t = 0.0, zm = 0.0;
539 G4int type = 0, i = 1, j = 0, tried = 0;
550 Quadratic(1.0, u, v, &szr, &szi, &lzr, &lzi);
556 if(std::fabs(std::fabs(szr) - std::fabs(lzr)) > 0.01 * std::fabs(lzr))
563 QuadraticSyntheticDivision(n, &u, &v, p, qp, &a, &b);
564 mp = std::fabs(a - szr * b) + std::fabs(szi * b);
568 zm = std::sqrt(std::fabs(v));
569 ee = 2.0 * std::fabs(qp[0]);
571 for(i = 1; i <
n; ++i)
573 ee = ee * zm + std::fabs(qp[i]);
575 ee = ee * zm + std::fabs(a + t);
576 ee *= (5.0 * mre + 4.0 * are);
577 ee = ee - (5.0 * mre + 2.0 * are) * (std::fabs(a + t) + std::fabs(b) * zm) +
578 2.0 * are * std::fabs(t);
598 if(!(relstp > 0.01 || mp < omp || (tried != 0)))
607 relstp = std::sqrt(relstp);
610 QuadraticSyntheticDivision(n, &u, &v, p, qp, &a, &b);
611 for(i = 0; i < 5; ++i)
613 ComputeScalarFactors(&type);
614 ComputeNextPolynomial(&type);
624 ComputeScalarFactors(&type);
625 ComputeNextPolynomial(&type);
626 ComputeScalarFactors(&type);
627 ComputeNewEstimate(type, &ui, &vi);
635 relstp = std::fabs((vi - v) / vi);
641void G4JTPolynomialSolver::RealPolynomialIteration(
G4double* sss,
G4int* nz,
651 G4double pv = 0.0, kv = 0.0, xs = *sss;
652 G4double mx = 0.0, mp = 0.0, ee = 0.0;
667 for(i = 1; i <=
n; ++i)
677 ee = (mre / (are + mre)) * std::fabs(qp[0]);
678 for(i = 1; i <=
n; ++i)
680 ee = ee * mx + std::fabs(qp[i]);
686 if(mp <= 20.0 * ((are + mre) * ee - mre * mp))
703 if(!(std::fabs(t) > 0.001 * std::fabs(xs - t) || mp < omp))
720 for(i = 1; i <
n; ++i)
725 if(std::fabs(kv) <= std::fabs(k[n - 1]) * 10.0 * eta)
728 for(i = 1; i <
n; ++i)
737 for(i = 1; i <
n; ++i)
739 k[i] = t * qk[i - 1] + qp[i];
743 for(i = 1; i <
n; ++i)
748 if(std::fabs(kv) > std::fabs(k[n - 1] * 10.0 * eta))
756void G4JTPolynomialSolver::ComputeScalarFactors(
G4int* type)
766 QuadraticSyntheticDivision(n - 1, &u, &v, k, qk, &c, &d);
767 if(std::fabs(c) <= std::fabs(k[n - 1] * 100.0 * eta))
769 if(std::fabs(d) <= std::fabs(k[n - 2] * 100.0 * eta))
776 if(std::fabs(d) < std::fabs(c))
783 a3 = a * e + (h / c + g) * b;
784 a1 = b - a * (d / c);
785 a7 = a + g * d + h * f;
793 a3 = (a + g) * e + h * (b / d);
795 a7 = (f + u) * a + h;
798void G4JTPolynomialSolver::ComputeNextPolynomial(
G4int* type)
809 for(i = 2; i <
n; ++i)
820 if(std::fabs(a1) <= std::fabs(temp) * eta * 10.0)
826 for(i = 2; i <
n; ++i)
828 k[i] = a3 * qk[i - 2] - a7 * qp[i - 1];
838 k[1] = qp[1] - a7 * qp[0];
839 for(i = 2; i <
n; ++i)
841 k[i] = a3 * qk[i - 2] - a7 * qp[i - 1] + qp[i];
845void G4JTPolynomialSolver::ComputeNewEstimate(
G4int type,
G4double* uu,
851 G4double a4 = 0.0, a5 = 0.0, b1 = 0.0, b2 = 0.0, c1 = 0.0, c2 = 0.0, c3 = 0.0,
852 c4 = 0.0, temp = 0.0;
864 a4 = (a + g) * f + h;
865 a5 = (f + u) * c + v * d;
869 a4 = a + u * b + h * f;
870 a5 = c + (u + v * f) * d;
875 b1 = -k[
n - 1] / p[
n];
876 b2 = -(k[
n - 2] + b1 * p[
n - 1]) / p[n];
881 temp = a5 + b1 * a4 - c4;
888 *uu = u - (u * (c3 + c2) + v * (b1 * a1 + b2 * a7)) / temp;
889 *vv = v * (1.0 + c4 / temp);
893void G4JTPolynomialSolver::QuadraticSyntheticDivision(
903 *aa =
pp[1] - (*bb) * (*uu);
907 cc =
pp[i] - (*aa) * (*uu) - (*bb) * (*vv);
924 G4double bb = 0.0, dd = 0.0, ee = 0.0;
953 if(std::fabs(bb) < std::fabs(cc))
963 ee = bb * (bb / std::fabs(cc)) - ee;
964 dd = std::sqrt(std::fabs(ee)) * std::sqrt(std::fabs(cc));
968 ee = 1.0 - (aa / bb) * (cc / bb);
969 dd = std::sqrt(std::fabs(ee)) * std::fabs(bb);
975 *ssi = std::fabs(dd / aa);
984 *lr = (-bb + dd) / aa;
988 *ssr = (cc / *lr) / aa;
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
G4double G4Log(G4double x)
G4int FindRoots(G4double *op, G4int degree, G4double *zeror, G4double *zeroi)
static G4Pow * GetInstance()
G4double powN(G4double x, G4int n) const