v0.16.0
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes | Private Attributes | List of all members
EigenMatrix::EigenMatrixContractedHessianImp< T1, T2, Dim > Struct Template Reference

#include "src/ftensor/src/MatrixFunctionTemplate.hpp"

Collaboration diagram for EigenMatrix::EigenMatrixContractedHessianImp< T1, T2, Dim >:
[legend]

Public Types

using Val = const FTensor::Tensor1< T1, Dim >
 
using Vec = const FTensor::Tensor2< T2, Dim, Dim >
 
using Fun = boost::function< double(const double)>
 
using V = double
 

Public Member Functions

 EigenMatrixContractedHessianImp (Val &t_val, Vec &t_vec)
 
template<typename T >
auto getDiffDiffMat (Fun f, Fun d_f, Fun dd_f, T &t_S)
 

Static Public Attributes

static constexpr int sizeSymm = (Dim * (Dim + 1)) / 2
 

Private Attributes

ValtVal
 
VectVec
 

Detailed Description

template<typename T1, typename T2, int Dim>
struct EigenMatrix::EigenMatrixContractedHessianImp< T1, T2, Dim >

Compute S:D2f(A) directly, without materialising sixth-order derivatives.

Definition at line 797 of file MatrixFunctionTemplate.hpp.

Member Typedef Documentation

◆ Fun

template<typename T1 , typename T2 , int Dim>
using EigenMatrix::EigenMatrixContractedHessianImp< T1, T2, Dim >::Fun = boost::function<double(const double)>

Definition at line 801 of file MatrixFunctionTemplate.hpp.

◆ V

template<typename T1 , typename T2 , int Dim>
using EigenMatrix::EigenMatrixContractedHessianImp< T1, T2, Dim >::V = double

Definition at line 802 of file MatrixFunctionTemplate.hpp.

◆ Val

template<typename T1 , typename T2 , int Dim>
using EigenMatrix::EigenMatrixContractedHessianImp< T1, T2, Dim >::Val = const FTensor::Tensor1<T1, Dim>

Definition at line 799 of file MatrixFunctionTemplate.hpp.

◆ Vec

template<typename T1 , typename T2 , int Dim>
using EigenMatrix::EigenMatrixContractedHessianImp< T1, T2, Dim >::Vec = const FTensor::Tensor2<T2, Dim, Dim>

Definition at line 800 of file MatrixFunctionTemplate.hpp.

Constructor & Destructor Documentation

◆ EigenMatrixContractedHessianImp()

template<typename T1 , typename T2 , int Dim>
EigenMatrix::EigenMatrixContractedHessianImp< T1, T2, Dim >::EigenMatrixContractedHessianImp ( Val t_val,
Vec t_vec 
)
inline

Member Function Documentation

◆ getDiffDiffMat()

template<typename T1 , typename T2 , int Dim>
template<typename T >
auto EigenMatrix::EigenMatrixContractedHessianImp< T1, T2, Dim >::getDiffDiffMat ( Fun  f,
Fun  d_f,
Fun  dd_f,
T &  t_S 
)
inline

Definition at line 810 of file MatrixFunctionTemplate.hpp.

810 {
811 // Coalesce only eigenvalues equal within the same tolerance as getUniqNb.
812 V group_ref[Dim];
813 V group_val[Dim]{};
814 int group_size[Dim]{};
815 int group_of[Dim];
816 int nb_groups = 0;
817
818 auto is_equal = [](const V a, const V b) {
819 const V eps = 100 * std::numeric_limits<V>::epsilon();
820 const V scale = std::max(V(1), std::max(std::abs(a), std::abs(b)));
821 return std::abs(a - b) <= eps * scale;
822 };
823
824 for (int aa = 0; aa != Dim; ++aa) {
825 int gg = 0;
826 for (; gg != nb_groups; ++gg)
827 if (is_equal(tVal(aa), group_ref[gg]))
828 break;
829
830 if (gg == nb_groups) {
831 group_ref[gg] = tVal(aa);
832 ++nb_groups;
833 }
834 group_of[aa] = gg;
835 group_val[gg] += tVal(aa);
836 ++group_size[gg];
837 }
838
839 V f_val[Dim];
840 V df_val[Dim];
841 V ddf_val[Dim];
842 for (int aa = 0; aa != nb_groups; ++aa) {
843 group_val[aa] /= group_size[aa];
844 f_val[aa] = f(group_val[aa]);
845 df_val[aa] = d_f(group_val[aa]);
846 ddf_val[aa] = dd_f(group_val[aa]);
847 }
848
849 auto first_divided_difference = [&](const int aa, const int bb) {
850 if (aa == bb)
851 return df_val[aa];
852 return (f_val[aa] - f_val[bb]) / (group_val[aa] - group_val[bb]);
853 };
854
855 auto second_divided_difference = [&](const int aa, const int bb,
856 const int cc) {
857 if (aa == bb && bb == cc)
858 return ddf_val[aa] / 2;
859
860 if (aa == bb) {
861 const V d1 = first_divided_difference(aa, cc);
862 return (df_val[aa] - d1) / (group_val[aa] - group_val[cc]);
863 }
864 if (aa == cc) {
865 const V d1 = first_divided_difference(aa, bb);
866 return (df_val[aa] - d1) / (group_val[aa] - group_val[bb]);
867 }
868 if (bb == cc) {
869 const V d1 = first_divided_difference(aa, bb);
870 return (d1 - df_val[bb]) / (group_val[aa] - group_val[bb]);
871 }
872
873 const V d1_ab = first_divided_difference(aa, bb);
874 const V d1_bc = first_divided_difference(bb, cc);
875 return (d1_ab - d1_bc) / (group_val[aa] - group_val[cc]);
876 };
877
878 V ddf[Dim][Dim][Dim];
879 for (int aa = 0; aa != Dim; ++aa)
880 for (int bb = 0; bb != Dim; ++bb)
881 for (int cc = 0; cc != Dim; ++cc)
882 ddf[aa][bb][cc] = second_divided_difference(
883 group_of[aa], group_of[bb], group_of[cc]);
884
885 V s_hat[Dim][Dim]{};
886 for (int aa = 0; aa != Dim; ++aa)
887 for (int cc = 0; cc != Dim; ++cc)
888 for (int ii = 0; ii != Dim; ++ii)
889 for (int jj = 0; jj != Dim; ++jj)
890 s_hat[aa][cc] += tVec(aa, ii) * t_S(ii, jj) * tVec(cc, jj);
891
892 int pair_0[sizeSymm];
893 int pair_1[sizeSymm];
894 V basis_hat[sizeSymm][Dim][Dim];
895 // Off-diagonal directions carry 1/2 to recover Cartesian Ddg components.
896 for (int ii = 0; ii != Dim; ++ii)
897 for (int jj = ii; jj != Dim; ++jj) {
898 const int LL = get_sym_index(ii, jj, Dim);
899 pair_0[LL] = ii;
900 pair_1[LL] = jj;
901 for (int aa = 0; aa != Dim; ++aa)
902 for (int bb = 0; bb != Dim; ++bb)
903 basis_hat[LL][aa][bb] =
904 (tVec(aa, ii) * tVec(bb, jj) + tVec(aa, jj) * tVec(bb, ii)) / 2;
905 }
906
908 for (int LL = 0; LL != sizeSymm; ++LL)
909 for (int JJ = 0; JJ <= LL; ++JJ) {
910 V v = 0;
911 for (int aa = 0; aa != Dim; ++aa)
912 for (int bb = 0; bb != Dim; ++bb)
913 for (int cc = 0; cc != Dim; ++cc)
914 v += s_hat[aa][cc] * ddf[aa][bb][cc] *
915 (basis_hat[LL][aa][bb] * basis_hat[JJ][bb][cc] +
916 basis_hat[JJ][aa][bb] * basis_hat[LL][bb][cc]);
917
918 t_diff_A(pair_0[LL], pair_1[LL], pair_0[JJ], pair_1[JJ]) = v;
919 if (JJ != LL)
920 t_diff_A(pair_0[JJ], pair_1[JJ], pair_0[LL], pair_1[LL]) = v;
921 }
922
923 return t_diff_A;
924 }
constexpr double a
static const double eps
const double v
phase velocity of light in medium (cm/ns)
auto get_sym_index(const Number< N1 > &, const Number< N2 > &, const Number< Dim > &)
double scale
Definition plastic.cpp:124

Member Data Documentation

◆ sizeSymm

template<typename T1 , typename T2 , int Dim>
constexpr int EigenMatrix::EigenMatrixContractedHessianImp< T1, T2, Dim >::sizeSymm = (Dim * (Dim + 1)) / 2
staticconstexpr

Definition at line 804 of file MatrixFunctionTemplate.hpp.

◆ tVal

template<typename T1 , typename T2 , int Dim>
Val& EigenMatrix::EigenMatrixContractedHessianImp< T1, T2, Dim >::tVal
private

Definition at line 927 of file MatrixFunctionTemplate.hpp.

◆ tVec

template<typename T1 , typename T2 , int Dim>
Vec& EigenMatrix::EigenMatrixContractedHessianImp< T1, T2, Dim >::tVec
private

Definition at line 928 of file MatrixFunctionTemplate.hpp.


The documentation for this struct was generated from the following file: