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

UDF Compiling / Parallel mode

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By obscureed

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 23, 2018, 11:34
Default UDF Compiling / Parallel mode
  #1
New Member
 
Join Date: May 2018
Posts: 8
Rep Power: 8
MV78 is on a distinguished road
Hi,
I am currently using a DEFINE_MATERIAL udf. I am a beginner as a Fluent user and I would have several questions if you can answer them :

- I understand that it is faster to use compilation for UDF material properties, but I've never seen anyone quantifying the speed improvement ? Has anyone how much faster it is ? No general result of course, but an idea ?

- What are the methods to compile a UDF or a library ? Following tutorials to compile with microsoft visual studio, I thought that somehow fluent has to be run in parallel with an external compiler by linking the environment variables of Fluent. That's why you use crossed commands from Visual Studio to launch Fluent. However, if the udf and the library have been compiled successfully the first time it will not be necessary to compile them again next time ? How does it work ?

- Do you think my UDF in parallel case ?

#include "udf.h"
#include "math.h"

DEFINE_SPECIFIC_HEAT(my_user_cp, T, Tref, h, yi)
{
real cp
real cps
real cpl
real DT
real r
real Tm

Tref=273.15;

cps=2025;
cpl=4180;
Tm=273.15;
DT=0.5;
r=10/DT;

cp=cps+(cpl-cps)/(1+exp(r*(Tm-T));

*h = cpl*(T-Tref)+(cpl-cps)/r*log(fabs(1+exp(-r*(T-Tm)))/fabs(1+exp(-r*(Tref-Tm))));

return cp;
}

Thank you in advance !

MV78
MV78 is offline   Reply With Quote

Old   May 23, 2018, 13:43
Default
  #2
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 12
obscureed is on a distinguished road
Hi MV78,


The number of limitations on an interpreted UDF is so large that I would never even consider using interpreted. DEFINE_SPECIFIC_HEAT is one of them -- this is mentioned explicitly in the help files for that macro.


There are some useful posts on compiling UDFs -- for example: links to instructions Visual Studio 2017 for udf use - which modules do I need?; troubleshooting errors How to solve UDF compilation problems in Fluent.; the basic steps of compile/load/hook The UDF library you are trying to load (libudf) is not compiled for 3D on the current. Note that with more recent installations, there is no requirement for the horrible clunky nonsense of starting Fluent from a yellow SDK command prompt or changing environment variables by hand.


Some comments on your UDF:
1) You need semicolons at the end of each statement -- specifically "real cp;" etc. The compiler should detect this and give you an error. (Try it and see -- that way, you may learn how to understand the compiler error for the next time.)
2) Tref is supplied to you as an input parameter -- it is not available for you to change. (Changing it inside the UDF would have no effect anyway.) The value is very very likely to be 298.15K. I would advise against changing it inside the Fluent model.
3) I have tried your integration of Cp to h, and it definitely rings alarm bells. I'm fairly sure that the first cpl in h should be a cps. I'm very sure that fabs should not creep in during integration. I suspect that the second term needs a minus sign in front of the whole thing. But the point is: you should check this super-carefully -- try the integration numerically in a spreadsheet, try the integration in WolframAlpha, and try it some other way.
4) It should be fine in parallel.


Good luck!
Ed
obscureed is offline   Reply With Quote

Old   May 24, 2018, 05:43
Default
  #3
New Member
 
Join Date: May 2018
Posts: 8
Rep Power: 8
MV78 is on a distinguished road
Hi obscureed,
Thank you for your detailed answer and your advices ! It really helps.

Concerning my UDF, I am sorry I picked the wrong file that still carries the syntax errors in C. I had corrected them.
1) Wrong file sorry

2) Indeed, the temperature reference is defined twice if I let it in the cp model... Thank you.

3) I had verified it of course with excel and it worked. The relative error was around 2%. It is a cpl because when you integrate, cps*(T-Tref) is eliminated with (cpl-cps)*(T-Tref). Thank you for the wolfram alpha reference !

4) Unfortunately, I encountered a problem when I switched the same case and UDF from serial to parallel. I don't understand why, it is a "the fl process could not be started" problem. Do you see any explanation ?




Have a good day,
MV78

Last edited by MV78; May 25, 2018 at 05:21.
MV78 is offline   Reply With Quote

Old   May 27, 2018, 22:14
Default
  #4
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
change
Code:
r=10/DT;
to
Code:
r=10.0/DT;
best regards
AlexanderZ is offline   Reply With Quote

Old   May 28, 2018, 09:07
Default
  #5
New Member
 
Join Date: May 2018
Posts: 8
Rep Power: 8
MV78 is on a distinguished road
Hi !

Thank you for your help !

I tried to fix the problem with your solution. It still doesn't work and I got this problem related to Visual Studio when I interprete the UDF even if it shouldn't...



The second confusing thing is that it worked two or three times at one moment. And after several trials to check if it was just luck or not it started crashing again.

Have a good day,
MV78
MV78 is offline   Reply With Quote

Old   May 28, 2018, 21:30
Default
  #6
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
you should compile udf instead if interpret

best regards
AlexanderZ is offline   Reply With Quote

Old   May 29, 2018, 06:02
Default
  #7
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 12
obscureed is on a distinguished road
Hi MV78,


As AlexanderZ says, you really need to compile this UDF. For a start, the help files for DEFINE_SPECIFIC_HEAT specifically state that interpreting a UDF of this type will not work (or is not intended to work, and is therefore not worth trying).


You might want to show us your updated code, and describe the (latest) problems in more detail. But if it is similar to the previous version but you are getting inconsistent behaviour, then it is time for troubleshooting: check (again) that your model runs consistently without the UDF; check that it runs consistently with a simpler UDF; check it all in serial and in parallel; etc etc. Sorry, no easy answers just now. (You might well be struck by the thought that a piecewise-linear definition of Cp would be just as good and much less trouble, and on this occasion you would probably be correct.)


Good luck!
Ed
MV78 likes this.
obscureed is offline   Reply With Quote

Reply


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
Unsteady Inlet Velocity UDF in Parallel Batch Mode vtyler Fluent UDF and Scheme Programming 4 April 1, 2020 06:44
Dynamic mesh in parallel udf rsarma Fluent UDF and Scheme Programming 3 August 2, 2018 08:02
problem using property udfs in parallel mode EllenW FLUENT 0 June 23, 2009 18:18
DPM model in parallel batch mode Prashanth FLUENT 2 March 6, 2009 08:54
udf compile in parallel system tahereh FLUENT 1 December 9, 2008 10:48


All times are GMT -4. The time now is 03:14.