OGS
FormEigenTensor.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 "FormEigenTensor.h"
13
15
16namespace MaterialPropertyLib
17{
18template <int GlobalDim>
20{
21 Eigen::Matrix<double, GlobalDim, GlobalDim> operator()(
22 double const& value) const
23 {
24 return Eigen::Matrix<double, GlobalDim, GlobalDim>::Identity() * value;
25 }
26
27 Eigen::Matrix<double, GlobalDim, GlobalDim> operator()(
28 Eigen::Vector2d const& values) const
29 {
30 if constexpr (GlobalDim == 2)
31 {
32 return values.asDiagonal();
33 }
34 OGS_FATAL("Cannot convert 2d vector to {:d}x{:d} diagonal matrix.",
35 GlobalDim, GlobalDim);
36 }
37
38 Eigen::Matrix<double, GlobalDim, GlobalDim> operator()(
39 Eigen::Vector3d const& values) const
40 {
41 if constexpr (GlobalDim == 3)
42 {
43 return values.asDiagonal();
44 }
45 OGS_FATAL("Cannot convert 3d vector to {:d}x{:d} diagonal matrix.",
46 GlobalDim, GlobalDim);
47 }
48
49 Eigen::Matrix<double, GlobalDim, GlobalDim> operator()(
50 Eigen::Matrix<double, 2, 2> const& values) const
51 {
52 if constexpr (GlobalDim == 2)
53 {
54 return values;
55 }
56 OGS_FATAL("Cannot convert a 2d tensor to {:d}x{:d} matrix", GlobalDim,
57 GlobalDim);
58 }
59 Eigen::Matrix<double, GlobalDim, GlobalDim> operator()(
60 Eigen::Matrix<double, 3, 3> const& values) const
61 {
62 if constexpr (GlobalDim == 3)
63 {
64 return values;
65 }
66 OGS_FATAL("Cannot convert a 3d tensor to {:d}x{:d} matrix", GlobalDim,
67 GlobalDim);
68 }
69
70 Eigen::Matrix<double, GlobalDim, GlobalDim> operator()(
71 Eigen::Matrix<double, 4, 1> const& values) const
72 {
73 Eigen::Matrix<double, GlobalDim, GlobalDim> result;
74 if constexpr (GlobalDim == 2)
75 { // skip the z-direction in this case
76 result << values[0], values[3], values[3], values[1];
77 }
78 if constexpr (GlobalDim == 3)
79 {
80 result << values[0], values[3], 0, values[3], values[1], 0, 0, 0,
81 values[2];
82 }
83 return result;
84 }
85
86 Eigen::Matrix<double, GlobalDim, GlobalDim> operator()(
87 Eigen::Matrix<double, 6, 1> const& values) const
88 {
89 if constexpr (GlobalDim == 3)
90 {
91 Eigen::Matrix<double, GlobalDim, GlobalDim> result;
92 result << values[0], values[3], values[5], values[3], values[1],
93 values[4], values[5], values[4], values[2];
94 return result;
95 }
96
97 OGS_FATAL("Cannot convert a symmetric 3d tensor to a {}x{} matrix",
98 GlobalDim, GlobalDim);
99 }
100
101 Eigen::Matrix<double, GlobalDim, GlobalDim> operator()(
102 Eigen::MatrixXd const& values) const
103 {
104 if (GlobalDim == values.rows() && GlobalDim == values.cols())
105 {
106 return values;
107 }
108
109 OGS_FATAL("Cannot convert a dynamic {}x{} matrix to a {}x{} matrix",
110 values.rows(), values.cols(), GlobalDim, GlobalDim);
111 }
112};
113
114template <int GlobalDim>
115Eigen::Matrix<double, GlobalDim, GlobalDim> formEigenTensor(
117{
118 return std::visit(FormEigenTensor<GlobalDim>(), values);
119}
120
121template Eigen::Matrix<double, 1, 1> formEigenTensor<1>(
123
124template Eigen::Matrix<double, 2, 2> formEigenTensor<2>(
126
127template Eigen::Matrix<double, 3, 3> formEigenTensor<3>(
129
130template Eigen::Matrix<double, 4, 4> formEigenTensor<4>(
132
133template Eigen::Matrix<double, 6, 6> formEigenTensor<6>(
135
136} // namespace MaterialPropertyLib
#define OGS_FATAL(...)
Definition Error.h:26
template Eigen::Matrix< double, 4, 4 > formEigenTensor< 4 >(MaterialPropertyLib::PropertyDataType const &values)
template Eigen::Matrix< double, 6, 6 > formEigenTensor< 6 >(MaterialPropertyLib::PropertyDataType const &values)
template Eigen::Matrix< double, 3, 3 > formEigenTensor< 3 >(MaterialPropertyLib::PropertyDataType const &values)
Eigen::Matrix< double, GlobalDim, GlobalDim > formEigenTensor(MaterialPropertyLib::PropertyDataType const &values)
template Eigen::Matrix< double, 1, 1 > formEigenTensor< 1 >(MaterialPropertyLib::PropertyDataType const &values)
template Eigen::Matrix< double, 2, 2 > formEigenTensor< 2 >(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, GlobalDim > operator()(Eigen::Vector2d const &values) const
Eigen::Matrix< double, GlobalDim, GlobalDim > operator()(Eigen::Matrix< double, 2, 2 > const &values) const
Eigen::Matrix< double, GlobalDim, GlobalDim > operator()(double const &value) const
Eigen::Matrix< double, GlobalDim, GlobalDim > operator()(Eigen::Vector3d const &values) const
Eigen::Matrix< double, GlobalDim, GlobalDim > operator()(Eigen::MatrixXd const &values) const
Eigen::Matrix< double, GlobalDim, GlobalDim > operator()(Eigen::Matrix< double, 4, 1 > const &values) const
Eigen::Matrix< double, GlobalDim, GlobalDim > operator()(Eigen::Matrix< double, 6, 1 > const &values) const
Eigen::Matrix< double, GlobalDim, GlobalDim > operator()(Eigen::Matrix< double, 3, 3 > const &values) const