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

Using parameter defined in one UDF into another UDF

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By pakk

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 13, 2021, 11:53
Default Using parameter defined in one UDF into another UDF
  #1
New Member
 
Jam
Join Date: Aug 2021
Posts: 15
Rep Power: 5
marijam is on a distinguished road
Hi,

I am writing 3 different udfs for calculating the concentration of 3 different species of mine. I also have a mass transfer coefficient in another UDF.
I need to use that mass transfer coefficient in one of the concentration UDFs.
I don't know how should I use a parameter that is defined in one UDF in another UDF.
I appreciate your help.

Thanks,
marijam is offline   Reply With Quote

Old   September 13, 2021, 14:35
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Write a function that calculates free mass transfer, and call that function in both macros.
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Old   September 14, 2021, 08:11
Default
  #3
New Member
 
Jam
Join Date: Aug 2021
Posts: 15
Rep Power: 5
marijam is on a distinguished road
Quote:
Originally Posted by pakk View Post
Write a function that calculates free mass transfer, and call that function in both macros.
Hi Pakk,

Thank you for your response. So my question is that how do I call the mass transfer in my source UDF? Should I use the name I chose for the mass transfer UDF in my source UDF? OR does fluen have a specified variable for kl (which I could not find any)? Do I need to add any thing in the beginning after #include udf.h?
I appreciate your help!
Thank you!
marijam is offline   Reply With Quote

Old   September 14, 2021, 14:56
Default
  #4
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
I did not say you should call the mass transfer function in your source UDF.

I mean you should write a separate function, and call that function in the mass transfer macro and in the source UDF.
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Old   September 21, 2021, 14:23
Default
  #5
New Member
 
Jam
Join Date: Aug 2021
Posts: 15
Rep Power: 5
marijam is on a distinguished road
Quote:
Originally Posted by pakk View Post
I did not say you should call the mass transfer function in your source UDF.

I mean you should write a separate function, and call that function in the mass transfer macro and in the source UDF.
Hello,

Sorry but I still do not know how I can do that.
So I have a multiphase system there is air as one phase and a mix of species in the liquid phase. mass transfer between gas and liquid is obtained from this UDF (I am not sure yet if it works)

#include "udf.h"

#define D_O2 1.97*pow(10,-9)
real m_lg;

DEFINE_MASS_TRANSFER(kl_my2, cell, thread, from_index, from_species_index, to_index, to_species_index)
{

cell_t c;

Thread *gas, *liq;
gas = THREAD_SUB_THREAD(thread, from_index);
liq = THREAD_SUB_THREAD(thread, to_index);
m_lg = 0.0;

m_lg = (0.4)*pow(D_O2,0.5)*pow(C_D(c,liq)*C_R(c,liq)/C_MU_EFF(c,liq), 0.25) ;

return (m_lg);
}

Then I have source codes for consumption or generation of two of my species:

/************************************************** *******************
UDF for specifying a volume reaction rate for a first order reaction.
************************************************** ********************/
#include "udf.h"

#define WRmax 0.67

#define KS 0.0004
#define KO 0.0004

DEFINE_SOURCE(BMsource,c,t,dS,eqn)
{
real BM, SUB, source;

BM = C_YI(c,t,0) * C_R(c,t); /*Biomass concentration*/

SUB = C_YI(c,t,1) * C_R(c,t); /*Substrate concentration*/


OXN = C_YI(c,t,2) * C_R(c,t)+kl*a*(0.08- C_YI(c,t,2) * C_R(c,t)); /*O2 concentration*

source = WRmax*(SUB/(SUB+KS)*BM)*(OXN/(OXN+KO)*BM); /*Source term*/

return source;

}

the part for O2 concentration I need to call the calculated kl which is from the UDF m_lg .

I do not know how to define it, do I need a UDM and how can I write it in my UDF?

I really appreciate your help.
marijam is offline   Reply With Quote

Old   September 22, 2021, 10:54
Default
  #6
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
A UDM can also work. Like this:

Code:
#include "udf.h"

#define D_O2 1.97e-9

DEFINE_MASS_TRANSFER(kl_my2, cell, thread, from_index, from_species_index, to_index, to_species_index)
{
 Thread *gas, *liq;
 gas = THREAD_SUB_THREAD(thread, from_index); /*isn't this from_species_index? species always confuse me */
 liq = THREAD_SUB_THREAD(thread, to_index);
 m_lg = (0.4)*pow(D_O2,0.5)*pow(C_D(cell,liq)*C_R(cell,liq)/C_MU_EFF(cell,liq), 0.25) ;
 UDMI(cell,thread,0)=m_lg;
 return (m_lg);
}

/************************************************** *******************
UDF for specifying a volume reaction rate for a first order reaction.
************************************************** ********************/

#define WRmax 0.67
#define KS 0.0004
#define KO 0.0004

DEFINE_SOURCE(BMsource,c,t,dS,eqn)
{
 real BM, SUB, source;
 BM = C_YI(c,t,0) * C_R(c,t); /*Biomass concentration*/
 SUB = C_YI(c,t,1) * C_R(c,t); /*Substrate concentration*/
 OXN = C_YI(c,t,2) * C_R(c,t)+UDMI(c,t,0)*a*(0.08- C_YI(c,t,2) * C_R(c,t)); /*O2 concentration*
 source = WRmax*(SUB/(SUB+KS)*BM)*(OXN/(OXN+KO)*BM); /*Source term*/
 return source;
}
Combine everything into one file, add one User Defined Memory location, and compile.
The code will not work yet because you multiply by "a" in OXN, and you never defined "a" and I have no idea what it should be.
marijam likes this.
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Old   September 22, 2021, 11:04
Default
  #7
New Member
 
Jam
Join Date: Aug 2021
Posts: 15
Rep Power: 5
marijam is on a distinguished road
Quote:
Originally Posted by pakk View Post
A UDM can also work. Like this:

Code:
#include "udf.h"

#define D_O2 1.97e-9

DEFINE_MASS_TRANSFER(kl_my2, cell, thread, from_index, from_species_index, to_index, to_species_index)
{
 Thread *gas, *liq;
 gas = THREAD_SUB_THREAD(thread, from_index); /*isn't this from_species_index? species always confuse me */
 liq = THREAD_SUB_THREAD(thread, to_index);
 m_lg = (0.4)*pow(D_O2,0.5)*pow(C_D(cell,liq)*C_R(cell,liq)/C_MU_EFF(cell,liq), 0.25) ;
 UDMI(cell,thread,0)=m_lg;
 return (m_lg);
}

/************************************************** *******************
UDF for specifying a volume reaction rate for a first order reaction.
************************************************** ********************/

#define WRmax 0.67
#define KS 0.0004
#define KO 0.0004

DEFINE_SOURCE(BMsource,c,t,dS,eqn)
{
 real BM, SUB, source;
 BM = C_YI(c,t,0) * C_R(c,t); /*Biomass concentration*/
 SUB = C_YI(c,t,1) * C_R(c,t); /*Substrate concentration*/
 OXN = C_YI(c,t,2) * C_R(c,t)+UDMI(c,t,0)*a*(0.08- C_YI(c,t,2) * C_R(c,t)); /*O2 concentration*
 source = WRmax*(SUB/(SUB+KS)*BM)*(OXN/(OXN+KO)*BM); /*Source term*/
 return source;
}
Combine everything into one file, add one User Defined Memory location, and compile.
The code will not work yet because you multiply by "a" in OXN, and you never defined "a" and I have no idea what it should be.
Thank you very much, I will try that.
marijam is offline   Reply With Quote

Old   November 18, 2021, 09:10
Default
  #8
New Member
 
Jam
Join Date: Aug 2021
Posts: 15
Rep Power: 5
marijam is on a distinguished road
Quote:
Originally Posted by pakk View Post
A UDM can also work. Like this:

Code:
#include "udf.h"

#define D_O2 1.97e-9

DEFINE_MASS_TRANSFER(kl_my2, cell, thread, from_index, from_species_index, to_index, to_species_index)
{
 Thread *gas, *liq;
 gas = THREAD_SUB_THREAD(thread, from_index); /*isn't this from_species_index? species always confuse me */
 liq = THREAD_SUB_THREAD(thread, to_index);
 m_lg = (0.4)*pow(D_O2,0.5)*pow(C_D(cell,liq)*C_R(cell,liq)/C_MU_EFF(cell,liq), 0.25) ;
 UDMI(cell,thread,0)=m_lg;
 return (m_lg);
}

/************************************************** *******************
UDF for specifying a volume reaction rate for a first order reaction.
************************************************** ********************/

#define WRmax 0.67
#define KS 0.0004
#define KO 0.0004

DEFINE_SOURCE(BMsource,c,t,dS,eqn)
{
 real BM, SUB, source;
 BM = C_YI(c,t,0) * C_R(c,t); /*Biomass concentration*/
 SUB = C_YI(c,t,1) * C_R(c,t); /*Substrate concentration*/
 OXN = C_YI(c,t,2) * C_R(c,t)+UDMI(c,t,0)*a*(0.08- C_YI(c,t,2) * C_R(c,t)); /*O2 concentration*
 source = WRmax*(SUB/(SUB+KS)*BM)*(OXN/(OXN+KO)*BM); /*Source term*/
 return source;
}
Combine everything into one file, add one User Defined Memory location, and compile.
The code will not work yet because you multiply by "a" in OXN, and you never defined "a" and I have no idea what it should be.
Hello,

I have another question related to the same code.
So here ''a'' is the interfacial area between gas and liquid. So in case I use a single bubble size in my model I can write the following code for the interfacial area and then store in another UDM and use it in the codes I mentioned above.

/************************************************** *******************
UDF for specifying interfacial area
************************************************** ********************/
#include "udf.h"

real area_intf;

DEFINE_EXCHANGE_PROPERTY(custom_ia,c,t,i,j)
{

/* i -- liquid-phase; j -- vapor-phase */

Thread **pt = THREAD_SUB_THREADS(t);

real diam = C_PHASE_DIAMETER(c, pt[j]);
real vof_i = C_VOF(c,pt[i]);
real vof_j = C_VOF(c,pt[j]);

area_intf = 6.*vof_j/diam;

C_UDMI(c,t,1)=area_intf;
return area_intf;
}


- I wanted to make sure if this is correct?, since I get 0 for data stored in C_UDMI(c,t,1).

-Also I wanted to see if anyone knows how do I define interfacial area when I am using interfacial area concentration model with a range of bubbles from 2mm to 1 cm?
Is there any specific macro defined for fluent that I can directly use? Or I need to find the interfacial area for different bubble categories? (sth similar to PBM) and what is the bubble size macro for the interfacial area concentration model?

Many thanks,
marijam 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
Is it possible to plot momentum source defined using UDF? CaptainCombo Fluent UDF and Scheme Programming 9 February 20, 2023 18:04
Scheme (or UDF) load Parameter value HHOS FLUENT 0 September 4, 2017 05:25
Using UDF to define parameter Oleg V. Fluent UDF and Scheme Programming 2 January 24, 2017 03:55
UDF error:strcpy has already been defined in the curren alinik FLUENT 0 November 2, 2016 21:17
Can I use UDF to input a parameter which is related to the result of last step? bagecy Fluent UDF and Scheme Programming 0 January 31, 2016 22:17


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