/** * \file * \copyright * Copyright (c) 2012-2020, OpenGeoSys Community (http://www.opengeosys.org) * Distributed under a Modified BSD License. * See accompanying file LICENSE.txt or * http://www.opengeosys.org/project/license * */ #include namespace MathLib { namespace KelvinVector { template double Invariants::equivalentStress( Eigen::Matrix const& deviatoric_v) { assert(std::abs(trace(deviatoric_v)) <= 2e-12 * diagonal(deviatoric_v).norm()); return std::sqrt(3 * J2(deviatoric_v)); } template double Invariants::FrobeniusNorm( Eigen::Matrix const& deviatoric_v) { return std::sqrt(deviatoric_v.transpose() * deviatoric_v); } template double Invariants::J2( Eigen::Matrix const& deviatoric_v) { assert(std::abs(trace(deviatoric_v)) <= 2e-12 * diagonal(deviatoric_v).norm()); return 0.5 * deviatoric_v.transpose() * deviatoric_v; } /// Third invariant, equal to determinant of a deviatoric tensor. /// \note The input vector must have trace equal zero. template double Invariants::J3( Eigen::Matrix const& deviatoric_v) { assert(std::abs(trace(deviatoric_v)) <= 2e-12 * diagonal(deviatoric_v).norm()); return determinant(deviatoric_v); } template Eigen::Vector3d Invariants::diagonal( Eigen::Matrix const& v) { return v.template topLeftCorner<3, 1>(); } /// Trace of the corresponding tensor. template double Invariants::trace( Eigen::Matrix const& v) { return diagonal(v).sum(); } // // Initialization of static Invariant variables. // namespace KelvinVector_detail { template Eigen::Matrix initDeviatoricProjection() { Eigen::Matrix P_dev = Eigen::Matrix::Identity(); P_dev.template topLeftCorner<3, 3>() -= 1. / 3. * Eigen::Matrix::Ones(); return P_dev; } template Eigen::Matrix initSphericalProjection() { Eigen::Matrix P_sph = Eigen::Matrix::Zero(); P_sph.template topLeftCorner<3, 3>().setConstant(1. / 3.); return P_sph; } template Eigen::Matrix initIdentity2() { Eigen::Matrix ivec = Eigen::Matrix::Zero(); ivec.template topLeftCorner<3, 1>().setConstant(1.); return ivec; } } // namespace detail template const Eigen::Matrix Invariants::deviatoric_projection = KelvinVector_detail::initDeviatoricProjection(); template Eigen::Matrix const Invariants::spherical_projection = KelvinVector_detail::initSphericalProjection(); template const Eigen::Matrix Invariants::identity2 = KelvinVector_detail::initIdentity2(); } // namespace KelvinVector } // namespace MathLib