def test_zero_div(self): g = lbnz.div(lbnz.curl(lbnz.thetaphir.phi)) self.assertAlmostEqualWithMagnitude(0, g, 6) g = lbnz.div(lbnz.curl(lbnz.thetaphir.theta)) self.assertAlmostEqualWithMagnitude(0, g, 6) g = lbnz.div(lbnz.curl(lbnz.thetaphir.r)) self.assertAlmostEqualWithMagnitude(0, g, 6) phx, phy, phz = lbnz.thetaphir.phi thx, thy, thz = lbnz.thetaphir.theta rx, ry, rz = lbnz.thetaphir.r g = lbnz.div(lbnz.curl((rx * rx + phx * thx, ry * ry + phy * thy, rz * rz + phz * thz))) self.assertAlmostEqualWithMagnitude(0, g, 6)
def test_curl1(self): # F = (y, -x, 0) # expect that curl_F = (0, 0, -2) fld = lbnz.y, -lbnz.x, lbnz.zero expt_x, expt_y, expt_z = lbnz.zero, lbnz.zero, -2 * lbnz.one test_x, test_y, test_z = lbnz.curl(fld) self.assertAlmostEqualWithMagExceptBoundary(expt_x, test_x, 6) self.assertAlmostEqualWithMagExceptBoundary(expt_y, test_y, 6) self.assertAlmostEqualWithMagExceptBoundary(expt_z, test_z, 6)
def test_curl2(self): # F = (0, cos(phi), 0) # expect that curl = (-cos(phi)/r, 0, -2*sin(phi)/r) fld = 0, th.cos(lbnz.phi), 0 expected_ph = -th.cos(lbnz.phi) / lbnz.r expected_th = lbnz.zero expected_r = -2 * th.sin(lbnz.phi) / lbnz.r test_ph, test_th, test_r = lbnz.curl(fld) self.assertAlmostEqualWithMagnitude(expected_ph, test_ph, 6) self.assertAlmostEqualWithMagnitude(expected_th, test_th, 6) self.assertAlmostEqualWithMagnitude(expected_r, test_r, 6)
def test_zero_curl(self): g0, g1, g2 = lbnz.curl(lbnz.grad(lbnz.x)) self.assertAlmostEqualWithMagExceptBoundary(lbnz.zero, g0, 6) self.assertAlmostEqualWithMagExceptBoundary(lbnz.zero, g1, 6) self.assertAlmostEqualWithMagExceptBoundary(lbnz.zero, g2, 6) g0, g1, g2 = lbnz.curl(lbnz.grad(lbnz.y)) self.assertAlmostEqualWithMagExceptBoundary(lbnz.zero, g0, 6) self.assertAlmostEqualWithMagExceptBoundary(lbnz.zero, g1, 6) self.assertAlmostEqualWithMagExceptBoundary(lbnz.zero, g2, 6) g0, g1, g2 = lbnz.curl(lbnz.grad(lbnz.z)) self.assertAlmostEqualWithMagExceptBoundary(lbnz.zero, g0, 6) self.assertAlmostEqualWithMagExceptBoundary(lbnz.zero, g1, 6) self.assertAlmostEqualWithMagExceptBoundary(lbnz.zero, g2, 6) g0, g1, g2 = lbnz.curl(lbnz.grad(lbnz.z * lbnz.z + lbnz.x * lbnz.y)) self.assertAlmostEqualWithMagExceptBoundary(lbnz.zero, g0, 6) self.assertAlmostEqualWithMagExceptBoundary(lbnz.zero, g1, 6) self.assertAlmostEqualWithMagExceptBoundary(lbnz.zero, g2, 6)
def test_curl2(self): # F = (0, - x**2, 0) # expect that curl_F = (0, 0, -2 * x) fld = lbnz.zero, -lbnz.x * lbnz.x, lbnz.zero expt_x, expt_y, expt_z = lbnz.zero, lbnz.zero, -2 * lbnz.x test_x, test_y, test_z = lbnz.curl(fld) self.assertAlmostEqualWithMagExceptBoundary(expt_x, test_x, 6) self.assertAlmostEqualWithMagExceptBoundary(expt_y, test_y, 6) self.assertAlmostEqualWithMagExceptBoundary(expt_z, test_z, 6) self.assertAlmostEqualWithMagnitude(expt_x, test_x, 6) self.assertAlmostEqualWithMagnitude(expt_y, test_y, 6) self.assertAlmostEqualWithMagnitude(expt_z, test_z, 6)
def test_zero_curl(self): g0, g1, g2 = lbnz.curl(lbnz.grad(lbnz.lat)) self.assertAlmostEqualWithMagnitude(0, g0, 6) self.assertAlmostEqualWithMagnitude(0, g1, 6) self.assertAlmostEqualWithMagnitude(0, g2, 6) g0, g1, g2 = lbnz.curl(lbnz.grad(lbnz.lng)) self.assertAlmostEqualWithMagnitude(0, g0, 6) self.assertAlmostEqualWithMagnitude(0, g1, 6) self.assertAlmostEqualWithMagnitude(0, g2, 6) g0, g1, g2 = lbnz.curl(lbnz.grad(lbnz.alt)) self.assertAlmostEqualWithMagnitude(0, g0, 6) self.assertAlmostEqualWithMagnitude(0, g1, 6) self.assertAlmostEqualWithMagnitude(0, g2, 6) g0, g1, g2 = lbnz.curl(lbnz.grad(lbnz.alt * lbnz.alt + lbnz.lng * lbnz.lat)) self.assertAlmostEqualWithMagnitude(0, g0, 6) self.assertAlmostEqualWithMagnitude(0, g1, 6) self.assertAlmostEqualWithMagnitude(0, g2, 6)
def test_curl1(self): # F = (-theta, phi * theta, r); # expect that curl_F = (-phi*theta/r, -theta/r, (theta-phi*theta*tan(phi)+1/cos(phi))/r) fld = - lbnz.theta, lbnz.phi * lbnz.theta, lbnz.r expected_ph = -lbnz.phi * lbnz.theta / lbnz.r expected_th = -lbnz.theta / lbnz.r expected_r = (lbnz.theta - lbnz.phi * lbnz.theta * th.tan(lbnz.phi) + 1 / th.cos(lbnz.phi)) / lbnz.r test_ph, test_th, test_r = lbnz.curl(fld) self.assertAlmostEqualWithMagnitude(expected_ph, test_ph, 6) self.assertAlmostEqualWithMagnitude(expected_th, test_th, 6) self.assertAlmostEqualWithMagnitude(expected_r, test_r, 6)