Page MenuHomec4science

sampling_engine_standard_pod.py
No OneTemporary

File Metadata

Created
Thu, Jun 6, 00:00

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/>.
#
from copy import deepcopy as copy
import numpy as np
from scipy.sparse import block_diag
from .pod_engine import PODEngine
from .sampling_engine_standard import SamplingEngineStandard
from rrompy.utilities.base.types import (Np1D, Np2D, TupleAny, DictAny, Any,
paramVal, sampList)
from rrompy.utilities.base import verbosityManager as vbMng
from rrompy.sampling import sampleList, emptySampleList
__all__ = ['SamplingEngineStandardPOD']
class SamplingEngineStandardPOD(SamplingEngineStandard):
@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)
@property
def feature_keys(self) -> TupleAny:
return super().feature_keys + ["samples_ortho", "RPOD"]
@property
def feature_vals(self) -> DictAny:
vals = super().feature_vals
vals["samples_ortho"] = self.samples_ortho
vals["RPOD"] = self.RPOD
return vals
def _mergeFeature(self, name:str, value:Any):
if name == "samples_ortho":
self.samples_ortho.append(value)
elif name == "RPOD":
self.RPOD = block_diag((self.RPOD, value), "csc")
else:
super()._mergeFeature(name, value)
@property
def projectionMatrix(self) -> Np2D:
return self.samples_ortho.data
def resetHistory(self):
super().resetHistory()
self.samples_ortho = emptySampleList()
self.RPOD = np.zeros((0, 0), dtype = np.complex)
def setsample_ortho(self, u:sampList, overwrite : bool = False):
if overwrite:
self.samples_ortho[self.nsamples] = u
else:
if self.nsamples == 0:
self.samples_ortho = sampleList(u)
else:
self.samples_ortho.append(u)
def popSample(self):
if hasattr(self, "nsamples") and self.nsamples > 1:
self.RPOD = self.RPOD[: -1, : -1]
self.samples_ortho.pop()
super().popSample()
def preallocateSamples(self, u:Np1D, mu:paramVal, n:int):
super().preallocateSamples(u, mu, n)
self.samples_ortho.reset((u.shape[0], n), u.dtype)
def postprocessu(self, u:sampList, overwrite : bool = False):
self.setsample(u, overwrite)
vbMng(self, "INIT", "Starting orthogonalization.", 20)
u, r, _ = self.PODEngine.GS(u, self.samples_ortho,
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)
self.setsample_ortho(u, overwrite)
def postprocessuBulk(self):
vbMng(self, "INIT", "Starting orthogonalization.", 10)
samples_ortho, self.RPOD = self.PODEngine.generalizedQR(self.samples,
is_state = self.sample_state)
vbMng(self, "DEL", "Done orthogonalizing.", 10)
nsamples, self.nsamples = self.nsamples, 0
self.setsample_ortho(samples_ortho)
self.nsamples = nsamples

Event Timeline