|
[Sponsors] |
(ask) how to create UDF for inlet velocity profile |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
March 18, 2017, 05:50 |
help me
|
#61 |
New Member
milad
Join Date: Jan 2017
Posts: 4
Rep Power: 9 |
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: 9 |
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,965
Rep Power: 27 |
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: 9 |
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,965
Rep Power: 27 |
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: 9 |
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 |
|
April 18, 2018, 04:34 |
|
#67 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
Which text editor are you using to edit your UDF? It looks like there are strange symbols in the code...
Additionally:
Code:
if xa*xa+xb*xb<1000*1000 /* not this */ if (xa*xa+xb*xb<1000*1000) /* but this */
Code:
if (time > 3600) /*not this */ if (time > 3600) { ... } /* but this */
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; } |
|
April 19, 2018, 01:46 |
Error: received a fatal signal (Segmentation fault) in UDF
|
#68 |
New Member
pornthep sittisak
Join Date: Apr 2018
Posts: 4
Rep Power: 8 |
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. |
|
April 19, 2018, 02:48 |
|
#69 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
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) } best regards |
|
April 19, 2018, 06:47 |
|
#70 |
New Member
pornthep sittisak
Join Date: Apr 2018
Posts: 4
Rep Power: 8 |
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: 2,363
Rep Power: 34 |
co has nothing inside (or any random value) on the first time step
so you apply random as a boundary condition best regards |
|
April 20, 2018, 05:20 |
|
#72 |
New Member
pornthep sittisak
Join Date: Apr 2018
Posts: 4
Rep Power: 8 |
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: 2,363
Rep Power: 34 |
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: 9 |
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:
|
||
May 22, 2018, 04:02 |
|
#75 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
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. |
|
May 24, 2018, 18:43 |
|
#76 |
New Member
Lisa
Join Date: Apr 2017
Location: USA
Posts: 19
Rep Power: 9 |
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 |
|
May 27, 2018, 11:19 |
|
#77 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
Code:
real x[ND_ND]; float x[0]; /* represents x-coordinate */ float x[1]; /* represents y-coordinate */ The latter two are not necessary (and wrong). |
|
June 4, 2018, 17:27 |
|
#78 |
New Member
Lisa
Join Date: Apr 2017
Location: USA
Posts: 19
Rep Power: 9 |
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. |
|
June 5, 2018, 04:11 |
|
#79 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
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. |
|
June 5, 2018, 18:43 |
|
#80 | |
New Member
Lisa
Join Date: Apr 2017
Location: USA
Posts: 19
Rep Power: 9 |
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:
|
||
|
|
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 |