Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F64747067
ReducedBasis.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
Wed, May 29, 04:03
Size
4 KB
Mime Type
text/x-python
Expires
Fri, May 31, 04:03 (2 d)
Engine
blob
Format
Raw Data
Handle
17953175
Attached To
R6746 RationalROMPy
ReducedBasis.py
View Options
import
numpy
as
np
from
helmholtz_square_bubble_problem_engine
import
\
HelmholtzSquareBubbleProblemEngine
as
HSBPE
from
helmholtz_square_transmission_problem_engine
import
\
HelmholtzSquareTransmissionProblemEngine
as
HSTPE
from
helmholtz_box_scattering_problem_engine
import
\
HelmholtzBoxScatteringProblemEngine
as
HBSPE
from
rrompy.reduction_methods.standard
import
ReducedBasis
as
RB
from
rrompy.parameter.parameter_sampling
import
QuadratureSampler
as
QS
testNo
=
1
verb
=
100
loadName
=
"ReducedBasisModel.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
params
=
{
'S'
:
5
,
'R'
:
4
,
'POD'
:
True
,
'sampler'
:
QS
(
k0s
,
"CHEBYSHEV"
,
2.
)}
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
.
setupApprox
()
# approx.plotSamples()
else
:
approx
=
RB
(
solver
,
mu0
=
0
,
approxParameters
=
{
'S'
:
1
,
'muBounds'
:[
0
,
1
]},
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
(
"ReducedBasisModel"
,
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
params
=
{
'S'
:
10
,
'R'
:
9
,
'POD'
:
True
,
'sampler'
:
QS
(
k0s
,
"CHEBYSHEV"
,
2.
)}
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
)
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
,
'sampler'
:
QS
(
k0s
,
"CHEBYSHEV"
)}
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
)
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