|
[Sponsors] |
June 8, 2017, 14:01 |
Using a UDF with Pressure Far Fields.
|
#1 |
New Member
Dominique V.
Join Date: Jan 2017
Posts: 6
Rep Power: 9 |
I have created a UDF that controls the mach number of a pressure far field in a transient problem but whenever it run I get a segmentation fault.
What am I doing wrong? Here is the UDF: Code:
#include "udf.h" DEFINE_PROFILE(farfield_speed,th,i) { face_t f; real flow_time = CURRENT_TIME; begin_f_loop(f,th) { if(flow_time <=2) F_PROFILE(f,th,i) = 0.5; else if(flow_time <=4) F_PROFILE(f,th,i) = 1.5; else F_PROFILE(f,th,i) = 2; } end_f_loop(f,th); } When I use this UDF on a velocity inlet it works fine. Thanks |
|
June 8, 2017, 21:28 |
Simplify, F_CENTROID
|
#2 |
Senior Member
Svetlana Tkachenko
Join Date: Oct 2013
Location: Australia, Sydney
Posts: 416
Rep Power: 15 |
Simplify it, make it always return 0.5. Check whether you have a segmentation fault then.
Following an example I also added "F_CENTROID(x,f,t);" line. Please check whether it makes any difference. I left it commented out below. #include "udf.h" DEFINE_PROFILE(farfield_speed,th,i) { face_t f; real flow_time = CURRENT_TIME; begin_f_loop(f,th) { //ADD THIS? //F_CENTROID(x,f,t); // FORGET THIS FOR NOW //if(flow_time <=2) // F_PROFILE(f,th,i) = 0.5; //else if(flow_time <=4) // F_PROFILE(f,th,i) = 1.5; //else // F_PROFILE(f,th,i) = 2; // USE THIS SIMPLE VERSION F_PROFILE(f,th,i) = 0.5; } end_f_loop(f,th); } Reference: https://www.sharcnet.ca/Software/Ans...e_profile.html |
|
June 8, 2017, 21:45 |
|
#3 |
New Member
Dominique V.
Join Date: Jan 2017
Posts: 6
Rep Power: 9 |
Hello and thank you for your reply.
I tried what you suggested: When I used F_CENTROID(x,f,t); I got that "x" was an undeclared variable. I also tried your simple version and it still game me the error with a pressure far field. However when I switched to a Mass flow inlet or a velocity inlet it worked well. |
|
June 9, 2017, 03:36 |
Define x
|
#4 |
Senior Member
Svetlana Tkachenko
Join Date: Oct 2013
Location: Australia, Sydney
Posts: 416
Rep Power: 15 |
To resolve the problem with 'x' undefined variable, add an extra line at the top as shown below.
Code:
#include "udf.h" DEFINE_PROFILE(farfield_speed,th,i) { real x[ND_ND]; /* this will hold the position vector */ face_t f; real flow_time = CURRENT_TIME; begin_f_loop(f,th) { //ADD THIS? //F_CENTROID(x,f,t); // FORGET THIS FOR NOW //if(flow_time <=2) // F_PROFILE(f,th,i) = 0.5; //else if(flow_time <=4) // F_PROFILE(f,th,i) = 1.5; //else // F_PROFILE(f,th,i) = 2; // USE THIS SIMPLE VERSION F_PROFILE(f,th,i) = 0.5; } end_f_loop(f,th); } |
|
June 9, 2017, 13:55 |
|
#5 |
New Member
Dominique V.
Join Date: Jan 2017
Posts: 6
Rep Power: 9 |
I'm still getting a segmentation fault.
If I switch to using a velocity inlet it works fine. I tried compiling it(MSVC 2015) to debug it but I get the following error: Code:
Copied C:\udf_compile_test/C:\udf_compile_test\udf_test.c to libudf\src udf_names.c and user_nt.udf files in 2d are upto date. (system "copy "C:\PROGRA~1\ANSYSI~1\v180\fluent"\fluent18.0.0\src\udf\makefile_nt.udf "libudf\win64\2d\makefile" ") 1 file(s) copied. (chdir "libudf")(chdir "win64\2d")udf_names.c udf_names.c(6): error C2449: found '{' at file scope (missing function header?) udf_names.c(18): fatal error C1004: unexpected end-of-file found Done. |
|
June 9, 2017, 17:43 |
|
#6 |
New Member
Dominique V.
Join Date: Jan 2017
Posts: 6
Rep Power: 9 |
I fixed the issue relating to the compilation error. I have to move the { from the DEFINE line to a new line.
Sadly I'm still getting a segmentation fault. Even with the latest version(18.1) it happens |
|
June 10, 2017, 01:31 |
|
#7 | |
Member
Davoud Malekian
Join Date: Jan 2016
Posts: 53
Rep Power: 10 |
Quote:
Hi, your code is completely right, this is the first time i'm actually seeing this error for define profile, so i think the only reason for this error is that the passed in variable (here i mean ''i'') is not defined for mach number so you can't access the mach number and segmentation error happens! as you know variable ''i'' in the second line of your udf ''(farfield_speed,th,i)'' determines which profile you want to access, for example if you hook your udf for velocity, fluent passes a number to your code (that number is ''i'') and if you hook it for pressure profile, fluent passes another number to your code (for example the ''i'' is 1 for velocity, 3 for pressure, 5 for mass flow and ...). so i think the only reason for this error is that there isn't any ''i'' defined for mach number and when you hook your code for the mach number, fluent can't access any ''i'' and pass it to your code. so the segmentation error happens. i think the only way to solve this problem is actually changing the pressure far field to velocity inlet and define the mach number there : (velocity = mach * c) , and one more thing, try to change the gas law to ideal gas and hook your udf into mach number again, see if it works or not!! let me know if you solved the problem, tnx. |
||
June 11, 2017, 16:10 |
|
#8 | |
New Member
Dominique V.
Join Date: Jan 2017
Posts: 6
Rep Power: 9 |
Quote:
I'm going to continue digging into the Fluent documentation and I'm also going to look into the source header files. There has to be some way to be able to access the mach number variable from a UDF. |
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
how to put udf inlet velocity and udf outlet pressure in fluent | raminostadi | Fluent UDF and Scheme Programming | 4 | July 3, 2017 07:43 |
CFX Solver stopped with error when requested for backup during solver running | Mfaizan | CFX | 40 | May 13, 2016 07:50 |
how to get pressure and pressure gradient using UDF | Honglin | Fluent UDF and Scheme Programming | 0 | May 24, 2012 07:47 |
Neumann pressure BC and velocity field | Antech | Main CFD Forum | 0 | April 25, 2006 03:15 |
Hydrostatic pressure in 2-phase flow modeling (CFX4.2) | HB &DS | CFX | 0 | January 9, 2000 14:19 |