version 0.4.1
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
29template <typename ST, int size>
30Dune::FieldVector<ST, size> toDune(const Eigen::Vector<ST, size>& vec) {
32 for (int i = 0; i < size; ++i)
33 fieldVector[i] = vec[i];
34 return fieldVector;
35}
36
46template <typename ST, int rows>
47Dune::FieldVector<ST, rows> toDune(const Eigen::Matrix<ST, rows, 0>& vec) {
48 assert(vec.cols() == 1 && "The passed matrix needs to have a single column.");
49 Dune::FieldVector<ST, rows> fieldVector{0.0};
50
51 for (int i = 0; i < vec.rows(); ++i)
52 fieldVector[i] = vec(i, 0);
53 return fieldVector;
54}
55
65template <typename ST, int rows, int cols>
66Dune::FieldMatrix<ST, rows, cols> toDune(const Eigen::Matrix<ST, rows, cols>& mat) {
67 Dune::FieldMatrix<ST, 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
82template <typename ST, int size>
83Eigen::Map<const Eigen::Vector<ST, size>> toEigenMap(const Dune::FieldVector<ST, size>& vec) {
84 return {vec.data(), size};
85}
86
94template <typename ST, int size>
95Eigen::Map<Eigen::Vector<ST, size>> toEigenMap(Dune::FieldVector<ST, size>& vec) {
96 return {vec.data(), size};
97}
98
99} // namespace Ikarus
Definition: assemblermanipulatorbuildingblocks.hh:22
Dune::FieldVector< ST, size > toDune(const Eigen::Vector< ST, size > &vec)
Create Eigen::Vector to Dune::FieldVector.
Definition: eigendunetransformations.hh:30
Eigen::Map< const Eigen::Vector< ST, size > > toEigenMap(const Dune::FieldVector< ST, size > &vec)
View a Dune::FieldVector as an Eigen::Vector using Map, no copies take place.
Definition: eigendunetransformations.hh:83
Definition: utils/dirichletvalues.hh:32