コード例 #1
0
def test_surf_approx(n, f, true=None):
    '''Surface integral (for benchmark problem)'''
    omega = UnitCubeMesh(n, n, 2 * n)

    A = np.array([0.5, 0.5, 0.0])
    B = np.array([0.5, 0.5, 1.0])
    gamma = StraightLineMesh(A, B, 2 * n)

    V3 = FunctionSpace(omega, 'CG', 1)
    V1 = FunctionSpace(gamma, 'CG', 1)

    f3 = interpolate(f, V3)

    shape = SquareRim(P=lambda x: np.array([0.25, 0.25, x[2]]), degree=10)

    Pi = average_matrix(V3, V1, shape=shape)
    x = Pi * f3.vector()

    f1 = Function(V1, x)

    if true is None:
        true = f
    error = sqrt(abs(assemble(inner(true - f1, true - f1) * dx)))

    return gamma.hmin(), error, f1
コード例 #2
0
def poisson_1d(n, u_true, f):
    '''1d part of benchmark'''
    A, B = np.array([0.5, 0.5, 0]), np.array([0.5, 0.5, 1])
    mesh = StraightLineMesh(A, B, n)

    V = FunctionSpace(mesh, 'CG', 1)
    bc = DirichletBC(V, u_true, 'on_boundary')

    u, v = TrialFunction(V), TestFunction(V)
    a = inner(grad(u), grad(v)) * dx
    L = inner(f, v) * dx

    A, b = assemble_system(a, L, bc)

    solver = KrylovSolver('cg', 'amg')
    solver.parameters['relative_tolerance'] = 1E-13

    uh = Function(V)
    solver.solve(A, uh.vector(), b)

    return mesh.hmin(), errornorm(u_true, uh, 'H1'), uh
コード例 #3
0
def test_Pi(n, f3, f1, Pi_f3):
    '''(Pi u_3d, u_1d)_Gamma.'''
    # True here is the reduced one
    omega = UnitCubeMesh(n, n, 2*n)

    A = np.array([0.5, 0.5, 0.0])
    B = np.array([0.5, 0.5, 1.0])             
    gamma = StraightLineMesh(A, B, 2*n)

    V3 = FunctionSpace(omega, 'CG', 1)
    V1 = FunctionSpace(gamma, 'CG', 1)

    u3 = TrialFunction(V3)
    v1 = TestFunction(V1)

    shape = SquareRim(P=lambda x: np.array([0.25, 0.25, x[2]]),
                      degree=10)

    dx_ = Measure('dx', domain=gamma)
    a = inner(Average(u3, gamma, shape=shape), v1)*dx_

    A = ii_assemble(a)

    # Now check action
    f3h = interpolate(f3, V3)
    x = A*f3h.vector()

    f1h = interpolate(f1, V1)
    Pi_f = Function(V1, x)
    result = f1h.vector().inner(x)

    true = assemble(inner(Pi_f3, f1)*dx_)
    
    error = abs(true - result)

    return gamma.hmin(), error, Pi_f