From 1184beccd8b93fda44d85cc96283dcc9a5361d87 Mon Sep 17 00:00:00 2001 From: dedner <a.s.dedner@warwick.ac.uk> Date: Tue, 11 Apr 2023 14:47:53 +0100 Subject: [PATCH] fix an issue caused by generated files being added to source tree - move to a temporary location --- dune/python/test/bcrsmatrix.mm | 10 ---- dune/python/test/bcrsmatrix.py | 66 +++++++++++++------------ dune/python/test/bcrsmatrix.txt | 5 -- dune/python/test/bcrsmatrix.txt.license | 2 - 4 files changed, 35 insertions(+), 48 deletions(-) delete mode 100644 dune/python/test/bcrsmatrix.mm delete mode 100644 dune/python/test/bcrsmatrix.txt delete mode 100644 dune/python/test/bcrsmatrix.txt.license diff --git a/dune/python/test/bcrsmatrix.mm b/dune/python/test/bcrsmatrix.mm deleted file mode 100644 index e73451e88..000000000 --- a/dune/python/test/bcrsmatrix.mm +++ /dev/null @@ -1,10 +0,0 @@ -%%MatrixMarket matrix coordinate real general -% SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root -% SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception -% ISTL_STRUCT blocked 1 1 -5 5 5 -1 1 1.000000e+00 -2 2 1.000000e+00 -3 3 1.000000e+00 -4 4 1.000000e+00 -5 5 1.000000e+00 diff --git a/dune/python/test/bcrsmatrix.py b/dune/python/test/bcrsmatrix.py index afda91a4a..5d8130571 100644 --- a/dune/python/test/bcrsmatrix.py +++ b/dune/python/test/bcrsmatrix.py @@ -1,6 +1,7 @@ # SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root # SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception +import tempfile,os import dune.common from dune.istl import blockVector, BlockVector, bcrsMatrix, BCRSMatrix, SeqJacobi, CGSolver, BuildMode @@ -55,37 +56,40 @@ if mat.shape != (5, 5) or mat.nonZeroes != 5 or mat.buildMode != BuildMode.impli # BMatrix = BCRSMatrix(Matrix) # mat = BMatrix((5,5), 5, BuildMode.implicit) -# store identity matrix -mat = identity(5) -if not isIdentity(mat): - raise Exception("Identity matrix not setup correctly") -mat.store("bcrsmatrix.mm", "matrixmarket") - -for i, row in mat.enumerate: - for j, col in row.enumerate: - if i != j: - raise Exception("Wrong sparsity pattern") - if col != 1: - raise Exception("Diagonal entry is not 1") - -mat = identity(5, BuildMode.implicit) -if not isIdentity(mat): - raise Exception("Identity matrix not setup correctly") - -# manipulate diagonal to 2 -for i in range(mat.rows): - mat[i, i] *= 2 -if isIdentity(mat): - raise Exception("Matrix not manipulated") - -# reload identity matrix -mat = bcrsMatrix() -mat.load("bcrsmatrix.mm", "matrixmarket") -if not isIdentity(mat): - raise Exception("Matrix not loaded correctly") - -# store in matlab format -mat.store("bcrsmatrix.txt", "matlab") +# generate a temporary directory to test 'store', 'load': + +with tempfile.TemporaryDirectory() as tmpDir: + # store identity matrix + mat = identity(5) + if not isIdentity(mat): + raise Exception("Identity matrix not setup correctly") + mat.store(os.path.join(tmpDir,"bcrsmatrix.mm"), "matrixmarket") + + for i, row in mat.enumerate: + for j, col in row.enumerate: + if i != j: + raise Exception("Wrong sparsity pattern") + if col != 1: + raise Exception("Diagonal entry is not 1") + + mat = identity(5, BuildMode.implicit) + if not isIdentity(mat): + raise Exception("Identity matrix not setup correctly") + + # manipulate diagonal to 2 + for i in range(mat.rows): + mat[i, i] *= 2 + if isIdentity(mat): + raise Exception("Matrix not manipulated") + + # reload identity matrix + mat = bcrsMatrix() + mat.load(os.path.join(tmpDir,"bcrsmatrix.mm"), "matrixmarket") + if not isIdentity(mat): + raise Exception("Matrix not loaded correctly") + + # store in matlab format + mat.store(os.path.join(tmpDir,"bcrsmatrix.txt"), "matlab") # solve trivial linear system x = blockVector(5) diff --git a/dune/python/test/bcrsmatrix.txt b/dune/python/test/bcrsmatrix.txt deleted file mode 100644 index 0c88019fb..000000000 --- a/dune/python/test/bcrsmatrix.txt +++ /dev/null @@ -1,5 +0,0 @@ -1 1 1 -2 2 1 -3 3 1 -4 4 1 -5 5 1 diff --git a/dune/python/test/bcrsmatrix.txt.license b/dune/python/test/bcrsmatrix.txt.license deleted file mode 100644 index ab53c287a..000000000 --- a/dune/python/test/bcrsmatrix.txt.license +++ /dev/null @@ -1,2 +0,0 @@ -SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root -SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception -- GitLab