Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91925421
sampling_engine_krylov.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
Fri, Nov 15, 19:03
Size
3 KB
Mime Type
text/x-python
Expires
Sun, Nov 17, 19:03 (2 d)
Engine
blob
Format
Raw Data
Handle
22348437
Attached To
R6746 RationalROMPy
sampling_engine_krylov.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
from
rrompy.sampling.base.sampling_engine_base
import
SamplingEngineBase
from
rrompy.utilities.base.types
import
Np1D
,
Np2D
from
rrompy.utilities.base
import
verbosityDepth
__all__
=
[
'SamplingEngineKrylov'
]
class
SamplingEngineKrylov
(
SamplingEngineBase
):
"""HERE"""
def
preprocesssamples
(
self
):
if
self
.
samples
is
None
:
return
return
self
.
samples
[:,
:
self
.
nsamples
]
def
preprocessb
(
self
,
mu
:
complex
,
overwrite
:
bool
=
False
,
homogeneize
:
bool
=
False
):
return
self
.
HFEngine
.
b
(
mu
,
self
.
nsamples
,
homogeneized
=
homogeneize
)
def
postprocessu
(
self
,
u
:
Np1D
,
overwrite
:
bool
=
False
):
return
u
def
preallocateSamples
(
self
,
u
:
Np1D
,
n
:
int
):
self
.
samples
=
np
.
empty
((
u
.
size
,
n
),
dtype
=
u
.
dtype
)
self
.
samples
[:,
0
]
=
u
def
nextSample
(
self
,
mu
:
complex
,
overwrite
:
bool
=
False
,
homogeneize
:
bool
=
False
)
->
Np1D
:
ns
=
self
.
nsamples
if
self
.
verbosity
>=
10
:
verbosityDepth
(
"INIT"
,
(
"Setting up computation of {}-th Taylor "
"coefficient."
)
.
format
(
ns
))
samplesOld
=
self
.
preprocesssamples
()
RHS
=
self
.
preprocessb
(
mu
,
overwrite
=
overwrite
,
homogeneize
=
homogeneize
)
for
i
in
range
(
1
,
ns
+
1
):
RHS
-=
self
.
HFEngine
.
A
(
mu
,
i
)
.
dot
(
samplesOld
[:,
-
i
])
if
self
.
verbosity
>=
10
:
verbosityDepth
(
"DEL"
,
"Done setting up for Taylor coefficient."
)
u
=
self
.
postprocessu
(
self
.
solveLS
(
mu
,
RHS
=
RHS
,
homogeneized
=
homogeneize
),
overwrite
=
overwrite
)
if
overwrite
:
self
.
samples
[:,
ns
]
=
u
else
:
if
ns
==
0
:
self
.
samples
=
u
[:,
None
]
else
:
self
.
samples
=
np
.
hstack
((
self
.
samples
,
u
[:,
None
]))
self
.
nsamples
+=
1
return
u
def
iterSample
(
self
,
mu
:
complex
,
n
:
int
,
homogeneize
:
bool
=
False
)
->
Np2D
:
if
self
.
verbosity
>=
5
:
verbosityDepth
(
"INIT"
,
"Starting sampling iterations at mu = {}."
\
.
format
(
mu
))
if
n
<=
0
:
raise
Exception
((
"Number of Krylov iterations must be positive."
))
self
.
resetHistory
()
u
=
self
.
nextSample
(
mu
,
homogeneize
=
homogeneize
)
if
n
>
1
:
self
.
preallocateSamples
(
u
,
n
)
for
_
in
range
(
1
,
n
):
self
.
nextSample
(
mu
,
overwrite
=
True
,
homogeneize
=
homogeneize
)
if
self
.
verbosity
>=
5
:
verbosityDepth
(
"DEL"
,
"Finished sampling iterations."
)
return
self
.
samples
Event Timeline
Log In to Comment