How to Understand the algorithm of the code

Hi,
I have studied the Numerics.pdf and Theory.pdf files. I started to read the main.f line by line but I finished without understanding where the solution actually takes place… most of the code was about initializing and suddenly it finishes… I get confused and I started to read the x-momentum source term subroutine to understand the momentum equation discretization. Yet, I do not understand what are the variables and I am getting confused more. It is necessary for me to understand each line of the code. I would appreciate any guidance!! How should I start to follow the code??

So you must not have liked my last suggestion!

If you continue to struggle, take a look at ~/model/mfix.f and ~/model/init_namelist.f

There’s a bit more commenting in mfix.f that may help you. Likewise in the namelist, although you’re still going to have to wade through tons of variable initialization.

Since there is no user support line for free software, you really do need to just dig in. MFIX is big, bulky and written by many, many people working together over decades. You will see lots of different programming styles and sometimes inconsistent variable naming. Be patient with yourself and your learning curve. It takes most people many months to understand its programmatic structure.

2 Likes

Another suggestion. If you’ve never done it, read:

Pantankar, S.V, “Numerical heat transfer and fluid flow,” McGraw-Hill, 1980. There are lots of newer copies floating around as well. This just happens to be the copy I have.

This book walks you through pretty much everything you need to know about how heat and mass transfer and fluid flow can be predicted with numerical solution. Much of MFIX is grounded in this seminal work.

1 Like

Thank you so much for your answer… your last answer helped me alot and I understand so many things. I have good knowledge of cfd but the problem is MFiX. I just get lost among all the subroutines and variable names. I do not know how does it take long to understand the code well to be able to change some parts. The problem is as you said. I should go forward to understand it if possible. But may be if someone make a flow chart of the implementation of subroutines, then everything would be much easier.
Thank you again for your answer. … always a great help for me…

I think you should starting with debugging with the “gdb”. Besides, I think it is better to use gdb with the help of Visual Studio Code, then you can start debugging the codes in GUI. The procedure is pretty standard like debugging all other open source programs. Ask the advice from your programmer friends would be helpful. Though I knows little about programming, I think this is the normal way to understand a open source program.

3 Likes

MFiX runs like this,
In mfix.f, there is the program MFIX,
it calls the SUBROUTINE RUN_MFIX,
In RUN_MFIX, it calls get_data to read the parameters in and allocate them, then it calls the INITIALIZE to initialize these parameters, then it has the do loop,
if there is fluid or TFM, run_fluid.
if there is DEM, run_dem,
if there is PIC, run_pic.
In each of this, it calculates the corresponding part one step by one step, one layer by one layer.
e.g. in run_fluid, it DO_ITERATION.
in run_dem, it DES_TIME_STEP
in run_pic, it PIC_TIME_MARCH.

Hope it helps.

3 Likes

Dear Yupeng,
Thank you for your answer. I am working on the implementation of OpenMP and MPI in MFiX, I have check most of the subroutines but I do not know some of the variables, which are not defined in comments. Actually because of these, I do not know how the MPI and OpenMP works in this software. Do you have any idea?

My suggestion is:
go through the routines for TFM that you are working on,
then check the MPI/SMP for MPI, e.g. how the domain was divided into sub regions for MPI.
and find OMP for OpenMP, they can be seen in the code.

1 Like

And any hint on the variables which is not defined explicitly in comments?

Thank you so much for your hints… That will help me a lot!!!

In which file can I find a detailed definition of the subroutine run fluid?

Chen -

Please do not add to old posts that are already marked “Solved”, this makes it easier for us to keep track of issues on the forum.

Many of the questions that are asked here about “Where do I find the definition of symbol X” could be solved with a simple search command (grep on Unix, also works on Windows in a Conda environment).

$ grep -ir 'run_fluid'
mfix.f:            call run_fluid
mfix.f:      subroutine run_fluid
mfix.f:      end subroutine run_fluid