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

Multiphase UDF coding

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By `e`
  • 1 Post By `e`

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 15, 2016, 14:34
Question Multiphase UDF coding
  #1
New Member
 
Abhinay Iyer
Join Date: May 2015
Posts: 11
Rep Power: 11
abhinayiyer2408 is on a distinguished road
Hi Everyone,

I'm working on a Multiphase Evaporation Modeling and I use Fluent 6.3.26 which doesn't have any inbuilt Evaporation Models. I've wrote a couple of programs to model species transport as a User Defined Scalar since I need some freedom on using the gradient of this UDS in my Mass Transfer UDF.

I have two questions regarding this.

1] My Species Transport equation contains only a Diffusivity Term in terms of the temperature. When I write the code for a single-phase flow, the diffusivity term gets complied and runs successfully. But the code that I've written for Multiphase, I get an ACCESS_VIOLATION error during Initialization. The Code is shown below;

DEFINE_DIFFUSIVITY(Species_Diff,c,t,i)
{
Domain *mix_d=Get_Domain(1); /* To obtain domain pointer of the mixture phase*/
real Diff, xc[ND_ND];
real pi=3.14, k=1.38e-23, dia=4e-10;
int zone=3; /* Liquid Zone */
Thread *mix_t=Lookup_Thread(mix_d,zone); /* Liquid thread lookup */

if (C_VOF(c,mix_t) == 1) /* If the Volume fraction is = 1 */
{
C_CENTROID(xc,c,mix_t);
Diff = C_R(c,mix_t)*k*C_T(c,mix_t)/(3.0*pi*C_MU_EFF(c,mix_t)*dia); /* Diffusivity Term */
}
return Diff;
}

I've added the header file. So, the problem is not that. I feel my problem is in the "if statement" that I've provided. Is there any other way to provide the "if statement" ?

2] Do I have to provide 2 different diffusivity term to access both the phases or can it be included in one?

Apart from this, I have a question regarding MASS_TRANSFER() syntax.

Do we have to provide an "if statement" and "loop" for this to access only the interface or does the argument "Thread" in the MASS_TRANSFER() access only the interface?
abhinayiyer2408 is offline   Reply With Quote

Old   March 16, 2016, 16:40
Default
  #2
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
You've used the Lookup_Thread function instead of the phase-level thread pointer (THREAD_SUB_THREAD). Have a read of the multiphase macros in the UDF manual and you should be able to restrict your diffusion equations according to the phase using conditional if statements.
cdegroot likes this.
`e` is offline   Reply With Quote

Old   March 17, 2016, 02:19
Default
  #3
New Member
 
Abhinay Iyer
Join Date: May 2015
Posts: 11
Rep Power: 11
abhinayiyer2408 is on a distinguished road
Hi 'e'. Thanks for the early reply.

I've solved the problem. Thanks a lot for your help. Now I face another problem. I'm using the gradient of this UDS to call into the Interaction Phase. I get an error saying that Fluent is unable to locate the UDS file that I have specified. I don't know why. Can you please help me out with it?
abhinayiyer2408 is offline   Reply With Quote

Old   March 17, 2016, 04:13
Default
  #4
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
The user-defined scalar (UDS) transport equations shouldn't require a separate file, what exactly is the error message?
`e` is offline   Reply With Quote

Old   March 18, 2016, 01:44
Default
  #5
New Member
 
Abhinay Iyer
Join Date: May 2015
Posts: 11
Rep Power: 11
abhinayiyer2408 is on a distinguished road
Hi e,

The exact error I'm getting is "Mass_Transfer_Trial.obj : error LNK2019: unresolved external symbol _C_UDS0_G referenced in function _mass_transfer
libudf.dll : fatal error LNK1120: 1 unresolved externals"
.

I have compiled 2 UDFs. One which has the Diffusivity Term for the UDS and the other which is my interface boundary condition. When I compile both together or separately, I get this error. My Code is written below.

FILE 1 :

#include "udf.h"

DEFINE_DIFFUSIVITY(Liq_Species_Transfer,c,t,i)
{
real Diff, pi=3.14, dia=4.0e-10, k=1.38e-23;

Diff = C_R(c,t)*k*C_T(c,t)/(3.0*pi*C_MU_EFF(c,t)*dia);

return Diff;
}

FILE 2:

#include "udf.h"

DEFINE_EXCHANGE_PROPERTY(mass_transfer,c,t,i,j)
{
real m_dot_grad=0.0;
real T_c = 647.0, T_sa = 298.18, H_sa = 2257.0, mw = 18.0152, ma = 28.996;
real V_s,C_s,h_fg,p_ratio,conc,temp_interface,term1_1,t erm1_2,term_1,term2_1,term_2,term3_1,term_3;

temp_interface = C_T(c,t);
term1_1 = (H_sa/UNIVERSAL_GAS_CONSTANT);
term1_2 = ((temp_interface-T_sa)/(temp_interface*T_sa));
term_1 = term1_1*term1_2;
term2_1 = log(temp_interface/T_sa);
term_2 = 0.38*term2_1/T_c;
term3_1 = temp_interface-T_sa;
term_3 = 0.118*term3_1/(T_c*T_c);
p_ratio = (exp(term_1-term_2-term_3));
C_s = 1.0/(1.0+((ma/mw)*(1.0/p_ratio)-1.0));
conc = C_UDS0_G(c,t,i);
V_s = 2.88e-5*conc/(1.0-C_s);
m_dot_grad += V_s*C_R(c,t);

return m_dot_grad;
}

When I debug the code, I found out the problem is in the line where I define my conc term. Without that term, my program simulates. Please help me out with this.
abhinayiyer2408 is offline   Reply With Quote

Old   March 18, 2016, 02:53
Default
  #6
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
The syntax for the UDS gradient is C_UDSI_G(c,t,i) where i is an index of the scalar; not "C_UDS0_G(c,t,i)". You've also used the same variable as an argument for the "second_column_phase_index". Have a read of these sections in the UDF manual for details.
`e` is offline   Reply With Quote

Old   March 19, 2016, 05:31
Unhappy
  #7
New Member
 
Abhinay Iyer
Join Date: May 2015
Posts: 11
Rep Power: 11
abhinayiyer2408 is on a distinguished road
Hi 'e',

Thanks a lot for your reply and suggestions. I've done the changes that you advised. I tried running the program, but during compilation I get an error like
"..\..\src\Mass_Transfer_Trial.c(20) : error C2440: '=' : cannot convert from 'real *' to 'real' ". I don't know what this error means. I've tried searching about this on different forums but never got any useful answer. Can you please help me out. The program is given below.

#include "udf.h"
#include "sg_mphase.h"

DEFINE_MASS_TRANSFER(mass_transfer,c,t,i,j,n,m)
{
real m_dot_grad=0.0;
real T_c = 647.0, T_sa = 298.18, H_sa = 2257.0, mw = 18.0152, ma = 28.996;
real V_s,C_s,h_fg,p_ratio,conc,temp_interface,term1_1,t erm1_2,term_1,term2_1,term_2,term3_1,term_3;

temp_interface = C_T(c,t);
term1_1 = (H_sa/UNIVERSAL_GAS_CONSTANT);
term1_2 = ((temp_interface-T_sa)/(temp_interface*T_sa));
term_1 = term1_1*term1_2;
term2_1 = log(temp_interface/T_sa);
term_2 = 0.38*term2_1/T_c;
term3_1 = temp_interface-T_sa;
term_3 = 0.118*term3_1/(T_c*T_c);
p_ratio = (exp(term_1-term_2-term_3));
C_s = 1.0/(1.0+((ma/mw)*(1.0/p_ratio)-1.0));
conc = C_UDSI_G(c,t,0);
V_s = 2.88e-5*conc/(1.0-C_s);
m_dot_grad += C_VOF(c,t)*V_s*C_R(c,t);
return m_dot_grad;
}
abhinayiyer2408 is offline   Reply With Quote

Old   March 19, 2016, 20:36
Default
  #8
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
The C_UDSI_G macro returns the gradient of the UDS in each direction (vector quantity represented with an array). An example in the UDF manual calculates the magnitude of this gradient with NV_MAG, but you could use the components if that's what you're after.
`e` is offline   Reply With Quote

Old   March 20, 2016, 02:15
Red face
  #9
New Member
 
Abhinay Iyer
Join Date: May 2015
Posts: 11
Rep Power: 11
abhinayiyer2408 is on a distinguished road
Hi 'e',

Yes, I need the y-component of the gradient at the interface thread alone. What is the macros for obtaining the y-component gradient ? UDF Manual doesn't provide these information properly. It is very brief and very easy to lose track. Again, Thank you so much for the help.
abhinayiyer2408 is offline   Reply With Quote

Old   March 20, 2016, 02:56
Default
  #10
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
The syntax should follow the other gradient macros (C_U_G for example); then the y-component would be: C_UDSI_G(c,t,0)[1] (the 1 corresponds to the y-direction, 0 would be for x and 2 for z).
abhinayiyer2408 likes this.
`e` is offline   Reply With Quote

Old   March 22, 2016, 13:34
Default
  #11
New Member
 
Abhinay Iyer
Join Date: May 2015
Posts: 11
Rep Power: 11
abhinayiyer2408 is on a distinguished road
Hi 'e',

I tried the one you said, but when I use that I get "ACCESS_VIOLATION" error for both coordinate specified gradient and NV_MAG of the gradient. Is there any other way to use the gradient of a UDS function? Can we add the gradient as another UDS and use that UDS in the expression?
abhinayiyer2408 is offline   Reply With Quote

Old   March 22, 2016, 16:50
Default
  #12
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Have you enabled the user-defined scalars? This won't be the cause if you're only getting errors with the gradient macro, and not the normal UDS macro.

There are reported issues with using the gradient on the first time step because the gradient hasn't been calculated for this first step. This problem is not only for UDS, but for other variables as well. Have a read of this thread for details and a solution for UDS gradients.
`e` is offline   Reply With Quote

Old   March 24, 2016, 00:23
Default
  #13
New Member
 
Abhinay Iyer
Join Date: May 2015
Posts: 11
Rep Power: 11
abhinayiyer2408 is on a distinguished road
I have enabled the user-defined scalars. Since I'm working on a multi-phase problem, I'm using 2 UDS for both phases separately and the number UDS matches the condition.

I'm using a steady state model so there should not be any issue with time steps. Just in case, I've used a User-Defined Memory location in my main program which saves the gradient of the UDS. I run the program for 5 iterations and later hook the gradient term on to the solution. Even after that, I get an ACCESS_VIOLATION error when I start to iterate. Does the User-Defined Scalar Gradients have these kind of problems?
abhinayiyer2408 is offline   Reply With Quote

Old   March 24, 2016, 08:32
Default
  #14
New Member
 
Abhinay Iyer
Join Date: May 2015
Posts: 11
Rep Power: 11
abhinayiyer2408 is on a distinguished road
Hi 'e'

Let me explain you the problem statement. Probably you could help me doing it in a different way.

A thin-film is flowing inside a channel along the wall at a prescribed velocity. Air flows adjacent to it at a higher velocity compared to the liquid. The wall of this channel is heated just below the boiling point of the liquid so that it evaporates. I have formulated heat and mass transfer equations at the interface. My aim is to track the liquid-gas interface.

I've attached an image of the problem that I want to solve. Here, I know the initial thickness of the liquid film but I don't know the profile of it. The profile depends on mass transfer at the interface. The equation of mass transfer is as shown in the image.

I tried using Species Transport equation directly and calling the y-direction species transport gradient in my Mass-Transfer UDF. I get an ACCESS_VIOLATION error due to that. I can only call the species transport but not the gradient. So I decided to write a diffusivity UDF for the species transport for both the phases separately and call the gradient of this UDS. When I do that, the solution never converges. But, the fluid starts to evaporate from the inlet point and at the end, the fluid stays as it is. The UDF for my mass transfer is given in the attachment. Now, I don't know where I've gone wrong or what mistake I commit. Please help me out.
Attached Images
File Type: jpg image.jpg (43.8 KB, 46 views)
Attached Files
File Type: c Mass_Transfer_Trial.c (820 Bytes, 68 views)
abhinayiyer2408 is offline   Reply With Quote

Reply

Tags
fluent - udf, fluent 6.3.26, udf and programming


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 problem in multiphase boundary condition abolfazl364 FLUENT 1 April 5, 2015 22:38
Udf mass transfer multiphase access violation majid_kamyab Fluent UDF and Scheme Programming 17 September 26, 2014 09:24
help UDF for multiphase turbulence doronzo Fluent UDF and Scheme Programming 3 March 2, 2012 22:40
UDF problem in multiphase abolfazl364 Fluent UDF and Scheme Programming 0 February 6, 2012 12:20
Multiphase Eulerian & UDF HP FLUENT 0 August 24, 2006 12:58


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