UDF with 2 source terms

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

 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("flow-time"); 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 < 6e-5) 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("physical-time-step"); temp_old= C_T_M1(c,t); temp_now=C_T(c,t); T_derivative=(temp_now-temp_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:
 Important Note that data from C_T_M1 is available only if user-defined scalars are defined. It can also be used with adaptive time stepping.
I've never used this macro so I don't know what exactly does it mean "if user-defined scalars are defined"

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("physical-time-step");
temp_now=C_T(c,t);
T_derivative=(temp_now)/physical_dt;

source = rho_b*wb*cb*tq*T_derivative;
dS[eqn]=0;
}```
it should work, if not, than check setting of your model

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("physical-time-step"); //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; }``` On the console, the value is shown to be -1.59e7, but stiill no change whatsoever to the temperature profile. 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;` add it best regards pakk likes this.

 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