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

New to UDF

Register Blogs Community New Posts Updated Threads Search

Like Tree7Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 2, 2015, 01:38
Default New to UDF
  #1
Senior Member
 
Join Date: Mar 2013
Location: B'lr
Posts: 130
Rep Power: 13
shivakumar is on a distinguished road
Hi,

I am new to fluent UDF. I need to compute shock and viscous regions using the following sensor equations. My question is how to write udf for these two?

Any help would be appreciated.

Shivakumar
Attached Images
File Type: jpg Capture.JPG (62.1 KB, 134 views)
shivakumar is offline   Reply With Quote

Old   March 2, 2015, 08:10
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
If you hope that somebody will read this, and will give you the UDF code, I predict that this will probably not happen. (Although I might be wrong...)

A better approach would be the following:


"Hi,

I am new to fluent UDF. I need to compute shock and viscous regions using the following sensor equations. I have looked into the Fluent manual, and found the UDF manual, and my first attempt to a udf was this:

...insert your code here...

Unfortunately, this did not work, because when I tried to compile it, Fluent said there was an error in line 5, but I don't understand that. Can anybody help me understand what is wrong with my code, and give me hints to get a working code for those two equations?

Any help would be appreciated.

Shivakumar
"
anon_h and abhay.uiet like this.
pakk is offline   Reply With Quote

Old   March 5, 2015, 21:51
Default
  #3
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Start with reading the section for DEFINE_SOURCE in the UDF manual. Next, you need to extract the values of the cell variables in those equations using macros such as C_NUT for turbulent viscosity.
`e` is offline   Reply With Quote

Old   March 6, 2015, 03:55
Unhappy
  #4
Senior Member
 
Join Date: Mar 2013
Location: B'lr
Posts: 130
Rep Power: 13
shivakumar is on a distinguished road
Thanks for the reply. I have written a program for the first equation( 1st thread ) and getting compilation error as udf is not compiled. The program looks like this. Please help.

#include "udf.h"
#define a 340.26

DEFINE_ON_DEMAND(shock_sensor)
{
Domain *d;
Thread *t;
cell_t c;
d=Get_Domain(1);

real f_shock, velocity;
thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
velocity=(C_U(c,t)+C_V(c,t));
f_shock = (velocity*C_P_G(c,t))/(a*abs(C_P_G(c,t)));

if(f_shock>=1)
{
C_UDMI(c,t,0)=f_shock;
}
}
end_c_loop(c,t)
}
}
shivakumar is offline   Reply With Quote

Old   March 6, 2015, 04:07
Default
  #5
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
And which compilation error do you get?
pakk is offline   Reply With Quote

Old   March 6, 2015, 04:27
Exclamation
  #6
Senior Member
 
Join Date: Mar 2013
Location: B'lr
Posts: 130
Rep Power: 13
shivakumar is on a distinguished road
Thanks for your speedy response.

The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform (win64).
The operation completed successfully.

C:\libudf\win64\2ddp_host\libudf.dll


Is this program is correct according to that equation?

Thanks
shivakumar is offline   Reply With Quote

Old   March 6, 2015, 04:41
Default
  #7
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
That is the load error, not the compilation error. Which error do you see when you click "build"?
pakk is offline   Reply With Quote

Old   March 6, 2015, 05:11
Unhappy
  #8
Senior Member
 
Join Date: Mar 2013
Location: B'lr
Posts: 130
Rep Power: 13
shivakumar is on a distinguished road
Not understanding this...

1 file(s) copied.
Copied C:\Users\NAL\Desktop\shiva\RAE2822\Un_str/C:\Users\NAL\Desktop\shiva\RAE2822\Un_str\shock_se nsor.c to libudf\src
(system "copy "C:\PROGRA~1\ANSYSI~1\v140\fluent"\fluent14.0.0\sr c\makefile_nt.udf "libudf\win64\2ddp_host\makefile" ")
1 file(s) copied.
(chdir "libudf")()
(chdir "win64\2ddp_host")()
'nmake' is not recognized as an internal or external command,
operable program or batch file.
'nmake' is not recognized as an internal or external command,
operable program or batch file.
(system "copy "C:\PROGRA~1\ANSYSI~1\v140\fluent"\fluent14.0.0\sr c\makefile_nt.udf "libudf\win64\2ddp_node\makefile" ")
1 file(s) copied.
(chdir "libudf")()
(chdir "win64\2ddp_node")()
'nmake' is not recognized as an internal or external command,
operable program or batch file.
'nmake' is not recognized as an internal or external command,
operable program or batch file.

Done.

Opening library "C:\Users\NAL\Desktop\shiva\RAE2822\Un_str\libudf" ...
Primitive Error at Node 0: The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform (win64).

The operation completed successfully.

C:\Users\NAL\Desktop\shiva\libudf\win64\2ddp_node\ libudf.dll

Primitive Error at Node 1: The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform (win64).

The system cannot find the file specified.

C:\Users\NAL\Desktop\shiva\libudf\win64\2ddp_node\ libudf.dll

Error: The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform (win64).

The operation completed successfully.

C:\Users\NAL\Desktop\shiva\RAE2822\Un_str\libudf\w in64\2ddp_host\libudf.dll
Error Object: #f
shivakumar is offline   Reply With Quote

Old   March 6, 2015, 05:20
Default
  #9
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Your problem is not the code, but that your computer has no compiler installed. Or at least not in the correct way, Fluent can not find the compiler.

I don't know much about how to set up Fluent for compiling, but search on this forum for "'nmake' is not recognized as an internal or external command", and you will find more of those questions with helpful answers.
pakk is offline   Reply With Quote

Old   March 6, 2015, 05:34
Red face
  #10
Senior Member
 
Join Date: Mar 2013
Location: B'lr
Posts: 130
Rep Power: 13
shivakumar is on a distinguished road
Thank you very much. I will install compiler, but how? which?


shivakumar
shivakumar is offline   Reply With Quote

Old   March 6, 2015, 06:10
Default
  #11
Senior Member
 
ghost82's Avatar
 
Rick
Join Date: Oct 2010
Posts: 1,016
Rep Power: 26
ghost82 will become famous soon enough
Maybe this is what you are searching:
http://www.cfd-online.com/Wiki/Fluen..._32bit_systems
__________________
Google is your friend and the same for the search button!
ghost82 is offline   Reply With Quote

Old   March 6, 2015, 12:16
Default
  #12
Senior Member
 
Join Date: Mar 2013
Location: B'lr
Posts: 130
Rep Power: 13
shivakumar is on a distinguished road
Thank you very much for the quick response.. That is helpful.
shivakumar is offline   Reply With Quote

Old   March 9, 2015, 12:55
Default
  #13
Senior Member
 
Join Date: Mar 2013
Location: B'lr
Posts: 130
Rep Power: 13
shivakumar is on a distinguished road
I had gone through the steps but still getting the errors while building. The error is

> Deleted old libudf\win64\2ddp\libudf.dll
1 file(s) copied.
Copied C:\Users\Mallikarjun\Desktop\New folder\C\compile_it\shock_sensor.c to libudf\src
(system "copy "C:\PROGRA~1\ANSYSI~1\v140\fluent"\fluent14.0.0\sr c\makefile_nt.udf "libudf\win64\2ddp\makefile" ")
1 file(s) copied.
(chdir "libudf")()
(chdir "win64\2ddp")()
# Generating ud_io1.h
shock_sensor.c
..\..\src\shock_sensor.c(11) : error C2275: 'real' : illegal use of this type as an expression
c:\program files\ansys inc\v140\fluent\fluent14.0.0\src\global.h(167) : see declaration of 'real'
..\..\src\shock_sensor.c(11) : error C2146: syntax error : missing ';' before identifier 'f_shock'
..\..\src\shock_sensor.c(11) : error C2065: 'f_shock' : undeclared identifier
..\..\src\shock_sensor.c(11) : error C2065: 'velocity' : undeclared identifier
..\..\src\shock_sensor.c(16) : error C2065: 'velocity' : undeclared identifier
..\..\src\shock_sensor.c(17) : error C2065: 'f_shock' : undeclared identifier
..\..\src\shock_sensor.c(17) : error C2065: 'velocity' : undeclared identifier
..\..\src\shock_sensor.c(17) : error C2297: '*' : illegal, right operand has type 'real [2]'
..\..\src\shock_sensor.c(17) : warning C4047: 'function' : 'int' differs in levels of indirection from 'real [2]'
..\..\src\shock_sensor.c(17) : warning C4024: 'abs' : different types for formal and actual parameter 1
..\..\src\shock_sensor.c(19) : error C2065: 'f_shock' : undeclared identifier
..\..\src\shock_sensor.c(21) : error C2440: '=' : cannot convert from 'void (*)(void)' to 'real'

Done.



Thanks
Shivakumar
shivakumar is offline   Reply With Quote

Old   March 10, 2015, 06:31
Default
  #14
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
I think you are declaring a variable too late.

Code:
d=Get_Domain(1);          <-- an assignment

real f_shock, velocity;     <-- a declaration
To be safe, declare all variables before you start doing assignments.
pakk is offline   Reply With Quote

Old   March 10, 2015, 12:10
Default
  #15
Senior Member
 
Join Date: Mar 2013
Location: B'lr
Posts: 130
Rep Power: 13
shivakumar is on a distinguished road
Thanks for the reply. Nice suggestion. I did and worked well but with 3 errors.

# Generating ud_io1.h
shock_sensor.c
..\..\src\shock_sensor.c(18) : error C2297: '*' : illegal, right operand has type 'real [2]'
..\..\src\shock_sensor.c(18) : error C2440: 'function' : cannot convert from 'real [2]' to 'double'
..\..\src\shock_sensor.c(18) : warning C4024: 'fabs' : different types for formal and actual parameter 1

Done.
shivakumar is offline   Reply With Quote

Old   March 10, 2015, 15:40
Default
  #16
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
You're trying to evaluate a vector (real array: 'velocity') and scalar with a multiplication operator. The C_U(c,t) macro returns a vector quantity, either select one dimension, C_U(c,t)[0], or determine the magnitude of the 'velocity' vector.
`e` is offline   Reply With Quote

Old   March 11, 2015, 03:43
Default
  #17
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Quote:
Originally Posted by `e` View Post
You're trying to evaluate a vector (real array: 'velocity') and scalar with a multiplication operator. The C_U(c,t) macro returns a vector quantity, either select one dimension, C_U(c,t)[0], or determine the magnitude of the 'velocity' vector.
You are completely right in one aspect, but completely wrong in another

The problem is indeed that he/she is trying to multiply a vector with a scalar, but here 'velocity' is the scalar. C_U(c,t) returns the x-component of velocity, so is a scalar (in the programming definition of scalar, not in the physical definition of scalar, since it depends on the coordinate system).
The vector in this problem is C_P_G, the gradient of the pressure.

At this point, there is no advice we can give you (shivakumar) with respect to programming, because the problem is in your equation. Which part of the pressure gradient do you want? Magnitude? X-component? Sum of X and Y-component? They all can be programmed.
pakk is offline   Reply With Quote

Old   March 11, 2015, 04:35
Default
  #18
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Ok, C_P_G is the gradient of pressure which of course is a vector quantity. I was thinking of P_VEL(p)[i] for the DPM where the velocity components are taken from the single macro rather than having an individual macro for each component (C_U, C_V and C_W for the fluid phase). Woops, I thought Fluent would have more consistent naming conventions...
`e` is offline   Reply With Quote

Old   March 11, 2015, 11:39
Unhappy
  #19
Senior Member
 
Join Date: Mar 2013
Location: B'lr
Posts: 130
Rep Power: 13
shivakumar is on a distinguished road
Thank you for your valuable responses.. Yes, the velocity vector is multiplied with the gradient of pressure. Since I am new to this udf, confusing which macro to use and all..

I tried using array C_U(c,t)[0] and still got the errors.. Let me share the whole paper which I am referring to you.

http://www.researchgate.net/profile/...9ffb000000.pdf


Thank you
Shivakumar
shivakumar is offline   Reply With Quote

Old   March 11, 2015, 16:51
Default
  #20
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Firstly, from our discussion above, the C_U macro gives only the x-component of the local cell velocity. There is no need to call the first element of the array C_U; namely C_U(c,t)[0].

The equation you're using has the dot product of the velocity vector (bold text style represents a vector quantity) with the gradient of pressure (del P). There may or may not be a dot product function available within Fluent/C. Otherwise, if you're working with 3D cartesian coordinates you could manually perform this operation yielding the following numerator for the f_shock evaluation:

Code:
(C_U(c,t)*C_P_G(c,t)[0] + C_V(c,t)*C_P_G(c,t)[1] + C_W(c,t)*C_P_G(c,t)[2])
shivakumar likes this.
`e` 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
WILLING TO PAY/ FREELANCER REQUIRED / small UDF coding force loads over body / 6DOF acasas CFD Freelancers 1 January 23, 2015 07:26
Source Term UDF VS Porous Media Model pchoopanya Fluent UDF and Scheme Programming 1 August 28, 2013 06:12
UDF parallel error: chip-exec: function not found????? shankara.2 Fluent UDF and Scheme Programming 1 January 16, 2012 22:14
How to add a UDF to a compiled UDF library kim FLUENT 3 October 26, 2011 21:38
UDF...UDF...UDF...UDF Luc SEMINEL FLUENT 0 November 25, 2002 04:03


All times are GMT -4. The time now is 02:01.