Exemple #1
0
def simple_mass_matrix(n_elements = 2, continuous = False):
    bf = basis_funcs.basis_from_degree(1)
    msh = simple_line_mesh(n_elements)
    q = quadrature.gauss(2)
    apply_to_elements(msh, "basis", bf, non_gen = True)
    apply_to_elements(msh, "continuous", continuous, non_gen = True)
    init_dofs(msh)
    return assemble_mass_matrix(msh, q)
Exemple #2
0
def test_M_integral_diff_dof():
    msh = simple_line_mesh(2)
    q = quadrature.gauss(2)
    bf = basis_funcs.basis_from_degree(1)
    kernel = MassMatrixKernel(0, 0)
    M_local = single_integral(msh.elements[0].mapping.eval, kernel, bf,
          bf, q, 0, 1)
    # integral of (1-x)*x from 0 to 1
    np.testing.assert_almost_equal(M_local[0][0], 1.0 / 6.0)
Exemple #3
0
def test_M_integral_same_dof_with_jacobian():
    msh = simple_line_mesh(4)
    q = quadrature.gauss(2)
    bf = basis_funcs.basis_from_degree(1)
    kernel = MassMatrixKernel(0, 0)
    M_local = single_integral(msh.elements[0].mapping.eval, kernel, bf,
                              bf, q, 0, 0)
    # Element size divided by two so the M value should be divided by two
    np.testing.assert_almost_equal(M_local[0][0], 1.0 / 6.0)
Exemple #4
0
def test_mass_matrix_functional():
    bf = basis_funcs.basis_from_nodes([0.001, 0.999])
    msh = simple_line_mesh(2)
    q = quadrature.gauss(2)
    apply_to_elements(msh, "basis", bf, non_gen = True)
    apply_to_elements(msh, "continuous", False, non_gen = True)
    init_dofs(msh)

    fnc_coeffs = interpolate(lambda x,d: [[1,2][x[0] >= 0]] * 2, msh)
    apply_coeffs(msh, fnc_coeffs, "function_yay")
    basis_grabber = lambda e: e.function_yay

    m = mass_matrix_for_rhs(assemble_mass_matrix(msh, q, basis_grabber))
    M_exact = [0.5, 0.5, 1.0, 1.0]
    np.testing.assert_almost_equal(M_exact, m[0:4])
Exemple #5
0
def test_gauss():
    qi = gauss(3)
    np.testing.assert_almost_equal(qi.x[0], sqrt(3.0 / 5.0) * 0.5 + 0.5)
Exemple #6
0
from codim1.fast_lib import double_integral, single_integral,\
    MassMatrixKernel, ZeroBasis, ConstantBasis
from which_kernels import _make_which_kernels
from shared import _choose_basis
from codim1.post.interior import interior
from codim1.core.quadrature import gauss

import numpy as np

gauss40 = gauss(40)

"""
These functions traverse the mesh and form the symmetric galerkin
matrices and right hand side vectors.

The implementation here follows equations 14 through 17 in the Bonnet 98
paper very closely.

This assumes that all the boundary conditions have already been attached to
the relevant element in the mesh.
"""
def sgbem_assemble(mesh, kernel_set):
    # Form the empty linear system
    total_dofs = mesh.total_dofs
    lhs_matrix = np.zeros((total_dofs, total_dofs))
    rhs_matrix = np.zeros((total_dofs, total_dofs))
    mass_matrix = np.zeros((total_dofs, total_dofs))

    # Set the kernels for each type of boundary condition.
    which_kernels = _make_which_kernels(kernel_set)