Skip to content

Commit

Permalink
test for jse
Browse files Browse the repository at this point in the history
  • Loading branch information
teseoch committed Oct 12, 2023
1 parent 45ec15a commit c9e0868
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
1 change: 0 additions & 1 deletion linear-solver-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"optional": [
"enable_overwrite_solver",
"solver",
"adjoint_solver",
"precond",
"Eigen::LeastSquaresConjugateGradient",
"Eigen::DGMRES",
Expand Down
1 change: 1 addition & 0 deletions src/polysolve/linear/Solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "SaddlePointSolver.hpp"

#include <jse/jse.h>
#include <spdlog/spdlog.h>

#include <fstream>

Expand Down
2 changes: 1 addition & 1 deletion src/polysolve/linear/Solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace polysolve::linear
// Virtual destructor
virtual ~Solver() = default;

static std::unique_ptr<Solver> create(const json &params, spdlog::logger &logger, const bool strict_validation = false);
static std::unique_ptr<Solver> create(const json &params, spdlog::logger &logger, const bool strict_validation = true);

// Static constructor
//
Expand Down
30 changes: 30 additions & 0 deletions tests/test_linear_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
#include <polysolve/Types.hpp>
#include <polysolve/linear/FEMSolver.hpp>

#include <polysolve/Utils.hpp>

#ifdef POLYSOLVE_WITH_AMGCL
#include <polysolve/linear/AMGCL.hpp>
#endif

#include <spdlog/sinks/stdout_color_sinks.h>

#include <catch2/catch.hpp>
#include <iostream>
#include <unsupported/Eigen/SparseExtra>
Expand Down Expand Up @@ -44,6 +48,32 @@ void loadSymmetric(Eigen::SparseMatrix<double> &A, std::string PATH)
fin.close();
A.setFromTriplets(triple.begin(), triple.end());
};

TEST_CASE("jse", "[solver]")
{
const std::string path = POLYFEM_DATA_DIR;
Eigen::SparseMatrix<double> A;
const bool ok = loadMarket(A, path + "/A_2.mat");
REQUIRE(ok);

static std::shared_ptr<spdlog::logger> logger = spdlog::stdout_color_mt("test_logger");
logger->set_level(spdlog::level::warn);

json input = {};
auto solver = Solver::create(input, *logger);
Eigen::VectorXd b(A.rows());
b.setRandom();
Eigen::VectorXd x(b.size());
x.setZero();

solver->analyze_pattern(A, A.rows());
solver->factorize(A);
solver->solve(b, x);
const double err = (A * x - b).norm();
INFO("solver: " + solver->name());
REQUIRE(err < 1e-8);
}

TEST_CASE("all", "[solver]")
{
const std::string path = POLYFEM_DATA_DIR;
Expand Down

0 comments on commit c9e0868

Please sign in to comment.