# logic of an UDF to define mass diffusion coefficients for all species in the system

• 37 Views
• Last Post 14 June 2019
• Topic Is Solved
Weiqiang Liu posted this 12 June 2019

Hi all,

I am trying to use an UDF to define mass diffusion coefficients for all species in the system. However, it causes divergence after some iterations.

In order to debug the code, I wrote a line "C_UDMI(c,t,i)=deffective[i]" to store mass diffusion coefficient of i specie in i UDM. Then I run the model and tried to display mass diffusion coefficient contour of some species before divergence happened. I found that all mass diffusion coefficients UDF returned were zero. This is definitely not reasonable. Therefore, I guess the following reasons:

1. Might it be some numerical reasons that all number below some threshold value is treated as zero in fluent? Because the magnitude of mass diffusion coefficient is normally e^-6 to e^-5.

2. I used the species index "i" in the macro DEFINE_DIFFUSIVITY(name,c,t,i) to loop every species in the system. I also defined an array to store mass diffusion coefficients the UDF returns which is deffective[16]. In every loop i, a coefficient deffective[i] is returned to species i. The reason I don't just define a real number deffective to store mass diffusion coefficient returned is because I think the value returned now will cover and erase the value returned previously for the last specie. Am I thinking right?

Any suggestions will be very appreciated?

Best.

Weiqiang

abenhadj posted this 13 June 2019

What is the formula of the diffusion coefficient?

Best regards,

Amine

abenhadj posted this 13 June 2019

And again you need an additional specie loop if the diffusion coefficients are dependent on other mass fraction of the not "i" specie. The whole macro should return a single value which will depend on the "i" specie.

Best regards,

Amine

Weiqiang Liu posted this 14 June 2019

Hi Amine

I think what you said really makes sense. Because I need to hook my UDF in mixture material panel. However, fluent can not loop every species for me. I need to use specie loop to loop every specie by myself.

Though I don't know how to do it now. I am starting to realize the logic of my UDF is wrong.

Thanks very much!!!

you're my life saver!!!!!

Best regards

Weiqiang

abenhadj posted this 14 June 2019

Fluent will loop over the species. You require if conditions and another species loop if the coefficients are depending on mass fraction of other !i specie(s)

Best regards,

Amine

Weiqiang Liu posted this 14 June 2019

you said I need 'if condition'. Do you mean I should use IF to return different diffusion coefficients to different zones. Because I need effective diffusion in porous zone while molecular diffusion in fluid zone.

Best regards

Weiqiang

abenhadj posted this 14 June 2019

Yes: if i==0 (means species with indexs 0) or better to check the species name etc.. then mycoeff= my value..

Best regards,

Amine

Weiqiang Liu posted this 14 June 2019

Hi Amine,

You said fluent can loop all species. I only need to use a species loop because my diffusion coefficient is related to the other species in the system. So what I think the way IF is used is like:

return deffective;

return dmolecular;

abenhadj posted this 14 June 2019

Again: DEFINE_DIFFUSIVITY is giving for each UDS/specie "i" a return value. I do not know what now you do want to do with THREAD_ID.

if i==0 (species-0)

mycoeff=123456.32155

if i==1

mycoeff=887978797

..

..

return my coeff

You can then customize all for every single cell zone..

Best regards,

Amine

Weiqiang Liu posted this 14 June 2019

I want to use THREAD_ID because I want to define different diffusion coefficients in different zones for every species. My code is like :

mycoeff=12345

mycoeff=23233

return mycoeff;

is this doable?

Best regards

Weiqiang

abenhadj posted this 14 June 2019

Try and debug.

Best regards,

Amine

Weiqiang Liu posted this 14 June 2019

I'll try hard. Thanks for your concern

Best regards

Weiqiang

abenhadj posted this 14 June 2019

good luck

Best regards,

Amine