Пример #1
0
def test_manualintegrate_special():
    f, F = 4*exp(-x**2/3), 2*sqrt(3)*sqrt(pi)*erf(sqrt(3)*x/3)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = 3*exp(4*x**2), 3*sqrt(pi)*erfi(2*x)/4
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = x**(S(1)/3)*exp(-x/8), -16*uppergamma(S(4)/3, x/8)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = exp(2*x)/x, Ei(2*x)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = exp(1 + 2*x - x**2), sqrt(pi)*exp(2)*erf(x - 1)/2
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f = sin(x**2 + 4*x + 1)
    F = (sqrt(2)*sqrt(pi)*(-sin(3)*fresnelc(sqrt(2)*(2*x + 4)/(2*sqrt(pi))) +
        cos(3)*fresnels(sqrt(2)*(2*x + 4)/(2*sqrt(pi))))/2)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = cos(4*x**2), sqrt(2)*sqrt(pi)*fresnelc(2*sqrt(2)*x/sqrt(pi))/4
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = sin(3*x + 2)/x, sin(2)*Ci(3*x) + cos(2)*Si(3*x)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = sinh(3*x - 2)/x, -sinh(2)*Chi(3*x) + cosh(2)*Shi(3*x)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = 5*cos(2*x - 3)/x, 5*cos(3)*Ci(2*x) + 5*sin(3)*Si(2*x)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = cosh(x/2)/x, Chi(x/2)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = cos(x**2)/x, Ci(x**2)/2
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = 1/log(2*x + 1), li(2*x + 1)/2
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = polylog(2, 5*x)/x, polylog(3, 5*x)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = 5/sqrt(3 - 2*sin(x)**2), 5*sqrt(3)*elliptic_f(x, S(2)/3)/3
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = sqrt(4 + 9*sin(x)**2), 2*elliptic_e(x, -S(9)/4)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
Пример #2
0
def test_manualintegrate_special():
    f, F = 4*exp(-x**2/3), 2*sqrt(3)*sqrt(pi)*erf(sqrt(3)*x/3)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = 3*exp(4*x**2), 3*sqrt(pi)*erfi(2*x)/4
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = x**Rational(1, 3)*exp(-x/8), -16*uppergamma(Rational(4, 3), x/8)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = exp(2*x)/x, Ei(2*x)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = exp(1 + 2*x - x**2), sqrt(pi)*exp(2)*erf(x - 1)/2
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f = sin(x**2 + 4*x + 1)
    F = (sqrt(2)*sqrt(pi)*(-sin(3)*fresnelc(sqrt(2)*(2*x + 4)/(2*sqrt(pi))) +
        cos(3)*fresnels(sqrt(2)*(2*x + 4)/(2*sqrt(pi))))/2)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = cos(4*x**2), sqrt(2)*sqrt(pi)*fresnelc(2*sqrt(2)*x/sqrt(pi))/4
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = sin(3*x + 2)/x, sin(2)*Ci(3*x) + cos(2)*Si(3*x)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = sinh(3*x - 2)/x, -sinh(2)*Chi(3*x) + cosh(2)*Shi(3*x)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = 5*cos(2*x - 3)/x, 5*cos(3)*Ci(2*x) + 5*sin(3)*Si(2*x)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = cosh(x/2)/x, Chi(x/2)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = cos(x**2)/x, Ci(x**2)/2
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = 1/log(2*x + 1), li(2*x + 1)/2
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = polylog(2, 5*x)/x, polylog(3, 5*x)
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = 5/sqrt(3 - 2*sin(x)**2), 5*sqrt(3)*elliptic_f(x, Rational(2, 3))/3
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
    f, F = sqrt(4 + 9*sin(x)**2), 2*elliptic_e(x, Rational(-9, 4))
    assert manualintegrate(f, x) == F and F.diff(x).equals(f)
Пример #3
0
 def eval(cls, s, j, n, alpha):
     # laplace coeffcients don't evaluate well with the C code
     # for large n, therefore I've substituted the exact expression
     # in terms of the elliptic K function when j=0
     if j is S.Zero:
         x = S('x')
         exprn = 4 / np.pi * diff(elliptic_k(x * x), x, n)
         return exprn.subs(x, alpha)
     elif j is S.One:
         x = S('x')
         exprn0 = 4 / np.pi * (elliptic_k(x * x) - elliptic_e(x * x)) / x
         exprn = diff(exprn0, x, n)
         return exprn.subs(x, alpha)
     else:
         return laplace_coefficient(s, j, n, alpha) / alpha**n
Пример #4
0
def test_latex_functions():
    assert latex(exp(x)) == "e^{x}"
    assert latex(exp(1) + exp(2)) == "e + e^{2}"

    f = Function('f')
    assert latex(f(x)) == r'f{\left (x \right )}'
    assert latex(f) == r'f'

    g = Function('g')
    assert latex(g(x, y)) == r'g{\left (x,y \right )}'
    assert latex(g) == r'g'

    h = Function('h')
    assert latex(h(x, y, z)) == r'h{\left (x,y,z \right )}'
    assert latex(h) == r'h'

    Li = Function('Li')
    assert latex(Li) == r'\operatorname{Li}'
    assert latex(Li(x)) == r'\operatorname{Li}{\left (x \right )}'

    beta = Function('beta')

    # not to be confused with the beta function
    assert latex(beta(x)) == r"\beta{\left (x \right )}"
    assert latex(beta) == r"\beta"

    assert latex(sin(x)) == r"\sin{\left (x \right )}"
    assert latex(sin(x), fold_func_brackets=True) == r"\sin {x}"
    assert latex(sin(2*x**2), fold_func_brackets=True) == \
        r"\sin {2 x^{2}}"
    assert latex(sin(x**2), fold_func_brackets=True) == \
        r"\sin {x^{2}}"

    assert latex(asin(x)**2) == r"\operatorname{asin}^{2}{\left (x \right )}"
    assert latex(asin(x)**2, inv_trig_style="full") == \
        r"\arcsin^{2}{\left (x \right )}"
    assert latex(asin(x)**2, inv_trig_style="power") == \
        r"\sin^{-1}{\left (x \right )}^{2}"
    assert latex(asin(x**2), inv_trig_style="power",
                 fold_func_brackets=True) == \
        r"\sin^{-1} {x^{2}}"

    assert latex(factorial(k)) == r"k!"
    assert latex(factorial(-k)) == r"\left(- k\right)!"

    assert latex(subfactorial(k)) == r"!k"
    assert latex(subfactorial(-k)) == r"!\left(- k\right)"

    assert latex(factorial2(k)) == r"k!!"
    assert latex(factorial2(-k)) == r"\left(- k\right)!!"

    assert latex(binomial(2, k)) == r"{\binom{2}{k}}"

    assert latex(
        FallingFactorial(3, k)) == r"{\left(3\right)}_{\left(k\right)}"
    assert latex(RisingFactorial(3, k)) == r"{\left(3\right)}^{\left(k\right)}"

    assert latex(floor(x)) == r"\lfloor{x}\rfloor"
    assert latex(ceiling(x)) == r"\lceil{x}\rceil"
    assert latex(Min(x, 2, x**3)) == r"\min\left(2, x, x^{3}\right)"
    assert latex(Min(x, y)**2) == r"\min\left(x, y\right)^{2}"
    assert latex(Max(x, 2, x**3)) == r"\max\left(2, x, x^{3}\right)"
    assert latex(Max(x, y)**2) == r"\max\left(x, y\right)^{2}"
    assert latex(Abs(x)) == r"\left\lvert{x}\right\rvert"
    assert latex(re(x)) == r"\Re{x}"
    assert latex(re(x + y)) == r"\Re{x} + \Re{y}"
    assert latex(im(x)) == r"\Im{x}"
    assert latex(conjugate(x)) == r"\overline{x}"
    assert latex(gamma(x)) == r"\Gamma\left(x\right)"
    assert latex(Order(x)) == r"\mathcal{O}\left(x\right)"
    assert latex(lowergamma(x, y)) == r'\gamma\left(x, y\right)'
    assert latex(uppergamma(x, y)) == r'\Gamma\left(x, y\right)'

    assert latex(cot(x)) == r'\cot{\left (x \right )}'
    assert latex(coth(x)) == r'\coth{\left (x \right )}'
    assert latex(re(x)) == r'\Re{x}'
    assert latex(im(x)) == r'\Im{x}'
    assert latex(root(x, y)) == r'x^{\frac{1}{y}}'
    assert latex(arg(x)) == r'\arg{\left (x \right )}'
    assert latex(zeta(x)) == r'\zeta\left(x\right)'

    assert latex(zeta(x)) == r"\zeta\left(x\right)"
    assert latex(zeta(x)**2) == r"\zeta^{2}\left(x\right)"
    assert latex(zeta(x, y)) == r"\zeta\left(x, y\right)"
    assert latex(zeta(x, y)**2) == r"\zeta^{2}\left(x, y\right)"
    assert latex(dirichlet_eta(x)) == r"\eta\left(x\right)"
    assert latex(dirichlet_eta(x)**2) == r"\eta^{2}\left(x\right)"
    assert latex(polylog(x, y)) == r"\operatorname{Li}_{x}\left(y\right)"
    assert latex(
        polylog(x, y)**2) == r"\operatorname{Li}_{x}^{2}\left(y\right)"
    assert latex(lerchphi(x, y, n)) == r"\Phi\left(x, y, n\right)"
    assert latex(lerchphi(x, y, n)**2) == r"\Phi^{2}\left(x, y, n\right)"

    assert latex(elliptic_k(z)) == r"K\left(z\right)"
    assert latex(elliptic_k(z)**2) == r"K^{2}\left(z\right)"
    assert latex(elliptic_f(x, y)) == r"F\left(x\middle| y\right)"
    assert latex(elliptic_f(x, y)**2) == r"F^{2}\left(x\middle| y\right)"
    assert latex(elliptic_e(x, y)) == r"E\left(x\middle| y\right)"
    assert latex(elliptic_e(x, y)**2) == r"E^{2}\left(x\middle| y\right)"
    assert latex(elliptic_e(z)) == r"E\left(z\right)"
    assert latex(elliptic_e(z)**2) == r"E^{2}\left(z\right)"
    assert latex(elliptic_pi(x, y, z)) == r"\Pi\left(x; y\middle| z\right)"
    assert latex(elliptic_pi(x, y, z)**2) == \
        r"\Pi^{2}\left(x; y\middle| z\right)"
    assert latex(elliptic_pi(x, y)) == r"\Pi\left(x\middle| y\right)"
    assert latex(elliptic_pi(x, y)**2) == r"\Pi^{2}\left(x\middle| y\right)"

    assert latex(Ei(x)) == r'\operatorname{Ei}{\left (x \right )}'
    assert latex(Ei(x)**2) == r'\operatorname{Ei}^{2}{\left (x \right )}'
    assert latex(expint(x, y)**2) == r'\operatorname{E}_{x}^{2}\left(y\right)'
    assert latex(Shi(x)**2) == r'\operatorname{Shi}^{2}{\left (x \right )}'
    assert latex(Si(x)**2) == r'\operatorname{Si}^{2}{\left (x \right )}'
    assert latex(Ci(x)**2) == r'\operatorname{Ci}^{2}{\left (x \right )}'
    assert latex(Chi(x)**2) == r'\operatorname{Chi}^{2}{\left (x \right )}', latex(Chi(x)**2)

    assert latex(
        jacobi(n, a, b, x)) == r'P_{n}^{\left(a,b\right)}\left(x\right)'
    assert latex(jacobi(n, a, b, x)**2) == r'\left(P_{n}^{\left(a,b\right)}\left(x\right)\right)^{2}'
    assert latex(
        gegenbauer(n, a, x)) == r'C_{n}^{\left(a\right)}\left(x\right)'
    assert latex(gegenbauer(n, a, x)**2) == r'\left(C_{n}^{\left(a\right)}\left(x\right)\right)^{2}'
    assert latex(chebyshevt(n, x)) == r'T_{n}\left(x\right)'
    assert latex(
        chebyshevt(n, x)**2) == r'\left(T_{n}\left(x\right)\right)^{2}'
    assert latex(chebyshevu(n, x)) == r'U_{n}\left(x\right)'
    assert latex(
        chebyshevu(n, x)**2) == r'\left(U_{n}\left(x\right)\right)^{2}'
    assert latex(legendre(n, x)) == r'P_{n}\left(x\right)'
    assert latex(legendre(n, x)**2) == r'\left(P_{n}\left(x\right)\right)^{2}'
    assert latex(
        assoc_legendre(n, a, x)) == r'P_{n}^{\left(a\right)}\left(x\right)'
    assert latex(assoc_legendre(n, a, x)**2) == r'\left(P_{n}^{\left(a\right)}\left(x\right)\right)^{2}'
    assert latex(laguerre(n, x)) == r'L_{n}\left(x\right)'
    assert latex(laguerre(n, x)**2) == r'\left(L_{n}\left(x\right)\right)^{2}'
    assert latex(
        assoc_laguerre(n, a, x)) == r'L_{n}^{\left(a\right)}\left(x\right)'
    assert latex(assoc_laguerre(n, a, x)**2) == r'\left(L_{n}^{\left(a\right)}\left(x\right)\right)^{2}'
    assert latex(hermite(n, x)) == r'H_{n}\left(x\right)'
    assert latex(hermite(n, x)**2) == r'\left(H_{n}\left(x\right)\right)^{2}'

    theta = Symbol("theta", real=True)
    phi = Symbol("phi", real=True)
    assert latex(Ynm(n,m,theta,phi)) == r'Y_{n}^{m}\left(\theta,\phi\right)'
    assert latex(Ynm(n, m, theta, phi)**3) == r'\left(Y_{n}^{m}\left(\theta,\phi\right)\right)^{3}'
    assert latex(Znm(n,m,theta,phi)) == r'Z_{n}^{m}\left(\theta,\phi\right)'
    assert latex(Znm(n, m, theta, phi)**3) == r'\left(Z_{n}^{m}\left(\theta,\phi\right)\right)^{3}'

    # Test latex printing of function names with "_"
    assert latex(
        polar_lift(0)) == r"\operatorname{polar\_lift}{\left (0 \right )}"
    assert latex(polar_lift(
        0)**3) == r"\operatorname{polar\_lift}^{3}{\left (0 \right )}"

    assert latex(totient(n)) == r'\phi\left( n \right)'

    # some unknown function name should get rendered with \operatorname
    fjlkd = Function('fjlkd')
    assert latex(fjlkd(x)) == r'\operatorname{fjlkd}{\left (x \right )}'
    # even when it is referred to without an argument
    assert latex(fjlkd) == r'\operatorname{fjlkd}'
Пример #5
0
def test_latex_functions():
    assert latex(exp(x)) == "e^{x}"
    assert latex(exp(1) + exp(2)) == "e + e^{2}"

    f = Function('f')
    assert latex(f(x)) == '\\operatorname{f}{\\left (x \\right )}'

    beta = Function('beta')

    assert latex(beta(x)) == r"\beta{\left (x \right )}"
    assert latex(sin(x)) == r"\sin{\left (x \right )}"
    assert latex(sin(x), fold_func_brackets=True) == r"\sin {x}"
    assert latex(sin(2*x**2), fold_func_brackets=True) == \
        r"\sin {2 x^{2}}"
    assert latex(sin(x**2), fold_func_brackets=True) == \
        r"\sin {x^{2}}"

    assert latex(asin(x)**2) == r"\operatorname{asin}^{2}{\left (x \right )}"
    assert latex(asin(x)**2, inv_trig_style="full") == \
        r"\arcsin^{2}{\left (x \right )}"
    assert latex(asin(x)**2, inv_trig_style="power") == \
        r"\sin^{-1}{\left (x \right )}^{2}"
    assert latex(asin(x**2), inv_trig_style="power",
                 fold_func_brackets=True) == \
        r"\sin^{-1} {x^{2}}"

    assert latex(factorial(k)) == r"k!"
    assert latex(factorial(-k)) == r"\left(- k\right)!"

    assert latex(subfactorial(k)) == r"!k"
    assert latex(subfactorial(-k)) == r"!\left(- k\right)"

    assert latex(factorial2(k)) == r"k!!"
    assert latex(factorial2(-k)) == r"\left(- k\right)!!"

    assert latex(binomial(2, k)) == r"{\binom{2}{k}}"

    assert latex(
        FallingFactorial(3, k)) == r"{\left(3\right)}_{\left(k\right)}"
    assert latex(RisingFactorial(3, k)) == r"{\left(3\right)}^{\left(k\right)}"

    assert latex(floor(x)) == r"\lfloor{x}\rfloor"
    assert latex(ceiling(x)) == r"\lceil{x}\rceil"
    assert latex(Min(x, 2, x**3)) == r"\min\left(2, x, x^{3}\right)"
    assert latex(Min(x, y)**2) == r"\min\left(x, y\right)^{2}"
    assert latex(Max(x, 2, x**3)) == r"\max\left(2, x, x^{3}\right)"
    assert latex(Max(x, y)**2) == r"\max\left(x, y\right)^{2}"
    assert latex(Abs(x)) == r"\left\lvert{x}\right\rvert"
    assert latex(re(x)) == r"\Re{x}"
    assert latex(re(x + y)) == r"\Re{x} + \Re{y}"
    assert latex(im(x)) == r"\Im{x}"
    assert latex(conjugate(x)) == r"\overline{x}"
    assert latex(gamma(x)) == r"\Gamma\left(x\right)"
    assert latex(Order(x)) == r"\mathcal{O}\left(x\right)"
    assert latex(lowergamma(x, y)) == r'\gamma\left(x, y\right)'
    assert latex(uppergamma(x, y)) == r'\Gamma\left(x, y\right)'

    assert latex(cot(x)) == r'\cot{\left (x \right )}'
    assert latex(coth(x)) == r'\coth{\left (x \right )}'
    assert latex(re(x)) == r'\Re{x}'
    assert latex(im(x)) == r'\Im{x}'
    assert latex(root(x, y)) == r'x^{\frac{1}{y}}'
    assert latex(arg(x)) == r'\arg{\left (x \right )}'
    assert latex(zeta(x)) == r'\zeta\left(x\right)'

    assert latex(zeta(x)) == r"\zeta\left(x\right)"
    assert latex(zeta(x)**2) == r"\zeta^{2}\left(x\right)"
    assert latex(zeta(x, y)) == r"\zeta\left(x, y\right)"
    assert latex(zeta(x, y)**2) == r"\zeta^{2}\left(x, y\right)"
    assert latex(dirichlet_eta(x)) == r"\eta\left(x\right)"
    assert latex(dirichlet_eta(x)**2) == r"\eta^{2}\left(x\right)"
    assert latex(polylog(x, y)) == r"\operatorname{Li}_{x}\left(y\right)"
    assert latex(
        polylog(x, y)**2) == r"\operatorname{Li}_{x}^{2}\left(y\right)"
    assert latex(lerchphi(x, y, n)) == r"\Phi\left(x, y, n\right)"
    assert latex(lerchphi(x, y, n)**2) == r"\Phi^{2}\left(x, y, n\right)"

    assert latex(elliptic_k(z)) == r"K\left(z\right)"
    assert latex(elliptic_k(z)**2) == r"K^{2}\left(z\right)"
    assert latex(elliptic_f(x, y)) == r"F\left(x\middle| y\right)"
    assert latex(elliptic_f(x, y)**2) == r"F^{2}\left(x\middle| y\right)"
    assert latex(elliptic_e(x, y)) == r"E\left(x\middle| y\right)"
    assert latex(elliptic_e(x, y)**2) == r"E^{2}\left(x\middle| y\right)"
    assert latex(elliptic_e(z)) == r"E\left(z\right)"
    assert latex(elliptic_e(z)**2) == r"E^{2}\left(z\right)"
    assert latex(elliptic_pi(x, y, z)) == r"\Pi\left(x; y\middle| z\right)"
    assert latex(elliptic_pi(x, y, z)**2) == \
        r"\Pi^{2}\left(x; y\middle| z\right)"
    assert latex(elliptic_pi(x, y)) == r"\Pi\left(x\middle| y\right)"
    assert latex(elliptic_pi(x, y)**2) == r"\Pi^{2}\left(x\middle| y\right)"

    assert latex(Ei(x)) == r'\operatorname{Ei}{\left (x \right )}'
    assert latex(Ei(x)**2) == r'\operatorname{Ei}^{2}{\left (x \right )}'
    assert latex(expint(x, y)**2) == r'\operatorname{E}_{x}^{2}\left(y\right)'
    assert latex(Shi(x)**2) == r'\operatorname{Shi}^{2}{\left (x \right )}'
    assert latex(Si(x)**2) == r'\operatorname{Si}^{2}{\left (x \right )}'
    assert latex(Ci(x)**2) == r'\operatorname{Ci}^{2}{\left (x \right )}'
    assert latex(Chi(x)**2) == r'\operatorname{Chi}^{2}{\left (x \right )}'

    assert latex(
        jacobi(n, a, b, x)) == r'P_{n}^{\left(a,b\right)}\left(x\right)'
    assert latex(jacobi(n, a, b, x)**2) == r'\left(P_{n}^{\left(a,b\right)}\left(x\right)\right)^{2}'
    assert latex(
        gegenbauer(n, a, x)) == r'C_{n}^{\left(a\right)}\left(x\right)'
    assert latex(gegenbauer(n, a, x)**2) == r'\left(C_{n}^{\left(a\right)}\left(x\right)\right)^{2}'
    assert latex(chebyshevt(n, x)) == r'T_{n}\left(x\right)'
    assert latex(
        chebyshevt(n, x)**2) == r'\left(T_{n}\left(x\right)\right)^{2}'
    assert latex(chebyshevu(n, x)) == r'U_{n}\left(x\right)'
    assert latex(
        chebyshevu(n, x)**2) == r'\left(U_{n}\left(x\right)\right)^{2}'
    assert latex(legendre(n, x)) == r'P_{n}\left(x\right)'
    assert latex(legendre(n, x)**2) == r'\left(P_{n}\left(x\right)\right)^{2}'
    assert latex(
        assoc_legendre(n, a, x)) == r'P_{n}^{\left(a\right)}\left(x\right)'
    assert latex(assoc_legendre(n, a, x)**2) == r'\left(P_{n}^{\left(a\right)}\left(x\right)\right)^{2}'
    assert latex(laguerre(n, x)) == r'L_{n}\left(x\right)'
    assert latex(laguerre(n, x)**2) == r'\left(L_{n}\left(x\right)\right)^{2}'
    assert latex(
        assoc_laguerre(n, a, x)) == r'L_{n}^{\left(a\right)}\left(x\right)'
    assert latex(assoc_laguerre(n, a, x)**2) == r'\left(L_{n}^{\left(a\right)}\left(x\right)\right)^{2}'
    assert latex(hermite(n, x)) == r'H_{n}\left(x\right)'
    assert latex(hermite(n, x)**2) == r'\left(H_{n}\left(x\right)\right)^{2}'

    # Test latex printing of function names with "_"
    assert latex(
        polar_lift(0)) == r"\operatorname{polar\_lift}{\left (0 \right )}"
    assert latex(polar_lift(
        0)**3) == r"\operatorname{polar\_lift}^{3}{\left (0 \right )}"

    assert latex(totient(n)) == r'\phi\left( n \right)'
Пример #6
0
import sympy as syp
#from sympy import Symbol
#from scipy.special import ellipk, ellipe, ellipkm1
from numpy import pi, sqrt, linspace
from pylab import plot, xlabel, ylabel, suptitle, legend, show

uo = 4E-7*pi     # Permeability constant - units of H/m
x = syp.Symbol('x')
Bo = lambda i, a, u=uo: i*u/(2*a)    # Central field = f(current, loop radius, perm. constant)
al = lambda r, a: r/a               # Alpha = f(radius of measurement point, radius of loop)
be = lambda x, a: x/a               # Beta = f(axial distance to meas. point, radius of loop)
ga = lambda x, r: x/r               # Gamma = f(axial distance, radius to meas. point)
Q = lambda r, x, a: (1 + al(r,a))**2 + be(x,a)**2   # Q = f(radius, distance to meas. point, loop radius)
k = lambda r, x, a: syp.sqrt(4*al(r,a)/Q(r,x,a))       # k = f(radius, distance to meas. point, loop radius)
K = lambda k: syp.elliptic_f(pi/2,k**2.0)          # Elliptic integral, first kind, as a function of k
E = lambda k: syp.elliptic_e(pi/2,k**2.0)          # Elliptic integral, second kind, as a function of k

N = 10;
lc = 0.065;
# Axial field component by a solenoid
def BxSol(i, a, r):
    pitch = lc/N;
    fBx = 0;
    for j in range(int(N)):
        Bxtemp = (Bo(i,a)*\
        (E(k(r,x-j*pitch,a))*((1.0-al(r,a)**2-be(x-j*pitch,a)**2)/(Q(r,x-j*pitch,a)-4*al(r,a))) + K(k(r,x-j*pitch,a))))\
        /pi/syp.sqrt(Q(r,x-j*pitch,a));

        fBx = fBx + Bxtemp;
    return fBx
Пример #7
0
def create_mesh_x():
    H = 0.001
    R = 0.1
    nodes = []
    nodes.append(FN.Node([0, -2 * H * 10], Ndof, timeOrder=tOrder))
    nodes.append(FN.Node([R * 2, -2 * H * 10], Ndof, timeOrder=tOrder))
    nodes.append(
        FN.Node([R * 2 + 0.1 * R, -2 * H * 10], Ndof, timeOrder=tOrder))

    edges = [mg.Edge(nodes[i], nodes[i + 1]) for i in range(len(nodes) - 1)]

    geo = mg.Geometry()
    d = np.array([0.0, 1.0])
    s = 10 * H

    for e in edges:
        geo.addPolygons(e.extendToQuad(d, s))

#    nodes1 = []
#    nodes1.append(FN.Node([0,H*21],Ndof,timeOrder = tOrder))
#    nodes1.append(FN.Node([R*2,H*21],Ndof,timeOrder = tOrder))
#    nodes1.append(FN.Node([R*2+0.1*R,H*21],Ndof,timeOrder = tOrder))
#
#    edges1 = [mg.Edge(nodes1[i],nodes1[i+1]) for i in range(len(nodes1)-1)]
#
#    for e in edges1:
#        geo.addPolygons(e.extendToQuad(d,s))

    nodes2 = []
    nodes2.append(FN.Node([0, 0], Ndof, timeOrder=tOrder))
    nodes2.append(FN.Node([R, 0], Ndof, timeOrder=tOrder))

    edges2 = [
        mg.Edge(nodes2[i], nodes2[i + 1]) for i in range(len(nodes2) - 1)
    ]

    s = H

    for e in edges2:
        geo.addPolygons(e.extendToQuad(d, s))

    polys = geo.getPolygons()

    polys[0].setDivisionEdge13(20)
    polys[0].setDivisionEdge24(1)
    polys[2].setDivisionEdge13(20)
    polys[2].setDivisionEdge24(1)

    #    polys[4].setDivisionEdge13(8)
    #    polys[4].setDivisionEdge24(1)

    mat1 = LinearMagneticMaterial(1000.0, 0.0, 0.0, 0)
    mat2 = LinearMagneticMaterial(1.0, 0.0, 1.0, 1)
    mat3 = LinearMagneticMaterial(100.0, 0.0, 1.0, 2)
    mat4 = LinearMagneticMaterial(1.0, 0.0, 1.0, 3)

    polys[0].setMaterial(mat3)
    polys[1].setMaterial(mat2)
    polys[2].setMaterial(mat1)
    #    polys[3].setMaterial(mat2)
    #    polys[4].setMaterial(mat1)

    geo.mesh()

    [nodesx, elems, mats, bdls] = geo.getMesh(None, mg.nodesQuad9, 2)

    for n in nodesx:
        if math.fabs(n.getX()[0]) < 1.0e-14:
            #            n.setConstraint(False, 0.0, 0)
            n.setConstraint(False, 0.0, 0)
            n.setConstraint(False, 0.0, 1)

    elements = []
    for i, e in enumerate(elems):
        m = mats[i]
        #        elements.append(AxiMechElement(e,[2,2],QE.LagrangeBasis1D,\
        #        nodeOrder,m,intDat,condt))
        elements.append(AxiSymMagnetic(e,[2,2],QE.LagrangeBasis1D,\
        nodeOrder,m,intDat))
        if m.idx == 1:
            elements[-1].setBodyLoad(loadfuncx)
#        if m.idx == 0:
#            elements[-1].setBodyLoad(loadfuncG)
#        elements[-1].setBodyLoad(loadfunc)

    mesh = FM.MeshWithBoundaryElement()
    mesh.addNodes(nodesx)
    mesh.addElements(elements)

    geo.meshBoundary()
    [nodes1, elems1, normBndVec, bndMat] = geo.getBoundaryMesh(None,\
    mg.nodesBoundaryQuad9,Ndof,get_mat=True)

    r0 = syp.sympify('r0')
    x0 = syp.sympify('x0')
    rx = syp.sympify('rx')
    xx = syp.sympify('xx')

    mt = (rx + r0)**2 + (xx - x0)**2
    m = 4.0 * rx * r0
    m = m / mt
    mtx = syp.sqrt(mt) * syp.pi
    kint = syp.elliptic_k(m)
    eint = syp.elliptic_e(m)
    #    Gf = r0*((2.0-m)*kint-2.0*eint)/(m*mtx)
    Gf = ((2.0 - m) * kint - 2.0 * eint) / (m * mtx)
    Gfr = syp.diff(Gf, rx)
    Gfz = syp.diff(Gf, xx)
    Gfr0 = syp.diff(Gf, r0)
    Gfz0 = syp.diff(Gf, x0)
    Gfr0r = syp.diff(Gfr, r0)
    Gfr0z = syp.diff(Gfr, x0)
    Gfz0r = syp.diff(Gfz, r0)
    Gfz0z = syp.diff(Gfz, x0)
    Gfrr = syp.diff(Gfr, rx)
    Gfrz = syp.diff(Gfr, xx)
    Gfzr = syp.diff(Gfz, rx)
    Gfzz = syp.diff(Gfz, xx)
    Gfunc = syp.lambdify((rx,xx,r0,x0),Gf,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGr = syp.lambdify((rx,xx,r0,x0),Gfr,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGz = syp.lambdify((rx,xx,r0,x0),Gfz,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGrr = syp.lambdify((rx,xx,r0,x0),Gfrr,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGrz = syp.lambdify((rx,xx,r0,x0),Gfrz,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGzr = syp.lambdify((rx,xx,r0,x0),Gfzr,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGzz = syp.lambdify((rx,xx,r0,x0),Gfzz,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGr0 = syp.lambdify((rx,xx,r0,x0),Gfr0,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGz0 = syp.lambdify((rx,xx,r0,x0),Gfz0,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGr0r = syp.lambdify((rx,xx,r0,x0),Gfr0r,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGr0z = syp.lambdify((rx,xx,r0,x0),Gfr0z,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGz0r = syp.lambdify((rx,xx,r0,x0),Gfz0r,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGz0z = syp.lambdify((rx,xx,r0,x0),Gfz0z,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])

    elementBs = []
    for i, e in enumerate(elems1):
        if np.fabs(e[1].getX()[0]) < 1.0e-13:
            continue
        elementBs.append(AxiSymMagneticBoundaryLinear(e,2,QE.LagrangeBasis1D,\
        QE.generateQuadNodeOrder(2,1),intDatB,intSingDat,normBndVec[i],i))
        elementBs[-1].setMaterial(bndMat[i])

        #        if bndMat[i].idx == 0:
        #            elementBs[-1].deformed=True

        #        if np.fabs(e[1].getX()[1])<1.0e-14:
        #            elementBs[-1].normv = np.array([0.0,-1.0])
        #        if np.fabs(e[1].getX()[1]-H)<1.0e-14:
        #            elementBs[-1].normv = np.array([0.0,1.0])
        #        if np.fabs(e[1].getX()[0]-R)<1.0e-14:
        #            elementBs[-1].normv = np.array([1.0,0.0])
        elementBs[-1].Gfunc = Gfunc
        elementBs[-1].Gdr = gradGr
        elementBs[-1].Gdz = gradGz
        elementBs[-1].Gdrr = gradGrr
        elementBs[-1].Gdrz = gradGrz
        elementBs[-1].Gdzr = gradGzr
        elementBs[-1].Gdzz = gradGzz
        elementBs[-1].Gdr0 = gradGr0
        elementBs[-1].Gdz0 = gradGz0
        elementBs[-1].Gdr0r = gradGr0r
        elementBs[-1].Gdr0z = gradGr0z
        elementBs[-1].Gdz0r = gradGz0r
        elementBs[-1].Gdz0z = gradGz0z
#        elementBs[-1].linear=False

    mesh.addBoundaryElements(elementBs)

    for n in mesh.getNodes():
        ine = False
        for e in elementBs:
            if n in e:
                ine = True
        if not ine:
            n.setConstraint(False, 0.0, 1)


#    ndup = []
#    for n in mesh.getNodes():
#        xn = n.getX()
#        n1 = np.fabs(xn[0]-0.2)<1.0e-14 and np.fabs(xn[1]+0.02)<1.0e-14
#        n2 = np.fabs(xn[0]-0.2)<1.0e-14 and np.fabs(xn[1]+0.01)<1.0e-14
#        n3 = np.fabs(xn[0]-0.2)<1.0e-14 and np.fabs(xn[1]-0.011)<1.0e-13
#        n4 = np.fabs(xn[0]-0.2)<1.0e-14 and np.fabs(xn[1]-0.021)<1.0e-13
#        if n1 or n2 or n3 or n4:
#            be1 = None
#            be2 = None
#            for be in mesh.BoundaryElements:
#                if n in be:
#                    if be1 is None:
#                        be1 = be
#                    elif be2 is None:
#                        be2 = be
#                        break
#            nx1 = n.copy()
#            nx1.setConstraint(False,0.0,0)
#            nx1.setConstraint(False,0.0,1)
#            nx1.friendOF(n,2)
#            nx2 = n.copy()
#            nx2.setConstraint(False,0.0,0)
#            nx2.setConstraint(False,0.0,1)
#            nx2.friendOF(n,2)
#            n.freedom[3] = False
#            for i1, nt1 in enumerate(be1.Nodes):
#                if n == nt1:
#                    be1.Nodes[i1] = nx1
#                    ndup.append(nx1)
#            for i2, nt2 in enumerate(be2.Nodes):
#                if n == nt2:
#                    be2.Nodes[i2] = nx2
#                    ndup.append(nx2)
#    for n in ndup:
#        mesh.Nodes.append(n)
#        mesh.Nnod += 1
    mesh.generateID()
    return mesh
Пример #8
0
def create_test_mesh():
    nodes = []
    nodes.append(FN.Node([0.0, -1.0], Ndof, timeOrder=tOrder))
    nodes.append(FN.Node([1.0, -1.0], Ndof, timeOrder=tOrder))
    nodes.append(FN.Node([2.0, -1.0], Ndof, timeOrder=tOrder))
    nodes.append(FN.Node([2.5, -1.0], Ndof, timeOrder=tOrder))
    nodes.append(FN.Node([3.0, -1.0], Ndof, timeOrder=tOrder))

    edges = [mg.Edge(nodes[i], nodes[i + 1]) for i in range(len(nodes) - 1)]

    geo = mg.Geometry()
    geo = mg.Geometry()
    d = np.array([0.0, 1.0])
    s = [1.0, 0.25, 0.55, 0.25, 1.0]

    for e in edges:
        geo.addPolygons(e.extendToQuad(d, s))

    polys = geo.getPolygons()

    mat1 = LinearMagneticMaterial(1.0, 1.0, 0.0, 1)
    #    mat2 = LinearMagneticMaterial(1.0,1.0,5.0e6,2)
    for p in polys:
        p.setMaterial(mat1)
    polys[12].setBodyLoad(1.0)

    for p in polys:
        p.setDivisionEdge13(2)
        p.setDivisionEdge24(2)

    geo.mesh()
    [nodesx, elems, mats, bdls] = geo.getMesh(None, mg.nodesQuad9, Ndof)
    load = 355.0
    for n in nodesx:
        if math.fabs(n.getX()[0] - 0.0) < 1.0e-14:
            n.setConstraint(False, 0.0, 0)


#            n.setConstraint(False, 0.0, 1)
#        if math.fabs(n.getX()[0])>1.0-1.0e-13 and \
#        n.getX()[1]>0.25-1.0e-13 and \
#        n.getX()[1]<0.75+1.0e-13 and n.getX()[0]<2.5+1.0e-13:
#            n.setLoad(load,0)
#        if math.fabs(n.getX()[0]-2.25)<1.0e-13 and\
#        math.fabs(n.getX()[1]-0.525)<1.0e-13:
#            n.setLoad(load*2.0*np.pi*n.getX()[0],0)
    elements = []

    for i, e in enumerate(elems):
        m = mats[i]
        elements.append(AxiSymMagnetic(e,[2,2],QE.LagrangeBasis1D,\
        QE.generateQuadNodeOrder([2,2],2),m,intDat))
        if bdls[i] is not None:

            def loadfunc(x, t):
                #return load*math.sin(8.1e3*2*np.pi*t)
                return load
        else:
            loadfunc = None
        elements[i].setBodyLoad(loadfunc)

    mesh = FM.MeshWithBoundaryElement()
    mesh.addNodes(nodesx)
    mesh.addElements(elements)

    geo.meshBoundary()
    [nodes1, elems1, normBndVec] = geo.getBoundaryMesh(None,\
    mg.nodesBoundaryQuad9,Ndof)

    r0 = syp.sympify('r0')
    x0 = syp.sympify('x0')
    rx = syp.sympify('rx')
    xx = syp.sympify('xx')

    mt = (rx + r0)**2 + (xx - x0)**2
    m = 4.0 * rx * r0
    m = m / mt
    mtx = syp.sqrt(mt) * syp.pi
    kint = syp.elliptic_k(m)
    eint = syp.elliptic_e(m)
    #    Gf = r0*((2.0-m)*kint-2.0*eint)/(m*mtx)
    Gf = ((2.0 - m) * kint - 2.0 * eint) / (m * mtx)
    Gfr = syp.diff(Gf, rx)
    Gfz = syp.diff(Gf, xx)
    Gfr0 = syp.diff(Gf, r0)
    Gfz0 = syp.diff(Gf, x0)
    Gfr0r = syp.diff(Gfr0, rx)
    Gfr0z = syp.diff(Gfr0, xx)
    Gfz0r = syp.diff(Gfz0, rx)
    Gfz0z = syp.diff(Gfz0, xx)
    Gfrr = syp.diff(Gfr, rx)
    Gfrz = syp.diff(Gfr, xx)
    Gfzr = syp.diff(Gfz, rx)
    Gfzz = syp.diff(Gfz, xx)
    Gfunc = syp.lambdify((rx,xx,r0,x0),Gf,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGr = syp.lambdify((rx,xx,r0,x0),Gfr,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGz = syp.lambdify((rx,xx,r0,x0),Gfz,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGrr = syp.lambdify((rx,xx,r0,x0),Gfrr,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGrz = syp.lambdify((rx,xx,r0,x0),Gfrz,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGzr = syp.lambdify((rx,xx,r0,x0),Gfzr,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGzz = syp.lambdify((rx,xx,r0,x0),Gfzz,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGr0 = syp.lambdify((rx,xx,r0,x0),Gfr0,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGz0 = syp.lambdify((rx,xx,r0,x0),Gfz0,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGr0r = syp.lambdify((rx,xx,r0,x0),Gfr0r,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGr0z = syp.lambdify((rx,xx,r0,x0),Gfr0z,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGz0r = syp.lambdify((rx,xx,r0,x0),Gfz0r,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGz0z = syp.lambdify((rx,xx,r0,x0),Gfz0z,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])

    elementBs = []
    for i, e in enumerate(elems1):
        if e[1].getX()[0] == 0.0:
            continue
        elementBs.append(AxiSymMagneticBoundaryLinear(e,2,QE.LagrangeBasis1D,\
        QE.generateQuadNodeOrder(2,1),intDatB,intSingDat,normBndVec[i],i))
        elementBs[-1].setMaterial(mat1)

        elementBs[-1].Gfunc = Gfunc
        elementBs[-1].Gdr = gradGr
        elementBs[-1].Gdz = gradGz
        elementBs[-1].Gdrr = gradGrr
        elementBs[-1].Gdrz = gradGrz
        elementBs[-1].Gdzr = gradGzr
        elementBs[-1].Gdzz = gradGzz
        elementBs[-1].Gdr0 = gradGr0
        elementBs[-1].Gdz0 = gradGz0
        elementBs[-1].Gdr0r = gradGr0r
        elementBs[-1].Gdr0z = gradGr0z
        elementBs[-1].Gdz0r = gradGz0r
        elementBs[-1].Gdz0z = gradGz0z
        elementBs[-1].linear = True

    for n in mesh.getNodes():
        ine = False
        for e in elementBs:
            if n in e:
                ine = True
        if not ine:
            n.setConstraint(False, 0.0, 1)

    #mesh.addElements(elementBs)
    mesh.addBoundaryElements(elementBs)
    mesh.generateID()

    return mesh
Пример #9
0
def create_simple_mesh():
    nodes = []
    nodes.append(FN.Node([0.0, 0.0], Ndof, timeOrder=tOrder))
    nodes.append(FN.Node([1.0, 0.0], Ndof, timeOrder=tOrder))
    nodes.append(FN.Node([2.0, 0.25], Ndof, timeOrder=tOrder))
    nodes.append(FN.Node([2.5, 0.25], Ndof, timeOrder=tOrder))

    edge1 = mg.Edge(nodes[0], nodes[1])
    poly1 = edge1.extendToQuad(np.array([0.0, 1.0]), 1.0)
    edge2 = mg.Edge(nodes[2], nodes[3])
    poly2 = edge2.extendToQuad(np.array([0.0, 1.0]), 0.5)
    poly2.setBodyLoad(1.0)

    poly1.setDivisionEdge24(2)

    geo = mg.Geometry()
    geo.addPolygon(poly1)
    geo.addPolygon(poly2)

    mat1 = LinearMagneticMaterial(1.0, 1.0, 0.0, 1)
    mat2 = LinearMagneticMaterial(1.0, 1.0, 0.0, 2)
    poly1.setMaterial(mat1)
    poly2.setMaterial(mat2)

    geo.mesh()
    [nodesx, elems, mats, bdls] = geo.getMesh(None, mg.nodesQuad9, Ndof)
    for n in nodesx:
        if math.fabs(n.getX()[0] - 0.0) < 1.0e-14:
            n.setConstraint(False, 0.0, 0)
            n.setConstraint(False, 0.0, 1)
    elements = []

    load = 355.0

    for i, e in enumerate(elems):
        m = mats[i]
        elements.append(AxiSymMagnetic(e,[2,2],QE.LagrangeBasis1D,\
        QE.generateQuadNodeOrder([2,2],2),m,intDat))
        if bdls[i] is not None:

            def loadfunc(x, t):
                #return load*math.sin(8.1e3*2*np.pi*t)
                return load
        else:
            loadfunc = None
        elements[i].setBodyLoad(loadfunc)

    mesh = FM.MeshWithBoundaryElement()
    mesh.addNodes(nodesx)
    mesh.addElements(elements)

    geo.meshBoundary()
    [nodes1, elems1, normBndVec] = geo.getBoundaryMesh(None,\
    mg.nodesBoundaryQuad9,Ndof)

    r0 = syp.sympify('r0')
    x0 = syp.sympify('x0')
    rx = syp.sympify('rx')
    xx = syp.sympify('xx')

    mt = (rx + r0)**2 + (xx - x0)**2
    m = 4.0 * rx * r0
    m = m / mt
    mtx = syp.sqrt(mt) * syp.pi
    kint = syp.elliptic_k(m)
    eint = syp.elliptic_e(m)
    #    Gf = r0*((2.0-m)*kint-2.0*eint)/(m*mtx)
    Gf = ((2.0 - m) * kint - 2.0 * eint) / (m * mtx)
    Gfr = syp.diff(Gf, rx)
    Gfz = syp.diff(Gf, xx)
    Gfr0 = syp.diff(Gf, r0)
    Gfz0 = syp.diff(Gf, x0)
    Gfr0r = syp.diff(Gfr, r0)
    Gfr0z = syp.diff(Gfr, x0)
    Gfz0r = syp.diff(Gfz, r0)
    Gfz0z = syp.diff(Gfz, x0)
    Gfrr = syp.diff(Gfr, rx)
    Gfrz = syp.diff(Gfr, xx)
    Gfzr = syp.diff(Gfz, rx)
    Gfzz = syp.diff(Gfz, xx)
    Gfunc = syp.lambdify((rx,xx,r0,x0),Gf,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGr = syp.lambdify((rx,xx,r0,x0),Gfr,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGz = syp.lambdify((rx,xx,r0,x0),Gfz,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGrr = syp.lambdify((rx,xx,r0,x0),Gfrr,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGrz = syp.lambdify((rx,xx,r0,x0),Gfrz,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGzr = syp.lambdify((rx,xx,r0,x0),Gfzr,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGzz = syp.lambdify((rx,xx,r0,x0),Gfzz,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGr0 = syp.lambdify((rx,xx,r0,x0),Gfr0,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGz0 = syp.lambdify((rx,xx,r0,x0),Gfz0,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGr0r = syp.lambdify((rx,xx,r0,x0),Gfr0r,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGr0z = syp.lambdify((rx,xx,r0,x0),Gfr0z,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGz0r = syp.lambdify((rx,xx,r0,x0),Gfz0r,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])
    gradGz0z = syp.lambdify((rx,xx,r0,x0),Gfz0z,\
    modules=['numpy',{'elliptic_k':scpsp.ellipk,'elliptic_e':scpsp.ellipe}])

    elementBs = []
    for i, e in enumerate(elems1):
        if e[1].getX()[0] == 0.0:
            continue
        elementBs.append(AxiSymMagneticBoundaryLinear(e,2,QE.LagrangeBasis1D,\
        QE.generateQuadNodeOrder(2,1),intDatB,intSingDat,normBndVec[i],i))
        elementBs[-1].setMaterial(mat1)

        elementBs[-1].Gfunc = Gfunc
        elementBs[-1].Gdr = gradGr
        elementBs[-1].Gdz = gradGz
        elementBs[-1].Gdrr = gradGrr
        elementBs[-1].Gdrz = gradGrz
        elementBs[-1].Gdzr = gradGzr
        elementBs[-1].Gdzz = gradGzz
        elementBs[-1].Gdr0 = gradGr0
        elementBs[-1].Gdz0 = gradGz0
        elementBs[-1].Gdr0r = gradGr0r
        elementBs[-1].Gdr0z = gradGr0z
        elementBs[-1].Gdz0r = gradGz0r
        elementBs[-1].Gdz0z = gradGz0z
        elementBs[-1].linear = True

    for n in mesh.getNodes():
        ine = False
        for e in elementBs:
            if n in e:
                ine = True
        if not ine:
            n.setConstraint(False, 0.0, 1)

    #mesh.addElements(elementBs)
    mesh.addBoundaryElements(elementBs)

    ndup = []
    for n in mesh.getNodes():
        xn = n.getX()
        #        n1 = np.fabs(xn[0])<1.0e-14 and np.fabs(xn[1])<1.0e-14
        n2 = np.fabs(xn[0] - 1.0) < 1.0e-14 and np.fabs(xn[1]) < 1.0e-14
        n3 = np.fabs(xn[0] - 1.0) < 1.0e-14 and np.fabs(xn[1] - 1.0) < 1.0e-14
        #        n4 = np.fabs(xn[0])<1.0e-14 and np.fabs(xn[1]-1.0)<1.0e-14
        n5 = np.fabs(xn[0] - 2.0) < 1.0e-14 and np.fabs(xn[1] - 0.25) < 1.0e-14
        n6 = np.fabs(xn[0] - 2.5) < 1.0e-14 and np.fabs(xn[1] - 0.25) < 1.0e-14
        n7 = np.fabs(xn[0] - 2.5) < 1.0e-14 and np.fabs(xn[1] - 0.75) < 1.0e-14
        n8 = np.fabs(xn[0] - 2.0) < 1.0e-14 and np.fabs(xn[1] - 0.75) < 1.0e-14
        if n2 or n3 or n5 or n6 or n7 or n8:
            be1 = None
            be2 = None
            for be in mesh.BoundaryElements:
                if n in be:
                    if be1 is None:
                        be1 = be
                    elif be2 is None:
                        be2 = be
                        break
            nx1 = n.copy()
            nx1.friendOF(n, 0)
            nx2 = n.copy()
            nx2.friendOF(n, 0)
            n.freedom[1] = False
            for i1, nt1 in enumerate(be1.Nodes):
                if n == nt1:
                    be1.Nodes[i1] = nx1
                    ndup.append(nx1)
            for i2, nt2 in enumerate(be2.Nodes):
                if n == nt2:
                    be2.Nodes[i2] = nx2
                    ndup.append(nx2)
    for n in ndup:
        mesh.Nodes.append(n)
        mesh.Nnod += 1

    mesh.generateID()

    #mesh.Nodes[4].setLoad(loadfunc,0)

    return mesh
Пример #10
0
def test_J2():
    assert diff(elliptic_e(x, y**2), y) == (elliptic_e(x, y**2) - elliptic_f(x, y**2))/y
Пример #11
0
import sympy as syp

x = syp.Symbol('x')
E = lambda x: syp.elliptic_e(pi / 2, x)
I = integrate(E, x)
print(I)
Пример #12
0
def test_latex_functions():
    assert latex(exp(x)) == "e^{x}"
    assert latex(exp(1) + exp(2)) == "e + e^{2}"

    f = Function('f')
    assert latex(f(x)) == r'f{\left (x \right )}'
    assert latex(f) == r'f'

    g = Function('g')
    assert latex(g(x, y)) == r'g{\left (x,y \right )}'
    assert latex(g) == r'g'

    h = Function('h')
    assert latex(h(x, y, z)) == r'h{\left (x,y,z \right )}'
    assert latex(h) == r'h'

    Li = Function('Li')
    assert latex(Li) == r'\operatorname{Li}'
    assert latex(Li(x)) == r'\operatorname{Li}{\left (x \right )}'

    beta = Function('beta')

    # not to be confused with the beta function
    assert latex(beta(x)) == r"\beta{\left (x \right )}"
    assert latex(beta) == r"\beta"

    assert latex(sin(x)) == r"\sin{\left (x \right )}"
    assert latex(sin(x), fold_func_brackets=True) == r"\sin {x}"
    assert latex(sin(2*x**2), fold_func_brackets=True) == \
        r"\sin {2 x^{2}}"
    assert latex(sin(x**2), fold_func_brackets=True) == \
        r"\sin {x^{2}}"

    assert latex(asin(x)**2) == r"\operatorname{asin}^{2}{\left (x \right )}"
    assert latex(asin(x)**2, inv_trig_style="full") == \
        r"\arcsin^{2}{\left (x \right )}"
    assert latex(asin(x)**2, inv_trig_style="power") == \
        r"\sin^{-1}{\left (x \right )}^{2}"
    assert latex(asin(x**2), inv_trig_style="power",
                 fold_func_brackets=True) == \
        r"\sin^{-1} {x^{2}}"

    assert latex(factorial(k)) == r"k!"
    assert latex(factorial(-k)) == r"\left(- k\right)!"

    assert latex(subfactorial(k)) == r"!k"
    assert latex(subfactorial(-k)) == r"!\left(- k\right)"

    assert latex(factorial2(k)) == r"k!!"
    assert latex(factorial2(-k)) == r"\left(- k\right)!!"

    assert latex(binomial(2, k)) == r"{\binom{2}{k}}"

    assert latex(FallingFactorial(3,
                                  k)) == r"{\left(3\right)}_{\left(k\right)}"
    assert latex(RisingFactorial(3, k)) == r"{\left(3\right)}^{\left(k\right)}"

    assert latex(floor(x)) == r"\lfloor{x}\rfloor"
    assert latex(ceiling(x)) == r"\lceil{x}\rceil"
    assert latex(Min(x, 2, x**3)) == r"\min\left(2, x, x^{3}\right)"
    assert latex(Min(x, y)**2) == r"\min\left(x, y\right)^{2}"
    assert latex(Max(x, 2, x**3)) == r"\max\left(2, x, x^{3}\right)"
    assert latex(Max(x, y)**2) == r"\max\left(x, y\right)^{2}"
    assert latex(Abs(x)) == r"\left\lvert{x}\right\rvert"
    assert latex(re(x)) == r"\Re{x}"
    assert latex(re(x + y)) == r"\Re{x} + \Re{y}"
    assert latex(im(x)) == r"\Im{x}"
    assert latex(conjugate(x)) == r"\overline{x}"
    assert latex(gamma(x)) == r"\Gamma{\left(x \right)}"
    w = Wild('w')
    assert latex(gamma(w)) == r"\Gamma{\left(w \right)}"
    assert latex(Order(x)) == r"\mathcal{O}\left(x\right)"
    assert latex(Order(x, x)) == r"\mathcal{O}\left(x\right)"
    assert latex(Order(x, x, 0)) == r"\mathcal{O}\left(x\right)"
    assert latex(Order(x, x,
                       oo)) == r"\mathcal{O}\left(x; x\rightarrow\infty\right)"
    assert latex(
        Order(x, x, y)
    ) == r"\mathcal{O}\left(x; \begin{pmatrix}x, & y\end{pmatrix}\rightarrow0\right)"
    assert latex(
        Order(x, x, y, 0)
    ) == r"\mathcal{O}\left(x; \begin{pmatrix}x, & y\end{pmatrix}\rightarrow0\right)"
    assert latex(
        Order(x, x, y, oo)
    ) == r"\mathcal{O}\left(x; \begin{pmatrix}x, & y\end{pmatrix}\rightarrow\infty\right)"
    assert latex(lowergamma(x, y)) == r'\gamma\left(x, y\right)'
    assert latex(uppergamma(x, y)) == r'\Gamma\left(x, y\right)'

    assert latex(cot(x)) == r'\cot{\left (x \right )}'
    assert latex(coth(x)) == r'\coth{\left (x \right )}'
    assert latex(re(x)) == r'\Re{x}'
    assert latex(im(x)) == r'\Im{x}'
    assert latex(root(x, y)) == r'x^{\frac{1}{y}}'
    assert latex(arg(x)) == r'\arg{\left (x \right )}'
    assert latex(zeta(x)) == r'\zeta\left(x\right)'

    assert latex(zeta(x)) == r"\zeta\left(x\right)"
    assert latex(zeta(x)**2) == r"\zeta^{2}\left(x\right)"
    assert latex(zeta(x, y)) == r"\zeta\left(x, y\right)"
    assert latex(zeta(x, y)**2) == r"\zeta^{2}\left(x, y\right)"
    assert latex(dirichlet_eta(x)) == r"\eta\left(x\right)"
    assert latex(dirichlet_eta(x)**2) == r"\eta^{2}\left(x\right)"
    assert latex(polylog(x, y)) == r"\operatorname{Li}_{x}\left(y\right)"
    assert latex(polylog(x,
                         y)**2) == r"\operatorname{Li}_{x}^{2}\left(y\right)"
    assert latex(lerchphi(x, y, n)) == r"\Phi\left(x, y, n\right)"
    assert latex(lerchphi(x, y, n)**2) == r"\Phi^{2}\left(x, y, n\right)"

    assert latex(elliptic_k(z)) == r"K\left(z\right)"
    assert latex(elliptic_k(z)**2) == r"K^{2}\left(z\right)"
    assert latex(elliptic_f(x, y)) == r"F\left(x\middle| y\right)"
    assert latex(elliptic_f(x, y)**2) == r"F^{2}\left(x\middle| y\right)"
    assert latex(elliptic_e(x, y)) == r"E\left(x\middle| y\right)"
    assert latex(elliptic_e(x, y)**2) == r"E^{2}\left(x\middle| y\right)"
    assert latex(elliptic_e(z)) == r"E\left(z\right)"
    assert latex(elliptic_e(z)**2) == r"E^{2}\left(z\right)"
    assert latex(elliptic_pi(x, y, z)) == r"\Pi\left(x; y\middle| z\right)"
    assert latex(elliptic_pi(x, y, z)**2) == \
        r"\Pi^{2}\left(x; y\middle| z\right)"
    assert latex(elliptic_pi(x, y)) == r"\Pi\left(x\middle| y\right)"
    assert latex(elliptic_pi(x, y)**2) == r"\Pi^{2}\left(x\middle| y\right)"

    assert latex(Ei(x)) == r'\operatorname{Ei}{\left (x \right )}'
    assert latex(Ei(x)**2) == r'\operatorname{Ei}^{2}{\left (x \right )}'
    assert latex(expint(x, y)**2) == r'\operatorname{E}_{x}^{2}\left(y\right)'
    assert latex(Shi(x)**2) == r'\operatorname{Shi}^{2}{\left (x \right )}'
    assert latex(Si(x)**2) == r'\operatorname{Si}^{2}{\left (x \right )}'
    assert latex(Ci(x)**2) == r'\operatorname{Ci}^{2}{\left (x \right )}'
    assert latex(Chi(x)**2) == r'\operatorname{Chi}^{2}{\left (x \right )}'
    assert latex(Chi(x)) == r'\operatorname{Chi}{\left (x \right )}'

    assert latex(jacobi(n, a, b,
                        x)) == r'P_{n}^{\left(a,b\right)}\left(x\right)'
    assert latex(jacobi(
        n, a, b,
        x)**2) == r'\left(P_{n}^{\left(a,b\right)}\left(x\right)\right)^{2}'
    assert latex(gegenbauer(n, a,
                            x)) == r'C_{n}^{\left(a\right)}\left(x\right)'
    assert latex(gegenbauer(
        n, a,
        x)**2) == r'\left(C_{n}^{\left(a\right)}\left(x\right)\right)^{2}'
    assert latex(chebyshevt(n, x)) == r'T_{n}\left(x\right)'
    assert latex(chebyshevt(n,
                            x)**2) == r'\left(T_{n}\left(x\right)\right)^{2}'
    assert latex(chebyshevu(n, x)) == r'U_{n}\left(x\right)'
    assert latex(chebyshevu(n,
                            x)**2) == r'\left(U_{n}\left(x\right)\right)^{2}'
    assert latex(legendre(n, x)) == r'P_{n}\left(x\right)'
    assert latex(legendre(n, x)**2) == r'\left(P_{n}\left(x\right)\right)^{2}'
    assert latex(assoc_legendre(n, a,
                                x)) == r'P_{n}^{\left(a\right)}\left(x\right)'
    assert latex(assoc_legendre(
        n, a,
        x)**2) == r'\left(P_{n}^{\left(a\right)}\left(x\right)\right)^{2}'
    assert latex(laguerre(n, x)) == r'L_{n}\left(x\right)'
    assert latex(laguerre(n, x)**2) == r'\left(L_{n}\left(x\right)\right)^{2}'
    assert latex(assoc_laguerre(n, a,
                                x)) == r'L_{n}^{\left(a\right)}\left(x\right)'
    assert latex(assoc_laguerre(
        n, a,
        x)**2) == r'\left(L_{n}^{\left(a\right)}\left(x\right)\right)^{2}'
    assert latex(hermite(n, x)) == r'H_{n}\left(x\right)'
    assert latex(hermite(n, x)**2) == r'\left(H_{n}\left(x\right)\right)^{2}'

    theta = Symbol("theta", real=True)
    phi = Symbol("phi", real=True)
    assert latex(Ynm(n, m, theta, phi)) == r'Y_{n}^{m}\left(\theta,\phi\right)'
    assert latex(
        Ynm(n, m, theta,
            phi)**3) == r'\left(Y_{n}^{m}\left(\theta,\phi\right)\right)^{3}'
    assert latex(Znm(n, m, theta, phi)) == r'Z_{n}^{m}\left(\theta,\phi\right)'
    assert latex(
        Znm(n, m, theta,
            phi)**3) == r'\left(Z_{n}^{m}\left(\theta,\phi\right)\right)^{3}'

    # Test latex printing of function names with "_"
    assert latex(
        polar_lift(0)) == r"\operatorname{polar\_lift}{\left (0 \right )}"
    assert latex(polar_lift(0)**
                 3) == r"\operatorname{polar\_lift}^{3}{\left (0 \right )}"

    assert latex(totient(n)) == r'\phi\left( n \right)'

    # some unknown function name should get rendered with \operatorname
    fjlkd = Function('fjlkd')
    assert latex(fjlkd(x)) == r'\operatorname{fjlkd}{\left (x \right )}'
    # even when it is referred to without an argument
    assert latex(fjlkd) == r'\operatorname{fjlkd}'