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

(ask) how to create UDF for inlet velocity profile

Register Blogs Community New Posts Updated Threads Search

Like Tree21Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 18, 2017, 05:50
Default help me
  #61
New Member
 
milad
Join Date: Jan 2017
Posts: 4
Rep Power: 9
miladspa is on a distinguished road
hello
im modeling nanofluid in two-phase mixture model,for Boundary conditions, velocity inlet,
I have defined two speeds, one for liquids, one for nanoparticles, but there's a problem, to define the fluid velocity, the Reynolds number is used, but to find out velocity nanoparticles, have problems, because it is solid nanoparticles viscosity no, it will not be used Reynolds
How do I find the velocity inlet nanoparticles?
The two-phase mixture model
Water is fluid and nanoparticles al2o3
miladspa is offline   Reply With Quote

Old   April 3, 2018, 20:31
Default
  #62
New Member
 
Lisa
Join Date: Apr 2017
Location: USA
Posts: 19
Rep Power: 9
cfd_worker99 is on a distinguished road
Hi Amir,
Your replies to previous posts are quite helpful.
Currently, I am working on a project which is basically a cylindrical domain. The properties (density, thermal conductivity and . . . Alas. . . the heat capacity) of the single phase medium need to change as a function of radial distance from the center and as a function of time. Would it be possible to this through the UDF. I tried writing a UDF for the thermal conductivity but was not very successful:

#include "udf.h"

DEFINE_PROPERTY(thermal_conduct,c,t)
{
real ktc;
real t = CURRENT_TIME
float x[3]; /* Position vector*/


if (t > 3600.)
if x[1]*x[2]<2000
ktc = 2.2e-1;
else
ktc = 1.5e-1;
else
if x[1]*x[2]<2000
ktc = 6.5e-1;
else
ktc = 8.2 e-1;
return ktc;
}
cfd_worker99 is offline   Reply With Quote

Old   April 4, 2018, 03:44
Default
  #63
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
You forgot how to properly calculate distance. It is not the square root of x*y, but the square root of x*x+y*y.
pakk is offline   Reply With Quote

Old   April 4, 2018, 15:44
Default
  #64
New Member
 
Lisa
Join Date: Apr 2017
Location: USA
Posts: 19
Rep Power: 9
cfd_worker99 is on a distinguished road
Thanks pakk.
Yeah you are correct.
But I think there is something else wrong with the syntax as well because I keep getting this warning:
Error: The UDF library you are trying to load (libudf) is not compiled for 3ddp on the current platform (win64).
cfd_worker99 is offline   Reply With Quote

Old   April 5, 2018, 09:31
Default
  #65
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Check the error messages that show up on the screen after you click 'build'.

Probably it gives an error on line 7, because you forgot a semicolon at the end of line 6.
There might be more errors, just look what you see on your screen, that makes debugging a lot easier.
pakk is offline   Reply With Quote

Old   April 16, 2018, 19:21
Default
  #66
New Member
 
Lisa
Join Date: Apr 2017
Location: USA
Posts: 19
Rep Power: 9
cfd_worker99 is on a distinguished road
Thanks Pakk.
I modified the code to the following:
/************************************************** ***********************
UDF for changing soil conductivity with radial distance and time
************************************************** ***********************/
#include "udf.h" /* must be at the beginning of every UDF you write */
#include "sg.h"
#include "sg_mphase.h"
#include "flow.h"
#include "mem.h"
#include "math.h"
#include <stdio.h>
#include <stdlib.h>
#include <unsteady.h>
DEFINE_PROPERTY(thermal_conduct,c,t)
{
real ktc;
real time = CURRENT_TIME;
​float xa = x[0]; /* represents x-coordinate */​
float xb = x[​1​]; ​/* represents y-coordinate */​ ​
if (time > 3600)
if xa*xa+xb*xb<1000*1000
ktc = 0.22;
else
ktc = 0.15;
else
if xa*xa+xb*xb<1000*1000
ktc = 0.65;
else
ktc = 0.82;
return ktc;
}

I know get the following errors (which is longer than any grocery list I have ever seen ;-D)
The declaration of the position vectors definitely needs correction. Can you help, Pakk?:


UDF_April.c

..\..\src\UDF_April.c(17): error C3872: '0x2039': this character is not allowed in an identifier

..\..\src\UDF_April.c(17): error C2065: 'ƒ?<float': undeclared identifier

..\..\src\UDF_April.c(17): error C2146: syntax error: missing ';' before identifier 'xa'

..\..\src\UDF_April.c(17): error C2065: 'xa': undeclared identifier

..\..\src\UDF_April.c(17): error C2065: 'x': undeclared identifier

..\..\src\UDF_April.c(17): error C2109: subscript requires array or pointer type

..\..\src\UDF_April.c(18): error C2065: 'ƒ?<': undeclared identifier

..\..\src\UDF_April.c(18): error C2143: syntax error: missing ';' before 'type'

..\..\src\UDF_April.c(18): error C2065: 'x': undeclared identifier

..\..\src\UDF_April.c(18): error C3872: '0x2039': this character is not allowed in an identifier

..\..\src\UDF_April.c(18): error C2065: 'ƒ?<1ƒ?<': undeclared identifier

..\..\src\UDF_April.c(18): error C2109: subscript requires array or pointer type

..\..\src\UDF_April.c(18): error C2146: syntax error: missing ';' before identifier 'ƒ?<'

..\..\src\UDF_April.c(19): error C2065: 'ƒ?<': undeclared identifier

..\..\src\UDF_April.c(19): error C2143: syntax error: missing ';' before 'type'

..\..\src\UDF_April.c(19): error C2065: 'x': undeclared identifier

..\..\src\UDF_April.c(19): error C2109: subscript requires array or pointer type

..\..\src\UDF_April.c(19): error C3872: '0x2039': this character is not allowed in an identifier

..\..\src\UDF_April.c(19): error C2146: syntax error: missing ';' before identifier 'ƒ?<'

..\..\src\UDF_April.c(20): error C2065: 'ƒ?<': undeclared identifier

..\..\src\UDF_April.c(20): error C2143: syntax error: missing ';' before 'if'

..\..\src\UDF_April.c(21): error C2061: syntax error: identifier 'xa'

..\..\src\UDF_April.c(25): error C2181: illegal else without matching if

..\..\src\UDF_April.c(26): error C2061: syntax error: identifier 'xa'

..\..\src\UDF_April.c(28): error C2181: illegal else without matching if
cfd_worker99 is offline   Reply With Quote

Old   April 18, 2018, 04:34
Default
  #67
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Which text editor are you using to edit your UDF? It looks like there are strange symbols in the code...

Additionally:
  • You don't have to include so many files. I believe only "udf.h" is sufficient, that one should include the other files.
  • You use variable "x", which should be the coordinates of the cell. However, you never tell the compiler that "x" is a variable, and the "x" should be filled with the coordinates of the cell.
  • For style: use brackets () around if-tests.
Code:
if xa*xa+xb*xb<1000*1000   /* not this */
if (xa*xa+xb*xb<1000*1000)  /* but this */
  • Use curly brackets around what the if should do
Code:
if (time > 3600)  /*not this */
if (time > 3600) { ... }  /* but this */
  • Use indentation in your code
Code:
if (time > 3600) {
 if (xa*xa+xb*xb<1000*1000) {
  ktc = 0.22;
 } else {
  ktc = 0.15;
 }
} else {
 if  (xa*xa+xb*xb<1000*1000) {
  ktc = 0.65;
 } else {
  ktc = 0.82;
 }
 return ktc;
}
This will make it much easier to visually understand your code, and see errors. Especially with nested if's that you have.
cfd_worker99 likes this.
pakk is offline   Reply With Quote

Old   April 19, 2018, 01:46
Default Error: received a fatal signal (Segmentation fault) in UDF
  #68
New Member
 
pornthep sittisak
Join Date: Apr 2018
Posts: 4
Rep Power: 8
Pom Sittisak is on a distinguished road
Hello All CFD member,

I try to find the cause of this error when in try to put below UDF in my problem.

Error: received a fatal signal (Segmentation fault).

Error: received a fatal signal (Segmentation fault).
Error Object: #f

Here my UDF, aim to bring the CO (species mass fraction) variable data from back to front of the long cylinder tube.

#include "udf.h"

//Global variable declaration
real co;

//Execute every timestep
DEFINE_EXECUTE_AT_END(Fanback)
{
//Specific the domain ** 1 = mixture domain
Domain *mix_domain = Get_Domain(1);
Thread *mix_thread;
Thread **pt;

//Initialize the variable
co = 0;

#if !RP_HOST
mp_thread_loop_f(mix_thread, mix_domain, pt)
{
face_t c;
// pt[0] ** number [0] is co phase index (co in this case)
begin_f_loop(c, pt[0])
{
// Check if it is a outlet thread (thread id = 5) (Lookup from region list)
if (THREAD_ID(mix_thread)==5){
// Loop and sum up the flux for each face
co =F_YI(c,pt[0],1);

}


}
end_f_loop(c, pt[0])


}

#endif /* !RP_HOST */
node_to_host_real_1(co);

#if RP_HOST
Message("CO Concentration at FAN BACK = %f\n",co);
#endif /* !RP_NODE */


}

// Creating profile for returning inlet
DEFINE_PROFILE(co_outlet,t,i)
{
face_t f;
begin_f_loop(f,t)
{
//Apply flowout variable to the face
F_PROFILE(f,t,i) = co;
}
end_f_loop(f,t)
}

I can pass the complied and Hook the run the simulation using these UDF but the error is shown when first the time step is finished.
Pom Sittisak is offline   Reply With Quote

Old   April 19, 2018, 02:48
Default
  #69
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
Code:
DEFINE_PROFILE(co_outlet,t,i)
{
face_t f;
begin_f_loop(f,t)
{
//Apply flowout variable to the face
F_PROFILE(f,t,i) = co;
}
end_f_loop(f,t)
}
co is not defined on the first timestep

best regards
Pom Sittisak likes this.
AlexanderZ is offline   Reply With Quote

Old   April 19, 2018, 06:47
Default
  #70
New Member
 
pornthep sittisak
Join Date: Apr 2018
Posts: 4
Rep Power: 8
Pom Sittisak is on a distinguished road
Dear AlexanderZ

Thank you very much ..for your reply.

//Global variable declaration
real co;

I wrote before DEFINE_EXECUTE_AT_END(FANBACK)

However, this UDF was passed Complied process and load libudf.dll for Hook process. I can run the simulation but only 1 timestep..It seems like the variable can not transfer to second step.
Pom Sittisak is offline   Reply With Quote

Old   April 19, 2018, 23:40
Default
  #71
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
co has nothing inside (or any random value) on the first time step
so you apply random as a boundary condition

best regards
Pom Sittisak likes this.
AlexanderZ is offline   Reply With Quote

Old   April 20, 2018, 05:20
Default
  #72
New Member
 
pornthep sittisak
Join Date: Apr 2018
Posts: 4
Rep Power: 8
Pom Sittisak is on a distinguished road
I have put the initial value of CO in Solution initialization as 0.00012. but still error. please advise me.
Pom Sittisak is offline   Reply With Quote

Old   April 22, 2018, 21:33
Default
  #73
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
I recommend you to put Message function in your code and debug line by line, which functions gives error

best regards
AlexanderZ is offline   Reply With Quote

Old   May 21, 2018, 19:20
Default
  #74
New Member
 
Lisa
Join Date: Apr 2017
Location: USA
Posts: 19
Rep Power: 9
cfd_worker99 is on a distinguished road
Hi Pakk,
Thanks for your help. Sorry for the delay in getting back to you.
I modified the code to the following based on your guidance. However, I am still getting a lot of errors. Could you please help.

:
/************************************************** ***********************
UDF for changing soil conductivity
************************************************** ***********************/
#include "udf.h" /* must be at the beginning of every UDF you write */
DEFINE_PROPERTY(thermal_conduct,c,t)
{
real ktc;
real time = CURRENT_TIME;
​float x[0]; /* represents x-coordinate */​
float x[​1​]; ​/* represents y-coordinate */​ ​
if (time > 3600) {
if (xa*xa+xb*xb<1000*1000) {
ktc = 0.22;
} else {
ktc = 0.15;
}
} else {
if (xa*xa+xb*xb<1000*1000) {
ktc = 0.65;
} else {
ktc = 0.82;
}
return ktc;
}



Quote:
Originally Posted by pakk View Post
Which text editor are you using to edit your UDF? It looks like there are strange symbols in the code...

Additionally:
  • You don't have to include so many files. I believe only "udf.h" is sufficient, that one should include the other files.
  • You use variable "x", which should be the coordinates of the cell. However, you never tell the compiler that "x" is a variable, and the "x" should be filled with the coordinates of the cell.
  • For style: use brackets () around if-tests.
Code:
if xa*xa+xb*xb<1000*1000   /* not this */
if (xa*xa+xb*xb<1000*1000)  /* but this */
  • Use curly brackets around what the if should do
Code:
if (time > 3600)  /*not this */
if (time > 3600) { ... }  /* but this */
  • Use indentation in your code
Code:
if (time > 3600) {
 if (xa*xa+xb*xb<1000*1000) {
  ktc = 0.22;
 } else {
  ktc = 0.15;
 }
} else {
 if  (xa*xa+xb*xb<1000*1000) {
  ktc = 0.65;
 } else {
  ktc = 0.82;
 }
 return ktc;
}
This will make it much easier to visually understand your code, and see errors. Especially with nested if's that you have.
Attached Files
File Type: c UDF_propertyvariation02.c (650 Bytes, 1 views)
cfd_worker99 is offline   Reply With Quote

Old   May 22, 2018, 04:02
Default
  #75
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
You use variable "xa", but you never told Fluent what "xa" is.
You use variable "xb", but you never told Fluent what "xb" is.

Look in the Fluent manual at C_CENTROID.
cfd_worker99 likes this.
pakk is offline   Reply With Quote

Old   May 24, 2018, 18:43
Default
  #76
New Member
 
Lisa
Join Date: Apr 2017
Location: USA
Posts: 19
Rep Power: 9
cfd_worker99 is on a distinguished road
Hi Pakk,
Thanks for the reply.
So I looked at the manual and tried to incorporate it. I also got rid of xa and xb and just used x[0] and x[1] directly
It did remove some errors but there are others
Could you please tell me what I am missing? I would be most thankful for your help.


Here is the modified code:
/************************************************** ***********************
UDF for changing soil conductivity
************************************************** ***********************/
#include "udf.h" /* must be at the beginning of every UDF you write */
DEFINE_PROPERTY(thermal_conduct,c,t)
{
real x[ND_ND];
real ktc;
real time = CURRENT_TIME;
​float x[0]; /* represents x-coordinate */​
float x[​1​]; ​/* represents y-coordinate */​ ​
C_CENTROID(x,c,t)
if (time > 3600) {
if (x[0]*x[0]+x[1]*x[1]<1000*1000) {
ktc = 0.22;
} else {
ktc = 0.15;
};
} else
if (x[0]*x[0]+x[1]*x[1]<1000*1000)
{
ktc = 0.65;
} else {
ktc = 0.82;
}
return ktc;
}



>>>>Here are the warnings from Fluent.


UDF_propertyvariation_May.c
..\..\src\UDF_propertyvariation_May.c(10): error C3872: '0x2039': this character is not allowed in an identifier
..\..\src\UDF_propertyvariation_May.c(10): error C2065: 'ƒ?<float': undeclared identifier
..\..\src\UDF_propertyvariation_May.c(10): error C2146: syntax error: missing ';' before identifier 'x'
..\..\src\UDF_propertyvariation_May.c(11): error C2065: 'ƒ?<': undeclared identifier
..\..\src\UDF_propertyvariation_May.c(11): error C2143: syntax error: missing ';' before 'type'
..\..\src\UDF_propertyvariation_May.c(11): error C3872: '0x2039': this character is not allowed in an identifier
..\..\src\UDF_propertyvariation_May.c(11): error C2065: 'ƒ?<1ƒ?<': undeclared identifier
..\..\src\UDF_propertyvariation_May.c(11): error C2057: expected constant expression
..\..\src\UDF_propertyvariation_May.c(11): error C2466: cannot allocate an array of constant size 0
..\..\src\UDF_propertyvariation_May.c(11): error C2371: 'x': redefinition; different basic types
..\..\src\UDF_propertyvariation_May.c(7): note: see declaration of 'x'
..\..\src\UDF_propertyvariation_May.c(11): error C2133: 'x': unknown size
..\..\src\UDF_propertyvariation_May.c(11): error C2146: syntax error: missing ';' before identifier 'ƒ?<'
..\..\src\UDF_propertyvariation_May.c(12): error C2109: subscript requires array or pointer type

Quote:
Originally Posted by pakk View Post
You use variable "xa", but you never told Fluent what "xa" is.
You use variable "xb", but you never told Fluent what "xb" is.

Look in the Fluent manual at C_CENTROID.
Attached Files
File Type: c UDF_propertyvariation_May.c (703 Bytes, 0 views)
cfd_worker99 is offline   Reply With Quote

Old   May 27, 2018, 11:19
Default
  #77
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Code:
real x[ND_ND];
​float x[0]; /* represents x-coordinate */​
float x[​1​]; ​/* represents y-coordinate */​ ​
You are giving three different definitions for x.

The latter two are not necessary (and wrong).
cfd_worker99 likes this.
pakk is offline   Reply With Quote

Old   June 4, 2018, 17:27
Default
  #78
New Member
 
Lisa
Join Date: Apr 2017
Location: USA
Posts: 19
Rep Power: 9
cfd_worker99 is on a distinguished road
Thank you so much Pakk.
I deleted these two and that got rid of all but one of the errors. I just get this warning:
UDF_propertyvariation_4June.c
..\..\src\UDF_propertyvariation_4June.c(10): error C3872: '0x2039': this character is not allowed in an identifier

Do you know what's wrong?
The code is attached for reference.
Thanks again for being super helpful.


Quote:
Originally Posted by pakk View Post
Code:
real x[ND_ND];
​float x[0]; /* represents x-coordinate */​
float x[​1​]; ​/* represents y-coordinate */​ ​
You are giving three different definitions for x.

The latter two are not necessary (and wrong).
Attached Files
File Type: c UDF_propertyvariation_4June.c (598 Bytes, 2 views)
cfd_worker99 is offline   Reply With Quote

Old   June 5, 2018, 04:11
Default
  #79
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
If I open your file, the tenth line in my editor is:
Code:
​C_CENTROID(x,c,t);

Notice the strange symbols in the beginning... They should not be there, and Fluent complains about them.



As I asked on 18 April: which text editor are you using? The one you use now ignores these strange symbols, which is very strange.
cfd_worker99 likes this.
pakk is offline   Reply With Quote

Old   June 5, 2018, 18:43
Default
  #80
New Member
 
Lisa
Join Date: Apr 2017
Location: USA
Posts: 19
Rep Power: 9
cfd_worker99 is on a distinguished road
Thanks Pakk.
I am using Notepad++ v7.5.6
Oddly enough, I don't see these symbols in the notepad file (as shown in the screen shot).
Am I using the wrong text editor? Please refer to me another suitable text editor.


Quote:
Originally Posted by pakk View Post
If I open your file, the tenth line in my editor is:
Code:
​C_CENTROID(x,c,t);

Notice the strange symbols in the beginning... They should not be there, and Fluent complains about them.



As I asked on 18 April: which text editor are you using? The one you use now ignores these strange symbols, which is very strange.
Attached Images
File Type: png Capture 4th June UDF.PNG (38.2 KB, 5 views)
Attached Files
File Type: c UDF_propertyvariation_4June.c (598 Bytes, 2 views)
cfd_worker99 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
UDF problems - velocity profile Oli Fluent UDF and Scheme Programming 6 October 24, 2016 11:38
How to create non-uniform velocity profile in FLUENT? pankaj FLUENT 7 October 24, 2016 05:52
udf for velocity profile in a geometry having two inlets shubham208011 Fluent UDF and Scheme Programming 0 April 6, 2009 16:13
UDF velocity and temperature Raj FLUENT 3 February 1, 2009 19:29
UDF velocity profile at nodes Emad FLUENT 2 January 29, 2009 07:35


All times are GMT -4. The time now is 11:53.