def test_pde_separate_add(): x, y, z, t = symbols("x,y,z,t") F, T, X, Y, Z, u = map(Function, 'FTXYZu') eq = Eq(D(u(x, t), x), D(u(x, t), t) * exp(u(x, t))) res = pde_separate_add(eq, u(x, t), [X(x), T(t)]) assert res == [D(X(x), x) * exp(-X(x)), D(T(t), t) * exp(T(t))]
def test_euler_sineg(): psi = Function('psi') t = Symbol('t') x = Symbol('x') L = D(psi(t, x), t)**2 / 2 - D(psi(t, x), x)**2 / 2 + cos(psi(t, x)) assert euler(L, psi(t, x), [t, x]) == [ Eq(-sin(psi(t, x)) - D(psi(t, x), t, t) + D(psi(t, x), x, x), 0) ]
def test_issue_11726(): x, t = symbols("x t") f = symbols("f", cls=Function) X, T = symbols("X T", cls=Function) u = f(x, t) eq = u.diff(x, 2) - u.diff(t, 2) res = pde_separate(eq, u, [T(x), X(t)]) assert res == [D(T(x), x, x) / T(x), D(X(t), t, t) / X(t)]
def test_euler_henonheiles(): x = Function('x') y = Function('y') t = Symbol('t') L = sum(D(z(t), t)**2 / 2 - z(t)**2 / 2 for z in [x, y]) L += -x(t)**2 * y(t) + y(t)**3 / 3 assert euler(L, [x(t), y(t)], t) == [ Eq(-2 * x(t) * y(t) - x(t) - D(x(t), t, t), 0), Eq(-x(t)**2 + y(t)**2 - y(t) - D(y(t), t, t), 0) ]
def test_euler_interface(): x = Function('x') y = Symbol('y') t = Symbol('t') raises(TypeError, lambda: euler()) raises(TypeError, lambda: euler(D(x(t), t) * y(t), [x(t), y])) raises(ValueError, lambda: euler(D(x(t), t) * x(y), [x(t), x(y)])) raises(TypeError, lambda: euler(D(x(t), t)**2, x(0))) raises(TypeError, lambda: euler(D(x(t), t) * y(t), [t])) assert euler(D(x(t), t)**2 / 2, {x(t)}) == [Eq(-D(x(t), t, t), 0)] assert euler(D(x(t), t)**2 / 2, x(t), {t}) == [Eq(-D(x(t), t, t), 0)]
def test_pde_separate_mul(): x, y, z, t = symbols("x,y,z,t") c = Symbol("C", real=True) Phi = Function('Phi') F, R, T, X, Y, Z, u = map(Function, 'FRTXYZu') r, theta, z = symbols('r,theta,z') # Something simple :) eq = Eq(D(F(x, y, z), x) + D(F(x, y, z), y) + D(F(x, y, z), z), 0) # Duplicate arguments in functions raises(ValueError, lambda: pde_separate_mul(eq, F(x, y, z), [X(x), u(z, z)])) # Wrong number of arguments raises(ValueError, lambda: pde_separate_mul(eq, F(x, y, z), [X(x), Y(y)])) # Wrong variables: [x, y] -> [x, z] raises(ValueError, lambda: pde_separate_mul(eq, F(x, y, z), [X(t), Y(x, y)])) assert pde_separate_mul(eq, F(x, y, z), [Y(y), u(x, z)]) == \ [D(Y(y), y)/Y(y), -D(u(x, z), x)/u(x, z) - D(u(x, z), z)/u(x, z)] assert pde_separate_mul(eq, F(x, y, z), [X(x), Y(y), Z(z)]) == \ [D(X(x), x)/X(x), -D(Z(z), z)/Z(z) - D(Y(y), y)/Y(y)] # wave equation wave = Eq(D(u(x, t), t, t), c**2 * D(u(x, t), x, x)) res = pde_separate_mul(wave, u(x, t), [X(x), T(t)]) assert res == [D(X(x), x, x) / X(x), D(T(t), t, t) / (c**2 * T(t))] # Laplace equation in cylindrical coords eq = Eq( 1 / r * D(Phi(r, theta, z), r) + D(Phi(r, theta, z), r, 2) + 1 / r**2 * D(Phi(r, theta, z), theta, 2) + D(Phi(r, theta, z), z, 2), 0) # Separate z res = pde_separate_mul(eq, Phi(r, theta, z), [Z(z), u(theta, r)]) assert res == [ D(Z(z), z, z) / Z(z), -D(u(theta, r), r, r) / u(theta, r) - D(u(theta, r), r) / (r * u(theta, r)) - D(u(theta, r), theta, theta) / (r**2 * u(theta, r)) ] # Lets use the result to create a new equation... eq = Eq(res[1], c) # ...and separate theta... res = pde_separate_mul(eq, u(theta, r), [T(theta), R(r)]) assert res == [ D(T(theta), theta, theta) / T(theta), -r * D(R(r), r) / R(r) - r**2 * D(R(r), r, r) / R(r) - c * r**2 ] # ...or r... res = pde_separate_mul(eq, u(theta, r), [R(r), T(theta)]) assert res == [ r * D(R(r), r) / R(r) + r**2 * D(R(r), r, r) / R(r) + c * r**2, -D(T(theta), theta, theta) / T(theta) ]
def test_pde_separate(): x, y, z, t = symbols("x,y,z,t") F, T, X, Y, Z, u = map(Function, 'FTXYZu') eq = Eq(D(u(x, t), x), D(u(x, t), t) * exp(u(x, t))) raises(ValueError, lambda: pde_separate(eq, u(x, t), [X(x), T(t)], 'div'))
def test_euler_high_order(): # an example from hep-th/0309038 m = Symbol('m') k = Symbol('k') x = Function('x') y = Function('y') t = Symbol('t') L = (m * D(x(t), t)**2 / 2 + m * D(y(t), t)**2 / 2 - k * D(x(t), t) * D(y(t), t, t) + k * D(y(t), t) * D(x(t), t, t)) assert euler(L, [x(t), y(t)]) == [ Eq(2 * k * D(y(t), t, t, t) - m * D(x(t), t, t), 0), Eq(-2 * k * D(x(t), t, t, t) - m * D(y(t), t, t), 0) ] w = Symbol('w') L = D(x(t, w), t, w)**2 / 2 assert euler(L) == [Eq(D(x(t, w), t, t, w, w), 0)]
def test_euler_pendulum(): x = Function('x') t = Symbol('t') L = D(x(t), t)**2 / 2 + cos(x(t)) assert euler(L, x(t), t) == [Eq(-sin(x(t)) - D(x(t), t, t), 0)]