Page MenuHomec4science

rb_centered_2d.py
No OneTemporary

File Metadata

Created
Sat, Dec 28, 07:01

rb_centered_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 RBCentered as RBC
def test_R():
mu = [5.5, 7.5]
mu0 = [5., 7.]
solver = matrixRandom()
uh = solver.solve(mu)[0]
uhN = solver.norm(uh)
params = {"POD": True, "S": 10}
approx = RBC(solver, mu0, params, verbosity = 0)
approx.setupApprox()
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(uhN, uhNP, rtol = 1e-1)
assert np.isclose(errNP / uhNP, 0., atol = 1e-1)
def test_moments():
mu0 = [2 + .5j, 3]
solver = matrixRandom()
params = {"POD": True, "S": 10}
approx = RBC(solver, mu0, params, verbosity = 0)
approx.setupApprox()
assert np.isclose(approx.normErr(mu0)[0], 0., atol = 1e-10)
def test_load_copy(capsys):
mu = [1.5, 3. + 1j]
mu0 = [2 + .5j, 3]
solver = matrixRandom()
params = {"POD": True, "S": 10}
approx1 = RBC(solver, mu0, params, verbosity = 100)
approx1.setupApprox()
err1 = approx1.normErr(mu)[0]
out, err = capsys.readouterr()
assert "Solving HF model for mu =" in out
assert len(err) == 0
approx2 = RBC(solver, mu0, params, verbosity = 100)
approx2.setTrainedModel(approx1.trainedModel)
approx2.setHF(mu, approx1.uHF)
err2 = approx2.normErr(mu)[0]
out, err = capsys.readouterr()
assert "Solving HF model for mu =" not in out
assert len(err) == 0
assert np.isclose(err1, err2, rtol = 1e-10)

Event Timeline