Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F60532701
RBLagrange.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, Apr 30, 22:05
Size
4 KB
Mime Type
text/x-python
Expires
Thu, May 2, 22:05 (2 d)
Engine
blob
Format
Raw Data
Handle
17368875
Attached To
R6746 RationalROMPy
RBLagrange.py
View Options
import
numpy
as
np
from
rrompy.hfengines.linear_problem
import
\
HelmholtzSquareBubbleProblemEngine
as
HSBPE
from
rrompy.hfengines.linear_problem
import
\
HelmholtzSquareTransmissionProblemEngine
as
HSTPE
from
rrompy.hfengines.linear_problem
import
\
HelmholtzBoxScatteringProblemEngine
as
HBSPE
from
rrompy.reduction_methods.lagrange
import
ApproximantLagrangeRB
as
RB
from
rrompy.utilities.parameter_sampling
import
QuadratureSampler
as
QS
testNo
=
-
1
verb
=
100
homog
=
True
#homog = False
loadName
=
"RBLagrangeModel.pkl"
if
testNo
in
[
1
,
-
1
]:
if
testNo
>
0
:
k0s
=
np
.
power
([
10
+
0.j
,
14
+
0.j
],
.
5
)
k0
=
np
.
mean
(
np
.
power
(
k0s
,
2.
))
**
.
5
rescaling
=
lambda
x
:
np
.
power
(
x
,
2.
)
rescalingInv
=
lambda
x
:
np
.
power
(
x
,
.
5
)
params
=
{
'S'
:
5
,
'R'
:
4
,
'POD'
:
True
}
ktar
=
(
11
+
.
5j
)
**
.
5
solver
=
HSBPE
(
kappa
=
12
**
.
5
,
theta
=
np
.
pi
/
3
,
n
=
40
,
verbosity
=
verb
)
if
testNo
>
0
:
approx
=
RB
(
solver
,
mu0
=
k0
,
approxParameters
=
params
,
verbosity
=
verb
)
approx
.
sampler
=
QS
(
k0s
,
"CHEBYSHEV"
,
rescaling
,
rescalingInv
)
approx
.
setupApprox
()
# approx.plotSamples()
else
:
approx
=
RB
(
solver
,
mu0
=
0
,
verbosity
=
verb
)
approx
.
loadTrainedModel
(
loadName
)
approx
.
plotApprox
(
ktar
,
name
=
'u_RB'
)
approx
.
plotHF
(
ktar
,
name
=
'u_HF'
)
approx
.
plotErr
(
ktar
,
name
=
'err'
)
approx
.
plotRes
(
ktar
,
name
=
'res'
)
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
)))
if
testNo
>
0
:
approx
.
storeTrainedModel
(
"RBLagrangeModel"
,
forceNewFile
=
False
)
print
(
approx
.
trainedModel
.
data
.
__dict__
)
############
elif
testNo
==
2
:
k0s
=
[
3.85
+
0.j
,
4.15
+
0.j
]
k0
=
np
.
mean
(
k0s
)
ktar
=
4
+
.
15j
rescaling
=
lambda
x
:
np
.
power
(
x
,
2.
)
rescalingInv
=
lambda
x
:
np
.
power
(
x
,
.
5
)
params
=
{
'S'
:
10
,
'R'
:
9
,
'POD'
:
True
}
solver
=
HSTPE
(
nT
=
2
,
nB
=
1
,
theta
=
np
.
pi
*
45
/
180
,
kappa
=
4.
,
n
=
50
,
verbosity
=
verb
)
solver
.
omega
=
np
.
real
(
k0
)
approx
=
RB
(
solver
,
mu0
=
k0
,
approxParameters
=
params
,
verbosity
=
verb
,
homogeneized
=
homog
)
approx
.
sampler
=
QS
(
k0s
,
"CHEBYSHEV"
,
rescaling
,
rescalingInv
)
approx
.
setupApprox
()
# approx.plotSamples()
approx
.
plotApprox
(
ktar
,
name
=
'u_RB'
)
approx
.
plotHF
(
ktar
,
name
=
'u_HF'
)
approx
.
plotErr
(
ktar
,
name
=
'err'
)
approx
.
plotRes
(
ktar
,
name
=
'res'
)
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
)))
############
elif
testNo
==
3
:
k0s
=
[
2
,
5
]
k0
=
np
.
mean
(
k0s
)
ktar
=
4.5
-
0.j
params
=
{
'S'
:
15
,
'R'
:
10
,
'POD'
:
True
}
solver
=
HBSPE
(
R
=
7
,
kappa
=
3
,
theta
=
-
np
.
pi
*
75
/
180
,
n
=
40
,
verbosity
=
verb
)
solver
.
omega
=
np
.
real
(
k0
)
approx
=
RB
(
solver
,
mu0
=
k0
,
approxParameters
=
params
,
verbosity
=
verb
,
homogeneized
=
homog
)
approx
.
sampler
=
QS
(
k0s
,
"CHEBYSHEV"
)
approx
.
setupApprox
()
# approx.plotSamples()
approx
.
plotApprox
(
ktar
,
name
=
'u_RB'
)
approx
.
plotHF
(
ktar
,
name
=
'u_HF'
)
approx
.
plotErr
(
ktar
,
name
=
'err'
)
approx
.
plotRes
(
ktar
,
name
=
'res'
)
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
)))
Event Timeline
Log In to Comment