Skip to content

Commit

Permalink
Merge pull request #40 from polyfem/nl-solver
Browse files Browse the repository at this point in the history
Nl solver
  • Loading branch information
teseoch authored Nov 9, 2023
2 parents a9b49b8 + 9c516c8 commit 96aa986
Show file tree
Hide file tree
Showing 77 changed files with 6,913 additions and 1,065 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
cd build
ctest --verbose --output-on-failure
lcov --directory . --capture --output-file coverage.info
lcov --remove coverage.info '/usr/*' "${HOME}"'/.cache/*' '*tests/*.cpp' --output-file coverage.info
lcov --remove coverage.info '/usr/*' "${HOME}"'/.cache/*' '*tests/*.cpp' '*tests/*.h' --output-file coverage.info
- name: Upload Coverage
uses: codecov/codecov-action@v3
Expand Down
93 changes: 65 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ endif()

# Set default minimum C++ standard
if(POLYSOLVE_TOPLEVEL_PROJECT)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()
Expand Down Expand Up @@ -145,28 +145,65 @@ endif()
################################################################################

# Add an empty library and fill in the list of sources in `src/CMakeLists.txt`.
add_library(polysolve_linear)
add_library(polysolve::linear ALIAS polysolve_linear)
add_subdirectory(src/polysolve)
add_subdirectory(src/polysolve/linear)

add_library(polysolve)
add_library(polysolve::polysolve ALIAS polysolve)
add_subdirectory(src/polysolve/nonlinear)

target_link_libraries(polysolve_linear PUBLIC polysolve_coverage_config)
target_link_libraries(polysolve PUBLIC polysolve_coverage_config)

add_subdirectory(src/polysolve)


target_compile_features(polysolve_linear PUBLIC cxx_std_17)
target_compile_features(polysolve PUBLIC cxx_std_17)

# Public include directory for Polysolve
target_include_directories(polysolve_linear PUBLIC ${PROJECT_SOURCE_DIR}/src)
target_include_directories(polysolve PUBLIC ${PROJECT_SOURCE_DIR}/src)

################################################################################
# Definitions
################################################################################

if(POLYSOLVE_LARGE_INDEX)
target_compile_definitions(polysolve PUBLIC -DPOLYSOLVE_LARGE_INDEX)
target_compile_definitions(polysolve_linear PUBLIC -DPOLYSOLVE_LARGE_INDEX)
endif()

target_compile_definitions(polysolve_linear PUBLIC -DPOLYSOLVE_LINEAR_SPEC="${CMAKE_SOURCE_DIR}/linear-solver-spec.json")
target_compile_definitions(polysolve_linear PUBLIC -DPOLYSOLVE_NON_LINEAR_SPEC="${CMAKE_SOURCE_DIR}/non-linear-solver-spec.json")


################################################################################
# Dependencies
################################################################################

# polysolve_linear
target_link_libraries(polysolve PUBLIC polysolve::linear)

# CppNumericalSolvers
include(cppoptlib)
target_link_libraries(polysolve PUBLIC cppoptlib)

# LBFGSpp
include(LBFGSpp)
target_link_libraries(polysolve PUBLIC LBFGSpp::LBFGSpp)




# JSON Specification Engine library
include(jse)
target_link_libraries(polysolve_linear PUBLIC jse::jse)

# spdlog
include(spdlog)
target_link_libraries(polysolve_linear PUBLIC spdlog::spdlog)

# Accelerate solver
if(POLYSOLVE_WITH_ACCELERATE)
include(CPM)
Expand All @@ -179,61 +216,63 @@ if(POLYSOLVE_WITH_ACCELERATE)
set(BLA_VENDOR Apple)
find_package(BLAS REQUIRED)
find_package(LAPACK REQUIRED)
target_link_libraries(polysolve PRIVATE BLAS::BLAS LAPACK::LAPACK)
target_link_libraries(polysolve_linear PRIVATE BLAS::BLAS LAPACK::LAPACK)
endif()

# Extra warnings
include(polysolve_warnings)
target_link_libraries(polysolve_linear PRIVATE polysolve::warnings)
target_link_libraries(polysolve PRIVATE polysolve::warnings)

# Sanitizers
if(POLYSOLVE_WITH_SANITIZERS)
include(sanitizers)
add_sanitizers(polysolve_linear)
add_sanitizers(polysolve)
endif()

include(eigen)
target_link_libraries(polysolve PUBLIC Eigen3::Eigen)
target_link_libraries(polysolve_linear PUBLIC Eigen3::Eigen)

# Hypre (GNU Lesser General Public License)
if(POLYSOLVE_WITH_HYPRE)
include(hypre)
target_link_libraries(polysolve PUBLIC HYPRE::HYPRE)
target_compile_definitions(polysolve PUBLIC -DPOLYSOLVE_WITH_HYPRE)
target_link_libraries(polysolve_linear PUBLIC HYPRE::HYPRE)
target_compile_definitions(polysolve_linear PRIVATE -DPOLYSOLVE_WITH_HYPRE)
if(HYPRE_WITH_MPI)
target_compile_definitions(polysolve PUBLIC HYPRE_WITH_MPI)
target_compile_definitions(polysolve_linear PUBLIC HYPRE_WITH_MPI)
endif()
endif()

# Json (MIT)
include(json)
target_link_libraries(polysolve PUBLIC nlohmann_json::nlohmann_json)
target_link_libraries(polysolve_linear PUBLIC nlohmann_json::nlohmann_json)

# Accelerate solvers
if(POLYSOLVE_WITH_ACCELERATE)
target_compile_definitions(polysolve PUBLIC -DPOLYSOLVE_WITH_ACCELERATE)
target_compile_definitions(polysolve_linear PRIVATE -DPOLYSOLVE_WITH_ACCELERATE)
endif()

# CHOLMOD solver
if(POLYSOLVE_WITH_CHOLMOD)
include(suitesparse)
target_link_libraries(polysolve PRIVATE SuiteSparse::CHOLMOD)
target_compile_definitions(polysolve PUBLIC -DPOLYSOLVE_WITH_CHOLMOD)
target_link_libraries(polysolve_linear PRIVATE SuiteSparse::CHOLMOD)
target_compile_definitions(polysolve_linear PRIVATE -DPOLYSOLVE_WITH_CHOLMOD)
endif()

# MKL library
if(POLYSOLVE_WITH_MKL)
include(mkl)
target_link_libraries(polysolve PRIVATE mkl::mkl)
target_compile_definitions(polysolve PUBLIC -DPOLYSOLVE_WITH_MKL)
target_link_libraries(polysolve_linear PRIVATE mkl::mkl)
target_compile_definitions(polysolve_linear PRIVATE -DPOLYSOLVE_WITH_MKL)
endif()

# Pardiso solver
if(POLYSOLVE_WITH_PARDISO)
include(pardiso)
if(TARGET Pardiso::Pardiso)
target_link_libraries(polysolve PRIVATE Pardiso::Pardiso)
target_compile_definitions(polysolve PUBLIC -DPOLYSOLVE_WITH_PARDISO)
target_link_libraries(polysolve_linear PRIVATE Pardiso::Pardiso)
target_compile_definitions(polysolve_linear PRIVATE -DPOLYSOLVE_WITH_PARDISO)
else()
message(WARNING "Pardiso not found, solver will not be available.")
endif()
Expand All @@ -242,16 +281,16 @@ endif()
# UmfPack solver
if(POLYSOLVE_WITH_UMFPACK)
include(suitesparse)
target_link_libraries(polysolve PRIVATE SuiteSparse::UMFPACK)
target_compile_definitions(polysolve PUBLIC -DPOLYSOLVE_WITH_UMFPACK)
target_link_libraries(polysolve_linear PRIVATE SuiteSparse::UMFPACK)
target_compile_definitions(polysolve_linear PRIVATE -DPOLYSOLVE_WITH_UMFPACK)
endif()

# SuperLU solver
if(POLYSOLVE_WITH_SUPERLU)
include(superlu)
if(TARGET SuperLU::SuperLU)
target_link_libraries(polysolve PRIVATE SuperLU::SuperLU)
target_compile_definitions(polysolve PUBLIC -DPOLYSOLVE_WITH_SUPERLU)
target_link_libraries(polysolve_linear PRIVATE SuperLU::SuperLU)
target_compile_definitions(polysolve_linear PRIVATE -DPOLYSOLVE_WITH_SUPERLU)
else()
message(WARNING "SuperLU not found, solver will not be available.")
endif()
Expand All @@ -260,23 +299,23 @@ endif()
# AMGCL solver
if(POLYSOLVE_WITH_AMGCL)
include(amgcl)
target_link_libraries(polysolve PUBLIC amgcl::amgcl)
target_compile_definitions(polysolve PUBLIC -DPOLYSOLVE_WITH_AMGCL)
target_link_libraries(polysolve_linear PUBLIC amgcl::amgcl)
target_compile_definitions(polysolve_linear PRIVATE -DPOLYSOLVE_WITH_AMGCL)
endif()

# Spectra (MPL 2.0)
if(POLYSOLVE_WITH_SPECTRA)
include(spectra)
target_link_libraries(polysolve PUBLIC Spectra::Spectra)
target_compile_definitions(polysolve PUBLIC -DPOLYSOLVE_WITH_SPECTRA)
target_link_libraries(polysolve_linear PUBLIC Spectra::Spectra)
target_compile_definitions(polysolve_linear PRIVATE -DPOLYSOLVE_WITH_SPECTRA)
endif()

# cuSolver solvers
if(POLYSOLVE_WITH_CUSOLVER)
include(cusolverdn)
if(TARGET CUDA::cusolver)
target_link_libraries(polysolve PUBLIC CUDA::cusolver)
target_compile_definitions(polysolve PUBLIC -DPOLYSOLVE_WITH_CUSOLVER)
target_link_libraries(polysolve_linear PUBLIC CUDA::cusolver)
target_compile_definitions(polysolve_linear PRIVATE -DPOLYSOLVE_WITH_CUSOLVER)
else()
message(WARNING "cuSOLVER not found, solver will not be available.")
endif()
Expand All @@ -286,8 +325,6 @@ endif()
# Compiler options
################################################################################

# Use C++14
target_compile_features(polysolve PUBLIC cxx_std_14)

################################################################################
# Tests
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ This library contains a cross-platform Eigen wrapper for many different external

```c++
const std::string solver_name = "Hypre"
auto solver = LinearSolver::create(solver_name, "");
auto solver = Solver::create(solver_name, "");

// Configuration parameters like iteration or accuracy for iterative solvers
// solver->setParameters(params);
// solver->set_parameters(params);

// System sparse matrix
Eigen::SparseMatrix<double> A;
Expand All @@ -29,12 +29,12 @@ Eigen::VectorXd b;
// Solution
Eigen::VectorXd x(b.size());

solver->analyzePattern(A, A.rows());
solver->analyze_pattern(A, A.rows());
solver->factorize(A);
solver->solve(b, x);
```
You can use `LinearSolver::availableSolvers()` to obtain the list of available solvers.
You can use `Solver::available_solvers()` to obtain the list of available solvers.
## Parameters
Expand Down
20 changes: 20 additions & 0 deletions cmake/recipes/LBFGSpp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# LBFGSpp (https://github.com/yixuan/LBFGSpp)
# License: MIT

if(TARGET LBGFSpp::LBGFSpp)
return()
endif()

message(STATUS "Third-party: creating target 'LBGFSpp::LBGFSpp'")

include(CPM)
CPMAddPackage(
NAME lbfgspp
GITHUB_REPOSITORY yixuan/LBFGSpp
GIT_TAG v0.2.0
DOWNLOAD_ONLY TRUE
)

add_library(LBFGSpp INTERFACE)
target_include_directories(LBFGSpp INTERFACE "${lbfgspp_SOURCE_DIR}/include")
add_library(LBFGSpp::LBFGSpp ALIAS LBFGSpp)
19 changes: 19 additions & 0 deletions cmake/recipes/cppoptlib.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# CppNumericalSolvers (https://github.com/PatWie/CppNumericalSolvers.git)
# License: MIT

if(TARGET cppoptlib)
return()
endif()

message(STATUS "Third-party: creating target 'cppoptlib'")

include(CPM)
CPMAddPackage(
NAME cppoptlib
GITHUB_REPOSITORY PatWie/CppNumericalSolvers
GIT_TAG 7eddf28fa5a8872a956d3c8666055cac2f5a535d
DOWNLOAD_ONLY TRUE
)

add_library(cppoptlib INTERFACE)
target_include_directories(cppoptlib SYSTEM INTERFACE ${cppoptlib_SOURCE_DIR}/include)
11 changes: 11 additions & 0 deletions cmake/recipes/jse.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# json spec engine (https://github.com/geometryprocessing/json-spec-engine)
# License: MIT

if(TARGET jse::jse)
return()
endif()

message(STATUS "Third-party: creating target 'jse::jse'")

include(CPM)
CPMAddPackage("gh:geometryprocessing/json-spec-engine#1261dc89478c7646ff99cbed8bc5357c2813565d")
37 changes: 37 additions & 0 deletions cmake/recipes/spdlog.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#
# Copyright 2020 Adobe. All rights reserved.
# This file is licensed to you under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. You may obtain a copy
# of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
# OF ANY KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.
#

# spdlog (https://github.com/gabime/spdlog)
# License: MIT

if(TARGET spdlog::spdlog)
return()
endif()

message(STATUS "Third-party: creating target 'spdlog::spdlog'")

option(SPDLOG_INSTALL "Generate the install target" ON)
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "spdlog")

include(CPM)
CPMAddPackage("gh:gabime/[email protected]")

set_target_properties(spdlog PROPERTIES POSITION_INDEPENDENT_CODE ON)

set_target_properties(spdlog PROPERTIES FOLDER external)

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang" OR
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
target_compile_options(spdlog PRIVATE
"-Wno-sign-conversion"
)
endif()
Loading

0 comments on commit 96aa986

Please sign in to comment.