8 #include <lifev/navier_stokes/function/bessel/bessel.hpp> 12 double gamma (
double);
14 static std::complex<
double>
cii (0.0, 1.0);
15 static std::complex<
double>
cone (1.0, 0.0);
16 static std::complex<
double>
czero (0.0, 0.0);
18 int cbessjy01 (std::complex<
double> z, std::complex<
double>& cj0, std::complex<
double>& cj1,
19 std::complex<
double>& cy0, std::complex<
double>& cy1, std::complex<
double>& cj0p,
20 std::complex<
double>& cj1p, std::complex<
double>& cy0p, std::complex<
double>& cy1p)
22 std::complex<
double> z1, z2, cr, cp, cs, cp0, cq0, cp1, cq1, ct1, ct2, cu;
38 -3.833534661393944e12,
40 -7.286857349377656e16,
54 -3.649010818849833e11,
56 -5.827244631566907e15,
71 -3.833857520742790e10,
73 -5.060568503314727e14,
89 -4.406481417852278e13,
91 -9.833883876590679e17,
102 cy0 = std::complex<
double> (-1e308, 0);
103 cy1 = std::complex<
double> (-1e308, 0);
105 cj1p = std::complex<
double> (0.5, 0.0);
106 cy0p = std::complex<
double> (1e308, 0);
107 cy1p = std::complex<
double> (1e308, 0);
118 for (k = 1; k <= 40; k++)
120 cr *= -0.25 * z2 / (
double) (k * k);
122 if (std::abs (cr) < std::abs (cj0) *
eps)
129 for (k = 1; k <= 40; k++)
131 cr *= -0.25 * z2 / (k * (k + 1.0) );
133 if (std::abs (cr) < std::abs (cj1) *
eps)
142 for (k = 1; k <= 40; k++)
145 cr *= -0.25 * z2 / (
double) (k * k);
148 if (std::abs (cp) < std::abs (cs) *
eps)
153 cy0 = M_2_PI * ( (std::log (0.5 * z1) +
el) * cj0 - cs);
157 for (k = 1; k <= 40; k++)
160 cr *= -0.25 * z2 / (k * (k + 1.0) );
161 cp = cr * (2.0 * w1 + 1.0 / (k + 1.0) );
163 if (std::abs (cp) < std::abs (cs) *
eps)
168 cy1 = M_2_PI * ( (std::log (0.5 * z1) +
el) * cj1 - 1.0 / z1 - 0.25 * z1 * cs);
186 for (k = 0; k < kz; k++)
188 cp0 += a[k] * std::pow (z1, -2.0 * k - 2.0);
191 for (k = 0; k < kz; k++)
193 cq0 += b[k] * std::pow (z1, -2.0 * k - 3.0);
195 cu = std::sqrt (M_2_PI / z1);
196 cj0 = cu * (cp0 * std::cos (ct1) - cq0 * std::sin (ct1) );
197 cy0 = cu * (cp0 * std::sin (ct1) + cq0 * std::cos (ct1) );
198 ct2 = z1 - 0.75 *
M_PI;
200 for (k = 0; k < kz; k++)
202 cp1 += a1[k] * std::pow (z1, -2.0 * k - 2.0);
205 for (k = 0; k < kz; k++)
207 cq1 += b1[k] * std::pow (z1, -2.0 * k - 3.0);
209 cj1 = cu * (cp1 * std::cos (ct2) - cq1 * std::sin (ct2) );
210 cy1 = cu * (cp1 * std::sin (ct2) + cq1 * std::cos (ct2) );
216 cy0 -= 2.0 * cii * cj0;
217 cy1 = - (cy1 - 2.0 * cii * cj1);
219 else if (imag (z) > 0.0)
221 cy0 += 2.0 * cii * cj0;
222 cy1 = - (cy1 + 2.0 * cii * cj1);
227 cj1p = cj0 - cj1 / z;
229 cy1p = cy0 - cy1 / z;
233 int cbessjyna (
int n, std::complex<
double> z,
int& nm, std::complex<
double>* cj,
234 std::complex<
double>* cy, std::complex<
double>* cjp, std::complex<
double>* cyp)
236 std::complex<
double> cbj0, cbj1, cby0, cby1, cj0, cjk, cj1, cf, cf1, cf2;
237 std::complex<
double> cs, cg0, cg1, cyk, cyl1, cyl2, cylk, cp11, cp12, cp21, cp22;
238 std::complex<
double> ch0, ch1, ch2;
239 double a0, yak, ya1, ya0, wa;
250 for (k = 0; k <= n; k++)
253 cy[k] = std::complex<
double> (-1e308, 0);
255 cyp[k] = std::complex<
double> (1e308, 0);
258 cjp[1] = std::complex<
double> (0.5, 0.0);
270 if (n < (
int) 0.25 * a0)
274 for (k = 2; k <= n; k++)
276 cjk = 2.0 * (k - 1.0) * cj1 / z - cj0;
294 cf1 = std::complex<
double> (1.0e-100, 0.0);
295 for (k = m; k >= 0; k--)
297 cf = 2.0 * (k + 1.0) * cf1 / z - cf2;
305 if (std::abs (cbj0) > std::abs (cbj1) )
313 for (k = 0; k <= nm; k++)
318 for (k = 2; k <= nm; k++)
320 cjp[k] = cj[k - 1] - (
double) k * cj[k] / z;
322 ya0 = std::abs (cby0);
326 for (k = 2; k <= nm; k++)
328 cyk = 2.0 * (k - 1.0) * cg1 / z - cg0;
329 yak = std::abs (cyk);
330 ya1 = std::abs (cg0);
331 if ( (yak < ya0) && (yak < ya1) )
340 if ( (lb > 4) && (imag (z) != 0.0) )
347 for (k = lb; k >= 1; k--)
349 ch0 = 2.0 * k * ch1 / z - ch2;
357 for (k = lb; k >= 1; k--)
359 ch0 = 2.0 * k * ch1 / z - ch2;
367 cj[lb + 1] = 2.0 * lb * cj[lb] / z - cj[lb - 1];
369 if (std::abs (cj[0]) > std::abs (cj[1]) )
371 cy[lb + 1] = (cj[lb + 1] * cby0 - 2.0 * cp11 / (
M_PI * z) ) / cj[0];
372 cy[lb] = (cj[lb] * cby0 + 2.0 * cp12 / (
M_PI * z) ) / cj[0];
376 cy[lb + 1] = (cj[lb + 1] * cby1 - 2.0 * cp21 / (
M_PI * z) ) / cj[1];
377 cy[lb] = (cj[lb] * cby1 + 2.0 * cp22 / (
M_PI * z) ) / cj[1];
381 for (k = lb - 1; k >= 0; k--)
383 cylk = 2.0 * (k + 1.0) * cyl1 / z - cyl2;
390 for (k = lb + 1; k < n; k++)
392 cylk = 2.0 * k * cyl2 / z - cyl1;
397 for (k = 2; k <= nm; k++)
399 wa = std::abs (cy[k]);
400 if (wa < std::abs (cy[k - 1]) )
407 for (k = 2; k <= nm; k++)
409 cyp[k] = cy[k - 1] - (
double) k * cy[k] / z;
414 int cbessjynb (
int n, std::complex<
double> z,
int& nm, std::complex<
double>* cj,
415 std::complex<
double>* cy, std::complex<
double>* cjp, std::complex<
double>* cyp)
417 std::complex<
double> cf, cf0, cf1, cf2, cbs, csu, csv, cs0, ce;
418 std::complex<
double> ct1, cp0, cq0, cp1, cq1, cu, cbj0, cby0, cbj1, cby1;
419 std::complex<
double> cyy, cbjk, ct2;
424 -0.7031250000000000e-1,
431 0.7324218750000000e-1,
451 y0 = std::abs (imag (z) );
456 for (k = 0; k <= n; k++)
459 cy[k] = std::complex<
double> (-1e308, 0);
461 cyp[k] = std::complex<
double> (1e308, 0);
464 cjp[1] = std::complex<
double> (0.5, 0.0);
467 if ( (a0 <= 300.0) || (n > (
int) (0.25 * a0) ) )
486 cf1 = std::complex<
double> (1.0e-100, 0.0);
487 for (k = m; k >= 0; k--)
489 cf = 2.0 * (k + 1.0) * cf1 / z - cf2;
494 if ( ( (k & 1) == 0) && (k != 0) )
502 cbs += (-1) * ( (k & 2) - 1) * 2.0 * cf;
504 csu += (
double) ( (-1) * ( (k & 2) - 1) ) * cf / (
double) k;
508 csv += (
double) ( (-1) * ( (k & 2) - 1) * k) * cf / (
double) (k * k - 1.0);
519 cs0 = (cbs + cf) / std::cos (z);
521 for (k = 0; k <= nm; k++)
525 ce = std::log (0.5 * z) +
el;
526 cy[0] = M_2_PI * (ce * cj[0] - 4.0 * csu / cs0);
527 cy[1] = M_2_PI * (-cj[0] / z + (ce - 1.0) * cj[1] - 4.0 * csv / cs0);
533 for (k = 0; k < 4; k++)
535 cp0 += a[k] * std::pow (z, -2.0 * k - 2.0);
538 for (k = 0; k < 4; k++)
540 cq0 += b[k] * std::pow (z, -2.0 * k - 3.0);
542 cu = std::sqrt (M_2_PI / z);
543 cbj0 = cu * (cp0 * std::cos (ct1) - cq0 * std::sin (ct1) );
544 cby0 = cu * (cp0 * std::sin (ct1) + cq0 * std::cos (ct1) );
547 ct2 = z - 0.75 *
M_PI;
549 for (k = 0; k < 4; k++)
551 cp1 += a1[k] * std::pow (z, -2.0 * k - 2.0);
554 for (k = 0; k < 4; k++)
556 cq1 += b1[k] * std::pow (z, -2.0 * k - 3.0);
558 cbj1 = cu * (cp1 * std::cos (ct2) - cq1 * std::sin (ct2) );
559 cby1 = cu * (cp1 * std::sin (ct2) + cq1 * std::cos (ct2) );
562 for (k = 2; k <= n; k++)
564 cbjk = 2.0 * (k - 1.0) * cbj1 / z - cbj0;
571 for (k = 1; k <= nm; k++)
573 cjp[k] = cj[k - 1] - (
double) k * cj[k] / z;
575 if (std::abs (cj[0]) > 1.0)
577 cy[1] = (cj[1] * cy[0] - 2.0 / (
M_PI * z) ) / cj[0];
579 for (k = 2; k <= nm; k++)
581 if (std::abs (cj[k - 1]) >= std::abs (cj[k - 2]) )
583 cyy = (cj[k] * cy[k - 1] - 2.0 / (
M_PI * z) ) / cj[k - 1];
587 cyy = (cj[k] * cy[k - 2] - 4.0 * (k - 1.0) / (
M_PI * z * z) ) / cj[k - 2];
592 for (k = 1; k <= nm; k++)
594 cyp[k] = cy[k - 1] - (
double) k * cy[k] / z;
600 int cbessjyva (
double v, std::complex<
double> z,
double& vm, std::complex<
double>* cjv,
601 std::complex<
double>* cyv, std::complex<
double>* cjvp, std::complex<
double>* cyvp)
603 std::complex<
double> z1, z2, zk, cjvl, cr, ca, cjv0, cjv1, cpz, crp;
604 std::complex<
double> cqz, crq, ca0, cck, csk, cyv0, cyv1, cju0, cju1, cb;
605 std::complex<
double> cs, cs0, cr0, cs1, cr1, cec, cf, cf0, cf1, cf2;
606 std::complex<
double> cfac0, cfac1, cg0, cg1, cyk, cp11, cp12, cp21, cp22;
607 std::complex<
double> ch0, ch1, ch2, cyl1, cyl2, cylk;
609 double a0, v0, pv0, pv1, vl, ga, gb, vg, vv, w0, w1, ya0, yak, ya1, wa;
610 int j, n, k, kz, l, lb, lb0, m;
621 pv1 =
M_PI * (1.0 + v0);
624 for (k = 0; k <= n; k++)
627 cyv[k] = std::complex<
double> (-1e308, 0);
629 cyvp[k] = std::complex<
double> (1e308, 0);
635 cjvp[1] = std::complex<
double> (0.5, 0.0);
639 cjvp[0] = std::complex<
double> (1e308, 0);
650 for (l = 0; l < 2; l++)
655 for (k = 1; k <= 40; k++)
657 cr *= -0.25 * z2 / (k * (k + vl) );
659 if (std::abs (cr) < std::abs (cjvl) *
eps)
666 ca = std::pow (0.5 * z1, vl) / ga;
691 for (j = 0; j < 2; j++)
693 vv = 4.0 * (j + v0) * (j + v0);
696 for (k = 1; k <= kz; k++)
698 crp = -0.78125e-2 * crp * (vv - std::pow (4.0 * k - 3.0, 2.0) ) *
699 (vv - std::pow (4.0 * k - 1.0, 2.0) ) / (k * (2.0 * k - 1.0) * z2);
704 for (k = 1; k <= kz; k++)
706 crq = -0.78125e-2 * crq * (vv - std::pow (4.0 * k - 1.0, 2.0) ) *
707 (vv - std::pow (4.0 * k + 1.0, 2.0) ) / (k * (2.0 * k + 1.0) * z2);
710 cqz *= 0.125 * (vv - 1.0) / z1;
711 zk = z1 - (0.5 * (j + v0) + 0.25) *
M_PI;
712 ca0 = std::sqrt (M_2_PI / z1);
717 cjv0 = ca0 * (cpz * cck - cqz * csk);
718 cyv0 = ca0 * (cpz * csk + cqz + cck);
722 cjv1 = ca0 * (cpz * cck - cqz * csk);
723 cyv1 = ca0 * (cpz * csk + cqz * cck);
731 for (l = 0; l < 2; l++)
736 for (k = 1; k <= 40; k++)
738 cr *= -0.25 * z2 / (k * (k - vl) );
740 if (std::abs (cr) < std::abs (cjvl) *
eps)
747 cb = std::pow (2.0 / z1, vl) / gb;
757 cyv0 = (cjv0 * std::cos (pv0) - cju0) / std::sin (pv0);
758 cyv1 = (cjv1 * std::cos (pv1) - cju1) / std::sin (pv1);
762 cec = std::log (0.5 * z1) +
el;
766 for (k = 1; k <= 30; k++)
769 cr0 *= -0.25 * z2 / (
double) (k * k);
772 cyv0 = M_2_PI * (cec * cjv0 - cs0);
776 for (k = 1; k <= 30; k++)
779 cr1 *= -0.25 * z2 / (k * (k + 1.0) );
780 cs1 += cr1 * (2.0 * w1 + 1.0 / (k + 1.0) );
782 cyv1 = M_2_PI * (cec * cjv1 - 1.0 / z1 - 0.25 * z1 * cs1);
787 cfac0 = std::exp (pv0 * cii);
788 cfac1 = std::exp (pv1 * cii);
791 cyv0 = cfac0 * cyv0 - 2.0 * cii * std::cos (pv0) * cjv0;
792 cyv1 = cfac1 * cyv1 - 2.0 * cii * std::cos (pv1) * cjv1;
796 else if (imag (z) > 0.0)
798 cyv0 = cyv0 / cfac0 + 2.0 * cii * std::cos (pv0) * cjv0;
799 cyv1 = cyv1 / cfac1 + 2.0 * cii * std::cos (pv1) * cjv1;
806 if ( (n >= 2) && (n <= (
int) (0.25 * a0) ) )
810 for (k = 2; k <= n; k++)
812 cf = 2.0 * (k + v0 - 1.0) * cf1 / z - cf0;
830 cf1 = std::complex<
double> (1.0e-100, 0.0);
831 for (k = m; k >= 0; k--)
833 cf = 2.0 * (v0 + k + 1.0) * cf1 / z - cf2;
841 if (std::abs (cjv0) > std::abs (cjv1) )
849 for (k = 0; k <= n; k++)
854 cjvp[0] = v0 * cjv[0] / z - cjv[1];
855 for (k = 1; k <= n; k++)
857 cjvp[k] = - (k + v0) * cjv[k] / z + cjv[k - 1];
861 ya0 = std::abs (cyv0);
865 for (k = 2; k <= n; k++)
867 cyk = 2.0 * (v0 + k - 1.0) * cg1 / z - cg0;
868 yak = std::abs (cyk);
869 ya1 = std::abs (cg0);
870 if ( (yak < ya0) && (yak < ya1) )
879 if ( (lb > 4) && (imag (z) != 0.0) )
886 for (k = lb; k >= 1; k--)
888 ch0 = 2.0 * (k + v0) * ch1 / z - ch2;
896 for (k = lb; k >= 1; k--)
898 ch0 = 2.0 * (k + v0) * ch1 / z - ch2;
906 cjv[lb + 1] = 2.0 * (lb + v0) * cjv[lb] / z - cjv[lb - 1];
908 if (std::abs (cjv[0]) > std::abs (cjv[1]) )
910 cyv[lb + 1] = (cjv[lb + 1] * cyv0 - 2.0 * cp11 / (
M_PI * z) ) / cjv[0];
911 cyv[lb] = (cjv[lb] * cyv0 + 2.0 * cp12 / (
M_PI * z) ) / cjv[0];
915 cyv[lb + 1] = (cjv[lb + 1] * cyv1 - 2.0 * cp21 / (
M_PI * z) ) / cjv[1];
916 cyv[lb] = (cjv[lb] * cyv1 + 2.0 * cp22 / (
M_PI * z) ) / cjv[1];
920 for (k = lb - 1; k >= 0; k--)
922 cylk = 2.0 * (k + v0 + 1.0) * cyl1 / z - cyl2;
929 for (k = lb + 1; k < n; k++)
931 cylk = 2.0 * (k + v0) * cyl2 / z - cyl1;
936 for (k = 2; k <= n; k++)
938 wa = std::abs (cyv[k]);
939 if (wa < std::abs (cyv[k - 1]) )
946 cyvp[0] = v0 * cyv[0] / z - cyv[1];
947 for (k = 1; k <= n; k++)
949 cyvp[k] = cyv[k - 1] - (k + v0) * cyv[k] / z;
int msta1(double x, int mp)
static std::complex< double > cii(0.0, 1.0)
int msta2(double x, int n, int mp)
int cbessjyva(double v, std::complex< double > z, double &vm, std::complex< double > *cjv, std::complex< double > *cyv, std::complex< double > *cjvp, std::complex< double > *cyvp)
static std::complex< double > czero(0.0, 0.0)
int cbessjy01(std::complex< double > z, std::complex< double > &cj0, std::complex< double > &cj1, std::complex< double > &cy0, std::complex< double > &cy1, std::complex< double > &cj0p, std::complex< double > &cj1p, std::complex< double > &cy0p, std::complex< double > &cy1p)
int cbessjynb(int n, std::complex< double > z, int &nm, std::complex< double > *cj, std::complex< double > *cy, std::complex< double > *cjp, std::complex< double > *cyp)
int cbessjyna(int n, std::complex< double > z, int &nm, std::complex< double > *cj, std::complex< double > *cy, std::complex< double > *cjp, std::complex< double > *cyp)
static std::complex< double > cone(1.0, 0.0)