Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F62047900
generic_standard_approximant.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
Fri, May 10, 14:16
Size
6 KB
Mime Type
text/x-python
Expires
Sun, May 12, 14:16 (2 d)
Engine
blob
Format
Raw Data
Handle
17595394
Attached To
R6746 RationalROMPy
generic_standard_approximant.py
View Options
# Copyright (C) 2018 by the RROMPy authors
#
# This file is part of RROMPy.
#
# RROMPy is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# RROMPy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with RROMPy. If not, see <http://www.gnu.org/licenses/>.
#
import
numpy
as
np
from
copy
import
deepcopy
as
copy
from
rrompy.reduction_methods.base.generic_approximant
import
(
GenericApproximant
)
from
rrompy.utilities.base
import
verbosityManager
as
vbMng
from
rrompy.utilities.exception_manager
import
RROMPyException
,
RROMPyAssert
from
rrompy.parameter
import
checkParameterList
__all__
=
[
'GenericStandardApproximant'
]
class
GenericStandardApproximant
(
GenericApproximant
):
"""
ROM interpolant computation for parametric problems (ABSTRACT).
Args:
HFEngine: HF problem solver.
mu0(optional): Default parameter. Defaults to 0.
approxParameters(optional): Dictionary containing values for main
parameters of approximant. Recognized keys are:
- 'POD': whether to compute POD of snapshots; defaults to True;
- 'S': total number of samples current approximant relies upon;
- 'sampler': sample point generator.
Defaults to empty dict.
approx_state(optional): Whether to approximate state. Defaults to
False.
verbosity(optional): Verbosity level. Defaults to 10.
Attributes:
HFEngine: HF problem solver.
mu0: Default parameter.
mus: Array of snapshot parameters.
approxParameters: Dictionary containing values for main parameters of
approximant. Recognized keys are in parameterList.
parameterListSoft: Recognized keys of soft approximant parameters:
- 'POD': whether to compute POD of snapshots.
parameterListCritical: Recognized keys of critical approximant
parameters:
- 'S': total number of samples current approximant relies upon;
- 'sampler': sample point generator.
approx_state: Whether to approximate state.
verbosity: Verbosity level.
POD: Whether to compute POD of snapshots.
S: Number of solution snapshots over which current approximant is
based upon.
sampler: Sample point generator.
muBounds: list of bounds for parameter values.
samplingEngine: Sampling engine.
uHF: High fidelity solution(s) with parameter(s) lastSolvedHF as
sampleList.
lastSolvedHF: Parameter(s) corresponding to last computed high fidelity
solution(s) as parameterList.
uApproxReduced: Reduced approximate solution(s) with parameter(s)
lastSolvedApprox as sampleList.
lastSolvedApproxReduced: Parameter(s) corresponding to last computed
reduced approximate solution(s) as parameterList.
uApprox: Approximate solution(s) with parameter(s) lastSolvedApprox as
sampleList.
lastSolvedApprox: Parameter(s) corresponding to last computed
approximate solution(s) as parameterList.
"""
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
_preInit
()
from
rrompy.parameter.parameter_sampling
import
QuadratureSampler
as
QS
self
.
_addParametersToList
([],
[],
[
"sampler"
],
[
QS
([[
0
],
[
1
]],
"UNIFORM"
)])
del
QS
super
()
.
__init__
(
*
args
,
**
kwargs
)
self
.
_postInit
()
@property
def
mus
(
self
):
"""Value of mus. Its assignment may reset snapshots."""
return
self
.
_mus
@mus.setter
def
mus
(
self
,
mus
):
mus
=
checkParameterList
(
mus
,
self
.
npar
)[
0
]
musOld
=
copy
(
self
.
mus
)
if
hasattr
(
self
,
'_mus'
)
else
None
if
(
musOld
is
None
or
len
(
mus
)
!=
len
(
musOld
)
or
not
mus
==
musOld
):
self
.
resetSamples
()
self
.
_mus
=
mus
@property
def
muBounds
(
self
):
"""Value of muBounds."""
return
self
.
sampler
.
lims
@property
def
sampler
(
self
):
"""Value of sampler."""
return
self
.
_sampler
@sampler.setter
def
sampler
(
self
,
sampler
):
if
'generatePoints'
not
in
dir
(
sampler
):
raise
RROMPyException
(
"Sampler type not recognized."
)
if
hasattr
(
self
,
'_sampler'
)
and
self
.
_sampler
is
not
None
:
samplerOld
=
self
.
sampler
self
.
_sampler
=
sampler
self
.
_approxParameters
[
"sampler"
]
=
self
.
sampler
.
__str__
()
if
not
'samplerOld'
in
locals
()
or
samplerOld
!=
self
.
sampler
:
self
.
resetSamples
()
def
setSamples
(
self
,
samplingEngine
):
"""Copy samplingEngine and samples."""
self
.
mus
=
copy
(
samplingEngine
.
mus
)
super
()
.
setSamples
(
samplingEngine
)
def
computeSnapshots
(
self
):
"""Compute snapshots of solution map."""
RROMPyAssert
(
self
.
_mode
,
message
=
"Cannot start snapshot computation."
)
self
.
computeScaleFactor
()
self
.
samplingEngine
.
scaleFactor
=
self
.
scaleFactor
if
self
.
samplingEngine
.
nsamples
!=
self
.
S
:
vbMng
(
self
,
"INIT"
,
"Starting computation of snapshots."
,
5
)
self
.
mus
=
self
.
sampler
.
generatePoints
(
self
.
S
)
while
len
(
self
.
mus
)
>
self
.
S
:
self
.
mus
.
pop
()
self
.
samplingEngine
.
iterSample
(
self
.
mus
)
vbMng
(
self
,
"DEL"
,
"Done computing snapshots."
,
5
)
def
computeScaleFactor
(
self
):
"""Compute parameter rescaling factor."""
RROMPyAssert
(
self
.
_mode
,
message
=
"Cannot compute rescaling factor."
)
self
.
scaleFactor
=
.
5
*
np
.
abs
(
self
.
muBounds
[
0
]
**
self
.
HFEngine
.
rescalingExp
-
self
.
muBounds
[
1
]
**
self
.
HFEngine
.
rescalingExp
)
Event Timeline
Log In to Comment