Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90802219
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
Mon, Nov 4, 21:45
Size
4 KB
Mime Type
text/x-python
Expires
Wed, Nov 6, 21:45 (2 d)
Engine
blob
Format
Raw Data
Handle
22124655
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/>.
#
import
numpy
as
np
from
rrompy.reduction_methods.base.generic_approximant
import
(
GenericApproximant
)
from
rrompy.utilities.base.types
import
paramList
from
rrompy.utilities.base
import
verbosityDepth
from
rrompy.utilities.exception_manager
import
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;
- 'S': total number of samples current approximant relies upon.
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.
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.
POD: Whether to compute QR factorization of derivatives.
S: Number of solution snapshots over which current approximant is
based upon.
initialHFData: HF problem initial data.
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.
uAppReduced: Reduced approximate solution(s) with parameter(s)
lastSolvedApp as sampleList.
lastSolvedAppReduced: Parameter(s) corresponding to last computed
reduced approximate solution(s) as parameterList.
uApp: Approximate solution(s) with parameter(s) lastSolvedApp as
sampleList.
lastSolvedApp: Parameter(s) corresponding to last computed approximate
solution(s) as parameterList.
"""
@property
def
S
(
self
):
"""Value of S."""
return
self
.
_S
@S.setter
def
S
(
self
,
S
):
GenericApproximant
.
S
.
fset
(
self
,
S
)
RROMPyAssert
(
len
(
self
.
S
),
1
,
"Length of S"
)
def
computeDerivatives
(
self
):
"""Compute derivatives of solution map starting from order 0."""
RROMPyAssert
(
self
.
_mode
,
message
=
"Cannot start derivative computation."
)
if
self
.
samplingEngine
.
nsamples
<
np
.
prod
(
self
.
S
):
if
self
.
verbosity
>=
5
:
verbosityDepth
(
"INIT"
,
"Starting computation of derivatives."
,
timestamp
=
self
.
timestamp
)
self
.
samplingEngine
.
iterSample
([
self
.
mu0
[
0
]]
*
np
.
prod
(
self
.
S
),
homogeneized
=
self
.
homogeneized
)
if
self
.
verbosity
>=
5
:
verbosityDepth
(
"DEL"
,
"Done computing derivatives."
,
timestamp
=
self
.
timestamp
)
def
normApprox
(
self
,
mu
:
paramList
,
homogeneized
:
bool
=
False
)
->
float
:
"""
Compute norm of approximant at arbitrary parameter.
Args:
mu: Target parameter.
homogeneized(optional): Whether to remove Dirichlet BC. Defaults to
False.
Returns:
Target norm of approximant.
"""
if
not
self
.
POD
or
self
.
homogeneized
!=
homogeneized
:
return
super
()
.
normApprox
(
mu
,
homogeneized
)
return
np
.
linalg
.
norm
(
self
.
getApproxReduced
(
mu
),
axis
=
0
)
Event Timeline
Log In to Comment