
[Sponsors] 
March 14, 2019, 10:01 
UDF with 2 source terms

#1 
Member
Saurabh Das
Join Date: Jul 2018
Posts: 43
Rep Power: 8 
Hello I have written the following udf:
Code:
#include "udf.h" #define PI 3.1415926 //Pi, a constant #define IO 1E14 //IO, initial intensity #define R 0.002 //R, radius of beam #define rho_b 1050 #define wb 0.29 #define cb 3850 #define tq 0.001 DEFINE_SOURCE(top_hat,c,t,dS,eqn) { real x[ND_ND],time; real r, source,vol; time=RP_Get_Real("flowtime"); C_CENTROID(x,c,t); r = sqrt(pow((x[0]0.0125),2) + pow((x[1]0.0025),2)); vol = (2*r*r)/(R*R); if (time < 6e5) if (r < 0.002) { source = IO*exp(vol); dS[eqn] = 0; } else { source = 0; dS[eqn] = 0; } else { source = 0; dS[eqn] = 0; } return source; } DEFINE_SOURCE(perfusion,c,t,dS,eqn) { real physical_dt,temp_old,temp_now,T_derivative,source; physical_dt = RP_Get_Real("physicaltimestep"); temp_old= C_T_M1(c,t); temp_now=C_T(c,t); T_derivative=(temp_nowtemp_old)/physical_dt; source = rho_b*wb*cb*tq*T_derivative; dS[eqn]=0; } In this code, the first source term is a gaussian heat source, while the second source term corresponds to the second term of the LHS of the following equation: However, the results are absolutely the same, with or without the second source term. Is there an error in the udf? Any advice would be appreciated. 

March 14, 2019, 10:52 

#2 
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26 
There is either an error in your physical equations, or in how you converted these equations to code, or the effect of the second term is really too small to see.
(Below, I assume you use SI units, but that's just for notation, the conclusion does not depend on it.) To estimate the magnitude of your first term, I look at r=0, so at the point (x,y)=(0.0125,0.0025) m. Things simplify with r=0, so your first term becomes 1E14 W/m3. To estimate the magnitude of your second term, just put in all the constants, and it is approximately 1E3*T_derivative. So for the two terms to be similar in size, T_derivative needs to be 1E11 K/s. That is a very high temperature change rate. If your temperature would increase one million kelvin per second (which is a lot), then your first term would still be 100000 times bigger. That is why you don't see any effect on the solution. 

March 14, 2019, 20:46 

#3 
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 
run your code with second source ONLY, check if it works
best regards 

March 15, 2019, 00:20 

#4 
Member
Saurabh Das
Join Date: Jul 2018
Posts: 43
Rep Power: 8 
I ran the simulation without the first source term, and unfortunately there seems to be no difference whatsoever. The thermal history, with or without the second source term is the same.


March 15, 2019, 04:18 

#5  
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 
from Ansys Fluent Customization Manual
Quote:
try simplified version of code first Code:
DEFINE_SOURCE(perfusion,c,t,dS,eqn) { real physical_dt,temp_now,T_derivative,source; physical_dt = RP_Get_Real("physicaltimestep"); temp_now=C_T(c,t); T_derivative=(temp_now)/physical_dt; source = rho_b*wb*cb*tq*T_derivative; dS[eqn]=0; } best regards 

March 18, 2019, 09:05 

#6 
Member
Saurabh Das
Join Date: Jul 2018
Posts: 43
Rep Power: 8 
This is not working. I remove the complicated temperature term,
Code:
DEFINE_SOURCE(perfusion,c,t,dS,eqn) { real physical_dt,temp_old,temp_now,T_derivative,source; physical_dt = RP_Get_Real("physicaltimestep"); //temp_old= C_T_M1(c,t); temp_now=C_T(c,t); T_derivative=(temp_now)/physical_dt; source = rho_b*wb*cb*tq*T_derivative; printf("\n %g",source); dS[eqn]=0; } However, if I include that value as the source term itself, then there's a change in the temperature profile.. This is very vexing. 

March 18, 2019, 21:21 

#7 
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 
there is no return line in code
Code:
return source; best regards 

March 19, 2019, 00:14 

#8 
Member
Saurabh Das
Join Date: Jul 2018
Posts: 43
Rep Power: 8 
Oh my goodness! Thank you, it's working!
I am so embarrassed right now.... 

Tags 
source terms, udf 
Thread Tools  Search this Thread 
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
[foamextend.org] Problems installing foamextend4.0 on openSUSE 42.2 and Ubuntu 16.04  ordinary  OpenFOAM Installation  19  September 3, 2019 18:13 
[Other] Adding solvers from DensityBasedTurbo to foamextend 3.0  Seroga  OpenFOAM Community Contributions  9  June 12, 2015 17:18 
[swak4Foam] funkySetFields compilation error  tayo  OpenFOAM Community Contributions  39  December 3, 2012 05:18 
OpenFOAM on MinGW crosscompiler hosted on Linux  allenzhao  OpenFOAM Installation  127  January 30, 2009 19:08 
DecomposePar links against liblamso0 with OpenMPI  jens_klostermann  OpenFOAM Bugs  11  June 28, 2007 17:51 