CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

How to improve the efficiency of my UDF?

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 19, 2019, 08:26
Default How to improve the efficiency of my UDF?
  #1
Member
 
Dave
Join Date: Mar 2019
Posts: 33
Rep Power: 3
bloodflow is on a distinguished road
Hi all,

I have two UDF's that I am using to define the viscosity of a secondary phase, one UDF works perfectly and doesnt slow down the solution, the other causes the iterations to be incredibly slow (for larger meshes). I think this is due to my if statement, but is there any way to improve the efficiency? currently the slow UDf is unusable due to how slow it is.

PHP Code:
DEFINE_PROPERTY(rbc_visco,c,thread)
{
Domain *mix_domain Get_Domain(1);
Thread *mix_thread;
Thread **pt;
real phirbcviscoshearmuplasmak0kinfgammackval;
mp_thread_loop_c(mix_threadmix_domainpt)
{
phi=C_VOF(c,pt[1]);
shear=C_STRAIN_RATE_MAG(c,pt[1]);
muplasma=0.00123;
k0=((0.06106410882322652)+(2/(0.047770935254055194+phi)));
kinf=exp(1.8009617109358729-(3.6660219116019688)*(phi)+(2.574119363866957)*(pow(phi,2))+(0.023458247768672405)*(pow(phi,3)));
gammac=exp(-7.013323148316977+(34.3877131444968)*(phi)-(39.80154094066538)*(pow(phi,2))+(13.991671192652591)*(pow(phi,3)));
kval=((k0)+(kinf)*(pow((shear)/(gammac),0.5)))/(1+(pow((shear)/(gammac),0.5)));
rbcvisco=((((muplasma)*(pow(1-((phi*kval)/2),-2))-((muplasma)*(1-phi)))/(phi)));
}
return 
rbcvisco;

This is the UDF that works without a problem, and is fast regardless of mesh but this one:

PHP Code:
DEFINE_PROPERTY(rbc_visco,c,thread)
{
Domain *mix_domain Get_Domain(1);
Thread *mix_thread;
Thread **pt;
real rbcvofrbcviscoshearmuplasmarbcvof_critbcharliebetalambflickvninfdimshearnstnsum;
muplasma=0.00123;
rbcvof_crit=0.98;
b=8.780739943551884;
charlie=2.823542271766962;
beta=16.277748270259284;
lamb=1252.6440693060042;
flickv=0.14274532071176718;

mp_thread_loop_c(mix_threadmix_domainpt)
{

begin_c_loop(c,pt[1])
{

rbcvof=C_VOF(c,pt[1]);

if (
rbcvof<0.2)
        {
        
shear=C_STRAIN_RATE_MAG(c,pt[1]);
        
ninf=(b)*(exp(-charlie*(rbcvof)));
        
nsum=ninf;
        
rbcvisco=((muplasma)*(rbcvof+(pow((1-(rbcvof/rbcvof_crit)),-nsum))-1))/(rbcvof);
        }
else
        {
        
shear=C_STRAIN_RATE_MAG(c,pt[1]);
        
ninf=(b)*(exp(-charlie*(rbcvof)));
        
dimshear=1+pow((lamb*shear),2);
        
nst=beta*(pow((dimshear),(-flickv)));
        
nsum=(ninf+nst);
        
rbcvisco=((muplasma)*(rbcvof+(pow((1-(rbcvof/rbcvof_crit)),-nsum))-1))/(rbcvof);
        }

}

end_c_loop(c,pt[1])
}

return 
rbcvisco;

Works okay for small meshes, but for my detailed models it is incredibly slow. What can I do to improve this, is it the additional "beging_c_loop"? I am not 100% on which part of my second UDF is relevant.


Thanks you for any advice.
bloodflow is offline   Reply With Quote

Old   August 20, 2019, 01:39
Default
  #2
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 1,574
Rep Power: 21
AlexanderZ will become famous soon enough
why do you use additional cell loop
remove
Code:
begin_c_loop(c,pt[1])
{
this is the reason, why it is slow, you have loop over all cells on each cell
c is already defined in the header of macro

best regards
AlexanderZ is offline   Reply With Quote

Reply

Tags
if-statement, phase, udf, viscosity

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Save output of udf in another udf! JuanJoMex FLUENT 0 February 8, 2018 13:43
UDF problem- time dependent temperature at inlet kaeran FLUENT 1 June 16, 2015 22:48
parse error while interpreting udf Kristin Fluent UDF and Scheme Programming 3 March 15, 2012 07:43
How to add a UDF to a compiled UDF library kim FLUENT 3 October 26, 2011 22:38
I need UDF help. S.Whitney FLUENT 0 October 15, 2007 12:29


All times are GMT -4. The time now is 05:48.