Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F60218153
generic_centered_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
Sun, Apr 28, 09:42
Size
5 KB
Mime Type
text/x-python
Expires
Tue, Apr 30, 09:42 (2 d)
Engine
blob
Format
Raw Data
Handle
17319227
Attached To
R6746 RationalROMPy
generic_centered_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/>.
#
from
rrompy.reduction_methods.base.generic_approximant
import
(
GenericApproximant
)
from
rrompy.utilities.base.types
import
DictAny
,
HFEng
,
paramVal
from
rrompy.utilities.base
import
purgeDict
,
verbosityDepth
from
rrompy.utilities.exception_manager
import
RROMPyException
,
RROMPyAssert
__all__
=
[
'GenericCenteredApproximant'
]
class
GenericCenteredApproximant
(
GenericApproximant
):
"""
ROM single-point approximant 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;
- 'E': total number of derivatives current approximant relies upon;
defaults to 1.
Defaults to empty dict.
homogeneized(optional): Whether to homogeneize Dirichlet BCs. Defaults
to False.
verbosity(optional): Verbosity level. Defaults to 10.
Attributes:
HFEngine: HF problem solver.
mu0: Default parameter.
homogeneized: Whether to homogeneize Dirichlet BCs.
approxParameters: Dictionary containing values for main parameters of
approximant. Recognized keys are in parameterList.
parameterList: Recognized keys of approximant parameters:
- 'POD': whether to compute POD of snapshots;
- 'E': total number of derivatives current approximant relies upon.
POD: Whether to compute QR factorization of derivatives.
E: Number of solution derivatives over which current approximant is
based upon.
initialHFData: HF problem initial data.
samplingEngine: Sampling engine.
uHF: High fidelity solution with wavenumber lastSolvedHF as numpy
complex vector.
lastSolvedHF: Wavenumber corresponding to last computed high fidelity
solution.
uApp: Last evaluated approximant as numpy complex vector.
"""
def
__init__
(
self
,
HFEngine
:
HFEng
,
mu0
:
paramVal
=
0
,
approxParameters
:
DictAny
=
{},
homogeneized
:
bool
=
False
,
verbosity
:
int
=
10
,
timestamp
:
bool
=
True
):
self
.
_preInit
()
self
.
_addParametersToList
([
"E"
])
super
()
.
__init__
(
HFEngine
=
HFEngine
,
mu0
=
mu0
,
approxParameters
=
approxParameters
,
homogeneized
=
homogeneized
,
verbosity
=
verbosity
,
timestamp
=
timestamp
)
self
.
_postInit
()
@property
def
approxParameters
(
self
):
"""Value of approximant parameters. Its assignment may change E."""
return
self
.
_approxParameters
@approxParameters.setter
def
approxParameters
(
self
,
approxParams
):
approxParameters
=
purgeDict
(
approxParams
,
self
.
parameterList
,
dictname
=
self
.
name
()
+
".approxParameters"
,
baselevel
=
1
)
approxParametersCopy
=
purgeDict
(
approxParameters
,
[
"E"
],
True
,
True
,
baselevel
=
1
)
GenericApproximant
.
approxParameters
.
fset
(
self
,
approxParametersCopy
)
keyList
=
list
(
approxParameters
.
keys
())
if
"E"
in
keyList
:
self
.
E
=
approxParameters
[
"E"
]
elif
hasattr
(
self
,
"_E"
)
and
self
.
_E
is
not
None
:
self
.
E
=
self
.
E
else
:
self
.
E
=
1
@property
def
E
(
self
):
"""Value of E."""
return
self
.
_E
@E.setter
def
E
(
self
,
E
):
if
E
<
0
:
raise
RROMPyException
(
"E must be non-negative."
)
self
.
_E
=
E
self
.
_approxParameters
[
"E"
]
=
self
.
E
def
computeDerivatives
(
self
):
"""Compute derivatives of solution map starting from order 0."""
RROMPyAssert
(
self
.
_mode
,
message
=
"Cannot start derivative computation."
)
if
self
.
samplingEngine
.
nsamples
<=
self
.
E
:
if
self
.
verbosity
>=
5
:
verbosityDepth
(
"INIT"
,
"Starting computation of derivatives."
,
timestamp
=
self
.
timestamp
)
self
.
samplingEngine
.
iterSample
([
self
.
mu0
]
*
(
self
.
E
+
1
),
homogeneized
=
self
.
homogeneized
)
if
self
.
verbosity
>=
5
:
verbosityDepth
(
"DEL"
,
"Done computing derivatives."
,
timestamp
=
self
.
timestamp
)
Event Timeline
Log In to Comment