Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F106875780
HelmholtzLagrangeApproximantsSweep.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
Tue, Apr 1, 22:19
Size
3 KB
Mime Type
text/x-python
Expires
Thu, Apr 3, 22:19 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
25294666
Attached To
R6746 RationalROMPy
HelmholtzLagrangeApproximantsSweep.py
View Options
from
copy
import
copy
import
numpy
as
np
from
rrompy.hfengines.fenics
import
HelmholtzSquareBubbleProblemEngine
as
HSBPE
from
rrompy.hfengines.fenics
import
HelmholtzBoxScatteringProblemEngine
as
HBSPE
from
rrompy.hsengines.fenics
import
HSEngine
as
HS
from
rrompy.reduction_methods.lagrange
import
ApproximantLagrangePade
as
Pade
from
rrompy.reduction_methods.lagrange
import
ApproximantLagrangeRB
as
RB
from
rrompy.reduction_methods.base
import
ParameterSweeper
as
Sweeper
from
rrompy.sampling
import
QuadratureSampler
as
QS
testNo
=
2
npoints
=
31
if
testNo
==
1
:
ks
=
[
4
+
.
5j
,
14
+
.
5j
]
solver
=
HSBPE
(
kappa
=
12
**
.
5
,
theta
=
np
.
pi
/
3
,
n
=
10
)
mutars
=
np
.
linspace
(
0
,
21
,
npoints
)
filenamebase
=
'../data/output/HelmholtzBubbleLagrange'
elif
testNo
==
2
:
ks
=
[
10
+
.
25j
,
14
+
.
25j
]
solver
=
HBSPE
(
R
=
5
,
kappa
=
3
,
theta
=
-
np
.
pi
*
75
/
180
,
n
=
10
)
mutars
=
np
.
linspace
(
9
,
14
,
npoints
)
filenamebase
=
'../data/output/HelmholtzBoxLagrange'
plotter
=
HS
(
solver
.
V
)
k0
=
np
.
mean
(
ks
)
shift
=
12
nsets
=
5
stride
=
3
Smax
=
stride
*
(
nsets
-
1
)
+
shift
+
2
paramsPade
=
{
'S'
:
Smax
,
'POD'
:
True
,
'sampler'
:
QS
(
ks
,
"CHEBYSHEV"
)}
paramsRB
=
copy
(
paramsPade
)
paramsSetsPade
=
[
None
]
*
nsets
paramsSetsRB
=
[
None
]
*
nsets
for
i
in
range
(
nsets
):
paramsSetsPade
[
i
]
=
{
'N'
:
stride
*
i
+
shift
+
1
,
'M'
:
stride
*
i
+
shift
,
'S'
:
stride
*
i
+
shift
+
2
}
paramsSetsRB
[
i
]
=
{
'R'
:
stride
*
i
+
shift
+
1
,
'S'
:
stride
*
i
+
shift
+
2
}
appPade
=
Pade
(
solver
,
plotter
,
mu0
=
k0
,
approxParameters
=
paramsPade
)
appRB
=
RB
(
solver
,
plotter
,
mu0
=
k0
,
approxParameters
=
paramsRB
)
sweeper
=
Sweeper
(
mutars
=
mutars
,
mostExpensive
=
'Approx'
)
sweeper
.
ROMEngine
=
appPade
sweeper
.
params
=
paramsSetsPade
filenamePade
=
sweeper
.
sweep
(
filenamebase
+
'PadeFE.dat'
,
outputs
=
'ALL'
)
sweeper
.
ROMEngine
=
appRB
sweeper
.
params
=
paramsSetsRB
filenameRB
=
sweeper
.
sweep
(
filenamebase
+
'RBFE.dat'
,
outputs
=
'ALL'
)
####################
from
matplotlib
import
pyplot
as
plt
for
i
in
range
(
nsets
):
nSamples
=
stride
*
i
+
shift
+
2
PadeOutput
=
sweeper
.
read
(
filenamePade
,
{
'S'
:
nSamples
},
[
'muRe'
,
'HFNorm'
,
'AppNorm'
,
'ErrNorm'
])
RBOutput
=
sweeper
.
read
(
filenameRB
,
{
'S'
:
nSamples
},
[
'muRe'
,
'AppNorm'
,
'ErrNorm'
])
ztarsF
=
PadeOutput
[
'muRe'
]
solNormF
=
PadeOutput
[
'HFNorm'
]
PadeztarsF
=
PadeOutput
[
'muRe'
]
PadeNormF
=
PadeOutput
[
'AppNorm'
]
PadeErrorF
=
PadeOutput
[
'ErrNorm'
]
RBztarsF
=
RBOutput
[
'muRe'
]
RBNormF
=
RBOutput
[
'AppNorm'
]
RBErrorF
=
RBOutput
[
'ErrNorm'
]
plt
.
figure
()
plt
.
semilogy
(
ztarsF
,
solNormF
,
'k-'
,
label
=
'Sol norm'
)
plt
.
semilogy
(
PadeztarsF
,
PadeNormF
,
'b.--'
,
label
=
'Pade'' norm, S = {}'
.
format
(
nSamples
))
plt
.
semilogy
(
RBztarsF
,
RBNormF
,
'g.--'
,
label
=
'RB norm, S = {}'
.
format
(
nSamples
))
plt
.
legend
()
plt
.
grid
()
plt
.
show
()
plt
.
close
()
plt
.
figure
()
plt
.
semilogy
(
ztarsF
,
PadeErrorF
/
solNormF
,
'b'
,
label
=
'Pade'' relative error, S = {}'
.
format
(
nSamples
))
plt
.
semilogy
(
RBztarsF
,
RBErrorF
/
solNormF
,
'g'
,
label
=
'RB relative error, S = {}'
.
format
(
nSamples
))
plt
.
legend
()
plt
.
grid
()
plt
.
show
()
plt
.
close
()
Event Timeline
Log In to Comment