Alien  1.3.0
User documentation
Loading...
Searching...
No Matches
EigenSolver.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7#pragma once
8
9#include <arccore/message_passing/MessagePassingGlobal.h>
10#include <alien/utils/Precomp.h>
11
12#include <memory>
13#include <vector>
14
15#include <alien/core/backend/BackEnd.h>
17
18/*---------------------------------------------------------------------------*/
19/*---------------------------------------------------------------------------*/
20
21namespace Alien
22{
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27class IVector;
28class IMatrix;
29class IOptions;
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
34/*!
35 * \ingroup core
36 * \brief Eigen problem definition
37 *
38 * Allows to specify the matrix and get the number of eigen vectors as well as the eigen
39 * vectors
40 *
41 * \tparam Tag The type of kernel used to compute eigen values
42 * \tparam VectorT The type of kernel used to store eigen vectors
43 */
44// FIXME: not implemented !
45template <class Tag, typename VectorT>
47{
48 public:
49 /*!
50 * \brief Eigen problem constructor
51 * \param[in] A The matrix of the eigen problem
52 */
54 : EigenProblem(A)
55 {}
56
57 //! Free resources
58 virtual ~EigenProblemT() {}
59
60 //! Type of the matrix used
62 //! Type of the vector used
64
65 /*!
66 * \brief Get the local size of the problem
67 * \return Local size of the problem
68 */
69 Arccore::Integer localSize() const;
70
71 /*!
72 * \brief Get the eigen matrix
73 * \return The eigen matrix
74 */
75 KernelMatrix const& getA() const;
76
77 /*!
78 * \brief Get the number of eigen vectors
79 * \return The number of eigen vectors
80 */
81 Arccore::Integer getNbEigenVectors() const { return m_eigen_vectors.size(); }
82
83 /*!
84 * \brief Get the eigen vectors
85 * \return The eigen vectors
86 */
87 std::vector<VectorT>& getEigenVectors() { return m_eigen_vectors; }
88
89 // TOCHECK: Commentaire
90 /*
91 void setEigenVectors(std::vector<std::vector<Real>>& ev_vectors)
92 {
93 auto const& vdist = this->m_A.impl()->distribution().rowDistribution() ;
94 for(auto const ev : ev_vectors)
95 {
96 VectorT v(vdist) ;
97 Alien::LocalVectorWriter vv(v) ;
98 for(auto i=0;i<vdist.localSize();++i)
99 {
100 vv[i] = ev[i] ;
101 m_eigen_vectors.add(v) ;
102 }
103 }
104 }*/
105
106 private:
107 //! Eigen vectors
108 std::vector<VectorT> m_eigen_vectors;
109};
110
111/*---------------------------------------------------------------------------*/
112/*---------------------------------------------------------------------------*/
113
114/*!
115 * \ingroup core
116 * \brief Generalized eigen problem definition
117 *
118 * Allows to specify the matrices and get the number of generalized eigen vectors as well
119 * as the generalized eigen vectors
120 *
121 * \tparam Tag The type of kernel used to compute eigen values
122 * \tparam VectorT The type of kernel used to store eigen vectors
123 */
124template <class Tag, typename VectorT>
126{
127 public:
128 /*!
129 * \brief Generalized eigen problem constructor
130 * \param[in] A The first matrix of the generalized eigen problem
131 * \param[in] B The second matrix of the generalized eigen problem
132 */
135 {}
136
137 //! Free resources
139
140 //! Type of the matrix used
142 //! Type of the vector used
144
145 /*!
146 * \brief Get the local size of the problem
147 * \return Local size of the problem
148 */
149 Arccore::Integer localSize() const;
150
151 /*!
152 * \brief Get the first eigen matrix of the generalized eigen problem
153 * \return The first eigen matrix
154 */
155 KernelMatrix const& getA() const;
156
157 /*!
158 * \brief Get the second eigen matrix of the generalized eigen problem
159 * \return The second eigen matrix
160 */
161 KernelMatrix const& getB() const;
162
163 /*!
164 * \brief Get the number of eigen vectors
165 * \return The number of eigen vectors
166 */
167 Arccore::Integer getNbEigenVectors() const { return m_eigen_vectors.size(); }
168
169 /*!
170 * \brief Get the eigen vectors
171 * \return The eigen vectors
172 */
173 std::vector<VectorT>& getEigenVectors() { return m_eigen_vectors; }
174
175 private:
176 //! Eigen vectors
177 std::vector<VectorT> m_eigen_vectors;
178};
179
180/*---------------------------------------------------------------------------*/
181/*---------------------------------------------------------------------------*/
182
183/*!
184 * \ingroup core
185 * \brief Eigen solver
186 *
187 * Solves an eigen problem and retrieve eigen vectors
188 *
189 * \tparam Tag The type of kernel used to compute eigen values
190 */
191template <class Tag>
193{
194 public:
195 //! Type of the eigen solver used
197
198 public:
199 /*!
200 * \brief Eigen solver constructor
201 * \param[in] parallel_mng The parallel manager for parallel solve
202 * \param[in] options Options passed to the eigen solver
203 */
204 EigenSolver(Arccore::MessagePassing::IMessagePassingMng* parallel_mng = nullptr,
205 IOptions* options = nullptr);
206
207 //! Free resources
208 virtual ~EigenSolver() {}
209
210 /*!
211 * \brief Get kernel back end name
212 * \returns The kernel name as a string
213 */
214 Arccore::String getBackEndName() const;
215
216 //! Initialize the eigen solver
217 void init();
218
219 /*!
220 * \brief Solve the eigen problem
221 * \param[in,out] p The eigen problem
222 * \returns Solver success status
223 */
224 bool solve(EigenProblem& p);
225
226 /*!
227 * \brief Indicates if the kernel is parallel
228 * \returns Parallel support capability
229 */
230 bool hasParallelSupport() const;
231
232 /*!
233 * \brief Get solver resolution status
234 * \returns The solver status
235 */
236 const IEigenSolver::Status& getStatus() const;
237
238 /*!
239 * \brief Get kernel solver implementation
240 * \return Eigen solver actual implementation
241 */
243
244 private:
245 //! Type of the matrix used
246 typedef typename AlgebraTraits<Tag>::matrix_type KernelMatrix;
247 //! Type of the vector used
248 typedef typename AlgebraTraits<Tag>::vector_type KernelVector;
249 //! The eigen solver
250 std::unique_ptr<KernelSolver> m_solver;
251};
252
253/*---------------------------------------------------------------------------*/
254/*---------------------------------------------------------------------------*/
255
256/*!
257 * \ingroup core
258 * \brief Generalized eigen solver
259 *
260 * Solves a generalized eigen problem and retrieve eigen vectors
261 *
262 * \tparam Tag The type of kernel used to compute eigen values
263 */
264template <class Tag>
266{
267 public:
268 //! Type of the eigen solver used
270
271 public:
272 /*!
273 * \brief Eigen solver constructor
274 * \param[in] parallel_mng The parallel manager for parallel solve
275 * \param[in] options Options passed to the eigen solver
276 */
278 IMessagePassingMng* parallel_mng = nullptr, IOptions* options = nullptr);
279
280 //! Free resources
282
283 /*!
284 * \brief Get kernel back end name
285 * \returns The kernel name as a string
286 */
287 Arccore::String getBackEndName() const;
288
289 //! Initialize the eigen solver
290 void init();
291
292 /*!
293 * \brief Solve the eigen problem
294 * \param[in,out] A The generalized eigen problem
295 * \returns Solver success status
296 */
298
299 /*!
300 * \brief Indicates if the kernel is parallel
301 * \returns Parallel support capability
302 */
303 bool hasParallelSupport() const;
304
305 /*!
306 * \brief Get solver resolution status
307 * \returns The solver status
308 */
309 const IEigenSolver::Status& getStatus() const;
310
311 /*!
312 * \brief Get kernel solver implementation
313 * \return Eigen solver actual implementation
314 */
316
317 private:
318 //! Type of the matrix used
319 typedef typename AlgebraTraits<Tag>::matrix_type KernelMatrix;
320 //! Type of the vector used
321 typedef typename AlgebraTraits<Tag>::vector_type KernelVector;
322 //! The generalized eigen solver
323 std::unique_ptr<KernelSolver> m_solver;
324};
325
326/*---------------------------------------------------------------------------*/
327/*---------------------------------------------------------------------------*/
328
329} // namespace Alien
330
331/*---------------------------------------------------------------------------*/
332/*---------------------------------------------------------------------------*/
IEigenSolver.h.
AlgebraTraits< Tag >::vector_type KernelVector
Type of the vector used.
Definition EigenSolver.h:63
AlgebraTraits< Tag >::matrix_type KernelMatrix
Type of the matrix used.
Definition EigenSolver.h:61
EigenProblemT(IMatrix const &A)
Eigen problem constructor.
Definition EigenSolver.h:53
KernelMatrix const & getA() const
Get the eigen matrix.
std::vector< VectorT > & getEigenVectors()
Get the eigen vectors.
Definition EigenSolver.h:87
virtual ~EigenProblemT()
Free resources.
Definition EigenSolver.h:58
Arccore::Integer getNbEigenVectors() const
Get the number of eigen vectors.
Definition EigenSolver.h:81
Arccore::Integer localSize() const
Get the local size of the problem.
Defines an eigen problem.
EigenProblem(IMatrix const &A)
Constructor.
bool hasParallelSupport() const
Indicates if the kernel is parallel.
AlgebraTraits< Tag >::eigen_solver_type KernelSolver
Type of the eigen solver used.
KernelSolver * implem()
Get kernel solver implementation.
const IEigenSolver::Status & getStatus() const
Get solver resolution status.
Arccore::String getBackEndName() const
Get kernel back end name.
virtual ~EigenSolver()
Free resources.
void init()
Initialize the eigen solver.
bool solve(EigenProblem &p)
Solve the eigen problem.
EigenSolver(Arccore::MessagePassing::IMessagePassingMng *parallel_mng=nullptr, IOptions *options=nullptr)
Eigen solver constructor.
virtual ~GeneralizedEigenProblemT()
Free resources.
GeneralizedEigenProblemT(IMatrix const &A, IMatrix const &B)
Generalized eigen problem constructor.
AlgebraTraits< Tag >::matrix_type KernelMatrix
Type of the matrix used.
KernelMatrix const & getB() const
Get the second eigen matrix of the generalized eigen problem.
AlgebraTraits< Tag >::vector_type KernelVector
Type of the vector used.
Arccore::Integer getNbEigenVectors() const
Get the number of eigen vectors.
Arccore::Integer localSize() const
Get the local size of the problem.
KernelMatrix const & getA() const
Get the first eigen matrix of the generalized eigen problem.
std::vector< VectorT > & getEigenVectors()
Get the eigen vectors.
Defines a generalized eigen problem.
GeneralizedEigenProblem(IMatrix const &A, IMatrix const &B)
Constructor.
const IEigenSolver::Status & getStatus() const
Get solver resolution status.
bool hasParallelSupport() const
Indicates if the kernel is parallel.
AlgebraTraits< Tag >::generalized_eigen_solver_type KernelSolver
Type of the eigen solver used.
bool solve(GeneralizedEigenProblem &A)
Solve the eigen problem.
virtual ~GeneralizedEigenSolver()
Free resources.
GeneralizedEigenSolver(IMessagePassingMng *parallel_mng=nullptr, IOptions *options=nullptr)
Eigen solver constructor.
KernelSolver * implem()
Get kernel solver implementation.
Arccore::String getBackEndName() const
Get kernel back end name.
void init()
Initialize the eigen solver.
IEigenSolver()
Constructor.
Interface for all matrices.
Definition IMatrix.h:51
Interface for all vectors.
Definition IVector.h:51
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17
Eigen solver status.