CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   UDF code(ask for help) (https://www.cfd-online.com/Forums/fluent-udf/101823-udf-code-ask-help.html)

Jo_vivian_lee May 15, 2012 05:41

UDF code(ask for help)
 
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)
}

Daniel Tanner May 15, 2012 09:43

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

laurentb May 15, 2012 11:20

replace t by ts in the velocity profile function (t is the thread)

Jo_vivian_lee May 21, 2012 11:04

Hi,
 
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 May 21, 2012 11:05

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

laurentb May 22, 2012 01:47

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)
}

Jo_vivian_lee May 22, 2012 03:47

Thank you for your note.
 
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




Daniel Tanner May 22, 2012 04:17

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);

Jo_vivian_lee May 22, 2012 04:21

Thank you for your note.
 
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"

laurentb May 22, 2012 04:40

I don't have any errors. This is the compilation commands.

Daniel Tanner May 22, 2012 05:28

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.

Jo_vivian_lee May 22, 2012 05:50

What should I do?
 
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"

Daniel Tanner May 22, 2012 06:24

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)
}

Jo_vivian_lee May 22, 2012 06:35

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?

Daniel Tanner May 22, 2012 07:47

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?

Jo_vivian_lee May 22, 2012 08:53

Quote:

Originally Posted by Daniel Tanner (Post 362426)
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

Jo_vivian_lee May 22, 2012 09:33

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

Daniel Tanner May 22, 2012 10:01

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.

Jo_vivian_lee May 22, 2012 10:35

Quote:

Originally Posted by Daniel Tanner (Post 362467)
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 May 23, 2012 08:02

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 ==========


All times are GMT -4. The time now is 10:55.