Skip to content
Snippets Groups Projects
Select Git revision
  • 2291b700be21cba30dd12962e07e4e1e9ac32c42
  • develop default protected
  • feature/advection
  • feature/composite-scheme-other-fluxes
  • origin/stage/bouguettaia
  • save_clemence
  • feature/local-dt-fsi
  • feature/variational-hydro
  • feature/gmsh-reader
  • feature/reconstruction
  • feature/kinetic-schemes
  • feature/composite-scheme-sources
  • feature/serraille
  • feature/composite-scheme
  • hyperplastic
  • feature/polynomials
  • feature/gks
  • feature/implicit-solver-o2
  • feature/coupling_module
  • feature/implicit-solver
  • feature/merge-local-dt-fsi
  • v0.5.0 protected
  • v0.4.1 protected
  • v0.4.0 protected
  • v0.3.0 protected
  • v0.2.0 protected
  • v0.1.0 protected
  • Kidder
  • v0.0.4 protected
  • v0.0.3 protected
  • v0.0.2 protected
  • v0 protected
  • v0.0.1 protected
33 results

test_ASTSymbolTableBuilder.cpp

Blame
  • test_LeastSquareSolver.cpp 1.47 KiB
    #include <catch2/catch.hpp>
    
    #include <algebra/LeastSquareSolver.hpp>
    #include <algebra/LocalRectangularMatrix.hpp>
    #include <algebra/Vector.hpp>
    
    // clazy:excludeall=non-pod-global-static
    
    TEST_CASE("LeastSquareSolver", "[algebra]")
    {
      SECTION("Least Squares [under-determined]")
      {
        Vector<double> b{3};
        b[0] = 1;
        b[1] = 0;
        b[2] = 0;
    
        LocalRectangularMatrix<double> A{3, 4};
        A(0, 0) = 1;
        A(0, 1) = 1;
        A(0, 2) = 1;
        A(0, 3) = 1;
        A(1, 0) = 1;
        A(1, 1) = -1;
        A(1, 2) = 0;
        A(1, 3) = 0;
        A(2, 0) = 0;
        A(2, 1) = 0;
        A(2, 2) = 1;
        A(2, 3) = -1;
    
        Vector<double> x_exact{4};
    
        x_exact[0] = 0.25;
        x_exact[1] = 0.25;
        x_exact[2] = 0.25;
        x_exact[3] = 0.25;
    
        Vector<double> x{4};
        x = 0;
    
        LeastSquareSolver ls_solver;
        ls_solver.solveLocalSystem(A, x, b);
    
        Vector error = x - x_exact;
        REQUIRE(std::sqrt((error, error)) < 1E-10 * std::sqrt((x, x)));
      }
    
      SECTION("Least Squares [over-determined]")
      {
        LocalRectangularMatrix<double> A{3, 2};
        A(0, 0) = 0;
        A(0, 1) = 1;
        A(1, 0) = 1;
        A(1, 1) = 1;
        A(2, 0) = 2;
        A(2, 1) = 1;
    
        Vector<double> x_exact{2};
        x_exact[0] = -3;
        x_exact[1] = 5;
    
        Vector b{3};
        b[0] = 6;
        b[1] = 0;
        b[2] = 0;
    
        Vector<double> x{2};
        x = 0;
    
        LeastSquareSolver ls_solver;
        ls_solver.solveLocalSystem(A, x, b);
    
        Vector error = x - x_exact;
        REQUIRE(std::sqrt((error, error)) < 1E-10 * std::sqrt((x_exact, x_exact)));
      }
    }