Skip to content

Commit a376e0d

Browse files
committed
Add Trilinos
1 parent 9ca0ffc commit a376e0d

File tree

8 files changed

+569
-2
lines changed

8 files changed

+569
-2
lines changed

CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ option(POLYSOLVE_WITH_PARDISO "Enable Pardiso library"
8080
option(POLYSOLVE_WITH_HYPRE "Enable hypre" ON)
8181
option(POLYSOLVE_WITH_AMGCL "Use AMGCL" ON)
8282
option(POLYSOLVE_WITH_SPECTRA "Enable Spectra library" ON)
83+
option(POLYSOLVE_WITH_TRILINOS "Enable Trilinos" ON)
84+
option(BUILD_TRILINOS_FROM_SOURCE "Build trilinos from source" OFF)
8385

8486
# Sanitizer options
8587
option(POLYSOLVE_SANITIZE_ADDRESS "Sanitize Address" OFF)
@@ -217,7 +219,7 @@ include(jse)
217219
target_link_libraries(polysolve_linear PUBLIC jse::jse)
218220

219221
# Hypre (GNU Lesser General Public License)
220-
if(POLYSOLVE_WITH_HYPRE)
222+
if(POLYSOLVE_WITH_HYPRE AND NOT POLYSOLVE_WITH_TRILINOS)
221223
include(hypre)
222224
target_link_libraries(polysolve_linear PUBLIC HYPRE::HYPRE)
223225
target_compile_definitions(polysolve_linear PRIVATE -DPOLYSOLVE_WITH_HYPRE)
@@ -283,6 +285,13 @@ if(POLYSOLVE_WITH_SPECTRA)
283285
target_compile_definitions(polysolve_linear PRIVATE -DPOLYSOLVE_WITH_SPECTRA)
284286
endif()
285287

288+
# Trilinos
289+
if (POLYSOLVE_WITH_TRILINOS)
290+
include(trilinos)
291+
target_link_libraries(polysolve_linear PUBLIC Trilinos::Trilinos)
292+
target_compile_definitions(polysolve_linear PRIVATE -DPOLYSOLVE_WITH_TRILINOS)
293+
endif()
294+
286295
# cuSolver solvers
287296
if(POLYSOLVE_WITH_CUSOLVER)
288297
include(cusolverdn)

cmake/recipes/trilinos.cmake

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
if(TARGET Trilinos::Trilinos)
2+
return()
3+
endif()
4+
5+
message(STATUS "Third-party: creating target 'Trilinos::Trilinos'")
6+
7+
find_package(Trilinos COMPONENTS ML Epetra)
8+
9+
if(NOT Trilinos_FOUND)
10+
message("Trilinos not found.")
11+
endif()
12+
13+
find_package(MPI)
14+
15+
if(NOT MPI_FOUND)
16+
message("MPI not found.")
17+
endif()
18+
19+
MESSAGE("\nFound Trilinos! Here are the details: ")
20+
MESSAGE(" Trilinos_DIR = ${Trilinos_DIR}")
21+
MESSAGE(" Trilinos_VERSION = ${Trilinos_VERSION}")
22+
MESSAGE(" Trilinos_PACKAGE_LIST = ${Trilinos_PACKAGE_LIST}")
23+
MESSAGE(" Trilinos_LIBRARIES = ${Trilinos_LIBRARIES} ")
24+
MESSAGE(" Trilinos_INCLUDE_DIRS = ${Trilinos_INCLUDE_DIRS} ")
25+
MESSAGE(" Trilinos_TPL_LIST = ${Trilinos_TPL_LIST}")
26+
MESSAGE(" Trilinos_TPL_LIBRARIES = ${Trilinos_TPL_LIBRARIES}")
27+
MESSAGE(" Trilinos_BUILD_SHARED_LIBS = ${Trilinos_BUILD_SHARED_LIBS}")
28+
MESSAGE("End of Trilinos details\n")
29+
# include(trilinos)
30+
if(TARGET Trilinos::Trilinos)
31+
else()
32+
add_library(trilinos INTERFACE)
33+
add_library(Trilinos::Trilinos ALIAS trilinos)
34+
target_include_directories(trilinos INTERFACE ${Trilinos_INCLUDE_DIRS} )
35+
target_link_libraries(trilinos INTERFACE ${Trilinos_LIBRARIES} )
36+
target_link_libraries(trilinos INTERFACE MPI::MPI_C MPI::MPI_CXX )
37+
endif()

linear-solver-spec.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"Eigen::MINRES",
1616
"Pardiso",
1717
"Hypre",
18-
"AMGCL"
18+
"AMGCL",
19+
"Trilinos"
1920
],
2021
"doc": "Settings for the linear solver."
2122
},
@@ -42,6 +43,7 @@
4243
"Pardiso",
4344
"Hypre",
4445
"AMGCL",
46+
"Trilinos",
4547
"Eigen::LeastSquaresConjugateGradient",
4648
"Eigen::DGMRES",
4749
"Eigen::ConjugateGradient",
@@ -153,6 +155,16 @@
153155
],
154156
"doc": "Settings for the AMGCL solver."
155157
},
158+
{
159+
"pointer": "/Trilinos",
160+
"default": null,
161+
"type": "object",
162+
"optional": [
163+
"solver",
164+
"precond"
165+
],
166+
"doc": "Settings for the Trilinos solver."
167+
},
156168
{
157169
"pointer": "/Eigen::LeastSquaresConjugateGradient/max_iter",
158170
"default": 1000,

src/polysolve/linear/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ set(SOURCES
1515
Pardiso.hpp
1616
SaddlePointSolver.cpp
1717
SaddlePointSolver.hpp
18+
TrilinosSolver.cpp
19+
TrilinosSolver.hpp
1820
)
1921

2022
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" PREFIX "Source Files" FILES ${SOURCES})

src/polysolve/linear/Solver.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,42 @@
3636
#ifdef POLYSOLVE_WITH_AMGCL
3737
#include "AMGCL.hpp"
3838
#endif
39+
#ifdef POLYSOLVE_WITH_TRILINOS
40+
#include "TrilinosSolver.hpp"
41+
#endif
3942
#ifdef POLYSOLVE_WITH_CUSOLVER
4043
#include "CuSolverDN.cuh"
4144
#endif
4245
#include <unsupported/Eigen/IterativeSolvers>
4346

4447
////////////////////////////////////////////////////////////////////////////////
48+
Eigen::MatrixXd test_vertices;
49+
Eigen::MatrixXd init_vertices;
50+
std::vector<int> test_boundary_nodes;
51+
Eigen::MatrixXd remove_boundary_vertices(const Eigen::MatrixXd &vertices, const std::vector<int> &boundary_nodes)
52+
{
53+
// Remove boundary vertices
54+
if (boundary_nodes.empty())
55+
{
56+
return vertices;
57+
}
58+
else
59+
{
60+
std::vector<int> order_nodes = boundary_nodes;
61+
std::sort(order_nodes.begin(), order_nodes.end());
62+
Eigen::MatrixXd out_vertices;
63+
std::vector<int> keep;
64+
for (int i = 0; i < vertices.rows(); i++)
65+
{
66+
if (!std::binary_search(order_nodes.begin(), order_nodes.end(),i))
67+
{
68+
keep.push_back(i);
69+
}
70+
}
71+
out_vertices = vertices(keep, Eigen::all);
72+
return out_vertices;
73+
}
74+
}
4575

4676
namespace polysolve::linear
4777
{
@@ -377,6 +407,12 @@ namespace polysolve::linear
377407
{
378408
return std::make_unique<AMGCL>();
379409
#endif
410+
#ifdef POLYSOLVE_WITH_TRILINOS
411+
}
412+
else if (solver == "Trilinos")
413+
{
414+
return std::make_unique<TrilinosSolver>();
415+
#endif
380416
#if EIGEN_VERSION_AT_LEAST(3, 3, 0)
381417
// Available only with Eigen 3.3.0 and newer
382418
#ifndef POLYSOLVE_LARGE_INDEX
@@ -499,6 +535,9 @@ namespace polysolve::linear
499535
#ifdef POLYSOLVE_WITH_AMGCL
500536
"AMGCL",
501537
#endif
538+
#ifdef POLYSOLVE_WITH_TRILINOS
539+
"Trilinos",
540+
#endif
502541
#if EIGEN_VERSION_AT_LEAST(3, 3, 0)
503542
#ifndef POLYSOLVE_LARGE_INDEX
504543
"Eigen::LeastSquaresConjugateGradient",

src/polysolve/linear/Solver.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,21 @@
44

55
#include <memory>
66

7+
#include <Eigen/Dense>
8+
#include <Eigen/Sparse>
9+
#include <vector>
10+
711
#define POLYSOLVE_DELETE_MOVE_COPY(Base) \
812
Base(Base &&) = delete; \
913
Base &operator=(Base &&) = delete; \
1014
Base(const Base &) = delete; \
1115
Base &operator=(const Base &) = delete;
1216

17+
extern Eigen::MatrixXd init_vertices;
18+
extern Eigen::MatrixXd test_vertices;
19+
extern std::vector<int> test_boundary_nodes;
20+
Eigen::MatrixXd remove_boundary_vertices(const Eigen::MatrixXd &vertices, const std::vector<int> &boundary_nodes);
21+
1322
////////////////////////////////////////////////////////////////////////////////
1423
// TODO:
1524
// - [ ] Support both RowMajor + ColumnMajor sparse matrices
@@ -25,6 +34,11 @@ namespace spdlog
2534

2635
namespace polysolve::linear
2736
{
37+
#ifdef POLYSOLVE_LARGE_INDEX
38+
typedef Eigen::SparseMatrix<double, Eigen::ColMajor, std::ptrdiff_t> StiffnessMatrix;
39+
#else
40+
typedef Eigen::SparseMatrix<double, Eigen::ColMajor> StiffnessMatrix;
41+
#endif
2842
/**
2943
* @brief Base class for linear solver.
3044
*/

0 commit comments

Comments
 (0)