Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F61130357
RationalInterpolant.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, May 4, 17:47
Size
4 KB
Mime Type
text/x-python
Expires
Mon, May 6, 17:47 (2 d)
Engine
blob
Format
Raw Data
Handle
17469650
Attached To
R6746 RationalROMPy
RationalInterpolant.py
View Options
import
numpy
as
np
from
rrompy.hfengines.linear_problem
import
\
HelmholtzSquareBubbleProblemEngine
as
HSBPE
from
rrompy.hfengines.linear_problem
import
\
HelmholtzSquareTransmissionProblemEngine
as
HSTPE
from
rrompy.hfengines.linear_problem
import
\
HelmholtzBoxScatteringProblemEngine
as
HBSPE
from
rrompy.reduction_methods.standard
import
RationalInterpolant
as
RI
from
rrompy.parameter.parameter_sampling
import
QuadratureSampler
as
QS
testNo
=
3
verb
=
100
polyBasis
=
"CHEBYSHEV"
polyBasis
=
"LEGENDRE"
#polyBasis = "MONOMIAL"
homog
=
True
#homog = False
loadName
=
"RationalInterpolantModel.pkl"
if
testNo
in
[
1
,
-
1
]:
if
testNo
>
0
:
k0s
=
np
.
power
([
10
+
0.j
,
14
+
0.j
],
.
5
)
k0
=
np
.
mean
(
np
.
power
(
k0s
,
2.
))
**
.
5
params
=
{
'N'
:
4
,
'M'
:
3
,
'S'
:
5
,
'POD'
:
True
,
'polybasis'
:
polyBasis
,
'sampler'
:
QS
(
k0s
,
"CHEBYSHEV"
,
2.
)}
ktar
=
(
11
+
.
5j
)
**
.
5
solver
=
HSBPE
(
kappa
=
12
**
.
5
,
theta
=
np
.
pi
/
3
,
n
=
40
,
verbosity
=
verb
)
if
testNo
>
0
:
solver
.
omega
=
np
.
real
(
k0
)
approx
=
RI
(
solver
,
mu0
=
k0
,
approxParameters
=
params
,
verbosity
=
verb
)
approx
.
setupApprox
()
# approx.plotSamples()
else
:
approx
=
RI
(
solver
,
mu0
=
0
,
approxParameters
=
{
'S'
:
1
,
'muBounds'
:[
0
,
1
]},
verbosity
=
verb
)
approx
.
loadTrainedModel
(
loadName
)
approx
.
plotApprox
(
ktar
,
name
=
'u_Pade'''
)
approx
.
plotHF
(
ktar
,
name
=
'u_HF'
)
approx
.
plotErr
(
ktar
,
name
=
'err'
)
approx
.
plotRes
(
ktar
,
name
=
'res'
)
appErr
,
solNorm
=
approx
.
normErr
(
ktar
),
approx
.
normHF
(
ktar
)
resNorm
,
RHSNorm
=
approx
.
normRes
(
ktar
),
approx
.
normRHS
(
ktar
)
print
((
'SolNorm:
\t
{}
\n
Err:
\t
{}
\n
ErrRel:
\t
{}'
)
.
format
(
solNorm
,
appErr
,
np
.
divide
(
appErr
,
solNorm
)))
print
((
'RHSNorm:
\t
{}
\n
Res:
\t
{}
\n
ResRel:
\t
{}'
)
.
format
(
RHSNorm
,
resNorm
,
np
.
divide
(
resNorm
,
RHSNorm
)))
print
(
'
\n
Poles Pade'':'
)
print
(
approx
.
getPoles
())
if
testNo
>
0
:
approx
.
storeTrainedModel
(
"RationalInterpolantModel"
,
forceNewFile
=
False
)
print
(
approx
.
trainedModel
.
data
.
__dict__
)
############
elif
testNo
==
2
:
k0s
=
[
3.85
+
0.j
,
4.15
+
0.j
]
k0
=
np
.
mean
(
k0s
)
ktar
=
4
+
0.j
params
=
{
'N'
:
8
,
'M'
:
9
,
'S'
:
10
,
'POD'
:
True
,
'polybasis'
:
polyBasis
,
'sampler'
:
QS
(
k0s
,
"CHEBYSHEV"
,
2.
)}
solver
=
HSTPE
(
nT
=
2
,
nB
=
1
,
theta
=
np
.
pi
*
45
/
180
,
kappa
=
4.
,
n
=
50
,
verbosity
=
verb
,
homogeneized
=
homog
)
solver
.
omega
=
np
.
real
(
k0
)
approx
=
RI
(
solver
,
mu0
=
k0
,
approxParameters
=
params
,
verbosity
=
verb
)
approx
.
setupApprox
()
# approx.plotSamples()
approx
.
plotApprox
(
ktar
,
name
=
'u_Pade'''
)
approx
.
plotHF
(
ktar
,
name
=
'u_HF'
)
approx
.
plotErr
(
ktar
,
name
=
'err'
)
approx
.
plotRes
(
ktar
,
name
=
'res'
)
appErr
,
solNorm
=
approx
.
normErr
(
ktar
),
approx
.
normHF
(
ktar
)
resNorm
,
RHSNorm
=
approx
.
normRes
(
ktar
),
approx
.
normRHS
(
ktar
)
print
((
'SolNorm:
\t
{}
\n
Err:
\t
{}
\n
ErrRel:
\t
{}'
)
.
format
(
solNorm
,
appErr
,
np
.
divide
(
appErr
,
solNorm
)))
print
((
'RHSNorm:
\t
{}
\n
Res:
\t
{}
\n
ResRel:
\t
{}'
)
.
format
(
RHSNorm
,
resNorm
,
np
.
divide
(
resNorm
,
RHSNorm
)))
print
(
'
\n
Poles Pade'':'
)
print
(
approx
.
getPoles
())
############
elif
testNo
==
3
:
k0s
=
[
2.
,
5.
]
k0
=
np
.
mean
(
k0s
)
ktar
=
4.5
-
0.j
params
=
{
'N'
:
10
,
'M'
:
9
,
'S'
:
15
,
'POD'
:
True
,
'polybasis'
:
polyBasis
,
'sampler'
:
QS
(
k0s
,
"CHEBYSHEV"
)}
solver
=
HBSPE
(
R
=
7
,
kappa
=
3
,
theta
=
-
np
.
pi
*
75
/
180
,
n
=
40
,
verbosity
=
verb
,
homogeneized
=
homog
)
solver
.
omega
=
np
.
real
(
k0
)
approx
=
RI
(
solver
,
mu0
=
k0
,
approxParameters
=
params
,
verbosity
=
verb
)
approx
.
setupApprox
()
# approx.plotSamples()
approx
.
plotApprox
(
ktar
,
name
=
'u_Pade'''
)
approx
.
plotHF
(
ktar
,
name
=
'u_HF'
)
approx
.
plotErr
(
ktar
,
name
=
'err'
)
approx
.
plotRes
(
ktar
,
name
=
'res'
)
appErr
,
solNorm
=
approx
.
normErr
(
ktar
),
approx
.
normHF
(
ktar
)
resNorm
,
RHSNorm
=
approx
.
normRes
(
ktar
),
approx
.
normRHS
(
ktar
)
print
((
'SolNorm:
\t
{}
\n
Err:
\t
{}
\n
ErrRel:
\t
{}'
)
.
format
(
solNorm
,
appErr
,
np
.
divide
(
appErr
,
solNorm
)))
print
((
'RHSNorm:
\t
{}
\n
Res:
\t
{}
\n
ResRel:
\t
{}'
)
.
format
(
RHSNorm
,
resNorm
,
np
.
divide
(
resNorm
,
RHSNorm
)))
print
(
'
\n
Poles Pade'':'
)
print
(
approx
.
getPoles
())
Event Timeline
Log In to Comment