CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   Could anyone help me write UDF for time dependent temperature in BC (https://www.cfd-online.com/Forums/fluent-udf/101628-could-anyone-help-me-write-udf-time-dependent-temperature-bc.html)

 PKM May 9, 2012 09:32

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

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! :)

 Patrick1 May 10, 2012 00:49

Quote:
 Originally Posted by PKM (Post 360111) 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.

 PKM May 10, 2012 09:17

I wrote it like this (I simplified it and changed times and temps a bit...):
#include "udf.h"

{ face_t f;

{

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

if ( t < 600.0 )

else if ( t < 1800.0 )

else

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?

 Daniel Tanner May 10, 2012 11:52

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?

 Patrick1 May 10, 2012 13:13

Quote:
 Originally Posted by PKM (Post 360335) 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?

 PKM May 10, 2012 15:29

=> 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.

 PKM May 11, 2012 06:13

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?

 Patrick1 May 11, 2012 07:01

Quote:
 Originally Posted by PKM (Post 360546) 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.

 Daniel Tanner May 11, 2012 07:38

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?

 PKM May 22, 2012 04:41

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 May 22, 2012 12:41

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...

 Daniel Tanner May 23, 2012 05:22

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).

 PKM May 23, 2012 16:02

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...

 Patrick1 May 28, 2012 17:36

1 Attachment(s)
Quote:
 Originally Posted by PKM (Post 362741) 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.

 Patrick1 May 28, 2012 17:38

Quote:
 Originally Posted by PKM (Post 362741) 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...

 mmunige June 5, 2016 21:07

nested if statement in udf

Respected members

I am using udf for defining transient temperature at inlet boundary of my model in fluent. I am writing nested if statement, but model keeps on using the same equation after 180 seconds, and does not move to the next if else statement. My udf is as follows:

#include"udf.h"

{

face_t f;

{

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

if ( t <= 100.0 )

else if (100.0 < t <= 180.0 )

else if (180.0 < t <= 200.0 )

else if (200.0 < t <= 400.0 )
else

}
}

sorry for my poor knowledge of programming.
Thanks.

 ViLaks November 10, 2017 02:37

Hello All,

I need to input temperature-time dependence as b.c. on a wall as part of my simulations. I have given the following as input udf.

{
face_t f;
real t = CURRENT_TIME;