def compute_resonances(elt=None, K0=None, K1=None, K2=None, neigs=0):
    """
    Compute resonances via a generalized linear eigenvalue problem.

    Input:
        elt
        K0
        K1
        K2
        neigs -- Number of poles desired (default: 0 --> compute all)

    Output:
        l
        V
    """

    if elt is not None:
        (N, nnz) = problem_size(elt)
        issparse = (neigs != 0) and (nnz < 0.2 * N ** 2) and (N > 100)
        (K0, K1, K2) = form_operators(elt, issparse)

    N = len(K0)

    # TODO: Adding sparsity
    Z = np.zeros((N, N))
    I = np.eye(N)

    A = np.vstack((np.hstack((K0, Z)), np.hstack((Z, I))))
    B = np.vstack((np.hstack((-K1, -K2)), np.hstack((I, Z))))

    ll = eig(a=A, b=B, left=False, right=False)
    ll_sorted = (np.unique(ll.round(decimals=4)))[np.argsort(np.abs(np.unique(ll.round(decimals=4))))]
    ll_sorted = ll_sorted[np.abs(ll_sorted) < 1e308]
    return ll_sorted * 1.0j
示例#2
0
def compute_scatter (elt, l):
    """
    Compute the scattered wave in response to a plane wave of the form exp(i*l*x)
    """
    (K0, K1, K2) = form_operators (elt, l)
    F = plane_forcing (elt, l)
    return np.linalg.solve((-l*l*K2 + 1.0j*l*K1 + K0), F)