Page MenuHomec4science

reduced_basis_utils.py
No OneTemporary

File Metadata

Created
Sat, Sep 21, 17:31

reduced_basis_utils.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.utilities.base.types import (Np1D, Np2D, Tuple, List, ListAny,
sampList)
from rrompy.utilities.numerical import hashIdxToDerivative as hashI
from rrompy.utilities.exception_manager import RROMPyAssert
from rrompy.sampling import sampleList
__all__ = ['projectAffineDecomposition']
def projectAffineDecomposition(As:List[Np2D], bs:List[Np1D], pMat:sampList,
ARBsOld : List[Np2D] = None,
bRBsOld : List[Np1D] = None,
pMatOld : sampList = None)\
-> Tuple[List[Np2D], List[Np1D]]:
"""Project affine decomposition of linear system onto basis."""
RROMPyAssert((ARBsOld is None, bRBsOld is None),
(pMatOld is None, pMatOld is None),
"Old affine projected terms")
if isinstance(pMat, (sampleList,)): pMat = pMat.data
pMatH = pMat.T.conj()
ARBs = [None] * len(As)
bRBs = [None] * len(bs)
if pMatOld is None:
for j in range(max(len(As), len(bs))):
if j < len(As):
ARBs[j] = pMatH.dot(As[j].dot(pMat))
if j < len(bs):
bRBs[j] = pMatH.dot(bs[j])
else:
RROMPyAssert((len(ARBsOld), len(bRBsOld)), (len(As), len(bs)),
"Old affine projected terms")
if isinstance(pMatOld, (sampleList,)): pMatOld = pMatOld.data
pMatOldH = pMatOld.T.conj()
Sold = pMatOld.shape[1]
Snew = pMat.shape[1]
for j in range(max(len(As), len(bs))):
if j < len(As):
ARBs[j] = np.empty((Sold + Snew, Sold + Snew),
dtype = ARBsOld[j].dtype)
ARBs[j][: Sold, : Sold] = ARBsOld[j]
ARBs[j][: Sold, Sold :] = pMatOldH.dot(As[j].dot(pMat))
ARBs[j][Sold :, : Sold] = pMatH.dot(As[j].dot(pMatOld))
ARBs[j][Sold :, Sold :] = pMatH.dot(As[j].dot(pMat))
if j < len(bs):
bRBs[j] = np.empty((Sold + Snew), dtype = bRBsOld[j].dtype)
bRBs[j][: Sold] = bRBsOld[j]
bRBs[j][Sold :] = pMatH.dot(bs[j])
return ARBs, bRBs

Event Timeline