Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F85920724
generic_problem_engine.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
Thu, Oct 3, 01:13
Size
2 KB
Mime Type
text/x-python
Expires
Sat, Oct 5, 01:13 (2 d)
Engine
blob
Format
Raw Data
Handle
21299468
Attached To
R6746 RationalROMPy
generic_problem_engine.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/>.
#
from
abc
import
abstractmethod
import
numpy
as
np
import
scipy.sparse.linalg
as
scspla
from
rrompy.utilities.base.types
import
Np1D
,
Np2D
,
Tuple
,
List
__all__
=
[
'GenericProblemEngine'
]
class
GenericProblemEngine
:
"""
Generic solver for parametric problems.
Attributes:
As: Scipy sparse array representation (in CSC format) of As.
bs: Numpy array representation of bs.
"""
Aterms
,
bterms
=
1
,
1
mu0Blocks
=
0.
functional
=
lambda
self
,
u
:
0.
def
name
(
self
)
->
str
:
return
self
.
__class__
.
__name__
def
__str__
(
self
)
->
str
:
return
self
.
name
()
@abstractmethod
def
energyNormMatrix
(
self
)
->
Np2D
:
"""Sparse matrix (in CSR format) representative of scalar product."""
pass
@abstractmethod
def
assembleA
(
self
):
"""Assemble matrix blocks of linear system."""
self
.
As
=
[
None
]
*
1
pass
@abstractmethod
def
assembleb
(
self
):
"""Assemble matrix blocks of linear system."""
self
.
bs
=
[
None
]
*
1
pass
def
A
(
self
,
mu
:
complex
)
->
Np2D
:
"""Assemble matrix of linear system."""
self
.
assembleA
()
A
=
self
.
As
[
0
]
for
j
in
range
(
1
,
len
(
self
.
As
)):
A
=
A
+
np
.
power
(
mu
,
j
)
*
self
.
As
[
j
]
return
A
def
b
(
self
,
mu
:
complex
)
->
Np1D
:
"""Assemble RHS of linear system."""
self
.
assembleb
()
b
=
self
.
bs
[
0
]
for
j
in
range
(
1
,
len
(
self
.
bs
)):
b
=
b
+
np
.
power
(
mu
,
j
)
*
self
.
bs
[
j
]
return
b
def
solve
(
self
,
mu
:
complex
)
->
Np1D
:
"""Find solution of linear system."""
return
scspla
.
spsolve
(
self
.
A
(
mu
),
self
.
b
(
mu
))
def
getLSBlocks
(
self
)
->
Tuple
[
List
[
Np2D
],
List
[
Np1D
]]:
"""Get blocks of linear system."""
self
.
assembleA
()
self
.
assembleb
()
return
self
.
As
,
self
.
bs
Event Timeline
Log In to Comment