|
[Sponsors] |
March 25, 2009, 05:08 |
temperature gradient problem in udf
|
#1 |
New Member
souviktor
Join Date: Mar 2009
Posts: 11
Rep Power: 17 |
Hi all,I am using a udf to attach 2 body forces(source terms in momentum equation)one in x direction and another in y direction with 2 define_source macros written in same source file.
They both call a third function for some computational task(like a sin or cos function,entirely mathematical stuff). Now,the problem is I am using c_t_g macro to calculate temperature gradient in both the source functions.I read in the manual "In order to retain the gradient data (when you want to set up user-dened scalar transport equations, for example), you can prevent the solver from freeing up memory by issuing the text command solve/set/expert and then answering yes to the question Keep temporary solver memory from being freed?. Note that when you do this, all of the gradient data is retained, but the calculation requires more memory to run." I did that...But I am getting ACCESS VIOLATION during runtime... Please help.... the udf is as follows.... Code:
#include "udf.h" real getfld(real x_cord,real y_cord,int option) { real px,py,sinphi,cosphi,ans,r,H1; px=.01; py=-.005; r=sqrt((x_cord-px)*(x_cord-px)+(y_cord-py)*(y_cord-py)); sinphi=fabs((y_cord-py)/r); if(x_cord>px) cosphi=sqrt(1-sinphi*sinphi); else cosphi=-sqrt(1-sinphi*sinphi); H1=29.6/(r*r); if (option==1) ans=2*H1*cosphi*sinphi; else if(option==2) ans=H1*(sinphi*sinphi-cosphi*cosphi); else ans=H1; return ans; } DEFINE_SOURCE(kbf_source_x, c, t, dS, eqn) { real x[ND_ND],beta_p,muzero,kai_m_zero,T_star,Tempt,term1,term2; real denct,x1,y1,px,py,rsinphi,cosphi,Hx,Hy,H_east,H_west,del_H_square_del_x,del_T_del_x,del_T_del_y; real con, source; muzero=4*3.1454*.0000001; kai_m_zero=.1; beta_p=5.6*0.0001; C_CENTROID(x, c, t); x1=x[0]; y1-x[1]; Hx=getfld(x1,y1,1); Hy=getfld(x1,y1,2); H_east=getfld(x1+0.00001,y1,3); H_west=getfld(x1-0.00001,y1,3); del_H_square_del_x=(H_east*H_east-H_west*H_west)/.00002; Tempt=C_T(c,t); T_star=300; del_T_del_x=C_T_G(c,t)[0]; del_T_del_y=C_T_G(c,t)[1]; term1=.5*muzero*kai_m_zero*(1-beta_p*(Tempt-T_star))*del_H_square_del_x; term2=muzero*kai_m_zero*kai_m_zero*beta_p*(Hx*del_T_del_x+Hy*del_T_del_y)*Hx; source=term1+term2; dS[eqn]=0; return source; } DEFINE_SOURCE(kbf_source_y, c, t, dS, eqn) { real x[ND_ND],beta_p,muzero,kai_m_zero,T_star,Tempt,term1,term2; real denct,x1,y1,px,py,rsinphi,cosphi,Hx,Hy,H_south,H_north,del_H_square_del_y,del_T_del_x,del_T_del_y; real con, source; muzero=4*3.1454*.0000001; kai_m_zero=.1; beta_p=5.6*0.0001; C_CENTROID(x, c, t); x1=x[0]; y1-x[1]; Hx=getfld(x1,y1,1); Hy=getfld(x1,y1,2); H_north=getfld(x1,y1+0.00001,3); H_south=getfld(x1,y1-0.00001,3); del_H_square_del_y=(H_north*H_north-H_south*H_south)/.00002; Tempt=C_T(c,t); T_star=300; del_T_del_x=C_T_G(c,t)[0]; del_T_del_y=C_T_G(c,t)[1]; term1=.5*muzero*kai_m_zero*(1-beta_p*(Tempt-T_star))*del_H_square_del_y; term2=muzero*kai_m_zero*kai_m_zero*beta_p*(Hx*del_T_del_x+Hy*del_T_del_y)*Hy; source=term1+term2; dS[eqn]=0; return source; } |
|
March 25, 2009, 05:53 |
|
#2 |
Member
Henrik Ström
Join Date: Mar 2009
Posts: 33
Rep Power: 17 |
If you turn on "Keep temporary solver memory from being freed", Fluent will start to store gradient data. However, there will be no gradient data stored from the previous iteration, so in your first iteration these will be undefined, which might cause your problem. Either turn the option on and do one or several iterations/time steps before you start your "real" simulation, to ensure that the gradients are there, or rewrite your code to include something like:
if ( NULL != THREAD_STORAGE(t,SV_T_G) ) { temp_gradient_x = C_T_G(c,t)[0]; } else { /* first iteration OR option to store gradients not turned on */ temp_gradient_x = 0.0; } Hope this helps! /Henrik |
|
March 31, 2009, 09:43 |
|
#3 |
New Member
souviktor
Join Date: Mar 2009
Posts: 11
Rep Power: 17 |
Thanks a lot Henriks ,Your code snippet worked like a charm...!!!!
|
|
July 11, 2015, 16:49 |
temperature gradient fluent
|
#4 |
New Member
Rasoul
Join Date: Jun 2015
Posts: 3
Rep Power: 11 |
Dear all
I entered the entropy generation equation in custom field function.but my result is wrong(not validated with paper). I examined my results and found that Fluent calculate the temperature gradient, but it can not properly calculate the square of the temperature gradient!!! please help with this problem thanks |
|
February 25, 2019, 15:25 |
|
#5 | |
New Member
Abhi
Join Date: Jan 2018
Posts: 27
Rep Power: 8 |
Quote:
|
||
February 26, 2019, 07:37 |
|
#6 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
There is no indication that Fluent can not "properly calculate the square of the temperature gradient".
It is much more likely that Ras0ul made a mistake in his code. But, because he never posted his code, we can not find out the truth. (I don't understand why so many people ask here for help with their code, but then don't post their code... I really don't know what they expect to happen.) |
|
March 10, 2019, 06:48 |
|
#7 |
New Member
Jayant Kumar
Join Date: Mar 2019
Posts: 2
Rep Power: 0 |
i have a cfd problem setup in which i have to insert a udf for soil temperature distribution with respect to depth and real time as an initial condition. I have the equation for it right now i have insert a constant soil temperature patch., please help in how may i proceed?
|
|
Tags |
access, gradient, temperature, udf, violation |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Help! Compiled UDF problem 4 Wave tank tutorial | Shane | FLUENT | 1 | September 3, 2010 03:32 |
Temperature gradient | Jaho | CFX | 2 | March 12, 2009 20:36 |
Urgent,species gradient problem | zhou | FLUENT | 0 | March 4, 2004 13:59 |
UDF reading the temperature gradient | Fabian | FLUENT | 1 | May 29, 2003 21:18 |
Direct calculation of temperature gradient | J.W.Ryu | FLUENT | 5 | December 27, 2001 07:39 |