version 0.4
eigendunetransformations.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2021-2024 The Ikarus Developers mueller@ibb.uni-stuttgart.de
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
9#pragma once
10
11#include <assert.h>
12
13#include <dune/common/diagonalmatrix.hh>
14#include <dune/common/fmatrix.hh>
15#include <dune/common/fvector.hh>
16#include <dune/istl/scaledidmatrix.hh>
17
18#include <Eigen/Core>
19
20namespace Ikarus {
21
29 template <typename ScalarType, int size>
30 Dune::FieldVector<ScalarType, size> toDune(const Eigen::Vector<ScalarType, size>& vec) {
32 for (int i = 0; i < size; ++i)
33 fieldVector[i] = vec[i];
34 return fieldVector;
35 }
36
46 template <typename ScalarType, int rows>
47 Dune::FieldVector<ScalarType, rows> toDune(const Eigen::Matrix<ScalarType, rows, 0>& vec) {
48 assert(vec.cols() == 1 && "The passed matrix needs to have a single column.");
50
51 for (int i = 0; i < vec.rows(); ++i)
52 fieldVector[i] = vec(i, 0);
53 return fieldVector;
54 }
55
65 template <typename ScalarType, int rows, int cols>
66 Dune::FieldMatrix<ScalarType, rows, cols> toDune(const Eigen::Matrix<ScalarType, rows, cols>& mat) {
67 Dune::FieldMatrix<ScalarType, rows, cols> fieldMatrix{0.0};
68
69 for (int i = 0; i < mat.rows(); ++i)
70 for (int j = 0; j < mat.cols(); ++j)
71 fieldMatrix[i][j] = mat(i, j);
72 return fieldMatrix;
73 }
74
82 template <typename ScalarType, int size>
83 Eigen::Map<const Eigen::Vector<ScalarType, size>> toEigenMap(const Dune::FieldVector<ScalarType, size>& vec) {
84 return {vec.data(), size};
85 }
86
94 template <typename ScalarType, int size>
95 Eigen::Map<Eigen::Vector<ScalarType, size>> toEigenMap(Dune::FieldVector<ScalarType, size>& vec) {
96 return {vec.data(), size};
97 }
98
99} // namespace Ikarus
Definition: simpleassemblers.hh:21
Eigen::Map< const Eigen::Vector< ScalarType, size > > toEigenMap(const Dune::FieldVector< ScalarType, size > &vec)
View a Dune::FieldVector as an Eigen::Vector using Map, no copies take place.
Definition: eigendunetransformations.hh:83
Dune::FieldVector< ScalarType, size > toDune(const Eigen::Vector< ScalarType, size > &vec)
Create Eigen::Vector to Dune::FieldVector.
Definition: eigendunetransformations.hh:30
Definition: resultevaluators.hh:20