Page MenuHomec4science

nonlinear_eigenproblem.py
No OneTemporary

File Metadata

Created
Fri, May 3, 22:23

nonlinear_eigenproblem.py

# Copyright (C) 2018 by the RROMPy authors
#
# This file is part of RROMPy.
#
# RROMPy is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# RROMPy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with RROMPy. If not, see <http://www.gnu.org/licenses/>.
#
import numpy as np
import scipy.linalg as scla
from rrompy.utilities.base.types import Tuple, List, Np1D, Np2D
from .pseudo_inverse import pseudoInverse
__all__ = ['linearizeDense', 'eigNonlinearDense', 'eigvalsNonlinearDense']
def linearizeDense(As:List[Np2D], jSupp : int = 1) -> Tuple[Np2D, Np2D]:
N = len(As)
n = As[0].shape[0]
stiff = np.zeros(((N - 1) * n, (N - 1) * n), dtype = As[0].dtype)
mass = np.zeros(((N - 1) * n, (N - 1) * n), dtype = As[0].dtype)
if N > 1:
if isinstance(jSupp, str) and jSupp.upper() == "COMPANION":
II = np.arange(n, (N - 1) * n)
stiff = np.pad(- np.hstack(As[-2 :: -1]),
[[0, (N - 2) * n], [0, 0]], "constant")
stiff[II, II - n] = 1.
mass = np.pad(As[-1], [0, (N - 2) * n], "constant")
mass[II, II] = 1.
else:
for j in range(jSupp):
for k in range(jSupp - j - 1, jSupp):
mass[n * j : n * (j + 1), k * n : (k + 1) * n] = \
As[N - 2 + jSupp - k - j]
for j in range(jSupp - 1, N - 1):
for k in range(jSupp, N - 1 + jSupp - j):
stiff[n * j : n * (j + 1), (k - 1) * n : k * n] = \
- As[jSupp - k + N - 2 - j]
stiff[: n * (jSupp - 1), : n * (jSupp - 1)] = \
mass[: n * (jSupp - 1), n : n * jSupp]
mass[n * jSupp :, n * jSupp :] = stiff[n * (jSupp - 1) : - n,
n * jSupp :]
return stiff, mass
def eigNonlinearDense(As:List[Np2D], jSupp : int = 1,
return_inverse : bool = False,
**kwargs_eig) -> Tuple[Np1D, Np2D]:
stiff, mass = linearizeDense(As, jSupp)
if stiff.shape[0] == 0: return stiff, stiff
ev, P = scla.eig(stiff, mass, overwrite_a = True, overwrite_b = True,
**kwargs_eig)
if not return_inverse: return ev, P
return ev, P, pseudoInverse(P)
def eigvalsNonlinearDense(As:List[Np2D], jSupp : int = 1,
**kwargs_eigvals) -> Np1D:
stiff, mass = linearizeDense(As, jSupp)
if stiff.shape[0] == 0: return stiff
return scla.eigvals(stiff, mass, overwrite_a = True, **kwargs_eigvals)

Event Timeline