Problems in using write_usr1.f

How to output a variable with only one value per time step?

Hello, everyone. I have a problem when using a two-fluid model to simulate a fluidized bed. I want to output a value related to particle volume fraction in the binary particle system, which is like standard deviation, meaning that a “standard deviation” will be calculated for each time step. I failed to output this “standard deviation”.

I tried outputting in write_usr1.f , and I didn’t think there was any logical problem. However, when I ran the case, it still reported an error and displayed float invalid . It looks like there is a problem with the ep_s , and I don’t know the reason for this issue or how it can be resolved.

May I ask if you can help me solve this difficulty? Looking forward to your help and reply. Thank you.
My case and f file are as follows.
test.mfx (9.7 KB)
write_usr1.f (3.5 KB)

Solids density ro_s is zero, triggering a divide-by-zero error:

$ gdb python core
$ where
#0  0x00007faa8ec9fd9b in fldvar::ep_s (ijk=1, xxm=1)
    at /home/cgw/miniforge3/envs/mfix-git/share/mfix/src/model/fldvar_mod.f:181
181	      EP_s = ROP_s(IJK, xxM)/RO_S(IJK,xxM)

(gdb) p IJK
$1 = 1
(gdb) p xxM
$2 = 1
(gdb) p RO_S(1,1)
$3 = 0

May I ask why this happened? I set the densities of both solid phases to non-zero constants in the mfix file.

It looks like this is happening in cell IJK=1 which is a corner cell, and is not used. If you add a line

        IF (.NOT. FLUID_AT(IJK)) CYCLE

to your IJK loop, the problem goes away.

I also suggest you fix the code indentation so the program structure is more visible. This is easy to do if you use a Fortran-aware editor or a tool like fprettify which you can install easily with
pip install fprettify
Here’s a cleaned-up version of the file:
write_usr1.f (3.7 KB)

Note that it’s also slightly more efficient to open the file once in write_usr0.f and close it in usr3.f instead of opening/closing for every write, as you are doing. But the overhead is probably not observable, at the rate you are writing.
See 10. User-Defined Functions — MFiX 24.4 documentation

Thank you very much! After making the changes you provided, the case ran successfully.

By the way, I will try the more efficient method you mentioned.