Exemple #1
0
def phi_r(r, X, d):
    """
    Return local basis function phi_r at local point X in
    a 1D element with d+1 nodes.
    """
    nodes = np.linspace(-1, 1, d+1)
    return Lagrange_polynomial(X, r, nodes)
Exemple #2
0
def basis(d, point_distribution='uniform', symbolic=True):
    """
    Return all local basis function phi as functions of the
    local point X in a 1D element with d+1 nodes.
    If symbolic=True, return symbolic expressions, else
    return Python functions of X.
    point_distribution can be 'uniform' or 'Chebyshev'.
    """
    X = sym.symbols('X')
    if d == 0:
        phi_sym = [1]
    else:
        if point_distribution == 'uniform':
            if symbolic:
                h = sym.Rational(1, d)  # node spacing
                nodes = [2 * i * h - 1 for i in range(d + 1)]
            else:
                nodes = np.linspace(-1, 1, d + 1)
        elif point_distribution == 'Chebyshev':
            # Just numeric nodes
            nodes = Chebyshev_nodes(-1, 1, d)

        phi_sym = [Lagrange_polynomial(X, r, nodes) for r in range(d + 1)]
    # Transform to Python functions
    phi_num = [
        sym.lambdify([X], phi_sym[r], modules='numpy') for r in range(d + 1)
    ]
    return phi_sym if symbolic else phi_num
Exemple #3
0
def phi_r(r, X, d, point_distribution='uniform'):
    """
    Return local basis function phi_r at local point X in
    a 1D element with d+1 nodes.
    point_distribution can be 'uniform' or 'Chebyshev'.
    """
    if point_distribution == 'uniform':
        nodes = np.linspace(-1, 1, d+1)
    elif point_distribution == 'Chebyshev':
        nodes = Chebyshev_nodes(-1, 1, d)
    return Lagrange_polynomial(X, r, nodes)
Exemple #4
0
def phi_r(r, X, d):
    """
    Return local basis function phi_r at local point X in
    a 1D element with d+1 nodes.
    """
    if isinstance(X, sm.Symbol):
        # Use sm.Rational and integers for nodes
        # (to maximize nice-looking output)
        h = sm.Rational(1, d)
        nodes = [2 * i * h - 1 for i in range(d + 1)]
    else:
        # X is numeric: use floats for nodes
        nodes = np.linspace(-1, 1, d + 1)
    return Lagrange_polynomial(X, r, nodes)
Exemple #5
0
def phi_r(r, X, d, point_distribution='uniform'):
    """
    Return local basis function phi_r at local point X in
    a 1D element with d+1 nodes.
    point_distribution can be 'uniform' or 'Chebyshev'.
    """
    if point_distribution == 'uniform':
        if isinstance(X, sm.Symbol):
            # Use sm.Rational and integers for nodes
            # (to maximize nice-looking output)
            h = sm.Rational(1, d)
            nodes = [2 * i * h - 1 for i in range(d + 1)]
        else:
            # X is numeric: use floats for nodes
            nodes = np.linspace(-1, 1, d + 1)
    elif point_distribution == 'Chebyshev':
        nodes = Chebyshev_nodes(-1, 1, d)
    return Lagrange_polynomial(X, r, nodes)