24小时热门版块排行榜    

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

yanboliu

金虫 (小有名气)

[求助] udf 并行计算 已有1人参与

请教各位,以下udf 单核可以成功计算,求相应多核计算程序
#include "udf.h"
#include "math.h"

DEFINE_PROFILE(unsteady_temperature, thread, position)
{

real t, temperature;
face_t f;

begin_f_loop(f, thread)
{
t = RP_Get_Real("flow-time";
temperature = 295.869+5.3462*pow(10,-18)*pow(t,4)-6.3431*pow(10,-13)*pow(t,3)+1.2431*pow(10,-8)*t*t+0.00042227*t;
F_PROFILE(f, thread, position) = temperature;
}
end_f_loop(f, thread)

}
回复此楼

» 本帖附件资源列表

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

» 本帖已获得的红花(最新10朵)

» 猜你喜欢

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

yanboliu

金虫 (小有名气)

引用回帖:
7楼: Originally posted by achilFes1990 at 2015-06-02 19:07:43
#include "udf.h"

DEFINE_PROFILE(unsteady_temperature, t, i)
{

real time = CURRENT_TIME;
real temperature;
face_t f;

begin_f_loop(f, t)
{
temperature = 295.869+5.3462*pow(10,- ...

achilFes1990 :
       您好!谢谢您前段时间给我的帮助,不好意思又来打扰您,请问能不能再方便的时间给我指点迷津,我要编一个udf程序,定义时间和温度的关系,关系式为y=y0+A/t0*exp(0.5*(w/t0)∧2-(x-xc)/t0)*(erf(z/sqrt(2))+1)/2
式中: double z=(x-xc)/w-w/t0;y0=-4.63764;A=81.9784;xc=5.98023;w=3.3487;t0=5.90205。
编写了以下udf程序:
#include <udf.h>
#include <math.h>
#define ERF_PI 3.141592653589793
#define ERF_N 100


double erf(double x)////erf(x) = the cumulation of { 2/sqrt(pi)*exp(-z*z) } from 0 to x; //error function
{        // 2/sqrt(pi) * { ∑[(-1)^n / n! * x^(2n+1)/(2n+1)] + x }
        double res = x;
        double factorial = 1;        //n!
        double x_pow = x;
        int one = 1, n;
        for( n=1; n<100; n++ ){
                factorial *= n;
                one *= -1;
                x_pow *= x*x;
                res += one / factorial * x_pow / ( 2*n+1 );
        }
        res *= 2 / sqrt(ERF_PI);
        return res;
}

double norm_cdf(double y)//cumulation distribution function of standard normal distribution
{
        real time = CURRENT_TIME;
        y=(time-5.98023)/3.3487-3.3487/5.90205
        return ( 1 + erf( y / sqrt(2) ) ) / 2;
}

DEFINE_PROFILE(unsteady_temperature, t, i)
{
real time = CURRENT_TIME;
real temperature;
face_t f;

begin_f_loop(f, t)
{
temperature = -4.6376+6.9448*exp(1.1742-time/5.90205)*(erf(y/sqrt(2))+1)/2;
F_PROFILE(f, t, i) = temperature;
}
end_f_loop(f, thread)

}

导入fluent出现以下错误:
ers\user\Desktop\udf unsteady temperature w 1.c: line 27: parse error.
Error: C:\Users\user\Desktop\udf unsteady temperature w 1.c: line 38: y: undeclared variable

望前辈给我指点迷津
16楼2015-09-16 08:42:52
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
查看全部 16 个回答

kylafree

至尊木虫 (知名作家)

你这个UDF的功能,单核跟多核是一样的,不用作修改

» 本帖已获得的红花(最新10朵)

3楼2015-06-01 10:05:56
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

yanboliu

金虫 (小有名气)

引用回帖:
3楼: Originally posted by kylafree at 2015-06-01 10:05:56
你这个UDF的功能,单核跟多核是一样的,不用作修改

您好,谢谢您的回复,但是我把这各UDF导入多核,显示找不到math.h,请问能继续向您请教吗?
4楼2015-06-02 11:31:31
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

achilFes1990

木虫 (著名写手)

【答案】应助回帖

★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★
yanboliu: 金币+25, ★★★★★最佳答案, 谢谢您的回复,改了下能运行了,还有一个问题:我的电脑在进行FLUENT多核计算的时候为什么会自动退出呢? 2015-06-02 18:14:47
引用回帖:
3楼: Originally posted by kylafree at 2015-06-01 10:05:56
你这个UDF的功能,单核跟多核是一样的,不用作修改

我觉得这个#include "math.h",是否可以去掉?
我之前有时候加上和去掉,貌似都没有什么问题

这个程序确实单双核都一样,但是有些写法还不是特别标准,有些整数后面最好加上.0以保证其为real类型
扫一扫关注我的微信公众号,共同学习船舶CFD
5楼2015-06-02 12:59:42
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
信息提示
请填处理意见