コード例 #1
0
def test_helper():
    assert_equal(fem.make_list(1), [1])
    assert_equal(fem.make_list([2]), [2])
    assert_equal(fem.make_list([1, 2]), [1, 2])
    assert_equal(fem.make_list([5], 3), [5, 5, 5])
    assert_equal(fem.make_list([1, 2], 3), [1, 2])

    mesh = UnitSquare(3, 3)

    V1 = dolfin.FunctionSpace(mesh, "Lagrange", 1)
    V1v = dolfin.VectorFunctionSpace(mesh, "Lagrange", 1)
    V2 = dolfin.FunctionSpace(mesh, "Lagrange", 2)
    V2v = dolfin.VectorFunctionSpace(mesh, "Lagrange", 2)
    
    assert_zero_func(fem.zero_function(V1), V1)
    assert_zero_func(fem.zero_function(V1v), V1v)
    assert_zero_func(fem.zero_function(V2), V2)
    assert_zero_func(fem.zero_function(V2v), V2v)

    assert_equal(fem.element_degree(dolfin.Function(V1)), 1)
    assert_equal(fem.element_degree(dolfin.TestFunction(V1)), 1)
    assert_equal(fem.element_degree(dolfin.TrialFunction(V1)), 1)
    assert_equal(fem.element_degree(dolfin.Function(V1v)), 1)
    assert_equal(fem.element_degree(dolfin.TestFunction(V1v)), 1)
    assert_equal(fem.element_degree(dolfin.TrialFunction(V1v)), 1)
    assert_equal(fem.element_degree(dolfin.Function(V2)), 2)
    assert_equal(fem.element_degree(dolfin.TestFunction(V2)), 2)
    assert_equal(fem.element_degree(dolfin.TrialFunction(V2)), 2)
    assert_equal(fem.element_degree(dolfin.Function(V2v)), 2)
    assert_equal(fem.element_degree(dolfin.TestFunction(V2v)), 2)
    assert_equal(fem.element_degree(dolfin.TrialFunction(V2v)), 2)
コード例 #2
0
ファイル: adaptive_solver.py プロジェクト: SpuqTeam/spuq
def prepare_rhs(A, w, coeff_field, pde):
    b = 0 * w
    zero = Multiindex()
    b[zero].coeffs = pde.assemble_rhs(basis=b[zero].basis, coeff=coeff_field.mean_func,
                                      withNeumannBC=True)
    
    f = pde.f
    if f.value_rank() == 0:
        zero_func = Constant(0.0)
    else:
        zero_func = Constant((0.0,) * f.value_size())
    zero_func = zero_function(b[zero].basis._fefs) 

    for m in range(w.max_order):
        eps_m = zero.inc(m)
        am_f, am_rv = coeff_field[m]
        beta = am_rv.orth_polys.get_beta(0)

        if eps_m in b.active_indices():
            g0 = b[eps_m].copy()
            g0.coeffs = pde.assemble_rhs(basis=b[eps_m].basis, coeff=am_f, withNeumannBC=False, f=zero_func)  # this equates to homogeneous Neumann bc
            pde.set_dirichlet_bc_entries(g0, homogeneous=True)
            b[eps_m] += beta[1] * g0

        g0 = b[zero].copy()
        g0.coeffs = pde.assemble_rhs(basis=b[zero].basis, coeff=am_f, f=zero_func)
        pde.set_dirichlet_bc_entries(g0, homogeneous=True)
        b[zero] += beta[0] * g0
    return b