Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F79435276
matrix_passive_pod.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
Mon, Aug 26, 09:36
Size
6 KB
Mime Type
text/x-python
Expires
Wed, Aug 28, 09:36 (2 d)
Engine
blob
Format
Raw Data
Handle
20188227
Attached To
R6746 RationalROMPy
matrix_passive_pod.py
View Options
import
numpy
as
np
from
rrompy.hfengines.linear_problem.tridimensional
import
\
MatrixDynamicalPassive
as
MDP
from
rrompy.reduction_methods.standard
import
RationalInterpolant
as
RI
from
rrompy.reduction_methods.standard
import
ReducedBasis
as
RB
from
rrompy.reduction_methods.pivoted
import
RationalInterpolantPivoted
as
RIP
#from rrompy.reduction_methods.pivoted import ReducedBasisPivoted as RBP
from
rrompy.parameter.parameter_sampling
import
(
QuadratureSampler
as
QS
,
QuadratureSamplerTotal
as
QST
,
ManualSampler
as
MS
,
RandomSampler
as
RS
)
verb
=
10
size
=
3
show_sample
=
True
show_norm
=
True
Delta
=
0
MN
=
5
R
=
(
MN
+
2
)
*
(
MN
+
1
)
//
2
STensorized
=
(
MN
+
1
)
**
2
PODTol
=
1e-6
SPivot
=
MN
+
1
SMarginal
=
3
MMarginal
=
SMarginal
-
1
samples
=
"centered"
samples
=
"standard"
samples
=
"pivoted"
algo
=
"rational"
algo
=
"RB"
sampling
=
"quadrature"
#sampling = "quadrature_total"
#sampling = "random"
samplingM
=
"quadrature"
#samplingM = "quadrature_total"
#samplingM = "random"
if
samples
in
[
"standard"
,
"pivoted"
]:
radial
=
""
# radial = "_gaussian"
# radial = "_thinplate"
# radial = "_multiquadric"
rW0
=
10.
radialWeight
=
[
rW0
]
if
samples
==
"pivoted"
:
radialM
=
""
# radialM = "_gaussian"
# radialM = "_thinplate"
# radialM = "_multiquadric"
rMW0
=
2.
radialWeightM
=
[
rMW0
]
matchingWeight
=
1.
cutOffTolerance
=
5.
cutOffType
=
"POTENTIAL"
if
size
==
1
:
mu0
=
[
2.7e2
,
20
]
mutar
=
[
3e2
,
25
]
murange
=
[[
20.
,
10
],
[
5.2e2
,
30
]]
elif
size
==
2
:
mu0
=
[
2.7e2
,
60
]
mutar
=
[
3e2
,
75
]
murange
=
[[
20.
,
10
],
[
5.2e2
,
110
]]
elif
size
==
3
:
mu0
=
[
2.7e2
,
160
]
mutar
=
[
3e2
,
105
]
murange
=
[[
20.
,
10
],
[
5.2e2
,
310
]]
assert
Delta
<=
0
aEff
=
1.
#25
bEff
=
1.
-
aEff
murangeEff
=
[[
aEff
*
murange
[
0
][
0
]
+
bEff
*
murange
[
1
][
0
],
aEff
*
murange
[
0
][
1
]
+
bEff
*
murange
[
1
][
1
]],
[
aEff
*
murange
[
1
][
0
]
+
bEff
*
murange
[
0
][
0
],
aEff
*
murange
[
1
][
1
]
+
bEff
*
murange
[
0
][
1
]]]
n
=
100
b
=
10
solver
=
MDP
(
mu0
=
mu0
,
n
=
n
,
b
=
b
,
verbosity
=
verb
)
if
algo
==
"rational"
:
params
=
{
'N'
:
MN
,
'M'
:
MN
+
Delta
,
'S'
:
R
,
'POD'
:
True
}
if
samples
==
"standard"
:
params
[
'polybasis'
]
=
"CHEBYSHEV"
+
radial
# params['polybasis'] = "LEGENDRE" + radial
# params['polybasis'] = "MONOMIAL" + radial
params
[
'radialDirectionalWeights'
]
=
radialWeight
*
2
method
=
RI
elif
samples
==
"centered"
:
params
[
'polybasis'
]
=
"MONOMIAL"
method
=
RI
elif
samples
==
"pivoted"
:
params
[
'S'
]
=
SPivot
params
[
'SMarginal'
]
=
SMarginal
params
[
'MMarginal'
]
=
MMarginal
params
[
'polybasisPivot'
]
=
"CHEBYSHEV"
+
radial
params
[
'polybasisMarginal'
]
=
"MONOMIAL"
+
radialM
params
[
'radialDirectionalWeightsPivot'
]
=
radialWeight
params
[
'radialDirectionalWeightsMarginal'
]
=
radialWeightM
params
[
'matchingWeight'
]
=
matchingWeight
params
[
'cutOffTolerance'
]
=
cutOffTolerance
params
[
"cutOffType"
]
=
cutOffType
method
=
RIP
else
:
#if algo == "RB":
params
=
{
'R'
:(
MN
+
2
+
Delta
)
*
(
MN
+
1
+
Delta
)
//
2
,
'S'
:
R
,
'POD'
:
True
,
'PODTolerance'
:
PODTol
}
if
samples
==
"standard"
:
method
=
RB
elif
samples
==
"centered"
:
method
=
RB
elif
samples
==
"pivoted"
:
raise
# params['R'] = SPivot
# params['S'] = SPivot
# params['SMarginal'] = SMarginal
# params['MMarginal'] = MMarginal
# params['polybasisMarginal'] = "MONOMIAL" + radialM
# params['radialDirectionalWeightsMarginal'] = radialWeightM
# params['matchingWeight'] = matchingWeight
# params['cutOffTolerance'] = cutOffTolerance
# params["cutOffType"] = cutOffType
# method = RBP
if
samples
==
"standard"
:
if
sampling
==
"quadrature"
:
params
[
'sampler'
]
=
QS
(
murange
,
"CHEBYSHEV"
)
# params['sampler'] = QS(murange, "GAUSSLEGENDRE")
# params['sampler'] = QS(murange, "UNIFORM")
params
[
"S"
]
=
STensorized
elif
sampling
==
"quadrature_total"
:
params
[
'sampler'
]
=
QST
(
murange
,
"CHEBYSHEV"
)
else
:
# if sampling == "random":
params
[
'sampler'
]
=
RS
(
murange
,
"HALTON"
)
elif
samples
==
"centered"
:
params
[
'sampler'
]
=
MS
(
murange
,
points
=
[
mu0
])
elif
samples
==
"pivoted"
:
if
sampling
==
"quadrature"
:
params
[
'samplerPivot'
]
=
QS
([
murange
[
0
][
0
],
murange
[
1
][
0
]],
"CHEBYSHEV"
)
# params['samplerPivot'] = QS([murange[0][0], murange[1][0]], "GAUSSLEGENDRE")
# params['samplerPivot'] = QS([murange[0][0], murange[1][0]], "UNIFORM")
elif
sampling
==
"quadrature_total"
:
params
[
'samplerPivot'
]
=
QST
([
murange
[
0
][
0
],
murange
[
1
][
0
]],
"CHEBYSHEV"
)
else
:
# if sampling == "random":
params
[
'samplerPivot'
]
=
RS
([
murange
[
0
][
0
],
murange
[
1
][
0
]],
"HALTON"
)
if
samplingM
==
"quadrature"
:
params
[
'samplerMarginal'
]
=
QS
([
murange
[
0
][
1
],
murange
[
1
][
1
]],
"UNIFORM"
)
elif
samplingM
==
"quadrature_total"
:
params
[
'samplerMarginal'
]
=
QST
([
murange
[
0
][
1
],
murange
[
1
][
1
]],
"CHEBYSHEV"
)
else
:
# if samplingM == "random":
params
[
'samplerMarginal'
]
=
RS
([
murange
[
0
][
1
],
murange
[
1
][
1
]],
"HALTON"
)
if
samples
!=
"pivoted"
:
approx
=
method
(
solver
,
mu0
=
mu0
,
approxParameters
=
params
,
verbosity
=
verb
)
else
:
approx
=
method
(
solver
,
mu0
=
mu0
,
directionPivot
=
[
0
],
approxParameters
=
params
,
verbosity
=
verb
)
approx
.
setupApprox
()
if
show_sample
:
L
=
mutar
[
1
]
approx
.
plotApprox
(
mutar
,
name
=
'u_app'
,
what
=
"REAL"
)
approx
.
plotHF
(
mutar
,
name
=
'u_HF'
,
what
=
"REAL"
)
approx
.
plotErr
(
mutar
,
name
=
'err'
,
what
=
"REAL"
)
# approx.plotRes(mutar, name = 'res', what = "REAL")
appErr
=
approx
.
normErr
(
mutar
)
solNorm
=
approx
.
normHF
(
mutar
)
resNorm
=
approx
.
normRes
(
mutar
)
RHSNorm
=
approx
.
normRHS
(
mutar
)
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
)))
try
:
from
plot_zero_set
import
plotZeroSet2
muZeroVals
,
Qvals
=
plotZeroSet2
(
murange
,
murangeEff
,
approx
,
mu0
,
200
,
[
1.
,
1
],
polesImTol
=
2.
)
except
:
pass
if
show_norm
:
from
plot_inf_set
import
plotInfSet2
muInfVals
,
normEx
,
normApp
,
normRes
,
normErr
,
beta
=
plotInfSet2
(
murange
,
murangeEff
,
approx
,
mu0
,
50
,
[
1.
,
1.
],
relative
=
False
,
nobeta
=
True
)
print
(
1.j
*
approx
.
getPoles
([
None
,
50.
]))
Event Timeline
Log In to Comment