Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F81714621
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, Sep 7, 14:04
Size
5 KB
Mime Type
text/x-python
Expires
Mon, Sep 9, 14:04 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
20611232
Attached To
R6746 RationalROMPy
pod.py
View Options
import
numpy
as
np
from
diapason_engine
import
DiapasonEngine
,
DiapasonEngineDamped
from
rrompy.reduction_methods.standard
import
RationalInterpolant
as
Pade
from
rrompy.reduction_methods.standard
import
ReducedBasis
as
RB
from
rrompy.parameter.parameter_sampling
import
QuadratureSampler
as
QS
verb
=
100
sol
=
"single"
sol
=
"sweep"
algo
=
"Pade"
#algo = "RB"
polyBasis
=
"LEGENDRE"
polyBasis
=
"CHEBYSHEV"
#polyBasis = "MONOMIAL"
dampingEta
=
0.
*
1e4
/
2.
/
np
.
pi
ktar
=
1.e4
# [Hz]
k0s
=
[
2.5e2
,
1.0e4
]
#k0s = np.array([2.5e3, 1.5e4])
#k0s = np.array([5.0e4, 1.0e5])
k0s
=
[
2.0e5
,
3.0e5
]
k0
=
np
.
mean
(
np
.
power
(
k0s
,
2.
))
**
.
5
theta
=
20.
*
np
.
pi
/
180.
phi
=
10.
*
np
.
pi
/
180.
c
=
3.e2
rho
=
8e3
*
(
2.
*
np
.
pi
)
**
2.
E
=
1.93e11
nu
=
.
3
T
=
1e6
###
if
np
.
isclose
(
dampingEta
,
0.
):
rescalingExp
=
2.
solver
=
DiapasonEngine
(
kappa
=
k0
,
c
=
c
,
rho
=
rho
,
E
=
E
,
nu
=
nu
,
T
=
T
,
theta
=
theta
,
phi
=
phi
,
meshNo
=
1
,
degree_threshold
=
8
,
verbosity
=
0
)
else
:
rescalingExp
=
1.
solver
=
DiapasonEngineDamped
(
kappa
=
k0
,
c
=
c
,
rho
=
rho
,
E
=
E
,
nu
=
nu
,
T
=
T
,
theta
=
theta
,
phi
=
phi
,
dampingEta
=
dampingEta
,
meshNo
=
1
,
degree_threshold
=
8
,
verbosity
=
0
)
params
=
{
'N'
:
39
,
'M'
:
39
,
'S'
:
40
,
'POD'
:
True
,
'polybasis'
:
polyBasis
,
'sampler'
:
QS
(
k0s
,
"CHEBYSHEV"
,
rescalingExp
)}
#,
# 'robustTol':1e-16}
if
algo
==
"Pade"
:
approx
=
Pade
(
solver
,
mu0
=
k0
,
approxParameters
=
params
,
verbosity
=
verb
)
else
:
params
.
pop
(
"N"
)
params
.
pop
(
"M"
)
params
.
pop
(
"polybasis"
)
# params.pop("robustTol")
approx
=
RB
(
solver
,
mu0
=
k0
,
approxParameters
=
params
,
verbosity
=
verb
)
approx
.
setupApprox
()
if
sol
==
"single"
:
approx
.
outParaviewTimeDomainSamples
(
filename
=
"out/outSamples{}"
.
format
(
dampingEta
),
forceNewFile
=
False
,
folders
=
True
)
nameBase
=
"{}_{}"
.
format
(
ktar
,
dampingEta
)
approx
.
outParaviewTimeDomainApprox
(
ktar
,
omega
=
2.
*
np
.
pi
*
ktar
,
filename
=
"out/outTApp{}"
.
format
(
nameBase
),
forceNewFile
=
False
,
folder
=
True
)
approx
.
outParaviewTimeDomainHF
(
ktar
,
omega
=
2.
*
np
.
pi
*
ktar
,
filename
=
"out/outTHF{}"
.
format
(
nameBase
),
forceNewFile
=
False
,
folder
=
True
)
approx
.
outParaviewTimeDomainErr
(
ktar
,
omega
=
2.
*
np
.
pi
*
ktar
,
filename
=
"out/outTErr{}"
.
format
(
nameBase
),
forceNewFile
=
False
,
folder
=
True
)
approx
.
outParaviewTimeDomainRes
(
ktar
,
omega
=
2.
*
np
.
pi
*
ktar
,
filename
=
"out/outTRes{}"
.
format
(
nameBase
),
forceNewFile
=
False
,
folder
=
True
)
appErr
,
solNorm
=
approx
.
normErr
(
ktar
),
approx
.
normHF
(
ktar
)
resNorm
,
RHSNorm
=
approx
.
normRes
(
ktar
),
approx
.
normRHS
(
ktar
)
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
)))
poles
=
approx
.
getPoles
()
print
(
'Poles:'
,
poles
)
if
sol
==
"sweep"
:
k0s
=
np
.
linspace
(
k0s
[
0
],
k0s
[
1
],
100
)
kl
,
kr
=
min
(
k0s
),
max
(
k0s
)
approx
.
samplingEngine
.
verbosity
=
0
approx
.
trainedModel
.
verbosity
=
0
approx
.
verbosity
=
0
kl
,
kr
=
np
.
real
(
kl
),
np
.
real
(
kr
)
from
matplotlib
import
pyplot
as
plt
normApp
=
np
.
zeros
(
len
(
k0s
))
norm
=
np
.
zeros_like
(
normApp
)
err
=
np
.
zeros_like
(
normApp
)
res
=
np
.
zeros_like
(
normApp
)
# errApp = np.zeros_like(normApp)
fNorm
=
approx
.
normRHS
(
k0s
[
0
])
for
j
in
range
(
len
(
k0s
)):
normApp
[
j
]
=
approx
.
normApprox
(
k0s
[
j
])
norm
[
j
]
=
approx
.
normHF
(
k0s
[
j
])
err
[
j
]
=
approx
.
normErr
(
k0s
[
j
])
/
norm
[
j
]
res
[
j
]
=
approx
.
normRes
(
k0s
[
j
])
/
fNorm
# errApp[j] = res[j] / np.min(np.abs(k0s[j] - poles))
# errApp *= np.mean(err) / np.mean(errApp)
plt
.
figure
()
plt
.
semilogy
(
k0s
,
norm
)
plt
.
semilogy
(
k0s
,
normApp
,
'--'
)
plt
.
semilogy
(
np
.
real
(
approx
.
mus
),
1.05
*
np
.
max
(
norm
)
*
np
.
ones_like
(
approx
.
mus
,
dtype
=
float
),
'rx'
)
plt
.
xlim
([
kl
,
kr
])
plt
.
grid
()
plt
.
show
()
plt
.
close
()
plt
.
figure
()
plt
.
semilogy
(
k0s
,
res
)
plt
.
xlim
([
kl
,
kr
])
plt
.
grid
()
plt
.
show
()
plt
.
close
()
plt
.
figure
()
plt
.
semilogy
(
k0s
,
err
)
# plt.semilogy(k0s, errApp)
plt
.
xlim
([
kl
,
kr
])
plt
.
grid
()
plt
.
show
()
plt
.
close
()
polesApp
=
approx
.
getPoles
()
mask
=
(
np
.
real
(
polesApp
)
<
kl
)
|
(
np
.
real
(
polesApp
)
>
kr
)
print
(
"Outliers:"
,
polesApp
[
mask
])
polesApp
=
polesApp
[
~
mask
]
plt
.
figure
()
plt
.
plot
(
np
.
real
(
polesApp
),
np
.
imag
(
polesApp
),
'kx'
)
plt
.
axis
(
'equal'
)
plt
.
grid
()
plt
.
show
()
plt
.
close
()
Event Timeline
Log In to Comment