Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F84720666
double_slit.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, Sep 24, 12:46
Size
3 KB
Mime Type
text/x-python
Expires
Thu, Sep 26, 12:46 (2 d)
Engine
blob
Format
Raw Data
Handle
21076323
Attached To
R6746 RationalROMPy
double_slit.py
View Options
import
numpy
as
np
from
double_slit_engine
import
DoubleSlitEngine
as
engine
from
rrompy.sampling
import
SamplingEngineStandard
as
SES
from
rrompy.reduction_methods
import
(
NearestNeighbor
as
NN
,
RationalInterpolant
as
RI
,
RationalInterpolantGreedy
as
RIG
)
from
rrompy.parameter.parameter_sampling
import
QuadratureSampler
as
QS
from
rrompy.solver.fenics
import
interp_project
ks
=
[
10.
,
15.
]
k0
,
n
=
np
.
mean
(
ks
),
150
solver
=
engine
(
k0
,
n
)
k
=
11.
for
method
in
[
"RI"
,
"RI_GREEDY"
]:
print
(
"Testing {} method"
.
format
(
method
))
if
method
==
"RI"
:
params
=
{
'S'
:
20
,
'POD'
:
True
,
'polybasis'
:
"CHEBYSHEV"
,
'sampler'
:
QS
(
ks
,
"CHEBYSHEV"
)}
algo
=
RI
if
method
==
"RI_GREEDY"
:
params
=
{
'S'
:
10
,
'POD'
:
True
,
'polybasis'
:
"LEGENDRE"
,
'greedyTol'
:
1e-2
,
'sampler'
:
QS
(
ks
,
"UNIFORM"
),
'errorEstimatorKind'
:
"LOOK_AHEAD"
,
'trainSetGenerator'
:
QS
(
ks
,
"CHEBYSHEV"
)}
algo
=
RIG
approx
=
algo
(
solver
,
mu0
=
k0
,
approx_state
=
True
,
approxParameters
=
params
,
verbosity
=
20
)
if
len
(
method
)
==
2
:
approx
.
setupApprox
()
else
:
approx
.
setupApprox
(
"LAST"
)
print
(
"--- Approximant ---"
)
approx
.
plotApprox
(
k
,
name
=
'u_app'
)
approx
.
plotHF
(
k
,
name
=
'u_HF'
)
approx
.
plotErr
(
k
,
name
=
'err_app'
)
approx
.
plotRes
(
k
,
name
=
'res_app'
)
normErr
=
approx
.
normErr
(
k
)[
0
]
normSol
=
approx
.
normHF
(
k
)[
0
]
normRes
=
approx
.
normRes
(
k
)[
0
]
normRHS
=
approx
.
normRHS
(
k
)[
0
]
print
(
"SolNorm:
\t
{:.5e}
\n
Err_app:
\t
{:.5e}
\n
ErrRel_app:
\t
{:.5e}"
.
format
(
normSol
,
normErr
,
normErr
/
normSol
))
print
(
"RHSNorm:
\t
{:.5e}
\n
Res_app:
\t
{:.5e}
\n
ResRel_app:
\t
{:.5e}"
.
format
(
normRHS
,
normRes
,
normRes
/
normRHS
))
print
(
"--- Closest snapshot ---"
)
eng
=
SES
(
solver
,
verbosity
=
0
)
approxNN
=
NN
(
solver
,
mu0
=
k0
,
approx_state
=
True
,
verbosity
=
0
,
approxParameters
=
{
'S'
:
approx
.
S
,
'POD'
:
True
})
approxNN
.
setSamples
(
approx
.
samplingEngine
)
approxNN
.
plotApprox
(
k
,
name
=
'u_close'
)
approxNN
.
plotHF
(
k
,
name
=
'u_HF'
)
approxNN
.
plotErr
(
k
,
name
=
'err_close'
)
approxNN
.
plotRes
(
k
,
name
=
'res_close'
)
normErr
=
approxNN
.
normErr
(
k
)[
0
]
normSol
=
approxNN
.
normHF
(
k
)[
0
]
normRes
=
approxNN
.
normRes
(
k
)[
0
]
normRHS
=
approxNN
.
normRHS
(
k
)[
0
]
print
(
"SolNorm:
\t
{:.5e}
\n
Err_close:
\t
{:.5e}
\n
ErrRel_close:
\t
{:.5e}"
.
format
(
normSol
,
normErr
,
normErr
/
normSol
))
print
(
"RHSNorm:
\t
{:.5e}
\n
Res_close:
\t
{:.5e}
\n
ResRel_close:
\t
{:.5e}"
.
format
(
normRHS
,
normRes
,
normRes
/
normRHS
))
uIncR
,
uIncI
=
solver
.
getDirichletValues
(
k
)
uIncR
=
interp_project
(
uIncR
,
solver
.
V
)
uIncI
=
interp_project
(
uIncI
,
solver
.
V
)
uInc
=
np
.
array
(
uIncR
.
vector
())
+
1.j
*
np
.
array
(
uIncI
.
vector
())
uEx
=
approx
.
getHF
(
k
)[
0
]
-
uInc
uApp
=
approx
.
getApprox
(
k
)[
0
]
-
uInc
solver
.
plot
(
uEx
,
name
=
'uex_tot'
)
solver
.
plot
(
uApp
,
name
=
'u_app_tot'
)
poles
,
residues
=
approx
.
getResidues
()
print
(
"Poles:
\n
{}"
.
format
(
poles
))
for
pol
,
res
in
zip
(
poles
,
residues
):
solver
.
plot
(
res
)
print
(
"pole = {:.5e}"
.
format
(
pol
))
print
(
"
\n
"
)
Event Timeline
Log In to Comment