Skip to content

Commit 300f96c

Browse files
initial skeleton
1 parent 1f52e59 commit 300f96c

21 files changed

+916
-11
lines changed

.clang-format

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
3+
Language: Cpp
4+
BasedOnStyle: LLVM
5+
# ColumnLimit: 80
6+
ColumnLimit: 0
7+
UseTab: Never
8+
IndentWidth: 4
9+
TabWidth: 4
10+
BreakBeforeBraces: Custom
11+
BraceWrapping:
12+
AfterCaseLabel: true
13+
AfterClass: true
14+
AfterControlStatement: Always
15+
AfterEnum: true
16+
AfterFunction: true
17+
AfterNamespace: true
18+
AfterObjCDeclaration: true
19+
AfterStruct: true
20+
AfterUnion: true
21+
AfterExternBlock: true
22+
BeforeCatch: true
23+
BeforeElse: true
24+
BeforeLambdaBody: false
25+
BeforeWhile: false
26+
IndentBraces: false
27+
SplitEmptyFunction: true
28+
SplitEmptyRecord: true
29+
SplitEmptyNamespace: true
30+
AllowShortIfStatementsOnASingleLine: false
31+
IndentCaseLabels: false
32+
SortIncludes: false
33+
BreakStringLiterals: false
34+
AlignTrailingComments: true
35+
FixNamespaceComments: true
36+
ContinuationIndentWidth: 4
37+
NamespaceIndentation: All
38+
AccessModifierOffset: -4
39+
BreakBeforeBinaryOperators: NonAssignment
40+
# ReflowComments: true
41+
# BinPackParameters: false
42+
# AllowAllParametersOfDeclarationOnNextLine: true
43+
# AlignAfterOpenBracket: AlwaysBreak
44+
...

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/**

CMakeLists.txt

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# Detects whether this is a top-level project
2+
get_directory_property(HAS_PARENT PARENT_DIRECTORY)
3+
if(HAS_PARENT)
4+
set(SJV_TOPLEVEL_PROJECT OFF)
5+
else()
6+
set(SJV_TOPLEVEL_PROJECT ON)
7+
endif()
8+
9+
# Check required CMake version
10+
set(REQUIRED_CMAKE_VERSION "3.14.0")
11+
if(SJV_TOPLEVEL_PROJECT)
12+
cmake_minimum_required(VERSION ${REQUIRED_CMAKE_VERSION})
13+
else()
14+
# Don't use cmake_minimum_required here to avoid implicitly overriding parent policies
15+
if(${CMAKE_VERSION} VERSION_LESS ${REQUIRED_CMAKE_VERSION})
16+
message(FATAL_ERROR "CMake required version to build SJV is ${REQUIRED_CMAKE_VERSION}")
17+
endif()
18+
endif()
19+
20+
# Include user-provided default options if available. We do that before the main
21+
# `project()` so that we can define the C/C++ compilers from the option file.
22+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/SJVOptions.cmake)
23+
message(STATUS "Using local options file: ${CMAKE_CURRENT_SOURCE_DIR}/SJVOptions.cmake")
24+
include(${CMAKE_CURRENT_SOURCE_DIR}/SJVOptions.cmake)
25+
endif()
26+
27+
################################################################################
28+
29+
project(SJV
30+
DESCRIPTION "Easy-to-use wrapper for linear solver"
31+
LANGUAGES CXX)
32+
33+
# SJV options
34+
option(SJV_WITH_SANITIZERS "Enable sanitizers in compilation targets" OFF)
35+
# Sanitizer options
36+
option(SJV_SANITIZE_ADDRESS "Sanitize Address" OFF)
37+
option(SJV_SANITIZE_MEMORY "Sanitize Memory" OFF)
38+
option(SJV_SANITIZE_THREAD "Sanitize Thread" OFF)
39+
option(SJV_SANITIZE_UNDEFINED "Sanitize Undefined" OFF)
40+
# Misc.
41+
option(SJV_WITH_TESTS "Build unit-tests" ${SJV_TOPLEVEL_PROJECT})
42+
43+
include(CMakeDependentOption)
44+
45+
# Set default minimum C++ standard
46+
if(SJV_TOPLEVEL_PROJECT)
47+
set(CMAKE_CXX_STANDARD 14)
48+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
49+
set(CMAKE_CXX_EXTENSIONS OFF)
50+
endif()
51+
52+
if (MSVC)
53+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
54+
endif()
55+
56+
### Configuration
57+
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/sjv/")
58+
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/recipes/")
59+
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/find/")
60+
61+
# Color output
62+
include(sjv_use_colors)
63+
64+
# IPC Toolkit utils
65+
include(sjv_prepend_current_path)
66+
include(sjv_set_source_group)
67+
68+
# Sort projects inside the solution
69+
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
70+
71+
# Generate position independent code by default
72+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
73+
74+
################################################################################
75+
# SJV Library
76+
################################################################################
77+
78+
# Add an empty library and fill in the list of sources in `src/CMakeLists.txt`.
79+
add_library(sjv)
80+
add_library(sjv::sjv ALIAS sjv)
81+
82+
add_subdirectory(src)
83+
84+
# Public include directory for SJV
85+
target_include_directories(sjv PUBLIC ${PROJECT_SOURCE_DIR}/src)
86+
87+
################################################################################
88+
# Definitions
89+
################################################################################
90+
91+
if(SJV_LARGE_INDEX)
92+
target_compile_definitions(sjv PUBLIC -DSJV_LARGE_INDEX)
93+
endif()
94+
95+
# No limit yay
96+
target_compile_definitions(sjv PUBLIC -DEIGEN_STACK_ALLOCATION_LIMIT=0)
97+
98+
# 8MB
99+
# target_compile_definitions(sjv PUBLIC -DEIGEN_STACK_ALLOCATION_LIMIT=8388608)
100+
101+
################################################################################
102+
# Dependencies
103+
################################################################################
104+
105+
# Extra warnings
106+
include(sjv_warnings)
107+
target_link_libraries(sjv PRIVATE sjv::warnings)
108+
109+
# Sanitizers
110+
if(SJV_WITH_SANITIZERS)
111+
include(sanitizers)
112+
add_sanitizers(sjv)
113+
endif()
114+
115+
# include(eigen)
116+
# target_link_libraries(SJV PUBLIC Eigen3::Eigen)
117+
118+
# Json (MIT)
119+
include(json)
120+
target_link_libraries(sjv PUBLIC nlohmann::json)
121+
122+
################################################################################
123+
# Compiler options
124+
################################################################################
125+
126+
# Use C++14
127+
target_compile_features(sjv PUBLIC cxx_std_14)
128+
129+
################################################################################
130+
# Tests
131+
################################################################################
132+
133+
# Compile extras only if this is a top-level project
134+
if(SJV_WITH_TESTS)
135+
# Unit tests
136+
include(CTest)
137+
enable_testing()
138+
139+
# Include Catch2 and provide function `catch_discover_tests` to register tests.
140+
include(catch2)
141+
FetchContent_GetProperties(catch2)
142+
include("${catch2_SOURCE_DIR}/contrib/Catch.cmake")
143+
144+
add_subdirectory(tests)
145+
endif()

README.md

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
![Build](https://github.com/polyfem/polysolve/workflows/Build/badge.svg)
2+
3+
4+
5+
# PolySolve
6+
7+
This library contains a cross-platform Eigen wrapper for many different external linear solvers including (but not limited to):
8+
9+
- CHOLMOD
10+
- Hypre
11+
- AMGCL
12+
- Pardiso
13+
14+
15+
## Example Usage
16+
17+
```c++
18+
const std::string solver_name = "Hypre"
19+
auto solver = LinearSolver::create(solver_name, "");
20+
21+
// Configuration parameters like iteration or accuracy for iterative solvers
22+
// solver->setParameters(params);
23+
24+
// System sparse matrix
25+
Eigen::SparseMatrix<double> A;
26+
27+
// Right-hand side
28+
Eigen::VectorXd b;
29+
30+
// Solution
31+
Eigen::VectorXd x(b.size());
32+
33+
solver->analyzePattern(A, A.rows());
34+
solver->factorize(A);
35+
solver->solve(b, x);
36+
```
37+
38+
You can use `LinearSolver::availableSolvers()` to obtain the list of available solvers.
39+
40+
## Parameters
41+
42+
Polysolve uses a json file to provide parameters to the individual solvers. The following template can be used as a starting points, and a more detailed explanation of the parameters is below.
43+
44+
```json
45+
{
46+
"Eigen::LeastSquaresConjugateGradient": {
47+
"max_iter": 1000,
48+
"tolerance": 1e-6
49+
},
50+
"Eigen::DGMRES": {
51+
"max_iter": 1000,
52+
"tolerance": 1e-6
53+
},
54+
"Eigen::ConjugateGradient": {
55+
"max_iter": 1000,
56+
"tolerance": 1e-6
57+
},
58+
"Eigen::BiCGSTAB": {
59+
"max_iter": 1000,
60+
"tolerance": 1e-6
61+
},
62+
"Eigen::GMRES": {
63+
"max_iter": 1000,
64+
"tolerance": 1e-6
65+
},
66+
"Eigen::MINRES": {
67+
"max_iter": 1000,
68+
"tolerance": 1e-6
69+
},
70+
"Pardiso": {
71+
"mtype": -1
72+
},
73+
"Hypre": {
74+
"max_iter": 1000,
75+
"pre_max_iter": 1000,
76+
"tolerance": 1e-6
77+
},
78+
"AMGCL": {
79+
"precond": {
80+
"relax": {
81+
"degree": 16,
82+
"type": "chebyshev",
83+
"power_iters": 100,
84+
"higher": 2,
85+
"lower": 0.008333333333,
86+
"scale": true
87+
},
88+
"class": "amg",
89+
"max_levels": 6,
90+
"direct_coarse": false,
91+
"ncycle": 2,
92+
"coarsening": {
93+
"type": "smoothed_aggregation",
94+
"estimate_spectral_radius": true,
95+
"relax": 1,
96+
"aggr": {
97+
"eps_strong": 0
98+
}
99+
}
100+
},
101+
"solver": {
102+
"tol": 1e-10,
103+
"maxiter": 1000,
104+
"type": "cg"
105+
}
106+
}
107+
}
108+
```
109+
110+
### Iterative solvers (AMGCL, Eigen Internal Solvers, HYPRE)
111+
112+
- `max_iter` controls the solver's iterations, default `1000`
113+
- `conv_tol`, `tolerance` controls the convergence tolerance, default `1e-10`
114+
115+
#### Hypre Only
116+
117+
- `pre_max_iter`, number of pre iterations, default `1`
118+
119+
#### AMGCL Only
120+
121+
The default parameters of the AMGCL solver are:
122+
```json
123+
{
124+
"precond": {
125+
"relax": {
126+
"degree": 16,
127+
"type": "chebyshev",
128+
"power_iters": 100,
129+
"higher": 2,
130+
"lower": 0.008333333333,
131+
"scale": true
132+
},
133+
"class": "amg",
134+
"max_levels": 6,
135+
"direct_coarse": false,
136+
"ncycle": 2,
137+
"coarsening": {
138+
"type": "smoothed_aggregation",
139+
"estimate_spectral_radius": true,
140+
"relax": 1,
141+
"aggr": {
142+
"eps_strong": 0
143+
}
144+
}
145+
},
146+
"solver": {
147+
"tol": 1e-10,
148+
"maxiter": 1000,
149+
"type": "cg"
150+
}
151+
}
152+
```
153+
154+
For a more details and options refer to the [AMGCL documentation](https://amgcl.readthedocs.io/en/latest/components.html).
155+
156+
### Pardiso
157+
158+
`mtype`, sets the matrix type, default 11
159+
160+
| mtype | Description |
161+
| ----- | --------------------------------------- |
162+
| 1 | real and structurally symmetric |
163+
| 2 | real and symmetric positive definite |
164+
| -2 | real and symmetric indefinite |
165+
| 3 | complex and structurally symmetric |
166+
| 4 | complex and Hermitian positive definite |
167+
| -4 | complex and Hermitian indefinite |
168+
| 6 | complex and symmetric |
169+
| 11 | real and nonsymmetric |
170+
| 13 | complex and nonsymmetric |

0 commit comments

Comments
 (0)