Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F96569787
rb_centered_2d.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
Sat, Dec 28, 07:01
Size
2 KB
Mime Type
text/x-python
Expires
Mon, Dec 30, 07:01 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
23208001
Attached To
R6746 RationalROMPy
rb_centered_2d.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
matrix_random
import
matrixRandom
from
rrompy.reduction_methods.centered
import
RBCentered
as
RBC
def
test_R
():
mu
=
[
5.5
,
7.5
]
mu0
=
[
5.
,
7.
]
solver
=
matrixRandom
()
uh
=
solver
.
solve
(
mu
)[
0
]
uhN
=
solver
.
norm
(
uh
)
params
=
{
"POD"
:
True
,
"S"
:
10
}
approx
=
RBC
(
solver
,
mu0
,
params
,
verbosity
=
0
)
approx
.
setupApprox
()
uhP
=
approx
.
getApprox
(
mu
)[
0
]
uhNP
=
approx
.
normApprox
(
mu
)[
0
]
errP
=
approx
.
getErr
(
mu
)[
0
]
errNP
=
approx
.
normErr
(
mu
)[
0
]
assert
np
.
allclose
(
np
.
abs
(
errP
-
(
uhP
-
uh
)),
0.
,
rtol
=
1e-3
)
assert
np
.
isclose
(
uhN
,
uhNP
,
rtol
=
1e-1
)
assert
np
.
isclose
(
errNP
/
uhNP
,
0.
,
atol
=
1e-1
)
def
test_moments
():
mu0
=
[
2
+
.
5j
,
3
]
solver
=
matrixRandom
()
params
=
{
"POD"
:
True
,
"S"
:
10
}
approx
=
RBC
(
solver
,
mu0
,
params
,
verbosity
=
0
)
approx
.
setupApprox
()
assert
np
.
isclose
(
approx
.
normErr
(
mu0
)[
0
],
0.
,
atol
=
1e-10
)
def
test_load_copy
(
capsys
):
mu
=
[
1.5
,
3.
+
1j
]
mu0
=
[
2
+
.
5j
,
3
]
solver
=
matrixRandom
()
params
=
{
"POD"
:
True
,
"S"
:
10
}
approx1
=
RBC
(
solver
,
mu0
,
params
,
verbosity
=
100
)
approx1
.
setupApprox
()
err1
=
approx1
.
normErr
(
mu
)[
0
]
out
,
err
=
capsys
.
readouterr
()
assert
"Solving HF model for mu ="
in
out
assert
len
(
err
)
==
0
approx2
=
RBC
(
solver
,
mu0
,
params
,
verbosity
=
100
)
approx2
.
setTrainedModel
(
approx1
.
trainedModel
)
approx2
.
setHF
(
mu
,
approx1
.
uHF
)
err2
=
approx2
.
normErr
(
mu
)[
0
]
out
,
err
=
capsys
.
readouterr
()
assert
"Solving HF model for mu ="
not
in
out
assert
len
(
err
)
==
0
assert
np
.
isclose
(
err1
,
err2
,
rtol
=
1e-10
)
Event Timeline
Log In to Comment