Alien  1.3.0
User documentation
Loading...
Searching...
No Matches
LinearSolver.h
Go to the documentation of this file.
1/*
2 * Copyright 2020 IFPEN-CEA
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * SPDX-License-Identifier: Apache-2.0
17 */
18
19/*!
20 * \file LinearSolver.h
21 * \brief LinearSolver.h
22 */
23#pragma once
24
25#include <alien/utils/Precomp.h>
26
27#include <memory>
28
29#include <arccore/base/NotImplementedException.h>
30#include <arccore/base/TraceInfo.h>
31
32#include <alien/core/backend/BackEnd.h>
33#include <alien/core/backend/IInternalLinearSolverT.h>
34
36
37#include <alien/expression/solver/SolverStater.h>
38/*---------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------*/
40
41namespace Alien
42{
43
44/*---------------------------------------------------------------------------*/
45/*---------------------------------------------------------------------------*/
46
47class Space;
48class IVector;
49class IMatrix;
50
51/*---------------------------------------------------------------------------*/
52/*---------------------------------------------------------------------------*/
53
54/*!
55 * \ingroup core
56 * \brief Linear solver interface
57 *
58 * Interface for all linear solver package
59 *
60 * \tparam Tag The tag of the type of solvers used
61 */
62template <class Tag>
64{
65 public:
66 //! The type of the solver
68
69 public:
70 /*!
71 * \brief Creates a linear solver
72 *
73 * Creates a linear solver using traits and the linear solver factory
74 *
75 * \tparam T Variadics type of linear solver
76 * \param[in] args Linear solvers
77 */
78 template <typename... T>
79 LinearSolver(T... args)
80 : m_solver(AlgebraTraits<Tag>::solver_factory(args...))
81 , m_stater(m_solver.get())
82 {}
83
84 //! Free resources
85 virtual ~LinearSolver();
86
87 /*!
88 * \brief Get package back end name
89 * \returns Package back end name
90 */
91 Arccore::String getBackEndName() const;
92
93 //! Initialize the linear solver
94 void init();
95
96 //! Finalize the linear solver
97 void end();
98
99 /*!
100 * \brief update parallel_mng, required for redistribution
101 * For some solver libraries, Solver is kind of a global object
102 * and must be updated accordingly with Matrices and Vectors (Think PETScInit)
103 *
104 * \param[in] pm : new parallel mng
105 */
106 void updateParallelMng(Arccore::MessagePassing::IMessagePassingMng* pm);
107
108 /*!
109 * \brief Solve the linear system A * x = b
110 * \param[in] A The matrix to invert
111 * \param[in] b The right hand side
112 * \param[in,out] x The solution
113 * \returns Solver success or failure
114 */
115 bool solve(const IMatrix& A, const IVector& b, IVector& x);
116
117 /*!
118 * \brief Get statistics on the solve phase
119 *
120 * Get statistics on the solver phase, such as iteration count, initialization time,
121 * solve time, etc.
122 *
123 * \return Solver statistics
124 */
125 const SolverStat& getSolverStat() const;
126
127 /*!
128 * \brief Indicates if the kernel is parallel
129 * \returns Parallel support capability
130 */
131 bool hasParallelSupport() const;
132
133 /*!
134 * \brief Get solver resolution status
135 * \returns The solver status
136 */
137 const SolverStatus& getStatus() const;
138
139 /*!
140 * \brief Get compatible linear algebra
141 * \returns Linear algebra pointer
142 */
143 std::shared_ptr<ILinearAlgebra> algebra() const;
144
145 /*!
146 * \brief Get kernel solver implementation
147 * \return Linear solver actual implementation
148 */
150
151 /*!
152 * \brief Option to add an extra-equation
153 *
154 * Option to add an extra-equation to the linear system such as a constraint equation
155 *
156 * \param[in] flag If the option is activated
157 *
158 * \todo Implement this method
159 */
160 virtual void setNullSpaceConstantOption([[maybe_unused]] bool flag)
161 {
162 throw NotImplementedException(A_FUNCINFO);
163 }
164
165 private:
166 //! The linear solver kernel
167 std::unique_ptr<KernelSolver> m_solver;
169};
170
171/*---------------------------------------------------------------------------*/
172/*---------------------------------------------------------------------------*/
173
174} // namespace Alien
175
176/*---------------------------------------------------------------------------*/
177/*---------------------------------------------------------------------------*/
ILinearSolver.h.
ILinearSolver()
Constructor.
Interface for all matrices.
Definition IMatrix.h:51
Interface for all vectors.
Definition IVector.h:51
void init()
Initialize the linear solver.
const SolverStatus & getStatus() const
Get solver resolution status.
virtual ~LinearSolver()
Free resources.
void updateParallelMng(Arccore::MessagePassing::IMessagePassingMng *pm)
update parallel_mng, required for redistribution For some solver libraries, Solver is kind of a globa...
Arccore::String getBackEndName() const
Get package back end name.
LinearSolver(T... args)
Creates a linear solver.
KernelSolver * implem()
Get kernel solver implementation.
bool hasParallelSupport() const
Indicates if the kernel is parallel.
virtual void setNullSpaceConstantOption(bool flag)
Option to add an extra-equation.
void end()
Finalize the linear solver.
std::shared_ptr< ILinearAlgebra > algebra() const
Get compatible linear algebra.
const SolverStat & getSolverStat() const
Get statistics on the solve phase.
AlgebraTraits< Tag >::solver_type KernelSolver
The type of the solver.
bool solve(const IMatrix &A, const IVector &b, IVector &x)
Solve the linear system A * x = b.
Implementation of an algebraic space.
Definition Space.h:47
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17
Structure to store a solver status.