Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F61719772
HelmholtzRBLagrangeApproximant.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
Wed, May 8, 13:19
Size
4 KB
Mime Type
text/x-python
Expires
Fri, May 10, 13:19 (2 d)
Engine
blob
Format
Raw Data
Handle
17549373
Attached To
R6746 RationalROMPy
HelmholtzRBLagrangeApproximant.py
View Options
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
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
FenicsHelmholtzScatteringEngine
as
HFSEngine
from
context
import
FenicsHelmholtzScatteringAugmentedEngine
as
HFSAEngine
from
context
import
FenicsHSEngine
as
HSEngine
from
context
import
FenicsHSAugmentedEngine
as
HSAEngine
from
context
import
ROMApproximantLagrangeRB
as
RB
PI
=
np
.
pi
testNo
=
3
if
testNo
==
1
:
params
=
{
'S'
:
5
,
'nodesType'
:
'CHEBYSHEV'
,
'POD'
:
True
}
nu
=
12
**.
5
theta
=
PI
/
3
ztar
=
11
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
=
40
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
)
approx
=
RB
(
solver
,
plotter
,
ks
=
[
10
+
.
5j
,
14
+
.
5j
],
w
=
np
.
real
(
nu
),
approxParameters
=
params
)
approx
.
plotApp
(
ztar
,
name
=
'u_RB'
)
approx
.
plotHF
(
ztar
,
name
=
'u_HF'
)
approx
.
plotErr
(
ztar
,
name
=
'err'
)
appErr
,
solNorm
=
approx
.
approxError
(
ztar
),
approx
.
HFNorm
(
ztar
)
print
(
appErr
,
solNorm
,
appErr
/
solNorm
)
print
(
approx
.
getPoles
(
True
))
############
elif
testNo
==
2
:
def
Dboundary
(
x
,
on_boundary
):
return
on_boundary
and
(
fen
.
near
(
x
[
0
],
0
)
or
fen
.
near
(
x
[
0
],
PI
))
A
=
10
kappa
=
4
theta
=
PI
*
90
/
180
x
,
y
=
sp
.
symbols
(
'x[0] x[1]'
,
real
=
True
)
phiex
=
kappa
*
(
x
*
np
.
cos
(
theta
)
+
y
*
np
.
sin
(
theta
))
u0ex
=
-
A
*
sp
.
exp
(
1.j
*
phiex
)
nx
=
ny
=
40
mesh
=
fen
.
RectangleMesh
(
fen
.
Point
(
0
,
0
),
fen
.
Point
(
PI
,
PI
),
nx
,
ny
)
DirichletTerm
=
[
sp
.
printing
.
ccode
(
sp
.
simplify
(
sp
.
re
(
u0ex
))),
sp
.
printing
.
ccode
(
sp
.
simplify
(
sp
.
im
(
u0ex
)))]
params
=
{
'S'
:
30
,
'nodesType'
:
'CHEBYSHEV'
,
'POD'
:
True
}
solver
=
HFSEngine
(
mesh
=
mesh
,
wavenumber
=
kappa
,
forcingTerm
=
0
,
FEDegree
=
3
,
DirichletBoundary
=
Dboundary
,
RobinBoundary
=
'rest'
,
DirichletDatum
=
DirichletTerm
)
plotter
=
HSEngine
(
solver
.
V
)
approx
=
RB
(
solver
,
plotter
,
ks
=
[
0
,
8
],
approxParameters
=
params
,
plotSnapshots
=
False
)
ktar
=
4.5
approx
.
plotApp
(
ktar
,
name
=
'u_RB'
)
approx
.
plotHF
(
ktar
,
name
=
'u_HF'
)
approx
.
plotErr
(
ktar
,
name
=
'err'
)
appErr
,
solNorm
=
approx
.
approxError
(
ktar
),
approx
.
HFNorm
(
ktar
)
print
(
appErr
,
solNorm
,
appErr
/
solNorm
)
print
(
approx
.
getPoles
(
True
))
############
elif
testNo
==
3
:
def
Dboundary
(
x
,
on_boundary
):
return
on_boundary
and
(
fen
.
near
(
x
[
0
],
0
)
or
fen
.
near
(
x
[
0
],
PI
))
A
=
10
kappa
=
4
theta
=
PI
*
90
/
180
x
,
y
=
sp
.
symbols
(
'x[0] x[1]'
,
real
=
True
)
phiex
=
kappa
*
(
x
*
np
.
cos
(
theta
)
+
y
*
np
.
sin
(
theta
))
u0ex
=
-
A
*
sp
.
exp
(
1.j
*
phiex
)
nx
=
ny
=
40
mesh
=
fen
.
RectangleMesh
(
fen
.
Point
(
0
,
0
),
fen
.
Point
(
PI
,
PI
),
nx
,
ny
)
DirichletTerm
=
[
sp
.
printing
.
ccode
(
sp
.
simplify
(
sp
.
re
(
u0ex
))),
sp
.
printing
.
ccode
(
sp
.
simplify
(
sp
.
im
(
u0ex
)))]
params
=
{
'S'
:
30
,
'nodesType'
:
'CHEBYSHEV'
,
'POD'
:
True
}
solver
=
HFSAEngine
(
mesh
=
mesh
,
wavenumber
=
kappa
,
forcingTerm
=
0
,
FEDegree
=
3
,
DirichletBoundary
=
Dboundary
,
RobinBoundary
=
'rest'
,
DirichletDatum
=
DirichletTerm
,
constraintType
=
'IDENTITY'
)
plotter
=
HSAEngine
(
solver
.
V
,
2
)
approx
=
RB
(
solver
,
plotter
,
ks
=
[
0
,
8
],
approxParameters
=
params
,
plotSnapshots
=
False
)
ktar
=
4.5
approx
.
plotApp
(
ktar
,
name
=
'u_RB'
)
approx
.
plotHF
(
ktar
,
name
=
'u_HF'
)
approx
.
plotErr
(
ktar
,
name
=
'err'
)
appErr
,
solNorm
=
approx
.
approxError
(
ktar
,
kappa
),
approx
.
HFNorm
(
ktar
,
kappa
)
print
(
appErr
,
solNorm
,
np
.
divide
(
appErr
,
solNorm
))
print
(
approx
.
getPoles
(
True
))
Event Timeline
Log In to Comment