Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F78505796
reduced_basis_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
Wed, Aug 21, 07:26
Size
8 KB
Mime Type
text/x-python
Expires
Fri, Aug 23, 07:26 (1 d, 22 h)
Engine
blob
Format
Raw Data
Handle
20056446
Attached To
R6746 RationalROMPy
reduced_basis_greedy.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
copy
import
deepcopy
as
copy
from
.generic_greedy_approximant
import
GenericGreedyApproximant
from
rrompy.reduction_methods.standard
import
ReducedBasis
from
rrompy.utilities.base.types
import
DictAny
,
HFEng
,
paramVal
from
rrompy.utilities.base
import
verbosityManager
as
vbMng
from
rrompy.utilities.numerical
import
dot
from
rrompy.utilities.exception_manager
import
RROMPyWarning
,
RROMPyAssert
__all__
=
[
'ReducedBasisGreedy'
]
class
ReducedBasisGreedy
(
GenericGreedyApproximant
,
ReducedBasis
):
"""
ROM greedy RB approximant computation for parametric problems.
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': number of starting training points;
- 'sampler': sample point generator;
- 'greedyTol': uniform error tolerance for greedy algorithm;
defaults to 1e-2;
- 'collinearityTol': collinearity tolerance for greedy algorithm;
defaults to 0.;
- 'interactive': whether to interactively terminate greedy
algorithm; defaults to False;
- 'maxIter': maximum number of greedy steps; defaults to 1e2;
- 'refinementRatio': ratio of test points to be exhausted before
test set refinement; defaults to 0.2;
- 'nTestPoints': number of test points; defaults to 5e2;
- 'trainSetGenerator': training sample points generator; defaults
to sampler.
Defaults to empty dict.
approx_state(optional): Whether to approximate state. Defaults and must
be True.
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.
- 'greedyTol': uniform error tolerance for greedy algorithm;
- 'collinearityTol': collinearity tolerance for greedy algorithm;
- 'interactive': whether to interactively terminate greedy
algorithm;
- 'maxIter': maximum number of greedy steps;
- 'refinementRatio': ratio of test points to be exhausted before
test set refinement;
- 'nTestPoints': number of test points;
- 'trainSetGenerator': training sample points generator.
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 test points.
sampler: Sample point generator.
greedyTol: uniform error tolerance for greedy algorithm.
collinearityTol: Collinearity tolerance for greedy algorithm.
interactive: whether to interactively terminate greedy algorithm.
maxIter: maximum number of greedy steps.
refinementRatio: ratio of training points to be exhausted before
training set refinement.
nTestPoints: number of starting training points.
trainSetGenerator: training sample points generator.
muBounds: list of bounds for parameter values.
samplingEngine: Sampling engine.
estimatorNormEngine: Engine for estimator norm computation.
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.
As: List of sparse matrices (in CSC format) representing coefficients
of linear system matrix.
bs: List of numpy vectors representing coefficients of linear system
RHS.
ARBs: List of sparse matrices (in CSC format) representing coefficients
of compressed linear system matrix.
bRBs: List of numpy vectors representing coefficients of compressed
linear system RHS.
"""
def
__init__
(
self
,
HFEngine
:
HFEng
,
mu0
:
paramVal
=
None
,
approxParameters
:
DictAny
=
{},
approx_state
:
bool
=
True
,
verbosity
:
int
=
10
,
timestamp
:
bool
=
True
):
if
not
approx_state
:
RROMPyWarning
(
"Overriding approx_state to True."
)
self
.
_preInit
()
self
.
_addParametersToList
([],
[],
toBeExcluded
=
[
"R"
,
"PODTolerance"
])
super
()
.
__init__
(
HFEngine
=
HFEngine
,
mu0
=
mu0
,
approxParameters
=
approxParameters
,
approx_state
=
True
,
verbosity
=
verbosity
,
timestamp
=
timestamp
)
self
.
_postInit
()
@property
def
R
(
self
):
"""Value of R."""
self
.
_R
=
self
.
_S
return
self
.
_R
@R.setter
def
R
(
self
,
R
):
RROMPyWarning
((
"R is used just to simplify inheritance, and its value "
"cannot be changed from that of S."
))
@property
def
PODTolerance
(
self
):
"""Value of PODTolerance."""
self
.
_PODTolerance
=
-
1
return
self
.
_PODTolerance
@PODTolerance.setter
def
PODTolerance
(
self
,
PODTolerance
):
RROMPyWarning
((
"PODTolerance is used just to simplify inheritance, "
"and its value cannot be changed from -1."
))
def
setupApprox
(
self
,
plotEst
:
bool
=
False
):
"""Compute RB projection matrix."""
if
self
.
checkComputedApprox
():
return
RROMPyAssert
(
self
.
_mode
,
message
=
"Cannot setup approximant."
)
vbMng
(
self
,
"INIT"
,
"Setting up {}."
.
format
(
self
.
name
()),
5
)
self
.
greedy
(
plotEst
)
vbMng
(
self
,
"INIT"
,
"Computing projection matrix."
,
7
)
pMat
=
self
.
samplingEngine
.
samples
.
data
pMatEff
=
dot
(
self
.
HFEngine
.
C
,
pMat
)
if
self
.
trainedModel
is
None
:
self
.
trainedModel
=
self
.
tModelType
()
self
.
trainedModel
.
verbosity
=
self
.
verbosity
self
.
trainedModel
.
timestamp
=
self
.
timestamp
datadict
=
{
"mu0"
:
self
.
mu0
,
"projMat"
:
pMatEff
,
"scaleFactor"
:
self
.
scaleFactor
,
"rescalingExp"
:
self
.
HFEngine
.
rescalingExp
}
data
=
self
.
initializeModelData
(
datadict
)[
0
]
ARBs
,
bRBs
=
self
.
assembleReducedSystem
(
pMat
)
data
.
affinePoly
=
self
.
HFEngine
.
affinePoly
self
.
HFEngine
.
buildA
()
self
.
HFEngine
.
buildb
()
data
.
thAs
,
data
.
thbs
=
self
.
HFEngine
.
thAs
,
self
.
HFEngine
.
thbs
self
.
trainedModel
.
data
=
data
else
:
self
.
trainedModel
=
self
.
trainedModel
Sold
=
self
.
trainedModel
.
data
.
projMat
.
shape
[
1
]
ARBs
,
bRBs
=
self
.
assembleReducedSystem
(
pMat
[:,
Sold
:],
pMat
[:,
:
Sold
])
self
.
trainedModel
.
data
.
projMat
=
copy
(
pMatEff
)
self
.
trainedModel
.
data
.
mus
=
copy
(
self
.
mus
)
self
.
trainedModel
.
data
.
ARBs
=
ARBs
self
.
trainedModel
.
data
.
bRBs
=
bRBs
vbMng
(
self
,
"DEL"
,
"Done computing projection matrix."
,
7
)
self
.
trainedModel
.
data
.
approxParameters
=
copy
(
self
.
approxParameters
)
vbMng
(
self
,
"DEL"
,
"Done setting up approximant."
,
5
)
Event Timeline
Log In to Comment