Page MenuHomec4science

sampling_engine_linear_pod_naive.py
No OneTemporary

File Metadata

Created
Wed, Aug 7, 19:30

sampling_engine_linear_pod_naive.py

# 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.sampling.base.pod_engine import PODEngine
from .sampling_engine_linear import SamplingEngineLinear
from rrompy.utilities.base.types import Np1D, paramVal, sampList
from rrompy.utilities.base import verbosityDepth
__all__ = ['SamplingEngineLinearPODNaive']
class SamplingEngineLinearPODNaive(SamplingEngineLinear):
"""HERE"""
def resetHistory(self):
super().resetHistory()
self.RPOD = None
def popSample(self):
if hasattr(self, "nsamples") and self.nsamples > 1:
self.RPOD = self.RPOD[: -1, : -1]
super().popSample()
@property
def HFEngine(self):
"""Value of HFEngine. Its assignment resets history."""
return self._HFEngine
@HFEngine.setter
def HFEngine(self, HFEngine):
self._HFEngine = HFEngine
self.resetHistory()
self.PODEngine = PODEngine(self._HFEngine)
def preprocesssamples(self, idxs:Np1D) -> sampList:
idxMax = np.max(idxs) + 1
sampleBase = super().preprocesssamples(np.arange(idxMax))
RPODBase = self.RPOD[: idxMax, idxs]
return sampleBase.dot(RPODBase)
def postprocessu(self, u:sampList, overwrite : bool = False) -> Np1D:
if self.verbosity >= 10:
verbosityDepth("INIT", "Starting orthogonalization.",
timestamp = self.timestamp)
ns = self.nsamples
if ns == 0:
u, r, _ = self.PODEngine.GS(u, np.empty((0, 0)))
r = r[0]
else:
u, r, _ = self.PODEngine.GS(u, self.samples(np.arange(ns)), ns)
if overwrite:
self.RPOD[: ns + 1, ns] = r
else:
if ns == 0:
self.RPOD = r.reshape((1, 1))
else:
self.RPOD=np.block([[ self.RPOD, r[:-1, None]],
[np.zeros((1, ns)), r[-1]]])
if self.verbosity >= 10:
verbosityDepth("DEL", "Done orthogonalizing.",
timestamp = self.timestamp)
return u
def postprocessuBulk(self, u:sampList) -> sampList:
if self.verbosity >= 10:
verbosityDepth("INIT", "Starting orthogonalization.",
timestamp = self.timestamp)
u, self.RPOD = self.PODEngine.QRHouseholder(u)
if self.verbosity >= 10:
verbosityDepth("DEL", "Done orthogonalizing.",
timestamp = self.timestamp)
return u
def preallocateSamples(self, u:Np1D, mu:paramVal, n:int):
super().preallocateSamples(u, mu, n)
r = self.RPOD
self.RPOD = np.zeros((n, n), dtype = u.dtype)
self.RPOD[0, 0] = r[0, 0]

Event Timeline