From c3b2b1ead805ad6626dd1589e485c23b6d2c8ce1 Mon Sep 17 00:00:00 2001
From: Dmitri Naumov <github@naumov.de>
Date: Mon, 29 Jan 2018 22:39:35 +0100
Subject: [PATCH] [PL] Use Kelvin vector conversion.

---
 MaterialLib/SolidModels/Ehlers-impl.h         | 22 ++++--------
 .../SmallDeformation/SmallDeformationFEM.h    | 36 +++----------------
 2 files changed, 10 insertions(+), 48 deletions(-)

diff --git a/MaterialLib/SolidModels/Ehlers-impl.h b/MaterialLib/SolidModels/Ehlers-impl.h
index 4f4d5000f83..e6327db8434 100644
--- a/MaterialLib/SolidModels/Ehlers-impl.h
+++ b/MaterialLib/SolidModels/Ehlers-impl.h
@@ -34,6 +34,8 @@
 
 #include <boost/math/special_functions/pow.hpp>
 
+#include "MathLib/LinAlg/Eigen/EigenMapTools.h"
+
 namespace MaterialLib
 {
 namespace Solids
@@ -673,24 +675,12 @@ SolidEhlers<DisplacementDim>::getInternalVariables() const
                         &state) != nullptr);
              auto const& ehlers_state =
                  static_cast<StateVariables<DisplacementDim> const&>(state);
-             auto const& D = ehlers_state.eps_p.D;
 
              cache.resize(KelvinVector::RowsAtCompileTime);
-
-             // TODO make a general implementation for converting KelvinVectors
-             // back to symmetric rank-2 tensors.
-             for (typename KelvinVector::Index component = 0;
-                  component < KelvinVector::RowsAtCompileTime && component < 3;
-                  ++component)
-             {  // xx, yy, zz components
-                 cache[component] = D[component];
-             }
-             for (typename KelvinVector::Index component = 3;
-                  component < KelvinVector::RowsAtCompileTime;
-                  ++component)
-             {  // mixed xy, yz, xz components
-                 cache[component] = D[component] / std::sqrt(2);
-             }
+             MathLib::toVector<KelvinVector>(cache,
+                                             KelvinVector::RowsAtCompileTime) =
+                 MathLib::KelvinVector::kelvinVectorToSymmetricTensor(
+                     ehlers_state.eps_p.D);
 
              return cache;
          }},
diff --git a/ProcessLib/SmallDeformation/SmallDeformationFEM.h b/ProcessLib/SmallDeformation/SmallDeformationFEM.h
index e96ec20638a..c34bcd56ff3 100644
--- a/ProcessLib/SmallDeformation/SmallDeformationFEM.h
+++ b/ProcessLib/SmallDeformation/SmallDeformationFEM.h
@@ -320,7 +320,6 @@ public:
         NumLib::LocalToGlobalIndexMap const& /*dof_table*/,
         std::vector<double>& cache) const override
     {
-        using KelvinVectorType = typename BMatricesType::KelvinVectorType;
         static const int kelvin_vector_size =
             MathLib::KelvinVector::KelvinVectorDimensions<
                 DisplacementDim>::value;
@@ -331,24 +330,11 @@ public:
             double, kelvin_vector_size, Eigen::Dynamic, Eigen::RowMajor>>(
             cache, kelvin_vector_size, num_intpts);
 
-        // TODO make a general implementation for converting KelvinVectors
-        // back to symmetric rank-2 tensors.
         for (unsigned ip = 0; ip < num_intpts; ++ip)
         {
             auto const& sigma = _ip_data[ip].sigma;
-
-            for (typename KelvinVectorType::Index component = 0;
-                 component < kelvin_vector_size && component < 3;
-                 ++component)
-            {  // xx, yy, zz components
-                cache_mat(component, ip) = sigma[component];
-            }
-            for (typename KelvinVectorType::Index component = 3;
-                 component < kelvin_vector_size;
-                 ++component)
-            {  // mixed xy, yz, xz components
-                cache_mat(component, ip) = sigma[component] / std::sqrt(2);
-            }
+            cache_mat.col(ip) =
+                MathLib::KelvinVector::kelvinVectorToSymmetricTensor(sigma);
         }
 
         return cache;
@@ -360,7 +346,6 @@ public:
         NumLib::LocalToGlobalIndexMap const& /*dof_table*/,
         std::vector<double>& cache) const override
     {
-        using KelvinVectorType = typename BMatricesType::KelvinVectorType;
         auto const kelvin_vector_size =
             MathLib::KelvinVector::KelvinVectorDimensions<
                 DisplacementDim>::value;
@@ -371,24 +356,11 @@ public:
             double, kelvin_vector_size, Eigen::Dynamic, Eigen::RowMajor>>(
             cache, kelvin_vector_size, num_intpts);
 
-        // TODO make a general implementation for converting KelvinVectors
-        // back to symmetric rank-2 tensors.
         for (unsigned ip = 0; ip < num_intpts; ++ip)
         {
             auto const& eps = _ip_data[ip].eps;
-
-            for (typename KelvinVectorType::Index component = 0;
-                 component < kelvin_vector_size && component < 3;
-                 ++component)
-            {  // xx, yy, zz components
-                cache_mat(component, ip) = eps[component];
-            }
-            for (typename KelvinVectorType::Index component = 3;
-                 component < kelvin_vector_size;
-                 ++component)
-            {  // mixed xy, yz, xz components
-                cache_mat(component, ip) = eps[component] / std::sqrt(2);
-            }
+            cache_mat.col(ip) =
+                MathLib::KelvinVector::kelvinVectorToSymmetricTensor(eps);
         }
 
         return cache;
-- 
GitLab