CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM (
-   -   Solving System of Linear equations (

shchepan September 29, 2009 08:33

Solving System of Linear equations
I need to solve in OpenFOAM system of linear equation like
A*b = c
where A is tensor (rank 2) and c is vector. A and c are constants.

How can I solve this equation?
Thank you

shchepan September 30, 2009 01:03

Thank you, Stanley!
Can you show how to use this function?
What H-file I should include solve function to work?

shchepan October 1, 2009 00:09

//I've created tensor A:
tensor A(Axx, Axy, Axz, Ayx, Ayy, Ayz, Azx, Azy, Azz);
//and vector c:
vector c(cx, cy, cz);

and now I want to get vector b: A*b=c

akidess October 1, 2009 19:05

Why use OpenFOAM instead of MATLAB / Octave for this?

shchepan October 2, 2009 00:46

Anton, because it is only one step of big programm.
First I solve MHD turbulent equations in crucible. Then I solve lagrangian equation for solid particle motion. I take into acount lift force to (proportional U x rot(U)). And to solve this aquation I need to solve system of linear algebraic equations.

nikwin November 14, 2010 14:03

Hi Mihails,

I would also be able to solve a system of linear equations in OF as a part of a larger code. Did you ever find out if there is a possibility to solve a system of linear equations i OF?


Lukasz November 14, 2010 16:04

Why don't you use our GPU-baed code ( It can be easily plugged to OF. So far we support CG/BiCGSTAB for solving symmetric/unsymmetric matrices in single/double precision (soon also with complex values).

shchepan November 15, 2010 03:50

Year ago I decided that it is much easier for me to write my own code that solve systems of linear equation using Gauss method.

Lukasz November 15, 2010 05:30

But happens if the matrix is huge and sparse. The memory requirements are quite high for Gauss method.

shchepan November 15, 2010 05:40

Of course you are right, Lukasz. I am solving my specific problem and I have no goal to write universal code for systems of linear equations.

nikwin November 16, 2010 05:27

Thanks both of you!

The simplest way for me is to go for Michails suggestion, which I've already implemented in Matlab. Now I will just need to rewrite it into OF which for me will be the tricky part.


herbert November 16, 2010 05:36


if you want to use Gauss-algorithm only, you don't have to hardcode it. There is already a class called simpleMatrix which can do this job. The source is located in src/OpenFOAM/matrices/simpleMatrix/ .

I don't know if there is an example in any solver, but it is quite simple to use.


nikwin November 16, 2010 07:52


It works as expected.


Danath December 5, 2013 11:40

Hello ! can you tell me how you add simpleMatrix to your code ?

I am trying to do the same thing but i have a lot of problems !

All times are GMT -4. The time now is 07:56.