2017-01-10 72 views
0

在我的代碼定義了一個模板類與定義如下的operator()Eigen沒有用於調用.dot()的匹配函數?

template<class Integrator, int ORDER> 
inline double operator() (FiniteElement<Integrator, ORDER,2,3>& currentfe_, 
          int i, int j, int iq, int ic = 0) 
{ 
    Real s = 0; 

    Eigen::Matrix<double,2,1> grad_phi_i; 
    Eigen::Matrix<double,2,1> grad_phi_j; 

    grad_phi_i(0) = ... 
    grad_phi_i(1) = ... 
    grad_phi_j(0) = ... 
    grad_phi_j(1) = ... 

    s = grad_phi_i.dot(currentfe_.metric().dot(grad_phi_j)); 

    return s; 
} 

currentfe_.metric() 

FiniteElement類的方法返回一個Eigen::Matrix<double,2,2>

我得到的錯誤是:

error: no matching function for call to ‘Eigen::Matrix<double, 2, 1>::dot(Eigen::internal::scalar_product_traits<double, double>::ReturnType)’ 
s = grad_phi_i.dot(currentfe_.metric().dot(grad_phi_j)); 

而且我想不通爲什麼。

回答

2

這是因爲Matrix .dot()方法僅適用於向量之間的標量乘積(請參閱documentation)。 Here您可以看到矩陣和矢量之間的乘法運算使用*執行。

一種可能的解決方案是:

grad_phi_i*currentfe_.metric()*grad_phi_j.transpose() 
+0

確切地說,它確實有一個'.DOT()'方法但這只是爲兩個向量之間的標量積,並返回類型因此是標量。 – ggael

+0

@ggael是對的。我將編輯答案以澄清這一點並提供參考。 – nickerx