# divergence when mass diffusion UDF is included

Hi all,

I wrote an UDF with which to define effective diffusion coefficients in porous zone. In my UDF, molecular mass diffusion coefficients for all species are calculated according to their L-J parameters. Because I have 16 species in the system. The code has nearly 1000 lines. The UDF can be compiled and loaded without any errors.

However, it causes divergence after some iterations. Since the code is so long, I don't know where to start to check error. I think firstly there should be no syntax error because it can be compiled and loaded without error.

I think the logic of the code is wrong. Maybe it gives unreasonable mass diffusion coefficients or the loop inside the UDF becomes infinity at some points. In order to find out why, I want ask a question about this macro: DEFINE_DIFFUSIVITY

what is the sequence for this macro to assign mass diffusion coefficients to every species? does it assign diffusion coefficient for every species in a cell and then go to another cell? Or it just gives diffusion coefficients for a species in the whole domain and then goes to next species?

best regards.

weiqiang

## Comments

That may well depend on how you structured the code. Do you apply a different DEFINE_DIFFUSIVITY loop for each species then loop over the domain, or?

Try putting a cap on the returned value at a physically reasonable but "high" value eg 1e-3. See if that limit is hit after a few iterations.

The truth is I just used one DEFINE_DIFFUSIVITY to loop every species. So this is illogical, right? This macro only loops all cells, not all species?

Best.

Weiqiang

I tried to return a constant mass diffusion 1e-3 to all species. Then divergence does not happen anymore. Then this means that return value of my UDF is physically wrong, right?

Best

Weiqiang

Possibly: you need to check each section of the UDF and figure out what's causing the problem.

The diffusion coefficients are temperature and species mass fraction dependent?

Best

yes, it must be the UDF returns physically wrong value

Or it returns correct values but the problem is now getting more stiff with different scales. Check both: the returned values (via C_UDMI) and be a bit conservative with solver settings.

I set the under-relaxation factor of both species and energy to 0.01. Then divergence doesn't happen. is it allowable for such a small under relaxation factor in fluent?

Best

I was wrong. No matter how small the under relaxation factor is, divergence will happen.

Does this mean my returned value is not physically right?

Best.

I wont reduce implicit URF too much. 0.01 is definitely too low. Do not do that.

I enabled the stiff chemistry and coupled solver. It just postponed the divergence to 400 iterations. However, convergence was very good and results seems were approaching reasonable results before divergence.

Best regards.

Weiqiang

If you look at the results about 10 iterations before it diverges how are the diffusivity rates etc looking?

I am trying to do this. Can I ask a question related to this? Since I have 16 species and so many cells. Which kind of species and in which cell the mass diffusion coefficient I should check?

Best

Weiqiang