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

LinkBack  Thread Tools  Display Modes 
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: 7 
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: 7 
Quote:
t=CURRENT_TIME; if t<100; Temp=300; if t<700; Temp=300+Gradient*(t100); 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: 7 
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("flowtime"); 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: 10 
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: 7 
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: 7 
=> 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: 7 
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: 7 
Quote:
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: 10 
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: 7 
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: 7 
I made some changes in the mesh and in the velocity Kepsilon 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: 10 
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 timestep 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: 7 
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 Kepsilon 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 
Answer to your PM about convergence

#14  
New Member
Patrick
Join Date: Apr 2012
Posts: 28
Rep Power: 7 
Quote:
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 51= 4. We then use our last result as the new guess: 1+1=2 , residual is 52=3 iterating again 1+2=3, residual is 53=2 iterate again.. 1+3=4, residual is 54=1 1+4=5, residual is 55=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 (nonconverged), 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. 

May 28, 2012, 17:38 

#15  
New Member
Patrick
Join Date: Apr 2012
Posts: 28
Rep Power: 7 
Quote:


June 5, 2016, 21:07 
nested if statement in udf

#16 
New Member
mm
Join Date: May 2016
Posts: 24
Rep Power: 2 
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" DEFINE_PROFILE(inlet_temperature,thread,position ) { face_t f; begin_f_loop(f,thread) { real t = RP_Get_Real("flowtime"); if ( t <= 100.0 ) F_PROFILE(f,thread,position) = 379.48 + 0.0004*t; else if (100.0 < t <= 180.0 ) F_PROFILE(f,thread,position) = 1.0624*t + 352.0; else if (180.0 < t <= 200.0 ) F_PROFILE(f,thread,position) = 0.2716*t + 494.4; else if (200.0 < t <= 400.0 ) F_PROFILE(f,thread,position) = 328.14*pow(t,0.097); else F_PROFILE(f,thread,position) = 727.82; } end_f_loop(f,thread) } sorry for my poor knowledge of programming. please help me on this error. Thanks. 

Thread Tools  
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Calculation of the Governing Equations  Mihail  CFX  7  September 7, 2014 06:27 
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 
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 13:10 