// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- // vi: set et ts=4 sw=2 sts=2: #include #include #include #include #include #include #include #include #include "laplacian.hh" using namespace Dune; template TestSuite runUMFPack(std::size_t N) { TestSuite t; Matrix mat; Vector b(N*N), x(N*N), b1(N/2), x1(N/2); // with additional diagonal regularization setupLaplacian(mat,N,100.0); b=1; b1=1; x=0; x1=0; Dune::Timer watch; watch.reset(); Dune::UMFPack solver(mat,1); Dune::InverseOperatorResult res; solver.apply(x, b, res); solver.free(); // test auto norm = b.two_norm(); mat.mmv(x,b); t.check( b.two_norm()/norm < 1e-11 ) << " Error in UMFPACK, relative residual is too large: " << b.two_norm()/norm; Dune::UMFPack solver1; std::set mrs; BitVector bitVector(N*N); bitVector = true; for(typename Matrix::size_type s=0; s < N/2; ++s) { mrs.insert(s); bitVector[s] = false; } solver1.setMatrix(mat,bitVector); solver1.apply(x1,b1, res); // test x=0; b=0; for( typename Matrix::size_type i=0; i(&x1[0]), reinterpret_cast(&b1[0])); Dune::UMFPack save_solver(mat,"umfpack_decomp",0); Dune::UMFPack load_solver(mat,"umfpack_decomp",0); return t; } template TestSuite runUMFPackMultitype2x2(std::size_t N) { TestSuite t; using namespace Dune::Indices; Matrix mat; Vector b,x,b1,x1; b[_0].resize(N*N); b[_1].resize(N*N); x[_0].resize(N*N); x[_1].resize(N*N); b1[_0].resize(N/2); b1[_1].resize(N/2); x1[_0].resize(N/2); x1[_1].resize(N/2); // initialize all 4 matrix blocks setupLaplacian(mat[_0][_0],N,100.0); // regularize the diagonal block setupLaplacian(mat[_0][_1],N); setupLaplacian(mat[_1][_0],N); setupLaplacian(mat[_1][_1],N,200.0); // regularize the diagonal block b=1.0; b1=1.0; x=0.0; x1=0.0; Dune::Timer watch; watch.reset(); Dune::UMFPack solver(mat,1); Dune::InverseOperatorResult res; solver.apply(x, b, res); solver.free(); // test auto norm = b.two_norm(); mat.mmv(x,b); t.check( b.two_norm()/norm < 1e-11 ) << " Error in UMFPACK, relative residual is too large: " << b.two_norm()/norm; Dune::UMFPack solver1; BitVector bitVector; bitVector[_0].resize(N*N); bitVector[_1].resize(N*N); bitVector = true; for(std::size_t s=0; s < N/2; ++s) { bitVector[_0][s] = false; bitVector[_1][s] = false; } solver1.setMatrix(mat,bitVector); solver1.apply(x1,b1, res); // test x=0; b=0; for( std::size_t i=0; i1) N = atoi(argv[1]); // ------------------------------------------------------------------------------ std::cout<<"testing for N="<"<; using Vector = Dune::BlockVector; using BitVector = Dune::BlockVector; t.subTest(runUMFPack(N)); } // ------------------------------------------------------------------------------ std::cout<<"testing for N="< >"< >; using Vector = Dune::BlockVector >; using BitVector = Dune::BlockVector >; t.subTest(runUMFPack(N)); } // ------------------------------------------------------------------------------ std::cout<<"testing for N="< >"< >; using Vector = Dune::BlockVector >; using BitVector = Dune::BlockVector >; t.subTest(runUMFPack(N)); } // ------------------------------------------------------------------------------ std::cout<<"testing for N="<> ... >"< >; using BlockRow = Dune::MultiTypeBlockVector; using Matrix = Dune::MultiTypeBlockMatrix; using VectorBlock = Dune::BlockVector >; using Vector = Dune::MultiTypeBlockVector; using BitVectorBlock = Dune::BlockVector >; using BitVector = Dune::MultiTypeBlockVector; t.subTest(runUMFPackMultitype2x2(N)); } return t.exit(); #else // HAVE_SUITESPARSE_UMFPACK std::cerr << "You need SuiteSparse's UMFPack to run this test." << std::endl; return 77; #endif // HAVE_SUITESPARSE_UMFPACK } catch (std::exception &e) { std::cout << "ERROR: " << e.what() << std::endl; return 1; }