version 0.4.1
vanishinghelpers.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
4#pragma once
5
6#include <ranges>
7
8#include <Eigen/Dense>
9
11
12namespace Ikarus::Impl {
13
17struct MatrixIndexPair
18{
19 Eigen::Index row;
20 Eigen::Index col;
21};
22
29template <size_t size>
30consteval auto createfreeVoigtIndices(const std::array<MatrixIndexPair, size>& fixed) {
31 std::array<size_t, 6 - size> res{};
32 std::array<size_t, size> voigtFixedIndices;
33 std::ranges::transform(fixed, voigtFixedIndices.begin(), [](auto pair) { return toVoigt(pair.row, pair.col); });
34 std::ranges::sort(voigtFixedIndices);
35 std::ranges::set_difference(std::ranges::iota_view(size_t(0), size_t(6)), voigtFixedIndices, res.begin());
36 std::ranges::sort(res);
37 return res;
38}
39
46template <size_t size>
47consteval auto createFixedVoigtIndices(const std::array<MatrixIndexPair, size>& fixed) {
48 std::array<size_t, size> fixedIndices;
49 std::ranges::transform(fixed, fixedIndices.begin(), [](auto pair) { return toVoigt(pair.row, pair.col); });
50 std::ranges::sort(fixedIndices);
51 return fixedIndices;
52}
53
60template <size_t size>
61constexpr size_t countDiagonalIndices(const std::array<MatrixIndexPair, size>& fixed) {
62 size_t count = 0;
63 for (auto v : fixed) {
64 if (v.col == v.row)
65 ++count;
66 }
67 return count;
68}
69
76template <typename Derived>
77decltype(auto) maybeFromVoigt(const Eigen::MatrixBase<Derived>& E) {
78 if constexpr (Concepts::EigenVector<Derived>) { // receiving vector means Voigt notation
79 return fromVoigt(E.derived(), true);
80 } else
81 return E.derived();
82}
83
84} // namespace Ikarus::Impl
Several concepts.
auto fromVoigt(const Eigen::Matrix< ST, size, 1, Options, maxSize, 1 > &EVoigt, bool isStrain=true)
Converts a vector given in Voigt notation to a matrix.
Definition: tensorutils.hh:271