Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F61036868
fracture_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
Sat, May 4, 03:26
Size
10 KB
Mime Type
text/x-python
Expires
Mon, May 6, 03:26 (2 d)
Engine
blob
Format
Raw Data
Handle
17456098
Attached To
R6746 RationalROMPy
fracture_pod.py
View Options
import
numpy
as
np
from
rrompy.hfengines.linear_problem.bidimensional
import
\
MembraneFractureEngine
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.reduction_methods.pole_matching
import
\
RationalInterpolantPoleMatching
as
RIPM
from
rrompy.reduction_methods.pole_matching
import
\
ReducedBasisPoleMatching
as
RBPM
from
rrompy.parameter.parameter_sampling
import
(
QuadratureSampler
as
QS
,
QuadratureSamplerTotal
as
QST
,
ManualSampler
as
MS
,
RandomSampler
as
RS
)
verb
=
70
size
=
2
show_sample
=
False
show_norm
=
True
Delta
=
0
MN
=
8
R
=
(
MN
+
2
)
*
(
MN
+
1
)
//
2
S
=
[
int
(
np
.
ceil
(
R
**
.
5
))]
*
2
PODTol
=
1e-4
SPivot
=
[
MN
+
1
,
4
]
MMarginal
=
SPivot
[
1
]
-
1
matchingWeight
=
1.
cutOffTolerance
=
1.
*
np
.
inf
cutOffType
=
"MAGNITUDE"
samples
=
"centered"
samples
=
"standard"
samples
=
"pivoted"
samples
=
"pole matching"
algo
=
"rational"
algo
=
"RB"
sampling
=
"quadrature"
sampling
=
"quadrature_total"
#sampling = "random"
samplingM
=
"quadrature"
#samplingM = "quadrature_total"
#samplingM = "random"
if
samples
in
[
"standard"
,
"pivoted"
,
"pole matching"
]:
radial
=
0
# radial = "gaussian"
# radial = "thinplate"
# radial = "multiquadric"
rW0
=
5.
radialWeight
=
[
rW0
]
if
samples
in
[
"pivoted"
,
"pole matching"
]:
radialM
=
0
# radialM = "gaussian"
# radialM = "thinplate"
# radialM = "multiquadric"
rMW0
=
2.
radialWeightM
=
[
rMW0
]
assert
Delta
<=
0
if
size
==
1
:
# below
mu0
=
[
40
**
.
5
,
.
4
]
mutar
=
[
45
**
.
5
,
.
4
]
murange
=
[[
30
**
.
5
,
.
3
],
[
50
**
.
5
,
.
5
]]
elif
size
==
2
:
# top
mu0
=
[
40
**
.
5
,
.
6
]
mutar
=
[
45
**
.
5
,
.
6
]
murange
=
[[
30
**
.
5
,
.
5
],
[
50
**
.
5
,
.
7
]]
elif
size
==
3
:
# interesting
mu0
=
[
40
**
.
5
,
.
5
]
mutar
=
[
45
**
.
5
,
.
5
]
murange
=
[[
30
**
.
5
,
.
3
],
[
50
**
.
5
,
.
7
]]
elif
size
==
4
:
# wide_low
mu0
=
[
40
**
.
5
,
.
2
]
mutar
=
[
45
**
.
5
,
.
2
]
murange
=
[[
10
**
.
5
,
.
1
],
[
70
**
.
5
,
.
3
]]
elif
size
==
5
:
# wide_hi
mu0
=
[
40
**
.
5
,
.
8
]
mutar
=
[
45
**
.
5
,
.
8
]
murange
=
[[
10
**
.
5
,
.
7
],
[
70
**
.
5
,
.
9
]]
elif
size
==
6
:
# top_zoom
mu0
=
[
50
**
.
5
,
.
8
]
mutar
=
[
55
**
.
5
,
.
8
]
murange
=
[[
40
**
.
5
,
.
7
],
[
60
**
.
5
,
.
9
]]
elif
size
==
7
:
# huge
mu0
=
[
50
**
.
5
,
.
5
]
mutar
=
[
55
**
.
5
,
.
5
]
murange
=
[[
10
**
.
5
,
.
2
],
[
90
**
.
5
,
.
8
]]
elif
size
==
11
:
#L below
mu0
=
[
110
**
.
5
,
.
4
]
mutar
=
[
115
**
.
5
,
.
4
]
murange
=
[[
90
**
.
5
,
.
3
],
[
130
**
.
5
,
.
5
]]
elif
size
==
12
:
#L top
mu0
=
[
110
**
.
5
,
.
6
]
mutar
=
[
115
**
.
5
,
.
6
]
murange
=
[[
90
**
.
5
,
.
5
],
[
130
**
.
5
,
.
7
]]
elif
size
==
13
:
#L interesting
mu0
=
[
110
**
.
5
,
.
5
]
mutar
=
[
115
**
.
5
,
.
5
]
murange
=
[[
90
**
.
5
,
.
3
],
[
130
**
.
5
,
.
7
]]
elif
size
==
14
:
#L belowbelow
mu0
=
[
110
**
.
5
,
.
2
]
mutar
=
[
115
**
.
5
,
.
2
]
murange
=
[[
90
**
.
5
,
.
1
],
[
130
**
.
5
,
.
3
]]
elif
size
==
15
:
#L toptop
mu0
=
[
110
**
.
5
,
.
8
]
mutar
=
[
115
**
.
5
,
.
8
]
murange
=
[[
90
**
.
5
,
.
7
],
[
130
**
.
5
,
.
9
]]
elif
size
==
16
:
#L interestinginteresting
mu0
=
[
110
**
.
5
,
.
5
]
mutar
=
[
115
**
.
5
,
.
6
]
murange
=
[[
90
**
.
5
,
.
1
],
[
130
**
.
5
,
.
9
]]
elif
size
==
17
:
#L interestingtop
mu0
=
[
110
**
.
5
,
.
7
]
mutar
=
[
115
**
.
5
,
.
6
]
murange
=
[[
90
**
.
5
,
.
5
],
[
130
**
.
5
,
.
9
]]
elif
size
==
18
:
#L interestingbelow
mu0
=
[
110
**
.
5
,
.
3
]
mutar
=
[
115
**
.
5
,
.
4
]
murange
=
[[
90
**
.
5
,
.
1
],
[
130
**
.
5
,
.
5
]]
elif
size
==
100
:
# tiny
mu0
=
[
32.5
**
.
5
,
.
5
]
mutar
=
[
34
**
.
5
,
.
5
]
murange
=
[[
30
**
.
5
,
.
3
],
[
35
**
.
5
,
.
7
]]
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
[
1
][
0
]
**
2.
+
bEff
*
murange
[
0
][
0
]
**
2.
)
**
.
5
,
aEff
*
murange
[
1
][
1
]
+
bEff
*
murange
[
0
][
1
]]]
H
=
1.
L
=
.
75
delta
=
.
05
n
=
20
solver
=
MFE
(
mu0
=
mu0
,
H
=
H
,
L
=
L
,
delta
=
delta
,
n
=
n
,
verbosity
=
verb
)
rescalingExp
=
[
2.
,
1.
]
if
algo
==
"rational"
:
params
=
{
'N'
:
MN
,
'M'
:
MN
+
Delta
,
'S'
:
S
,
'POD'
:
True
}
if
samples
==
"standard"
:
params
[
'polybasis'
]
=
"CHEBYSHEV"
# params['polybasis'] = "LEGENDRE"
# params['polybasis'] = "MONOMIAL"
params
[
'E'
]
=
MN
params
[
'radialBasis'
]
=
radial
params
[
'radialBasisWeights'
]
=
radialWeight
method
=
RI
elif
samples
==
"centered"
:
params
[
'polybasis'
]
=
"MONOMIAL"
params
[
'S'
]
=
R
method
=
RI
elif
samples
in
[
"pivoted"
,
"pole matching"
]:
params
[
'S'
]
=
[
SPivot
[
0
]]
params
[
'SMarginal'
]
=
[
SPivot
[
1
]]
params
[
'MMarginal'
]
=
MMarginal
params
[
'polybasisPivot'
]
=
"CHEBYSHEV"
params
[
'polybasisMarginal'
]
=
"MONOMIAL"
params
[
'radialBasisPivot'
]
=
radial
params
[
'radialBasisMarginal'
]
=
radialM
params
[
'radialBasisWeightsPivot'
]
=
radialWeight
params
[
'radialBasisWeightsMarginal'
]
=
radialWeightM
if
samples
==
"pivoted"
:
method
=
RIP
else
:
params
[
'matchingWeight'
]
=
matchingWeight
params
[
'cutOffTolerance'
]
=
cutOffTolerance
params
[
"cutOffType"
]
=
cutOffType
method
=
RIPM
else
:
#if algo == "RB":
params
=
{
'R'
:(
MN
+
2
+
Delta
)
*
(
MN
+
1
+
Delta
)
//
2
,
'S'
:
S
,
'POD'
:
True
,
'PODTolerance'
:
PODTol
}
if
samples
==
"standard"
:
method
=
RB
elif
samples
==
"centered"
:
params
[
'S'
]
=
R
method
=
RB
elif
samples
in
[
"pivoted"
,
"pole matching"
]:
params
[
'S'
]
=
[
SPivot
[
0
]]
params
[
'SMarginal'
]
=
[
SPivot
[
1
]]
params
[
'MMarginal'
]
=
MMarginal
params
[
'polybasisMarginal'
]
=
"MONOMIAL"
params
[
'radialBasisMarginal'
]
=
radialM
params
[
'radialBasisWeightsMarginal'
]
=
radialWeightM
method
=
RBP
if
samples
==
"pivoted"
:
method
=
RBP
else
:
params
[
'matchingWeight'
]
=
matchingWeight
params
[
'cutOffTolerance'
]
=
cutOffTolerance
params
[
"cutOffType"
]
=
cutOffType
method
=
RBPM
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
in
[
"pivoted"
,
"pole matching"
]:
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"
)
else
:
# if sampling == "random":
params
[
'samplerPivot'
]
=
RS
([
murange
[
0
][
0
],
murange
[
1
][
0
]],
"HALTON"
)
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"
)
else
:
# if samplingM == "random":
params
[
'samplerMarginal'
]
=
RS
([
murange
[
0
][
1
],
murange
[
1
][
1
]],
"HALTON"
)
if
samples
not
in
[
"pivoted"
,
"pole matching"
]:
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
:
import
ufl
import
fenics
as
fen
from
rrompy.solver.fenics
import
affine_warping
L
=
mutar
[
1
]
y
=
fen
.
SpatialCoordinate
(
solver
.
V
.
mesh
())[
1
]
warp1
,
warpI1
=
affine_warping
(
solver
.
V
.
mesh
(),
np
.
array
([[
1
,
0
],
[
0
,
2.
*
L
]]))
warp2
,
warpI2
=
affine_warping
(
solver
.
V
.
mesh
(),
np
.
array
([[
1
,
0
],
[
0
,
2.
-
2.
*
L
]]))
warp
=
ufl
.
conditional
(
ufl
.
ge
(
y
,
0.
),
warp1
,
warp2
)
warpI
=
ufl
.
conditional
(
ufl
.
ge
(
y
,
0.
),
warpI1
,
warpI2
)
approx
.
plotApprox
(
mutar
,
[
warp
,
warpI
],
name
=
'u_app'
,
homogeneized
=
False
,
what
=
"REAL"
)
approx
.
plotHF
(
mutar
,
[
warp
,
warpI
],
name
=
'u_HF'
,
homogeneized
=
False
,
what
=
"REAL"
)
approx
.
plotErr
(
mutar
,
[
warp
,
warpI
],
name
=
'err'
,
homogeneized
=
False
,
what
=
"REAL"
)
# approx.plotRes(mutar, [warp, warpI], name = 'res',
# homogeneized = False, 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
)))
approx
.
verbosity
=
5
from
plot_zero_set
import
plotZeroSet2
muZeroVals
,
Qvals
=
plotZeroSet2
(
murange
,
murangeEff
,
approx
,
mu0
,
200
,
[
2.
,
1.
])
if
show_norm
:
solver
.
_solveBatchSize
=
100
from
plot_inf_set
import
plotInfSet2
muInfVals
,
normEx
,
normApp
,
normRes
,
normErr
,
beta
=
plotInfSet2
(
murange
,
murangeEff
,
approx
,
mu0
,
50
,
[
2.
,
1.
],
relative
=
True
,
nobeta
=
True
)
print
(
np
.
sort
(
approx
.
getPoles
([
None
,
.
5
])
**
2.
))
Event Timeline
Log In to Comment