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

Could anyone help me write UDF for time dependent temperature in BC

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   May 9, 2012, 09:32
Default Could anyone help me write UDF for time dependent temperature in BC
  #1
PKM
New Member
 
Join Date: May 2012
Posts: 7
Rep Power: 4
PKM is on a distinguished road
Hey all, I need some help on writing UDF for Inlet BC. The inlet temp changes in time from 300K to 800K and back to 300K.
Problem:
Step1. 100 s temp stays 300K
Step 2. 100s to 700s Temp grows linearly to 800 K
Step 3. 700s to 1600s Temp remains 800K
Step 4. 1600s to 1900s Temp is 300K

Hope anyone can help me!
PKM is offline   Reply With Quote

Old   May 10, 2012, 00:49
Default
  #2
New Member
 
Patrick
Join Date: Apr 2012
Posts: 28
Rep Power: 4
Patrick1 is on a distinguished road
Quote:
Originally Posted by PKM View Post
Hey all, I need some help on writing UDF for Inlet BC. The inlet temp changes in time from 300K to 800K and back to 300K.
Problem:
Step1. 100 s temp stays 300K
Step 2. 100s to 700s Temp grows linearly to 800 K
Step 3. 700s to 1600s Temp remains 800K
Step 4. 1600s to 1900s Temp is 300K

Hope anyone can help me!
You will need something like:

t=CURRENT_TIME;

if t<100;
Temp=300;

if t<700;
Temp=300+Gradient*(t-100);

if t>700;
Temp=800;

if t>1600 AND t<1900;
Temp=300;

This syntax will be wrong but this is the idea you need! Obviously the gradient is the slope of your linear increase.
Patrick1 is offline   Reply With Quote

Old   May 10, 2012, 09:17
Default
  #3
PKM
New Member
 
Join Date: May 2012
Posts: 7
Rep Power: 4
PKM is on a distinguished road
Thank you for your ideas.
I wrote it like this (I simplified it and changed times and temps a bit...):
#include "udf.h"


DEFINE_PROFILE(temperature_profile,thread,position )
{ face_t f;


begin_f_loop(f,thread)


{


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


if ( t < 600.0 )


F_PROFILE(f,thread,position) = 300.0+1.16666667 * t;


else if ( t < 1800.0 )


F_PROFILE(f,thread,position) = 1000.0;


else


F_PROFILE(f,thread,position) = 300.0;


} end_f_loop(f,thread) }


This is a pic from the pipes inside surface monitor. Time step is 120, step 20 s and 20 iterations per step.

Itīs working but until the end when it does the jump up again. Can please anyone help me to fine the problem?
PKM is offline   Reply With Quote

Old   May 10, 2012, 11:52
Default
  #4
Member
 
Daniel Tanner
Join Date: Apr 2009
Posts: 54
Rep Power: 7
Daniel Tanner is on a distinguished road
Did you check that the correct temperature boundary condition was being applied? Do the contours of temperature at the boundary look ok?

Are you sure that the solution is converging?
Daniel Tanner is offline   Reply With Quote

Old   May 10, 2012, 13:13
Default
  #5
New Member
 
Patrick
Join Date: Apr 2012
Posts: 28
Rep Power: 4
Patrick1 is on a distinguished road
Quote:
Originally Posted by PKM View Post
Thank you for your ideas.

real t;
t= RP_Get_Real("flow-time");
Change to that, see if it makes any difference. Your graph is quite confusing, start with a simpler version? Also a graph of the temperature at the boundary over time would be easier to understand what is happening.

Try putting another if statement

if t>1800
temp=300

Do you want it to be constant afterwards or do you want thist profile to repeat?
Patrick1 is offline   Reply With Quote

Old   May 10, 2012, 15:29
Default
  #6
PKM
New Member
 
Join Date: May 2012
Posts: 7
Rep Power: 4
PKM is on a distinguished road
=> Daniel Tanner the temperature change is put on to inlet boundary witch is were I need it. The temp at the wall doesnīt look that grate in the end.

=> Iīm gonna try the other if statement tomorrow. In the first solution it dosnīt have to repeat but in the later solution it should stay 300 K for some time and then repeat again.

Thank you for your help!
PKM is offline   Reply With Quote

Old   May 11, 2012, 06:13
Default
  #7
PKM
New Member
 
Join Date: May 2012
Posts: 7
Rep Power: 4
PKM is on a distinguished road
Tested it out and the temperature distripution looks nice through out the flow time and itīs the heattransfer results come back as I expected. But there are still some problems.



reversed flow in 377 faces on outflow 12.
turbulent viscosity limited to viscosity ratio of 1.000000e+05 in 62286 cells
Should I just ignore it or what should I do?
PKM is offline   Reply With Quote

Old   May 11, 2012, 07:01
Default
  #8
New Member
 
Patrick
Join Date: Apr 2012
Posts: 28
Rep Power: 4
Patrick1 is on a distinguished road
Quote:
Originally Posted by PKM View Post
Tested it out and the temperature distripution looks nice through out the flow time and itīs the heattransfer results come back as I expected. But there are still some problems.


reversed flow in 377 faces on outflow 12.
turbulent viscosity limited to viscosity ratio of 1.000000e+05 in 62286 cells
Should I just ignore it or what should I do?
Outflow is your boundary condition I guess? I don't think Outflow deals well with reversed flow, check the manual, has some little graphs showing what flows aren't good for this BC. As far as I know, Pressure Outlet is better for reversed flow. You might want to change 'backflow specification method' to 'from neighbouring cell' (click on edit in the BC panel to change this). Play around and see if it changes your results.

Also your solution doesn't seem to be converged, how many iterations per time step are you using and what is your timestep? Is your Reynolds number what you would expect it to be, roughly? EDIT: OK I've just seen that you've plotted 2500+ iterations so of course it doesn't look converged, ignore that comment.
Patrick1 is offline   Reply With Quote

Old   May 11, 2012, 07:38
Default
  #9
Member
 
Daniel Tanner
Join Date: Apr 2009
Posts: 54
Rep Power: 7
Daniel Tanner is on a distinguished road
It looks like you have one iteration per time step and have a time step of one second, is this correct? I think you need to reconsider this. How have you calculated your time step?
Daniel Tanner is offline   Reply With Quote

Old   May 22, 2012, 04:41
Default
  #10
PKM
New Member
 
Join Date: May 2012
Posts: 7
Rep Power: 4
PKM is on a distinguished road
I used Time step size: 20 steps: 120 and iterations 20. I canīt use pressure outlet because I donīt know the temp there. How can I know when the solution is converged?
PKM is offline   Reply With Quote

Old   May 22, 2012, 12:41
Default
  #11
PKM
New Member
 
Join Date: May 2012
Posts: 7
Rep Power: 4
PKM is on a distinguished road
I made some changes in the mesh and in the velocity K-epsilon model and run the calculation again with 100 iterations per time step. At first everything was running smoothly but as the temp rose near 1000 K the solution didnīt want to converge. And the velocity limitation and back flow warnings are still there...
PKM is offline   Reply With Quote

Old   May 23, 2012, 05:22
Default
  #12
Member
 
Daniel Tanner
Join Date: Apr 2009
Posts: 54
Rep Power: 7
Daniel Tanner is on a distinguished road
I don't think this is a good way to do it. Ideally there should be less than 20 iterations per time step and it should achieve convergence (not just stop because it reaches 20).

Try reducing the time step such that you get this. It might require some playing around. You could base this on the maximum velocity and the mesh size as an estimate. Try to get udt/dx < 1 as an estimate for your time-step t (u is the velocity and dx the mesh spacing - the CFL condition).
Daniel Tanner is offline   Reply With Quote

Old   May 23, 2012, 16:02
Default
  #13
PKM
New Member
 
Join Date: May 2012
Posts: 7
Rep Power: 4
PKM is on a distinguished road
I changed 1s 2400 steps 20 iterations and one other way but the solution doesenīt reach convergence. I checked the out flow pattern and that is jumping as well. There is some problem with the flow that shouldnīt be there... I tried with changing the flow to laminar, changing the outflow to pressure outlet, changed K-epsilon model from standard to releasable, played around with the mesh but same thing happens. I donīt know what do do next. I have heard that itīs some times difficult to get conjugate heat transfer to reach convergence.
All though the temp distripution is looking oky and it seems to do in the temp wise what I expect.
Just out of ideas...
PKM is offline   Reply With Quote

Old   May 28, 2012, 17:36
Default Answer to your PM about convergence
  #14
New Member
 
Patrick
Join Date: Apr 2012
Posts: 28
Rep Power: 4
Patrick1 is on a distinguished road
Quote:
Originally Posted by PKM View Post
I changed 1s 2400 steps 20 iterations and one other way but the solution doesenīt reach convergence. I checked the out flow pattern and that is jumping as well. There is some problem with the flow that shouldnīt be there... I tried with changing the flow to laminar, changing the outflow to pressure outlet, changed K-epsilon model from standard to releasable, played around with the mesh but same thing happens. I donīt know what do do next. I have heard that itīs some times difficult to get conjugate heat transfer to reach convergence.
All though the temp distripution is looking oky and it seems to do in the temp wise what I expect.
Just out of ideas...

Hi, sorry for late reply I've been very busy.

When you run a CFD simulation, you are trying to iteratively solve a set of equations.

As you know, when you start a CFD simulation, you initialise the solution to a guess (eg. flow velocity = 0 everywhere). After each iteration, you (hopefully) have a better guess of the flow you are trying to solve.

Say we are trying to iteratively solve the equation

x+1=5

Let our first guess be x=0..

0+1=1

The residual can be though of as the difference between the guessed solution and the real one, so here the absolute residual is 5-1= 4. We then use our last result as the new guess:

1+1=2 , residual is 5-2=3

iterating again

1+2=3, residual is 5-3=2 iterate again..

1+3=4, residual is 5-4=1

1+4=5, residual is 5-5=0

So the residual has gone 3,2,1,0.

When the residual is zero, our solution is fully converged.

The exact residual value that you seen in Fluent is a bit more complicated than this, but you get the idea. We want the residual to be as low as possible. When it is as low as it can get, we say the solution is converged. Sometimes though, this doesn't happen. Sometimes the residual goes to infinity (divergence), or stays the same (non-converged), or goes up and down about a fixed value (oscillating convergence).

You can see an example in the attachment. The top graph shows convergence for a transient solution like your problem. For each timestep, the solution has to converge because the flow properties (hence the equations to be solved) change with each timestep.

Ideally you want to be converged in under 20 iterations per timestep, this is done by gradually reducing the timestep. Sometimes, however, you can get OK results by waiting longer for convergence, and using a bigger timestep (=faster simulation).

Hope this helps, let me know if you have any more questions.
Attached Images
File Type: jpg conv.jpg (43.4 KB, 9 views)
Patrick1 is offline   Reply With Quote

Old   May 28, 2012, 17:38
Default
  #15
New Member
 
Patrick
Join Date: Apr 2012
Posts: 28
Rep Power: 4
Patrick1 is on a distinguished road
Quote:
Originally Posted by PKM View Post
I changed 1s 2400 steps 20 iterations and one other way but the solution doesenīt reach convergence. I checked the out flow pattern and that is jumping as well. There is some problem with the flow that shouldnīt be there... I tried with changing the flow to laminar, changing the outflow to pressure outlet, changed K-epsilon model from standard to releasable, played around with the mesh but same thing happens. I donīt know what do do next. I have heard that itīs some times difficult to get conjugate heat transfer to reach convergence.
All though the temp distripution is looking oky and it seems to do in the temp wise what I expect.
Just out of ideas...
Decrease your timestep, start with 0.001 s perhaps and see what happens.
Patrick1 is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to write a UDF to input temperature at nodes as I.C? tensun Fluent UDF and Scheme Programming 2 July 21, 2013 10:44
Inlet won't apply UDF and has temperature at 0K! tccruise Fluent UDF and Scheme Programming 2 September 14, 2012 06:08
Calculation of the Governing Equations Mihail CFX 5 July 25, 2008 17:29
Time Dependent Temperature Dependent BC Analysis RP Main CFD Forum 1 March 28, 2008 02:22
UDF to write interp files Karl FLUENT 6 February 7, 2002 12:10


All times are GMT -4. The time now is 04:26.