CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   Define_adjust does't work (https://www.cfd-online.com/Forums/fluent/120809-define_adjust-doest-work.html)

luckchen July 15, 2013 09:42

Define_adjust does't work
 
HI,guys!
I'm aiming to write a udf to achieve getting the water vaper mass fraction and store it. the codes as follows:

DEFINE_ADJUST(water_fraction,d)
{Thread *t;
cell_t c;
real watdry;
real watwet;
real watdryav;
real watwetav;
real volume;
real vol_tot;
real vol_tot2;
thread_loop_c(t,d)
{if(THREAD_ID(t)==26) /* dry gdl */
{
begin_c_loop(c,t)
{
volume=C_VOLUME(c,t);
watdry=C_YI(c,t,0);
watdryav+=watdry*volume;
vol_tot+=volume;
}
end_c_loop(c,t)
}
else if(THREAD_ID(t)==27) /* wet gdl */
{
begin_c_loop(c,t)
{
volume=C_VOLUME(c,t);
watwet=C_YI(c,t,0);
watwetav+=watwet*volume;
vol_tot2+=volume;
}
end_c_loop(c,t)
}
}
watdryav/=vol_tot;
watwetav/=vol_tot2;
thread_loop_c(t,d)
{if(THREAD_ID(t)==26)
{
begin_c_loop(c,t)
{
C_UDMI(c,t,1)=watdryav;
}
end_c_loop(c,t)
}
else if(THREAD_ID(t)==27)
{
begin_c_loop(c,t)
{
C_UDMI(c,t,2)=watwetav;
}
end_c_loop(c,t)
}
}
}

I get the THREAD_ID(t) number (26,27) from fluent bc pannel,and they are porous zones,but when i run through this codes,it does't work,the value of C_UDMI(c,t,2) or C_UDMI(c,t,1) is still zero when i check out the fluent results.
Thanks in advance for any suggestions

blackmask July 15, 2013 10:06

You need a text editor with indention. Add a "{" after
Code:

thread_loop_c(t,d)
and put a "}" at the end of your code shown above and try again.

luckchen July 15, 2013 21:03

Quote:

Originally Posted by blackmask (Post 439822)
You need a text editor with indention. Add a "{" after
Code:

thread_loop_c(t,d)
and put a "}" at the end of your code shown above and try again.

Hi,blackmask,thanks for your reply.in my codes,i have a "{" after the thread_loop_c(t,d),maybe you haven't seen it clearly.
Code:

thread_loop_c(t,d)
{if(THREAD_ID(t)==26)

In order to make my codes more clear,i present my codes again as follows:
Code:

DEFINE_ADJUST(water_fraction,d)
{Thread *t;
 cell_t c;
 real watdry;
 real watwet;
 real watdryav;
 real watwetav;
 real volume;
 real vol_tot;
 real vol_tot2;
 thread_loop_c(t,d)
 {
        if(THREAD_ID(t)==26) /* dry gdl */
    {
            begin_c_loop(c,t)
            {
        volume=C_VOLUME(c,t);
        watdry=C_YI(c,t,0);
        watdryav+=watdry*volume;
        vol_tot+=volume;
            }
            end_c_loop(c,t)
            }
    else if(THREAD_ID(t)==27) /* wet gdl */
    {
            begin_c_loop_all(c,t)
            {
                    volume=C_VOLUME(c,t);
                    watwet=C_YI(c,t,0);
                    watwetav+=watwet*volume;
                    vol_tot2+=volume;
            }
            end_c_loop_all(c,t)
    }
 }
 watdryav/=vol_tot;
 watwetav/=vol_tot2;
 thread_loop_c(t,d)
 {
        if(THREAD_ID(t)==26)
    {
            begin_c_loop(c,t)
            {
        C_UDMI(c,t,1)=watdryav;
            }
            end_c_loop(c,t)
    }
    else if(THREAD_ID(t)==27)
    {
            begin_c_loop(c,t)
            {
        C_UDMI(c,t,2)=watwetav;
            }
            end_c_loop(c,t)
    }
  }
}


blackmask July 15, 2013 21:42

Fair enough. You could use
Code:

Lookup_Thread
instead of "thread_loop_c" for you purpose.

Are you sure that both "watdry" and "watwet" are the same species "C_YI(c,t,0)"? You could print the value of watdryav, watwetav, vol_tot, vol_tot2 use
Code:

Message
Make sure that the loop over cells is actually executed.

luckchen July 16, 2013 10:15

hi blackmask,thank you for your advices.
i just try the code lookup_thread,but it also can't not work.the udf presented is a small part among my all udf documents,and there are many udfs i haven't present here including
Code:

thread_loop_c(t,d)
 {
        if(THREAD_ID(t)==26) /* dry gdl */
    {
            begin_c_loop(c,t)
            {
        .......
            }
            end_c_loop(c,t)
            }
 }

so i just want to figure out the mistake using the code above,which will also help modify other udfs.

both "watdry" and "watwet" are the same species "C_YI(c,t,0)",i use species transport model in my case,the fluid is a mixture of watervapor and dry air.C_YI(c,t,0) represents the watervapor.

and i use the syntax 'message' to print the value of some varibles,when run the case,all values equal to zero,so thread_loop_c(t,d) is not actually executed.

achint August 8, 2015 19:19

Hi Luckchen,

Were you ever able to resolve this problem? Could you please share the details?


All times are GMT -4. The time now is 13:46.