Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pugs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
code
pugs
Commits
db22fdf6
Commit
db22fdf6
authored
4 months ago
by
Stéphane Del Pino
Browse files
Options
Downloads
Patches
Plain Diff
Add missing tests
parent
095f172d
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_LinearSolver.cpp
+922
-332
922 additions, 332 deletions
tests/test_LinearSolver.cpp
with
922 additions
and
332 deletions
tests/test_LinearSolver.cpp
+
922
−
332
View file @
db22fdf6
...
...
@@ -836,6 +836,8 @@ TEST_CASE("LinearSolver", "[algebra]")
}
SECTION
(
"Dense Matrices"
)
{
SECTION
(
"SmallMatrix"
)
{
SECTION
(
"check linear solvers"
)
{
...
...
@@ -1470,4 +1472,592 @@ TEST_CASE("LinearSolver", "[algebra]")
}
}
}
SECTION
(
"TinyMatrix"
)
{
SECTION
(
"check linear solvers"
)
{
SECTION
(
"symmetric system"
)
{
TinyMatrix
<
5
>
A
=
zero
;
A
(
0
,
0
)
=
2
;
A
(
0
,
1
)
=
-
1
;
A
(
1
,
0
)
=
-
1
;
A
(
1
,
1
)
=
2
;
A
(
1
,
2
)
=
-
1
;
A
(
2
,
1
)
=
-
1
;
A
(
2
,
2
)
=
2
;
A
(
2
,
3
)
=
-
1
;
A
(
3
,
2
)
=
-
1
;
A
(
3
,
3
)
=
2
;
A
(
3
,
4
)
=
-
1
;
A
(
4
,
3
)
=
-
1
;
A
(
4
,
4
)
=
2
;
TinyVector
<
5
>
x_exact
{
1
,
3
,
2
,
4
,
5
};
TinyVector
b
=
A
*
x_exact
;
SECTION
(
"builtin"
)
{
SECTION
(
"CG no preconditioner"
)
{
LinearSolverOptions
options
;
options
.
library
()
=
LSLibrary
::
builtin
;
options
.
method
()
=
LSMethod
::
cg
;
options
.
precond
()
=
LSPrecond
::
none
;
TinyVector
<
5
>
x
=
zero
;
LinearSolver
solver
{
options
};
solver
.
solveLocalSystem
(
A
,
x
,
b
);
TinyVector
error
=
x
-
x_exact
;
REQUIRE
(
std
::
sqrt
(
dot
(
error
,
error
))
<
1E-10
*
std
::
sqrt
(
dot
(
x_exact
,
x_exact
)));
}
}
SECTION
(
"Eigen3"
)
{
#ifdef PUGS_HAS_EIGEN3
SECTION
(
"CG"
)
{
LinearSolverOptions
options
;
options
.
library
()
=
LSLibrary
::
eigen3
;
options
.
method
()
=
LSMethod
::
cg
;
options
.
precond
()
=
LSPrecond
::
none
;
options
.
verbose
()
=
true
;
SECTION
(
"CG no preconditioner"
)
{
options
.
precond
()
=
LSPrecond
::
none
;
TinyVector
<
5
>
x
=
zero
;
LinearSolver
solver
{
options
};
solver
.
solveLocalSystem
(
A
,
x
,
b
);
TinyVector
error
=
x
-
x_exact
;
REQUIRE
(
std
::
sqrt
(
dot
(
error
,
error
))
<
1E-10
*
std
::
sqrt
(
dot
(
x_exact
,
x_exact
)));
}
SECTION
(
"CG Diagonal"
)
{
options
.
precond
()
=
LSPrecond
::
diagonal
;
TinyVector
<
5
>
x
=
zero
;
LinearSolver
solver
{
options
};
solver
.
solveLocalSystem
(
A
,
x
,
b
);
TinyVector
error
=
x
-
x_exact
;
REQUIRE
(
std
::
sqrt
(
dot
(
error
,
error
))
<
1E-10
*
std
::
sqrt
(
dot
(
x_exact
,
x_exact
)));
}
SECTION
(
"CG ICholesky"
)
{
options
.
precond
()
=
LSPrecond
::
incomplete_cholesky
;
TinyVector
<
5
>
x
=
zero
;
LinearSolver
solver
{
options
};
REQUIRE_THROWS_WITH
(
solver
.
solveLocalSystem
(
A
,
x
,
b
),
"error: incomplete cholesky is not available for dense matrices in Eigen3"
);
}
SECTION
(
"CG AMG"
)
{
options
.
precond
()
=
LSPrecond
::
amg
;
REQUIRE_THROWS_WITH
(
LinearSolver
{
options
},
"error: AMG is not an Eigen3 preconditioner!"
);
}
}
SECTION
(
"Cholesky"
)
{
LinearSolverOptions
options
;
options
.
library
()
=
LSLibrary
::
eigen3
;
options
.
method
()
=
LSMethod
::
cholesky
;
options
.
precond
()
=
LSPrecond
::
none
;
TinyVector
<
5
>
x
=
zero
;
LinearSolver
solver
{
options
};
solver
.
solveLocalSystem
(
A
,
x
,
b
);
TinyVector
error
=
x
-
x_exact
;
REQUIRE
(
std
::
sqrt
(
dot
(
error
,
error
))
<
1E-10
*
std
::
sqrt
(
dot
(
x_exact
,
x_exact
)));
}
#else // PUGS_HAS_EIGEN3
SECTION
(
"Eigen3 not linked"
)
{
LinearSolverOptions
options
;
options
.
library
()
=
LSLibrary
::
eigen3
;
options
.
method
()
=
LSMethod
::
cg
;
options
.
precond
()
=
LSPrecond
::
none
;
REQUIRE_THROWS_WITH
(
LinearSolver
{
options
},
"error: Eigen3 is not linked to pugs. Cannot use it!"
);
}
#endif // PUGS_HAS_EIGEN3
}
SECTION
(
"PETSc"
)
{
#ifdef PUGS_HAS_PETSC
SECTION
(
"CG"
)
{
LinearSolverOptions
options
;
options
.
library
()
=
LSLibrary
::
petsc
;
options
.
method
()
=
LSMethod
::
cg
;
options
.
precond
()
=
LSPrecond
::
none
;
options
.
verbose
()
=
true
;
SECTION
(
"CG no preconditioner"
)
{
options
.
precond
()
=
LSPrecond
::
none
;
TinyVector
<
5
>
x
=
zero
;
LinearSolver
solver
{
options
};
solver
.
solveLocalSystem
(
A
,
x
,
b
);
TinyVector
error
=
x
-
x_exact
;
REQUIRE
(
std
::
sqrt
(
dot
(
error
,
error
))
<
1E-10
*
std
::
sqrt
(
dot
(
x_exact
,
x_exact
)));
}
SECTION
(
"CG Diagonal"
)
{
options
.
precond
()
=
LSPrecond
::
diagonal
;
TinyVector
<
5
>
x
=
zero
;
LinearSolver
solver
{
options
};
solver
.
solveLocalSystem
(
A
,
x
,
b
);
TinyVector
error
=
x
-
x_exact
;
REQUIRE
(
std
::
sqrt
(
dot
(
error
,
error
))
<
1E-10
*
std
::
sqrt
(
dot
(
x_exact
,
x_exact
)));
}
SECTION
(
"CG ICholesky"
)
{
options
.
precond
()
=
LSPrecond
::
incomplete_cholesky
;
TinyVector
<
5
>
x
=
zero
;
LinearSolver
solver
{
options
};
solver
.
solveLocalSystem
(
A
,
x
,
b
);
TinyVector
error
=
x
-
x_exact
;
REQUIRE
(
std
::
sqrt
(
dot
(
error
,
error
))
<
1E-10
*
std
::
sqrt
(
dot
(
x_exact
,
x_exact
)));
}
SECTION
(
"CG AMG"
)
{
options
.
precond
()
=
LSPrecond
::
amg
;
TinyVector
<
5
>
x
=
zero
;
LinearSolver
solver
{
options
};
solver
.
solveLocalSystem
(
A
,
x
,
b
);
TinyVector
error
=
x
-
x_exact
;
REQUIRE
(
std
::
sqrt
(
dot
(
error
,
error
))
<
1E-10
*
std
::
sqrt
(
dot
(
x_exact
,
x_exact
)));
}
}
SECTION
(
"Cholesky"
)
{
LinearSolverOptions
options
;
options
.
library
()
=
LSLibrary
::
petsc
;
options
.
method
()
=
LSMethod
::
cholesky
;
options
.
precond
()
=
LSPrecond
::
none
;
TinyVector
<
5
>
x
=
zero
;
LinearSolver
solver
{
options
};
solver
.
solveLocalSystem
(
A
,
x
,
b
);
TinyVector
error
=
x
-
x_exact
;
REQUIRE
(
std
::
sqrt
(
dot
(
error
,
error
))
<
1E-10
*
std
::
sqrt
(
dot
(
x_exact
,
x_exact
)));
}
#else // PUGS_HAS_PETSC
SECTION
(
"PETSc not linked"
)
{
LinearSolverOptions
options
;
options
.
library
()
=
LSLibrary
::
petsc
;
options
.
method
()
=
LSMethod
::
cg
;
options
.
precond
()
=
LSPrecond
::
none
;
REQUIRE_THROWS_WITH
(
LinearSolver
{
options
},
"error: PETSc is not linked to pugs. Cannot use it!"
);
}
#endif // PUGS_HAS_PETSC
}
}
SECTION
(
"none symmetric system"
)
{
SECTION
(
"Dense matrix"
)
{
TinyMatrix
<
5
>
A
=
zero
;
A
(
0
,
0
)
=
2
;
A
(
0
,
1
)
=
-
1
;
A
(
1
,
0
)
=
-
0.2
;
A
(
1
,
1
)
=
2
;
A
(
1
,
2
)
=
-
1
;
A
(
2
,
1
)
=
-
1
;
A
(
2
,
2
)
=
4
;
A
(
2
,
3
)
=
-
2
;
A
(
3
,
2
)
=
-
1
;
A
(
3
,
3
)
=
2
;
A
(
3
,
4
)
=
-
0.1
;
A
(
4
,
3
)
=
1
;
A
(
4
,
4
)
=
3
;
const
TinyVector
<
5
>
x_exact
{
1
,
3
,
2
,
4
,
5
};
const
TinyVector
b
=
A
*
x_exact
;
SECTION
(
"builtin"
)
{
SECTION
(
"BICGStab no preconditioner"
)
{
LinearSolverOptions
options
;
options
.
library
()
=
LSLibrary
::
builtin
;
options
.
method
()
=
LSMethod
::
bicgstab
;
options
.
precond
()
=
LSPrecond
::
none
;
TinyVector
<
5
>
x
=
zero
;
LinearSolver
solver
{
options
};
solver
.
solveLocalSystem
(
A
,
x
,
b
);
TinyVector
error
=
x
-
x_exact
;
REQUIRE
(
std
::
sqrt
(
dot
(
error
,
error
))
<
1E-10
*
std
::
sqrt
(
dot
(
x_exact
,
x_exact
)));
}
}
SECTION
(
"Eigen3"
)
{
#ifdef PUGS_HAS_EIGEN3
SECTION
(
"BICGStab"
)
{
LinearSolverOptions
options
;
options
.
library
()
=
LSLibrary
::
eigen3
;
options
.
method
()
=
LSMethod
::
bicgstab
;
options
.
precond
()
=
LSPrecond
::
none
;
options
.
verbose
()
=
true
;
SECTION
(
"BICGStab no preconditioner"
)
{
options
.
precond
()
=
LSPrecond
::
none
;
TinyVector
<
5
>
x
=
zero
;
LinearSolver
solver
{
options
};
solver
.
solveLocalSystem
(
A
,
x
,
b
);
TinyVector
error
=
x
-
x_exact
;
REQUIRE
(
std
::
sqrt
(
dot
(
error
,
error
))
<
1E-10
*
std
::
sqrt
(
dot
(
x_exact
,
x_exact
)));
}
SECTION
(
"BICGStab Diagonal"
)
{
options
.
precond
()
=
LSPrecond
::
diagonal
;
TinyVector
<
5
>
x
=
zero
;
LinearSolver
solver
{
options
};
solver
.
solveLocalSystem
(
A
,
x
,
b
);
TinyVector
error
=
x
-
x_exact
;
REQUIRE
(
std
::
sqrt
(
dot
(
error
,
error
))
<
1E-10
*
std
::
sqrt
(
dot
(
x_exact
,
x_exact
)));
}
SECTION
(
"BICGStab ILU"
)
{
options
.
precond
()
=
LSPrecond
::
incomplete_LU
;
TinyVector
<
5
>
x
=
zero
;
LinearSolver
solver
{
options
};
REQUIRE_THROWS_WITH
(
solver
.
solveLocalSystem
(
A
,
x
,
b
),
"error: incomplete LU is not available for dense matrices in Eigen3"
);
}
}
SECTION
(
"BICGStab2"
)
{
LinearSolverOptions
options
;
options
.
library
()
=
LSLibrary
::
eigen3
;
options
.
method
()
=
LSMethod
::
bicgstab2
;
options
.
precond
()
=
LSPrecond
::
none
;
SECTION
(
"BICGStab2 no preconditioner"
)
{
options
.
precond
()
=
LSPrecond
::
none
;
REQUIRE_THROWS_WITH
(
LinearSolver
{
options
},
"error: BICGStab2 is not an Eigen3 linear solver!"
);
}
}
SECTION
(
"GMRES"
)
{
LinearSolverOptions
options
;
options
.
library
()
=
LSLibrary
::
eigen3
;
options
.
method
()
=
LSMethod
::
gmres
;
options
.
precond
()
=
LSPrecond
::
none
;
SECTION
(
"GMRES no preconditioner"
)
{
options
.
precond
()
=
LSPrecond
::
none
;
TinyVector
<
5
>
x
=
zero
;
LinearSolver
solver
{
options
};
solver
.
solveLocalSystem
(
A
,
x
,
b
);
TinyVector
error
=
x
-
x_exact
;
REQUIRE
(
std
::
sqrt
(
dot
(
error
,
error
))
<
1E-10
*
std
::
sqrt
(
dot
(
x_exact
,
x_exact
)));
}
SECTION
(
"GMRES Diagonal"
)
{
options
.
precond
()
=
LSPrecond
::
diagonal
;
TinyVector
<
5
>
x
=
zero
;
LinearSolver
solver
{
options
};
solver
.
solveLocalSystem
(
A
,
x
,
b
);
TinyVector
error
=
x
-
x_exact
;
REQUIRE
(
std
::
sqrt
(
dot
(
error
,
error
))
<
1E-10
*
std
::
sqrt
(
dot
(
x_exact
,
x_exact
)));
}
SECTION
(
"GMRES ILU"
)
{
options
.
precond
()
=
LSPrecond
::
incomplete_LU
;
TinyVector
<
5
>
x
=
zero
;
LinearSolver
solver
{
options
};
REQUIRE_THROWS_WITH
(
solver
.
solveLocalSystem
(
A
,
x
,
b
),
"error: incomplete LU is not available for dense matrices in Eigen3"
);
}
}
SECTION
(
"LU"
)
{
LinearSolverOptions
options
;
options
.
library
()
=
LSLibrary
::
eigen3
;
options
.
method
()
=
LSMethod
::
lu
;
options
.
precond
()
=
LSPrecond
::
none
;
TinyVector
<
5
>
x
=
zero
;
LinearSolver
solver
{
options
};
solver
.
solveLocalSystem
(
A
,
x
,
b
);
TinyVector
error
=
x
-
x_exact
;
REQUIRE
(
std
::
sqrt
(
dot
(
error
,
error
))
<
1E-10
*
std
::
sqrt
(
dot
(
x_exact
,
x_exact
)));
}
#else // PUGS_HAS_EIGEN3
SECTION
(
"Eigen3 not linked"
)
{
LinearSolverOptions
options
;
options
.
library
()
=
LSLibrary
::
eigen3
;
options
.
method
()
=
LSMethod
::
cg
;
options
.
precond
()
=
LSPrecond
::
none
;
REQUIRE_THROWS_WITH
(
LinearSolver
{
options
},
"error: Eigen3 is not linked to pugs. Cannot use it!"
);
}
#endif // PUGS_HAS_EIGEN3
}
SECTION
(
"PETSc"
)
{
#ifdef PUGS_HAS_PETSC
SECTION
(
"BICGStab"
)
{
LinearSolverOptions
options
;
options
.
library
()
=
LSLibrary
::
petsc
;
options
.
method
()
=
LSMethod
::
bicgstab
;
options
.
precond
()
=
LSPrecond
::
none
;
options
.
verbose
()
=
true
;
SECTION
(
"BICGStab no preconditioner"
)
{
options
.
precond
()
=
LSPrecond
::
none
;
TinyVector
<
5
>
x
=
zero
;
LinearSolver
solver
{
options
};
solver
.
solveLocalSystem
(
A
,
x
,
b
);
TinyVector
error
=
x
-
x_exact
;
REQUIRE
(
std
::
sqrt
(
dot
(
error
,
error
))
<
1E-10
*
std
::
sqrt
(
dot
(
x_exact
,
x_exact
)));
}
SECTION
(
"BICGStab Diagonal"
)
{
options
.
precond
()
=
LSPrecond
::
diagonal
;
TinyVector
<
5
>
x
=
zero
;
LinearSolver
solver
{
options
};
solver
.
solveLocalSystem
(
A
,
x
,
b
);
TinyVector
error
=
x
-
x_exact
;
REQUIRE
(
std
::
sqrt
(
dot
(
error
,
error
))
<
1E-10
*
std
::
sqrt
(
dot
(
x_exact
,
x_exact
)));
}
SECTION
(
"BICGStab ILU"
)
{
options
.
precond
()
=
LSPrecond
::
incomplete_LU
;
TinyVector
<
5
>
x
=
zero
;
LinearSolver
solver
{
options
};
solver
.
solveLocalSystem
(
A
,
x
,
b
);
TinyVector
error
=
x
-
x_exact
;
REQUIRE
(
std
::
sqrt
(
dot
(
error
,
error
))
<
1E-10
*
std
::
sqrt
(
dot
(
x_exact
,
x_exact
)));
}
}
SECTION
(
"BICGStab2"
)
{
LinearSolverOptions
options
;
options
.
library
()
=
LSLibrary
::
petsc
;
options
.
method
()
=
LSMethod
::
bicgstab2
;
options
.
precond
()
=
LSPrecond
::
none
;
SECTION
(
"BICGStab2 no preconditioner"
)
{
options
.
precond
()
=
LSPrecond
::
none
;
TinyVector
<
5
>
x
=
zero
;
LinearSolver
solver
{
options
};
solver
.
solveLocalSystem
(
A
,
x
,
b
);
TinyVector
error
=
x
-
x_exact
;
REQUIRE
(
std
::
sqrt
(
dot
(
error
,
error
))
<
1E-10
*
std
::
sqrt
(
dot
(
x_exact
,
x_exact
)));
}
SECTION
(
"BICGStab2 Diagonal"
)
{
options
.
precond
()
=
LSPrecond
::
diagonal
;
TinyVector
<
5
>
x
=
zero
;
LinearSolver
solver
{
options
};
solver
.
solveLocalSystem
(
A
,
x
,
b
);
TinyVector
error
=
x
-
x_exact
;
REQUIRE
(
std
::
sqrt
(
dot
(
error
,
error
))
<
1E-10
*
std
::
sqrt
(
dot
(
x_exact
,
x_exact
)));
}
}
SECTION
(
"GMRES"
)
{
LinearSolverOptions
options
;
options
.
library
()
=
LSLibrary
::
petsc
;
options
.
method
()
=
LSMethod
::
gmres
;
options
.
precond
()
=
LSPrecond
::
none
;
SECTION
(
"GMRES no preconditioner"
)
{
options
.
precond
()
=
LSPrecond
::
none
;
TinyVector
<
5
>
x
=
zero
;
LinearSolver
solver
{
options
};
solver
.
solveLocalSystem
(
A
,
x
,
b
);
TinyVector
error
=
x
-
x_exact
;
REQUIRE
(
std
::
sqrt
(
dot
(
error
,
error
))
<
1E-10
*
std
::
sqrt
(
dot
(
x_exact
,
x_exact
)));
}
SECTION
(
"GMRES Diagonal"
)
{
options
.
precond
()
=
LSPrecond
::
diagonal
;
TinyVector
<
5
>
x
=
zero
;
LinearSolver
solver
{
options
};
solver
.
solveLocalSystem
(
A
,
x
,
b
);
TinyVector
error
=
x
-
x_exact
;
REQUIRE
(
std
::
sqrt
(
dot
(
error
,
error
))
<
1E-10
*
std
::
sqrt
(
dot
(
x_exact
,
x_exact
)));
}
SECTION
(
"GMRES ILU"
)
{
options
.
precond
()
=
LSPrecond
::
incomplete_LU
;
TinyVector
<
5
>
x
=
zero
;
LinearSolver
solver
{
options
};
solver
.
solveLocalSystem
(
A
,
x
,
b
);
TinyVector
error
=
x
-
x_exact
;
REQUIRE
(
std
::
sqrt
(
dot
(
error
,
error
))
<
1E-10
*
std
::
sqrt
(
dot
(
x_exact
,
x_exact
)));
}
}
SECTION
(
"LU"
)
{
LinearSolverOptions
options
;
options
.
library
()
=
LSLibrary
::
petsc
;
options
.
method
()
=
LSMethod
::
lu
;
options
.
precond
()
=
LSPrecond
::
none
;
TinyVector
<
5
>
x
=
zero
;
LinearSolver
solver
{
options
};
solver
.
solveLocalSystem
(
A
,
x
,
b
);
TinyVector
error
=
x
-
x_exact
;
REQUIRE
(
std
::
sqrt
(
dot
(
error
,
error
))
<
1E-10
*
std
::
sqrt
(
dot
(
x_exact
,
x_exact
)));
}
#else // PUGS_HAS_PETSC
SECTION
(
"PETSc not linked"
)
{
LinearSolverOptions
options
;
options
.
library
()
=
LSLibrary
::
petsc
;
options
.
method
()
=
LSMethod
::
cg
;
options
.
precond
()
=
LSPrecond
::
none
;
REQUIRE_THROWS_WITH
(
LinearSolver
{
options
},
"error: PETSc is not linked to pugs. Cannot use it!"
);
}
#endif // PUGS_HAS_PETSC
}
}
}
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment