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

Using a UDF with Pressure Far Fields.

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 1 Post By dominique120
  • 1 Post By dominique120
  • 1 Post By D.M
  • 1 Post By dominique120

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 8, 2017, 14:01
Default Using a UDF with Pressure Far Fields.
  #1
New Member
 
Dominique V.
Join Date: Jan 2017
Posts: 6
Rep Power: 9
dominique120 is on a distinguished road
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);
 }
I'm Using Fluent 18. I've tried using Serial and Parallel versions of Fluent. I'm using the density based solver and double precision.

When I use this UDF on a velocity inlet it works fine.

Thanks
Svetlana likes this.
dominique120 is offline   Reply With Quote

Old   June 8, 2017, 21:28
Default Simplify, F_CENTROID
  #2
Senior Member
 
Svetlana Tkachenko
Join Date: Oct 2013
Location: Australia, Sydney
Posts: 416
Rep Power: 15
Svetlana is on a distinguished road
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
Svetlana is offline   Reply With Quote

Old   June 8, 2017, 21:45
Default
  #3
New Member
 
Dominique V.
Join Date: Jan 2017
Posts: 6
Rep Power: 9
dominique120 is on a distinguished road
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.

Svetlana likes this.
dominique120 is offline   Reply With Quote

Old   June 9, 2017, 03:36
Default Define x
  #4
Senior Member
 
Svetlana Tkachenko
Join Date: Oct 2013
Location: Australia, Sydney
Posts: 416
Rep Power: 15
Svetlana is on a distinguished road
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);
}
Svetlana is offline   Reply With Quote

Old   June 9, 2017, 13:55
Default
  #5
New Member
 
Dominique V.
Join Date: Jan 2017
Posts: 6
Rep Power: 9
dominique120 is on a distinguished road
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.
I also tried the UDF on a pressure far field in double/single prescision fluent, and in serial/parallel fluent. I always get a segmentation fault.
dominique120 is offline   Reply With Quote

Old   June 9, 2017, 17:43
Default
  #6
New Member
 
Dominique V.
Join Date: Jan 2017
Posts: 6
Rep Power: 9
dominique120 is on a distinguished road
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
dominique120 is offline   Reply With Quote

Old   June 10, 2017, 01:31
Default
  #7
D.M
Member
 
Davoud Malekian
Join Date: Jan 2016
Posts: 53
Rep Power: 10
D.M is on a distinguished road
Quote:
Originally Posted by dominique120 View Post
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);
 }
I'm Using Fluent 18. I've tried using Serial and Parallel versions of Fluent. I'm using the density based solver and double precision.

When I use this UDF on a velocity inlet it works fine.

Thanks



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.
Svetlana likes this.
D.M is offline   Reply With Quote

Old   June 11, 2017, 16:10
Default
  #8
New Member
 
Dominique V.
Join Date: Jan 2017
Posts: 6
Rep Power: 9
dominique120 is on a distinguished road
Quote:
Originally Posted by D.M View Post
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.
Thank you for your explanation. Unfortunately I cant use velocity-inlet because this is a problem with compressible fluid(I was always using ideal gas) and I was hoping to create two more UDFs to control the pressure-far-field vector.

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.
Svetlana likes this.
dominique120 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
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


All times are GMT -4. The time now is 21:00.