Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90320723
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
Thu, Oct 31, 11:54
Size
3 KB
Mime Type
text/x-python
Expires
Sat, Nov 2, 11:54 (2 d)
Engine
blob
Format
Raw Data
Handle
22051261
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
fenics
as
fen
import
numpy
as
np
import
sympy
as
sp
from
context
import
FenicsHelmholtzEngine
as
HFEngine
from
context
import
FenicsHSEngine
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
)
x
,
y
=
sp
.
symbols
(
'x[0] x[1]'
,
real
=
True
)
wex
=
16
/
PI
**
4
*
x
*
y
*
(
x
-
PI
)
*
(
y
-
PI
)
phiex
=
nu
*
(
x
*
np
.
cos
(
theta
)
+
y
*
np
.
sin
(
theta
))
uex
=
wex
*
sp
.
exp
(
-
1.j
*
phiex
)
fex
=
-
uex
.
diff
(
x
,
2
)
-
uex
.
diff
(
y
,
2
)
-
nu
**
2
*
uex
nx
=
ny
=
10
mesh
=
fen
.
RectangleMesh
(
fen
.
Point
(
0
,
0
),
fen
.
Point
(
PI
,
PI
),
nx
,
ny
)
forcingTerm
=
[
sp
.
printing
.
ccode
(
sp
.
simplify
(
sp
.
re
(
fex
))),
sp
.
printing
.
ccode
(
sp
.
simplify
(
sp
.
im
(
fex
)))]
solver
=
HFEngine
(
mesh
=
mesh
,
wavenumber
=
nu
,
forcingTerm
=
forcingTerm
,
FEDegree
=
3
,
DirichletBoundary
=
'all'
,
DirichletDatum
=
0
)
plotter
=
HSEngine
(
solver
.
V
)
shift
=
5
nsets
=
5
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/HelmholtzBubbleTaylorPade.dat'
,
outputs
=
'ALL'
)
sweeper
.
ROMEngine
=
appRB
sweeper
.
params
=
paramsSetsRB
filenameRB
=
sweeper
.
sweep
(
'../Data/HelmholtzBubbleTaylorRB.dat'
,
outputs
=
'ALL'
)
####################
from
matplotlib
import
pyplot
as
plt
plt
.
jet
()
for
i
in
range
(
nsets
):
nDerivatives
=
stride
*
i
+
shift
+
1
PadeOutput
=
sweeper
.
read
(
filenamePade
,
{
'E'
:
nDerivatives
},
[
'kRe'
,
'HFNorm'
,
'AppNorm'
,
'AppError'
])
RBOutput
=
sweeper
.
read
(
filenameRB
,
{
'E'
:
nDerivatives
},
[
'kRe'
,
'AppNorm'
,
'AppError'
])
ktarsF
=
PadeOutput
[
'kRe'
]
solNormF
=
PadeOutput
[
'HFNorm'
]
PadektarsF
=
PadeOutput
[
'kRe'
]
PadeNormF
=
PadeOutput
[
'AppNorm'
]
PadeErrorF
=
PadeOutput
[
'AppError'
]
RBktarsF
=
RBOutput
[
'kRe'
]
RBNormF
=
RBOutput
[
'AppNorm'
]
RBErrorF
=
RBOutput
[
'AppError'
]
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
.
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
.
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
()
Event Timeline
Log In to Comment