Currently I’m working on dense system matrices and I’m not sure which data typ is best to use for that kind of problem.
Sure, typically FlatMatrix and Matrix are used in such cases. However your KrylovSpaceSolver is a child of BaseMatrix. Since FlatMatrix and Matrix are children of MatExpr, and not BaseMatrix, those solvers can’t be used. I was thinking about still using a SparseMatrix ( with losts of entries) to be able to use the solvers. But I have no idea if that will result in more memory consumption that simply using FlatMatrix.
Could you please tell me what the preferred matrix type should be for dense system matrices?
Thank you all!
I would use the Matrix class to store dense matrices. You could wrap you dense matrix in a BaseMatrix to use it in a routine that expects BaseMatrix.
You can even do this in Python, you only need to implement Mult, Height and Width functions:
def Mult(self, x, y):
# implement y = mat * x
the incoming vectors are BaseVector. You can use the x.FV() to get a flatvector from the basevector
Thank you for your answer.
I have my code in c++ (kinda included in the mylittleNGSolve structure for easy installing) Therefore I tried to simply make a child class of BaseMatrix as you adviced. (but in c++)
However, since the constructors of BaseMatrix are all protected, the constructor of my child class does not work.
For example: Put MyBaseMatrix2.hpp into the folder 1_Basic/4_utility_functions (of mlngs) and put an “#include “myBaseMatrix2.hpp”” in the beginning of myAssembling.cpp and “MyBaseMatrix2<> sys_matrix(ne,ne);” in line 35 of the same file. While installing, you won’t be having problems, but if you then run 4_utility_functions/assembling.py with python3, you’ll get the error
“ImportError: [location of installation of myngspy.so]: undefined symbol: _ZN4ngla13MyBaseMatrix2IdED1Ev”.
However DiagonalMatrix (in linalg/special_matrix.hpp) seems to be implemented in the pretty same way, which confuses me.
Could you please tell me how to write a proper matrix class in c++? Or is there a simple error in “myBasisMatrix2.hpp”?
Thank you again, Julia
You have to define your functions, the destructor and the createvectors are only declared but not defined.
Oh, yes. That’s right. However it didn’t fix the problem. The same error (_ZN4ngla13MyBaseMatrix2IdED1Ev) was still there.
I got it fixed by putting
template class MyBaseMatrix2;
into the end of the .cpp file. Otherwise python seems to have problems to find the class.
Thanks for your answers again.
Not python. The compiler creates the code only at template instantiation. If you do not specify it while compiling the cpp file then they cannot be found from the other (python export) cpp file afterwards. Other option is to define the functions in the header file.