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

UDMI and DEFINE_EXECUTE_AT_END

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes
  • 3 Post By obscureed

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 1, 2018, 09:52
Question UDMI and DEFINE_EXECUTE_AT_END
  #1
New Member
 
Hoang Nhu Quynh
Join Date: Jul 2016
Posts: 6
Rep Power: 10
MsRuby is on a distinguished road
Dear all,

I am quite new with UDF so I am here to seek for some advice. Much appreciated if someone can tell me what is basic problem with my code.

Basically, I am writing an UDF to update the properties of a porous zone, then use these variables to calculate the mass source for a transient case. I use:
1. DEFINE_INIT to set the initial values of three variables: density, volatile fraction and formation rate of volatile, save them in three UDMI (0,1,2).
2. DEFINE_ADJUST to calculate the mass loss due to the reaction rate of volatile, then recalculate the density and volatile fraction. Two new variables are saved in two other UDMI (4,5)
3. DEFINE_SOURCE to calculate the formation rate of volatile, I save this varabile in one UDMI (3)
4. DEFINE_EXECUTE_AT_END, I set the UDMI (0,1,2) to UDMI (4,5,3) so that in the next time step (t+deltat), step 2 and 3 can use the new input of density, volatile fraction, and product formation rate.

The code works very well with DEFINE_INIT, DEFINE_ADJUST, DEFINE_SOURCE, but when I hook up DEFINE_EXECUTE_AT_END, this error occurs (this time I use interpretation because of some software issues)

================================================== ============================

Node 0: Process 9976: Received signal SIGSEGV.

================================================== ============================
MPI Application rank 0 exited before MPI_Finalize() with status 2
The fl process could not be started.

Below you can find my code:

#include "udf.h"

/* input */

DEFINE_INIT(udm,d)
{
Thread *t;
cell_t c;
thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
C_UDMI(c,t,0)=625.0; /*density (initial)*/
C_UDMI(c,t,1)=0.74; /*vol_fraction (initial)*/
C_UDMI(c,t,2)=0.0; /*rate of reaction*/
C_UDMI(c,t,3)=0.0;
C_UDMI(c,t,4)=0.0;
C_UDMI(c,t,5)=0.0;
}
end_c_loop(c,t)
}

/* calculate the rate of reaction */
DEFINE_SOURCE(vol_release,c,t,dS,eqn)
{
const real a=1.63e5, e=9.04e4;
real rho, vol_frac;
real k,source;
rho=C_UDMI(c,t,0);
vol_frac=C_UDMI(c,t,1);
k=a*exp(-e/8.314/C_T(c,t));
source=k*vol_frac*rho;
dS[eqn]=rho*vol_frac;
C_UDMI(c,t,3)=source;
return source;
}
/* re-calculate density and vol_fraction */
DEFINE_ADJUST(properties,d)
{
Thread *t;
cell_t c;
real delta_t=CURRENT_TIMESTEP;
thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
real rho,rate,vol_frac;
real mass_0, mass_1, mass_vol, mass_loss;
/* data from the previous time step */
rho=C_UDMI(c,t,0);
vol_frac=C_UDMI(c,t,1);
mass_0=rho*C_VOLUME(c,t);
rate=C_UDMI(c,t,2);
/*calculate data for this time step */
mass_vol=mass_0*vol_frac;
mass_loss=rate*delta_t*C_VOLUME(c,t);
mass_1=mass_0-mass_loss;

/*recaculate the density and vol fraction*/
C_UDMI(c,t,4)=mass_1/C_VOLUME(c,t); /*density*/
C_UDMI(c,t,5)=(mass_vol-mass_loss)/mass_1; /*volatile fraction */
}
end_c_loop(c,t)
}
}

DEFINE_EXECUTE_AT_END(execute_at_end) /* only at the end of time step */
{
Domain *d;
Thread *t;
cell_t c;
thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
C_UDMI(c,t,0)=C_UDMI(c,t,4); /* 0,1,2 is input for next step, 3,4,5 is for this step */
C_UDMI(c,t,1)=C_UDMI(c,t,5);
C_UDMI(c,t,2)=C_UDMI(c,t,3);
}
end_c_loop(c,t)
}
}
MsRuby is offline   Reply With Quote

Old   July 1, 2018, 18:55
Default
  #2
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 12
obscureed is on a distinguished road
Hi MsRuby,

The domain pointer is never given a value in the DEFINE_EXECUTE_AT_END. You need
Code:
domain = Get_Domain (1);
I haven't checked anything else in detail -- at first sight, it all looks OK.

I temporarily worried that your user-defined reaction will occur every iteration (in DEFINE_ADJUST) -- but it operates on the previous timestep every time, so I think it's OK. Calculating it only once in DEFINE_EXECUTE_AT_END seems like a possible idea.

Good luck!
Ed
MsRuby, Papes and KozlovN1 like this.
obscureed is offline   Reply With Quote

Old   July 2, 2018, 03:43
Default
  #3
New Member
 
Hoang Nhu Quynh
Join Date: Jul 2016
Posts: 6
Rep Power: 10
MsRuby is on a distinguished road
Quote:
Originally Posted by obscureed View Post
Hi MsRuby,

The domain pointer is never given a value in the DEFINE_EXECUTE_AT_END. You need
Code:
domain = Get_Domain (1);
I haven't checked anything else in detail -- at first sight, it all looks OK.

I temporarily worried that your user-defined reaction will occur every iteration (in DEFINE_ADJUST) -- but it operates on the previous timestep every time, so I think it's OK. Calculating it only once in DEFINE_EXECUTE_AT_END seems like a possible idea.

Good luck!
Ed
Thank you Ed, the problem is solved nicely
MsRuby 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
udmi question, is it possible to hold memory when mesh or cas file changes? ssavi22 Fluent UDF and Scheme Programming 2 May 26, 2016 20:10
Running out of UDMI, what can in use to replace it ? Sdvk Fluent UDF and Scheme Programming 0 May 23, 2014 14:16
problems with UDMI... !!! Nady FLUENT 0 May 16, 2007 03:38
Problem with Dissipation rate storage in UDMI Sam FLUENT 0 January 26, 2006 06:19
UDMI error when memorizing Dissipation of TKE Lohen FLUENT 0 June 23, 2005 10:59


All times are GMT -4. The time now is 19:01.