关于成核模型中的UDF问题
-
各位大佬好,最近在PBM模型中要写入一个关于成核的UDF,按照教程中的示例做了修改,然后再fluent中编译时出现了问题,麻烦各位大佬看看时怎么了
代码如下:
/************************************************************************ UDF that computes the particle nucleation rate *************************************************************************/ #include "udf.h" #include "sg_pb.h" #include "sg_mphase.h" DEFINE_PB_NUCLEATION_RATE(nuc_rate, cell, thread) { real B;/* nucleation rate in #/(s kg-solvent)*/ real Kb_1 = 4.355; /* primary nucleation rate constant */ real Kb_2 = 3.968e14;/* secondary nucleation rate constant */ real b_1 = 1.852;/* primary nucleation law power index */ real b_2 = 4.226;/* secondary nucleation law power index */ real x;/*the antisolvent proportion in kg- antisolvent/kg-antisolvent and solvent */ real y;/*the solubility in kg-solute/kg- antisolvent and solvent */ real C;/*the solute concentration in kg-solute/kg-solvent*/ real Solubility;/*the solubility in kg-solute/kg-solvent */ real delta_C;/*the difference between the solute concentration and the solubility, kg-solute/kg-solvent*/ real solute_mass_frac,solvent_mass_frac,antisolvent_mass_frac; real m; Thread *tc = THREAD_SUPER_THREAD(thread); /*obtain mixture thread */ Thread **pt = THREAD_SUB_THREADS(tc); /* pointer to sub_threads */ Thread *tp = pt[P_PHASE]; /* primary phase thread */ solute_mass_frac = C_YI(cell,tp,0);/*mass fraction of solute in primary phase (solvent,antisolvent,Paracetamol)*/ solvent_mass_frac = C_YI(cell,tp,1);/* mass fraction of solvent in primary phase (solvent,antisolvent,Paracetamol ) */ antisolvent_mass_frac = 1-solute_mass_frac-solvent_mass_frac;/* mass fraction of antisolvent in primary phase (solvent,antisolvent,Paracetamol)*/ x=antisolvent_mass_frac/(antisolvent_mass_frac+solvent_mass_frac);/*the antisolvent proportion in kg- antisolvent/kg-antisolvent and solvent */ y =-2.63748*pow(x,4)+9.04654*pow(x,3)-10.86277*pow(x,2)+5.04399*x-0.57920;/*the solubility in kg-solute/kg- antisolvent and solvent */ Solubility=y*(1+(antisolvent_mass_frac/solvent_mass_frac));/*the solubility in kg-solute/kg- solvent */ C=solute_mass_frac/solvent_mass_frac;/*the solute concentration in kg-solute/kg- solvent*/ delta_C = C-Solubility; /* Definition of Supersaturation */ m=C_VOF(cell,pt[1])*1293; if (delta_C == 0.) { B = 0.; } else { B = (Kb_1)*pow(delta_C,b_1)+(Kb_2)*pow(delta_C,b_2)*m; } return B; }
Build的时候提示是这样的
然后点击Load的提示是这样的
编程功力不太行,只能按照示例在上面修改,很多地方不太懂,还请各位大佬帮忙看看,这究竟是咋回事呢?@东岳
-
你这注释的格式就有问题呀!
#include "udf.h" #include "sg_pb.h" #include "sg_mphase.h" DEFINE_PB_NUCLEATION_RATE(nuc_rate, cell, thread) { real B;/* nucleation rate in #/(s kg-solvent) */ real Kb_1 = 4.355; /* primary nucleation rate constant */ real Kb_2 = 3.968e14; /*secondary nucleation rate constant */ real b_1 = 1.852; /* primary nucleation law power index */ real b_2 = 4.226;/* secondary nucleation law power index */ real x;/*the antisolvent proportion in kg- antisolvent/kg-antisolvent and solvent */ real y;/*the solubility in kg-solute/kg- antisolvent and solvent */ real C;/*the solute concentration in kg-solute/kg-solvent*/ real Solubility;/*the solubility in kg-solute/kg-solvent */ real delta_C;/*the difference between the solute concentration and the solubility, kg-solute/kg-solvent*/ real solute_mass_frac,solvent_mass_frac,antisolvent_mass_frac; real m; Thread *tc = THREAD_SUPER_THREAD(thread); /*obtain mixture thread */ Thread *pt = THREAD_SUB_THREADS(thread); /*pointer to sub_threads */ Thread tp = pt[P_PHASE]; /* primary phase thread */ solute_mass_frac = C_YI(cell,tp,0);/*mass fraction of solute in primary phase (solvent,antisolvent,Paracetamol)*/ solvent_mass_frac = C_YI(cell,tp,1);/* mass fraction of solvent in primary phase (solvent,antisolvent,Paracetamol ) */ antisolvent_mass_frac = 1.-solute_mass_frac-solvent_mass_frac;/* mass fraction of antisolvent in primary phase (solvent,antisolvent,Paracetamol)*/ x = antisolvent_mass_frac/(antisolvent_mass_frac+solvent_mass_frac);/*the antisolvent proportion in kg- antisolvent/kg-antisolvent and solvent */ y = -2.63748*pow(x,4)+9.04654*pow(x,3)-10.86277*pow(x,2)+5.04399*x-0.57920; /* the solubility in kg-solute/kg- antisolvent and solvent */ Solubility = y*(1+(antisolvent_mass_frac/solvent_mass_frac)); /*the solubility in kg-solute/kg- solvent */ C = solute_mass_frac/solvent_mass_frac;/*the solute concentration in kg-solute/kg- solvent*/ delta_C = C-Solubility; /* Definition of Supersaturation */ m = C_VOF(cell, pt[1])*1293.; if (delta_C == 0.) { B = 0.; } else { B = (Kb_1)*pow(delta_C,b_1)+(Kb_2)*pow(delta_C,b_2)*m; } return B; }
代码的部分问题我帮你修改了,不一定都正确,你自己再检查检查,然后再按上面这图中提示的信息自己查阅资料(无论UDF手册还是C语言基础书籍还是其他什么资料)去进行调试吧,加油! -
@lee459317530 他注视格式不对是因为代码部分的"
*
"被当成正文里的markdown标记,被吃了@关伯兰在笑 开fluent的时候在“开始”里搜"commander",开那个带“x64”的,是commander tool还是啥。然后在那个终端里输入fluent,回车,这样的打开的fluent带64位编译功能。如果没有64位commander,需要安装visual studio。
-
@lee459317530
请问为什么要将Thread **pt = THREAD_SUB_THREADS(tc);
改成Thread *pt = THREAD_SUB_THREADS(thread);
呢?
我使用Thread **pt = THREAD_SUB_THREADS(tc);
的时候就显示“生成成功”了
但还是有之前同样的问题