CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   Execute On Demand Error (https://www.cfd-online.com/Forums/fluent/237110-execute-demand-error.html)

Cooper24 July 1, 2021 02:13

Execute On Demand Error
 
I am new to UDF coding. I have written an UDF for adding a moving laser heat source in energy equation. I have written the following code:

#include "udf.h"
#include "sg_mphase.h"
#include "mem.h"
#include "sg_mem.h"
#include "math.h"
#include "flow.h"
#include "unsteady.h"

#define A 0.4 // Absorption coefficient
#define P 200 // Laser power
#define R 80e-6 // spot radius
#define v 0.1 // scan speed of laser
#define h 25 // Heat transfer coefficient
#define Ta 298 // Ambient air temperature
#define s 5.67e-8 // Stefan Boltzmann constant
#define e 0.5 // Emmisivity
#define Pi 3.1415926535
#define Ts 1658 // Solidus temperature
#define Tl 1723 // Liquidus temperature
#define x0 100e-6 // Initial x position of the laser
#define y0 0.0 // Intiial y position of the laser
#define domain_ID 3 // Domain ID of metal substrate


DEFINE_INIT(volume_fraction, mixture_domain)
{
int phase_domain_index = 1;
cell_t c;
Thread *t;
Domain *subdomain;
real xc[ND_ND];
sub_domain_loop(subdomain, mixture_domain, phase_domain_index)
{
if(DOMAIN_ID(subdomain) == 3)
thread_loop_c (t,subdomain)
{
begin_c_loop_all(c,t)
{
C_CENTROID(xc,c,t);
if(xc[0] > -0.5e-3 && xc[0] < 0.5e-3 && xc[1] > -0.25e-3 && xc[1] < 0.25e-3 && xc[2] < 0 && xc[2] > -0.3e-3)
C_VOF(c,t) = 1.0;
else
C_VOF(c,t) = 0.0;
}
end_c_loop_all(c,t)
}
}
}




DEFINE_ADJUST(adjust_gradient, domain)
{
Thread *t;
cell_t c;
domain = Get_Domain(domain_ID);

thread_loop_c(t, domain)
{
begin_c_loop(c,t)
{
C_UDSI(c,t,0) = C_VOF(c,t);
}
end_c_loop(c,t)
}
}

DEFINE_ON_DEMAND(store_gradient)
{
Domain *domain;
cell_t c;
Thread *t;
domain = Get_Domain(domain_ID);

thread_loop_c(t, domain)
{
begin_c_loop(c,t)
{
C_UDMI(c,t,0) = NV_MAG(C_UDSI_G(c,t,0));
}
end_c_loop(c,t)
}
}



DEFINE_SOURCE(heat_source, c, t, dS, eqn) // The name of the UDF is heat_source
{
real source;
real x[ND_ND], time;
time = RP_Get_Real("flow-time");
C_CENTROID(x, c, t);
real T = C_T(c,t);


if(C_VOF(c,t)>0.05 && C_VOF(c,t)<1)
{
source = (((2*A*P)/(Pi*R*R))*exp((-2*(pow(x[0]-x0-v*time,2.0) + pow(x[1]-y0,2.0)))/(R*R)) - h*(T-Ta) - s*e*(pow(T,4) - pow(Ta,4)))*C_UDMI(c,t,0);
dS[eqn] = 0.0;
}
else
{
source = 0.0;
dS[eqn] = 0.0;
}
return source;
}
The UDF compiles without any error. When I am trying to hook the functions, DEFINE_ADJUST and DEFINE_INIT are hooked without any error. When I try to hook DEFINE_ON_DEMAND using Execute on demand, FLUENT crashes with error: Node X: Process YYYY: Received Signal SIGSEGV.
The number of messages is same as the number of processors I am using, which is 6. I am not receiving any error related to MPI.

Please someone help!!


All times are GMT -4. The time now is 02:32.