Skip to content
  • 最新
  • 版块
  • 东岳流体
  • 随机看[请狂点我]
皮肤
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • 默认(不使用皮肤)
  • 不使用皮肤
折叠
CFD中文网

CFD中文网

  1. CFD中文网
  2. OpenFOAM
  3. 如何从字典读入一串系数

如何从字典读入一串系数

已定时 已固定 已锁定 已移动 OpenFOAM
6 帖子 4 发布者 5.1k 浏览
  • 从旧到新
  • 从新到旧
  • 最多赞同
回复
  • 在新帖中回复
登录后回复
此主题已被删除。只有拥有主题管理权限的用户可以查看。
  • Y 离线
    Y 离线
    yfclark 神
    写于 最后由 编辑
    #1

    各位大佬好,我最近在写一个流体的热物性参数,计算Cp和he等需要使用多项式,需要读入一串的scalar,我采用的scalarList,但是编译时出现了类型错误,我想请问一下,需要读入一串scalar的时候,大家采用的是什么方法?
    LiquidThermo.C

    class LiquidThermo
    {
        private:
            //constructor
            LiquidThermo();
            //constructor 
            LiquidThermo(const fvMesh & mesh,const dictionary & dict);    
            protected:
            //rho
            scalarList Coerho_[8];
            scalarList Coepsi_[7];
            // NSRDfunc
            scalarList Coemu_[5];
            //cp
            scalarList CoeCp_[8];
            //kappa
            scalarList Coekappa_[6];
            //he
            scalarList Coehe_[8];
        public:
            //inline functions used for constructor and correct function 
            //rho
            inline scalar rho(const scalar p,const scalar T) const;
            inline scalar psi(const scalar p,const scalar T) const;
            inline scalar mu(const scalar p,const scalar T) const;
            inline scalar Cp(const scalar p,const scalar T) const;
            inline scalar kappa(const scalar p,const scalar T) const;
            inline scalar alpha(const scalar p,const scalar T) const;
            inline scalar he(const scalar p,const scalar T) const;
    ...
    

    LiquidThermo.H
    //constructor and member fucntion

    //constructor 
    Foam::LiquidThermo::LiquidThermo
    (
        const fvMesh & mesh,
        const dictionary& dict
    ):
        name_(dict.dictName()),
        mesh_(mesh),
        p_(mesh.thisDb().lookupObject<volScalarField>(dict.lookup("p"))),
        T_(mesh.thisDb().lookupObject<volScalarField>(dict.lookup("T"))),
        rho_
        (
    	IOobject
    	(
    	    IOobject::groupName("rho", name_),
    	    mesh.time().timeName(),
    	    mesh,
    	    IOobject::NO_READ,
    	    IOobject::NO_WRITE
    	),
        ...
    {
        //read scalar
        Coerho_ = dict.lookup("Coerho");
        Coepsi_ = dict.lookup("Coepsi");
        Coemu_ = dict.lookup("Coemu");
        CoeCp_ = dict.lookup("CoeCp");
        Coekappa_ = dict.lookup("Coekappa");
        Coehe_ = dict.lookup("Coehe");
        R_   = readScalar(dict.lookup("R"));
        ...
    }
    //inline function 
    inline Foam::scalar Foam::LiquidThermo::rho
    (
        const scalar p,
        const scalar T
    ) const
    {
        //Coerho_[6]=pref ,Coerho_[7]=Tref
        return Coerho_[0]+Coerho_[1]*(p-Coerho_[6])+Coerho_[2]*(T-Coerho_[7])
        +Coerho_[3]*Foam::pow(p-Coerho_[6],2.0)+Coerho_[4]*Foam::pow(T-Coerho_[7],2.0)+Coerho_[5]*(p-Coerho_[6])*(T-Coerho_[7]);
    }
    

    基于OpenFoam2.4,编译错误为:

    LiquidThermo.C: In member function ‘Foam::scalar Foam::LiquidThermo::rho(Foam::scalar, Foam::scalar) const’:
    LiquidThermo.C:20:123: error: cannot convert ‘Foam::tmp<Foam::Field<double> >’ to ‘Foam::scalar {aka double}’ in return
         +Coerho_[3]*Foam::pow(p-Coerho_[6],2.0)+Coerho_[4]*Foam::pow(T-Coerho_[7],2.0)+Coerho_[5]*(p-Coerho_[6])*(T-Coerho_[7]);
                                                                                                                               ^
    
    1 条回复 最后回复
  • Y 离线
    Y 离线
    yfclark 神
    写于 最后由 编辑
    #2

    在http://www.tfd.chalmers.se/~hani/kurser/OS_CFD_2017/DavidSegersson/report_David_Segersson.pdf找到了相关的例子。

    定义变量: scalarList Coerho_;//8
    初始化:从字典读取 
     dict.lookup("Coerho")>>Coerho_;
    在字典中书写:
    Coerho   (1.0 2.0 3.0);
    

    以上为例子调用如下代码不会出错:

    Info<<Coerho_[0]+Coerho_[6];
    

    Coerho_[6]会被默认为0.

    1 条回复 最后回复
  • 李东岳李 在线
    李东岳李 在线
    李东岳 管理员
    写于 最后由 编辑
    #3

    感谢分享!:xiexie:

    http://dyfluid.com/index.html
    需要帮助debug算例的看这个 https://cfd-china.com/topic/8018

    1 条回复 最后回复
  • W 离线
    W 离线
    wwzhao 超神
    写于 最后由 编辑
    #4

    OpenFOAM 中提供了专门描述多项式的类:Polynomial

    用法可以参考:src/thermophysicalModels/specie/transport/polynomial/polynomialTransport.H

    1 条回复 最后回复
  • 范准范 离线
    范准范 离线
    范准
    写于 最后由 编辑
    #5

    我是这样做的:
    在求解器中,添加这样的代码:

            IOdictionary meshProperties
            (
                IOobject
                (
                    "meshProperties",
                    runTime.constant(),
                    mesh,
                    IOobject::MUST_READ,
                    IOobject::NO_WRITE
                )
            );
    	scalar xnumber(int(readScalar(meshProperties.lookup("xnumber"))));
    	scalar ynumber(int(readScalar(meshProperties.lookup("ynumber"))));
    

    在算例文件夹的constant文件夹中,创建一个名为meshProperties的文件,内容为

    /*--------------------------------*- C++ -*----------------------------------*\
    | =========                 |                                                 |
    | \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
    |  \\    /   O peration     | Version:  2.0.x                                 |
    |   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
    |    \\/     M anipulation  |                                                 |
    \*---------------------------------------------------------------------------*/
    
    FoamFile
    {
        version     2.0;
        format      ascii;
        class       dictionary;
        object      meshProperties;
    }
    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
    
    xnumber                       20;
    ynumber                       10;
    

    这样一来,参数xnumber和参数ynumber的值,就是通过算例文件夹里面的参数设定文件读取的了

    李东岳李 1 条回复 最后回复
  • 李东岳李 在线
    李东岳李 在线
    李东岳 管理员
    在 中回复了 范准 最后由 编辑
    #6

    @范准 非常好,感谢分享 :xiexie:

    http://dyfluid.com/index.html
    需要帮助debug算例的看这个 https://cfd-china.com/topic/8018

    1 条回复 最后回复

  • 登录

  • 登录或注册以进行搜索。
  • 第一个帖子
    最后一个帖子
0
  • 最新
  • 版块
  • 东岳流体
  • 随机看[请狂点我]