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

UDF for function defined by parts

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes
  • 1 Post By `e`
  • 1 Post By `e`
  • 1 Post By `e`

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 15, 2018, 17:10
Default UDF for function defined by parts
  #1
New Member
 
Madrid
Join Date: Apr 2018
Posts: 15
Rep Power: 8
miguwhynot is on a distinguished road
Hi, I'm currently working on a model to define the pressure and temperature of the atmospheric air, in an altitude dependant model(see attached file).

I'm reading a lot of different guides, but I'm not familiar with the define types and every example I can find involves different profiles(as shown in the udf guide). It should be pretty easy to make my case, I hope any of you can give me a hand or give me any tips so I can start to understand the coding.

Thanks in advance!

PS: I will change the h in the ecuations, since my model has a 4 m/s ascend velocity it will be h=4*time
Attached Images
File Type: png Forum.png (16.5 KB, 10 views)

Last edited by miguwhynot; July 15, 2018 at 18:50.
miguwhynot is offline   Reply With Quote

Old   July 15, 2018, 18:13
Default
  #2
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Use the DEFINE_PROFILE macro, loop through all faces on the boundary and find the height with F_CENTROID (where x[1] would correspond to the y-direction in the Cartesian coordinate system) and then use conditional if statements to apply the relevant equation.

The examples in the UDF manual provide starting codes for this task. Example 2 contains one conditional statement, and you would then extend to include three sections:

Code:
if ( (h > 0.) && (h <= 11.e3) ) {
	// Eq. 2a
} else if (h <= 20.e3) {
	// Eq. 2b
} else if (h <= 32.e3) {
	// Eq. 2c
} else {
	// Capture h values outside the allowed range:
	// print a message to the console and stop.
	Message("%d: Error: h=%e not allowed.\n",myid,h);
	return;
}
miguwhynot likes this.
`e` is offline   Reply With Quote

Old   July 15, 2018, 19:18
Default
  #3
New Member
 
Madrid
Join Date: Apr 2018
Posts: 15
Rep Power: 8
miguwhynot is on a distinguished road
Thank you for your fast reply, it has been really helpfull. I've checked the example and it was indeed pretty similar to my needs.

Based on my model, I now have a pressure defined only by time dependant ecuations as follows:

For times between 0s and 2750s
Eq 1

For times between 2750 and 5000s

Eq 2

For times between 5000 and 8000s

Eq 3

I want to use this equations to set the value of my inlet flow pressure.
This is what I have so far (thanks for the coding from your previous reply):

#include "udf.h"
DEFINE_PROFILE(pressure_inlet, thread, position)
{
face_t f;
real t = CURRENT_TIME;
begin_f_loop(f, thread)
{
if (t <= 2750) ) {
F_PROFILE(f, thread, position) = 101325.0*((288.15-0.0065*4*t)/288.15)^5.25577;
} else if (t <= 5000) {
F_PROFILE(f, thread, position) = 22632^(-(4*t-1000)/6341.62);
} else if (h <= 8000) {
F_PROFILE(f, thread, position) = 5474.87*((216.65+0.010*(4*t-20000))/216.65)^-34.163;
} else {
// Capture h values outside the allowed range:
// print a message to the console and stop.
Message("%d: Error: h=%e not allowed.\n",myid,h);
return;
}
end_
miguwhynot is offline   Reply With Quote

Old   July 15, 2018, 19:23
Default
  #4
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Quote:
Originally Posted by miguwhynot View Post
F_PROFILE(f, thread, position) = 101325.0*((288.15-0.0065*4*t)/288.15)^5.25577;
Use the pow function instead of the ^ symbol:

Code:
101325.0*pow((288.15-0.0065*4*t)/288.15,5.25577)
and you have variable h instead of t on lines 12, 15 and 17.
miguwhynot likes this.
`e` is offline   Reply With Quote

Old   July 15, 2018, 19:36
Default
  #5
New Member
 
Madrid
Join Date: Apr 2018
Posts: 15
Rep Power: 8
miguwhynot is on a distinguished road
Thanks again, for your fast reply.

Final code:

#include "udf.h"
DEFINE_PROFILE(pressure_inlet, thread, position)
{
face_t f;
real t = CURRENT_TIME;
begin_f_loop(f, thread)
{
if (t <= 2750) ) {
F_PROFILE(f, thread, position) = 101325.0*pow((288.15-0.0065*4*t)/288.15,5.25577)
} else if (t <= 5000) {
F_PROFILE(f, thread, position) = pow(22632,(-(4*t-1000)/6341.62));
} else if (t <= 8000) {
F_PROFILE(f, thread, position) = 5474.87*pow(((216.65+0.010*(4*t-20000))/216.65),-34.163);
} else {
// Capture t values outside the allowed range:
// print a message to the console and stop.
Message("%d: Error: t=%e not allowed.\n",myid,t);
return;
}
end_


Would this be a correct answer?

Thank you again for your time and efforts.
miguwhynot is offline   Reply With Quote

Old   July 15, 2018, 19:52
Default
  #6
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
You're missing the end_f_loop and a few brackets are not matching. Carefully check each opening bracket has a closing bracket and is where it should be, and then try compiling the UDF (the compilation notifications are usually helpful to identify errors in your code).
miguwhynot likes this.
`e` is offline   Reply With Quote

Old   July 15, 2018, 20:52
Default
  #7
New Member
 
Madrid
Join Date: Apr 2018
Posts: 15
Rep Power: 8
miguwhynot is on a distinguished road
Compilation notifications were really useful.

I think I know have it:


#include "udf.h"
DEFINE_PROFILE(pressure_inlet, thread, position)
{
face_t f;
real t = CURRENT_TIME;
begin_f_loop(f, thread)
{
if (t <= 2750)
{
F_PROFILE(f, thread, position) = 101325.0*pow((288.15-0.0065*4*t)/288.15,5.25577);
}
else if (t <= 5000)
{
F_PROFILE(f, thread, position) = pow(22632,(-(4*t-1000)/6341.62));
}
else if (t <= 8000) {
F_PROFILE(f, thread, position) = 5474.87*pow(((216.65+0.010*(4*t-20000))/216.65),-34.163);
}
else {
// Capture t values outside the allowed range:
// print a message to the console and stop.
Message("%d: Error: t=%e not allowed.\n",myid,t);
return;
}
end_f_loop(f,thread)

}
}

Compilation seemed to work just fine. Is it just correct?

Thank you again for your time and sorry for my many questions.
miguwhynot is offline   Reply With Quote

Old   July 17, 2018, 02:55
Default
  #8
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Sounds good, try running the simulations and see if the results are as expected. You could monitor the inlet conditions with a surface monitor to double check that the correct values have been applied.
`e` 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
Not able to use Interpreted in User Defined Function (UDF) Touré FLUENT 0 March 8, 2017 20:15
UDF error:strcpy has already been defined in the curren alinik FLUENT 0 November 2, 2016 21:17
Velocity inlet user defined function UDF in fluent Ammofreak Fluent UDF and Scheme Programming 0 January 14, 2014 05:59
Fluent User defined Scalars and UDF Anirudh_Deodhar Fluent UDF and Scheme Programming 0 February 16, 2011 21:16
UDF...UDF...UDF...UDF Luc SEMINEL FLUENT 0 November 25, 2002 05:03


All times are GMT -4. The time now is 13:43.