Arcane  v4.1.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
EigenSolver.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 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/*---------------------------------------------------------------------------*/
8/* EigenAdapter.h (C) 2000-2026 */
9/* */
10/* Wrapper around eigen direct solvers. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_ALINA_EIGENSOLVER_H
13#define ARCCORE_ALINA_EIGENSOLVER_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16/*
17 * This file is based on the work on AMGCL library (version march 2026)
18 * which can be found at https://github.com/ddemidov/amgcl.
19 *
20 * Copyright (c) 2012-2022 Denis Demidov <dennis.demidov@gmail.com>
21 * SPDX-License-Identifier: MIT
22 */
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
26// Remove warnings for Eigen
27#pragma GCC diagnostic ignored "-Wdeprecated-copy"
28#pragma GCC diagnostic ignored "-Wint-in-bool-context"
29
30#include <Eigen/Dense>
31#include <Eigen/SparseCore>
32
33#include <type_traits>
34
35#include "arccore/alina/BuiltinBackend.h"
36#include "arccore/alina/AlinaUtils.h"
37
38/*---------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------*/
40
41namespace Arcane::Alina
42{
43
44/*---------------------------------------------------------------------------*/
45/*---------------------------------------------------------------------------*/
49template <class Solver>
50class EigenSolver
51{
52 public:
53
54 typedef typename Solver::MatrixType MatrixType;
55 typedef typename Solver::Scalar value_type;
56
57 typedef Alina::detail::empty_params params;
58
59 static size_t coarse_enough()
60 {
62 }
63
64 template <class Matrix>
65 EigenSolver(const Matrix& A, const params& = params())
66 : n(backend::nbRow(A))
67 {
68 typedef typename std::remove_const<typename std::remove_pointer<typename backend::col_data_impl<Matrix>::type>::type>::type col_type;
69 typedef typename std::remove_const<typename std::remove_pointer<typename backend::ptr_data_impl<Matrix>::type>::type>::type ptr_type;
70
71 S.compute(MatrixType(Eigen::Map<Eigen::SparseMatrix<value_type, Eigen::RowMajor, ptrdiff_t>>(
72 backend::nbRow(A), backend::nbColumn(A), backend::nonzeros(A),
73 const_cast<ptr_type*>(backend::ptr_data(A)),
74 const_cast<col_type*>(backend::col_data(A)),
75 const_cast<value_type*>(backend::val_data(A)))));
76 }
77
78 template <class Vec1, class Vec2>
79 void operator()(const Vec1& rhs, Vec2& x) const
80 {
81 Eigen::Map<Eigen::Matrix<value_type, Eigen::Dynamic, 1>>
82 RHS(const_cast<value_type*>(&rhs[0]), n), X(&x[0], n);
83
84 X = S.solve(RHS);
85 }
86
87 friend std::ostream& operator<<(std::ostream& os, const EigenSolver& s)
88 {
89 return os << "eigen: " << s.n << " unknowns";
90 }
91
92 private:
93
94 ptrdiff_t n;
95 Solver S;
96};
97
98/*---------------------------------------------------------------------------*/
99/*---------------------------------------------------------------------------*/
100
101} // namespace Arcane::Alina
102
103/*---------------------------------------------------------------------------*/
104/*---------------------------------------------------------------------------*/
105
106#endif
Class to handle empty parameters list.
Definition AlinaUtils.h:90
Matrix class, to be used by user.
Number of rows for statically sized matrix types.