def test_differential_operators_curvilinear_system(): A = CoordSysCartesian('A') A._set_lame_coefficient_mapping('spherical') B = CoordSysCartesian('B') B._set_lame_coefficient_mapping('cylindrical') # Test for spherical coordinate system and gradient assert gradient(3 * A.x + 4 * A.y) == 3 * A.i + 4 / A.x * A.j assert gradient( 3 * A.x * A.z + 4 * A.y) == 3 * A.z * A.i + 4 / A.x * A.j + (3 / sin(A.y)) * A.k assert gradient(0 * A.x + 0 * A.y + 0 * A.z) == Vector.zero assert gradient( A.x * A.y * A.z) == A.y * A.z * A.i + A.z * A.j + (A.y / sin(A.y)) * A.k # Test for spherical coordinate system and divergence assert divergence(A.x * A.i + A.y * A.j + A.z * A.k) == \ (sin(A.y)*A.x + cos(A.y)*A.x*A.y)/(sin(A.y)*A.x**2) + 3 + 1/(sin(A.y)*A.x) assert divergence(3*A.x*A.z*A.i + A.y*A.j + A.x*A.y*A.z*A.k) == \ (sin(A.y)*A.x + cos(A.y)*A.x*A.y)/(sin(A.y)*A.x**2) + 9*A.z + A.y/sin(A.y) assert divergence(Vector.zero) == 0 assert divergence(0 * A.i + 0 * A.j + 0 * A.k) == 0 # Test for cylindrical coordinate system and divergence assert divergence(B.x * B.i + B.y * B.j + B.z * B.k) == 2 + 1 / B.y assert divergence(B.x * B.j + B.z * B.k) == 1 # Test for spherical coordinate system and divergence assert curl(A.x*A.i + A.y*A.j + A.z*A.k) == \ (cos(A.y)*A.z/(sin(A.y)*A.x))*A.i + (-A.z/A.x)*A.j + A.y/A.x*A.k assert curl(A.x * A.j + A.z * A.k) == (cos(A.y) * A.z / (sin(A.y) * A.x)) * A.i + (-A.z / A.x) * A.j + 2 * A.k
def test_lame_coefficients(): a = CoordSysCartesian('a') a._set_lame_coefficient_mapping('spherical') assert a.lame_coefficients() == (1, a.x, sin(a.y) * a.x) a = CoordSysCartesian('a') assert a.lame_coefficients() == (1, 1, 1) a = CoordSysCartesian('a') a._set_lame_coefficient_mapping('cartesian') assert a.lame_coefficients() == (1, 1, 1) a = CoordSysCartesian('a') a._set_lame_coefficient_mapping('cylindrical') assert a.lame_coefficients() == (1, a.y, 1)