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

Erros hooking UDF for recirculation flow

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By AlexanderZ
  • 1 Post By AlexanderZ

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 17, 2021, 14:33
Post Erros hooking UDF for recirculation flow
  #1
New Member
 
Gregori
Join Date: Nov 2018
Location: Uberlândia - Minas Gerais, Brazil
Posts: 8
Rep Power: 7
greg93 is on a distinguished road
Hi everyone,

I'm writing a UDF to simulate the recirculation flow effect of species in a tubular reactor. This UDF also computes the dilution effect in the tank before the reactor. This UDF is compiled with no errors, however, when I try to hook this UDF in the species mass fraction boundary box I got the message below. I've tried to correct it in many ways by reading the Ansys Customization Manual and forums but with no success. Could anybody help me to find out what is the problem with my code? (attached)

I would really appreciate any tips or help, this is an important step in my thesis.

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

Node 0: Process 6096: Received signal SIGSEGV.

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

Node 6: Process 14268: Received signal SIGSEGV.

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

Code:
#include "udf.h"
#define ST 2.98
#define zone_ID1 8
#define zone_ID2 7

  face_t f;
  real Ain[ND_ND];
  real Aout[ND_ND];
  real area_in = 0;
  real area_out = 0;
  real initial_mfracBACT = 2.17e-07;
  real sum_mfracBACT_in = 0.;
  real sum_mfracBACT_out = 0;
  real mfracBACT_in;
  real mfracBACT_out;

DEFINE_PROFILE(inlet_mfracBACT,t,i)
{
  Domain *domain = Get_Domain(1);
  Thread *outletthread = Lookup_Thread(domain,zone_ID2);
  Thread *inletthread = Lookup_Thread(domain,zone_ID1);

if(N_TIME < 1)
{
  F_PROFILE(f,t,i)= initial_mfracBACT;
}
/* -------------------------------------------------------------*/
else
{
begin_f_loop(f,outletthread)
{
  F_AREA(Aout,f,outletthread);
  area_out += NV_MAG(Aout);
  sum_mfracBACT_out += F_YI(f,outletthread,4)*NV_MAG(Aout);/*In the species list BACT is in the 4th position*/
}
end_f_loop(f,outletthread)

mfracBACT_out = sum_mfracBACT_out/area_out;
/* --------------------------------------------------------------*/
begin_f_loop(f,inletthread)
{
  F_AREA(Ain,f,inletthread);
  area_in += NV_MAG(Ain);
  sum_mfracBACT_in += F_YI(f,inletthread,4)*NV_MAG(Ain);
}
end_f_loop(f,inletthread)

mfracBACT_in = sum_mfracBACT_in/area_in;
/* ---------------------------------------------------------------*/

begin_f_loop(f,inletthread) /*recirculation effect with dilution effect >> Inletmassfraction-specie1 at every time step= (Outletmassfraction-specie1* time step (s)+ ST*Inletmassfraction-specie1)/(time step (s) *ST)*/
{
   F_PROFILE(f,t,i) = (F_YI(f, outletthread, 4)*CURRENT_TIMESTEP+ST*F_YI(f, inletthread, 4))/(CURRENT_TIMESTEP+ST);
}
end_f_loop(f,inletthread)
}
}
Attached Files
File Type: c UDF_recirculation_effect_BACT_alternativa2.c (1.6 KB, 4 views)
greg93 is offline   Reply With Quote

Old   April 18, 2021, 23:09
Default
  #2
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
I think the problem comes from F_YI species mass fraction macro
are you sure that number is 4 ? counting starts from 0

you can initialize case first, then load UDF, not sure that information about mass fraction is available before initialization

since fluent v201 you should make your code suitable for parallel computation, few minor changes:
Code:
#include "udf.h"
#define ST 2.98
#define zone_ID1 8
#define zone_ID2 7

  face_t f;
  real Ain[ND_ND];
  real Aout[ND_ND];
  real area_in = 0;
  real area_out = 0;
  real initial_mfracBACT = 2.17e-07;
  real sum_mfracBACT_in = 0.;
  real sum_mfracBACT_out = 0;
  real mfracBACT_in;
  real mfracBACT_out;

DEFINE_PROFILE(inlet_mfracBACT,t,i)
{
  Domain *domain = Get_Domain(1);
  Thread *outletthread = Lookup_Thread(domain,zone_ID2);
  Thread *inletthread = Lookup_Thread(domain,zone_ID1);

if(N_TIME < 1)
{
  F_PROFILE(f,t,i)= initial_mfracBACT;
}
/* -------------------------------------------------------------*/
else
{
begin_f_loop(f,outletthread)
{
  F_AREA(Aout,f,outletthread);
  area_out += NV_MAG(Aout);
  sum_mfracBACT_out += F_YI(f,outletthread,4)*NV_MAG(Aout);/*In the species list BACT is in the 4th position*/
}
end_f_loop(f,outletthread)
#if RP_NODE
	area_out = PRF_GRSUM1(area_out);
	sum_mfracBACT_out = PRF_GRSUM1(sum_mfracBACT_out);
#endif
mfracBACT_out = sum_mfracBACT_out/area_out;
/* --------------------------------------------------------------*/
begin_f_loop(f,inletthread)
{
  F_AREA(Ain,f,inletthread);
  area_in += NV_MAG(Ain);
  sum_mfracBACT_in += F_YI(f,inletthread,4)*NV_MAG(Ain);
}
end_f_loop(f,inletthread)
#if RP_NODE
	area_in = PRF_GRSUM1(area_in);
	sum_mfracBACT_in = PRF_GRSUM1(sum_mfracBACT_in);
#endif
mfracBACT_in = sum_mfracBACT_in/area_in;
/* ---------------------------------------------------------------*/

begin_f_loop(f,inletthread) /*recirculation effect with dilution effect >> Inletmassfraction-specie1 at every time step= (Outletmassfraction-specie1* time step (s)+ ST*Inletmassfraction-specie1)/(time step (s) *ST)*/
{
   F_PROFILE(f,t,i) = (F_YI(f, outletthread, 4)*CURRENT_TIMESTEP+ST*F_YI(f, inletthread, 4))/(CURRENT_TIMESTEP+ST);
}
end_f_loop(f,inletthread)
}
}
greg93 likes this.
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   April 19, 2021, 07:55
Default
  #3
New Member
 
Gregori
Join Date: Nov 2018
Location: Uberlândia - Minas Gerais, Brazil
Posts: 8
Rep Power: 7
greg93 is on a distinguished road
Dear AlexanderZ,

Thank you very much for taking the time to analyze my code. I'm sure that the index of the Bact species is correct because there are more species involved in the reactions and they are listed starting from 0. I need to recirculate all species, but I'm using this udf to verify the suitability of the code and then I'll copy the code for the other species and make the appropriate changes for each one.
I've tried to load the udf with your suggestions before and after initializing, and also after steady simulation, but with no success. The same errors are displayed. Before initialization, the errors appear by clicking initialize, and after initialization and steady simulation, the errors appear by hooking the udf in the inlet boundary.
greg93 is offline   Reply With Quote

Old   April 20, 2021, 00:38
Default
  #4
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
to localize the problem try to change F_YI to any constant value, compile and apply. Is problem gone?

do you use multiphase model? in that case may be it is issue with domain definition:
The value of domain_id is always 1 for the mixture domain.

read mode in Ansys Fluent Customization manual -> Domain Pointer
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   April 20, 2021, 14:08
Default
  #5
New Member
 
Gregori
Join Date: Nov 2018
Location: Uberlândia - Minas Gerais, Brazil
Posts: 8
Rep Power: 7
greg93 is on a distinguished road
Dear AlexanderZ,

I've made some changes in the UDF based on a thread that I found in this forum. Now the code looks like this. It is working only when I load the case in serial mode, which is already awesome since I can get some results. However, I'm trying to make it applicable also to parallel mode, using the code lines that you suggested above, but it's not working. I'm reading the customization manual and I hope to get some results in parallel mode.
Quote:
#include "udf.h"

DEFINE_PROFILE(species_profile, t, i)
{
/* Declare variables */
face_t f, c;
Thread *outletthread;
Thread *inletthread;
real Ain[ND_ND], Aout[ND_ND], areain=0, areaout=0, sumspeciein=0, sumspecieout=0, ST=2.98, specieout, speciein;
Domain *domain;

domain = Get_Domain(1); /* Returns fluid domain pointer (1 = Mixture) */

outletthread = Lookup_Thread(domain, 7); /* Here put the number of the outlet thread. */
inletthread = Lookup_Thread(domain, 8);/* Here put the number of the inlet thread. */
/*--------------------------------------------------------------------*/
begin_f_loop(f, outletthread)
{
/* Loop through faces of your outlet */
F_AREA(Aout, f, outletthread); /* make A the the face vector */
areaout += NV_MAG(Aout);
sumspecieout += F_YI(f, outletthread, 7) * NV_MAG(Aout);
}
end_f_loop(f, outletthread);

specieout = sumspecieout / areaout; /* specie becomes the average specie */
/*--------------------------------------------------------------------*/
begin_f_loop(f, inletthread)
{
/* Loop through faces of your outlet */
F_AREA(Ain, f, inletthread); /* make A the the face vector */
areain += NV_MAG(Ain);
sumspeciein += F_YI(f, inletthread, 7) * NV_MAG(Ain);
}
end_f_loop(f, inletthread);

speciein = sumspeciein / areain; /* specie becomes the average specie */
/*--------------------------------------------------------------------*/
begin_f_loop(c, t)
{
F_PROFILE(c, t, i) = (specieout*CURRENT_TIMESTEP+ST*speciein)/(CURRENT_TIMESTEP+ST);
}
end_f_loop(c, t);
}
greg93 is offline   Reply With Quote

Old   April 20, 2021, 22:21
Default
  #6
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
not sure how it could work in serial either parallel

why did you add loop over cell at the end of the code?
are you trying to define boundary condition (apply to face) or source (apply to zone)? In case of BC you want to have loop over faces.

to have a loop over face you use
Code:
begin_f_loop(f, t)
{}
end_f_loop(f, t);
to have a loop over cell
Code:
begin_c_loop(c, t)
{}
end_c_loop(c, t);
choose one of them

Code:
#include "udf.h"

DEFINE_PROFILE(species_profile, t, i)
{
/* Declare variables */
face_t f, c;
Thread *outletthread;
Thread *inletthread;
real Ain[ND_ND], Aout[ND_ND], areain=0, areaout=0, sumspeciein=0, sumspecieout=0, ST=2.98, specieout, speciein;
Domain *domain;

domain = Get_Domain(1); /* Returns fluid domain pointer (1 = Mixture) */

outletthread = Lookup_Thread(domain, 7); /* Here put the number of the outlet thread. */
inletthread = Lookup_Thread(domain, 8);/* Here put the number of the inlet thread. */
/*--------------------------------------------------------------------*/
begin_f_loop(f, outletthread)
{
/* Loop through faces of your outlet */
F_AREA(Aout, f, outletthread); /* make A the the face vector */
areaout += NV_MAG(Aout);
sumspecieout += F_YI(f, outletthread, 7) * NV_MAG(Aout);
}
end_f_loop(f, outletthread);
#if RP_NODE
	areaout = PRF_GRSUM1(areaout);
	sumspecieout = PRF_GRSUM1(sumspecieout);
#endif
specieout = sumspecieout / areaout; /* specie becomes the average specie */
/*--------------------------------------------------------------------*/
begin_f_loop(f, inletthread)
{
/* Loop through faces of your outlet */
F_AREA(Ain, f, inletthread); /* make A the the face vector */
areain += NV_MAG(Ain);
sumspeciein += F_YI(f, inletthread, 7) * NV_MAG(Ain);
}
end_f_loop(f, inletthread);
#if RP_NODE
	areain = PRF_GRSUM1(areain);
	sumspeciein = PRF_GRSUM1(sumspeciein);
#endif
speciein = sumspeciein / areain; /* specie becomes the average specie */
/*--------------------------------------------------------------------*/
begin_c_loop(c, t)
{
F_PROFILE(c, t, i) = (specieout*CURRENT_TIMESTEP+ST*speciein)/(CURRENT_TIMESTEP+ST);
}
end_c_loop(c, t);
}
greg93 likes this.
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   April 26, 2021, 14:01
Default
  #7
New Member
 
Gregori
Join Date: Nov 2018
Location: Uberlândia - Minas Gerais, Brazil
Posts: 8
Rep Power: 7
greg93 is on a distinguished road
Dear AlexanderZ,

Indeed the last loop should be over face. Thank you for noting this, I fixed this issue. I'm still working on the UDF trying to make it work in parallel. For serial it is working very well =).
greg93 is offline   Reply With Quote

Old   April 26, 2021, 22:33
Default
  #8
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
the code I've shared above is ready for parallel
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Reply

Tags
mass fraction, recirculation, species, udf


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
UDF bug, for reversing flow direction and magnitude EngGhost Fluent UDF and Scheme Programming 12 April 20, 2020 07:50
How to run multiple cycle pulsetile flow simulation in Ansys fluent using UDF code? Md Al Amin Sheikh Fluent UDF and Scheme Programming 4 January 28, 2020 11:55
volume flow rate for outlet boundry condition and dfine udf for it raminostadi FLUENT 0 December 24, 2016 01:52
UDF for 3D turbulent fully developed flow howhs Fluent UDF and Scheme Programming 0 August 1, 2013 11:47
UDF for transient pressure inlet, mass flow check at nozzle exit and volumetric heat kokoory FLUENT 0 August 17, 2011 02:07


All times are GMT -4. The time now is 16:29.