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

Haeting Surface sensor using UDF

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 14, 2016, 03:04
Default Haeting Surface sensor using UDF
  #1
New Member
 
Nasser
Join Date: Mar 2014
Posts: 7
Rep Power: 12
nasergasembagloo is on a distinguished road
Dear friends,

I am trying to write a UDF to control my heating source surface boundary condition in a dish washer; it is a multi-phase problem and this UDF should check all cells to see if it contains water; if it is the UDF should get its temp and add it to a variable with the name of "temp"; also it should count the cell numbers if they contain water and add it to the "count" variable. After this it should divide "temp" variable by "count" variable to get the average temperature of all cells which contains water and write it to "twater" variable. Finally it should check if this average temperature is less or more than 338. If it is less than 338 it should set the boundary heat flux to 60000 and if its is higher than 338 it should set this "source" to zero.
I have written the following code; but I get errors continuously. Also I need to use it in parallel processing which as I read somewhere requires some corrections in code. Please help me to correct and run the code. I appreciate your help in advance.

#include "udf.h"

DEFINE_PROFILE(wallheatfluxprofile,thread,i)
{
{
Thread *t;
real temp = 0;
real count = 0;
real twater;
cell_t c;
d = Get_Domain(2);
thread_loop_c(t,d)
{
begin_c_loop(c,t)
temp += C_T(c,t);
count = count + 1;
end_c_loop(c,t)
}
twater = temp/count;
printf("temp is: %g\n", twater);
}
real source;
face_t f;
if (twater > 338)
source = 0;
else
source = 60000;

begin_f_loop(f,thread)
F_PROFILE(f,thread,i) = source;
end_f_loop(f,thread)

}

Regards,
nasergasembagloo is offline   Reply With Quote

Old   June 14, 2016, 03:25
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Quote:
Originally Posted by nasergasembagloo View Post
Dear friends,

I am trying to write a UDF to control my heating source surface boundary condition in a dish washer; it is a multi-phase problem and this UDF should check all cells to see if it contains water; if it is the UDF should get its temp and add it to a variable with the name of "temp"; also it should count the cell numbers if they contain water and add it to the "count" variable. After this it should divide "temp" variable by "count" variable to get the average temperature of all cells which contains water and write it to "twater" variable. Finally it should check if this average temperature is less or more than 338. If it is less than 338 it should set the boundary heat flux to 60000 and if its is higher than 338 it should set this "source" to zero.
I have written the following code; but I get errors continuously. Also I need to use it in parallel processing which as I read somewhere requires some corrections in code. Please help me to correct and run the code. I appreciate your help in advance.

#include "udf.h"

DEFINE_PROFILE(wallheatfluxprofile,thread,i)
{
{
Thread *t;
real temp = 0;
real count = 0;
real twater;
cell_t c;
d = Get_Domain(2);
thread_loop_c(t,d)
{
begin_c_loop(c,t)
temp += C_T(c,t);
count = count + 1;
end_c_loop(c,t)
}
twater = temp/count;
printf("temp is: %g\n", twater);
}
real source;
face_t f;
if (twater > 338)
source = 0;
else
source = 60000;

begin_f_loop(f,thread)
F_PROFILE(f,thread,i) = source;
end_f_loop(f,thread)

}

Regards,
I don't understand what you are trying to do with the {}s... In the code below I just moved all declaration of variables to the top, and made de {}s logical. Is this what you want?

Code:
#include "udf.h"

DEFINE_PROFILE(wallheatfluxprofile,thread,i)
{
Thread *t;
real temp = 0;
real count = 0;
real twater;
cell_t c;
d = Get_Domain(2);
real source;
face_t f;

thread_loop_c(t,d)
{
  begin_c_loop(c,t)
  temp += C_T(c,t);
  count = count + 1;
}
end_c_loop(c,t);
twater = temp/count;
printf("temp is: %g\n", twater);
if (twater > 338) 	source = 0; else source = 60000;
	
  begin_f_loop(f,thread) {
    F_PROFILE(f,thread,i) = source;
  }
  end_f_loop(f,thread);
  
}
By the way: your method of taking the average cell temperature is only giving what normal people would call "averaged temperature" if the cells all have the same volume.
pakk is offline   Reply With Quote

Old   June 14, 2016, 03:55
Default
  #3
New Member
 
Nasser
Join Date: Mar 2014
Posts: 7
Rep Power: 12
nasergasembagloo is on a distinguished road
Thank you very mcuh for your response; as I mentioned before I need to get the average temperature of water which is not included in all cells and as a result of tempreature increment reduces gradually. So what should I do to get the average temperature of water?

Regards,
nasergasembagloo is offline   Reply With Quote

Old   June 14, 2016, 04:46
Default
  #4
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
If you want the volume-averaged temperature, the code should look something like this:

Code:
real sumtemp = 0;
real sumvolume = 0;
real twater;
cell_t c;

d = Get_Domain(2);

/* loop through all cells that contain water */
 {
  sumtemp += C_T(c,t) * C_VOLUME(c,t);
  sumvolume += C_VOLUME(c,t);
 }
end_c_loop(c,t)
twater = sumtemp /sumvolume;
But I have to say that I don't understand how you intend to loop through all cells that contain water. I don't see any line in your code at all that tries to check if the cell contains water.
pakk is offline   Reply With Quote

Old   June 14, 2016, 04:57
Default
  #5
New Member
 
Nasser
Join Date: Mar 2014
Posts: 7
Rep Power: 12
nasergasembagloo is on a distinguished road
Quote:
Originally Posted by pakk View Post
If you want the volume-averaged temperature, the code should look something like this:

Code:
real sumtemp = 0;
real sumvolume = 0;
real twater;
cell_t c;

d = Get_Domain(2);

/* loop through all cells that contain water */
 {
  sumtemp += C_T(c,t) * C_VOLUME(c,t);
  sumvolume += C_VOLUME(c,t);
 }
end_c_loop(c,t)
twater = sumtemp /sumvolume;
But I have to say that I don't understand how you intend to loop through all cells that contain water. I don't see any line in your code at all that tries to check if the cell contains water.
Thank you very much for your answer and help; I am very new in writing UDF's. So I could do some errors in code. How can I do this? (Checking if it is water or not?)
Does your written code do this?

Best regards,
nasergasembagloo is offline   Reply With Quote

Reply

Tags
fluent - udf, heat flux, multi phase flow


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 for variable surface tension on VOF OmarEGB FLUENT 3 June 18, 2022 01:08
UDF Surface Reaction Basics FreeFall79 Fluent UDF and Scheme Programming 2 January 15, 2019 11:09
surface reaction UDF taekyu8 Fluent UDF and Scheme Programming 1 June 16, 2013 03:23
Ansys FLUENT UDF - Velocity profile (of known values) across edge / surface emmkell Fluent UDF and Scheme Programming 2 October 21, 2011 13:12
need help regarding error in surface rxn UDF Ashish Jain FLUENT 0 May 16, 2005 10:43


All times are GMT -4. The time now is 20:03.