Arcane  v4.1.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
ValueTypeEigen.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/* ValueTypeEigen.h (C) 2000-2026 */
9/* */
10/* Enable statically sized eigen matrices as value types. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_ALINA_VALUETYPEEIGEN_H
13#define ARCCORE_ALINA_VALUETYPEEIGEN_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 <Eigen/Dense>
27
28#include "arccore/alina/BuiltinBackend.h"
29#include "arccore/alina/ValueTypeInterface.h"
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
34namespace Arcane::Alina::backend
35{
36
37/*---------------------------------------------------------------------------*/
38/*---------------------------------------------------------------------------*/
39
41template <typename T, int N, int M>
42struct is_builtin_vector<std::vector<Eigen::Matrix<T, N, M>>> : std::true_type
43{};
44
45/*---------------------------------------------------------------------------*/
46/*---------------------------------------------------------------------------*/
47
48} // namespace Arcane::Alina::backend
49
50/*---------------------------------------------------------------------------*/
51/*---------------------------------------------------------------------------*/
52
53namespace Arcane::Alina::math
54{
55
56/*---------------------------------------------------------------------------*/
57/*---------------------------------------------------------------------------*/
58
60template <class T, int N, int M>
61struct scalar_of<Eigen::Matrix<T, N, M>>
62{
63 typedef typename math::scalar_of<T>::type type;
64};
65
67template <class T, int N, int M, class S>
68struct replace_scalar<Eigen::Matrix<T, N, M>, S>
69{
70 typedef Eigen::Matrix<S, N, M> type;
71};
72
74template <class T, int N>
75struct rhs_of<Eigen::Matrix<T, N, N>>
76{
77 typedef Eigen::Matrix<T, N, 1> type;
78};
79
81template <class T, int N, int M>
82struct element_of<Eigen::Matrix<T, N, M>>
83{
84 typedef T type;
85};
86
88template <class T, int N, int M>
89struct is_static_matrix<Eigen::Matrix<T, N, M>> : std::true_type
90{};
91
93template <class T, int N, int M>
94struct static_rows<Eigen::Matrix<T, N, M>> : std::integral_constant<int, N>
95{};
96
98template <class T, int N, int M>
99struct static_cols<Eigen::Matrix<T, N, M>> : std::integral_constant<int, M>
100{};
101
103template <typename T, int N, int M>
104struct adjoint_impl<Eigen::Matrix<T, N, M>>
105{
106 typedef typename Eigen::Matrix<T, N, M>::AdjointReturnType return_type;
107
108 static return_type get(const Eigen::Matrix<T, N, M>& x)
109 {
110 return x.adjoint();
111 }
112};
113
115template <class T, int N>
116struct inner_product_impl<Eigen::Matrix<T, N, 1>>
117{
118 typedef T return_type;
119 static T get(const Eigen::Matrix<T, N, 1>& x, const Eigen::Matrix<T, N, 1>& y)
120 {
121 return x.adjoint() * y;
122 }
123};
124
126template <class T, int N, int M>
127struct inner_product_impl<Eigen::Matrix<T, N, M>>
128{
129 typedef Eigen::Matrix<T, M, M> return_type;
130
131 static return_type get(const Eigen::Matrix<T, N, M>& x, const Eigen::Matrix<T, N, M>& y)
132 {
133 return x.adjoint() * y;
134 }
135};
136
138template <typename T, int N, int M>
139struct norm_impl<Eigen::Matrix<T, N, M>>
140{
141 static typename math::scalar_of<T>::type get(const Eigen::Matrix<T, N, M>& x)
142 {
143 return x.norm();
144 }
145};
146
148template <typename T, int N, int M>
149struct zero_impl<Eigen::Matrix<T, N, M>>
150{
151 static Eigen::Matrix<T, N, M> get()
152 {
153 return Eigen::Matrix<T, N, M>::Zero();
154 }
155};
156
158template <typename T, int N, int M>
159struct is_zero_impl<Eigen::Matrix<T, N, M>>
160{
161 static bool get(const Eigen::Matrix<T, N, M>& x)
162 {
163 return x.isZero();
164 }
165};
166
168template <typename T, int N>
169struct identity_impl<Eigen::Matrix<T, N, N>>
170{
171 static Eigen::Matrix<T, N, N> get()
172 {
173 return Eigen::Matrix<T, N, N>::Identity();
174 }
175};
176
178template <typename T, int N, int M>
179struct constant_impl<Eigen::Matrix<T, N, M>>
180{
181 static Eigen::Matrix<T, N, M> get(T c)
182 {
183 return Eigen::Matrix<T, N, M>::Constant(c);
184 }
185};
186
188template <typename T, int N>
189struct inverse_impl<Eigen::Matrix<T, N, N>>
190{
191 static Eigen::Matrix<T, N, N> get(const Eigen::Matrix<T, N, N>& x)
192 {
193 return x.inverse();
194 }
195};
196
197/*---------------------------------------------------------------------------*/
198/*---------------------------------------------------------------------------*/
199
200} // namespace Arcane::Alina::math
201
202/*---------------------------------------------------------------------------*/
203/*---------------------------------------------------------------------------*/
204
205namespace Eigen
206{
207
208/*---------------------------------------------------------------------------*/
209/*---------------------------------------------------------------------------*/
210
211template <class A, class B>
212bool operator<(const MatrixBase<A>& a, const MatrixBase<B>& b)
213{
214 return a.trace() < b.trace();
215}
216
217/*---------------------------------------------------------------------------*/
218/*---------------------------------------------------------------------------*/
219
220} // namespace Eigen
221
222/*---------------------------------------------------------------------------*/
223/*---------------------------------------------------------------------------*/
224
225#endif
Matrix class, to be used by user.
bool operator<(const Item &item1, const Item &item2)
Compare deux entités.
Definition Item.h:551
Default implementation for conjugate transpose.
Default implementation for the constant element.
Element type of a non-scalar type.
Default implementation for the identity element.
Default implementation for inner product.
Default implementation of inversion operation.
Whether the value type is a statically sized matrix.
Default implementation for zero check.
Default implementation for element norm.
Replace scalar type in the static matrix.
RHS type corresponding to a non-scalar type.
Scalar type of a non-scalar type.
Number of columns for statically sized matrix types.
Number of rows for statically sized matrix types.
Default implementation for the zero element.