CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

Moving heat source term using Define-Source

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By snsd03090412

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 5, 2017, 06:04
Default Moving heat source term using Define-Source
  #1
New Member
 
魏志軒
Join Date: Apr 2017
Posts: 1
Rep Power: 0
snsd03090412 is on a distinguished road
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)
}
}
Attached Images
File Type: gif formula.gif (14.0 KB, 51 views)
File Type: jpg result.jpg (121.0 KB, 87 views)
rishitosh likes this.

Last edited by snsd03090412; May 5, 2017 at 07:10.
snsd03090412 is offline   Reply With Quote

Old   January 24, 2018, 11:50
Default
  #2
New Member
 
rishitosh's Avatar
 
Rishitosh Ranjan
Join Date: Dec 2012
Location: Trichirapalli, Tamilnadu, India
Posts: 22
Rep Power: 14
rishitosh is on a distinguished road
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.
rishitosh is offline   Reply With Quote

Old   January 25, 2018, 04:39
Default
  #3
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Quote:
Originally Posted by rishitosh View Post
a=b= 0.003;
This is not allowed. (Or it might technically be valid code, but will do something completely different then what you expect.)

I think you mean:
Code:
a=0.003;
b=0.003;
pakk is offline   Reply With Quote

Old   January 26, 2018, 14:11
Default
  #4
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 12
obscureed is on a distinguished road
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
obscureed is offline   Reply With Quote

Old   January 28, 2018, 13:44
Default
  #5
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
I stand corrected...
pakk is offline   Reply With Quote

Old   January 29, 2018, 05:22
Default
  #6
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
By the way: the "Fluent-way" of defining a variable for position is
Code:
real y[ND_ND];
ND_ND here means the number of dimensions. In this way, if you go to a two-dimensional case and are able to use the same code, it uses a tiny little bit less memory. In most cases not enough to be noticeable, but it might be a good habit to use it always.

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?
pakk is offline   Reply With Quote

Old   October 10, 2023, 03:22
Post Heat source moving problem
  #7
New Member
 
sumanta mondal
Join Date: Oct 2023
Posts: 1
Rep Power: 0
sumantam22 is on a distinguished road
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)
}
Attached Files
File Type: c gauss_2d_heat_flux.c (649 Bytes, 9 views)
sumantam22 is offline   Reply With Quote

Old   October 10, 2023, 05:49
Default
  #8
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
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
AlexanderZ is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 14:40.