12#ifndef ARCCORE_ALINA_EIGENBACKEND_H
13#define ARCCORE_ALINA_EIGENBACKEND_H
26#include "arccore/alina/EigenAdapter.h"
27#include "arccore/alina/SkylineLUSolver.h"
32namespace Arcane::Alina::backend
46template <
typename real>
49 typedef real value_type;
50 typedef ptrdiff_t index_type;
51 typedef ptrdiff_t col_type;
52 typedef ptrdiff_t ptr_type;
54 typedef Eigen::Map<Eigen::SparseMatrix<value_type, Eigen::RowMajor, index_type>> matrix;
56 typedef Eigen::Matrix<value_type, Eigen::Dynamic, 1> vector;
57 typedef Eigen::Matrix<value_type, Eigen::Dynamic, 1> matrix_diagonal;
67 static std::string name() {
return "eigen"; }
70 static std::shared_ptr<matrix>
73 const typename BuiltinBackend<real>::matrix& a = *A;
75 return std::shared_ptr<matrix>(
new matrix(
76 nbRow(*A), nbColumn(*A), nonzeros(*A),
77 const_cast<index_type*
>(a.ptr.data()),
78 const_cast<index_type*
>(a.col.data()),
79 const_cast<value_type*
>(a.val.data())),
84 static std::shared_ptr<vector>
87 return std::make_shared<vector>(
88 Eigen::Map<const vector>(x.data(), x.size()));
92 static std::shared_ptr<vector>
99 static std::shared_ptr<vector>
102 return std::make_shared<vector>(size);
106 static std::shared_ptr<direct_solver>
109 return std::make_shared<direct_solver>(*A);
116 typedef std::shared_ptr<CSRMatrix<real, ptrdiff_t, ptrdiff_t>> host_matrix;
119 hold_host(host_matrix host)
123 void operator()(matrix* ptr)
const
130template <
class Alpha,
class M,
class V1,
class Beta,
class V2>
132 typename std::enable_if<
133 is_eigen_sparse_matrix<M>::value &&
134 is_eigen_type<V1>::value &&
135 is_eigen_type<V2>::value>::type>
137 static void apply(Alpha alpha,
const M& A,
const V1& x, Beta beta, V2& y)
139 if (!math::is_zero(beta))
140 y = alpha * A * x + beta * y;
146template <
class M,
class V1,
class V2,
class V3>
148 typename std::enable_if<
149 is_eigen_sparse_matrix<M>::value &&
150 is_eigen_type<V1>::value &&
151 is_eigen_type<V2>::value &&
152 is_eigen_type<V3>::value>::type>
154 static void apply(
const V1& rhs,
const M& A,
const V2& x, V3& r)
161struct clear_impl<V, typename std::enable_if<is_eigen_type<V>::value>::type>
163 static void apply(V& x)
169template <
class V1,
class V2>
171 typename std::enable_if<
172 is_eigen_type<V1>::value &&
173 is_eigen_type<V2>::value>::type>
175 typedef typename value_type<V1>::type real;
176 static real get(
const V1& x,
const V2& y)
182template <
class A,
class V1,
class B,
class V2>
184 typename std::enable_if<
185 is_eigen_type<V1>::value &&
186 is_eigen_type<V2>::value>::type>
188 static void apply(A a,
const V1& x, B b, V2& y)
190 if (!math::is_zero(b))
197template <
class A,
class V1,
class B,
class V2,
class C,
class V3>
199 typename std::enable_if<
200 is_eigen_type<V1>::value &&
201 is_eigen_type<V2>::value &&
202 is_eigen_type<V3>::value>::type>
204 typedef typename value_type<V1>::type real;
206 static void apply(real a,
const V1& x, real b,
const V2& y, real c, V3& z)
208 if (!math::is_zero(c))
209 z = a * x + b * y + c * z;
215template <
class Alpha,
class V1,
class V2,
class Beta,
class V3>
217 typename std::enable_if<is_eigen_type<V1>::value &&
218 is_eigen_type<V2>::value &&
219 is_eigen_type<V3>::value>::type>
221 static void apply(Alpha a,
const V1& x,
const V2& y, Beta b, V3& z)
223 if (!math::is_zero(b))
224 z.array() = a * x.array() * y.array() + b * z.array();
226 z.array() = a * x.array() * y.array();
230template <
class V1,
class V2>
232 typename std::enable_if<
233 is_eigen_type<V1>::value &&
234 is_eigen_type<V2>::value>::type>
236 static void apply(
const V1& x, V2& y)
Class to handle empty parameters list.
Direct solver that uses Skyline LU factorization.
static std::shared_ptr< vector > copy_vector(typename BuiltinBackend< real >::vector const &x, const params &)
Copy vector from builtin backend.
Alina::detail::empty_params params
Backend parameters.
static std::shared_ptr< direct_solver > create_solver(std::shared_ptr< typename BuiltinBackend< real >::matrix > A, const params &)
Create direct solver for coarse level.
static std::shared_ptr< vector > create_vector(size_t size, const params &)
Create vector of the specified size.
static std::shared_ptr< matrix > copy_matrix(std::shared_ptr< typename BuiltinBackend< real >::matrix > A, const params &)
Copy matrix from builtin backend.
static std::shared_ptr< vector > copy_vector(std::shared_ptr< typename BuiltinBackend< real >::vector > x, const params &prm)
Copy vector from builtin backend.
Implementation for linear combination of two vectors.
Implementation for linear combination of three vectors.
Implementation for zeroing out a vector.
Implementation for vector copy.
Implementation for inner product.
Implementation for residual error compuatation.
Implementation for matrix-vector product.
Implementation for element-wize vector product.