| 830 | } |
| 831 | |
| 832 | shared_ptr<CoefficientFunction> Diff (const CoefficientFunction * var, |
| 833 | shared_ptr<CoefficientFunction> dir) const override |
| 834 | { |
| 835 | if (this == var) return dir; |
| 836 | if (this->Dimensions()[0] <= 2) |
| 837 | { |
| 838 | //Cofactor Matrix linear in 2d (in 1d Cofactor Matrix = 0) |
| 839 | return CofactorCF(c1->Diff(var,dir)); |
| 840 | } |
| 841 | else if (this->Dimensions()[0] == 3) //3d |
| 842 | { |
| 843 | //formula follows from Cayley–Hamilton |
| 844 | //Cof(A) = 0.5*(tr(A)**2 - tr(A**2))I - tr(A)A^T +(AA)^T |
| 845 | |
| 846 | //return (0.5*(TraceCF(c1)*TraceCF(c1) - TraceCF(c1*c1))*IdentityCF(3) - TraceCF(c1)*TransposeCF(c1) + TransposeCF(c1*c1))->Diff(var,dir); |
| 847 | auto trace_c1 = TraceCF(c1); |
| 848 | auto diff_c1 = c1->Diff(var,dir); |
| 849 | auto trace_diff_c1 = TraceCF(diff_c1); |
| 850 | auto diff_c1_x_c1 = diff_c1 * c1; |
| 851 | auto c1_x_diff_c1 = c1 * diff_c1; |
| 852 | return (trace_c1 * trace_diff_c1 - TraceCF(diff_c1_x_c1)) * IdentityCF(3) |
| 853 | - trace_diff_c1 * TransposeCF(c1) |
| 854 | - trace_c1 * TransposeCF(diff_c1) + TransposeCF(diff_c1_x_c1 + c1_x_diff_c1); |
| 855 | } |
| 856 | else |
| 857 | throw Exception("CofactorCF Diff only implemented for dim <=3"); |
| 858 | } |
| 859 | |
| 860 | shared_ptr<CoefficientFunction> DiffJacobi (const CoefficientFunction * var, typename BASE::T_DJC & cache) const override |
| 861 | { |
nothing calls this directly
no test coverage detected