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

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

 May 9, 2012, 09:32 Could anyone help me write UDF for time dependent temperature in BC #1 New Member   Join Date: May 2012 Posts: 7 Rep Power: 6 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!

May 10, 2012, 00:49
#2
New Member

Patrick
Join Date: Apr 2012
Posts: 28
Rep Power: 6
Quote:
 Originally Posted by PKM 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;

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.

 May 10, 2012, 09:17 #3 New Member   Join Date: May 2012 Posts: 7 Rep Power: 6 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?

 May 10, 2012, 11:52 #4 Member   Daniel Tanner Join Date: Apr 2009 Posts: 54 Rep Power: 9 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?

May 10, 2012, 13:13
#5
New Member

Patrick
Join Date: Apr 2012
Posts: 28
Rep Power: 6
Quote:
 Originally Posted by PKM 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?

 May 10, 2012, 15:29 #6 New Member   Join Date: May 2012 Posts: 7 Rep Power: 6 => 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!

 May 11, 2012, 06:13 #7 New Member   Join Date: May 2012 Posts: 7 Rep Power: 6 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?

May 11, 2012, 07:01
#8
New Member

Patrick
Join Date: Apr 2012
Posts: 28
Rep Power: 6
Quote:
 Originally Posted by PKM 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.

 May 11, 2012, 07:38 #9 Member   Daniel Tanner Join Date: Apr 2009 Posts: 54 Rep Power: 9 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?

 May 22, 2012, 04:41 #10 New Member   Join Date: May 2012 Posts: 7 Rep Power: 6 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?

 May 22, 2012, 12:41 #11 New Member   Join Date: May 2012 Posts: 7 Rep Power: 6 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...

 May 23, 2012, 05:22 #12 Member   Daniel Tanner Join Date: Apr 2009 Posts: 54 Rep Power: 9 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).

 May 23, 2012, 16:02 #13 New Member   Join Date: May 2012 Posts: 7 Rep Power: 6 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...

May 28, 2012, 17:36
#14
New Member

Patrick
Join Date: Apr 2012
Posts: 28
Rep Power: 6
Quote:
 Originally Posted by PKM 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
 conv.jpg (43.4 KB, 23 views)

May 28, 2012, 17:38
#15
New Member

Patrick
Join Date: Apr 2012
Posts: 28
Rep Power: 6
Quote:
 Originally Posted by PKM 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...