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

Refactor the test for MultiTypeBlockMatrix a bit

In preparation of testing more matrix types
parent 2b376b38
Branches
Tags
1 merge request!282Improve matrix testing
......@@ -28,63 +28,61 @@
using namespace Dune;
int main(int argc, char** argv) try
{
// Import the static constants _0, _1, etc
using namespace Indices;
///////////////////////////////////////////////////////////////////////////////////////////////////////////
// First, we test a MultiTypeBlockMatrix consisting of an array of 2x2 dense matrices.
// The upper left dense matrix has dense 3x3 blocks, the lower right matrix has 1x1 blocks,
// the off-set diagonal matrix block sizes are set accordingly.
///////////////////////////////////////////////////////////////////////////////////////////////////////////
// Import the static constants _0, _1, etc
using namespace Indices;
// set up the test matrix
typedef MultiTypeBlockVector<Matrix<FieldMatrix<double,3,3> >, Matrix<FieldMatrix<double,3,1> > > RowType0;
typedef MultiTypeBlockVector<Matrix<FieldMatrix<double,1,3> >, Matrix<FieldMatrix<double,1,1> > > RowType1;
void testInterfaceMethods()
{
{
///////////////////////////////////////////////////////////////////////////////////////////////////////////
// First, we test a MultiTypeBlockMatrix consisting of an array of 2x2 dense matrices.
// The upper left dense matrix has dense 3x3 blocks, the lower right matrix has 1x1 blocks,
// the off-set diagonal matrix block sizes are set accordingly.
///////////////////////////////////////////////////////////////////////////////////////////////////////////
MultiTypeBlockMatrix<RowType0,RowType1> multiMatrix;
// set up the test matrix
typedef MultiTypeBlockVector<Matrix<FieldMatrix<double,3,3> >, Matrix<FieldMatrix<double,3,1> > > RowType0;
typedef MultiTypeBlockVector<Matrix<FieldMatrix<double,1,3> >, Matrix<FieldMatrix<double,1,1> > > RowType1;
multiMatrix[_0][_0].setSize(3,3);
multiMatrix[_0][_1].setSize(3,2);
multiMatrix[_1][_0].setSize(2,3);
multiMatrix[_1][_1].setSize(2,2);
MultiTypeBlockMatrix<RowType0,RowType1> multiMatrix;
// lazy solution: initialize the entire matrix with zeros
multiMatrix = 0;
multiMatrix[_0][_0].setSize(3,3);
multiMatrix[_0][_1].setSize(3,2);
multiMatrix[_1][_0].setSize(2,3);
multiMatrix[_1][_1].setSize(2,2);
printmatrix(std::cout, multiMatrix[_0][_0], "(0,0)", "--");
printmatrix(std::cout, multiMatrix[_0][_1], "(0,1)", "--");
printmatrix(std::cout, multiMatrix[_1][_0], "(1,0)", "--");
printmatrix(std::cout, multiMatrix[_1][_1], "(1,1)", "--");
// Init with scalar values
multiMatrix[_0][_0] = 4200;
multiMatrix[_0][_1] = 4201;
multiMatrix[_1][_0] = 4210;
multiMatrix[_1][_1] = 4211;
// Test vector space operations
testVectorSpaceOperations(multiMatrix);
// Set up a test vector
MultiTypeBlockVector<BlockVector<FieldVector<double,3> >, BlockVector<FieldVector<double,1> > > domainVector;
// Test whether matrix class has the required constructors
testMatrixConstructibility<decltype(multiMatrix)>();
domainVector[_0] = {{1,0,0},
{0,1,0},
{0,0,1}};
// set up a test vector
MultiTypeBlockVector<BlockVector<FieldVector<double,3> >, BlockVector<FieldVector<double,1> > > multiVector;
domainVector[_1] = {3.14, 42};
multiVector[_0] = {{1,0,0},
{0,1,0},
{0,0,1}};
auto rangeVector = domainVector; // Range == Domain, because the matrix nesting pattern is symmetric
multiVector[_1] = {3.14, 42};
// Test vector space operations
testVectorSpaceOperations(multiMatrix);
// Test matrix-vector products
MultiTypeBlockVector<BlockVector<FieldVector<double,3> >, BlockVector<FieldVector<double,1> > > result;
result[_0].resize(3);
result[_1].resize(2);
// Test whether matrix class has the required constructors
testMatrixConstructibility<decltype(multiMatrix)>();
multiMatrix[_0][_0] = 4200;
multiMatrix[_0][_1] = 4201;
multiMatrix[_1][_0] = 4210;
multiMatrix[_1][_1] = 4211;
// Test matrix-vector products
testMatrixVectorProducts(multiMatrix, domainVector, rangeVector);
}
}
auto rangeVector = result; // Range == Domain, because the matrix nesting pattern is symmetric
testMatrixVectorProducts(multiMatrix, result, rangeVector);
int main(int argc, char** argv) try
{
// Run the standard tests for the dune-istl matrix interface
testInterfaceMethods();
///////////////////////////////////////////////////////////////////////////////////////////////////////////
// Next test: Set up a linear system with a matrix consisting of 2x2 sparse scalar matrices.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment