Ejemplo n.º 1
0
def mbfv(x, p, poly_type):
    assert np.min(x) >= -1 and np.max(x) <= 1, "x should be in [-1,1]"
    assert p >= 1 and isinstance(p, int), "p should be positve integer"

    if poly_type == "LobN":  # lobatto polynomials
        nodes, weights = lobatto_quad(p)
        basis = lagrange_basis(nodes, x)
        return basis
    elif poly_type == "LobE":  # lobatto edges functions
        nodes, weights = lobatto_quad(p)
        basis = edge_basis(nodes, x)
        return basis

    elif poly_type == "GauN":  # gauss polynomials
        nodes, weights = gauss_quad(p)
        basis = lagrange_basis(nodes, x)
        return basis
    elif poly_type == "GauE":  # gauss edges functions
        nodes, weights = gauss_quad(p)
        basis = edge_basis(nodes, x)
        return basis

    elif poly_type == "etGN":  # extended-gauss polynomials
        nodes, weights = extended_gauss_quad(p)
        basis = lagrange_basis(nodes, x)
        return basis
    elif poly_type == "etGE":  # extended-gauss edges functions
        nodes, weights = extended_gauss_quad(p)
        basis = edge_basis(nodes, x)
        return basis

    else:
        raise Exception("Error, poly_type wrong......")
Ejemplo n.º 2
0
def integral1d_(metric, basis_1, basis_2, Quad=None):
    """
    #SUMMARY: Integrate "metric * basis_1 * basis_2" on [-1, 1]
    #OUTPUTS: [0] 2d array: basis_1 -> 1st axis
                            basis_2 -> 2nd axis
    """
    if isinstance(metric, types.FunctionType): pass
    elif isinstance(metric, int) or isinstance(metric, float):
        temp = metric

        def fun(x):
            return temp

        metric = fun
    else:
        raise Exception(
            "metric type wrong, only accept function, int or float")

    sd1 = _size_check(basis_1)
    sd2 = _size_check(basis_2)

    if Quad is None:
        QuadType, QuadOrder = 'gauss', np.int(np.ceil((sd1 + sd2) / 2 + 1))
    else:
        QuadType, QuadOrder = Quad

    if QuadType == 'gauss': Qnodes, weights = gauss_quad(QuadOrder)
    elif QuadType == 'lobatto': Qnodes, weights = lobatto_quad(QuadOrder)
    elif QuadType == 'extended_gauss':
        Qnodes, weights = extended_gauss_quad(QuadOrder)
    else:
        raise Exception(
            "Quad Type should be gauss, lobatto or extended_gauss.......")

    basis_1 = _bf_value(basis_1, Qnodes)
    basis_2 = _bf_value(basis_2, Qnodes)

    metric = metric(Qnodes)

    if np.size(metric) == 1: metric = metric * np.ones((np.size(Qnodes)))
    IntValue = np.einsum('ik,jk,k,k->ij', basis_1, basis_2, metric, weights)

    return IntValue
Ejemplo n.º 3
0

def vfunc(x, y):
    return -3 * np.pi * x * np.sin(3 * np.pi * x * y)


def f2func(x, y):
    return -9 * np.pi**2 * (x**2 + y**2) * np.cos(3 * np.pi * x * y)


# bounds_domain = ((0, 1), (0, 1))

nx = 2
ny = 2

ele_pnt_x = fn.lobatto_quad(nx)[0]
ele_pnt_y = fn.lobatto_quad(ny)[0]

ele_spa_x = [ele_pnt_x[i + 1] - ele_pnt_x[i] for i in range(0, nx)]
ele_spa_y = [ele_pnt_y[i + 1] - ele_pnt_y[i] for i in range(0, ny)]

Element_Spacing = [ele_spa_x, ele_spa_y]

n = (nx, ny)
p = (2, 2)
c = 0.
# ^^^^^^^^^^^^^^^^^^^^^^^^ standard ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
print("n, p, c=", n, p, c)

mesh = CrazyMesh(elements_layout=n,
Ejemplo n.º 4
0
            self.n_x, self.n_y, element)

        dy_deta_result = 0.5 * delta_y[index_y] * (self.y_bounds[1] - self.y_bounds[0]) * 0.5 + \
            np.pi * delta_y[index_y] * 0.5 * self.curvature * \
            np.cos(np.pi * ((eta + 1) * 0.5 * delta_y[index_y] + y_left)) * \
            np.sin(np.pi * ((xi + 1) * 0.5 * delta_x[index_x] + x_left)) * \
            (self.y_bounds[1] - self.y_bounds[0]) * 0.5
        return dy_deta_result


# %% THE MAIN TEST PART
if __name__ == '__main__':
    import functionals

    m, n = 13, 13
    ele_pnt_x = functionals.lobatto_quad(m)[0]
    ele_pnt_y = functionals.lobatto_quad(n)[0]

    ele_spa_x = [ele_pnt_x[i + 1] - ele_pnt_x[i] for i in range(0, m)]
    ele_spa_y = [ele_pnt_y[i + 1] - ele_pnt_y[i] for i in range(0, n)]

    Element_Spacing = [ele_spa_x, ele_spa_y]

    mesh = CrazyMesh((m, n), ((0, 1), (0, 1)),
                     curvature=0,
                     element_spacing=Element_Spacing)
    # xi = np.linspace(-1, 1, 10)
    # xi, eta = np.meshgrid(xi, xi)
    # x, y = mesh.mapping(xi, eta)
    mesh.plot_mesh()