24小时热门版块排行榜    

查看: 1414  |  回复: 20
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

huangkai1

新虫 (小有名气)

[求助] udf代码求助已有3人参与

各位老师同学好,最近在在做毕设,遇到一个问题实在不知如何解决,特来求助,先谢谢各位的帮助。

我做的主要是固定床反应器的模拟,在不加载udf源项时,能够得到模拟结果,但当加载源项后,就出现Sample Text的错误,现附上自己的cas和代码,希望大家能够指导,献上所有金币。


#include "udf.h"
/*动力学参数常量*/
#define PRE_EXP1 865.609      /*指前因子 单位mol/g.h.kpa2*/
#define PRE_EXP2 6275.871     /*指前因子 单位mol/g.h.kpa2*/
#define PRE_EXP3 1.60375e+05  /*指前因子 单位mol/g.h.kpa*/
#define PRE_EXP4 3277.5722    /*指前因子 单位mol/g.h.kpa*/
#define PRE_EXP5 13481.3718   /*指前因子 单位mol/g.h.kpa*/

#define ACTIVE1  6.04e+04    /*活化能 J/mol*/
#define ACTIVE2  6.24e+04    /*活化能 J/mol*/
#define ACTIVE3  6.66e+04    /*活化能 J/mol*/
#define ACTIVE4  2.64e+04    /*活化能 J/mol*/
#define ACTIVE5  5.42e+04    /*活化能 J/mol*/

#define BETA 0.0         /*温度指数*/

double arrhenius_rate1(real temp)
{
   return PRE_EXP1*pow(temp,BETA)*exp(-ACTIVE1/(UNIVERSAL_GAS_CONSTANT*temp));
}
double arrhenius_rate2(real temp)
{
   return PRE_EXP2*pow(temp,BETA)*exp(-ACTIVE2/(UNIVERSAL_GAS_CONSTANT*temp));
}
double arrhenius_rate3(real temp)
{
   return PRE_EXP3*pow(temp,BETA)*exp(-ACTIVE3/(UNIVERSAL_GAS_CONSTANT*temp));
}
double arrhenius_rate4(real temp)
{
   return PRE_EXP4*pow(temp,BETA)*exp(-ACTIVE4/(UNIVERSAL_GAS_CONSTANT*temp));
}
double arrhenius_rate5(real temp)
{
   return PRE_EXP5*pow(temp,BETA)*exp(-ACTIVE5/(UNIVERSAL_GAS_CONSTANT*temp));
}

#define P_C8H10    0
#define O_C8H10    1
#define M_C8H10    2
#define C6H6       3
#define C2H4       4
#define H20        5
#define CH3OH  6
#define C7H8   7


double reaction_rate1(cell_t c, Thread *cthread,real mw[],real yi[])
{
    real concenC7H8 = C_R(c,cthread)*yi[C7H8]/mw[C7H8];
        real concenCH3OH = C_R(c,cthread)*yi[CH3OH]/mw[CH3OH];
    return arrhenius_rate1(C_T(c,cthread))*pow(concenC7H8,1)*pow(concenCH3OH,1)*pow((UNIVERSAL_GAS_CONSTANT*C_T(c,cthread)),2);
}

double reaction_rate2(cell_t c, Thread *cthread,real mw[],real yi[])
{
    real concenCH3OH = C_R(c,cthread)*yi[CH3OH]/mw[CH3OH];
    return arrhenius_rate2(C_T(c,cthread))*pow(concenCH3OH,2)*pow((UNIVERSAL_GAS_CONSTANT*C_T(c,cthread)),2);
}

double reaction_rate3(cell_t c, Thread *cthread,real mw[],real yi[])
{
    real concenC7H8 = C_R(c,cthread)*yi[C7H8]/mw[C7H8];
    return arrhenius_rate3(C_T(c,cthread))*pow(concenC7H8,1)*pow((UNIVERSAL_GAS_CONSTANT*C_T(c,cthread)),1);
}

double reaction_rate4(cell_t c, Thread *cthread,real mw[],real yi[])
{
    real concenP_C8H10 = C_R(c,cthread)*yi[P_C8H10]/mw[P_C8H10];
    return arrhenius_rate4(C_T(c,cthread))*pow(concenP_C8H10,1)*pow((UNIVERSAL_GAS_CONSTANT*C_T(c,cthread)),1);
}

double reaction_rate5(cell_t c, Thread *cthread,real mw[],real yi[])
{
    real concenP_C8H10 = C_R(c,cthread)*yi[P_C8H10]/mw[P_C8H10];
    return arrhenius_rate5(C_T(c,cthread))*pow(concenP_C8H10,1)*pow((UNIVERSAL_GAS_CONSTANT*C_T(c,cthread)),1);
}

/*定义能量方程源项*/
DEFINE_SOURCE(energy_source,c,t,dS,eqn)
{
    real delt_h1,delt_h2,delt_h3,delt_h4,delt_h5, source,mw[8],yi[8];
    /*下面是五个反应的生成焓 单位kJ/mol*/
    delt_h1=-73.682;
        delt_h2=-14.430;
        delt_h3=-47.772;
        delt_h4=59.252;
        delt_h5=0.862;         
    source=(delt_h1*reaction_rate1(c,t,mw,yi)+delt_h2*reaction_rate2(c,t,mw,yi)+delt_h3*reaction_rate3(c,t,mw,yi)+delt_h4*reaction_rate4(c,t,mw,yi)+delt_h5*reaction_rate5(c,t,mw,yi))*1000*235.785;/*计算所有反应的反应热 单位kj/h*/
    dS=0;
        return source;
}

/*定义C7H8组分方程源项*/
DEFINE_SOURCE(c7h8_source,c,t,dS,eqn)
{
        real source,mw[8],yi[8];
        source=(0-reaction_rate1(c,t,mw,yi)-reaction_rate3(c,t,mw,yi)+reaction_rate4(c,t,mw,yi))*mw[C7H8]*0.2385785;          /*计算甲苯的消耗速度 单位g/h)*/
        dS=0;
                return source;
}
/*定义CH3OH组分方程源项*/
DEFINE_SOURCE(ch3oh_source,c,t,dS,eqn)
{
        real source,mw[8],yi[8];
        source=(-reaction_rate1(c,t,mw,yi)-reaction_rate2(c,t,mw,yi))*mw[CH3OH]*0.235785;                                  /*计算CH30H的消耗速度 单位g/h*/
        dS=0;
                return source;
}
/*定义C6H6组分方程源项*/
DEFINE_SOURCE(C6H6,c,t,dS,eqn)
{
        real source,mw[8],yi[8];
        source=0.5*(reaction_rate3(c,t,mw,yi))*mw[C6H6]*0.235785;                                                        /*计算CO2的生成速度 单位g/h*/
        dS=0;
                return source;
}

/*定义H20组分方程源项*/
DEFINE_SOURCE(h2o_source,c,t,dS,eqn)
{
        real source,mw[8],yi[8];
        source=(reaction_rate1(c,t,mw,yi)+reaction_rate2(c,t,mw,yi))*mw[H2O]*0.235785;/*计算H2O的生成速度 单位g/h*/
        dS=0;
                return source;
}

/*定义P-X组分方程源项*/
DEFINE_SOURCE(P_C810source,c,t,dS,eqn)
{
        real source,mw[8],yi[8];
        source=(reaction_rate1(c,t,mw,yi)-reaction_rate4(c,t,mw,yi)-reaction_rate5(c,t,mw,yi))*mw[P_C8H10]*0.235785; /*计算P-X的生成速度 单位g/h*/
        dS=0;
                return source;
}

/*定义O-X组分方程源项*/
DEFINE_SOURCE(O_C8H10source,c,t,dS,eqn)
{
        real source,mw[8],yi[8];
        source=0.5*reaction_rate5(c,t,mw,yi)*mw[O_C8H10]*0.235785; /*计算O-X的生成速度 单位g/h*/
        dS=0;
                return source;
}

/*定义M-X组分方程源项*/
DEFINE_SOURCE(M_C8H10source,c,t,dS,eqn)
{
        real source,mw[8],yi[8];
        source=0.5*reaction_rate5(c,t,mw,yi)*mw[M_C8H10]*0.235785; /*计算M-X的生成速度 单位g/h*/
        dS=0;
                return source;
}
/*定义GH组分方程源项*/
DEFINE_SOURCE(GHsource,c,t,dS,eqn)
{
        real source,mw[8],yi[8];
        source=0.5*(reaction_rate2(c,t,mw,yi)+reaction_rate4(c,t,mw,yi))*mw[C2H4]*0.235785; /*计算M-X的生成速度 单位g/h*/
        dS=0;
                return source;
}
回复此楼

» 本帖附件资源列表

  • 欢迎监督和反馈:小木虫仅提供交流平台,不对该内容负责。
    本内容由用户自主发布,如果其内容涉及到知识产权问题,其责任在于用户本人,如对版权有异议,请联系邮箱:xiaomuchong@tal.com
  • 附件 1 : fanyinqimoxing.cas
  • 2015-05-25 16:55:43, 735.67 K

» 猜你喜欢

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

huangkai1

新虫 (小有名气)

引用回帖:
12楼: Originally posted by CFD_light at 2015-05-26 11:03:36
case发散?udf通过了?...

出现Divergence detected in AMG solver: species-0的错误,udf应该是通过了,不过有这样的warning:temp definition shadows previous definition
temp definition shadows previous definition
temp definition shadows previous definition
temp definition shadows previous definition
temp definition shadows previous definition
mw definition shadows previous definition
yi definition shadows previous definition
mw definition shadows previous definition
yi definition shadows previous definition
mw definition shadows previous definition
yi definition shadows previous definition
mw definition shadows previous definition
yi definition shadows previous definition
mw definition shadows previous definition
yi definition shadows previous definition
mw definition shadows previous definition
yi definition shadows previous definition
mw definition shadows previous definition
yi definition shadows previous definition
mw definition shadows previous definition
yi definition shadows previous definition
mw definition shadows previous definition
yi definition shadows previous definition
mw definition shadows previous definition
yi definition shadows previous definition
mw definition shadows previous definition
yi definition shadows previous definition
mw definition shadows previous definition
yi definition shadows previous definition
mw definition shadows previous definition
yi definition shadows previous definition
mw definition shadows previous definition
yi definition shadows previous definition
肯定是哪里有问题了,不过我真是小白。
13楼2015-05-26 14:02:04
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
查看全部 21 个回答

huangkai1

新虫 (小有名气)

真诚期待得到大家的帮助指导,快不能毕业了。
2楼2015-05-25 16:58:03
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

nickma

至尊木虫 (著名写手)

【答案】应助回帖

感谢参与,应助指数 +1
DEFINE_SOURCE(C6H6,c,t,dS,eqn)
改为下面名称:
DEFINE_SOURCE(C6H6_source,c,t,dS,eqn)
C6H6已经定为常量了
4楼2015-05-25 18:26:28
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

huangkai1

新虫 (小有名气)

引用回帖:
4楼: Originally posted by nickma at 2015-05-25 18:26:28
DEFINE_SOURCE(C6H6,c,t,dS,eqn)
改为下面名称:
DEFINE_SOURCE(C6H6_source,c,t,dS,eqn)
C6H6已经定为常量了

这个我程序改了,没有什么用,不过还是要谢谢你。
5楼2015-05-25 19:30:10
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
信息提示
请填处理意见