TAGGED: udf
-
-
March 31, 2023 at 5:37 pm
Salil P
SubscriberHello,I am trying to simulate the Selective Laser Melting process at the mesoscale using Ansys Fluent. When writing the source term, I need to multiply it by the magnitude of the volume fraction gradient at the interface. For this, I have written the UDF given below where I store the magnitude of the volume fraction gradient in a C_UDMI using DEFINE_ADJUST and then call it in the DEFINE_SOURCE macros and assign it to the variable vf_g. If I don't call the C_UDMI in the DEFINE_SOURCE term the simulation runs without any issue and I can also visualize the C_UDMI in the contour plots, however, when I call it in DEFINE_SOURCE to multiply it with the source term, fluent simply crashes. Any errors that can be seen here? I have had the same issue regardless of the thread C_UDMI(c,t,0) wherein both the mixture domain thread and the phase thread result in fluent crashing#include#include#include#include//#include#include#include#include#define PI 3.1415926535#define domain_ID 3DEFINE_ADJUST(adjust_gradient, domain){Thread *t;cell_t c;face_t f;domain = Get_Domain(domain_ID);/* Fill UDS with the variable. */thread_loop_c (t,domain){begin_c_loop (c,t){C_UDSI(c,t,0) = C_VOF(c,t);}end_c_loop (c,t)}thread_loop_f (t,domain){if (THREAD_STORAGE(t,SV_UDS_I(0))!=NULL)begin_f_loop (f,t){F_UDSI(f,t,0) = F_VOF(f,t);}end_f_loop (f,t)}domain=Get_Domain(1);/* Fill the UDM with magnitude of gradient. */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(surface_laser,c,t,dS,eqn){real current_time=CURRENT_TIME;Thread *tp;//parametersreal r=35e-6; // 100 micronreal P=50.0; //PowerDomain *subdomain;int phase_domain_index;real v_d=0.12;real source;real eta=0.5;//start posreal xs=1.5e-5+current_time*v_d;real ys=6e-5;// cell paramtersreal x[ND_ND];real T;real Q;real Sb;real x1;real y1;real z1;real vf;real I_z;real H_s; //real gamma; // liq fractionreal h; // HT coefreal T_a;real n_fact; // normalizing factorreal Cpg;real Cpl;real Cpm;real Cps;real Cp; // avg cell specific heatreal rho; // avg cell densityreal rhog; // density of argon gasreal rhos; // solid densityreal rhol; // liquid densityreal rhom; // mixture densityreal vf_g; //magnitude of volume fraction gradientreal s=15e-6;Sb=5.67e-8;h=25;T_a=298;C_CENTROID(x,c,t);x1=x[0];y1=x[1];z1=x[2]-5e-5+1.25e-6;tp = THREAD_SUB_THREAD(t,1);vf=C_VOF(c,tp); // get cell volume fractionT = C_T(c,tp); // get cell temperaturegamma = C_LIQF(c,tp);// cell liquid fraction//Get the volume fraction gradient magnitudevf_g=C_UDMI(c,tp,0);//calculate mixture specific heatCpg=520.64;Cps=462.656+0.1338*T;Cpl=790;Cpm=Cpl*gamma+Cps*(1-gamma);Cp=Cpm*vf+Cpg*(1-vf);// calculate mixture densityrhog=1.6228;rhos=8000.0-800.0/1385.0*(T-273);rhol=6900.0-900.0/1277.0*(T-1723);rhom=rhol*gamma+rhos*(1-gamma);rho = vf*rhom + rhog*(1-vf);// calculate stabilizing factorn_fact=(2*rho*Cp)/(rhom*Cpm + rhog*Cpg);Q=0.23*P/(PI*r*r) * exp(-2*(pow(x1-xs,2)+pow(y1-ys,2))/pow(r,2));source=0;dS[eqn]=0;if(vf>0.05 && vf<1){source= (Q-h*(T-T_a)-Sb*0.5*(pow(T,4)-pow(T_a,4)))*n_fact*vf_g;dS[eqn]=(-h-Sb*2*pow(C_T(c,tp),3))*n_fact*vf_g;}return source;} -
April 6, 2023 at 11:26 am
Keyur Kanade
Ansys EmployeeAs support we do not debug UDFs. But can provide help on particular syntex. Please check following link for details of UDF. Also if you have any subsequent questions, please post it on Ansys Forum Ansys Learning Forum under specific category.
Chapter 1: Overview of User-Defined Functions (UDFs) (ansys.com)
Regards,
Keyur
How to access Ansys Online Help Document
Guidelines on the Student Community
Fluids Engineering Courses | Ansys Innovation Courses
-
- You must be logged in to reply to this topic.

Boost Ansys Fluent Simulations with AWS
Computational Fluid Dynamics (CFD) helps engineers design products in which the flow of fluid components is a significant challenge. These different use cases often require large complex models to solve on a traditional workstation. Click here to join this event to learn how to leverage Ansys Fluids on the cloud, thanks to Ansys Gateway powered by AWS.

Earth Rescue – An Ansys Online Series
The climate crisis is here. But so is the human ingenuity to fight it. Earth Rescue reveals what visionary companies are doing today to engineer radical new ideas in the fight against climate change. Click here to watch the first episode.

Ansys Blog
Subscribe to the Ansys Blog to get great new content about the power of simulation delivered right to your email on a weekly basis. With content from Ansys experts, partners and customers you will learn about product development advances, thought leadership and trends and tips to better use Ansys tools. Sign up here.
- Suppress Fluent to open with GUI while performing in journal file
- Floating point exception in Fluent
- What are the differences between CFX and Fluent?
- Heat transfer coefficient
- Getting graph and tabular data from result in workbench mechanical
- Difference between K-epsilon and K-omega Turbulence Model
- The solver failed with a non-zero exit code of : 2
- Time Step Size and Courant Number
- Mesh Interfaces in ANSYS FLUENT
- error: Received signal SIGSEGV
-
5268
-
3299
-
2469
-
1308
-
998
© 2023 Copyright ANSYS, Inc. All rights reserved.