21 #ifndef RFFGEN_LINEAR_ALGEBRA_PRINCIPAL_INVARIANTS_HH
22 #define RFFGEN_LINEAR_ALGEBRA_PRINCIPAL_INVARIANTS_HH
24 #include <type_traits>
26 #include "dimension.hh"
28 #include "cofactor.hh"
29 #include "determinant.hh"
30 #include "shiftedInvariant.hh"
31 #include "../Util/base.hh"
38 namespace Concepts {
template <
class>
struct SymmetricMatrixConceptCheck; }
43 namespace LinearAlgebra
50 template <
class Matrix>
51 auto computeCofactors(
const Matrix& A, std::integral_constant<int,2>)
53 return computeCofactor<0,0>(A) + computeCofactor<1,1>(A);
56 template <
class Matrix>
57 auto computeCofactors(
const Matrix& A, std::integral_constant<int,3>)
59 return computeCofactor<0,0>(A) + computeCofactor<1,1>(A) + computeCofactor<2,2>(A);
62 template <
class Matrix >
63 auto computeCofactors(
const Matrix& A, std::integral_constant<int,-1>)
65 if(rows(A) == 2)
return computeCofactors(A,std::integral_constant<int,2>());
66 return computeCofactors(A,std::integral_constant<int,3>());
69 template <
int row,
class Matrix>
70 auto symmetricCofactorDerivative(
const Matrix& A,
const Matrix& dA)
72 return computeCofactorDirectionalDerivative<row,row>(A,dA) + computeCofactorDirectionalDerivative<row,row>(dA,A);
76 template <
class Matrix>
77 auto computeSymmetricCofactorDerivatives(
const Matrix& A,
const Matrix& B, std::integral_constant<int,2>)
79 return symmetricCofactorDerivative<0>(A,B) + symmetricCofactorDerivative<1>(A,B);
82 template <
class Matrix>
83 auto computeSymmetricCofactorDerivatives(
const Matrix& A,
const Matrix& B, std::integral_constant<int,3>)
85 return symmetricCofactorDerivative<0>(A,B) + symmetricCofactorDerivative<1>(A,B) + symmetricCofactorDerivative<2>(A,B);
89 template <
class Matrix >
90 auto computeSymmetricCofactorDerivatives(
const Matrix& A,
const Matrix& B, std::integral_constant<int,-1>)
92 if(rows(A) == 2)
return computeSymmetricCofactorDerivatives(A,B,std::integral_constant<int,2>());
93 return computeSymmetricCofactorDerivatives(A,B,std::integral_constant<int,3>());
106 template <
class Matrix>
113 template <
class Matrix,
class = Concepts::SymmetricMatrixConceptCheck<Matrix> >
116 using DimIdentifier = std::integral_constant<int,dimension<Matrix>()>;
131 resultOfD0 = Detail::computeCofactors(A,dimIdentifier);
145 auto d1(
const Matrix& dA1)
const
147 return Detail::computeSymmetricCofactorDerivatives(A_,dA1,dimIdentifier);
156 auto d2(
const Matrix& dA1,
const Matrix& dA2)
const
158 return Detail::computeSymmetricCofactorDerivatives(dA1,dA2,dimIdentifier);
163 std::decay_t< at_t<Matrix> > resultOfD0 = 0.;
164 DimIdentifier dimIdentifier;
171 template <
class Matrix>
179 template <
class Matrix ,
int offset = dimension<Matrix>() >
186 template <
class Matrix ,
int offset = dimension<Matrix>() >
193 template <
class Matrix >
198 #endif // RFFGEN_LINEAR_ALGEBRA_PRINCIPAL_INVARIANTS_HH
auto d2(const Matrix &dA1, const Matrix &dA2) const
Second directional derivative.
Definition: principalInvariants.hh:156
void update(const Matrix &A)
Reset matrix to compute second principal invariant from.
Definition: principalInvariants.hh:128
SecondPrincipalInvariant(const Matrix &A)
Constructor.
Definition: principalInvariants.hh:125
auto d0() const
Value of the second principal invariant.
Definition: principalInvariants.hh:135
Base class for functions satisfying FunctionConcept. Required for enabling the operators in generate...
Definition: base.hh:27
Possibly scaled, shifted invariant , where for the first two (principal,modified) invariants and fo...
Definition: shiftedInvariant.hh:43
SecondPrincipalInvariant()=default
Default constructor.
Second principal invariant for .
Definition: principalInvariants.hh:114
Determinant< Matrix > ThirdPrincipalInvariant
Third principal invariant for .
Definition: principalInvariants.hh:172
auto d1(const Matrix &dA1) const
First directional derivative.
Definition: principalInvariants.hh:145
std::conditional_t< Checks::isConstantSizeMatrix< Matrix >(), ConstantSizeTrace< Matrix >, DynamicSizeTrace< Matrix > > Trace
Trace of a matrix (sum of diagonal elements).
Definition: trace.hh:213
std::conditional_t< Checks::isConstantSizeMatrix< Matrix >(), ConstantSizeDeterminant< Matrix >, DynamicSizeDeterminant< Matrix > > Determinant
Determinant with first three derivatives.
Definition: determinant.hh:230
Trace< Matrix > FirstPrincipalInvariant
First principal invariant for .
Definition: principalInvariants.hh:107