Skip to content
Snippets Groups Projects
Commit 0d13fc73 authored by Oliver Sander's avatar Oliver Sander
Browse files

beginning of a unit test for dynamic matrices

[[Imported from SVN: r643]]
parent 156327bc
Branches
Tags
No related merge requests found
......@@ -7,7 +7,7 @@ if MPI
endif
# which tests where program to build and run are equal
NORMALTESTS = matrixutilstest bvectortest indexsettest $(SELECTPROG)
NORMALTESTS = matrixutilstest matrixtest bvectortest indexsettest $(SELECTPROG)
# list of tests to run (indicestest is special case)
TESTS = $(NORMALTESTS) $(DUNE_COMMON_ROOT)/bin/perhapsstartmpi $(INDEXRUN) $(DUNE_COMMON_ROOT)/bin/perhapsstopmpi
......@@ -23,6 +23,8 @@ bvectortest_SOURCES = bvectortest.cc
matrixutilstest_SOURCES = matrixutilstest.cc laplacian.hh
#matrixutilstest_DEPENDENCIES = $(LOCAL_LIBS)
matrixtest_SOURCES = matrixtest.cc
indicestest_SOURCES = indicestest.cc
indicestest_CXXFLAGS = $(MPI_CPPFLAGS)
indicestest_LDFLAGS = $(MPI_LDFLAGS) $(MPI_LIBS)
......
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
/** \file
\brief Unit tests for the different dynamic matrices provided by ISTL
*/
#include <dune/common/fmatrix.hh>
#include <dune/istl/bcrsmatrix.hh>
#include <dune/istl/matrix.hh>
#include <dune/istl/bdmatrix.hh>
using namespace Dune;
template <class MatrixType>
void testMatrix(MatrixType& matrix)
{
// ////////////////////////////////////////////////////////
// Count number of rows, columns, and nonzero entries
// ////////////////////////////////////////////////////////
typename MatrixType::RowIterator rowIt = matrix.begin();
typename MatrixType::RowIterator rowEndIt = matrix.end();
int numRows = 0, numEntries = 0;
for (; rowIt!=rowEndIt; ++rowIt) {
typename MatrixType::ColIterator colIt = rowIt->begin();
typename MatrixType::ColIterator colEndIt = rowIt->end();
for (; colIt!=colEndIt; ++colIt)
numEntries++;
numRows++;
}
assert (numRows == matrix.N());
// test assignment from scalar
matrix = 0;
}
int main()
{
// ////////////////////////////////////////////////////////////
// Test the Matrix class -- a dense dynamic matrix
// ////////////////////////////////////////////////////////////
Matrix<FieldMatrix<double,3,3> > matrix(10,10);
for (int i=0; i<10; i++)
for (int j=0; j<10; j++)
for (int k=0; k<3; k++)
for (int l=0; l<3; l++)
matrix[i][j][k][l] = (i+j)/((double)(k*l)); // just anything
testMatrix(matrix);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment