Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F66433356
fracture3_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
Mon, Jun 10, 12:08
Size
9 KB
Mime Type
text/x-python
Expires
Wed, Jun 12, 12:08 (2 d)
Engine
blob
Format
Raw Data
Handle
18221881
Attached To
R6746 RationalROMPy
fracture3_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
\
MembraneFractureEngine3
as
MFE
from
rrompy.reduction_methods.standard
import
RationalInterpolant
as
RI
from
rrompy.reduction_methods.standard
import
ReducedBasis
as
RB
from
rrompy.reduction_methods.pivoted
import
RationalInterpolantPivoted
as
RIP
from
rrompy.reduction_methods.pivoted
import
ReducedBasisPivoted
as
RBP
from
rrompy.parameter.parameter_sampling
import
(
QuadratureSampler
as
QS
,
QuadratureSamplerTotal
as
QST
,
ManualSampler
as
MS
,
RandomSampler
as
RS
)
verb
=
70
size
=
4
show_sample
=
False
show_norm
=
False
clip
=
-
1
#clip = .4
#clip = .6
Delta
=
0
MN
=
5
R
=
(
MN
+
3
)
*
(
MN
+
2
)
*
(
MN
+
1
)
//
6
S
=
[
int
(
np
.
ceil
(
R
**
(
1.
/
3.
)))]
*
3
PODTol
=
1e-8
SPivot
=
[
MN
+
1
,
5
,
5
]
MMarginal
=
SPivot
[
1
]
-
1
matchingWeight
=
10.
samples
=
"centered"
samples
=
"standard"
#samples = "pivoted"
algo
=
"rational"
#algo = "RB"
sampling
=
"quadrature"
#sampling = "quadrature_total"
#sampling = "random"
samplingM
=
"quadrature"
samplingM
=
"quadrature_total"
#samplingM = "random"
polydegreetype
=
"TOTAL"
#polydegreetype = "FULL"
if
samples
==
"standard"
:
radial
=
""
# radial = "_gaussian"
# radial = "_thinplate"
# radial = "_multiquadric"
rW0
=
5.
radialWeight
=
[
rW0
]
*
3
if
samples
==
"pivoted"
:
radial
=
""
# radial = "_gaussian"
# radial = "_thinplate"
# radial = "_multiquadric"
rW0
=
5.
radialWeight
=
[
rW0
]
radialM
=
""
# radialM = "_gaussian"
# radialM = "_thinplate"
# radialM = "_multiquadric"
rMW0
=
2.
radialWeightM
=
[
rMW0
]
*
2
assert
Delta
<=
0
if
size
==
1
:
mu0
=
[
47.5
**
.
5
,
.
4
,
.
05
]
mutar
=
[
50
**
.
5
,
.
45
,
.
07
]
murange
=
[[
40
**
.
5
,
.
3
,
.
025
],
[
55
**
.
5
,
.
5
,
.
075
]]
if
size
==
2
:
mu0
=
[
50
**
.
5
,
.
3
,
.
02
]
mutar
=
[
55
**
.
5
,
.
4
,
.
03
]
murange
=
[[
40
**
.
5
,
.
1
,
.
005
],
[
60
**
.
5
,
.
5
,
.
035
]]
if
size
==
3
:
mu0
=
[
45
**
.
5
,
.
5
,
.
05
]
mutar
=
[
47
**
.
5
,
.
4
,
.
045
]
murange
=
[[
40
**
.
5
,
.
3
,
.
04
],
[
50
**
.
5
,
.
7
,
.
06
]]
if
size
==
4
:
mu0
=
[
45
**
.
5
,
.
4
,
.
05
]
mutar
=
[
47
**
.
5
,
.
45
,
.
045
]
murange
=
[[
40
**
.
5
,
.
3
,
.
04
],
[
50
**
.
5
,
.
5
,
.
06
]]
if
size
==
5
:
mu0
=
[
45
**
.
5
,
.
5
,
.
05
]
mutar
=
[
47
**
.
5
,
.
45
,
.
045
]
murange
=
[[
40
**
.
5
,
.
3
,
.
04
],
[
50
**
.
5
,
.
7
,
.
06
]]
aEff
=
1.
#25
bEff
=
1.
-
aEff
murangeEff
=
[[(
aEff
*
murange
[
0
][
0
]
**
2.
+
bEff
*
murange
[
1
][
0
]
**
2.
)
**
.
5
,
aEff
*
murange
[
0
][
1
]
+
bEff
*
murange
[
1
][
1
],
aEff
*
murange
[
0
][
2
]
+
bEff
*
murange
[
1
][
2
]],
[(
aEff
*
murange
[
1
][
0
]
**
2.
+
bEff
*
murange
[
0
][
0
]
**
2.
)
**
.
5
,
aEff
*
murange
[
1
][
1
]
+
bEff
*
murange
[
0
][
1
],
aEff
*
murange
[
1
][
2
]
+
bEff
*
murange
[
0
][
2
]]]
H
=
1.
L
=
.
75
delta
=
.
05
n
=
50
solver
=
MFE
(
mu0
=
mu0
,
H
=
H
,
L
=
L
,
delta
=
delta
,
n
=
n
,
verbosity
=
verb
)
rescalingExp
=
[
2.
,
1.
,
1.
]
if
algo
==
"rational"
:
params
=
{
'N'
:
MN
,
'M'
:
MN
+
Delta
,
'S'
:
S
,
'POD'
:
True
,
'polydegreetype'
:
polydegreetype
}
if
samples
==
"standard"
:
params
[
'polybasis'
]
=
"CHEBYSHEV"
+
radial
# params['polybasis'] = "LEGENDRE" + radial
# params['polybasis'] = "MONOMIAL" + radial
params
[
'radialDirectionalWeights'
]
=
radialWeight
method
=
RI
elif
samples
==
"centered"
:
params
[
'polybasis'
]
=
"MONOMIAL"
params
[
'S'
]
=
R
method
=
RI
elif
samples
==
"pivoted"
:
params
[
'S'
]
=
[
SPivot
[
0
]]
params
[
'SMarginal'
]
=
SPivot
[
1
:]
params
[
'MMarginal'
]
=
MMarginal
params
[
'polybasisPivot'
]
=
"CHEBYSHEV"
+
radial
params
[
'polybasisMarginal'
]
=
"MONOMIAL"
+
radialM
params
[
'matchingWeight'
]
=
matchingWeight
params
[
'radialDirectionalWeightsPivot'
]
=
radialWeight
params
[
'radialDirectionalWeightsMarginal'
]
=
radialWeightM
method
=
RIP
else
:
#if algo == "RB":
params
=
{
'R'
:(
MN
+
3
+
Delta
)
*
(
MN
+
2
+
Delta
)
*
(
MN
+
1
+
Delta
)
//
6
,
'S'
:
S
,
'POD'
:
True
,
'PODTolerance'
:
PODTol
}
if
samples
==
"standard"
:
method
=
RB
elif
samples
==
"centered"
:
params
[
'S'
]
=
R
method
=
RB
elif
samples
==
"pivoted"
:
params
[
'S'
]
=
[
SPivot
[
0
]]
params
[
'SMarginal'
]
=
SPivot
[
1
:]
params
[
'MMarginal'
]
=
MMarginal
params
[
'polybasisMarginal'
]
=
"MONOMIAL"
+
radialM
params
[
'matchingWeight'
]
=
matchingWeight
params
[
'radialDirectionalWeightsMarginal'
]
=
radialWeightM
method
=
RBP
if
samples
==
"standard"
:
if
sampling
==
"quadrature"
:
params
[
'sampler'
]
=
QS
(
murange
,
"CHEBYSHEV"
,
scalingExp
=
rescalingExp
)
# params['sampler'] = QS(murange, "GAUSSLEGENDRE",scalingExp = rescalingExp)
# params['sampler'] = QS(murange, "UNIFORM", scalingExp = rescalingExp)
params
[
'S'
]
=
[
max
(
j
,
MN
+
1
)
for
j
in
params
[
'S'
]]
elif
sampling
==
"quadrature_total"
:
params
[
'sampler'
]
=
QST
(
murange
,
"CHEBYSHEV"
,
scalingExp
=
rescalingExp
)
params
[
'S'
]
=
R
else
:
# if sampling == "random":
params
[
'sampler'
]
=
RS
(
murange
,
"HALTON"
,
scalingExp
=
rescalingExp
)
params
[
'S'
]
=
R
elif
samples
==
"centered"
:
params
[
'sampler'
]
=
MS
(
murange
,
points
=
[
mu0
],
scalingExp
=
rescalingExp
)
elif
samples
==
"pivoted"
:
if
sampling
==
"quadrature"
:
params
[
'samplerPivot'
]
=
QS
([
murange
[
0
][
0
],
murange
[
1
][
0
]],
"CHEBYSHEV"
)
# params['samplerPivot'] = QS([murange[0][0], murange[1][0]], "GAUSSLEGENDRE")
# params['samplerPivot'] = QS([murange[0][0], murange[1][0]], "UNIFORM")
elif
sampling
==
"quadrature_total"
:
params
[
'samplerPivot'
]
=
QST
([
murange
[
0
][
0
],
murange
[
1
][
0
]],
"CHEBYSHEV"
)
params
[
'S'
]
=
MN
+
1
else
:
# if sampling == "random":
params
[
'samplerPivot'
]
=
RS
([
murange
[
0
][
0
],
murange
[
1
][
0
]],
"HALTON"
)
params
[
'S'
]
=
MN
+
1
if
samplingM
==
"quadrature"
:
params
[
'samplerMarginal'
]
=
QS
([
murange
[
0
][
1
:],
murange
[
1
][
1
:]],
"UNIFORM"
)
elif
samplingM
==
"quadrature_total"
:
params
[
'samplerMarginal'
]
=
QST
([
murange
[
0
][
1
:],
murange
[
1
][
1
:]],
"CHEBYSHEV"
)
params
[
'SMarginal'
]
=
(
MMarginal
+
2
)
*
(
MMarginal
+
1
)
//
2
params
[
'polybasisMarginal'
]
=
"CHEBYSHEV"
+
radialM
else
:
# if samplingM == "random":
params
[
'samplerMarginal'
]
=
RS
([
murange
[
0
][
1
:],
murange
[
1
][
1
:]],
"HALTON"
)
params
[
'SMarginal'
]
=
(
MMarginal
+
2
)
*
(
MMarginal
+
1
)
//
2
if
samples
!=
"pivoted"
:
approx
=
method
(
solver
,
mu0
=
mu0
,
approxParameters
=
params
,
verbosity
=
verb
)
else
:
approx
=
method
(
solver
,
mu0
=
mu0
,
directionPivot
=
[
0
],
approxParameters
=
params
,
verbosity
=
verb
)
if
samples
!=
"centered"
:
approx
.
samplingEngine
.
allowRepeatedSamples
=
False
approx
.
setupApprox
()
if
show_sample
:
from
fracture3_warping
import
fracture3_warping
warps
=
fracture3_warping
(
solver
.
V
.
mesh
(),
L
,
mutar
[
1
],
delta
,
mutar
[
2
])
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
(
np
.
real
(
approx
.
mus
(
0
)
**
2.
),
np
.
real
(
approx
.
mus
(
1
)),
np
.
real
(
approx
.
mus
(
2
)),
'.'
)
plt
.
show
()
plt
.
close
()
approx
.
verbosity
=
0
approx
.
trainedModel
.
verbosity
=
0
from
plot_zero_set_3
import
plotZeroSet3
#muZeroVals, Qvals = plotZeroSet3(murange, murangeEff, approx, mu0, 200,
# [None, mu0[1], mu0[2]], [2., 1., 1.],
# clip = clip)
#muZeroVals, Qvals = plotZeroSet3(murange, murangeEff, approx, mu0, 200,
# [None, None, mu0[2]], [2., 1., 1.],
# clip = clip)
#muZeroVals, Qvals = plotZeroSet3(murange, murangeEff, approx, mu0, 200,
# [None, mu0[1], None], [2., 1., 1.],
# clip = clip)
muZeroScatter
=
plotZeroSet3
(
murange
,
murangeEff
,
approx
,
mu0
,
50
,
[
None
,
None
,
None
],
[
2.
,
1.
,
1.
],
clip
=
clip
)
if
show_norm
:
solver
.
_solveBatchSize
=
25
from
plot_inf_set_3
import
plotInfSet3
muInfVals
,
normEx
,
normApp
,
normRes
,
normErr
,
beta
=
plotInfSet3
(
murange
,
murangeEff
,
approx
,
mu0
,
25
,
[
None
,
mu0
[
1
],
mu0
[
2
]],
[
2.
,
1.
,
1.
],
clip
=
clip
,
relative
=
False
,
normalizeDen
=
True
)
muInfVals
,
normEx
,
normApp
,
normRes
,
normErr
,
beta
=
plotInfSet3
(
murange
,
murangeEff
,
approx
,
mu0
,
25
,
[
None
,
None
,
mu0
[
2
]],
[
2.
,
1.
,
1.
],
clip
=
clip
,
relative
=
False
,
normalizeDen
=
True
)
muInfVals
,
normEx
,
normApp
,
normRes
,
normErr
,
beta
=
plotInfSet3
(
murange
,
murangeEff
,
approx
,
mu0
,
25
,
[
None
,
mu0
[
1
],
None
],
[
2.
,
1.
,
1.
],
clip
=
clip
,
relative
=
False
,
normalizeDen
=
True
)
print
(
approx
.
getPoles
([
None
,
.
5
,
.
05
])
**
2.
)
Event Timeline
Log In to Comment