Forum Message

 

 

We have moved the forum to https://forum.ngsolve.org . This is an archived version of the topics until 05/05/23. All the topics were moved to the new forum and conversations can be continued there. This forum is just kept as legacy to not invalidate old links. If you want to continue a conversation just look for the topic in the new forum.

Notice

The forum is in read only mode.

Dense Matrix - c++ mlngs

More
3 years 2 months ago #3535 by jhauser
Hallo!

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!
Julia
More
3 years 2 months ago #3554 by christopher
Hi,
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:
Code:
class MyBaseMatrix(BaseMatrix): def __init__(self): super().__init__() def Height(self): return ... def Width(self): return ... 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

Best Christopher
More
3 years 1 month ago - 3 years 1 month ago #3575 by jhauser
Replied by jhauser on topic Dense Matrix - c++ mlngs
Hi!
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
Last edit: 3 years 1 month ago by jhauser.
More
3 years 1 month ago #3580 by christopher
You have to define your functions, the destructor and the createvectors are only declared but not defined.

Best
Christopher
More
3 years 3 weeks ago #3644 by jhauser
Replied by jhauser on topic Dense Matrix - c++ mlngs
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<double>;

into the end of the .cpp file. Otherwise python seems to have problems to find the class.
Thanks for your answers again.
More
3 years 3 weeks ago #3645 by christopher
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.
The following user(s) said Thank You: jhauser
Time to create page: 0.148 seconds