Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F60247248
rational_interpolant_pivoted_greedy.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, 15:03
Size
16 KB
Mime Type
text/x-python
Expires
Tue, Apr 30, 15:03 (2 d)
Engine
blob
Format
Raw Data
Handle
17324694
Attached To
R6746 RationalROMPy
rational_interpolant_pivoted_greedy.py
View Options
# Copyright (C) 2018-2020 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
copy
import
deepcopy
as
copy
import
numpy
as
np
from
.generic_pivoted_greedy_approximant
import
(
GenericPivotedGreedyApproximantBase
,
GenericPivotedGreedyApproximantPoleMatch
)
from
rrompy.reduction_methods.standard
import
RationalInterpolant
from
rrompy.reduction_methods.pivoted
import
(
RationalInterpolantPivotedPoleMatch
)
from
rrompy.utilities.base.types
import
paramList
from
rrompy.utilities.base
import
verbosityManager
as
vbMng
from
rrompy.utilities.exception_manager
import
RROMPyAssert
from
rrompy.parameter
import
emptyParameterList
from
rrompy.utilities.parallel
import
poolRank
,
recv
__all__
=
[
'RationalInterpolantPivotedGreedyPoleMatch'
]
class
RationalInterpolantPivotedGreedyBase
(
GenericPivotedGreedyApproximantBase
):
def
computeSnapshots
(
self
):
"""Compute snapshots of solution map."""
RROMPyAssert
(
self
.
_mode
,
message
=
"Cannot start snapshot computation."
)
vbMng
(
self
,
"INIT"
,
"Starting computation of snapshots."
,
5
)
self
.
samplingEngine
.
scaleFactor
=
self
.
scaleFactorDer
if
not
hasattr
(
self
,
"musPivot"
)
or
len
(
self
.
musPivot
)
!=
self
.
S
:
self
.
musPivot
=
self
.
samplerPivot
.
generatePoints
(
self
.
S
)
while
len
(
self
.
musPivot
)
>
self
.
S
:
self
.
musPivot
.
pop
()
musLoc
=
emptyParameterList
()
musLoc
.
reset
((
self
.
S
,
self
.
HFEngine
.
npar
))
self
.
samplingEngine
.
resetHistory
()
musLoc
.
data
[:,
self
.
directionPivot
]
=
self
.
musPivot
.
data
musLoc
.
data
[:,
self
.
directionMarginal
]
=
np
.
repeat
(
self
.
muMargLoc
,
self
.
S
,
axis
=
0
)
self
.
samplingEngine
.
iterSample
(
musLoc
)
vbMng
(
self
,
"DEL"
,
"Done computing snapshots."
,
5
)
self
.
_m_selfmus
=
copy
(
musLoc
)
self
.
_mus
=
self
.
musPivot
self
.
_m_HFEparameterMap
=
copy
(
self
.
HFEngine
.
parameterMap
)
self
.
HFEngine
.
parameterMap
=
{
"F"
:
[
self
.
HFEngine
.
parameterMap
[
"F"
][
self
.
directionPivot
[
0
]]],
"B"
:
[
self
.
HFEngine
.
parameterMap
[
"B"
][
self
.
directionPivot
[
0
]]]}
def
addMarginalSamplePoints
(
self
,
musMarginal
:
paramList
,
*
args
,
**
kwargs
):
"""Add marginal sample points to reduced model."""
raise
RROMPyException
((
"Cannot add marginal samples to marginal "
"greedy reduced model."
))
def
setupApproxPivoted
(
self
,
mus
:
paramList
)
->
int
:
if
self
.
checkComputedApproxPivoted
():
return
-
1
RROMPyAssert
(
self
.
_mode
,
message
=
"Cannot setup approximant."
)
vbMng
(
self
,
"INIT"
,
"Setting up pivoted approximant."
,
10
)
idx
,
sizes
,
emptyCores
=
self
.
_preSetupApproxPivoted
(
mus
)
pMat
,
Ps
,
Qs
,
req
,
musA
=
None
,
[],
[],
[],
None
if
len
(
idx
)
==
0
:
vbMng
(
self
,
"MAIN"
,
"Idling."
,
45
)
if
self
.
storeAllSamples
:
self
.
storeSamples
()
pL
,
pT
,
mT
=
recv
(
source
=
0
,
tag
=
poolRank
())
pMat
=
np
.
empty
((
pL
,
0
),
dtype
=
pT
)
musA
=
np
.
empty
((
0
,
self
.
mu0
.
shape
[
1
]),
dtype
=
mT
)
else
:
for
i
in
idx
:
self
.
muMargLoc
=
mus
[[
i
]]
vbMng
(
self
,
"MAIN"
,
"Building marginal model no. {} at "
"{}."
.
format
(
i
+
1
,
self
.
muMargLoc
[
0
]),
25
)
self
.
samplingEngine
.
resetHistory
()
self
.
trainedModel
=
None
self
.
verbosity
-=
5
self
.
samplingEngine
.
verbosity
-=
5
RationalInterpolant
.
setupApprox
(
self
)
self
.
verbosity
+=
5
self
.
samplingEngine
.
verbosity
+=
5
self
.
_mus
=
self
.
_m_selfmus
self
.
HFEngine
.
parameterMap
=
self
.
_m_HFEparameterMap
del
self
.
_m_selfmus
,
self
.
_m_HFEparameterMap
if
self
.
storeAllSamples
:
self
.
storeSamples
(
i
+
self
.
_nmusOld
)
pMat
,
req
,
musA
=
self
.
_localPivotedResult
(
pMat
,
req
,
emptyCores
,
musA
)
Ps
+=
[
copy
(
self
.
trainedModel
.
data
.
P
)]
Qs
+=
[
copy
(
self
.
trainedModel
.
data
.
Q
)]
if
not
self
.
matchState
and
self
.
autoCollapse
:
Ps
[
-
1
]
.
postmultiplyTensorize
(
pMat
.
T
)
del
self
.
muMargLoc
for
r
in
req
:
r
.
wait
()
if
not
self
.
matchState
and
self
.
autoCollapse
:
pMat
=
pMat
[:,
:
0
]
self
.
_postSetupApproxPivoted
(
musA
,
pMat
,
Ps
,
Qs
,
sizes
)
vbMng
(
self
,
"DEL"
,
"Done setting up pivoted approximant."
,
10
)
return
0
class
RationalInterpolantPivotedGreedyPoleMatch
(
RationalInterpolantPivotedGreedyBase
,
GenericPivotedGreedyApproximantPoleMatch
,
RationalInterpolantPivotedPoleMatch
):
"""
ROM pivoted greedy rational interpolant computation for parametric
problems (with pole matching).
Args:
HFEngine: HF problem solver.
mu0(optional): Default parameter. Defaults to 0.
directionPivot(optional): Pivot components. Defaults to [0].
approxParameters(optional): Dictionary containing values for main
parameters of approximant. Recognized keys are:
- 'POD': kind of snapshots orthogonalization; allowed values
include 0, 1/2, and 1; defaults to 1, i.e. POD;
- 'scaleFactorDer': scaling factors for derivative computation;
defaults to 'AUTO';
- 'matchState': whether to match the system state rather than the
system output; defaults to False;
- 'matchingWeight': weight for pole matching optimization; defaults
to 1;
- 'matchingShared': required ratio of marginal points to share
resonance; defaults to 1.;
- 'badPoleCorrection': strategy for correction of bad poles;
available values include 'ERASE', 'RATIONAL', and 'POLYNOMIAL';
defaults to 'ERASE';
- 'matchingWeightError': weight for pole matching optimization in
error estimation; defaults to 0;
- 'S': total number of pivot samples current approximant relies
upon;
- 'samplerPivot': pivot sample point generator;
- 'SMarginal': number of starting marginal samples;
- 'samplerMarginal': marginal sample point generator via sparse
grid;
- 'errorEstimatorKindMarginal': kind of marginal error estimator;
available values include 'LOOK_AHEAD' and 'LOOK_AHEAD_RECOVER';
defaults to 'NONE';
- 'polybasis': type of polynomial basis for pivot interpolation;
defaults to 'MONOMIAL';
- 'polybasisMarginal': type of polynomial basis for marginal
interpolation; allowed values include 'MONOMIAL_*',
'CHEBYSHEV_*', 'LEGENDRE_*', 'NEARESTNEIGHBOR', and
'PIECEWISE_LINEAR_*'; defaults to 'MONOMIAL';
- 'paramsMarginal': dictionary of parameters for marginal
interpolation; include:
. 'MMarginal': degree of marginal interpolant; defaults to
'AUTO', i.e. maximum allowed; not for 'NEARESTNEIGHBOR' or
'PIECEWISE_LINEAR_*';
. 'nNeighborsMarginal': number of marginal nearest neighbors;
defaults to 1; only for 'NEARESTNEIGHBOR';
. 'polydegreetypeMarginal': type of polynomial degree for
marginal; defaults to 'TOTAL'; not for 'NEARESTNEIGHBOR' or
'PIECEWISE_LINEAR_*';
. 'interpTolMarginal': tolerance for marginal interpolation;
defaults to None; not for 'NEARESTNEIGHBOR' or
'PIECEWISE_LINEAR_*';
. 'radialDirectionalWeightsMarginalAdapt': bounds for adaptive
rescaling of marginal radial basis weights; only for
radial basis.
- 'M': degree of rational interpolant numerator; defaults to
'AUTO', i.e. maximum allowed;
- 'N': degree of rational interpolant denominator; defaults to
'AUTO', i.e. maximum allowed;
- 'greedyTolMarginal': uniform error tolerance for marginal greedy
algorithm; defaults to 1e-1;
- 'maxIterMarginal': maximum number of marginal greedy steps;
defaults to 1e2;
- 'radialDirectionalWeights': radial basis weights for pivot
numerator; defaults to 1;
- 'radialDirectionalWeightsAdapt': bounds for adaptive rescaling of
radial basis weights; defaults to [-1, -1];
- 'radialDirectionalWeightsMarginal': radial basis weights for
marginal interpolant; defaults to 1;
- 'autoCollapse': whether to collapse trained reduced model as soon
as it is built; defaults to False;
- 'functionalSolve': strategy for minimization of denominator
functional; allowed values include 'NORM', 'DOMINANT',
'BARYCENTRIC[_NORM]', and 'BARYCENTRIC_AVERAGE' (check pdf in
main folder for explanation); defaults to 'NORM';
- 'interpTol': tolerance for pivot interpolation; defaults to None;
- 'QTol': tolerance for robust rational denominator management;
defaults to 0.
Defaults to empty dict.
verbosity(optional): Verbosity level. Defaults to 10.
Attributes:
HFEngine: HF problem solver.
mu0: Default parameter.
directionPivot: Pivot components.
mus: Array of snapshot parameters.
musPivot: Array of pivot snapshot parameters.
musMarginal: Array of marginal snapshot parameters.
approxParameters: Dictionary containing values for main parameters of
approximant. Recognized keys are in parameterList.
parameterListSoft: Recognized keys of soft approximant parameters:
- 'POD': kind of snapshots orthogonalization;
- 'scaleFactorDer': scaling factors for derivative computation;
- 'matchState': whether to match the system state rather than the
system output;
- 'matchingWeight': weight for pole matching optimization;
- 'matchingShared': required ratio of marginal points to share
resonance;
- 'badPoleCorrection': strategy for correction of bad poles;
- 'matchingWeightError': weight for pole matching optimization in
error estimation;
- 'errorEstimatorKindMarginal': kind of marginal error estimator;
- 'polybasis': type of polynomial basis for pivot interpolation;
- 'polybasisMarginal': type of polynomial basis for marginal
interpolation;
- 'paramsMarginal': dictionary of parameters for marginal
interpolation; include:
. 'MMarginal': degree of marginal interpolant;
. 'nNeighborsMarginal': number of marginal nearest neighbors;
. 'polydegreetypeMarginal': type of polynomial degree for
marginal;
. 'interpTolMarginal': tolerance for marginal interpolation;
. 'radialDirectionalWeightsMarginalAdapt': bounds for adaptive
rescaling of marginal radial basis weights.
- 'M': degree of rational interpolant numerator;
- 'N': degree of rational interpolant denominator;
- 'greedyTolMarginal': uniform error tolerance for marginal greedy
algorithm;
- 'maxIterMarginal': maximum number of marginal greedy steps;
- 'radialDirectionalWeights': radial basis weights for pivot
numerator;
- 'radialDirectionalWeightsAdapt': bounds for adaptive rescaling of
radial basis weights;
- 'radialDirectionalWeightsMarginal': radial basis weights for
marginal interpolant;
- 'autoCollapse': whether to collapse trained reduced model as soon
as it is built;
- 'functionalSolve': strategy for minimization of denominator
functional;
- 'interpTol': tolerance for pivot interpolation;
- 'QTol': tolerance for robust rational denominator management.
parameterListCritical: Recognized keys of critical approximant
parameters:
- 'S': total number of pivot samples current approximant relies
upon;
- 'samplerPivot': pivot sample point generator;
- 'SMarginal': total number of marginal samples current approximant
relies upon;
- 'samplerMarginal': marginal sample point generator via sparse
grid.
verbosity: Verbosity level.
POD: Kind of snapshots orthogonalization.
scaleFactorDer: Scaling factors for derivative computation.
matchState: Whether to match the system state rather than the system
output.
matchingWeight: Weight for pole matching optimization.
matchingShared: Required ratio of marginal points to share resonance.
badPoleCorrection: Strategy for correction of bad poles.
matchingWeightError: Weight for pole matching optimization in error
estimation.
S: Total number of pivot samples current approximant relies upon.
samplerPivot: Pivot sample point generator.
SMarginal: Total number of marginal samples current approximant relies
upon.
samplerMarginal: Marginal sample point generator via sparse grid.
errorEstimatorKindMarginal: Kind of marginal error estimator.
polybasis: Type of polynomial basis for pivot interpolation.
polybasisMarginal: Type of polynomial basis for marginal interpolation.
paramsMarginal: Dictionary of parameters for marginal interpolation.
M: Degree of rational interpolant numerator.
N: Degree of rational interpolant denominator.
greedyTolMarginal: Uniform error tolerance for marginal greedy
algorithm.
maxIterMarginal: Maximum number of marginal greedy steps.
radialDirectionalWeights: Radial basis weights for pivot numerator.
radialDirectionalWeightsAdapt: Bounds for adaptive rescaling of radial
basis weights.
radialDirectionalWeightsMarginal: Radial basis weights for marginal
interpolant.
autoCollapse: Whether to collapse trained reduced model as soon as it
is built.
functionalSolve: Strategy for minimization of denominator functional.
interpTol: Tolerance for pivot interpolation.
QTol: Tolerance for robust rational denominator management.
muBounds: list of bounds for pivot parameter values.
muBoundsMarginal: list of bounds for marginal 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.
"""
Event Timeline
Log In to Comment