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

Temperature-dependent source term udf

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 12, 2013, 09:42
Default Temperature-dependent source term udf
  #1
New Member
 
ashkan
Join Date: May 2013
Posts: 12
Rep Power: 12
ashkan_1984 is on a distinguished road
Dear all
I have one problem in fluent udf.I want to write one temperature-dependent source term.I want my temperature increase up to 350K because of source term,and when it reach to 350K ,source term is stop and because of free convection the temperature come back to initial values and again this cycle continue.I write one udf but I have really problem in this,please help me.
I sent the my UDF,

#include "udf.h"
DEFINE_SOURCE(cell_source, cell, thread)
{
real source;

real temp = C_T(cell, thread);
if(temp <350.15)
{
source=20000000*(1+.02*(temp-250.15));
}
if(temp>=350.15)
{
while(temp>=250.15)
{
temp = C_T(cell, thread);
source=0;
}
}
return source;
}
ashkan_1984 is offline   Reply With Quote

Old   May 12, 2013, 20:34
Default
  #2
Senior Member
 
Join Date: Aug 2011
Posts: 421
Blog Entries: 1
Rep Power: 21
blackmask will become famous soon enough
You should have a clear definition of the point when the source terms should be switch on, and you should tell us whether such switch is global or cell-wise.

Quote:
Originally Posted by ashkan_1984 View Post
Dear all
I have one problem in fluent udf.I want to write one temperature-dependent source term.I want my temperature increase up to 350K because of source term,and when it reach to 350K ,source term is stop and because of free convection the temperature come back to initial values and again this cycle continue.I write one udf but I have really problem in this,please help me.
I sent the my UDF,

#include "udf.h"
DEFINE_SOURCE(cell_source, cell, thread)
{
real source;

real temp = C_T(cell, thread);

if(temp <350.15)
{
source=20000000*(1+.02*(temp-250.15));
}
if(temp>=350.15)
{

/* this branch results in an indefinite loop */
while(temp>=250.15) /*always true because temp >= 350.15*/
{
/* it does not change the value of temp */
temp = C_T(cell, thread);
source=0;
}

}
return source;
}
blackmask is offline   Reply With Quote

Old   May 13, 2013, 06:04
Default reply
  #3
New Member
 
ashkan
Join Date: May 2013
Posts: 12
Rep Power: 12
ashkan_1984 is on a distinguished road
Thanks for your answer,
The temperature of the center of channel is important for me where the cordinate axis is (0,0,0).
I have problem in second loop,when source==0,because of free convection the cell is cooled and temperature is decrease.I want when temperature reach to initial value again repeat the cycle.
ashkan_1984 is offline   Reply With Quote

Old   May 13, 2013, 20:28
Default
  #4
Senior Member
 
Join Date: Aug 2011
Posts: 421
Blog Entries: 1
Rep Power: 21
blackmask will become famous soon enough
The reference cell is fixed so that you could find cell index cell_at_0 and cell thread thread_at_0 once for all. Replace the "???" by the values you find for that particular value. The value of T_lower should be a bit higher than the initial and surrounding values, or the source may never be turned on again.

#include "udf.h"

#define T_upper 350.15
#define T_lower 250.15

Thread *thread_at_0;
cell_t cell_at_0;

DEFINE_ON_DEMAND(once_for_all) {
/*The solution is provided by William Wangard*/
CX_Cell_Id *cc;
real p0[]={0.0, 0.0, 0.0};
CX_Start_ND_Point_Search();

cc = CX_Find_Cell_With_Point(p0);
if ( NNULLP(cc) ) {
thread_at_0 = cc->ct.t;
cell_at_0 = cc->ct.c;
} else {
Error("Point not in domain\n");
}
CX_End_ND_Point_Search();

}

DEFINE_SOURCE(cell_source, cell, thread)
{
static int SRC_ON=1;
real source;

real temp = C_T(cell_at_0, thread_at_0);

if(temp>=T_higher)
{
SRC_ON = 0;
}

if (temp < T_lower)
{
SRC_ON = 1;
}

if(SRC_ON)
{
source=20000000*(1+.02*(temp-250.15));
} else {
source = 0.
}



return source;
}

Last edited by blackmask; May 15, 2013 at 19:40.
blackmask is offline   Reply With Quote

Old   May 14, 2013, 08:24
Default reply
  #5
New Member
 
ashkan
Join Date: May 2013
Posts: 12
Rep Power: 12
ashkan_1984 is on a distinguished road
I used your udf code but I have some problem that I said in following:

1-I give cell_at_0 and thread_at_0 the center of my channel cordinate [0,0,0] but the system get a error.

2-the fluent give error to static int SRC_ON=1 and I change it to int SRC_ON=1

3-the fluent give error to real temp = C_T(cell0, thread0); and I change it to
real temp = C_T(cell, thread);

4-after this changes,I run the fluent but unfortunately my temperature isn,t increase.

I sent the last udf I used


#define cell_at_0 [0,0,0]
#define thread_at_0 [0,0,0]
#define T_upper 353.15
#define T_lower 280.15

#include "udf.h"
DEFINE_SOURCE(cell_source, cell, thread)
{
int SRC_ON=1;
real source;

real temp = C_T(cell, thread);
if (temp>=T_upper)
{
SRC_ON=0.0;
}
if(temp<=T_lower)
{
SRC_ON=1.0;
}
if(SRC_ON)
{
source=20000000*(1+.02*(temp-250.15));}
else
{
source=0.0;
}
return source;
}
ashkan_1984 is offline   Reply With Quote

Old   May 14, 2013, 21:44
Default
  #6
Senior Member
 
Join Date: Aug 2011
Posts: 421
Blog Entries: 1
Rep Power: 21
blackmask will become famous soon enough
I have modified my code in my last post but have never test it. I will give you some suggestion but I really do not have the time for the entire solution.
blackmask is offline   Reply With Quote

Old   May 15, 2013, 05:05
Default reply
  #7
New Member
 
ashkan
Join Date: May 2013
Posts: 12
Rep Power: 12
ashkan_1984 is on a distinguished road
Thank you dear,
in fact this is my M.S. thesis and I try to in for a long time.I am really confused.
ashkan_1984 is offline   Reply With Quote

Old   May 15, 2013, 06:50
Default
  #8
Senior Member
 
Join Date: Aug 2011
Posts: 421
Blog Entries: 1
Rep Power: 21
blackmask will become famous soon enough
Message me if you need help. The code I posted above should work for some versions of fluent. It seems that FLUENT has modified the interface for some functions among different versions.
blackmask is offline   Reply With Quote

Old   May 15, 2013, 14:57
Default reply
  #9
New Member
 
ashkan
Join Date: May 2013
Posts: 12
Rep Power: 12
ashkan_1984 is on a distinguished road
I have this error in fluent 6.3 for this sentence

cc = CX_Find_Cell_With_Point(p0);

CX_Find_Cell_With_Point: argument 1 type mismatch (float instead of pointer to float)


and in fluent 14 for this sentence

CX_Start_ND_Point_Search()

I have this error:

CX_Start_ND_Point_Search: undeclared variable
ashkan_1984 is offline   Reply With Quote

Old   May 15, 2013, 19:41
Default
  #10
Senior Member
 
Join Date: Aug 2011
Posts: 421
Blog Entries: 1
Rep Power: 21
blackmask will become famous soon enough
Sorry. The line
real p0={0.0, 0.0, 0.0};
should be changed to
real p0[] = {0.0, 0.0, 0.0};
blackmask is offline   Reply With Quote

Old   May 16, 2013, 04:38
Default reply
  #11
New Member
 
ashkan
Join Date: May 2013
Posts: 12
Rep Power: 12
ashkan_1984 is on a distinguished road
Sorry for my more question,I'm really beginner in udf. Now I have this error for this line

thread_at_0 = cc->ct.t;

fluent write;

structure reference not implemented

I remove the _ and write this line like this thread_at_0 = cc>ct.t;

but again fluent said
ct: undeclared variable
ashkan_1984 is offline   Reply With Quote

Old   May 16, 2013, 05:03
Default
  #12
Senior Member
 
Join Date: Aug 2011
Posts: 421
Blog Entries: 1
Rep Power: 21
blackmask will become famous soon enough
Did you interpret the UDF? Try compile it.
blackmask is offline   Reply With Quote

Old   May 16, 2013, 11:03
Default reply
  #13
New Member
 
ashkan
Join Date: May 2013
Posts: 12
Rep Power: 12
ashkan_1984 is on a distinguished road
I try to learn how to compile the file,after that I message you again.
Thanks
ashkan_1984 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 Source term problem natantyt FLUENT 2 May 15, 2018 21:40
[swak4Foam] swak4Foam-groovyBC build problem zxj160 OpenFOAM Community Contributions 18 July 30, 2013 13:14
UDF Source Term Christian FLUENT 4 August 1, 2009 05:53
DecomposePar links against liblamso0 with OpenMPI jens_klostermann OpenFOAM Bugs 11 June 28, 2007 17:51
UDF for energy source mauricio sanchez FLUENT 0 August 30, 2005 15:56


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