|
[Sponsors] |
May 5, 2017, 06:04 |
Moving heat source term using Define-Source
|
#1 |
New Member
魏志軒
Join Date: Apr 2017
Posts: 1
Rep Power: 0 |
Hi! Gus. I am working on the simulation of selective laser melting for time dependent heat source term in DEFINE_SOURCE Macros. I want to simulate one track situation to know the distribution of temperature. My volumetric heat source formula is as follows . The size of substrate is 0.5m*0.5m*0.3 m. The initial laser xyz position ( 0.01 m, 0.03 m, 0.028 m) move to the final position ( 0.04 m, 0.03 m, 0.028 m) as time goes by. But, after I interpret my udf, the result shows floating point exception. I don't know why it doesn't work, can any of you guys give me some suggestions?
#include "udf.h" DEFINE_SOURCE(gaussian_heat_flux,c,t,dS,eqn) { float A = 0; real x[3]; real se; real s=0.000006; real source; // heat flux real d=0.000006; real p = 450; // laser power real n = 0.45; // process efficiency; real a = 0.0015; // deposition half width real b = 0.0009; // melt pool depth real cc = 0.0015; // longitudinal ellipsoid axis c. real FF = 1; // scaling factor real vel = 0.01; // laser beam velocity real time; // time real x_coor; // x_coordinates real y_coor; // y_coordinates real z_coor; // z_coordinates real x_ini = 0.01; // x_ini real y_ini = 0.03; // y_ini real z_ini = 0.028; // z_ini real absorp = 0.4; // absorptivity of ss316 real circle = 3.14; // PI real emis; // emissivity real sigma = 0.0000000567; // stefan-boltzmann real Tinf = 300.0; // environment temp real coeff_h; // heat transfer coefficient real dummy; // dummy variable time = RP_Get_Real("flow-time"); C_CENTROID(x,c,t); x_coor = x[0]; y_coor = x[1]; z_coor = x[2]; if (vel*time<=0.04) { dummy = 3 * pow((x_coor - x_ini - vel*time), 2) / pow(a, 2) + 3 * pow((y_coor - y_ini), 2) / pow(b, 2) + 3 * (z_coor - z_ini ) / pow(cc, 2); se = (6 * pow(3, 0.5)*p*n*FF) / (a*b*cc*circle*pow(circle, 0.5)); source = se*exp(-dummy); dS[eqn] = 0.0; return source; } else { source = 0; dS[eqn] = 0; }} DEFINE_PROPERTY(ss316_density, c, t) { real rho_lam; real temp = C_T(c, t); if (temp <= 1658) { rho_lam = -0.5212*temp + 8126.4; } else if (temp>1658 && temp <= 1723) { rho_lam = -5.9702*temp + 17161; } else if (temp > 1723) { rho_lam = -0.7653*temp + 8192.8; } return rho_lam; } DEFINE_PROPERTY(ss316_conductivity, c, t) { real rho_lam; real temp = C_T(c, t); if (temp <= 1658) { rho_lam = 0.0141*temp + 10.665; } else if (temp>1658 && temp <= 1723) { rho_lam = -0.0855*temp + 175.88; } else if (temp > 1723) { rho_lam = 0.0143*temp + 3.8433; } return rho_lam; } DEFINE_INIT(initial, d) { cell_t c; Thread *t; /* loop over all cell threads in the domain */ thread_loop_c(t, d) { /* loop over all cells */ begin_c_loop_all(c, t) { C_T(c, t) = 300.0; } end_c_loop_all(c, t) } } Last edited by snsd03090412; May 5, 2017 at 07:10. |
|
January 24, 2018, 11:50 |
|
#2 |
New Member
Rishitosh Ranjan
Join Date: Dec 2012
Location: Trichirapalli, Tamilnadu, India
Posts: 22
Rep Power: 14 |
hey snsd03090412!!
did u solve the problem?? I am trying solve similar kind of problem.. using your idea... #include "udf.h" #include "metric.h" #include "math.h" #define P 7000 /*peak power of laser*/ DEFINE_SOURCE(gaussian_heat_flux,c,t,dS,eqn) { real x[2]; real Q, a1, b, time, vel,dt; real x1, x2, y[2]; a=b= 0.003; time = RP_Get_Real("flow-time"); vel = 1e-3; C_CENTROID(y,c,t); x1 = y[0]; /*xmax=0.0005 ans xmin=-0.0005*/ x2 = y[1]; /*ymax=0 and ymin=-.0003*/ if (vel*time<=0.005) { Q=(3 * P / (M_PI*a1*b))*exp(- (3 * pow(x1-vel*time, 2) / pow(a1, 2)) - (3 * pow(x2, 2) / pow(b, 2))); dS[eqn] = 0.0; return Q; } else { return 0; dS[eqn] = 0; } } but its is not wrking well... can you help in this regard.. thank you. |
|
January 25, 2018, 04:39 |
|
#3 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
||
January 26, 2018, 14:11 |
|
#4 |
Senior Member
Join Date: Sep 2017
Posts: 246
Rep Power: 12 |
I do not agree with you on this, Pakk -- that looks like perfectly valid C to me, and it should do the same as the two-line alternative that you propose. See https://en.wikipedia.org/wiki/Operat...ment_operators
There is a problem that variable "a" is not declared in either case -- I don't know why, but the variables are "a1" and "b". It surprises me that this file gets through the compiler without errors. A serious error is that size-3 arrays need to be declared as "real y[3];", for example, so that y[0], y[1] and y[2] are available. (It seems not to matter for x[2], since x is not used.) A (possibly benign, possibly dangerous) error is that no value is returned in the "else" branch. I would advise you to check the equation for Q -- there is nothing clearly wrong, but... there seem to be some significantly different lengthscales in operation (0.3m to 0.0003m), which is possible; the factors of 3 are surprising (for a standard definition of widths "a1" and "b"); and the laser appears to be centred on 0.0 for the y-coordinate "x2". (It looks possible that exp(XXX) could evaluated for some large negative values of XXX -- I would hope that these would safely underflow to zero.) Ed |
|
January 28, 2018, 13:44 |
|
#5 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
I stand corrected...
|
|
January 29, 2018, 05:22 |
|
#6 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
By the way: the "Fluent-way" of defining a variable for position is
Code:
real y[ND_ND]; And although the "y[2]" part is definitely wrong in this code, I don't see how it could lead to a floating point exception... Are you compiling or interpreting? |
|
October 10, 2023, 03:22 |
Heat source moving problem
|
#7 |
New Member
sumanta mondal
Join Date: Oct 2023
Posts: 1
Rep Power: 0 |
Hi everyone,
I have written the UDF for moving gaussian heat source and after compiling it into fluent my temperature profile is not changing with position. Can anybody please guide me!!!! #include "udf.h" DEFINE_PROFILE(gauss2D_heat_flux, thread, position) { real x[ND_ND]; face_t f; real current_time; real Q = 250; real PI = acos(-1); real vel = 1e-3; real r = 0.002; real B = -3; real A; real d; real dt; real x_pos; current_time = CURRENT_TIME; dt = CURRENT_TIMESTEP; A = (2 * Q) / (PI * pow(r, 2.)); begin_f_loop(f, thread) { F_CENTROID(x, f, thread); x_pos = vel * current_time; F_PROFILE(f, thread, position) = A * exp(B * (pow((x[0] - x_pos), 2.) + pow(x[1], 2.)) / pow(r, 2.)); } end_f_loop(f, thread) } |
|
October 10, 2023, 05:49 |
|
#8 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
code seems to be correct,
compile, load udf, hook profile as a source, check units (for length)
__________________
best regards ****************************** press LIKE if this message was helpful |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[swak4Foam] swak4Foam-groovyBC build problem | zxj160 | OpenFOAM Community Contributions | 18 | July 30, 2013 14:14 |
Free surface boudary conditions with SOLA-VOF | Fan | Main CFD Forum | 10 | September 9, 2006 13:24 |
UDF Scalar Code: HT 1 | Greg Perkins | FLUENT | 8 | October 20, 2000 13:40 |
UDFs for Scalar Eqn - Fluid/Solid HT | Greg Perkins | FLUENT | 0 | October 14, 2000 00:03 |
UDFs for Scalar Eqn - Fluid/Solid HT | Greg Perkins | FLUENT | 0 | October 11, 2000 04:43 |