Page MenuHomec4science

rational_interpolant.py
No OneTemporary

File Metadata

Created
Thu, Nov 7, 04:02

rational_interpolant.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 matrix_fft import matrixFFT
from rrompy.reduction_methods.distributed import RationalInterpolant as RI
from rrompy.parameter.parameter_sampling import (QuadratureSampler as QS,
ManualSampler as MS)
def test_monomials(capsys):
mu = 1.5
solver = matrixFFT()
params = {"POD": False, "M": 9, "N": 9, "S": 10, "robustTol": 1e-6,
"interpRcond": 1e-3, "polybasis": "MONOMIAL",
"sampler": QS([1.5, 6.5], "UNIFORM")}
approx = RI(solver, 4., params, verbosity = 0)
approx.setupApprox()
out, err = capsys.readouterr()
assert (("poorly conditioned.\nReducing N from 9 to" in out)
and ("eigenvalues below tolerance. Reducing N from" in out))
assert len(err) == 0
assert np.isclose(approx.normErr(mu), .00773727, rtol = 1e-3)
def test_well_cond():
mu = 1.5
solver = matrixFFT()
params = {"POD": True, "M": 9, "N": 9, "S": 10, "robustTol": 1e-14,
"interpRcond": 1e-10, "polybasis": "CHEBYSHEV",
"sampler": QS([1., 7.], "CHEBYSHEV")}
approx = RI(solver, 4., params, verbosity = 0)
approx.setupApprox()
for mu in approx.mus:
assert np.isclose(approx.normErr(mu), 0., atol = 1e-8)
poles = approx.getPoles()
for lambda_ in np.arange(1, 8):
assert np.isclose(np.min(np.abs(poles - lambda_)), 0., atol = 1e-4)
def test_hermite():
mu = 1.5
solver = matrixFFT()
sampler0 = QS([1., 7.], "CHEBYSHEV")
points = np.tile(sampler0.generatePoints(4)[0], 3)
params = {"POD": True, "M": 11, "N": 11, "S": 12, "polybasis": "CHEBYSHEV",
"sampler": MS([1., 7.], points = points)}
approx = RI(solver, 4., params, verbosity = 0)
approx.setupApprox()
for mu in approx.mus:
assert np.isclose(approx.normErr(mu), 0., atol = 1e-8)
poles = approx.getPoles()
for lambda_ in np.arange(1, 8):
assert np.isclose(np.min(np.abs(poles - lambda_)), 0., atol = 1e-4)
#_multistorage

Event Timeline