Page MenuHomec4science

reduced_basis_1d.py
No OneTemporary

File Metadata

Created
Tue, Apr 30, 12:07

reduced_basis_1d.py

# Copyright (C) 2018-2020 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 import ReducedBasis as RB
from rrompy.parameter.parameter_sampling import (QuadratureSampler as QS,
ManualSampler as MS)
from rrompy.parameter import checkParameterList
def test_LS():
solver = matrixFFT()
params = {"POD": True, "R": 5, "S": 10,
"sampler": QS([1., 7.], "CHEBYSHEV")}
approx = RB(solver, 4., approxParameters = params, verbosity = 0)
approx.setupApprox()
for mu in approx.mus:
assert not np.isclose(approx.normErr(mu)[0], 0., atol = 1e-7)
approx.POD = False
approx.setupApprox()
for mu in approx.mus[approx.R :]:
assert not np.isclose(approx.normErr(mu)[0], 0., atol = 1e-3)
def test_interp():
solver = matrixFFT()
params = {"POD": False, "S": 10, "sampler": QS([1., 7.], "CHEBYSHEV")}
approx = RB(solver, 4., approxParameters = params, verbosity = 0)
approx.setupApprox()
for mu in approx.mus:
assert np.isclose(approx.normErr(mu)[0], 0., atol = 1e-7)
def test_hermite():
mu = 1.5
solver = matrixFFT()
sampler0 = QS([1., 7.], "CHEBYSHEV")
points = checkParameterList(np.tile(sampler0.generatePoints(4)(0), 3))
params = {"POD": True, "S": 12, "sampler": MS([1., 7.], points = points)}
approx = RB(solver, 4., approxParameters = params, verbosity = 0)
approx.setupApprox()
for mu in approx.mus:
assert np.isclose(approx.normErr(mu)[0], 0., atol = 1e-8)

Event Timeline