Generation and export of system matrices


I want to integrate the FE model of a given geometry in a simulation model that is solved in another tool, e.g. Matlab. For that I want to mesh the geometry with Netgen and generate/export the system matrices (as linearization at a given point).

The problem would be a transient heat transfer problem. The interface/BC should be the heat flux densities at the surface elements of the generated mesh.

Would this be possible to do with Netgen/NGSolve?


In principle? Yes. You can create numpy/scipy matrics from NGSolve and afaik you can store these matrices in Matlab format. Probably won’t be very efficient though…

Thanks for the rapid reply.
Efficiency is not our major concern atm.
Can you give me an entry point in the documentation for this?

I think the easiest way is to first go to numpy. Then there is a lot of stuff online for numpy ↔ matlab. For exporting to numpy see for example here:

Ok, thanks. I guess Numpy/Matlab is already covered on my side.
Basically I wanted to know if there is (easy) access to a vector/matrix representation of the system equations in NGSolve.

Yes. After assembling the matrix (stored in sparse csr format) is accessible by a.mat, the vector of the right hand side as f.vec. The sparse matrix has .CSR and .COO methods to get numpy arrays for the different sparse matrix formats.

For the input it depends how your heat flux is given. If it is described by a function you can formulate it using NGSolve CoefficientFunctions.