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

Source terms... again

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 25, 2006, 11:11
Default Source terms... again
  #1
AdN
Guest
 
Posts: n/a
Hello!

I already post this message, but no one as enable to help me. So try again, and I hope this time someone could help me.

I'm working with UDF in FLuent. I'm in unsteady flow, and I Want to inject mass source term when the temperature is greater than a critical temperature. So I use DEFINE_SOURCE to say that when T>=Tc so source=constant.

I have 2 questions: 1)In the Fluent user book, it said that we don't need to loop over cells in the thread since Fluent already doing it: How DEFINE_SOURCE work? Is fluent call my function for the first cell and return the value and exit the function, and then call again my function for the next cell (and ect..)? Or is fluent apply the same value for all cell?

2) when i run my simulation with UDF, I remark that when T>Tc, my source term is apply, but at the other time step, it's also apply. How can i said in my function to apply only once.

I know I ask a lot, but it become really hard for me to continue without this programm
  Reply With Quote

Old   April 25, 2006, 17:49
Default Re: Source terms... again
  #2
Luca
Guest
 
Posts: n/a
Hi Adn! Here are the answers:

1) DEFINE_SOURCE macro is called for each cell. So you do not have to make a cell-loop. Of course the source value may be different for each cell. It depends on you and on your UDF. 2) To avoid this problem you need to insert in the body of your UDF a simple if-condition. For example if TRUE you add the source term otherwise you simply RETURN 0. Luca
  Reply With Quote

Old   April 26, 2006, 04:24
Default Re: Source terms... again
  #3
AdN
Guest
 
Posts: n/a
Thank you Luca for your response!

But I have again problem with my function:

#include <udf.h>

#define Tc2 1800

int A[4000];

int last_ts = -1;

int i=1;

DEFINE_SOURCE(ajout_mass, cell, thread, dS, eqn)

{

float source;

real curr_ts;

real t = RP_Get_Real("flow-time");

/* The function will ork only on the beginning of every time step*/

curr_ts = N_TIME;

if (last_ts != curr_ts) {

last_ts = curr_ts;

/*I verify the temperature of my cell, and I want to index it on a array*/

if ((C_T(cell, thread) > Tc) && (A[i] == 0))

{

source = 5000. ;

dS[eqn]= 0.;

A[i]=1;

}

else

{

source = dS[eqn] = 0.;

}

i=i+1;

}

else

{

i=1;

}

return source;

}

When I add my condition on the temperature, my function work almost well. The only problem (but not the least), is when my cell temperature is greater than Tc, at the next time step, it will be an injection of mass again! How can I say to my function to stop when it did it one time. You have to know, that all my cells in my domain don't attain the critical temperature at the same time.

Thank you a lot
  Reply With Quote

Old   April 26, 2006, 05:08
Default Re: Source terms... again
  #4
Luca
Guest
 
Posts: n/a
Ok! so you what you want to do is to tell Fluent not to add the source because somewhere you 've already reached the limited temperature (and you have already added the source), right? it's simple: just declare a variable after int A[], for example int SOURCE_ADDED = 0; in your functions now you can check that value. if 0 you add the source and you change SOURCE_ADDED to 1, if 1 you add a zero source value. Hope to be clear. Luca
  Reply With Quote

Old   April 26, 2006, 09:00
Default Re: Source terms... again
  #5
AdN
Guest
 
Posts: n/a
Thank you a lot for your help! it was very useful.

But tell me (if you have the time), how does the function DEFINE_SOURCE exactly work? I'm curious, because, naturraly, i will think that if I put just a test like you suggest me, when fluen will verify the first cell, and if the condition were satisfy, it will put SOURCE_ADD = 1... So when it will verify the second cell, in my mind the function will do nothing because SOURCE_ADD=1 ?!? Or fluent will create a memory case for SOURCE_ADD for each cell?

I'm very greatful for you're help. And thank you again to have take the time to read my messages! AdN
  Reply With Quote

Old   April 26, 2006, 13:33
Default Re: Source terms... again
  #6
Luca
Guest
 
Posts: n/a
Exactly Fluent will do nothing because you have set the variable to 1. Is this what you want to do? Luca
  Reply With Quote

Old   April 26, 2006, 14:25
Default Re: Source terms... again
  #7
AdN
Guest
 
Posts: n/a
I'm not really sur to understand: Fluent will do nothing because i set the variable to 1, but it will do nothing only for a particular cell or for all the cell present in my domain? Because, it can have cells in my domain that are not yet "switch on". And with the time the temperature of those cells can grow until Tc, so they have to be switch on (injection of source terms). So i want to keep switch off the cells who were already swith on, and switch on the others...

I hope i'm enough clear in my demand Thanxxxx
  Reply With Quote

Old   April 26, 2006, 14:53
Default Re: Source terms... again
  #8
Luca
Guest
 
Posts: n/a
Ah ok now I understand! So you need to set a variable for each cell to decide if you want to add the source term, right? It's easy. Instead of a variable SOURCE_ADDED you can define an array int *SOURCE_ADDED (or int SOURCE_ADDED[400] for example) and then simply setting tha variable for each cell by simply writing: SOURCE_ADDED[cell] = 1 or 0. So you need to check for the value of the variable SOURCE_ADDED[cell] (cell is an integer from zero to N-1 cells in your domain). Luca
  Reply With Quote

Old   April 26, 2006, 19:59
Default Re: Source terms... again
  #9
Raphael
Guest
 
Posts: n/a
I can not see how you have a system in which the source will appears only if T<Tc and will never appear again. However, including if clauses inside loops are very CPU time consuming. Besides, if you do what is in the source code proposed by Luca you would deactivate your source term if T<Tc but just T>Tc during an interaction. I mean if before the convergence T>Tc you would deactivate the source term unproperly. May be you'd better use a function which will be executed at the final (or at the beggingn) of each time step and mark that variable. Besides, you could avoid the if clause inside the loops multipling the source term by SOURCE_ADD and leaving it to be calculated all the time. You have to set SOURCE_ADD[cell]=0.0 when T<Tc after convergence. This way in that cell the source will be source*SOURCE_ADD = 0.
  Reply With Quote

Old   April 27, 2006, 05:34
Default Re: Source terms... again
  #10
AdN
Guest
 
Posts: n/a
Thank you a lot!

I don't think about this solution. It seems to work...

And to response to Raphael, I know that my program inject the term source at every iteration. I already write a function to execute my term source only at the begining of every time step. I wouldn't want to write all my program because it was unecessary for the comprehension of my problem.

Thank you for all how help me, and thank you again Luca
  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
wmake compiling new solver mksca OpenFOAM Programming & Development 14 June 22, 2018 07:29
[swak4Foam] swak4foam building problem GGerber OpenFOAM Community Contributions 54 April 24, 2015 17:02
pisoFoam compiling error with OF 1.7.1 on MAC OSX Greg Givogue OpenFOAM Programming & Development 3 March 4, 2011 18:18
DxFoam reader update hjasak OpenFOAM Post-Processing 69 April 24, 2008 02:24
DecomposePar links against liblamso0 with OpenMPI jens_klostermann OpenFOAM Bugs 11 June 28, 2007 18:51


All times are GMT -4. The time now is 16:29.