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

How to use a UDF to assign a temperature to cells that is within a range of z coord

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 23, 2023, 09:38
Default How to use a UDF to assign a temperature to cells that is within a range of z coord
  #1
New Member
 
Khanh Dang
Join Date: Sep 2022
Posts: 3
Rep Power: 3
kdang is on a distinguished road
Hello,

Could I get help with writing my first UDF in Fluent? I have written a UDF to assign a temperature to the cells whose z-coordinates are within a specified range. But it doesn't seem to work. Could everyone take a look at my code and point what I have done wrong?

I'm doing a series of transient simulations of the heat transfer between food cans and hot gas in a convection oven. I have a 228-in length filled with cans, and the can locations are periodic such that there are 19 units of cans. Each unit is 12 in long.

I want to use the UDF to set an initial temperature for the first unit of cans (Unit 1) and then solve for 16 s. Then, the current temperature of the Unit 1 will be the initial temperature of Unit 2. I will repeat this procedure until Unit 19.

I used DEFINE_ON_DEMAND instead of DEFINE_INIT because I'm using a steady-state solution as the initial solution for the hot gas.

Thank you so much in advance for your time and help!

Code:
#include "udf.h"

DEFINE_ON_DEMAND(can_unit_1_temp)
{
	/* declare domain pointer since it is not passed as an argument to the DEFINE macro */
	Domain *domain; 
	domain = Get_Domain(1); 

	/* get the cell thread pointer by using the macro Lookup_Thread(domain, zone_id) instead of thread *ct */
	int id = 55; /* ID of can solid cell zone */
	Thread *ct = Lookup_Thread(domain, id);

	cell_t c; /* cell index - an special Ansys Fluent data type */
	real pos[ND_ND];
 
	/* loop through all the cells in the cell thread of the can solid */
	begin_c_loop(c,ct)
	{
		C_CENTROID(pos,c,ct);
		if (0.1524 < pos[2] && pos[2] < 0.4572) /* the first 12 inch of cans (unit 1) is between 0.1524 and 0.4572 m */
			C_T(c,ct) = 600.0;
	}
	end_c_loop(c,ct)
}
kdang is offline   Reply With Quote

Old   February 4, 2023, 10:52
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
code seems to be ok
by default fluent uses SI for all UNITs so check your values, that could be a problem
Code:
if (0.1524 < pos[2] && pos[2] < 0.4572)
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ 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
[snappyHexMesh] snappyHexMesh sticking point natty_king OpenFOAM Meshing & Mesh Conversion 11 February 20, 2024 09:12
SimpleFoam & Theater jipai OpenFOAM Running, Solving & CFD 3 June 18, 2019 10:11
cellZone not taking all the cells inside rahulksoni OpenFOAM Running, Solving & CFD 6 January 25, 2019 00:11
[snappyHexMesh] sHM layer process keeps getting killed MBttR OpenFOAM Meshing & Mesh Conversion 4 August 15, 2016 03:21
[Netgen] Import netgen mesh to OpenFOAM hsieh OpenFOAM Meshing & Mesh Conversion 32 September 13, 2011 05:50


All times are GMT -4. The time now is 09:33.