关于成核模型中的UDF问题



  • 各位大佬好,最近在PBM模型中要写入一个关于成核的UDF,按照教程中的示例做了修改,然后再fluent中编译时出现了问题,麻烦各位大佬看看时怎么了
    0651838e-fcfa-4b81-8a4f-f4e6f639a2f5-image.png

    代码如下:

    /************************************************************************
               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的时候提示是这样的
    045aac1c-88a5-415b-b12f-1d3df27cb94f-image.png
    然后点击Load的提示是这样的
    da68d094-d34b-4818-8d45-1e4577602747-image.png

    1119fa27-2001-4060-91f7-4269cce9435e-image.png

    编程功力不太行,只能按照示例在上面修改,很多地方不太懂,还请各位大佬帮忙看看,这究竟是咋回事呢?@东岳



  • 你这注释的格式就有问题呀!

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

    2.png
    1.png
    代码的部分问题我帮你修改了,不一定都正确,你自己再检查检查,然后再按上面这图中提示的信息自己查阅资料(无论UDF手册还是C语言基础书籍还是其他什么资料)去进行调试吧,加油!:146:


  • Linux讲师 OpenFOAM讲师

    @lee459317530 他注视格式不对是因为代码部分的"*"被当成正文里的markdown标记,被吃了:chigua2:

    @关伯兰在笑 开fluent的时候在“开始”里搜"commander",开那个带“x64”的,是commander tool还是啥。然后在那个终端里输入fluent,回车,这样的打开的fluent带64位编译功能。如果没有64位commander,需要安装visual studio。



  • @bestucan 多谢多谢!



  • @lee459317530
    请问为什么要将Thread **pt = THREAD_SUB_THREADS(tc);改成Thread *pt = THREAD_SUB_THREADS(thread); 呢?
    我使用Thread **pt = THREAD_SUB_THREADS(tc);的时候就显示“生成成功”了
    ff7102d6-6afc-4ff1-91f2-63c30c084d13-image.png

    但还是有之前同样的问题



  • @bestucan
    在开始里面搜commander是这个吗
    fd8de95e-de88-4bd4-93a8-03f9990a1808-image.png


  • Linux讲师 OpenFOAM讲师

    @关伯兰在笑 试试,我搜出来的是 x64 Native Tools Command Prompt for VS 2019。兴许不同版本的不一样,也可能是中英文的区别。


  • CORE Fluent讲师

    @关伯兰在笑关于成核模型中的UDF问题 中说:

    @bestucan
    在开始里面搜commander是这个吗
    fd8de95e-de88-4bd4-93a8-03f9990a1808-image.png


    以管理员身份运行


  • CORE Fluent讲师


Log in to reply
 

CFD中文网 2016 - 2020 | 京ICP备15017992号-2