Page MenuHomec4science

rational_pade_2d.py
No OneTemporary

File Metadata

Created
Wed, Jun 5, 18:47

rational_pade_2d.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_random import matrixRandom
from rrompy.reduction_methods.centered import RationalPade as RP
def test_rho():
mu = [5.5, 7.5]
mu0 = [5., 7.]
solver = matrixRandom()
uh = solver.solve(mu)[0]
params = {"POD": False, "M": 3, "N": 3, "S": 10, "robustTol": 1e-6}
approx = RP(solver, mu0, params, verbosity = 0)
approx.setupApprox()
uhP1 = approx.getApprox(mu)[0]
errP = approx.getErr(mu)[0]
errNP = approx.normErr(mu)[0]
myerrP = uhP1 - uh
assert np.allclose(np.abs(errP - myerrP), 0., rtol = 1e-3)
assert np.isclose(solver.norm(errP), errNP, rtol = 1e-3)
resP = approx.getRes(mu)[0]
resNP = approx.normRes(mu)
assert np.isclose(solver.norm(resP), resNP, rtol = 1e-3)
assert np.allclose(np.abs(resP - (solver.b(mu) - solver.A(mu).dot(uhP1))),
0., rtol = 1e-3)
def test_E_warn(capsys):
mu = [5.5, 7.5]
mu0 = [5., 7.]
solver = matrixRandom()
uh = solver.solve(mu)[0]
params = {"POD": True, "M": 3, "N": 4, "S": 10}
approx = RP(solver, mu0, params, verbosity = 0)
approx.setupApprox()
out, err = capsys.readouterr()
assert "Prescribed E is too small. Decreasing M" not in out
assert "Prescribed E is too small. Decreasing N" in out
assert len(err) == 0
uhP = approx.getApprox(mu)[0]
uhNP = approx.normApprox(mu)[0]
errP = approx.getErr(mu)[0]
errNP = approx.normErr(mu)[0]
assert np.allclose(np.abs(errP - (uhP - uh)), 0., rtol = 1e-3)
assert np.isclose(errNP / uhNP, 1.41336e-2, rtol = 1e-1)

Event Timeline