36const G4double G4JTPolynomialSolver::base = 2;
51 G4double t = 0.0, aa = 0.0, bb = 0.0, cc = 0.0, factor = 1.0;
52 G4double max = 0.0, min = infin, xxx = 0.0, x = 0.0, sc = 0.0, bnd = 0.0;
53 G4double xm = 0.0, ff = 0.0, df = 0.0, dx = 0.0;
54 G4int cnt = 0, nz = 0, i = 0, j = 0, jj = 0, l = 0, nm1 = 0, zerok = 0;
59 static const G4double xx = std::sqrt(0.5);
60 static const G4double rot = 94.0 * deg;
61 static const G4double cosr = std::cos(rot), sinr = std::sin(rot);
74 while(!(op[n] != 0.0))
88 std::vector<G4double> temp(degr + 1);
89 std::vector<G4double> pt(degr + 1);
91 p.assign(degr + 1, 0);
92 qp.assign(degr + 1, 0);
93 k.assign(degr + 1, 0);
94 qk.assign(degr + 1, 0);
95 svk.assign(degr + 1, 0);
99 for(i = 0; i <= n; ++i)
108 zeror[degr - 1] = -p[1] / p[0];
109 zeroi[degr - 1] = 0.0;
115 Quadratic(p[0], p[1], p[2], &zeror[degr - 2], &zeroi[degr - 2],
116 &zeror[degr - 1], &zeroi[degr - 1]);
125 for(i = 0; i <= n; ++i)
132 if(x != 0.0 && x < min)
146 if(((sc <= 1.0) && (max >= 10.0)) || ((sc > 1.0) && (infin / sc >= max)) ||
147 ((infin / sc >= max) && (max >= 10)))
154 factor = power->
powN(base, l);
157 for(i = 0; i <= n; ++i)
159 p[i] = factor * p[i];
166 for(i = 0; i <= n; ++i)
168 pt[i] = (std::fabs(p[i]));
180 xm = -pt[n] / pt[n - 1];
193 for(i = 1; i <= n; ++i)
195 ff = ff * xm + pt[i];
207 while(std::fabs(dx / x) > 0.005)
211 for(i = 1; i < n; ++i)
226 for(i = 1; i < n; ++i)
233 zerok = (k[n - 1] == 0);
234 for(jj = 0; jj < 5; ++jj)
242 for(i = 0; i < nm1; ++i)
245 k[j] = t * k[j - 1] + p[j];
248 zerok = (std::fabs(k[n - 1]) <= std::fabs(bb) * eta * 10.0);
252 for(i = 0; i < nm1; ++i)
258 zerok = (!(k[n - 1] != 0.0));
264 for(i = 0; i < n; ++i)
271 for(cnt = 0; cnt < 20; ++cnt)
278 xxx = cosr * xo - sinr * yo;
279 yo = sinr * xo + cosr * yo;
285 ComputeFixedShiftPolynomial(20 * (cnt + 1), &nz);
297 for(i = 0; i <= n; ++i)
313 for(i = 0; i < n; ++i)
326void G4JTPolynomialSolver::ComputeFixedShiftPolynomial(
G4int l2,
G4int* nz)
332 G4double svu = 0.0, svv = 0.0, ui = 0.0, vi = 0.0, xs = 0.0;
333 G4double betas = 0.25, betav = 0.25, oss = sr, ovv = v, ss = 0.0, vv = 0.0,
337 G4int type = 0, i = 0, j = 0, iflag = 0, vpass = 0, spass = 0, vtry = 0,
344 QuadraticSyntheticDivision(n, &u, &v, p, qp, &a, &b);
345 ComputeScalarFactors(&type);
346 for(j = 0; j < l2; ++j)
350 ComputeNextPolynomial(&type);
351 ComputeScalarFactors(&type);
352 ComputeNewEstimate(type, &ui, &vi);
360 ss = -p[n] / k[n - 1];
364 if(j == 0 || type == 3)
377 tv = std::fabs((vv - ovv) / vv);
381 ts = std::fabs((ss - oss) / ss);
397 vpass = (tvv < betav);
398 spass = (tss < betas);
399 if(!(spass || vpass))
413 for(i = 0; i < n; ++i)
423 if((spass && (!vpass)) || (tss < tvv))
425 RealPolynomialIteration(&xs, nz, &iflag);
438 goto _restore_variables;
448 _quadratic_iteration:
452 QuadraticPolynomialIteration(&ui, &vi, nz);
471 for(i = 0; i <
n; ++i)
475 RealPolynomialIteration(&xs, nz, &iflag);
504 for(i = 0; i <
n; ++i)
514 goto _quadratic_iteration;
520 QuadraticSyntheticDivision(n, &u, &v, p, qp, &a, &b);
521 ComputeScalarFactors(&type);
530void G4JTPolynomialSolver::QuadraticPolynomialIteration(
G4double* uu,
542 G4double mp = 0.0, ee = 0.0, t = 0.0, zm = 0.0;
543 G4int type = 0, i = 1, j = 0, tried = 0;
554 Quadratic(1.0, u, v, &szr, &szi, &lzr, &lzi);
560 if(std::fabs(std::fabs(szr) - std::fabs(lzr)) > 0.01 * std::fabs(lzr))
567 QuadraticSyntheticDivision(n, &u, &v, p, qp, &a, &b);
568 mp = std::fabs(a - szr * b) + std::fabs(szi * b);
572 zm = std::sqrt(std::fabs(v));
573 ee = 2.0 * std::fabs(qp[0]);
575 for(i = 1; i <
n; ++i)
577 ee = ee * zm + std::fabs(qp[i]);
579 ee = ee * zm + std::fabs(a + t);
580 ee *= (5.0 * mre + 4.0 * are);
581 ee = ee - (5.0 * mre + 2.0 * are) * (std::fabs(a + t) + std::fabs(b) * zm) +
582 2.0 * are * std::fabs(t);
602 if(!(relstp > 0.01 || mp < omp || tried))
611 relstp = std::sqrt(relstp);
614 QuadraticSyntheticDivision(n, &u, &v, p, qp, &a, &b);
615 for(i = 0; i < 5; ++i)
617 ComputeScalarFactors(&type);
618 ComputeNextPolynomial(&type);
628 ComputeScalarFactors(&type);
629 ComputeNextPolynomial(&type);
630 ComputeScalarFactors(&type);
631 ComputeNewEstimate(type, &ui, &vi);
639 relstp = std::fabs((vi - v) / vi);
645void G4JTPolynomialSolver::RealPolynomialIteration(
G4double* sss,
G4int* nz,
655 G4double pv = 0.0, kv = 0.0, xs = *sss;
656 G4double mx = 0.0, mp = 0.0, ee = 0.0;
671 for(i = 1; i <=
n; ++i)
681 ee = (mre / (are + mre)) * std::fabs(qp[0]);
682 for(i = 1; i <=
n; ++i)
684 ee = ee * mx + std::fabs(qp[i]);
690 if(mp <= 20.0 * ((are + mre) * ee - mre * mp))
707 if(!(std::fabs(t) > 0.001 * std::fabs(xs - t) || mp < omp))
724 for(i = 1; i <
n; ++i)
729 if(std::fabs(kv) <= std::fabs(k[n - 1]) * 10.0 * eta)
732 for(i = 1; i <
n; ++i)
741 for(i = 1; i <
n; ++i)
743 k[i] = t * qk[i - 1] + qp[i];
747 for(i = 1; i <
n; ++i)
752 if(std::fabs(kv) > std::fabs(k[n - 1] * 10.0 * eta))
760void G4JTPolynomialSolver::ComputeScalarFactors(
G4int* type)
770 QuadraticSyntheticDivision(n - 1, &u, &v, k, qk, &c, &d);
771 if(std::fabs(c) <= std::fabs(k[n - 1] * 100.0 * eta))
773 if(std::fabs(d) <= std::fabs(k[n - 2] * 100.0 * eta))
780 if(std::fabs(d) < std::fabs(c))
787 a3 = a * e + (h / c + g) * b;
788 a1 = b - a * (d / c);
789 a7 = a + g * d + h * f;
797 a3 = (a + g) * e + h * (b / d);
799 a7 = (f + u) * a + h;
802void G4JTPolynomialSolver::ComputeNextPolynomial(
G4int* type)
813 for(i = 2; i <
n; ++i)
824 if(std::fabs(a1) <= std::fabs(temp) * eta * 10.0)
830 for(i = 2; i <
n; ++i)
832 k[i] = a3 * qk[i - 2] - a7 * qp[i - 1];
842 k[1] = qp[1] - a7 * qp[0];
843 for(i = 2; i <
n; ++i)
845 k[i] = a3 * qk[i - 2] - a7 * qp[i - 1] + qp[i];
849void G4JTPolynomialSolver::ComputeNewEstimate(
G4int type,
G4double* uu,
855 G4double a4 = 0.0, a5 = 0.0, b1 = 0.0, b2 = 0.0, c1 = 0.0, c2 = 0.0, c3 = 0.0,
856 c4 = 0.0, temp = 0.0;
868 a4 = (a + g) * f + h;
869 a5 = (f + u) * c + v * d;
873 a4 = a + u * b + h * f;
874 a5 = c + (u + v * f) * d;
879 b1 = -k[
n - 1] / p[
n];
880 b2 = -(k[
n - 2] + b1 * p[
n - 1]) / p[n];
885 temp = a5 + b1 * a4 - c4;
892 *uu = u - (u * (c3 + c2) + v * (b1 * a1 + b2 * a7)) / temp;
893 *vv = v * (1.0 + c4 / temp);
897void G4JTPolynomialSolver::QuadraticSyntheticDivision(
907 *aa =
pp[1] - (*bb) * (*uu);
911 cc =
pp[i] - (*aa) * (*uu) - (*bb) * (*vv);
928 G4double bb = 0.0, dd = 0.0, ee = 0.0;
957 if(std::fabs(bb) < std::fabs(cc))
967 ee = bb * (bb / std::fabs(cc)) - ee;
968 dd = std::sqrt(std::fabs(ee)) * std::sqrt(std::fabs(cc));
972 ee = 1.0 - (aa / bb) * (cc / bb);
973 dd = std::sqrt(std::fabs(ee)) * std::fabs(bb);
979 *ssi = std::fabs(dd / aa);
988 *lr = (-bb + dd) / aa;
992 *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