Example #1
0
def ex3(N, hk, r0):
    r"""
    Compute the integral of  :math:`1_{|[x,y]|<= r0}`
    :math: `r0<=0.5*sqrt(2)`

    Parameters
    ----------
    N : int
        Order of base quadrature rule
    hk : double
         submesh element diameter
    r0 : integrand parameter
    """

    quad = Quadrature.GaussTriangle(N)
    comp_quad = Quadrature.CompositeTriangle(quad, hk)

    N = int(np.ceil(old_div(1, hk)))

    ii = np.sum(comp_quad.weights[np.less_equal(
        comp_quad.points[:, 0]**2 + comp_quad.points[:, 1]**2, r0 * r0)])
    ee = np.abs(ii - r0**2 * 0.25 * np.pi)
    logEvent("hk=%f\t true-int=%f\t comp-int=%f error=%f" %
             (old_div(1.0, N), r0**2 * 0.25 * np.pi, ii, ee))
    return old_div(1.0, N), ee
Example #2
0
def ex4(N, hk):
    r"""
    Compute the integral of :math:`x` over the reference triangle

    Parameters
    ----------
    N : int
        Order of base quadrature rule
    hk : double
         submesh element diameter
    """

    quad = Quadrature.GaussTriangle(N)
    comp_quad = Quadrature.CompositeTriangle(quad, hk)

    N = int(np.ceil(old_div(1, hk)))

    quad_points = np.asarray(quad.points, 'd')
    quad_weights = np.asarray(quad.weights, 'd')

    ii_quad = np.sum(quad_weights * quad_points[:, 0])
    ii_comp_quad = np.sum(comp_quad.weights * comp_quad.points[:, 0])

    ee = np.abs(ii_quad - ii_comp_quad)
    logEvent("hk=%f\t quad-int=%f\t comp-quad-int=%f error=%f" %
             (old_div(1.0, N), ii_quad, ii_comp_quad, ee))
    return old_div(1.0, N), ee
Example #3
0
def ex2(N, hk, x0, y0):
    r"""
    Compute the integral of :math:`1_{x0*y+y0*x<= x0*y0}`
    :math:`0\leqx0\leq1` and :math:`0\leqy0\leq1`

    Parameters
    ----------
    N : int
        Order of base quadrature rule
    hk : double
         submesh element diameter
    x0 : integrand parameter
    y0 : integrand parameter
    """

    quad = Quadrature.GaussTriangle(N)
    comp_quad = Quadrature.CompositeTriangle(quad, hk)

    N = int(np.ceil(old_div(1, hk)))

    ii = np.sum(comp_quad.weights[np.less_equal(
        comp_quad.points[:, 0] * y0 + comp_quad.points[:, 1] * x0, x0 * y0)])

    ee = np.abs(ii - x0 * y0 * 0.5)

    logEvent("hk=%f\t true-int=%f\t comp-int=%f error=%f" %
             (old_div(1.0, N), x0 * y0 * 0.5, ii, ee))
    return old_div(1.0, N), ee