Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F61186773
scattering1_pod.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
Sun, May 5, 02:23
Size
6 KB
Mime Type
text/x-python
Expires
Tue, May 7, 02:23 (2 d)
Engine
blob
Format
Raw Data
Handle
17477526
Attached To
R6746 RationalROMPy
scattering1_pod.py
View Options
import
numpy
as
np
from
mpl_toolkits.mplot3d
import
Axes3D
from
matplotlib
import
pyplot
as
plt
from
rrompy.hfengines.linear_problem.tridimensional
import
Scattering1d
as
S1D
from
rrompy.reduction_methods.standard
import
RationalInterpolant
as
RI
from
rrompy.reduction_methods.standard
import
ReducedBasis
as
RB
from
rrompy.parameter.parameter_sampling
import
(
QuadratureSampler
as
QS
,
QuadratureSamplerTotal
as
QST
,
ManualSampler
as
MS
,
RandomSampler
as
RS
)
verb
=
50
size
=
2
show_sample
=
True
show_norm
=
False
clip
=
-
1
#clip = .4
#clip = .6
homogeneize
=
False
#homogeneize = True
Delta
=
0
MN
=
15
R
=
(
MN
+
3
)
*
(
MN
+
2
)
*
(
MN
+
1
)
//
6
STensorized
=
(
MN
+
1
)
**
3
PODTol
=
1e-8
samples
=
"centered"
samples
=
"standard"
samples
,
nDer
=
"standard_MMM"
,
15
algo
=
"rational"
#algo = "RB"
sampling
=
"quadrature"
sampling
=
"quadrature_total"
sampling
=
"random"
if
samples
==
"standard"
:
radial
=
""
# radial = "_gaussian"
# radial = "_thinplate"
# radial = "_multiquadric"
rW0
=
5.
radialWeight
=
[
rW0
]
*
3
assert
Delta
<=
0
if
size
==
1
:
mu0
=
[
4.
,
np
.
pi
,
0.
]
mutar
=
[
4.05
,
.
95
*
np
.
pi
,
.
2
]
murange
=
[[
2.
,
.
9
*
np
.
pi
,
-.
5
],
[
6.
,
1.1
*
np
.
pi
,
.
5
]]
if
size
==
2
:
mu0
=
[
4.
,
np
.
pi
,
.
375
]
mutar
=
[
4.05
,
.
95
*
np
.
pi
,
.
2
]
murange
=
[[
2.
,
.
9
*
np
.
pi
,
0.
],
[
6.
,
1.1
*
np
.
pi
,
.
75
]]
aEff
=
1.
#25
bEff
=
1.
-
aEff
murangeEff
=
[[
aEff
*
murange
[
0
][
0
]
+
bEff
*
murange
[
1
][
0
],
aEff
*
murange
[
0
][
1
]
+
bEff
*
murange
[
1
][
1
],
aEff
*
murange
[
0
][
2
]
+
bEff
*
murange
[
1
][
2
]],
[
aEff
*
murange
[
1
][
0
]
+
bEff
*
murange
[
0
][
0
],
aEff
*
murange
[
1
][
1
]
+
bEff
*
murange
[
0
][
1
],
aEff
*
murange
[
1
][
2
]
+
bEff
*
murange
[
0
][
2
]]]
n
=
100
solver
=
S1D
(
mu0
=
mu0
,
n
=
n
,
verbosity
=
verb
,
homogeneized
=
homogeneize
)
if
algo
==
"rational"
:
params
=
{
'N'
:
MN
,
'M'
:
MN
+
Delta
,
'S'
:
R
,
'POD'
:
True
}
if
samples
==
"standard"
:
params
[
'polybasis'
]
=
"CHEBYSHEV"
+
radial
# params['polybasis'] = "LEGENDRE" + radial
# params['polybasis'] = "MONOMIAL" + radial
params
[
'radialDirectionalWeights'
]
=
radialWeight
elif
samples
==
"centered"
:
params
[
'polybasis'
]
=
"MONOMIAL"
else
:
#MMM
params
[
'S'
]
=
nDer
*
int
(
np
.
ceil
(
R
/
nDer
))
method
=
RI
else
:
#if algo == "RB":
params
=
{
'R'
:(
MN
+
3
+
Delta
)
*
(
MN
+
2
+
Delta
)
*
(
MN
+
1
+
Delta
)
//
6
,
'S'
:
R
,
'POD'
:
True
,
'PODTolerance'
:
PODTol
}
if
samples
==
"MMM"
:
params
[
'S'
]
=
nDer
*
int
(
np
.
ceil
(
R
/
nDer
))
method
=
RB
if
samples
==
"standard"
:
if
sampling
==
"quadrature"
:
params
[
'sampler'
]
=
QS
(
murange
,
"CHEBYSHEV"
)
# params['sampler'] = QS(murange, "GAUSSLEGENDRE")
# params['sampler'] = QS(murange, "UNIFORM")
params
[
'S'
]
=
STensorized
elif
sampling
==
"quadrature_total"
:
params
[
'sampler'
]
=
QST
(
murange
,
"CHEBYSHEV"
)
else
:
# if sampling == "random":
params
[
'sampler'
]
=
RS
(
murange
,
"HALTON"
)
elif
samples
==
"centered"
:
params
[
'sampler'
]
=
MS
(
murange
,
points
=
[
mu0
])
elif
samples
==
"standard_MMM"
:
if
sampling
==
"quadrature"
:
SdirEff
=
int
(
np
.
ceil
(
int
(
np
.
ceil
(
R
/
nDer
))
**
(
1.
/
3
)))
**
3
pts
=
QS
(
murange
,
"CHEBYSHEV"
)
.
generatePoints
(
SdirEff
)
elif
sampling
==
"quadrature_total"
:
pts
=
QST
(
murange
,
"CHEBYSHEV"
)
.
generatePoints
(
int
(
np
.
ceil
(
R
/
nDer
)))
else
:
# if sampling == "random":
pts
=
RS
(
murange
,
"HALTON"
)
.
generatePoints
(
int
(
np
.
ceil
(
R
/
nDer
)))
params
[
'sampler'
]
=
MS
(
murange
,
points
=
pts
)
approx
=
method
(
solver
,
mu0
=
mu0
,
approxParameters
=
params
,
verbosity
=
verb
)
approx
.
setupApprox
()
if
show_sample
:
import
fenics
as
fen
x
=
fen
.
SpatialCoordinate
(
solver
.
V
.
mesh
())
warps
=
[
x
*
mutar
[
1
]
/
solver
.
_L
-
x
,
x
*
solver
.
_L
/
mutar
[
1
]
-
x
]
approx
.
plotApprox
(
mutar
,
warps
,
name
=
'u_app'
,
what
=
"REAL"
)
approx
.
plotHF
(
mutar
,
warps
,
name
=
'u_HF'
,
what
=
"REAL"
)
approx
.
plotErr
(
mutar
,
warps
,
name
=
'err'
,
what
=
"REAL"
)
# approx.plotRes(mutar, warps, name = 'res', what = "REAL")
appErr
=
approx
.
normErr
(
mutar
)
solNorm
=
approx
.
normHF
(
mutar
)
resNorm
=
approx
.
normRes
(
mutar
)
RHSNorm
=
approx
.
normRHS
(
mutar
)
print
((
'SolNorm:
\t
{}
\n
Err:
\t
{}
\n
ErrRel:
\t
{}'
)
.
format
(
solNorm
,
appErr
,
np
.
divide
(
appErr
,
solNorm
)))
print
((
'RHSNorm:
\t
{}
\n
Res:
\t
{}
\n
ResRel:
\t
{}'
)
.
format
(
RHSNorm
,
resNorm
,
np
.
divide
(
resNorm
,
RHSNorm
)))
fig
=
plt
.
figure
(
figsize
=
(
8
,
6
))
ax
=
Axes3D
(
fig
)
ax
.
scatter
(
approx
.
trainedModel
.
data
.
mus
(
0
),
approx
.
trainedModel
.
data
.
mus
(
1
),
approx
.
trainedModel
.
data
.
mus
(
2
),
'.'
)
ax
.
set_xlim3d
(
murangeEff
[
0
][
0
],
murangeEff
[
1
][
0
])
ax
.
set_ylim3d
(
murangeEff
[
0
][
1
],
murangeEff
[
1
][
1
])
ax
.
set_zlim3d
(
murangeEff
[
0
][
2
],
murangeEff
[
1
][
2
])
plt
.
show
()
plt
.
close
()
approx
.
verbosity
=
0
approx
.
trainedModel
.
verbosity
=
0
if
algo
==
"rational"
and
approx
.
N
>
0
:
from
plot_zero_set_3
import
plotZeroSet3
muZeroVals
,
Qvals
=
plotZeroSet3
(
murange
,
murangeEff
,
approx
,
mu0
,
200
,
[
None
,
mu0
[
1
],
mu0
[
2
]],
[
1.
,
1.
,
1.
],
clip
=
clip
)
muZeroVals
,
Qvals
=
plotZeroSet3
(
murange
,
murangeEff
,
approx
,
mu0
,
200
,
[
None
,
None
,
mu0
[
2
]],
[
1.
,
1.
,
1.
],
clip
=
clip
)
muZeroVals
,
Qvals
=
plotZeroSet3
(
murange
,
murangeEff
,
approx
,
mu0
,
200
,
[
None
,
mu0
[
1
],
None
],
[
1.
,
1.
,
1.
],
clip
=
clip
)
plotZeroSet3
(
murange
,
murangeEff
,
approx
,
mu0
,
100
,
[
None
,
None
,
None
],
[
1.
,
1.
,
1.
],
clip
=
clip
,
imagTol
=
1e-2
)
if
show_norm
:
from
plot_inf_set_3
import
plotInfSet3
muInfVals
,
normEx
,
normApp
,
normRes
,
normErr
,
beta
=
plotInfSet3
(
murange
,
murangeEff
,
approx
,
mu0
,
25
,
[
None
,
mu0
[
1
],
mu0
[
2
]],
[
1.
,
1.
,
1.
],
clip
=
clip
,
relative
=
False
,
normalizeDen
=
True
)
muInfVals
,
normEx
,
normApp
,
normRes
,
normErr
,
beta
=
plotInfSet3
(
murange
,
murangeEff
,
approx
,
mu0
,
25
,
[
None
,
None
,
mu0
[
2
]],
[
1.
,
1.
,
1.
],
clip
=
clip
,
relative
=
False
,
normalizeDen
=
True
)
muInfVals
,
normEx
,
normApp
,
normRes
,
normErr
,
beta
=
plotInfSet3
(
murange
,
murangeEff
,
approx
,
mu0
,
25
,
[
None
,
mu0
[
1
],
None
],
[
1.
,
1.
,
1.
],
clip
=
clip
,
relative
=
False
,
normalizeDen
=
True
)
print
(
approx
.
getPoles
([
None
,
np
.
pi
,
0.
]))
Event Timeline
Log In to Comment