# (ask) how to create UDF for inlet velocity profile

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

 March 18, 2017, 05:50 help me #61 New Member   milad Join Date: Jan 2017 Posts: 4 Rep Power: 6 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

 April 3, 2018, 20:31 #62 New Member   Lisa Join Date: Apr 2017 Location: USA Posts: 19 Rep Power: 6 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; }

 April 4, 2018, 03:44 #63 Senior Member   Join Date: Nov 2013 Posts: 1,947 Rep Power: 24 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.

 April 4, 2018, 15:44 #64 New Member   Lisa Join Date: Apr 2017 Location: USA Posts: 19 Rep Power: 6 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).

 April 5, 2018, 09:31 #65 Senior Member   Join Date: Nov 2013 Posts: 1,947 Rep Power: 24 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.

 April 16, 2018, 19:21 #66 New Member   Lisa Join Date: Apr 2017 Location: USA Posts: 19 Rep Power: 6 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 #include #include 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: 'ƒ?

 April 18, 2018, 04:34 #67 Senior Member   Join Date: Nov 2013 Posts: 1,947 Rep Power: 24 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.

 April 19, 2018, 02:48 #69 Senior Member   Alexander Join Date: Apr 2013 Posts: 1,845 Rep Power: 29 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.

 April 19, 2018, 06:47 #70 New Member   pornthep sittisak Join Date: Apr 2018 Posts: 4 Rep Power: 5 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.

 April 19, 2018, 23:40 #71 Senior Member   Alexander Join Date: Apr 2013 Posts: 1,845 Rep Power: 29 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.

 April 20, 2018, 05:20 #72 New Member   pornthep sittisak Join Date: Apr 2018 Posts: 4 Rep Power: 5 I have put the initial value of CO in Solution initialization as 0.00012. but still error. please advise me.

 April 22, 2018, 21:33 #73 Senior Member   Alexander Join Date: Apr 2013 Posts: 1,845 Rep Power: 29 I recommend you to put Message function in your code and debug line by line, which functions gives error best regards

May 21, 2018, 19:20
#74
New Member

Lisa
Join Date: Apr 2017
Location: USA
Posts: 19
Rep Power: 6
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 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
 UDF_propertyvariation02.c (650 Bytes, 1 views)

 May 22, 2018, 04:02 #75 Senior Member   Join Date: Nov 2013 Posts: 1,947 Rep Power: 24 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.

May 24, 2018, 18:43
#76
New Member

Lisa
Join Date: Apr 2017
Location: USA
Posts: 19
Rep Power: 6
Hi Pakk,
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 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
 UDF_propertyvariation_May.c (703 Bytes, 0 views)

 May 27, 2018, 11:19 #77 Senior Member   Join Date: Nov 2013 Posts: 1,947 Rep Power: 24 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.

June 4, 2018, 17:27
#78
New Member

Lisa
Join Date: Apr 2017
Location: USA
Posts: 19
Rep Power: 6
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 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
 UDF_propertyvariation_4June.c (598 Bytes, 2 views)

 June 5, 2018, 04:11 #79 Senior Member   Join Date: Nov 2013 Posts: 1,947 Rep Power: 24 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.

June 5, 2018, 18:43
#80
New Member

Lisa
Join Date: Apr 2017
Location: USA
Posts: 19
Rep Power: 6
Thanks Pakk.
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 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
 Capture 4th June UDF.PNG (38.2 KB, 5 views)
Attached Files
 UDF_propertyvariation_4June.c (598 Bytes, 1 views)