示例#1
0
def test_jac(mesh, ref1, ref2, refi):
    X, cells = mesh()

    jac = cpt.jac_uniform(X, cells)

    nc = jac.flatten()
    norm1 = numpy.linalg.norm(nc, ord=1)
    norm2 = numpy.linalg.norm(nc, ord=2)
    normi = numpy.linalg.norm(nc, ord=numpy.inf)

    tol = 1.0e-12
    assert abs(norm1 - ref1) < tol * ref1
    assert abs(norm2 - ref2) < tol * ref2
    assert abs(normi - refi) < tol * refi
    return
示例#2
0
def test_simple1_jac():
    X, cells = simple1()

    # First assert that the Jacobian at interior points coincides with the finite
    # difference computed for the energy component from that point. Note that the
    # contribution from all other points is disregarded here, just like in the
    # definition of the Jacobian of Chen-Holst; it's only an approximation after all.
    jac = cpt.jac_uniform(X, cells)
    for j in [0, 1]:
        eps = 1.0e-7
        x0 = X.copy()
        x1 = X.copy()
        x0[4, j] -= eps
        x1[4, j] += eps
        f1 = cpt._energy_uniform_per_node(x1, cells)
        f0 = cpt._energy_uniform_per_node(x0, cells)
        dE = (f1 - f0) / (2 * eps)
        assert abs(dE[4] - jac[4, j]) < 1.0e-10

    return