CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   UDF for energy source (https://www.cfd-online.com/Forums/fluent-udf/178006-udf-energy-source.html)

dexter September 26, 2016 20:17

UDF for energy source
 
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...

Bruno Machado September 27, 2016 05:11

Quote:

Originally Posted by dexter (Post 619349)
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.

dexter September 27, 2016 06:03

UDF for energy source
 
Quote:

Originally Posted by Bruno Machado (Post 619400)
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;
}

Bruno Machado September 27, 2016 06:35

Quote:

Originally Posted by dexter (Post 619404)
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).

dexter September 27, 2016 09:07

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).

Bruno Machado September 27, 2016 11:53

Quote:

Originally Posted by dexter (Post 619421)
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...

dexter September 28, 2016 05:47

Quote:

Originally Posted by Bruno Machado (Post 619442)
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"?

Bruno Machado September 30, 2016 04:52

Quote:

Originally Posted by dexter (Post 619572)
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.


All times are GMT -4. The time now is 13:53.