|
[Sponsors] |
September 27, 2023, 09:28 |
Struggling with if-else statement in UDF
|
#1 |
New Member
Mumin Biyiklioglu
Join Date: Sep 2023
Posts: 3
Rep Power: 2 |
Hi I am writing for udf pulsed laser source. But I got problem with changing the velocity(it needs to be 0 when heating and become 1 when waiting time). So I discrete my code understand that origin of problem. So I seperated if statement for source and velocity. If statement for source is working very well. But if statement for vel has a problem. The "else" part is working when condition met but for if part it uses the predefined(0.0) value.
Code:
#include "udf.h" DEFINE_SOURCE(Goldak7, cell, thread, dS, eqn) { real x[ND_ND]; real current_time; real LayerThickness = 0.00005; real LaserSpotRadii = 0.000075; real K = -3.0; real F = 0.6; real Q = 2000; real vel = 0.0; real x0 = 0.0; real PI = acos(-1); real KGoldak; real x_pos; real source; current_time = CURRENT_TIME; KGoldak = (6 * sqrt(3) * F * Q) / (LaserSpotRadii * LaserSpotRadii * LayerThickness * PI *sqrt(PI)); C_CENTROID(x, cell, thread); if ( current_time > 0.01) { vel = 0.99; } else { vel = 0.1; } x_pos = vel * current_time; if ( current_time > 0.01) { source = KGoldak*exp(K*(pow((x[0] - x_pos),2.)/pow(LaserSpotRadii,2.) + pow(x[1],2.)/pow(LaserSpotRadii,2.) + pow(x[2],2.) / pow(LayerThickness,2.))); dS[eqn] = 0.0; } else { source = KGoldak*exp(K*(pow((x[0] - x_pos),2.)/pow(LaserSpotRadii,2.) + pow(x[1],2.)/pow(LaserSpotRadii,2.) + pow(x[2],2.) / pow(LayerThickness,2.))); dS[eqn] = 0.0; } return source; } P.S; I notice while writing this post, I can use initial value like if condition value. But still I am wandering where is my mistake |
|
Tags |
ifelse, pulse, udf |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Call defined property by UDF to another UDF | Selawe97 | FLUENT | 0 | December 27, 2022 08:57 |
Understanding of contact detection UDF | Silence | Fluent UDF and Scheme Programming | 0 | June 10, 2021 04:30 |
Unable to use if statement in UDF | AGP | Fluent UDF and Scheme Programming | 22 | June 6, 2016 10:03 |
Opening a file and if statement before a DPM UDF | anthony05 | Fluent UDF and Scheme Programming | 4 | August 14, 2014 00:39 |
UDF "AND" Statement | Curtis | FLUENT | 1 | December 11, 2002 21:34 |