Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F78373194
HelmholtzTaylorApproximantsSweep.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, Aug 20, 09:53
Size
3 KB
Mime Type
text/x-python
Expires
Thu, Aug 22, 09:53 (2 d)
Engine
blob
Format
Raw Data
Handle
20034997
Attached To
R6746 RationalROMPy
HelmholtzTaylorApproximantsSweep.py
View Options
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Example homogeneous Dirichlet forcing wave SWEEP
from
__future__
import
print_function
import
numpy
as
np
from
context
import
FreeFemHelmholtzEngine
as
HFEngine
from
context
import
FreeFemHSEngine
as
HSEngine
from
context
import
ROMApproximantTaylorPade
as
Pade
from
context
import
ROMApproximantTaylorRB
as
RB
from
context
import
ROMApproximantSweeper
as
Sweeper
PI
=
np
.
pi
nu
=
12
**.
5
theta
=
PI
/
3
z0
=
12
+
.
5j
npoints
=
31
ktars
=
np
.
linspace
(
7
,
16
,
npoints
)
V
=
(
"int n = 10;
\n
"
"real nu = 12^.5, theta = pi / 3;
\n
"
"mesh Th = square(n, n, [pi * x, pi * y]);
\n
"
"load
\"
Element_P3
\"
;
\n
"
"fespace V(Th, P3);"
)
f
=
(
"16 / pi^4 * exp(-1i * nu*(cos(theta) * x + sin(theta) * y)) * ( 2i *"
" nu *cos(theta) * (2 * x * y^2 - 2 * pi * x * y - pi * y^2 + pi^2 * "
"y) + 2i * nu * sin(theta) * (2 *x^2 * y - pi * x^2 - 2 * pi * x * y "
"+ pi^2 * x) - (2 * y^2 - 2 * pi * y + 2 * x^2 - 2 * pi * x))"
)
solver
=
HFEngine
(
V
,
nu
,
forcingTerm
=
f
,
DirichletBoundary
=
"1,2,3,4"
)
plotter
=
HSEngine
(
solver
.
V
)
shift
=
5
nsets
=
3
stride
=
2
Emax
=
stride
*
(
nsets
-
1
)
+
shift
+
2
params
=
{
'Emax'
:
Emax
,
'sampleType'
:
'ARNOLDI'
,
'POD'
:
True
}
paramsSetsPade
=
[
None
]
*
nsets
paramsSetsRB
=
[
None
]
*
nsets
for
i
in
range
(
nsets
):
paramsSetsPade
[
i
]
=
{
'N'
:
stride
*
i
+
shift
+
1
,
'M'
:
stride
*
i
+
shift
,
'E'
:
stride
*
i
+
shift
+
1
}
paramsSetsRB
[
i
]
=
{
'E'
:
stride
*
i
+
shift
+
1
,
'R'
:
stride
*
i
+
shift
+
2
}
appPade
=
Pade
(
solver
,
plotter
,
k0
=
z0
,
w
=
np
.
real
(
z0
**.
5
),
approxParameters
=
params
)
appRB
=
RB
(
solver
,
plotter
,
k0
=
z0
,
w
=
np
.
real
(
z0
**.
5
),
approxParameters
=
params
)
sweeper
=
Sweeper
.
ROMApproximantSweeper
(
ktars
=
ktars
,
mostExpensive
=
'Approx'
)
sweeper
.
ROMEngine
=
appPade
sweeper
.
params
=
paramsSetsPade
filenamePade
=
sweeper
.
sweep
(
'../Data/HelmholtzBubbleTaylorPadeFF.dat'
,
outputs
=
'ALL'
)
sweeper
.
ROMEngine
=
appRB
sweeper
.
params
=
paramsSetsRB
filenameRB
=
sweeper
.
sweep
(
'../Data/HelmholtzBubbleTaylorRBFF.dat'
,
outputs
=
'ALL'
)
####################
from
matplotlib
import
pyplot
as
plt
for
i
in
range
(
nsets
):
nDerivatives
=
stride
*
i
+
shift
+
1
PadeOutput
=
sweeper
.
read
(
filenamePade
,
{
'E'
:
nDerivatives
},
[
'kRe'
,
'HFNorm'
,
'AppNorm'
,
'ErrNorm'
])
RBOutput
=
sweeper
.
read
(
filenameRB
,
{
'E'
:
nDerivatives
},
[
'kRe'
,
'AppNorm'
,
'ErrNorm'
])
ktarsF
=
PadeOutput
[
'kRe'
]
solNormF
=
PadeOutput
[
'HFNorm'
]
PadektarsF
=
PadeOutput
[
'kRe'
]
PadeNormF
=
PadeOutput
[
'AppNorm'
]
PadeErrorF
=
PadeOutput
[
'ErrNorm'
]
RBktarsF
=
RBOutput
[
'kRe'
]
RBNormF
=
RBOutput
[
'AppNorm'
]
RBErrorF
=
RBOutput
[
'ErrNorm'
]
plt
.
figure
()
plt
.
semilogy
(
ktarsF
,
solNormF
,
'k-'
,
label
=
'Sol norm'
)
plt
.
semilogy
(
PadektarsF
,
PadeNormF
,
'b.--'
,
label
=
'Pade'' norm, E = {}'
.
format
(
nDerivatives
))
plt
.
semilogy
(
RBktarsF
,
RBNormF
,
'g.--'
,
label
=
'RB norm, E = {}'
.
format
(
nDerivatives
))
plt
.
legend
()
plt
.
grid
()
plt
.
show
()
plt
.
close
()
plt
.
figure
()
plt
.
semilogy
(
PadektarsF
,
PadeErrorF
,
'b'
,
label
=
'Pade'' error, E = {}'
.
format
(
nDerivatives
))
plt
.
semilogy
(
RBktarsF
,
RBErrorF
,
'g'
,
label
=
'RB error, E = {}'
.
format
(
nDerivatives
))
plt
.
legend
()
plt
.
grid
()
plt
.
show
()
plt
.
close
()
plt
.
figure
()
plt
.
semilogy
(
ktarsF
,
PadeErrorF
/
solNormF
,
'b'
,
label
=
'Pade'' relative error, E = {}'
.
format
(
nDerivatives
))
plt
.
semilogy
(
RBktarsF
,
RBErrorF
/
solNormF
,
'g'
,
label
=
'RB relative error, E = {}'
.
format
(
nDerivatives
))
plt
.
legend
()
plt
.
grid
()
plt
.
show
()
plt
.
close
()
Event Timeline
Log In to Comment