User defined function

• 243 Views
• Last Post 10 October 2018
• Topic Is Solved
Karthik K R posted this 05 October 2018

How can i introduce a UDF of density and depth. That is density varying linearly with depth.

Karthik K R posted this 05 October 2018

In order to get a linearly stratified medium. Thanks Karthik

Kremella posted this 05 October 2018

Hello,

Please check out the DEFINE_PROPERTY UDF macro in the Fluent Customization manual. There are some examples such as defining viscosity as a function of temperature, and density function for compressible fluids. You might want to make density a function of your coordinate which indicates depth.

You might also want to look into this example - "UDF for specifying an x-momentum source term in a spatially dependent porous media". This will give you some idea as to how to use the centroid macro in such UDFs.

I hope this helps.

Best Regards,

Karthik

• Liked by
Karthik K R posted this 06 October 2018

Can any one please help me writing the UDF function Its a function of detph Density varies linearly with depth Assuming the fuction as f(x)

Karthik K R posted this 06 October 2018

Depth is the y-coordinate

Kremella posted this 06 October 2018

Hello,

I'd strongly recommend you go through the Fluent customization manual. It contains several examples. You might find a similar UDF which you can make small modifications to suit your needs. I've found this approach to writing UDFs extremely useful. I'll let other members of this community weigh in their opinions.

Thank you.

Best Regards,

Karthik

Karthik K R posted this 07 October 2018

I am very new to this .. it will be really helpful if any body could help me..please..

raul.raghav posted this 07 October 2018

KKR, attached is a snippet of the UDF you need.

DEFINE_PROPERTY(density_function,c,t)

{

real rho;

real y, x[ND_ND];

C_CENTROID(x,c,t);

y = x[1];

rho = /*define your function rho(y)*/ ;

return rho;

}

And as Karthik (Kremella) mentioned, you need to go through the given examples to write your own UDFs. And if you are writing a complicated UDF, you can ask specific questions and users of the community would be of help. Good luck!

Rahul

• Liked by
Karthik K R posted this 07 October 2018

Thanks a lot for the replay...

abenhadj posted this 07 October 2018

What is the fluid used here? Are you trying to model atmospheric problem? Using DEFINE_PROPERTY for density is generally only suitable for temperature depdendency or for compressible liquid (small compressibility).

Best regards,

Amine

Karthik K R posted this 08 October 2018

Fluid is water.. and i want to create a linearly density stratified medium. That is density increases linearly with depth(y axis). I want simulate sea condition (pycnocline)

Karthik K R posted this 08 October 2018

This code is not working properly. There is an error 'undefined variable x)

Karthik K R posted this 08 October 2018

Can you please verify and debug the code.

abenhadj posted this 08 October 2018

First of all ANSYS Stuff colleagues are not here to debug your code as this is mainly your task. We are here only to provide guidance.

The snipped provided has to work:

#include "udf.h"

DEFINE_PROPERTY(density_function,c,t)

{

real rho;

real y, x[ND_ND];

C_CENTROID(x,c,t);

y = x[1];

rho =y*1000  ;/*define your function rho(y)*/

return rho;

}

You might past you final function here.

Best regards,

Amine

Karthik K R posted this 08 October 2018

I have done the same . But there is an error can 'undefined variable x')

abenhadj posted this 08 October 2018

Best regards,

Amine

Karthik K R posted this 08 October 2018

Error: The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform (win64).\n\nThe system cannot find the path specified.
\n\nC:\Users\Sunayan\Desktop\KARNAV\20.7 successful\GEOM AND MESH\1_files\dp0\FFF\Fluent\libudf\win64\3ddp_host\libudf.dll

Karthik K R posted this 08 October 2018

while I complied my code this error popped up. how can I rectify this problem.

abenhadj posted this 08 October 2018

You go under Mange to unload any loaded libraries. Then you comple the UDF once again and load it.

Best regards,

Amine

abenhadj posted this 08 October 2018

You go under Mange to unload any loaded libraries. Then you comple the UDF once again and load it.

Best regards,

Amine

Karthik K R posted this 08 October 2018

yes I did that still there is problem

Karthik K R posted this 08 October 2018

Error: The UDF library you are trying to load (C:\Users\Sunayan\Desktop\KARNAV\20.7 successful\GEOM AND MESH\1_files\dp0\FFF\Fluent\libudf) is not compiled for 3ddp on the current platform (win64).\n\nThe system cannot find the path specified.
\n\nC:\Users\Sunayan\Desktop\KARNAV\20.7 successful\GEOM AND MESH\1_files\dp0\FFF\Fluent\C:\Users\Sunayan\Desktop\KARNAV\20.7 successful\GEOM AND MESH\1_files\dp0\FFF\Fluent\libudf\win64\3ddp\libudf.dll
Error Object: #f

abenhadj posted this 08 October 2018

Terminate Fluent. Compile and try again. You can even try Standalone.

Best regards,

Amine

Karthik K R posted this 10 October 2018