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

UDF code(ask for help)

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 15, 2012, 06:41
Default UDF code(ask for help)
  #1
New Member
 
zhuoweili
Join Date: Oct 2011
Posts: 14
Rep Power: 15
Jo_vivian_lee is on a distinguished road
I am struggled with UDF, now I suppose to define the inlet velocity as below, but the code has some error, could you please help me out and check what is wrong about my code?

I appreciate it.
the equation is as below:

V(x,y,t)=15.2*((2*x/0.00625)^8-1)+0.076*sin(0.8*pi*t)+0.076*sin(6*y/0.00625)
#include "udf.h"

DEFINE_PROFILE(velocity_profile,t,i)
{
int ts;
real x[ND_ND]; /* this will hold the position vector */
real y;
face_t f;

ts = N_TIME; /*you can calculate real time from time step obtained here*/

begin_f_loop(f,t)
{
F_CENTROID(pos,f,t);
x = pos[0];
y = pos[1];
F_PROFILE(f,t,i) =-{1-(2*x/0.00625)^8 }*15.2+0.076*sin(0.8*π*t)+0.076*sin(6*y/0.00625);
}
end_f_loop(f,t)
}
Jo_vivian_lee is offline   Reply With Quote

Old   May 15, 2012, 10:43
Default
  #2
Member
 
Daniel Tanner
Join Date: Apr 2009
Posts: 54
Rep Power: 18
Daniel Tanner is on a distinguished road
There are some mistakes here:
Where is pos specified?

Try this and let me know how it works.
real pos[ND_ND]; /* this will hold the position vector */
real x,y;

Always run these over multiple time steps (even without converging) to ensure that the boundary condition is behaving as you intend.

The N_TIME macro only returns the current time step in you case it may be worth considering CURRENT_TIME instead (time independent to the time-step size), see:
http://hpce.iitm.ac.in/website/Manua...df/node105.htm

Last edited by Daniel Tanner; May 15, 2012 at 10:48. Reason: More information
Daniel Tanner is offline   Reply With Quote

Old   May 15, 2012, 12:20
Default
  #3
Member
 
laurentb's Avatar
 
Laurent B
Join Date: Jun 2009
Location: Lille, FRANCE
Posts: 70
Rep Power: 17
laurentb is on a distinguished road
replace t by ts in the velocity profile function (t is the thread)
laurentb is offline   Reply With Quote

Old   May 21, 2012, 12:04
Default Hi,
  #4
New Member
 
zhuoweili
Join Date: Oct 2011
Posts: 14
Rep Power: 15
Jo_vivian_lee is on a distinguished road
Hi there,
Thank you for your note.
I fixed my code, but it is still not working for me...I got mad...Please help me out.
The code is as below:
#include "udf.h"

DEFINE_PROFILE(unsteady_velocity,thread,index)
{
real x [ND_ND];
face_t f;
begin_f_loop(f, f_thread)
{
F_CENTROID (x, f, t);
x=pos[1];
real t=RP_Get_Real("flow time");
F_PROFILE(f,thread,position) =-(1-(2*x/0.00625)^8)*15.2+0.076*sin(0.8*3.1415926*t);
}
end_f_loop(f, f_thread)
}
Jo_vivian_lee is offline   Reply With Quote

Old   May 21, 2012, 12:05
Default
  #5
New Member
 
zhuoweili
Join Date: Oct 2011
Posts: 14
Rep Power: 15
Jo_vivian_lee is on a distinguished road
Error: D:\\Tem/udf.h: line 4: parse error.

cpp -I"C:\PROGRA~1\ANSYSI~1\v140\fluent\fluent14.0.0/src" -I"C:\PROGRA~1\ANSYSI~1\v140\fluent\fluent14.0.0/cortex/src" -I"C:\PROGRA~1\ANSYSI~1\v140\fluent\fluent14.0.0/client/src" -I"C:\PROGRA~1\ANSYSI~1\v140\fluent\fluent14.0.0/multiport/src" -I. -DUDF
ONFIG_H="<C:/DOCUME~1/lzhuowei/LOCALS~1/Temp/udfconfig-node0.h>" "C:/DOCUME~1/lzhuowei/LOCALS~1/Temp/New Text Document (3).c.0.c"
Error: C:/DOCUME~1/lzhuowei/LOCALS~1/Temp/New Text Document (3).c.0.c: line 7: f_thread: undeclared variable
Jo_vivian_lee is offline   Reply With Quote

Old   May 22, 2012, 02:47
Default
  #6
Member
 
laurentb's Avatar
 
Laurent B
Join Date: Jun 2009
Location: Lille, FRANCE
Posts: 70
Rep Power: 17
laurentb is on a distinguished road
The code with no compilation error :

#include "udf.h"

DEFINE_PROFILE(unsteady_velocity,thread,index)
{
real pos [ND_ND];
real x, t;
face_t f;
begin_f_loop(f, thread)
{
F_CENTROID (pos, f, thread);
x=pos[1];
t=RP_Get_Real("flow time");
F_PROFILE(f,thread,index) =-(1-pow(2*x/0.00625,8))*15.2+0.076*sin(0.8*3.1415926*t);
}
end_f_loop(f, thread)
}
laurentb is offline   Reply With Quote

Old   May 22, 2012, 04:47
Default Thank you for your note.
  #7
New Member
 
zhuoweili
Join Date: Oct 2011
Posts: 14
Rep Power: 15
Jo_vivian_lee is on a distinguished road
Hi, I tried your revised code, I supposed to read it in FLUENT, but I still got error, I don`t know why. What should I do when I hook this code with FLUENT?
p.s. Can we talk on skype?
pps. I am using Ansys 14.0, do you think the version of FLUENT is the problem?
ppps. Is there any space here (pos, f, thread);?(f, thread)?
(pos,f,thread);?(f,thread)? Which one is correct?

I am looking forward to your reply.
Kind regards



Jo_vivian_lee is offline   Reply With Quote

Old   May 22, 2012, 05:17
Default
  #8
Member
 
Daniel Tanner
Join Date: Apr 2009
Posts: 54
Rep Power: 18
Daniel Tanner is on a distinguished road
It looks like you have extra spaces this might be the problem:

Try changing these!

real pos [ND_ND]; => real pos[ND_ND];
F_CENTROID (pos, f, thread); => F_CENTROID(pos, f, thread);
Daniel Tanner is offline   Reply With Quote

Old   May 22, 2012, 05:21
Default Thank you for your note.
  #9
New Member
 
zhuoweili
Join Date: Oct 2011
Posts: 14
Rep Power: 15
Jo_vivian_lee is on a distinguished road
Hi, thank you both of you.

I still got an error which is attached below...What does it mean?


cpp -I"C:\PROGRA~1\ANSYSI~1\v140\fluent\fluent14.0.0/src" -I"C:\PROGRA~1\ANSYSI~1\v140\fluent\fluent14.0.0/cortex/src" -I"C:\PROGRA~1\ANSYSI~1\v140\fluent\fluent14.0.0/client/src" -I"C:\PROGRA~1\ANSYSI~1\v140\fluent\fluent14.0.0/multiport/src" -I. -DUDF
ONFIG_H="<udfconfig-host.h>" "D:\Tem\u.c"
cpp -I"C:\PROGRA~1\ANSYSI~1\v140\fluent\fluent14.0.0/src" -I"C:\PROGRA~1\ANSYSI~1\v140\fluent\fluent14.0.0/cortex/src" -I"C:\PROGRA~1\ANSYSI~1\v140\fluent\fluent14.0.0/client/src" -I"C:\PROGRA~1\ANSYSI~1\v140\fluent\fluent14.0.0/multiport/src" -I. -DUDF
ONFIG_H="<C:/DOCUME~1/lzhuowei/LOCALS~1/Temp/udfconfig-node0.h>" "C:/DOCUME~1/lzhuowei/LOCALS~1/Temp/u.c.0.c"
Jo_vivian_lee is offline   Reply With Quote

Old   May 22, 2012, 05:40
Default
  #10
Member
 
laurentb's Avatar
 
Laurent B
Join Date: Jun 2009
Location: Lille, FRANCE
Posts: 70
Rep Power: 17
laurentb is on a distinguished road
I don't have any errors. This is the compilation commands.
laurentb is offline   Reply With Quote

Old   May 22, 2012, 06:28
Default
  #11
Member
 
Daniel Tanner
Join Date: Apr 2009
Posts: 54
Rep Power: 18
Daniel Tanner is on a distinguished road
As laurentb says the output you have included does not mention either warnings or errors. Is this all of the message? It may well have compiled correctly.
Daniel Tanner is offline   Reply With Quote

Old   May 22, 2012, 06:50
Default What should I do?
  #12
New Member
 
zhuoweili
Join Date: Oct 2011
Posts: 14
Rep Power: 15
Jo_vivian_lee is on a distinguished road
mmmmm...
Thanks alot.
but I don`t know why I could not read it in FLUENT.
first, I saved it as .c file
second, in FLUENT I used define-user defined-functions-interpreted

and then I got this
cpp -I"C:\PROGRA~1\ANSYSI~1\v140\fluent\fluent14.0.0/src" -I"C:\PROGRA~1\ANSYSI~1\v140\fluent\fluent14.0.0/cortex/src" -I"C:\PROGRA~1\ANSYSI~1\v140\fluent\fluent14.0.0/client/src" -I"C:\PROGRA~1\ANSYSI~1\v140\fluent\fluent14.0.0/multiport/src" -I. -DUDF
ONFIG_H="<C:/DOCUME~1/lzhuowei/LOCALS~1/Temp/udfconfig-node0.h>" "C:/DOCUME~1/lzhuowei/LOCALS~1/Temp/u.c.0.c"
Jo_vivian_lee is offline   Reply With Quote

Old   May 22, 2012, 07:24
Default
  #13
Member
 
Daniel Tanner
Join Date: Apr 2009
Posts: 54
Rep Power: 18
Daniel Tanner is on a distinguished road
The message you showed is not an error! This is just the compilation sequence. This was fine for me but had problems when I was applying it as a boundary condition.
I tried this and it seemed to work fine:

#include "udf.h"

DEFINE_PROFILE(unsteady_velocity,thread,index)
{
real pos[ND_ND];
real x, t;
face_t f;
begin_f_loop(f, thread)
{
F_CENTROID(pos, f, thread);
x=pos[1];
t=CURRENT_TIME;
F_PROFILE(f,thread,index) =-(1-pow(2*x/0.00625,8))*15.2+0.076*sin(0.8*3.1415926*t);
}
end_f_loop(f, thread)
}
Daniel Tanner is offline   Reply With Quote

Old   May 22, 2012, 07:35
Default
  #14
New Member
 
zhuoweili
Join Date: Oct 2011
Posts: 14
Rep Power: 15
Jo_vivian_lee is on a distinguished road
Thank you for your note.
I tried this code, and I got new information...

cpp -I"C:\PROGRA~1\ANSYSI~1\v140\fluent\fluent14.0.0/src" -I"C:\PROGRA~1\ANSYSI~1\v140\fluent\fluent14.0.0/cortex/src" -I"C:\PROGRA~1\ANSYSI~1\v140\fluent\fluent14.0.0/client/src" -I"C:\PROGRA~1\ANSYSI~1\v140\fluent\fluent14.0.0/multiport/src" -I. -DUDF
ONFIG_H="<udfconfig-host.h>" "D:\Tem\example.c"
Error: D:\\Tem\\example.c: line 2: D:\\Tem\\example.c:1: `#include' expects "FILENAME" or <FILENAME>
parse error.
999999 (..\src\mpsystem.c@1173): mpt_read: failed: errno = 10054
999999: mpt_read: error: read failed trying to read 4 bytes: No such file or directory
MPI Application rank 0 exited before MPI_Finalize() with status -1073741819
The Parallel FLUENT process could not be started.

what should I do?
Jo_vivian_lee is offline   Reply With Quote

Old   May 22, 2012, 08:47
Default
  #15
Member
 
Daniel Tanner
Join Date: Apr 2009
Posts: 54
Rep Power: 18
Daniel Tanner is on a distinguished road
You will have to debug this problem:
1) try it in serial (1 cpu)
2) try without the t=CURRENT_TIME; use t =0; instead.

These will help to narrow down the problem.

I'm not sure what happened earlier when you had problems, can you explain it further? the message "cpp -I"C:\PROGRA~1\ANSYSI~1\v140\fluent\fluent14.0.0/src" -I"C:\PROGRA~1\ANSYSI~1\v140\fluent\fluent14.0.0/cortex/src" -I"C:\PROGRA~1\ANSYSI~1\v140\fluent\fluent14.0.0/client/src" -I"C:\PROGRA~1\ANSYSI~1\v140\fluent\fluent14.0.0/multiport/src" -I. -DUDF
ONFIG_H="<C:/DOCUME~1/lzhuowei/LOCALS~1/Temp/udfconfig-node0.h>" "C:/DOCUME~1/lzhuowei/LOCALS~1/Temp/u.c.0.c"" seems fine to me (not an error, just normal output). Did you have problems when you hooked it as a boundary condition or where did the error occur?
Daniel Tanner is offline   Reply With Quote

Old   May 22, 2012, 09:53
Default
  #16
New Member
 
zhuoweili
Join Date: Oct 2011
Posts: 14
Rep Power: 15
Jo_vivian_lee is on a distinguished road
Quote:
Originally Posted by Daniel Tanner View Post
You will have to debug this problem:
1) try it in serial (1 cpu)
2) try without the t=CURRENT_TIME; use t =0; instead.

These will help to narrow down the problem.

I'm not sure what happened earlier when you had problems, can you explain it further? the message "cpp -I"C:\PROGRA~1\ANSYSI~1\v140\fluent\fluent14.0.0/src" -I"C:\PROGRA~1\ANSYSI~1\v140\fluent\fluent14.0.0/cortex/src" -I"C:\PROGRA~1\ANSYSI~1\v140\fluent\fluent14.0.0/client/src" -I"C:\PROGRA~1\ANSYSI~1\v140\fluent\fluent14.0.0/multiport/src" -I. -DUDF
ONFIG_H="<C:/DOCUME~1/lzhuowei/LOCALS~1/Temp/udfconfig-node0.h>" "C:/DOCUME~1/lzhuowei/LOCALS~1/Temp/u.c.0.c"" seems fine to me (not an error, just normal output). Did you have problems when you hooked it as a boundary condition or where did the error occur?

Hi, I appreciate both of you.
Finally the code is working properly. I am using serial instead of parallel, and also I read the udf in case rather than data and case. So it works now. It seems that there is no problem with the code. It is hooked with FLUENT, I could read this velocity in boundary condition.

Please keep contacting with me, I hope you can help me again in the near future, I am a beginner of UDF, I need you
kind regards
zhuowei

Last edited by Jo_vivian_lee; May 22, 2012 at 10:33.
Jo_vivian_lee is offline   Reply With Quote

Old   May 22, 2012, 10:33
Default
  #17
New Member
 
zhuoweili
Join Date: Oct 2011
Posts: 14
Rep Power: 15
Jo_vivian_lee is on a distinguished road
Hi, I appreciate both of you.
Now I am trying to plot the velocity profile in FLUENT, this work will be done if I can see a sinusoidal curve the same as what the math function describes, thanks a lot.

Unfortunately, I couldn't see the sine curve...oh my god... May I ask that how can I plot the velocity changing with time?

Usually I just can plot the velocity changing with position…

kind regards
zhuowei
Jo_vivian_lee is offline   Reply With Quote

Old   May 22, 2012, 11:01
Default
  #18
Member
 
Daniel Tanner
Join Date: Apr 2009
Posts: 54
Rep Power: 18
Daniel Tanner is on a distinguished road
You can set up a monitor at the inlet. Set it as the area weighted average velocity or just display the volume flow rate and see how it changes as time progresses (display as time-step not iteration).
For this you don't need a converged solution you just want to check what condition you have applied at the boundary so one iteration per time step is fine.
Daniel Tanner is offline   Reply With Quote

Old   May 22, 2012, 11:35
Default
  #19
New Member
 
zhuoweili
Join Date: Oct 2011
Posts: 14
Rep Power: 15
Jo_vivian_lee is on a distinguished road
Quote:
Originally Posted by Daniel Tanner View Post
You can set up a monitor at the inlet. Set it as the area weighted average velocity or just display the volume flow rate and see how it changes as time progresses (display as time-step not iteration).
For this you don't need a converged solution you just want to check what condition you have applied at the boundary so one iteration per time step is fine.
Hi Daniel,
Thank you for your note.
I did what you told me, but I got a message that "cx-xy-plot-files: No data points in range." I used auto range.
I look forward to your reply.
Many thanks
Zhuowei
Jo_vivian_lee is offline   Reply With Quote

Old   May 23, 2012, 09:02
Default
  #20
New Member
 
zhuoweili
Join Date: Oct 2011
Posts: 14
Rep Power: 15
Jo_vivian_lee is on a distinguished road
Hi, I got another problem.
I have had the code, and it also could be read into FLUENT. Now I want to verify it in C++, I want to see the sin curve in c++, but unfortunately, in c++ I got some errors as below:what is the problem?
How can I fix them?

the system cannot find the path specified
1>------ Build started: Project: 01, Configuration: Debug Win32 ------
1>Compiling...
1>01.cpp
1>d:\tem\01\01\01.cpp(6) : error C2065: 'cout' : undeclared identifier
1>d:\tem\01\01\01.cpp(6) : error C2065: 'endl' : undeclared identifier
1>Build log was saved at "file://d:\Tem\01\01\Debug\BuildLog.htm"
1>01 - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Jo_vivian_lee 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
Source Term UDF VS Porous Media Model pchoopanya Fluent UDF and Scheme Programming 1 August 28, 2013 07:12
UDF parallel error: chip-exec: function not found????? shankara.2 Fluent UDF and Scheme Programming 1 January 16, 2012 23:14
How to add a UDF to a compiled UDF library kim FLUENT 3 October 26, 2011 22:38
UDF...UDF...UDF...UDF Luc SEMINEL FLUENT 0 November 25, 2002 05:03
UDF, UDF, UDF, UDF Luc SEMINEL Main CFD Forum 0 November 25, 2002 05:01


All times are GMT -4. The time now is 19:59.