Arcane  v4.1.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
EigenAdapter.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/* Adapters for Eigen types to be used with builtin backend. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_ALINA_EIGENADAPTER_H
13#define ARCCORE_ALINA_EIGENADAPTER_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#include <type_traits>
27#include <Eigen/SparseCore>
28#include "arccore/alina/AlinaUtils.h"
29#include "arccore/alina/BuiltinBackend.h"
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
34namespace Arcane::Alina::backend
35{
36
37/*---------------------------------------------------------------------------*/
38/*---------------------------------------------------------------------------*/
39
40//---------------------------------------------------------------------------
41// Backend interface specialization for Eigen types
42//---------------------------------------------------------------------------
43template <class T, class Enable = void>
44struct is_eigen_sparse_matrix : std::false_type
45{};
46
47template <class T, class Enable = void>
48struct is_eigen_type : std::false_type
49{};
50
51template <typename Scalar, int Flags, typename Storage>
52struct is_eigen_sparse_matrix<Eigen::Map<Eigen::SparseMatrix<Scalar, Flags, Storage>>> : std::true_type
53{};
54
55template <typename Scalar, int Flags, typename Storage>
56struct is_eigen_sparse_matrix<Eigen::SparseMatrix<Scalar, Flags, Storage>> : std::true_type
57{};
58
59template <class T>
61 typename std::enable_if<std::is_arithmetic<typename T::RealScalar>::value &&
62 std::is_base_of<Eigen::EigenBase<T>, T>::value>::type> : std::true_type
63{};
64
65template <class T>
66struct value_type<T, typename std::enable_if<is_eigen_type<T>::value>::type>
67{
68 typedef typename T::Scalar type;
69};
70
71template <class T>
72struct nonzeros_impl<T, typename std::enable_if<is_eigen_sparse_matrix<T>::value>::type>
73{
74 static size_t get(const T& matrix)
75 {
76 return matrix.nonZeros();
77 }
78};
79
80template <class T>
81struct row_iterator<T, typename std::enable_if<is_eigen_sparse_matrix<T>::value>::type>
82{
83 typedef typename T::InnerIterator type;
84};
85
86template <class T>
87struct row_begin_impl<T, typename std::enable_if<is_eigen_sparse_matrix<T>::value>::type>
88{
89 typedef typename row_iterator<T>::type iterator;
90 static iterator get(const T& matrix, size_t row)
91 {
92 return iterator(matrix, row);
93 }
94};
95
96/*---------------------------------------------------------------------------*/
97/*---------------------------------------------------------------------------*/
98
99} // namespace Arcane::Alina::backend
100
101/*---------------------------------------------------------------------------*/
102/*---------------------------------------------------------------------------*/
103
104#endif
Implementation for function returning the number of nonzeros in a matrix.
Implementation for function returning row iterator for a matrix.
Metafunction that returns value type of a matrix or a vector type.