CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (http://www.cfd-online.com/Forums/fluent-udf/)
-   -   Temperature-dependent source term udf (http://www.cfd-online.com/Forums/fluent-udf/117625-temperature-dependent-source-term-udf.html)

ashkan_1984 May 12, 2013 09:42

Temperature-dependent source term udf
 
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;
}

blackmask May 12, 2013 20:34

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 (Post 427008)
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;
}


ashkan_1984 May 13, 2013 06:04

reply
 
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.

blackmask May 13, 2013 20:28

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;
}

ashkan_1984 May 14, 2013 08:24

reply
 
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;
}

blackmask May 14, 2013 21:44

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.

ashkan_1984 May 15, 2013 05:05

reply
 
Thank you dear,
in fact this is my M.S. thesis and I try to in for a long time.I am really confused.

blackmask May 15, 2013 06:50

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.

ashkan_1984 May 15, 2013 14:57

reply
 
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

blackmask May 15, 2013 19:41

Sorry. The line
real p0={0.0, 0.0, 0.0};
should be changed to
real p0[] = {0.0, 0.0, 0.0};

ashkan_1984 May 16, 2013 04:38

reply
 
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

blackmask May 16, 2013 05:03

Did you interpret the UDF? Try compile it.

ashkan_1984 May 16, 2013 11:03

reply
 
I try to learn how to compile the file,after that I message you again.
Thanks


All times are GMT -4. The time now is 15:53.