Skip to content
Snippets Groups Projects
Commit 1184becc authored by Andreas Dedner's avatar Andreas Dedner
Browse files

fix an issue caused by generated files being added to source tree - move to a temporary location

parent 89b9c4f0
No related branches found
No related tags found
1 merge request!529fix an issue caused by generated files being added to source tree - move to a temporary location
Pipeline #61461 passed
%%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
# 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)
......
1 1 1
2 2 1
3 3 1
4 4 1
5 5 1
SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment