DNDSR 0.1.0.dev1+gcd065ad
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
test_Direct.cpp File Reference

Unit tests for block-sparse LU factorization in Solver/Direct.hpp. More...

#include "doctest.h"
#include "DNDS/Defines.hpp"
#include "DNDS/MPI.hpp"
#include "Solver/Direct.hpp"
#include <Eigen/Dense>
#include <iostream>
#include <iomanip>
#include <vector>
#include <memory>
#include <cmath>
Include dependency graph for test_Direct.cpp:

Go to the source code of this file.

Classes

struct  TestBlockLU
 
struct  TestBlockLDLT
 

Macros

#define DOCTEST_CONFIG_IMPLEMENT
 

Typedefs

using Block = Eigen::Matrix< real, BS, BS >
 
using BVec = Eigen::Vector< real, BS >
 
using tVec = std::vector< BVec >
 
using tBase = Direct::LocalLUBase< TestBlockLU, Block, tVec >
 
using tLDLTBase = Direct::LocalLDLTBase< TestBlockLDLT, Block, tVec >
 

Functions

 TEST_CASE ("Direct 2D periodic: symbolic factorization has fill-in")
 
 TEST_CASE ("Direct 2D periodic: MatMul is correct")
 
 TEST_CASE ("Direct 2D periodic: complete LU solve is exact")
 
symLU0 ObtainSymmetricSymbolicFactorization (adj, {0, NCells}, 0)
 
 fill2DLaplacian (luOrig)
 
tVec x_known (NCells)
 
tVec b (NCells)
 
tVec x_ilu (NCells)
 
tVec Ax_ilu (NCells)
 
 for (int i=0;i< NCells;i++)
 
luOrig MatMul (x_known, b)
 
 fill2DLaplacian (luILU)
 
luILU InPlaceDecompose ()
 
luILU Solve (b, x_ilu)
 
 fill2DLaplacian (luMul)
 
luMul MatMul (x_ilu, Ax_ilu)
 
 fill2DLaplacian (luA)
 
symM ObtainSymmetricSymbolicFactorization (adj, {0, NCells}, iluCode)
 
 fill2DLaplacian (luM)
 
tVec x (NCells)
 
tVec r (NCells)
 
tVec z (NCells)
 
tVec Ax (NCells)
 
 TEST_CASE ("Direct 2D periodic: ILU(1) converges faster than ILU(0) as preconditioner")
 
 TEST_CASE ("Direct 2D periodic LDLT: MatMul matches LU MatMul for symmetric system")
 
 TEST_CASE ("Direct 2D periodic LDLT: complete decompose + solve is exact")
 
int main (int argc, char **argv)
 

Variables

auto adj = build2DPeriodicAdj()
 
auto symLUorig = std::make_shared<Direct::SerialSymLUStructure>(g_mpi, NCells)
 
TestBlockLU luOrig (symLUorig, NCells)
 
TestBlockLU luILU (symLU0, NCells)
 
auto symLUmul = std::make_shared<Direct::SerialSymLUStructure>(g_mpi, NCells)
 
TestBlockLU luMul (symLUmul, NCells)
 
real residualNorm = 0
 
real bNorm = 0
 
real relResidual = residualNorm / bNorm
 
TestBlockLU luA (symA, NCells)
 
auto symM = std::make_shared<Direct::SerialSymLUStructure>(g_mpi, NCells)
 
TestBlockLU luM (symM, NCells)
 
real err = 0
 

Detailed Description

Unit tests for block-sparse LU factorization in Solver/Direct.hpp.

Tests a 2D periodic Laplacian with 2x2 blocks on an NxN grid: A = 5-point stencil with periodic boundary (4 neighbors per cell). Each cell (i,j) connects to (i±1,j) and (i,j±1) with wrap-around. Diag = 4*I + delta*diag(i,2i), off-diag = -I (non-symmetric diag to exercise the full LU, not just LDLT).

Verifies:

  • SerialSymLUStructure: symbolic factorization with fill-in
  • LocalLUBase: MatMul (A*x == b), InPlaceDecompose, Solve (A^{-1}b == x)
  • ILU(0): approximate solve, residual reduction
  • Complete LU (iluCode=-1): exact solve
  • ILU(1): intermediate fill, better than ILU(0)

Definition in file test_Direct.cpp.

Macro Definition Documentation

◆ DOCTEST_CONFIG_IMPLEMENT

#define DOCTEST_CONFIG_IMPLEMENT

Definition at line 19 of file test_Direct.cpp.

Typedef Documentation

◆ Block

using Block = Eigen::Matrix<real, BS, BS>

Definition at line 35 of file test_Direct.cpp.

◆ BVec

using BVec = Eigen::Vector<real, BS>

Definition at line 36 of file test_Direct.cpp.

◆ tBase

Definition at line 43 of file test_Direct.cpp.

◆ tLDLTBase

Definition at line 360 of file test_Direct.cpp.

◆ tVec

using tVec = std::vector<BVec>

Definition at line 42 of file test_Direct.cpp.

Function Documentation

◆ Ax()

tVec Ax ( NCells  )
Here is the caller graph for this function:

◆ Ax_ilu()

tVec Ax_ilu ( NCells  )
Here is the caller graph for this function:

◆ b()

tVec b ( NCells  )
Here is the caller graph for this function:

◆ fill2DLaplacian() [1/5]

fill2DLaplacian ( luA  )

◆ fill2DLaplacian() [2/5]

fill2DLaplacian ( luILU  )

◆ fill2DLaplacian() [3/5]

fill2DLaplacian ( luM  )

◆ fill2DLaplacian() [4/5]

fill2DLaplacian ( luMul  )

◆ fill2DLaplacian() [5/5]

fill2DLaplacian ( luOrig  )

◆ for()

for ( )

Definition at line 239 of file test_Direct.cpp.

Here is the call graph for this function:

◆ InPlaceDecompose()

luM InPlaceDecompose ( )

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 514 of file test_Direct.cpp.

Here is the call graph for this function:

◆ MatMul() [1/2]

luMul MatMul ( x_ilu  ,
Ax_ilu   
)

◆ MatMul() [2/2]

luOrig MatMul ( x_known  ,
b   
)

◆ ObtainSymmetricSymbolicFactorization() [1/2]

symA ObtainSymmetricSymbolicFactorization ( adj  ,
{0, NCells}  ,
 
)

◆ ObtainSymmetricSymbolicFactorization() [2/2]

symM ObtainSymmetricSymbolicFactorization ( adj  ,
{0, NCells}  ,
iluCode   
)

◆ r()

tVec r ( NCells  )

◆ Solve()

luILU Solve ( b  ,
x_ilu   
)

◆ TEST_CASE() [1/6]

TEST_CASE ( "Direct 2D periodic LDLT: complete decompose + solve is exact"  )

Definition at line 474 of file test_Direct.cpp.

Here is the call graph for this function:

◆ TEST_CASE() [2/6]

TEST_CASE ( "Direct 2D periodic LDLT: MatMul matches LU MatMul for symmetric system"  )

Definition at line 438 of file test_Direct.cpp.

Here is the call graph for this function:

◆ TEST_CASE() [3/6]

TEST_CASE ( "Direct 2D periodic: complete LU solve is exact"  )

Definition at line 191 of file test_Direct.cpp.

Here is the call graph for this function:

◆ TEST_CASE() [4/6]

TEST_CASE ( "Direct 2D periodic: ILU(1) converges faster than ILU(0) as preconditioner"  )

Definition at line 321 of file test_Direct.cpp.

Here is the call graph for this function:

◆ TEST_CASE() [5/6]

TEST_CASE ( "Direct 2D periodic: MatMul is correct"  )

Definition at line 153 of file test_Direct.cpp.

Here is the call graph for this function:

◆ TEST_CASE() [6/6]

TEST_CASE ( "Direct 2D periodic: symbolic factorization has fill-in"  )

Definition at line 137 of file test_Direct.cpp.

Here is the call graph for this function:

◆ x()

tVec x ( NCells  )
Here is the caller graph for this function:

◆ x_ilu()

tVec x_ilu ( NCells  )
Here is the caller graph for this function:

◆ x_known()

tVec x_known ( NCells  )
Here is the caller graph for this function:

◆ z()

tVec z ( NCells  )
Here is the caller graph for this function:

Variable Documentation

◆ adj

auto adj = build2DPeriodicAdj()

Definition at line 229 of file test_Direct.cpp.

◆ bNorm

bNorm = 0

Definition at line 265 of file test_Direct.cpp.

◆ err

real err = 0

Definition at line 315 of file test_Direct.cpp.

◆ luA

TestBlockLU luA(symA, NCells) ( symA  ,
NCells   
)

◆ luILU

TestBlockLU luILU(symLU0, NCells) ( symLU0  ,
NCells   
)

◆ luM

TestBlockLU luM(symM, NCells) ( symM  ,
NCells   
)

◆ luMul

TestBlockLU luMul(symLUmul, NCells) ( symLUmul  ,
NCells   
)

◆ luOrig

TestBlockLU luOrig(symLUorig, NCells) ( symLUorig  ,
NCells   
)

◆ relResidual

real relResidual = residualNorm / bNorm

Definition at line 274 of file test_Direct.cpp.

◆ residualNorm

residualNorm = 0

Definition at line 265 of file test_Direct.cpp.

◆ symLUmul

auto symLUmul = std::make_shared<Direct::SerialSymLUStructure>(g_mpi, NCells)

Definition at line 259 of file test_Direct.cpp.

◆ symLUorig

auto symLUorig = std::make_shared<Direct::SerialSymLUStructure>(g_mpi, NCells)

Definition at line 233 of file test_Direct.cpp.

◆ symM

auto symM = std::make_shared<Direct::SerialSymLUStructure>(g_mpi, NCells)

Definition at line 295 of file test_Direct.cpp.