CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   UDF code for heat generating source (https://www.cfd-online.com/Forums/fluent-udf/161510-udf-code-heat-generating-source.html)

valerhain October 23, 2015 08:07

UDF code for heat generating source
 
hi dear friends
I am supposed to write a udf for heat generation rate which is a function at this form:


http://uupload.ir/files/uyew_cfd123.jpg


I prepared this code for simulating :

#include "udf.h"
#define EPS 0.01
#define SIGMA 0.004
DEFINE_SOURCE(cell_x_source, cell, thread, dS, eqn)
{
real x[ND_ND];
real source;
C_CENTROID(x,cell,thread);

source=EPS*exp(((x[0]-0.4)*(x[0]-0.4)+(x[1]-0.004)*(x[1]-0.004))/(-SIGMA*SIGMA));
dS[eqn]=0;
return source;
}


but is not work. this code dont have any effect in my results. dear friend I have less than 5 days for simulating this. please help me and I will thankfull of you...

krushna October 27, 2015 02:14

hi yashar,
i think first you define scalar for x[0] and x[1] and also write udf for initialization of x[0] and x[1]
regards,
krushna

pakk October 28, 2015 06:31

It is not about x[0] and x[1], they are defined in the code and you don't need a udf to initialize them.

Can you tell us what you did with the code?

You saved it in a text file, and then what? How did you tell Fluent to use this code?

(And are you sure that the source locus, (x0,y0)=(0.4,0.004), is in your domain?)

valerhain October 28, 2015 07:06

Quote:

Originally Posted by pakk (Post 570669)
It is not about x[0] and x[1], they are defined in the code and you don't need a udf to initialize them.

Can you tell us what you did with the code?

You saved it in a text file, and then what? How did you tell Fluent to use this code?

(And are you sure that the source locus, (x0,y0)=(0.4,0.004), is in your domain?)

first of all I am very thankful
I have written this code on the notepad and save it with .c format
If you see the pictures that I was adding in first post, I am trying to add this code in energy equation
user define-->function-->interpreted-->and after choosing the file, I have interpreted the code
then I in boundary condition part, I choose fluid and adding the code to the heat source part
I want to this code define a heat source in (0.4.0.004) and affect boundary layer
but unfortunately it is not work and there is heat source effects in the results
as you said I am going to check domain again

pakk October 28, 2015 07:10

Those seem like good steps...

To check if your code is really used, you can put the following line in:
Code:

Message("Test\n");
Put it for example directly above your "return"-line. If you see "Test" appearing in your text user interface, the code is run, and if you don't see it, it is not run.

Another thing you could do is to increase epsilon for testing. Maybe the source is really added, but the effect is too small to notice. Change epsilon from 0.01 to a big value such as 1000, and see if your result changes.

valerhain October 28, 2015 07:26

Quote:

Originally Posted by pakk (Post 570676)
Those seem like good steps...

To check if your code is really used, you can put the following line in:
Code:

Message("Test\n");
Put it for example directly above your "return"-line. If you see "Test" appearing in your text user interface, the code is run, and if you don't see it, it is not run.

Another thing you could do is to increase epsilon for testing. Maybe the source is really added, but the effect is too small to notice. Change epsilon from 0.01 to a big value such as 1000, and see if your result changes.

I added your code to my UDF and this is what I see :


Error: H:\source.c: line 14: function "CX_Message" not found (pc=128).

:(:(:(:(:(:(:(:(:(

pakk October 28, 2015 07:29

Quote:

Originally Posted by valerhain (Post 570679)
I added your code to my UDF and this is what I see :


Error: H:\source.c: line 14: function "CX_Message" not found (pc=128).

:(:(:(:(:(:(:(:(:(

Silly me, you are interpreting, then Message does not work...
Use printf instead.

printf("test\n");

valerhain October 28, 2015 07:44

Quote:

Originally Posted by pakk (Post 570680)
Silly me, you are interpreting, then Message does not work...
Use printf instead.

printf("test\n");

I tried again....there is not any error that be written in the user text interface but the test message also not!
:(

pakk October 28, 2015 07:48

To be clear: the text should show up when you clicked 'Calculate'.
If it doesn't show up then, the code is never run by Fluent, but I can not explain why not.

valerhain October 28, 2015 07:53

Quote:

Originally Posted by pakk (Post 570686)
To be clear: the text should show up when you clicked 'Calculate'.
If it doesn't show up then, the code is never run by Fluent, but I can not explain why not.

bingooooooooooooooooooooooooooooooooo
it is works.....when i push calculate buttun many of test!!! letter are written in the interfaaaaaaaaaaaaaaaaace!
yohuuuuuuuuuuuuuuuuuuuuu:p:p:p:p:p

valerhain October 28, 2015 08:06

Quote:

Originally Posted by pakk (Post 570686)
To be clear: the text should show up when you clicked 'Calculate'.
If it doesn't show up then, the code is never run by Fluent, but I can not explain why not.

my Pc works on it
fluent process the problem
so as soon as I see the results I will tell you

dear friend
you are reallllllllllllllly helpful person
thank alooooooooooooooooot

kcgmech October 31, 2015 03:56

Quote:

Originally Posted by valerhain (Post 569918)
hi dear friends
I am supposed to write a udf for heat generation rate which is a function at this form:


http://uupload.ir/files/uyew_cfd123.jpg


I prepared this code for simulating :

#include "udf.h"
#define EPS 0.01
#define SIGMA 0.004
DEFINE_SOURCE(cell_x_source, cell, thread, dS, eqn)
{
real x[ND_ND];
real source;
C_CENTROID(x,cell,thread);

source=EPS*exp(((x[0]-0.4)*(x[0]-0.4)+(x[1]-0.004)*(x[1]-0.004))/(-SIGMA*SIGMA));
dS[eqn]=0;
return source;
}


but is not work. this code dont have any effect in my results. dear friend I have less than 5 days for simulating this. please help me and I will thankfull of you...

dear valerhain,
what you are trying to do? if you want to include the heat generation source as surface heat flux, you can apply using DEFINE PROFILE...

bhargavbharathan November 18, 2015 11:55

Hi,

I'm not sure if it has been addressed already but I think source UDFs can only be compiled and interpreted.

Bhargav

valerhain November 18, 2015 14:24

Quote:

Originally Posted by bhargavbharathan (Post 573907)
Hi,

I'm not sure if it has been addressed already but I think source UDFs can only be compiled and interpreted.

Bhargav

thanks alot dear friend


All times are GMT -4. The time now is 19:31.