Skip to content
Snippets Groups Projects
Commit 0fbeeb7b authored by Tom Fischer's avatar Tom Fischer
Browse files

[NL|MaL] Move NL::LinearSolverBehaviour to MathLib

parent 62781589
No related branches found
No related tags found
No related merge requests found
......@@ -63,7 +63,7 @@ public:
}
bool compute(Matrix& A, EigenOption& opt,
NumLib::LinearSolverBehaviour const linear_solver_behaviour)
MathLib::LinearSolverBehaviour const linear_solver_behaviour)
{
#ifdef USE_EIGEN_UNSUPPORTED
if (opt.scaling)
......@@ -83,7 +83,7 @@ protected:
virtual bool computeImpl(
Matrix& A, EigenOption& opt,
NumLib::LinearSolverBehaviour const linear_solver_behaviour) = 0;
MathLib::LinearSolverBehaviour const linear_solver_behaviour) = 0;
private:
#ifdef USE_EIGEN_UNSUPPORTED
......@@ -114,7 +114,7 @@ public:
}
bool computeImpl(Matrix& A, EigenOption& opt,
[[maybe_unused]] NumLib::LinearSolverBehaviour const
[[maybe_unused]] MathLib::LinearSolverBehaviour const
linear_solver_behaviour) override
{
INFO("-> compute with Eigen direct linear solver {:s}",
......@@ -243,7 +243,7 @@ class EigenIterativeLinearSolver final : public EigenLinearSolverBase
public:
bool computeImpl(
Matrix& A, EigenOption& opt,
NumLib::LinearSolverBehaviour const linear_solver_behaviour) override
MathLib::LinearSolverBehaviour const linear_solver_behaviour) override
{
INFO("-> compute with Eigen iterative linear solver {:s} (precon {:s})",
EigenOption::getSolverName(opt.solver_type),
......@@ -276,7 +276,7 @@ public:
switch (linear_solver_behaviour)
{
case NumLib::LinearSolverBehaviour::RECOMPUTE_AND_STORE:
case MathLib::LinearSolverBehaviour::RECOMPUTE_AND_STORE:
{
// matrix must be copied, because Eigen's linear solver stores a
// reference to it cf.
......@@ -285,12 +285,12 @@ public:
compute(A_);
break;
}
case NumLib::LinearSolverBehaviour::RECOMPUTE:
case MathLib::LinearSolverBehaviour::RECOMPUTE:
{
compute(A);
break;
}
case NumLib::LinearSolverBehaviour::REUSE:
case MathLib::LinearSolverBehaviour::REUSE:
OGS_FATAL(
"If NumLib::LinearSolverBehaviour::REUSE is set then "
"EigenLinearSolver::compute() should never be executed");
......@@ -495,7 +495,8 @@ EigenLinearSolver::EigenLinearSolver(std::string const& /*solver_name*/,
EigenLinearSolver::~EigenLinearSolver() = default;
bool EigenLinearSolver::compute(
EigenMatrix& A, NumLib::LinearSolverBehaviour const linear_solver_behaviour)
EigenMatrix& A,
MathLib::LinearSolverBehaviour const linear_solver_behaviour)
{
INFO("------------------------------------------------------------------");
INFO("*** Eigen solver compute()");
......@@ -513,7 +514,7 @@ bool EigenLinearSolver::solve(EigenVector& b, EigenVector& x)
bool EigenLinearSolver::solve(
EigenMatrix& A, EigenVector& b, EigenVector& x,
NumLib::LinearSolverBehaviour const linear_solver_behaviour)
MathLib::LinearSolverBehaviour const linear_solver_behaviour)
{
return solver_->compute(A.getRawMatrix(), option_,
linear_solver_behaviour) &&
......
......@@ -14,7 +14,7 @@
#include <vector>
#include "EigenOption.h"
#include "NumLib/ODESolver/NonlinearSystem.h"
#include "MathLib/LinAlg/LinearSolverBehaviour.h"
namespace MathLib
{
......@@ -54,7 +54,7 @@ public:
* computes the preconditioner of an iterative solver.
*/
bool compute(EigenMatrix& A,
NumLib::LinearSolverBehaviour const linear_solver_behaviour);
MathLib::LinearSolverBehaviour const linear_solver_behaviour);
/**
* Solves the linear system for the given right-hand side \c b and initial
* guess \c x.
......@@ -68,8 +68,8 @@ public:
bool solve(EigenMatrix& A,
EigenVector& b,
EigenVector& x,
NumLib::LinearSolverBehaviour const linear_solver_behaviour =
NumLib::LinearSolverBehaviour::RECOMPUTE);
MathLib::LinearSolverBehaviour const linear_solver_behaviour =
MathLib::LinearSolverBehaviour::RECOMPUTE);
protected:
EigenOption option_;
......
/**
* \file
* \copyright
* Copyright (c) 2012-2024, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#pragma once
namespace MathLib
{
enum class LinearSolverBehaviour : int
{
RECOMPUTE,
RECOMPUTE_AND_STORE,
REUSE
};
} // namespace MathLib
......@@ -29,13 +29,14 @@ namespace detail
#if !defined(USE_PETSC) && !defined(USE_LIS)
bool solvePicard(GlobalLinearSolver& linear_solver, GlobalMatrix& A,
GlobalVector& rhs, GlobalVector& x,
LinearSolverBehaviour const linear_solver_behaviour)
MathLib::LinearSolverBehaviour const linear_solver_behaviour)
{
BaseLib::RunTime time_linear_solver;
time_linear_solver.start();
if (linear_solver_behaviour == LinearSolverBehaviour::RECOMPUTE ||
linear_solver_behaviour == LinearSolverBehaviour::RECOMPUTE_AND_STORE)
if (linear_solver_behaviour == MathLib::LinearSolverBehaviour::RECOMPUTE ||
linear_solver_behaviour ==
MathLib::LinearSolverBehaviour::RECOMPUTE_AND_STORE)
{
if (!linear_solver.compute(A, linear_solver_behaviour))
{
......@@ -60,10 +61,11 @@ bool solvePicard(GlobalLinearSolver& linear_solver, GlobalMatrix& A,
#else
bool solvePicard(GlobalLinearSolver& linear_solver, GlobalMatrix& A,
GlobalVector& rhs, GlobalVector& x,
LinearSolverBehaviour const linear_solver_behaviour)
MathLib::LinearSolverBehaviour const linear_solver_behaviour)
{
if (linear_solver_behaviour == LinearSolverBehaviour::RECOMPUTE_AND_STORE ||
linear_solver_behaviour == LinearSolverBehaviour::REUSE)
if (linear_solver_behaviour ==
MathLib::LinearSolverBehaviour::RECOMPUTE_AND_STORE ||
linear_solver_behaviour == MathLib::LinearSolverBehaviour::REUSE)
{
WARN(
"The performance optimization to skip the linear solver compute() "
......
......@@ -11,18 +11,11 @@
#pragma once
#include "EquationSystem.h"
#include "MathLib/LinAlg/LinearSolverBehaviour.h"
#include "Types.h"
namespace NumLib
{
enum class LinearSolverBehaviour : int
{
RECOMPUTE,
RECOMPUTE_AND_STORE,
REUSE
};
//! \addtogroup ODESolver
//! @{
......@@ -137,7 +130,8 @@ public:
//! Returns whether the assembled matrix \f$A\f$ has changed and the linear
//! solver must perform the MathLib::EigenLinearSolver::compute() step.
virtual LinearSolverBehaviour linearSolverNeedsToCompute() const = 0;
virtual MathLib::LinearSolverBehaviour linearSolverNeedsToCompute()
const = 0;
};
//! @}
......
......@@ -234,21 +234,21 @@ public:
return _ode.getMatrixSpecifications(process_id);
}
LinearSolverBehaviour linearSolverNeedsToCompute() const override
MathLib::LinearSolverBehaviour linearSolverNeedsToCompute() const override
{
if (_ode.shouldLinearSolverComputeOnlyUponTimestepChange() &&
_time_disc.getCurrentTimeIncrement() !=
_time_disc.getPreviousTimeIncrement())
{
return LinearSolverBehaviour::RECOMPUTE_AND_STORE;
return MathLib::LinearSolverBehaviour::RECOMPUTE_AND_STORE;
}
if (_ode.shouldLinearSolverComputeOnlyUponTimestepChange() &&
_time_disc.getCurrentTimeIncrement() ==
_time_disc.getPreviousTimeIncrement())
{
return LinearSolverBehaviour::REUSE;
return MathLib::LinearSolverBehaviour::REUSE;
}
return LinearSolverBehaviour::RECOMPUTE;
return MathLib::LinearSolverBehaviour::RECOMPUTE;
}
private:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment