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

DEFINE_SOURCE to cells near wall

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 18, 2020, 08:37
Default DEFINE_SOURCE to cells near wall
  #1
Senior Member
 
Arun raj.S
Join Date: Jul 2011
Posts: 194
Rep Power: 14
arunraj is on a distinguished road
Hello everyone, the below UDF works fine. However, the unit of mass flux is kg/m3s. However, the unit I have incorporate for mass flux is kg/s. May i know how to incorporate volume of the wall into the UDF to ensure proper unit. When I divide by C_VOLUME(c,t), my UDF is not working.

#include "udf.h"
int boundaryID1=78;
int boundaryID2=80;
int boundaryID3=82;
int boundaryID4=79;
int boundaryID5=81;
int boundaryID6=83;
int boundaryID7=76;
int boundaryID8=84;
int boundaryID9=86;
int boundaryID10=77;
int boundaryID11=85;
int boundaryID12=87;

DEFINE_INIT(initialize, d)
{
Thread *t;
cell_t c;
face_t f;
thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
C_UDMI(c,t,0) = 0;
}
end_c_loop(c,t)
}
}
DEFINE_SOURCE(mass_source,c,t,dS,eqn)
{
return C_UDMI(c,t,0);
}
DEFINE_ON_DEMAND(on_demand_calc)
{
face_t f;
cell_t c;
Domain *domain=Get_Domain(1);
Thread *t;
thread_loop_c(t,domain)
{
begin_c_loop(c,t)
{
C_UDMI(c,t,0)=0;
}
end_c_loop(c,t)
}
thread_loop_f(t,domain)
{
if (THREAD_ID(t)==boundaryID1)
{
begin_f_loop(f,t)
{
C_UDMI(F_C0(f,t),THREAD_T0(t),0)=4.23729E-05;
}
end_f_loop(f,t)
}
}
thread_loop_f(t,domain)
{
if (THREAD_ID(t)==boundaryID2)
{
begin_f_loop(f,t)
{
C_UDMI(F_C0(f,t),THREAD_T0(t),0)=0.0;
}
end_f_loop(f,t)
}
}
thread_loop_f(t,domain)
{
if (THREAD_ID(t)==boundaryID3)
{
begin_f_loop(f,t)
{
C_UDMI(F_C0(f,t),THREAD_T0(t),0)=-4.23729E-05;
}
end_f_loop(f,t)
}
}
thread_loop_f(t,domain)
{
if (THREAD_ID(t)==boundaryID4)
{
begin_f_loop(f,t)
{
C_UDMI(F_C0(f,t),THREAD_T0(t),0)=4.23729E-05;
}
end_f_loop(f,t)
}
}
thread_loop_f(t,domain)
{
if (THREAD_ID(t)==boundaryID5)
{
begin_f_loop(f,t)
{
C_UDMI(F_C0(f,t),THREAD_T0(t),0)=0.0;
}
end_f_loop(f,t)
}
}
thread_loop_f(t,domain)
{
if (THREAD_ID(t)==boundaryID6)
{
begin_f_loop(f,t)
{
C_UDMI(F_C0(f,t),THREAD_T0(t),0)=-4.23729E-05;
}
end_f_loop(f,t)
}
}
thread_loop_f(t,domain)
{
if (THREAD_ID(t)==boundaryID7)
{
begin_f_loop(f,t)
{
C_UDMI(F_C0(f,t),THREAD_T0(t),0)=4.23729E-05;
}
end_f_loop(f,t)
}
}
thread_loop_f(t,domain)
{
if (THREAD_ID(t)==boundaryID8)
{
begin_f_loop(f,t)
{
C_UDMI(F_C0(f,t),THREAD_T0(t),0)=0.0;
}
end_f_loop(f,t)
}
}
thread_loop_f(t,domain)
{
if (THREAD_ID(t)==boundaryID9)
{
begin_f_loop(f,t)
{
C_UDMI(F_C0(f,t),THREAD_T0(t),0)=-4.23729E-05;
}
end_f_loop(f,t)
}
}
thread_loop_f(t,domain)
{
if (THREAD_ID(t)==boundaryID10)
{
begin_f_loop(f,t)
{
C_UDMI(F_C0(f,t),THREAD_T0(t),0)=4.23729E-05;
}
end_f_loop(f,t)
}
}
thread_loop_f(t,domain)
{
if (THREAD_ID(t)==boundaryID11)
{
begin_f_loop(f,t)
{
C_UDMI(F_C0(f,t),THREAD_T0(t),0)=0.0;
}
end_f_loop(f,t)
}
}
thread_loop_f(t,domain)
{
if (THREAD_ID(t)==boundaryID12)
{
begin_f_loop(f,t)
{
C_UDMI(F_C0(f,t),THREAD_T0(t),0)=-4.23729E-05;
}
end_f_loop(f,t)
}
}
}
arunraj is offline   Reply With Quote

Old   June 18, 2020, 12:36
Default Source
  #2
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
I suppose by mass flux you mean mass source. Source should always be volumetric because Fluent multiplies the value provided as input with the volume of the cell. If you do not divide by the cell volume, then the actual source would be much smaller than the one being returned by UDF. You don't really need DEFINE_INIT since you are repeating the process in DEFINE_ON_DEMAND.

And what do you mean by not working? Does it not compile or give run-time error or does it not converge?

Furthermore, you should not loop over threads so many times. This is quite expensive. Use thread_loop_f only once with switch and case.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   June 19, 2020, 00:21
Default
  #3
Senior Member
 
Arun raj.S
Join Date: Jul 2011
Posts: 194
Rep Power: 14
arunraj is on a distinguished road
Dear vinerm,
Thank you for the suggestion and effort. I think I am successful now. Actually, I need to run few iterations and then hook up the UDF. its working.

Last edited by arunraj; June 19, 2020 at 02:05.
arunraj is offline   Reply With Quote

Old   June 20, 2020, 09:19
Default
  #4
Senior Member
 
Arun raj.S
Join Date: Jul 2011
Posts: 194
Rep Power: 14
arunraj is on a distinguished road
Hi vinerm;

Could you please where should i divide cell volume in the UDF ? Should i divide by C_VOLUME(c0,t0). My mass source seems very small. I divide by C_VOLUME(c,t) in DEFINE_SOURCE part. But source term seems so small.
arunraj is offline   Reply With Quote

Old   June 20, 2020, 11:21
Default Source Term
  #5
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
Divide C_UDMI by C_VOLUME(c, t) within DEFINE_SOURCE. Also note that mass source should always be accompanied by sources for other fields, such as, momentum, turbulence, energy, etc.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   June 21, 2020, 00:55
Default
  #6
Senior Member
 
Arun raj.S
Join Date: Jul 2011
Posts: 194
Rep Power: 14
arunraj is on a distinguished road
Dear vinerm,
Thank you for your advice.
I agree Divide C_UDMI by C_VOLUME(c, t) within DEFINE_SOURCE works. But I want to divide the volume of the face not by the entire domain. If it divided by the entire domain, then again the source term applied in the liquid-vapor interface or wick-vapor interface becomes so small. Am I wrong? Is there any way to overcome this problem. The paper I am following suggest to apply q/hfg as mass flux in the liquid-wick interface at evaporator and condenser which comes around 4.23729E-05 kg/s at evaporator and -4.23729E-05 kg/s at condenser. I am simulating from Page:365 conditions of the paper. They are getting a temperature difference of 17 from 350K to 333K. However, I am getting for the same condition a temperature of 10 from 330 to 320.

Poplaski, L.M., Benn, S.P. and Faghri, A., 2017. Thermal performance of heat pipes using nanofluids. International Journal of Heat and Mass Transfer, 107, pp.358-371.

#include "udf.h"
int boundaryID1=78;
int boundaryID2=80;
int boundaryID3=82;
int boundaryID4=79;
int boundaryID5=81;
int boundaryID6=83;
int boundaryID7=76;
int boundaryID8=84;
int boundaryID9=86;
int boundaryID10=77;
int boundaryID11=85;
int boundaryID12=87;
DEFINE_SOURCE(massflux,c,t,dS,eqn)
{
real mdot;
mdot=C_UDMI(c,t,0)/C_VOLUME(c,t);
return (mdot);
}
DEFINE_ON_DEMAND(on_demand_calc)
{
face_t f;
cell_t c;
Domain *domain=Get_Domain(1);
Thread *t;

thread_loop_f(t,domain)
{
if (THREAD_ID(t)==boundaryID1)
{
begin_f_loop(f,t)
{
C_UDMI(F_C0(f,t),THREAD_T0(t),0)=4.23729E-05;
}
end_f_loop(f,t)
}
else if(THREAD_ID(t)==boundaryID2)
{
begin_f_loop(f,t)
{
C_UDMI(F_C0(f,t),THREAD_T0(t),0)=0.0;
}
end_f_loop(f,t)
}
else if(THREAD_ID(t)==boundaryID3)
{
begin_f_loop(f,t)
{
C_UDMI(F_C0(f,t),THREAD_T0(t),0)=-4.23729E-05;
}
end_f_loop(f,t)
}
else if(THREAD_ID(t)==boundaryID4)
{
begin_f_loop(f,t)
{
C_UDMI(F_C0(f,t),THREAD_T0(t),0)=4.23729E-05;
}
end_f_loop(f,t)
}
else if(THREAD_ID(t)==boundaryID5)
{
begin_f_loop(f,t)
{
C_UDMI(F_C0(f,t),THREAD_T0(t),0)=0.0;
}
end_f_loop(f,t)
}
else if(THREAD_ID(t)==boundaryID6)
{
begin_f_loop(f,t)
{
C_UDMI(F_C0(f,t),THREAD_T0(t),0)=-4.23729E-05;
}
end_f_loop(f,t)
}
else if(THREAD_ID(t)==boundaryID7)
{
begin_f_loop(f,t)
{
C_UDMI(F_C0(f,t),THREAD_T0(t),0)=4.23729E-05;
}
end_f_loop(f,t)
}
else if(THREAD_ID(t)==boundaryID8)
{
begin_f_loop(f,t)
{
C_UDMI(F_C0(f,t),THREAD_T0(t),0)=0.0;
}
end_f_loop(f,t)
}
else if(THREAD_ID(t)==boundaryID9)
{
begin_f_loop(f,t)
{
C_UDMI(F_C0(f,t),THREAD_T0(t),0)=-4.23729E-05;
}
end_f_loop(f,t)
}
else if(THREAD_ID(t)==boundaryID10)
{
begin_f_loop(f,t)
{
C_UDMI(F_C0(f,t),THREAD_T0(t),0)=4.23729E-05;
}
end_f_loop(f,t)
}
else if(THREAD_ID(t)==boundaryID11)
{
begin_f_loop(f,t)
{
C_UDMI(F_C0(f,t),THREAD_T0(t),0)=0.0;
}
end_f_loop(f,t)
}
else if(THREAD_ID(t)==boundaryID12)
{
begin_f_loop(f,t)
{
C_UDMI(F_C0(f,t),THREAD_T0(t),0)=-4.23729E-05;
}
end_f_loop(f,t)
}
}
}
arunraj is offline   Reply With Quote

Old   June 21, 2020, 03:24
Default
  #7
Senior Member
 
Arun raj.S
Join Date: Jul 2011
Posts: 194
Rep Power: 14
arunraj is on a distinguished road
Also I want to know, why now I can use udf like below to apply directly on the liquid-vapor interface of evaporator and condenser. As per fluent manual, it says source terms are applied on each cell. So I mention the range of x-coordinate and y-coordinate, it will apply right. Why do we need to apply to the cells adjacent to interface.


#include "udf.h" // UDFs require this header file

DEFINE_SOURCE(local_energy_source,c,t,dS,eqn)
{
real x[ND_ND]; // array of cell coordinates
real source = 0.; // default the source term to zero

C_CENTROID(x,c,t); // retrieves the cell coordinates
dS[eqn] = 0.; // derivative of source term

if (x[0] > 0.5) // only if this cell belongs in the domain where x > 0.5 m
{
source = 1.; // non-zero source [generation-rate/volume e.g. W/m^3]
}

return source; // source is returned to solver
}
arunraj is offline   Reply With Quote

Old   June 21, 2020, 16:15
Default C_volume
  #8
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
Quote:
Originally Posted by arunraj View Post
Dear vinerm,
Thank you for your advice.
I agree Divide C_UDMI by C_VOLUME(c, t) within DEFINE_SOURCE works. But I want to divide the volume of the face not by the entire domain. If it divided by the entire domain, then again the source term applied in the liquid-vapor interface or wick-vapor interface becomes so small. Am I wrong? Is there any way to overcome this problem. The paper I am following suggest to apply q/hfg as mass flux in the liquid-wick interface at evaporator and condenser which comes around 4.23729E-05 kg/s at evaporator and -4.23729E-05 kg/s at condenser. I am simulating from Page:365 conditions of the paper. They are getting a temperature difference of 17 from 350K to 333K. However, I am getting for the same condition a temperature of 10 from 330 to 320.

Poplaski, L.M., Benn, S.P. and Faghri, A., 2017. Thermal performance of heat pipes using nanofluids. International Journal of Heat and Mass Transfer, 107, pp.358-371.
Faces do not have volume, cells do. C_VOLUME(c,t) returns volume of individual cell pointed to by its index c. So, source is being divided by the volume of the cell to which it is being applied. Fluent uses the value returned by UDF and multiplies it by the cell volume to which it is being applied. Consequently, the source value applied is what user intended it to be.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   June 21, 2020, 16:16
Default Interface
  #9
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
Quote:
Originally Posted by arunraj View Post
Also I want to know, why now I can use udf like below to apply directly on the liquid-vapor interface of evaporator and condenser. As per fluent manual, it says source terms are applied on each cell. So I mention the range of x-coordinate and y-coordinate, it will apply right. Why do we need to apply to the cells adjacent to interface.


#include "udf.h" // UDFs require this header file

DEFINE_SOURCE(local_energy_source,c,t,dS,eqn)
{
real x[ND_ND]; // array of cell coordinates
real source = 0.; // default the source term to zero

C_CENTROID(x,c,t); // retrieves the cell coordinates
dS[eqn] = 0.; // derivative of source term

if (x[0] > 0.5) // only if this cell belongs in the domain where x > 0.5 m
{
source = 1.; // non-zero source [generation-rate/volume e.g. W/m^3]
}

return source; // source is returned to solver
}
During phase change, mass, momentum, thermal energy, etc. are exchanged only at the interface and not everywhere. Therefore, sources must be applied only in the cells containing the interface and not throughout the domain.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   June 21, 2020, 18:08
Default
  #10
Senior Member
 
Arun raj.S
Join Date: Jul 2011
Posts: 194
Rep Power: 14
arunraj is on a distinguished road
Hi vinerm,

I prepared as per your advice but it does not yield the result i expected. kindly check if the overall idea in UDF is right.


#include "udf.h"


DEFINE_SOURCE(massflux,c,t,dS,eqn)

{

real x[ND_ND];

real source;


C_CENTROID(x,c,t);
dS[eqn]=0;

{

if((0>=x[0]<=0.1)&&(x[1]=0.002))
{

source=4.23729E-05/C_VOLUME(c,t);

}

else if((0.18>=x[0]<=0.33)&&(x[1]=0.002))
{

source=-4.23729E-05/C_VOLUME(c,t);

}

else if((0>=x[0]<=0.1)&&(x[1]=0.022))
{

source=4.23729E-05/C_VOLUME(c,t);

}

else if((0.18>=x[0]<=0.33)&&(x[1]=0.022))
{

source=-4.23729E-05/C_VOLUME(c,t);

}

return source;
}

}
DEFINE_SOURCE(umomentumflux,c,t,dS,eqn)

{

real x[ND_ND];

real source;


dS[eqn]=0;
{

if((0>=x[0]<=0.1)&&(x[1]=0.002))
{

source=4.23729E-05*C_U(c,t)/C_VOLUME(c,t);

}

else if((0.18>=x[0]<=0.33)&&(x[1]=0.002))

{

source=-4.23729E-05*C_U(c,t)/C_VOLUME(c,t);

}

else if((0>=x[0]<=0.1)&&(x[1]=0.022))
{

source=4.23729E-05*C_U(c,t)/C_VOLUME(c,t);

}

else if((0.18>=x[0]<=0.33)&&(x[1]=0.022))
{

source=-4.23729E-05*C_U(c,t)/C_VOLUME(c,t);

}

return source;
}

}
DEFINE_SOURCE(vmomentumflux,c,t,dS,eqn)

{

real x[ND_ND];

real source;



dS[eqn]=0;
{

if((0>=x[0]<=0.1)&&(x[1]=0.002))

{

source=-4.23729E-05*C_V(c,t)/C_VOLUME(c,t);

}

else if((0.18>=x[0]<=0.33)&&(x[1]=0.002))
{

source=4.23729E-05*C_V(c,t)/C_VOLUME(c,t);

}

else if((0>=x[0]<=0.1)&&(x[1]=0.022))
{

source=-4.23729E-05*C_V(c,t)/C_VOLUME(c,t);

}

else if((0.18>=x[0]<=0.33)&&(x[1]=0.022))

{

source=4.23729E-05*C_V(c,t)/C_VOLUME(c,t);

}

return source;
}

}
DEFINE_SOURCE(energy,c,t,dS,eqn)

{

real x[ND_ND];

real source;


dS[eqn]=0;
{

if((0>=x[0]<=0.1)&&(x[1]=0.002))
source=100/C_VOLUME(c,t);

}

else if((0.18>=x[0]<=0.33)&&(x[1]=0.002))
{

source=-100/C_VOLUME(c,t);

}

else if((0>=x[0]<=0.1)&&(x[1]=0.022))
{

source=100/C_VOLUME(c,t);

}

else if((0.18>=x[0]<=0.33)&&(x[1]=0.022))
{

source=-100/C_VOLUME(c,t);

}

return source;
}

}
arunraj is offline   Reply With Quote

Old   June 22, 2020, 04:01
Default Interface
  #11
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
What's the objective of your simulation? You appear to have a fixed location of the interface. If that is the case, multiphase (VOF) model is not really required.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   June 22, 2020, 04:43
Default
  #12
Senior Member
 
Arun raj.S
Join Date: Jul 2011
Posts: 194
Rep Power: 14
arunraj is on a distinguished road
Hi vinerm,

Thank you for the advice. I am not using multiphase VOF. I am simulating heat pipe with single phase assumption. I need to apply difference between temperature gradient between wick and vapor region as energy source term and the velocity calculated from energy balance as inlet for liquid-vapor interface. However, in the above UDF, I assumed input heat and rejected heat. But it does not yield any good results.
arunraj is offline   Reply With Quote

Old   June 22, 2020, 04:48
Default Process
  #13
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
Then the UDFs are incomplete. If the simulation is single phase, you cannot have only one-way sources, i.e., if you add only positive sources, but not negative ones, then you are adding external sources that don't exist in the system. This will slowly either increase or decrease the amount of fluid, depending upon whether the sources are positive or negative. Eventually, it will lead to divergence.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   June 22, 2020, 04:52
Default
  #14
Senior Member
 
Arun raj.S
Join Date: Jul 2011
Posts: 194
Rep Power: 14
arunraj is on a distinguished road
Yes, I understood that now. So I will incorporate using gradient. Thank you for your advice.
arunraj 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
SimpleFoam & Theater jipai OpenFOAM Running, Solving & CFD 3 June 18, 2019 10:11
Locating near wall cells for evaporation model mehrdad_kbg OpenFOAM Programming & Development 2 February 4, 2014 02:56
Radiation interface hinca CFX 15 January 26, 2014 17:11
Water subcooled boiling Attesz CFX 7 January 5, 2013 03:32
[ICEM] Export ICEM mesh to Gambit / Fluent romekr ANSYS Meshing & Geometry 1 November 26, 2011 12:11


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