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

Can udf plays the role of excel

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 18, 2019, 10:24
Default Can udf plays the role of excel
  #1
New Member
 
Join Date: Feb 2019
Posts: 2
Rep Power: 0
fan-violaine is on a distinguished road
Hello everyone,
I am trying to use fluent to solve the equations which I've solved with excel. In excel, i have 2 unknown variables: Temperature and y11(mole fraciton of the first components). I have also 3 others variables(y12,y16,y18 represnt the mole fraction of the 3 other components) which can be expressed by temperature and y1, i used solver to solve it.

My case in fluent is a 2D case with a laminar flow problem. In ordre to get the same results as excel, i used source term for y11,y12,y16,y18 and energy. I just add the heat of the formation in the energy source and let fluent calcul the m*Cp*dT for the different components(with energy equation on)

I can run them in fleunt but i can not get convergence!

I am thankful for any suggestions, please help me!
fan-violaine is offline   Reply With Quote

Old   February 18, 2019, 11:30
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
In theory, you can replicate ANY software in a UDF.
So if Excel can calculate something, then your UDF can calculate it.


But how, and if it is practical, that is a different question. A question I can not answer, because your description is still too vague. Maybe it would help if you would show the equation that you solve in excel, and if you show your UDF.
pakk is offline   Reply With Quote

Old   February 18, 2019, 12:01
Default
  #3
New Member
 
Join Date: Feb 2019
Posts: 2
Rep Power: 0
fan-violaine is on a distinguished road
Quote:
Originally Posted by pakk View Post
In theory, you can replicate ANY software in a UDF.
So if Excel can calculate something, then your UDF can calculate it.


But how, and if it is practical, that is a different question. A question I can not answer, because your description is still too vague. Maybe it would help if you would show the equation that you solve in excel, and if you show your UDF.
Hi pakk, thanks a lot for your quick response. Here are my codes UDF, i wrote the equations exactly the same as in excel. I am pretty new to fluent, if you find sth wrong in the codes, i would appreciate if you could tell me !


#include "udf.h"


/******************************* CONSTANTS ******************************/
#define M_HF 20.01 /* g/mol */
#define M_H2O 18.02/* g/mol */
#define M_H2F2 40.12/* g/mol */
#define M_H6F6 120.36/* g/mol */
#define M_H8F8 160.08/* g/mol */
#define M_air 28.966/* g/mol */
#define dH2 -12775.229 /* cal/mol */
#define dH6 -41927.495/* cal/mol */
#define dH8 -50120.984/* cal/mol */
#define dHcond 10519/* cal/mol */
#define dS2 -47.97731/* cal/mol */
#define dS6 -138.55185/* cal/mol */
#define dS8 -165.85264/* cal/mol */
#define CpHF 6.96/* cal/(K*mol) */
#define Cpair 6.96/* cal/(K*mol) */
#define Cpeau_V 8.05/* cal/(K*mol) */
#define Cp_aq 15.73642742/* cal/(K*mol) */
#define R 1.9869/* cal/(K*mol) */
#define frac 0.567



DEFINE_SOURCE(sourcey11_fin,c,t,dS,eqn)
{

real source;
real y11_0;
real y11_fin;
real Umean;
real ntotal;
/* C_YI(c,t,0):fraction massique en H6F6
C_YI(C,t,1):fraction massique en HF
C_YI(C,t,2):fraction massique en H2F2
C_YI(C,t,3):fraction massique en H8F8
(1-(C_YI(c,t,0)+C_YI(c,t,1)+C_YI(c,t,2)+C_YI(c,t,3))) :fraction massique en air */


Umean=sqrt(pow(C_U(c,t),2)+pow(C_V(c,t),2));
ntotal=C_YI(c,t,0)/M_H6F6+C_YI(c,t,1)/M_HF+C_YI(c,t,2)/M_H2F2+C_YI(c,t,3)/M_H8F8+(1-(C_YI(c,t,0)+C_YI(c,t,1)+C_YI(c,t,2)+C_YI(c,t,3)))/M_air;
y11_0=C_YI(c,t,1)/M_HF/ntotal;
y11_fin=((C_YI(c,t,0)+C_YI(c,t,2)+C_YI(c,t,3))/M_HF/frac-((C_YI(c,t,0)+C_YI(c,t,2)+C_YI(c,t,3))/M_HF+(1-(C_YI(c,t,0)+C_YI(c,t,1)+C_YI(c,t,2)+
C_YI(c,t,3)))/M_air))/ntotal;
source= (y11_fin-y11_0)*ntotal*M_HF*C_R(c,t)*Umean/pow(C_VOLUME_2D(c,t),1/3);
C_UDMI(c,t,0)=source;
dS[eqn]=0;
return source;

}


DEFINE_SOURCE(sourcey16_fin,c,t,dS,eqn)
{

real source;
real y16_0;
real y16_fin,y11_fin;
real Umean;
real K6;
real Ptot;
real ntotal;

ntotal=C_YI(c,t,0)/M_H6F6+C_YI(c,t,1)/M_HF+C_YI(c,t,2)/M_H2F2+C_YI(c,t,3)/M_H8F8+(1-(C_YI(c,t,0)+C_YI(c,t,1)+C_YI(c,t,2)+C_YI(c,t,3)))/M_air;
Ptot=C_P(c,t)/101325; /*on calcule la pression totale en atm*/
Umean=sqrt(pow(C_U(c,t),2)+pow(C_V(c,t),2));
y16_0=C_YI(c,t,0)/M_H6F6/ntotal;
K6=exp((-dH6/C_T(c,t)+dS6)/R);
y11_fin=C_YI(c,t,1)/(M_HF)/ntotal;
y16_fin=pow(y11_fin,6)*K6/Ptot;

source= (y16_fin-y16_0)*ntotal*M_H6F6*C_R(c,t)*Umean/pow(C_VOLUME_2D(c,t),1/3);


dS[eqn]=0;
/*pow(y11_fin,6)*dH6/pow(C_T(c,t),2)/R*exp(-dH6/C_T(c,t)/R)/Ptot*M_H6F6*C_R(c,t)*Umean/pow(C_VOLUME_2D(c,t),1/3);*/
return source;
}


DEFINE_SOURCE(sourcey12_fin,c,t,dS,eqn)
{

real source;
real y12_fin,y11_fin;
real y12_0;
real Umean;
real K2;
real Ptot;
real ntotal;

ntotal=C_YI(c,t,0)/M_H6F6+C_YI(c,t,1)/M_HF+C_YI(c,t,2)/M_H2F2+C_YI(c,t,3)/M_H8F8+(1-(C_YI(c,t,0)+C_YI(c,t,1)+C_YI(c,t,2)+C_YI(c,t,3)))/M_air;
Ptot=C_P(c,t)/101325; /*on calcule la pression totale en atm*/
Umean=sqrt(pow(C_U(c,t),2)+pow(C_V(c,t),2));
y12_0=C_YI(c,t,2)/M_H2F2/ntotal;
K2=exp((-dH2/C_T(c,t)+dS2)/R);
y11_fin=C_YI(c,t,1)/(M_HF)/ntotal;
y12_fin=pow(y11_fin,2)*K2/Ptot;

source= (y12_fin-y12_0)*ntotal*M_H2F2*C_R(c,t)*Umean/pow(C_VOLUME_2D(c,t),1/3);

dS[eqn]=0;
/*dS[eqn]=pow(y11_fin,2)*dH2/pow(C_T(c,t),2)/R*exp(-dH2/C_T(c,t)/R)/Ptot*M_H2F2*C_R(c,t)*Umean/pow(C_VOLUME_2D(c,t),1/3);*/
return source;
}


DEFINE_SOURCE(sourcey18_fin,c,t,dS,eqn)
{

real source;
real y18_fin,y11_fin;
real Umean;
real K8;
real y18_0;
real Ptot;
real ntotal;

ntotal=C_YI(c,t,0)/M_H6F6+C_YI(c,t,1)/M_HF+C_YI(c,t,2)/M_H2F2+C_YI(c,t,3)/M_H8F8+(1-(C_YI(c,t,0)+C_YI(c,t,1)+C_YI(c,t,2)+C_YI(c,t,3)))/M_air;
Ptot=C_P(c,t)/101325; /*on calcule la pression totale en atm*/
Umean=sqrt(pow(C_U(c,t),2)+pow(C_V(c,t),2));
y18_0=C_YI(c,t,3)/M_H8F8/ntotal;
K8=exp((-dH8/C_T(c,t)+dS8)/R);
y11_fin=C_YI(c,t,1)/(M_HF)/ntotal;
y18_fin=pow(y11_fin,8)*K8/Ptot;

source= (y18_fin-y18_0)*ntotal*M_H8F8*C_R(c,t)*Umean/pow(C_VOLUME_2D(c,t),1/3);


dS[eqn]=0;
/*dS[eqn]=pow(y11_fin,8)*dH8/pow(C_T(c,t),2)/R*exp(-dH8/C_T(c,t)/R)/Ptot*M_H8F8*C_R(c,t)*Umean/pow(C_VOLUME_2D(c,t),1/3);*/

return source;
}


DEFINE_SOURCE(energy1,c,t,dS,eqn)
{
real source;
real h6,h2,h8;
real K2,K6,K8;
real Umean;
real Ptot,y18_0,y16_0,y12_0,y11_fin,y16_fin,y12_fin,y18 _fin;
real ntotal;

ntotal=C_YI(c,t,0)/M_H6F6+C_YI(c,t,1)/M_HF+C_YI(c,t,2)/M_H2F2+C_YI(c,t,3)/M_H8F8+(1-(C_YI(c,t,0)+C_YI(c,t,1)+C_YI(c,t,2)+C_YI(c,t,3)))/M_air;
Umean=sqrt(pow(C_U(c,t),2)+pow(C_V(c,t),2));
Ptot=C_P(c,t)/101325; /*on calcule la pression totale en atm*/
y11_fin=C_YI(c,t,1)/(M_HF)/ntotal;


y16_0=C_YI(c,t,0)/M_H6F6/ntotal;
K6=exp((-dH6/C_T(c,t)+dS6)/R);
y16_fin=pow(y11_fin,6)*K6/Ptot;


h6=(y16_fin-y16_0)*ntotal*(-175.44*1000);

source=(h6)*Umean*C_R(c,t)/pow(C_VOLUME_2D(c,t),1/3);
dS[eqn]=0;
/*dS[eqn]=pow(y11_fin,6)*dH6/pow(C_T(c,t),2)/R*exp(-dH6/C_T(c,t)/R)/Ptot*(-175.44*1000)*Umean*C_R(c,t)/pow(C_VOLUME_2D(c,t),1/3);*/

return source;
}

DEFINE_SOURCE(energy2,c,t,dS,eqn)
{
real source;
real h6,h2,h8;
real K2,K6,K8;
real Umean;
real Ptot,y18_0,y16_0,y12_0,y11_fin,y16_fin,y12_fin,y18 _fin;
real ntotal;

ntotal=C_YI(c,t,0)/M_H6F6+C_YI(c,t,1)/M_HF+C_YI(c,t,2)/M_H2F2+C_YI(c,t,3)/M_H8F8+(1-(C_YI(c,t,0)+C_YI(c,t,1)+C_YI(c,t,2)+C_YI(c,t,3)))/M_air;
Umean=sqrt(pow(C_U(c,t),2)+pow(C_V(c,t),2));
Ptot=C_P(c,t)/101325; /*on calcule la pression totale en atm*/
y11_fin=C_YI(c,t,1)/(M_HF)/ntotal;

y12_0=C_YI(c,t,2)/M_H2F2/ntotal;
K2=exp((-dH2/C_T(c,t)+dS2)/R);
y12_fin=pow(y11_fin,2)*K2/Ptot;


h2=(y12_fin-y12_0)*ntotal*(-56.43*1000);
source=(h2)*Umean*C_R(c,t)/pow(C_VOLUME_2D(c,t),1/3);
dS[eqn]=0;
/*dS[eqn]=pow(y11_fin,2)*dH2/pow(C_T(c,t),2)/R*exp(-dH2/C_T(c,t)/R)/Ptot*(-56.43*1000)*Umean*C_R(c,t)/pow(C_VOLUME_2D(c,t),1/3);*/

return source;
}

DEFINE_SOURCE(energy3,c,t,dS,eqn)
{
real source;
real h6,h2,h8;
real K2,K6,K8;
real Umean;
real Ptot,y18_0,y16_0,y12_0,y11_fin,y16_fin,y12_fin,y18 _fin;
real ntotal;

ntotal=C_YI(c,t,0)/M_H6F6+C_YI(c,t,1)/M_HF+C_YI(c,t,2)/M_H2F2+C_YI(c,t,3)/M_H8F8+(1-(C_YI(c,t,0)+C_YI(c,t,1)+C_YI(c,t,2)+C_YI(c,t,3)))/M_air;
Umean=sqrt(pow(C_U(c,t),2)+pow(C_V(c,t),2));
Ptot=C_P(c,t)/101325; /*on calcule la pression totale en atm*/
y11_fin=C_YI(c,t,1)/(M_HF)/ntotal;


y18_0=C_YI(c,t,3)/M_H8F8/ntotal;
K8=exp((-dH8/C_T(c,t)+dS8)/R);
y18_fin=pow(y11_fin,8)*K8/Ptot;

h8=(y18_fin-y18_0)*ntotal*(-209.73*1000);
source=(h8)*Umean*C_R(c,t)/pow(C_VOLUME_2D(c,t),1/3);
dS[eqn]=0;
/*dS[eqn]=pow(y11_fin,8)*dH8/pow(C_T(c,t),2)/R*exp(-dH8/C_T(c,t)/R)/Ptot*(-209.73*1000)*Umean*C_R(c,t)/pow(C_VOLUME_2D(c,t),1/3);*/
return source;
}

DEFINE_SOURCE(sourceMass,c,t,dS,eqn)
{
real source;
source=0;

dS[eqn]=0;
return source;
}
fan-violaine 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
udf for one dimensional linear motion based on force maccheese Fluent UDF and Scheme Programming 2 September 1, 2019 03:18
can anyone help me about the udf of dynamic contact angle in FLUENT? Albert Lee FLUENT 0 July 1, 2018 09:21
Save output of udf in another udf! JuanJoMex FLUENT 0 February 8, 2018 13:43
UDF Compilation Error - Loading Library - COMMON Problem! Help! robtheslob Fluent UDF and Scheme Programming 8 July 24, 2015 01:53
UDF parallel error: chip-exec: function not found????? shankara.2 Fluent UDF and Scheme Programming 1 January 16, 2012 23:14


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