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

 May 15, 2012, 05:41 UDF code(ask for help) #1 New Member   zhuoweili Join Date: Oct 2011 Posts: 14 Rep Power: 6 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) }

 May 15, 2012, 09:43 #2 Member   Daniel Tanner Join Date: Apr 2009 Posts: 54 Rep Power: 9 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 09:48. Reason: More information

 May 15, 2012, 11:20 #3 Member     Laurent B Join Date: Jun 2009 Location: Lille, FRANCE Posts: 70 Rep Power: 9 replace t by ts in the velocity profile function (t is the thread)

 May 21, 2012, 11:04 Hi, #4 New Member   zhuoweili Join Date: Oct 2011 Posts: 14 Rep Power: 6 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) }

 May 21, 2012, 11:05 #5 New Member   zhuoweili Join Date: Oct 2011 Posts: 14 Rep Power: 6 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/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

 May 22, 2012, 01:47 #6 Member     Laurent B Join Date: Jun 2009 Location: Lille, FRANCE Posts: 70 Rep Power: 9 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) }

 May 22, 2012, 03:47 Thank you for your note. #7 New Member   zhuoweili Join Date: Oct 2011 Posts: 14 Rep Power: 6 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

 May 22, 2012, 04:17 #8 Member   Daniel Tanner Join Date: Apr 2009 Posts: 54 Rep Power: 9 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);

 May 22, 2012, 04:21 Thank you for your note. #9 New Member   zhuoweili Join Date: Oct 2011 Posts: 14 Rep Power: 6 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="" "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/u.c.0.c"

 May 22, 2012, 04:40 #10 Member     Laurent B Join Date: Jun 2009 Location: Lille, FRANCE Posts: 70 Rep Power: 9 I don't have any errors. This is the compilation commands.

 May 22, 2012, 05:28 #11 Member   Daniel Tanner Join Date: Apr 2009 Posts: 54 Rep Power: 9 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.

 May 22, 2012, 05:50 What should I do? #12 New Member   zhuoweili Join Date: Oct 2011 Posts: 14 Rep Power: 6 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/u.c.0.c"

 May 22, 2012, 06:24 #13 Member   Daniel Tanner Join Date: Apr 2009 Posts: 54 Rep Power: 9 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) }

 May 22, 2012, 06:35 #14 New Member   zhuoweili Join Date: Oct 2011 Posts: 14 Rep Power: 6 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="" "D:\Tem\example.c" Error: D:\\Tem\\example.c: line 2: D:\\Tem\\example.c:1: `#include' expects "FILENAME" or 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?

 May 22, 2012, 07:47 #15 Member   Daniel Tanner Join Date: Apr 2009 Posts: 54 Rep Power: 9 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/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?

May 22, 2012, 08:53
#16
New Member

zhuoweili
Join Date: Oct 2011
Posts: 14
Rep Power: 6
Quote:
 Originally Posted by Daniel Tanner 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/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 09:33.

 May 22, 2012, 09:33 #17 New Member   zhuoweili Join Date: Oct 2011 Posts: 14 Rep Power: 6 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

 May 22, 2012, 10:01 #18 Member   Daniel Tanner Join Date: Apr 2009 Posts: 54 Rep Power: 9 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.

May 22, 2012, 10:35
#19
New Member

zhuoweili
Join Date: Oct 2011
Posts: 14
Rep Power: 6
Quote:
 Originally Posted by Daniel Tanner 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,
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.
Many thanks
Zhuowei

 May 23, 2012, 08:02 #20 New Member   zhuoweili Join Date: Oct 2011 Posts: 14 Rep Power: 6 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 ==========

 Thread Tools Display Modes Linear Mode

 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 OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post pchoopanya Fluent UDF and Scheme Programming 1 August 28, 2013 06:12 shankara.2 Fluent UDF and Scheme Programming 1 January 16, 2012 23:14 kim FLUENT 3 October 26, 2011 21:38 Luc SEMINEL FLUENT 0 November 25, 2002 05:03 Luc SEMINEL Main CFD Forum 0 November 25, 2002 05:01

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