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

UDF to locate coordinates of least pressure

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 14, 2017, 09:14
Default UDF to locate coordinates of least pressure
  #1
New Member
 
Join Date: Dec 2017
Posts: 11
Rep Power: 9
Kukka is on a distinguished road
Dear all,

I am working with swirl flow confined in a cylinder. The center of rotating inner vortex undergoes displacement with time.

I wrote a UDF to run with fluent 16.2. Basically, I need the coordinates of the points with least pressure on a plane with time. Though I am getting the values of least pressure on that plane, yet I am unable to extract the coordinates - in my case it is x-y plane with z direction coinciding with the axis of cylinder.

My programming skills are not good enough. I am sharing to what I have been able to do so far.

#include "udf.h"
#include "mem.h"
#include "metric.h"

DEFINE_ADJUST(least_pressure,d)
{
face_t f;
Thread *t;
real x[ND_ND];
float pressure;
int zone_ID;
float coordinate[ND_ND];
float least_press = 10000;
FILE *fp;

thread_loop_f(t,d)
{
zone_ID = THREAD_ID(t);
if(zone_ID == 7)
{
begin_f_loop(f,t)
{
pressure = F_P(f,t);
if(pressure<least_press)
{
F_CENTROID(x,f,t);
NV_V(coordinate, =, x);
least_press = pressure;
}
end_f_loop(f,t)
}

fp = fopen("pressure_writer.txt","a");
fprintf(fp,"%f* ",coordinate);
fprintf(fp," %f\n",least_press);
fclose(fp);
}
}
}


Could anyone simply point out where am I going wrong? This I ran in serial mode as I have least idea of programming for parallel processing.

Regards,
Kukka
Kukka is offline   Reply With Quote

Old   December 14, 2017, 21:27
Default
  #2
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
Quote:
Originally Posted by Kukka View Post
Dear all,

I am working with swirl flow confined in a cylinder. The center of rotating inner vortex undergoes displacement with time.

I wrote a UDF to run with fluent 16.2. Basically, I need the coordinates of the points with least pressure on a plane with time. Though I am getting the values of least pressure on that plane, yet I am unable to extract the coordinates - in my case it is x-y plane with z direction coinciding with the axis of cylinder.

My programming skills are not good enough. I am sharing to what I have been able to do so far.

#include "udf.h"
#include "mem.h"
#include "metric.h"

DEFINE_ADJUST(least_pressure,d)
{
face_t f;
Thread *t;
real x[ND_ND];
float pressure;
int zone_ID;
float coordinate[ND_ND];
float least_press = 10000;
FILE *fp;

thread_loop_f(t,d)
{
zone_ID = THREAD_ID(t);
if(zone_ID == 7)
{
begin_f_loop(f,t)
{
pressure = F_P(f,t);
if(pressure<least_press)
{
F_CENTROID(x,f,t);
NV_V(coordinate, =, x);
least_press = pressure;
}
end_f_loop(f,t)
}

fp = fopen("pressure_writer.txt","a");
fprintf(fp,"%f* ",coordinate);
fprintf(fp," %f\n",least_press);
fclose(fp);
}
}
}


Could anyone simply point out where am I going wrong? This I ran in serial mode as I have least idea of programming for parallel processing.

Regards,
Kukka
Hello,
try this code

Code:
#include "udf.h"
#include "mem.h"
#include "metric.h"

DEFINE_ADJUST(least_pressure,d)
{
face_t f;
Thread *t;
real x[ND_ND];
float pressure;
int zone_ID;
real coordinate;
float least_press = 10000;
FILE *fp;

thread_loop_f(t,d)
{
zone_ID = THREAD_ID(t);
if(zone_ID == 7)
{
begin_f_loop(f,t)
{
pressure = F_P(f,t);
if(pressure<least_press)
{
F_CENTROID(x,f,t);
coordinate = x[0];
least_press = pressure;
}
end_f_loop(f,t)
}

fp = fopen("pressure_writer.txt","a");
fprintf(fp,"%f* ",coordinate);
fprintf(fp," %f\n",least_press);
fclose(fp);
}
}
}
Best regards
AlexanderZ is offline   Reply With Quote

Old   December 15, 2017, 04:04
Default
  #3
New Member
 
Join Date: Dec 2017
Posts: 11
Rep Power: 9
Kukka is on a distinguished road
Dear AlexanderZ,

Thanks a lot for your reply and support. It worked for me and I have started getting the x-coordinate values for minimum pressure. Now I would try getting both x- and y-coordinates, simultaneously, and I hope it would just be the same as for X.

The planes which it recognizes are the boundaries and not the planes which we create manually inside the solver (FLUENT). So as a trial, I monitored at outlet boundary to generate this data. Do I need to go with cell marking to generate a boundary at my desired location (which would be, of course, inside the fluid domain) where actually I will be monitoring? Any idea on this?

I look forward to hearing from you.


Best Regards,
Kukka
Kukka is offline   Reply With Quote

Old   December 15, 2017, 07:48
Default
  #4
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
x-axis is x[0]
y-axis is x[1]

Code:
y_coordinate = x[1];
Regarding monitors, you may use this approach:

If you need to get values from your domain across y-axis, for instance y=0,
you may make a loop over all faces(for 2D), and monitor if x[1] == 0, than you save pressure (or whatever you want)

I hope you got my idea.

Best regards
AlexanderZ is offline   Reply With Quote

Old   December 15, 2017, 09:43
Default
  #5
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
You do everything right, except for printing the answer. You do that by:
Code:
fprintf(fp,"%f* ",coordinate);
The %f tells that you want to print a single number, but "coordinate" is a combination of three numbers. So that does not work.

Instead, what you can do:
Code:
fprintf(fp,"(%f,%f,%f) ",coordinate[0],coordinate[1],coordinate[2]);
This has three %f's, so you tell that you want to print three numbers, and then you specify which three numbers.

==Edit: I was responding to the original question, did not see that there was already an answer==
pakk is offline   Reply With Quote

Old   December 17, 2017, 08:51
Default
  #6
New Member
 
Join Date: Dec 2017
Posts: 11
Rep Power: 9
Kukka is on a distinguished road
Dear AlexanderZ,

Thank you for your extended support. I would return to my institute on Tuesday and give it a try.

I hope now it should work well :-)

Best Regards,
Kukka
Kukka is offline   Reply With Quote

Old   December 17, 2017, 08:53
Default
  #7
New Member
 
Join Date: Dec 2017
Posts: 11
Rep Power: 9
Kukka is on a distinguished road
Dear Pakk,

Many thanks for your suggestions :-)

I will run this code and incorporate your suggestions as well.


Best Regards,
Kukka
Kukka 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 to adjust pressure outlet a.lynchy FLUENT 4 February 15, 2021 01:50
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
Setting up the pressure variation due to tornado in a duct(UDF)+animation guillaume1990 FLUENT 0 March 3, 2014 12:59
Neumann pressure BC and velocity field Antech Main CFD Forum 0 April 25, 2006 03:15


All times are GMT -4. The time now is 16:56.