Page MenuHomec4science

sampling_engine_standard_pod.py
No OneTemporary

File Metadata

Created
Sat, May 4, 20:57

sampling_engine_standard_pod.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_standard import SamplingEngineStandard
from rrompy.utilities.base.types import Np1D, paramVal, sampList
from rrompy.utilities.base import verbosityManager as vbMng
from rrompy.sampling import sampleList, emptySampleList
__all__ = ['SamplingEngineStandardPOD']
class SamplingEngineStandardPOD(SamplingEngineStandard):
"""HERE"""
def resetHistory(self):
super().resetHistory()
self.samples_full = emptySampleList()
self.RPOD = np.zeros((0, 0), dtype = np.complex)
def popSample(self):
if hasattr(self, "nsamples") and self.nsamples > 1:
self.RPOD = self.RPOD[: -1, : -1]
self.samples_full.pop()
super().popSample()
@property
def HFEngine(self):
"""Value of HFEngine. Its assignment resets history."""
return self._HFEngine
@HFEngine.setter
def HFEngine(self, HFEngine):
SamplingEngineStandard.HFEngine.fset(self, HFEngine)
self.PODEngine = PODEngine(self._HFEngine)
def preprocesssamples(self, idxs:Np1D) -> sampList:
if self.samples_full is None or len(self.samples_full) == 0: return
return self.samples_full(idxs)
def setsample(self, u:sampList, overwrite : bool = False):
super().setsample(u, overwrite)
if overwrite:
self.samples_full[self.nsamples] = u
else:
if self.nsamples == 0:
self.samples_full = sampleList(u)
else:
self.samples_full.append(u)
def postprocessu(self, u:sampList, overwrite : bool = False):
if overwrite:
self.samples_full[self.nsamples] = u
else:
if self.nsamples == 0:
self.samples_full = sampleList(u)
else:
self.samples_full.append(u)
vbMng(self, "INIT", "Starting orthogonalization.", 20)
u, r, _ = self.PODEngine.GS(u, self.samples,
is_state = self.sample_state)
self.RPOD = np.pad(self.RPOD, ((0, 1), (0, 1)), 'constant')
self.RPOD[:, -1] = r
vbMng(self, "DEL", "Done orthogonalizing.", 20)
super().setsample(u, overwrite)
def postprocessuBulk(self):
vbMng(self, "INIT", "Starting orthogonalization.", 10)
u, self.RPOD = self.PODEngine.generalizedQR(self.samples_full,
is_state = self.sample_state)
vbMng(self, "DEL", "Done orthogonalizing.", 10)
self.samples = sampleList(u)
def preallocateSamples(self, u:Np1D, mu:paramVal, n:int):
super().preallocateSamples(u, mu, n)
self.samples_full.reset((u.shape[0], n), u.dtype)
self.samples_full[0] = u

Event Timeline