CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   CFD Freelancers (https://www.cfd-online.com/Forums/cfd-freelancers/)
-   -   Define_source macro fluent udf (https://www.cfd-online.com/Forums/cfd-freelancers/190603-define_source-macro-fluent-udf.html)

Shehryar July 18, 2017 01:28

Define_source macro fluent udf
 
Hello experts!

Hope you are all fine. i am in need to take guidance regarding a small UDF which i wrote to add a source term. Actually i am working on transient Multiphase Eulerian model with one primary phase and one secondary phae. i have deactivated built in gravity and want to introduce a source term in y-momentum equation of secondary phase. Here is my UDF for the said purpose

#include "udf.h"


DEFINE_SOURCE(gravity_source,c,t,dS,eqn)
{
real gravity;
real source;
real density;
Thread *subthread;
subthread=THREAD_SUB_THREAD(t,1);
gravity = 9.8;
density=1000.0;
source = gravity*density*C_VOF(c,subthread);
dS[eqn] = 0.0;
return source;
}

that is, source=gravity x density x volume fraction of secondary phase.


but when i interpret/compile it with FLUENT i receive "Segmentation fault" error due to the presence of term "C_VOF(c,subthread)"
i run my UDF without this term and it runs fine. but i have to use this term to extract the volume fraction in the cell.

if you know where i am at fault please let me know, much appreciated.
Thanks in anticipation.

Micael October 29, 2017 06:25

This should have been posted in FLUENT UDF forum.

I think your DEFINE_SOURCE is passing the primary phase thread and not the mixture one so that THREAD_SUB_THREAD is not doing what you expect.

Code:

#include "udf.h"

DEFINE_SOURCE(gravity_source,c,t,dS,eqn)
{
  real gravity, source, density;
  Thread *tm, *ts;  /* mixture and secondary thread */

  tm = THREAD_SUPER_THREAD(t);  /* get mixture thread */
  ts = THREAD_SUB_THREAD(tm,1); /* get secondary thread */

  gravity = 9.8;
  density=1000.0;
  source = gravity*density*C_VOF(c,ts);
  dS[eqn] = 0.0;

  return source;
}



All times are GMT -4. The time now is 15:50.