// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception #include #include #include #include #include #include #include #include #include #include using namespace Dune; TestSuite testFlatVectorForEach() { TestSuite t; // mix up some types [[maybe_unused]] FieldVector f3; [[maybe_unused]] FieldVector f1; DynamicVector> d3; std::vector> v1; d3.resize(5); v1.resize(5); using MTBV = MultiTypeBlockVector>,std::vector>>; MTBV v; v[Indices::_0] = d3; v[Indices::_1] = v1; int entries = 0; auto countEntres = [&](auto&& entry, auto&& index){ entries++; }; auto s = flatVectorForEach(v,countEntres); t.check( entries == 20 ); t.check( s == 20 ); return t; } TestSuite testFlatVectorForEachBitSetVector() { TestSuite t; int entries = 0; auto countEntres = [&](auto&& entry, auto&& index){ entries++; }; BitSetVector<2> bitSetVector; bitSetVector.resize(10); auto s = flatVectorForEach(bitSetVector,countEntres); t.check( entries == 20 ); t.check( s == 20 ); return t; } TestSuite testFlatMatrixForEachStatic() { TestSuite t; [[maybe_unused]] FieldMatrix F33; [[maybe_unused]] FieldMatrix F31; [[maybe_unused]] FieldMatrix F13; [[maybe_unused]] FieldMatrix F11; BCRSMatrix> B33; BCRSMatrix> B31; BCRSMatrix> B13; BCRSMatrix> B11; MatrixIndexSet mis; mis.resize(3,3); // set some indices ( skip one row for the top left block ) mis.add(0,0); mis.add(2,1); mis.exportIdx(B33); mis.add(1,1); mis.exportIdx(B31); mis.exportIdx(B13); mis.exportIdx(B11); using Row0 = MultiTypeBlockVector>,BCRSMatrix>>; using Row1 = MultiTypeBlockVector>,BCRSMatrix>>; using MTMatrix = MultiTypeBlockMatrix; MTMatrix M; M[Indices::_0][Indices::_0] = B33; M[Indices::_0][Indices::_1] = B31; M[Indices::_1][Indices::_0] = B13; M[Indices::_1][Indices::_1] = B11; int entries = 0; auto [ rows , cols ] = flatMatrixForEach( M, [&](auto&& /*entry*/, auto&& rowIndex, auto&& colIndex){ entries++; }); t.check( entries == 39 , " wrong number of entries "); t.check( rows == 12 , " wrong number of rows "); t.check( cols == 12 , " wrong number of cols "); return t; } TestSuite testFlatMatrixForEachDynamic() { TestSuite t; DynamicMatrix F33(3,3); BCRSMatrix> B; MatrixIndexSet mis; mis.resize(3,3); // set some entries and leave one line empty on purpose mis.add(0,0); mis.add(1,1); mis.exportIdx(B); B[0][0] = F33; B[1][1] = F33; int entries = 0; auto [ rows , cols ] = flatMatrixForEach( B, [&](auto&& /*entry*/, auto&& rowIndex, auto&& colIndex){ entries++; }); t.check( entries == 18 , " wrong number of entries "); t.check( rows == 9 , " wrong number of rows "); t.check( cols == 9 , " wrong number of cols "); return t; } int main(int argc, char** argv) { TestSuite t; t.subTest(testFlatVectorForEach()); t.subTest(testFlatVectorForEachBitSetVector()); t.subTest(testFlatMatrixForEachStatic()); t.subTest(testFlatMatrixForEachDynamic()); return t.exit(); }