CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   DEFINE_SOURCE to cells near wall (https://www.cfd-online.com/Forums/fluent/228057-define_source-cells-near-wall.html)

arunraj June 18, 2020 08:37

DEFINE_SOURCE to cells near wall
 
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)
}
}
}

vinerm June 18, 2020 12:36

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

arunraj June 19, 2020 00:21

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.

arunraj June 20, 2020 09:19

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.

vinerm June 20, 2020 11:21

Source Term
 
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.

arunraj June 21, 2020 00:55

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 June 21, 2020 03:24

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
}

vinerm June 21, 2020 16:15

C_volume
 
Quote:

Originally Posted by arunraj (Post 775336)
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.

vinerm June 21, 2020 16:16

Interface
 
Quote:

Originally Posted by arunraj (Post 775344)
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.

arunraj June 21, 2020 18:08

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;
}

}

vinerm June 22, 2020 04:01

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

arunraj June 22, 2020 04:43

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.

vinerm June 22, 2020 04:48

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

arunraj June 22, 2020 04:52

Yes, I understood that now. So I will incorporate using gradient. Thank you for your advice.


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