From df6bcabf4c364d41ecdb60add2f370bcccfa4749 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Buchwald?= <joerg.buchwald@ufz.de> Date: Fri, 12 Feb 2021 18:40:08 +0100 Subject: [PATCH] add FormEigenVector --- MaterialLib/MPL/Utils/FormEigenVector.cpp | 97 +++++++++++++++++++++++ MaterialLib/MPL/Utils/FormEigenVector.h | 23 ++++++ 2 files changed, 120 insertions(+) create mode 100644 MaterialLib/MPL/Utils/FormEigenVector.cpp create mode 100644 MaterialLib/MPL/Utils/FormEigenVector.h diff --git a/MaterialLib/MPL/Utils/FormEigenVector.cpp b/MaterialLib/MPL/Utils/FormEigenVector.cpp new file mode 100644 index 00000000000..372cd9c6d08 --- /dev/null +++ b/MaterialLib/MPL/Utils/FormEigenVector.cpp @@ -0,0 +1,97 @@ +/* + * \file + * \copyright + * Copyright (c) 2012-2021, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + * Created on July 31, 2019, 11:28 AM + */ + +#include "FormEigenVector.h" + +#include "MaterialLib/MPL/PropertyType.h" + +namespace MaterialPropertyLib +{ +template <int GlobalDim> +struct FormEigenVector +{ + Eigen::Matrix<double, GlobalDim, 1> operator()(double const value) const + { + if constexpr (GlobalDim == 1) + { + return Eigen::Matrix<double, 1, 1>{value}; + } + if constexpr (GlobalDim == 2) + { + return Eigen::Matrix<double, 2, 1>{ value, value }; + } + if constexpr (GlobalDim == 3) + { + return Eigen::Matrix<double, 3, 1>{ value, value, value }; + } + } + + Eigen::Matrix<double, GlobalDim, 1> operator()( + Eigen::Vector2d const& values) const + { + if constexpr (GlobalDim == 2) + { + return values; + } + OGS_FATAL("Cannot convert 2d vector to {:d}d vector.", GlobalDim); + } + + Eigen::Matrix<double, GlobalDim, 1> operator()( + Eigen::Vector3d const& values) const + { + if constexpr (GlobalDim == 3) + { + return values; + } + OGS_FATAL("Cannot convert 3d vector to a {:d}d vector.", GlobalDim); + } + + Eigen::Matrix<double, GlobalDim, 1> operator()( + Eigen::Matrix<double, 2, 2> const& /*values*/) const + { + OGS_FATAL("Cannot convert a 2d tensor to a {:d}d Vector.", GlobalDim); + } + Eigen::Matrix<double, GlobalDim, 1> operator()( + Eigen::Matrix<double, 3, 3> const& /*values*/) const + { + OGS_FATAL("Cannot convert a 3d tensor to a {:d}d Vector.", GlobalDim); + } + + Eigen::Matrix<double, GlobalDim, 1> operator()( + Eigen::Matrix<double, 4, 1> const& /*values*/) const + { + OGS_FATAL("Cannot convert a 4d vector to a {:d}d vector.", GlobalDim); + } + + Eigen::Matrix<double, GlobalDim, 1> operator()( + Eigen::Matrix<double, 6, 1> const& /*values*/) const + { + OGS_FATAL("Cannot convert a 6d vector to a {:d}d vector.", GlobalDim); + } +}; + +template <int GlobalDim> +Eigen::Matrix<double, GlobalDim, 1> formEigenVector( + MaterialPropertyLib::PropertyDataType const& values) +{ + return std::visit(FormEigenVector<GlobalDim>(), values); +} + +template Eigen::Matrix<double, 1, 1> formEigenVector<1>( + 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); + +} // namespace MaterialPropertyLib diff --git a/MaterialLib/MPL/Utils/FormEigenVector.h b/MaterialLib/MPL/Utils/FormEigenVector.h new file mode 100644 index 00000000000..a62dabff21d --- /dev/null +++ b/MaterialLib/MPL/Utils/FormEigenVector.h @@ -0,0 +1,23 @@ +/* + * \file + * \copyright + * Copyright (c) 2012-2021, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + * Created on July 29, 2019, 2:48 PM + */ + +#pragma once + +#include <Eigen/Dense> + +#include "MaterialLib/MPL/Property.h" + +namespace MaterialPropertyLib +{ +template <int GlobalDim> +Eigen::Matrix<double, GlobalDim, 1> formEigenVector( + MaterialPropertyLib::PropertyDataType const& values); +} // namespace MaterialPropertyLib -- GitLab