diff --git a/setup.cfg b/setup.cfg index a25ec20..a95dc41 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,10 +1,10 @@ [aliases] test=pytest [tool:pytest] -addopts = --verbose --tb=short +addopts = --tb=short python_files = tests/*/*.py filterwarnings = error ignore::DeprecationWarning ignore::FutureWarning diff --git a/tests/test_2_hfengines/fracture.py b/tests/hfengines/fracture.py similarity index 100% rename from tests/test_2_hfengines/fracture.py rename to tests/hfengines/fracture.py diff --git a/tests/test_2_hfengines/helmholtz_elasticity.py b/tests/hfengines/helmholtz_elasticity.py similarity index 100% rename from tests/test_2_hfengines/helmholtz_elasticity.py rename to tests/hfengines/helmholtz_elasticity.py diff --git a/tests/test_2_hfengines/helmholtz_external.py b/tests/hfengines/helmholtz_external.py similarity index 100% rename from tests/test_2_hfengines/helmholtz_external.py rename to tests/hfengines/helmholtz_external.py diff --git a/tests/test_2_hfengines/helmholtz_internal.py b/tests/hfengines/helmholtz_internal.py similarity index 100% rename from tests/test_2_hfengines/helmholtz_internal.py rename to tests/hfengines/helmholtz_internal.py diff --git a/tests/test_2_hfengines/laplace.py b/tests/hfengines/laplace.py similarity index 100% rename from tests/test_2_hfengines/laplace.py rename to tests/hfengines/laplace.py diff --git a/tests/test_2_hfengines/linear_elasticity.py b/tests/hfengines/linear_elasticity.py similarity index 100% rename from tests/test_2_hfengines/linear_elasticity.py rename to tests/hfengines/linear_elasticity.py diff --git a/tests/test_2_hfengines/matrix.py b/tests/hfengines/matrix.py similarity index 100% rename from tests/test_2_hfengines/matrix.py rename to tests/hfengines/matrix.py diff --git a/tests/test_2_hfengines/rod.xml b/tests/hfengines/rod.xml similarity index 100% rename from tests/test_2_hfengines/rod.xml rename to tests/hfengines/rod.xml diff --git a/tests/test_2_hfengines/rod_3d.py b/tests/hfengines/rod_3d.py similarity index 96% rename from tests/test_2_hfengines/rod_3d.py rename to tests/hfengines/rod_3d.py index 164c56b..528e0f1 100644 --- a/tests/test_2_hfengines/rod_3d.py +++ b/tests/hfengines/rod_3d.py @@ -1,37 +1,37 @@ # 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 . # import fenics as fen from rrompy.hfengines.vector_linear_problem import ( LinearElasticityProblemEngine) def rod3Dsolver(): - mesh = fen.Mesh("./tests/test_2_hfengines/rod.xml") + mesh = fen.Mesh("./tests/hfengines/rod.xml") rho_ = 1e3 nu = .45 E = 1e6 g = 1e3 solver = LinearElasticityProblemEngine(verbosity = 0) solver.V = fen.VectorFunctionSpace(mesh, "P", 1) solver.lambda_ = E * nu / (1. + nu) / (1. - 2 * nu) solver.mu_ = E / (1. + nu) solver.forcingTerm = [fen.Constant((0., - rho_ * g / E, 0.)), fen.Constant((0., 0., 0.))] solver.DirichletBoundary = lambda x, on_b: on_b and fen.near(x[2], 0.) solver.NeumannBoundary = "REST" return solver diff --git a/tests/test_3_reduction_methods_1D/matrix_fft.py b/tests/reduction_methods_1D/matrix_fft.py similarity index 100% rename from tests/test_3_reduction_methods_1D/matrix_fft.py rename to tests/reduction_methods_1D/matrix_fft.py diff --git a/tests/test_3_reduction_methods_1D/rational_interpolant_1d.py b/tests/reduction_methods_1D/rational_interpolant_1d.py similarity index 100% rename from tests/test_3_reduction_methods_1D/rational_interpolant_1d.py rename to tests/reduction_methods_1D/rational_interpolant_1d.py diff --git a/tests/test_3_reduction_methods_1D/rational_interpolant_greedy_1d.py b/tests/reduction_methods_1D/rational_interpolant_greedy_1d.py similarity index 100% rename from tests/test_3_reduction_methods_1D/rational_interpolant_greedy_1d.py rename to tests/reduction_methods_1D/rational_interpolant_greedy_1d.py diff --git a/tests/test_3_reduction_methods_1D/rational_pade_1d.py b/tests/reduction_methods_1D/rational_pade_1d.py similarity index 100% rename from tests/test_3_reduction_methods_1D/rational_pade_1d.py rename to tests/reduction_methods_1D/rational_pade_1d.py diff --git a/tests/test_3_reduction_methods_1D/rb_centered_1d.py b/tests/reduction_methods_1D/rb_centered_1d.py similarity index 100% rename from tests/test_3_reduction_methods_1D/rb_centered_1d.py rename to tests/reduction_methods_1D/rb_centered_1d.py diff --git a/tests/test_3_reduction_methods_1D/rb_distributed_1d.py b/tests/reduction_methods_1D/rb_distributed_1d.py similarity index 100% rename from tests/test_3_reduction_methods_1D/rb_distributed_1d.py rename to tests/reduction_methods_1D/rb_distributed_1d.py diff --git a/tests/test_3_reduction_methods_1D/rb_distributed_greedy_1d.py b/tests/reduction_methods_1D/rb_distributed_greedy_1d.py similarity index 100% rename from tests/test_3_reduction_methods_1D/rb_distributed_greedy_1d.py rename to tests/reduction_methods_1D/rb_distributed_greedy_1d.py diff --git a/tests/test_4_reduction_methods_multiD/matrix_random.py b/tests/reduction_methods_multiD/matrix_random.py similarity index 100% rename from tests/test_4_reduction_methods_multiD/matrix_random.py rename to tests/reduction_methods_multiD/matrix_random.py diff --git a/tests/test_4_reduction_methods_multiD/rational_interpolant_2d.py b/tests/reduction_methods_multiD/rational_interpolant_2d.py similarity index 100% rename from tests/test_4_reduction_methods_multiD/rational_interpolant_2d.py rename to tests/reduction_methods_multiD/rational_interpolant_2d.py diff --git a/tests/test_4_reduction_methods_multiD/rational_pade_2d.py b/tests/reduction_methods_multiD/rational_pade_2d.py similarity index 100% rename from tests/test_4_reduction_methods_multiD/rational_pade_2d.py rename to tests/reduction_methods_multiD/rational_pade_2d.py diff --git a/tests/test_4_reduction_methods_multiD/rb_centered_2d.py b/tests/reduction_methods_multiD/rb_centered_2d.py similarity index 100% rename from tests/test_4_reduction_methods_multiD/rb_centered_2d.py rename to tests/reduction_methods_multiD/rb_centered_2d.py diff --git a/tests/test_4_reduction_methods_multiD/rb_distributed_2d.py b/tests/reduction_methods_multiD/rb_distributed_2d.py similarity index 100% rename from tests/test_4_reduction_methods_multiD/rb_distributed_2d.py rename to tests/reduction_methods_multiD/rb_distributed_2d.py diff --git a/tests/test_1_utilities/basic_routines.py b/tests/utilities/basic_routines.py similarity index 100% rename from tests/test_1_utilities/basic_routines.py rename to tests/utilities/basic_routines.py diff --git a/tests/test_1_utilities/fenics_const.py b/tests/utilities/fenics_const.py similarity index 100% rename from tests/test_1_utilities/fenics_const.py rename to tests/utilities/fenics_const.py diff --git a/tests/test_1_utilities/fenics_norms.py b/tests/utilities/fenics_norms.py similarity index 100% rename from tests/test_1_utilities/fenics_norms.py rename to tests/utilities/fenics_norms.py diff --git a/tests/test_1_utilities/parameter_sampling.py b/tests/utilities/parameter_sampling.py similarity index 100% rename from tests/test_1_utilities/parameter_sampling.py rename to tests/utilities/parameter_sampling.py diff --git a/tests/test_1_utilities/poly_fitting.py b/tests/utilities/poly_fitting.py similarity index 100% rename from tests/test_1_utilities/poly_fitting.py rename to tests/utilities/poly_fitting.py diff --git a/tests/test_1_utilities/radial_fitting.py b/tests/utilities/radial_fitting.py similarity index 94% rename from tests/test_1_utilities/radial_fitting.py rename to tests/utilities/radial_fitting.py index 1736734..e1cd8c7 100644 --- a/tests/test_1_utilities/radial_fitting.py +++ b/tests/utilities/radial_fitting.py @@ -1,131 +1,128 @@ # 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 . # import numpy as np from rrompy.utilities.poly_fitting import customFit from rrompy.utilities.poly_fitting.radial_basis import (radialGaussian, thinPlateSpline, multiQuadric, polybases, polyfitname, polydomcoeff, radialFunction, polyval, polyvander) from rrompy.parameter import checkParameterList def test_monomial_gaussian(): polyrbname = "MONOMIAL_GAUSSIAN" assert polyrbname in polybases fitname = polyfitname(polyrbname) domcoeff = polydomcoeff(5, polyrbname) assert fitname == "polyfit_gaussian" assert np.isclose(domcoeff, 1., rtol = 1e-5) directionalWeights = np.array([5.]) xSupp = checkParameterList(np.arange(-1, 3), 1)[0] cRBCoeffs = np.array([-1., 3., -3., 1., 1., 2., -.5]) cRB = radialFunction(directionalWeights = directionalWeights, - localBasis = "GAUSSIAN", globalBasis = "MONOMIAL", supportPoints = xSupp, localCoeffs = cRBCoeffs[: 4], globalCoeffs = cRBCoeffs[4 :]) ySupp = 1 + 2. * xSupp.data - .5 * xSupp.data ** 2. xx = np.linspace(-2., 3., 100) yy = polyval(checkParameterList(xx, 1)[0], cRB, polyrbname) yyman = 1. + 2. * xx - .5 * xx ** 2. for j, xc in enumerate(np.arange(-1, 3)): r2j = (5. * (xx - xc)) ** 2. rbj = radialGaussian(r2j) assert np.allclose(rbj, np.exp(-.5 * r2j)) yyman += cRB.localCoeffs[j] * rbj ySupp += cRB.localCoeffs[j] * radialGaussian((directionalWeights[0] * (xSupp.data - xc)) ** 2.) assert np.allclose(yy, yyman, atol = 1e-5) VanT = polyvander(xSupp, [2], polyrbname, directionalWeights = directionalWeights) ySupp = np.pad(ySupp.flatten(), (0, len(VanT) - len(xSupp)), "constant") out = customFit(VanT, ySupp) assert np.allclose(out, cRBCoeffs, atol = 1e-8) def test_legendre_thinplate(): polyrbname = "LEGENDRE_THINPLATE" assert polyrbname in polybases fitname = polyfitname(polyrbname) domcoeff = polydomcoeff(5, polyrbname) assert fitname == "legfit_thinplate" assert np.isclose(domcoeff, 63. / 8, rtol = 1e-5) directionalWeights = np.array([.5]) xSupp = checkParameterList(np.arange(-1, 3), 1)[0] cRBCoeffs = np.array([-1., 3., -3., 1., 1., 2., -.5]) cRB = radialFunction(directionalWeights = directionalWeights, - localBasis = "THINPLATE", globalBasis = "LEGENDRE", supportPoints = xSupp, localCoeffs = cRBCoeffs[: 4], globalCoeffs = cRBCoeffs[4 :]) ySupp = 1 + 2. * xSupp.data - .5 * (.5 * (3. * xSupp.data ** 2. - 1.)) xx = np.linspace(-2., 3., 100) yy = polyval(checkParameterList(xx, 1)[0], cRB, polyrbname) yyman = 1. + 2. * xx - .5 * (.5 * (3. * xx ** 2. - 1.)) for j, xc in enumerate(np.arange(-1, 3)): r2j = (directionalWeights[0] * (xx - xc)) ** 2. rbj = thinPlateSpline(r2j) assert np.allclose(rbj, .5 * r2j * np.log(np.finfo(float).eps + r2j)) yyman += cRB.localCoeffs[j] * rbj ySupp += cRB.localCoeffs[j] * thinPlateSpline((directionalWeights[0] * (xSupp.data - xc)) ** 2.) assert np.allclose(yy, yyman, atol = 1e-5) VanT = polyvander(xSupp, [2], polyrbname, directionalWeights = directionalWeights) ySupp = np.pad(ySupp.flatten(), (0, len(VanT) - len(xSupp)), "constant") out = customFit(VanT, ySupp) assert np.allclose(out, cRBCoeffs, atol = 1e-8) def test_chebyshev_multiquadric(): polyrbname = "CHEBYSHEV_MULTIQUADRIC" assert polyrbname in polybases fitname = polyfitname(polyrbname) domcoeff = polydomcoeff(5, polyrbname) assert fitname == "chebfit_multiquadric" assert np.isclose(domcoeff, 16, rtol = 1e-5) directionalWeights = np.array([1.]) xSupp = checkParameterList(np.arange(-1, 3), 1)[0] cRBCoeffs = np.array([-1., 3., -3., 1., 1., 2., -.5]) cRB = radialFunction(directionalWeights = directionalWeights, - localBasis = "MULTIQUADRIC", - globalBasis = "CHEBYSHEV", supportPoints = xSupp, - localCoeffs = cRBCoeffs[: 4], + supportPoints = xSupp, localCoeffs = cRBCoeffs[: 4], globalCoeffs = cRBCoeffs[4 :]) ySupp = 1 + 2. * xSupp.data - .5 * (2. * xSupp.data ** 2. - 1.) xx = np.linspace(-2., 3., 100) yy = polyval(checkParameterList(xx, 1)[0], cRB, polyrbname) yyman = 1. + 2. * xx - .5 * (2. * xx ** 2. - 1.) for j, xc in enumerate(np.arange(-1, 3)): r2j = (directionalWeights[0] * (xx - xc)) ** 2. rbj = multiQuadric(r2j) assert np.allclose(rbj, np.power(r2j + 1, -.5)) yyman += cRB.localCoeffs[j] * rbj ySupp += cRB.localCoeffs[j] * multiQuadric((directionalWeights[0] * (xSupp.data - xc)) ** 2.) assert np.allclose(yy, yyman, atol = 1e-5) VanT = polyvander(xSupp, [2], polyrbname, directionalWeights = directionalWeights) ySupp = np.pad(ySupp.flatten(), (0, len(VanT) - len(xSupp)), "constant") out = customFit(VanT, ySupp) assert np.allclose(out, cRBCoeffs, atol = 1e-8) + diff --git a/tests/test_1_utilities/sampling.py b/tests/utilities/sampling.py similarity index 100% rename from tests/test_1_utilities/sampling.py rename to tests/utilities/sampling.py diff --git a/tests/test_1_utilities/scipy_tensorize.py b/tests/utilities/scipy_tensorize.py similarity index 100% rename from tests/test_1_utilities/scipy_tensorize.py rename to tests/utilities/scipy_tensorize.py