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

UDF for energy source

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 26, 2016, 21:17
Default UDF for energy source
  #1
New Member
 
Nitesh Kumar
Join Date: May 2016
Posts: 17
Rep Power: 10
dexter is on a distinguished road
Hello everyone,
I am writing UDF for energy source.I need to retrieve subdomain for primary ans secondary phase using THREAD_SUB_THREAD.
I have gone through UDF manual but i,m having some problem in implementation part. Can someone help me?

Thanks a lot...
dexter is offline   Reply With Quote

Old   September 27, 2016, 06:11
Default
  #2
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 13
Bruno Machado is on a distinguished road
Quote:
Originally Posted by dexter View Post
Hello everyone,
I am writing UDF for energy source.I need to retrieve subdomain for primary ans secondary phase using THREAD_SUB_THREAD.
I have gone through UDF manual but i,m having some problem in implementation part. Can someone help me?

Thanks a lot...
share what you've done and we can see possible faults.
Bruno Machado is offline   Reply With Quote

Old   September 27, 2016, 07:03
Default UDF for energy source
  #3
New Member
 
Nitesh Kumar
Join Date: May 2016
Posts: 17
Rep Power: 10
dexter is on a distinguished road
Quote:
Originally Posted by Bruno Machado View Post
share what you've done and we can see possible faults.

Thanks for reply..


#include "udf.h"
#define LH 2250.0
#define T_SAT 373.15
DEFINE_SOURCE(eng_eqn,cell,thread,dS,eqn)
{
real x[ND_ND];
real con, source;
begin_c_loop_all(cell,thread)
{
C_CENTROID(x,cell,thread);
Thread *thread, *thread;
thread = THREAD_SUB_THREAD(cell,thread);
thread = THREAD_SUB_THREAD(cell,thread);
if (C_T(cell, thread) > T_SAT)
{
con = -0.1*C_VOF(cell,thread)*C_R(cell,thread)*((C_T(cell ,thread)-T_SAT)/T_SAT)*x[1];
source = con*LH;
}
else if (C_T(cell, thread) < T_SAT)
{
con = 0.1*C_VOF(cell,thread)*C_R(cell,thread)*((T_SAT-C_T(cell,thread))/T_SAT)*x[1];
source = con*LH;
}
}
end_c_loop_all(cell,thread)
dS[eqn] =0.1*C_VOF(cell,thread)*C_R(cell,thread)/T_SAT;
return source;
}
dexter is offline   Reply With Quote

Old   September 27, 2016, 07:35
Default
  #4
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 13
Bruno Machado is on a distinguished road
Quote:
Originally Posted by dexter View Post
Thanks for reply..


#include "udf.h"
#define LH 2250.0
#define T_SAT 373.15
DEFINE_SOURCE(eng_eqn,cell,thread,dS,eqn)
{
real x[ND_ND];
real con, source;
begin_c_loop_all(cell,thread)
{
C_CENTROID(x,cell,thread);
Thread *thread, *thread;
thread = THREAD_SUB_THREAD(cell,thread);
thread = THREAD_SUB_THREAD(cell,thread);
if (C_T(cell, thread) > T_SAT)
{
con = -0.1*C_VOF(cell,thread)*C_R(cell,thread)*((C_T(cell ,thread)-T_SAT)/T_SAT)*x[1];
source = con*LH;
}
else if (C_T(cell, thread) < T_SAT)
{
con = 0.1*C_VOF(cell,thread)*C_R(cell,thread)*((T_SAT-C_T(cell,thread))/T_SAT)*x[1];
source = con*LH;
}
}
end_c_loop_all(cell,thread)
dS[eqn] =0.1*C_VOF(cell,thread)*C_R(cell,thread)/T_SAT;
return source;
}
Have a look in this website https://www.sharcnet.ca/Software/Flu...udf/node99.htm

Search for the Phase-Level Thread Pointer ( THREAD_SUB_THREAD). You will see that it defines for the primary phase as 0, but you can also define other fazes as different integers.

In addition to that, you are also pointing and defining thread 2 times (and this value is already retrieved from the source macro).
Bruno Machado is offline   Reply With Quote

Old   September 27, 2016, 10:07
Default
  #5
New Member
 
Nitesh Kumar
Join Date: May 2016
Posts: 17
Rep Power: 10
dexter is on a distinguished road
i have modified it as:


#include "udf.h"
#define LH 2250.0
#define T_SAT 373.15
DEFINE_SOURCE(eng_source,cell,thread,dS,eqn)
{
real x[ND_ND];
real con, source;
cell_t gas, liq;
begin_c_loop_all(cell,thread)
{
C_CENTROID(x,cell,thread);

liq = THREAD_SUB_THREAD(liq,0);
gas = THREAD_SUB_THREAD(gas,1);
if (C_T(cell, liq) > T_SAT)
{
con = -0.1*C_VOF(cell,liq)*C_R(cell,liq)*((C_T(cell,liq)-T_SAT)/T_SAT)*x[1];
source = con*LH;
}
else if (C_T(cell, gas) < T_SAT)
{
con = 0.1*C_VOF(cell,gas)*C_R(cell,gas)*((T_SAT-C_T(cell,gas))/T_SAT)*x[1];
source = con*LH;
}
}
end_c_loop_all(cell,thread)
dS[eqn] =0.1*C_VOF(cell,thread)*C_R(cell,thread)/T_SAT;
return source;
}


But, after i interpret it at the first iteration it shows error as
Error: received a fatal signal (Segmentation fault).
dexter is offline   Reply With Quote

Old   September 27, 2016, 12:53
Default
  #6
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 13
Bruno Machado is on a distinguished road
Quote:
Originally Posted by dexter View Post
i have modified it as:


#include "udf.h"
#define LH 2250.0
#define T_SAT 373.15
DEFINE_SOURCE(eng_source,cell,thread,dS,eqn)
{
real x[ND_ND];
real con, source;
cell_t gas, liq;
begin_c_loop_all(cell,thread)
{
C_CENTROID(x,cell,thread);

liq = THREAD_SUB_THREAD(liq,0);
gas = THREAD_SUB_THREAD(gas,1);
if (C_T(cell, liq) > T_SAT)
{
con = -0.1*C_VOF(cell,liq)*C_R(cell,liq)*((C_T(cell,liq)-T_SAT)/T_SAT)*x[1];
source = con*LH;
}
else if (C_T(cell, gas) < T_SAT)
{
con = 0.1*C_VOF(cell,gas)*C_R(cell,gas)*((T_SAT-C_T(cell,gas))/T_SAT)*x[1];
source = con*LH;
}
}
end_c_loop_all(cell,thread)
dS[eqn] =0.1*C_VOF(cell,thread)*C_R(cell,thread)/T_SAT;
return source;
}


But, after i interpret it at the first iteration it shows error as
Error: received a fatal signal (Segmentation fault).
you are defining "gas" and "liq" as cells and later defining it as sub threads...
Bruno Machado is offline   Reply With Quote

Old   September 28, 2016, 06:47
Default
  #7
New Member
 
Nitesh Kumar
Join Date: May 2016
Posts: 17
Rep Power: 10
dexter is on a distinguished road
Quote:
Originally Posted by Bruno Machado View Post
you are defining "gas" and "liq" as cells and later defining it as sub threads...

Ohh..
Thank you. You have been very helpful.
I've also written a mass transfer udf. Would you please give it a look?

#include "udf.h"

DEFINE_MASS_TRANSFER(liq_gas_source, cell, thread, from_index,from_species_index,to_index, to_species_index)
{
real m_lg;
real T_SAT = 373.15;
Thread *gas, *liq;
gas = THREAD_SUB_THREAD(thread, from_index);
liq = THREAD_SUB_THREAD(thread, to_index);
m_lg = 0.0;
if (C_T(cell, liq) > T_SAT)
{
m_lg = -0.1*C_VOF(cell,liq)*C_R(cell,liq)*(C_T(cell,liq)-T_SAT)/T_SAT; /* Evaporating*/
}
else if (C_T(cell, gas) < T_SAT)
{
m_lg = 0.1*C_VOF(cell,gas)*C_R(cell,gas)*(T_SAT-C_T(cell,gas))/T_SAT; /* Condensing */
}
return (m_lg);
}


Do i need to use #include "sg_mphase.h"?
dexter is offline   Reply With Quote

Old   September 30, 2016, 05:52
Default
  #8
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 13
Bruno Machado is on a distinguished road
Quote:
Originally Posted by dexter View Post
Ohh..
Thank you. You have been very helpful.
I've also written a mass transfer udf. Would you please give it a look?

#include "udf.h"

DEFINE_MASS_TRANSFER(liq_gas_source, cell, thread, from_index,from_species_index,to_index, to_species_index)
{
real m_lg;
real T_SAT = 373.15;
Thread *gas, *liq;
gas = THREAD_SUB_THREAD(thread, from_index);
liq = THREAD_SUB_THREAD(thread, to_index);
m_lg = 0.0;
if (C_T(cell, liq) > T_SAT)
{
m_lg = -0.1*C_VOF(cell,liq)*C_R(cell,liq)*(C_T(cell,liq)-T_SAT)/T_SAT; /* Evaporating*/
}
else if (C_T(cell, gas) < T_SAT)
{
m_lg = 0.1*C_VOF(cell,gas)*C_R(cell,gas)*(T_SAT-C_T(cell,gas))/T_SAT; /* Condensing */
}
return (m_lg);
}


Do i need to use #include "sg_mphase.h"?
i cant check all udfs by just looking it. you need to try it on you pc, see if it returns any error, or if the values it is returning are the ones you are expecting.

about the sg_mpahse.h library, i do not know.check the udf.h and see either it is already included or not in it.
Bruno Machado 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
HELP! adding a mass source to VOF eqn. by UDF??? ROOZBEH FLUENT 5 December 3, 2016 18:53
[Other] How to use finite area method in official OpenFOAM 2.2.0? Detian Liu OpenFOAM Meshing & Mesh Conversion 4 November 3, 2015 04:04
[Other] Adding solvers from DensityBasedTurbo to foam-extend 3.0 Seroga OpenFOAM Community Contributions 9 June 12, 2015 18:18
[swak4Foam] Swak4FOAM 0.2.3 / OF2.2.x installation error FerdiFuchs OpenFOAM Community Contributions 27 April 16, 2014 16:14
UDF Scalar Code: HT 1 Greg Perkins FLUENT 8 October 20, 2000 13:40


All times are GMT -4. The time now is 21:22.