CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   Temperature-dependent source term udf (https://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"
{
real source;

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

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

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.

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

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) ) {
cell_at_0 = cc->ct.c;
} else {
Error("Point not in domain\n");
}
CX_End_ND_Point_Search();

}

{
static int SRC_ON=1;
real source;

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

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

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 T_upper 353.15
#define T_lower 280.15

#include "udf.h"
{
int SRC_ON=1;
real source;

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

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

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

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

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

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

Sorry for my more question,I'm really beginner in udf. Now I have this error for this line

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