Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F60177114
nonlinear_eigenproblem.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Apr 28, 02:24
Size
4 KB
Mime Type
text/x-objective-c
Expires
Tue, Apr 30, 02:24 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
17313154
Attached To
R6746 RationalROMPy
nonlinear_eigenproblem.py
View Options
# 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
#import scipy.sparse as scsp
from
rrompy.utilities.base.types
import
Tuple
,
List
,
Np1D
,
Np2D
from
.custom_pinv
import
customPInv
__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
Pinv
=
customPInv
(
P
)
return
ev
,
P
,
Pinv
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
)
#def linearizeSparse(As:List[Np2D], jSupp : int = 1) -> Tuple[Np2D, Np2D]:
# N = len(As)
# n = As[0].shape[0]
# if isinstance(jSupp, str) and jSupp.upper() == "COMPANION":
# II = np.arange(n, (N - 1) * n)
# III = np.arange((N - 2) * n + 1)
# IIII = np.arange(0, n ** 2, n)
# improve management of sparse As...
# Alist = - np.hstack([A.todense() for A in As[-2 :: -1]])
# stiffD = np.concatenate((Alist.flatten(), np.ones((N - 2) * n)))
# stiffP = np.concatenate(((N - 1) * IIII, (N - 1) * n ** 2 + III))
# stiffI = np.concatenate((np.tile(np.arange((N - 1) * n), n), II - n))
# massD = np.concatenate((As[-1].todense().flatten(),
# np.ones((N - 2) * n)))
# massP = np.concatenate((IIII, n ** 2 + III))
# massI = np.concatenate((np.tile(np.arange(n), n), II))
# else:
# compute stiffD, stiffP, stiffI depending on jSupp
# compute massD, massP, massI depending on jSupp
# stiff = scsp.csr_matrix((stiffD, stiffI, stiffP),
# shape = ((N - 1) * n, (N - 1) * n))
# mass = scsp.csr_matrix((massD, massI, massP),
# shape = ((N - 1) * n, (N - 1) * n))
# return stiff, mass
#
#def eigNonlinearSparse(As:List[Np2D], jSupp : int = 1,
# return_inverse : bool = False,
# **kwargs_eig) -> Tuple[Np1D, Np2D]:
# stiff, mass = linearizeSparse(As, jSupp)
# ev, P = scsp.linalg.eig(stiff, M = mass, return_eigenvectors = True,
# **kwargs_eig)
# if not return_inverse: return ev, P
# Pinv = customPInv(P)
# return ev, P, Pinv
#
#def eigvalsNonlinearSparse(As:List[Np2D], jSupp : int = 1,
# **kwargs_eigvals) -> Np1D:
# stiff, mass = linearizeSparse(As, jSupp)
# return scsp.linalg.eig(stiff, M = mass, return_eigenvectors = False,
# **kwargs_eigvals)
Event Timeline
Log In to Comment