Page MenuHomec4science

sampling_engine_distributed_pod.py
No OneTemporary

File Metadata

Created
Sat, May 4, 08:17

sampling_engine_distributed_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_distributed import SamplingEngineDistributed
from rrompy.utilities.base.types import Np1D
from rrompy.utilities.base import verbosityDepth
__all__ = ['SamplingEngineDistributedPOD']
class SamplingEngineDistributedPOD(SamplingEngineDistributed):
"""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):
idxMax = np.max(idxs) + 1
sampleBase = super().preprocesssamples(np.arange(idxMax))
RPODBase = self.RPOD[: idxMax, idxs]
return sampleBase.dot(RPODBase)
def postprocessu(self, u:Np1D, overwrite : bool = False):
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[:, : 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 preallocateSamples(self, u:Np1D, mu:np.complex, 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