Registered Member
|
According to Eigen documentation, using fixed-size matrices has efficiency benefits over dynamic size ones.
I have a situation in C++ multiple inheritance, say finite element method as an example. Base class: CElement Two derived classes: CTriangleElement, CBrickElement Assume there are two data members in the base class CElement, _n, the number of nodes in the element, and a stiff matrix, say Km with size of(_n x_n). The _n data member will be initialized to the known actual number of nodes in the derived classes accordingly. The _n in CTriangleElement is 3 and 8 in CBrickElement. In this scheme, how do I use the fixed sized Km in the derived classes which is declared in the based class? |
Moderator
|
I'm not sure to understand your precise issue, so I'll assume your classes are template classes, so you can do something like:
using Base::Km; in your derived classes where Base is CElement<...> |
Registered Member
|
What I mean is that for the stiff matrix Km, declared at base class CElement, it will be Matrix3d for CTriangleElement and Matrix8d for CBrickElement as fixed matrices for efficiency reason. Is it possible to accomplish this?
|
Moderator
|
sure, to this end you have two options: add a template parameter to CElement representing the size of the matrix, or use the CRTP pattern which is more complex but more powerful to factorize code (this is what do all the time in Eigen):
|
Registered Member
|
Thanks for your help. However I still have problems understanding your codes. Could you make a simple c++ program to demonstrate it?
Also , I would like to have CTriangleElement derived from CElement, say something looks like class CTriangleElement:public CElement { };
|
Moderator
|
I forgot something:
this probably makes more sense now!! |
Registered Member
|
sorry, I got it.
|
Registered users: Baidu [Spider], Bing [Bot], Google [Bot]