Exemplo n.º 1
0
def exercise_volume():
  for (a,b,c) in ((1,2,3), (2,3,1), (3,1,2)):
    for vertices in permutations(((1,1,1), (1+a,1,1), (1,1+b,1), (1,1,1+c))):
      t = tetrahedron(vertices)
      assert t.vertices == vertices
      vol = a*b*c/6
      assert approx_equal(t.volume(), vol)
  # regular tetrahedron
  for vertices in permutations(((1,1,1), (1,-1,-1), (-1,1,-1), (-1,-1,1))):
    t = tetrahedron(vertices)
    assert approx_equal(t.volume(), 8/3)
Exemplo n.º 2
0
def exercise_volume():
    for (a, b, c) in ((1, 2, 3), (2, 3, 1), (3, 1, 2)):
        for vertices in permutations(
            ((1, 1, 1), (1 + a, 1, 1), (1, 1 + b, 1), (1, 1, 1 + c))):
            t = tetrahedron(vertices)
            assert t.vertices == vertices
            vol = a * b * c / 6
            assert approx_equal(t.volume(), vol)
    # regular tetrahedron
    for vertices in permutations(
        ((1, 1, 1), (1, -1, -1), (-1, 1, -1), (-1, -1, 1))):
        t = tetrahedron(vertices)
        assert approx_equal(t.volume(), 8 / 3)
Exemplo n.º 3
0
def exercise_gradients(n_points):
  eta = 1e-6
  for i in xrange(n_points):
    v = tuple((random(), random(), random()) for j in xrange(4))
    t = tetrahedron(v)
    g = t.gradients()
    for j in xrange(4):
      for k in xrange(3):
        (tm, tp) = tuple(tetrahedron(
          v[:j] + (v[j][:k] + (v[j][k] + h,) + v[j][k+1:],) + v[j+1:])
          for h in (-eta, eta))
        dv = (tp.volume() - tm.volume())/(2*eta)
        assert approx_equal(dv, g[j][k]), (j,k)
Exemplo n.º 4
0
def exercise_gradients(n_points):
    eta = 1e-6
    for i in range(n_points):
        v = tuple((random(), random(), random()) for j in range(4))
        t = tetrahedron(v)
        g = t.gradients()
        for j in range(4):
            for k in range(3):
                (tm, tp) = tuple(
                    tetrahedron(v[:j] + (v[j][:k] +
                                         (v[j][k] + h, ) + v[j][k + 1:], ) +
                                v[j + 1:]) for h in (-eta, eta))
                dv = (tp.volume() - tm.volume()) / (2 * eta)
                assert approx_equal(dv, g[j][k]), (j, k)