OGS
FormEigenVector.cpp
Go to the documentation of this file.
1/*
2 * \file
3 * \copyright
4 * Copyright (c) 2012-2024, OpenGeoSys Community (http://www.opengeosys.org)
5 * Distributed under a Modified BSD License.
6 * See accompanying file LICENSE.txt or
7 * http://www.opengeosys.org/project/license
8 *
9 * Created on July 31, 2019, 11:28 AM
10 */
11
12#include "FormEigenVector.h"
13
15
16namespace MaterialPropertyLib
17{
18template <int GlobalDim>
20{
21 Eigen::Matrix<double, GlobalDim, 1> operator()(double const value) const
22 {
23 if constexpr (GlobalDim == 1)
24 {
25 return Eigen::Matrix<double, 1, 1>{value};
26 }
27 if constexpr (GlobalDim == 2)
28 {
29 return Eigen::Matrix<double, 2, 1>{value, value};
30 }
31 if constexpr (GlobalDim == 3)
32 {
33 return Eigen::Matrix<double, 3, 1>{value, value, value};
34 }
35 OGS_FATAL("Cannot convert a scalar to a {:d}d vector.", GlobalDim);
36 }
37
38 Eigen::Matrix<double, GlobalDim, 1> operator()(
39 Eigen::Vector2d const& values) const
40 {
41 if constexpr (GlobalDim == 2)
42 {
43 return values;
44 }
45 OGS_FATAL("Cannot convert a 2d vector to a {:d}d vector.", GlobalDim);
46 }
47
48 Eigen::Matrix<double, GlobalDim, 1> operator()(
49 Eigen::Vector3d const& values) const
50 {
51 if constexpr (GlobalDim == 3)
52 {
53 return values;
54 }
55 OGS_FATAL("Cannot convert a 3d vector to a {:d}d vector.", GlobalDim);
56 }
57
58 Eigen::Matrix<double, GlobalDim, 1> operator()(
59 Eigen::Matrix<double, 2, 2> const& /*values*/) const
60 {
61 OGS_FATAL("Cannot convert a 2d tensor to a {:d}d Vector.", GlobalDim);
62 }
63 Eigen::Matrix<double, GlobalDim, 1> operator()(
64 Eigen::Matrix<double, 3, 3> const& /*values*/) const
65 {
66 OGS_FATAL("Cannot convert a 3d tensor to a {:d}d Vector.", GlobalDim);
67 }
68
69 Eigen::Matrix<double, GlobalDim, 1> operator()(
70 Eigen::Matrix<double, 4, 1> const& /*values*/) const
71 {
72 OGS_FATAL("Cannot convert a 4d vector to a {:d}d vector.", GlobalDim);
73 }
74
75 Eigen::Matrix<double, GlobalDim, 1> operator()(
76 Eigen::Matrix<double, 6, 1> const& /*values*/) const
77 {
78 OGS_FATAL("Cannot convert a 6d vector to a {:d}d vector.", GlobalDim);
79 }
80
81 Eigen::Matrix<double, GlobalDim, 1> operator()(
82 Eigen::MatrixXd const& /*values*/) const
83 {
84 OGS_FATAL("Cannot convert a dynamic Eigen matrix to a {:d}d vector ",
85 GlobalDim);
86 }
87};
88
89template <int GlobalDim>
90Eigen::Matrix<double, GlobalDim, 1> formEigenVector(
92{
93 return std::visit(FormEigenVector<GlobalDim>(), values);
94}
95
96template Eigen::Matrix<double, 1, 1> formEigenVector<1>(
98
99template Eigen::Matrix<double, 2, 1> formEigenVector<2>(
101
102template Eigen::Matrix<double, 3, 1> formEigenVector<3>(
104
105} // namespace MaterialPropertyLib
#define OGS_FATAL(...)
Definition Error.h:26
template Eigen::Matrix< double, 1, 1 > formEigenVector< 1 >(MaterialPropertyLib::PropertyDataType const &values)
Eigen::Matrix< double, GlobalDim, 1 > formEigenVector(MaterialPropertyLib::PropertyDataType const &values)
template Eigen::Matrix< double, 2, 1 > formEigenVector< 2 >(MaterialPropertyLib::PropertyDataType const &values)
template Eigen::Matrix< double, 3, 1 > formEigenVector< 3 >(MaterialPropertyLib::PropertyDataType const &values)
std::variant< double, Eigen::Matrix< double, 2, 1 >, Eigen::Matrix< double, 3, 1 >, Eigen::Matrix< double, 2, 2 >, Eigen::Matrix< double, 3, 3 >, Eigen::Matrix< double, 4, 1 >, Eigen::Matrix< double, 6, 1 >, Eigen::MatrixXd > PropertyDataType
Definition Property.h:31
Eigen::Matrix< double, GlobalDim, 1 > operator()(Eigen::Vector2d const &values) const
Eigen::Matrix< double, GlobalDim, 1 > operator()(Eigen::Matrix< double, 4, 1 > const &) const
Eigen::Matrix< double, GlobalDim, 1 > operator()(Eigen::Matrix< double, 3, 3 > const &) const
Eigen::Matrix< double, GlobalDim, 1 > operator()(Eigen::Matrix< double, 2, 2 > const &) const
Eigen::Matrix< double, GlobalDim, 1 > operator()(double const value) const
Eigen::Matrix< double, GlobalDim, 1 > operator()(Eigen::Vector3d const &values) const
Eigen::Matrix< double, GlobalDim, 1 > operator()(Eigen::Matrix< double, 6, 1 > const &) const
Eigen::Matrix< double, GlobalDim, 1 > operator()(Eigen::MatrixXd const &) const