湍流模型跨版本(2.1.1与2.3.1)编译问题-已解决



  • 最近需要将2.1.1版本下开发的湍流KOmegaMDH 模型添加到2.3.1中,直接在如下根目录下新建文件夹KOmegaMDH将KOmegaMDH.C和KOmegaMDH.H放进去,

    2.3.1/src/turbulenceModels/incompressible/RAS
    

    在Make/files 中添加’KOmegaMDH/KOmegaMDH.C’并保存,在RAS下运行wclean和wmake libso 自动将库模型全部更新一遍,但编译到KOmegaMDH模型时便会报如下错误:

        error:invalid new-expression of abstruct class type 'FOAM::incompressible::RASModels::KOmegaMDH'   //出现这个错误原因是new 了一个抽象类出错,说明父类(接口)中有纯虚函数没有实现。接口里的纯虚函数全部需要实现,这样才能new 子类。https://www.cnblogs.com/laizhenghong2012/p/11302657.html(参考此文档解释)
        
            return auto<basseType>(new baseType##Type parlist); 
                                                             ^
    /home/kdd/OpenFOAM/OpenFOAM-2.3.1/src/turbulenceModels/incompressible/RAS/lnInclude/RASModel.H:125:9: note: in expansion of macro 鈥榙eclareRunTimeSelectionTable鈥?         declareRunTimeSelectionTable
                   ^
    In file included from kOmegaMHD.C:26:0:
    kOmegaMHD.H:77:7: note:   because the following virtual functions are pure within 'Foam::incompressible::RASModels::kOmegaMHD':
                    class kOmegaMHD
                          ^
    In file included from /home/kdd/OpenFOAM/OpenFOAM-2.3.1/src/turbulenceModels/incompressible/RAS/lnInclude/RASModel.H:47:0,
                 from kOmegaMHD.H:62,
                 from kOmegaMHD.C:26:
    /home/kdd/OpenFOAM%(#804e4e)[/OpenFOAM-2.3.1/src/turbulenceModels/incompressible/turbulenceModel/turbulenceModel.H:217:37]: note: 	virtual Foam::tmp<Foam::fvMatrix<Foam::Vector<double> > > Foam::incompressible::turbulenceModel::divDevRhoReff(const volScalarField&, Foam::volVectorField&) const  //这里才是最关键,显示这个H文件里217行有个虚函数const=0没有实现
         virtual tmp<fvVectorMatrix> divDevRhoReff
                                     ^
    

    找到/OpenFOAM-2.3.1/src/turbulenceModels/incompressible/turbulenceModel/turbulenceModel.H 并将这个H文件打开找到217行如下:

      213  //- Return the source term for the momentum equation
      214 virtual tmp<fvVectorMatrix> divDevReff(volVectorField& U) const = 0;
      215 
      216 //- Return the source term for the momentum equation
      217  virtual tmp<fvVectorMatrix> divDevRhoReff
           (
                const volScalarField& rho,
                volVectorField& U
            ) const = 0;
        //- Solve the turbulence equations and correct the turbulence viscosity
        virtual void correct() = 0;
    

    发现在2.3.1版本下的湍流模型的H文件中有两个同样的//- Return the source term for the momentum equation (213行和217行)
    再找到/OpenFOAM-2.1.1/src/turbulenceModels/incompressible/turbulenceModel/turbulenceModel.H 发现只有一个//- Return the source term for the momentum equation ,如下:

       //- Return the source term for the momentum equation
        virtual tmp<fvVectorMatrix> divDevReff(volVectorField& U) const;          
       //- Solve the turbulence equations and correct the turbulence viscosity
        virtual void correct();
    

    所以正确的做法是在KOmegaMDH.H文档中再添加一个与2.3.1相同的//- Return the source term for the momentum equation 函数,添加如下内容:

       //- Return the source term for the momentum equation
        virtual tmp<fvVectorMatrix> divDevReff(volVectorField& U) const;
    
        //- Return the source term for the momentum equation
        virtual tmp<fvVectorMatrix> divDevRhoReff
        (
            const volScalarField& rho,
            volVectorField& U
        ) const;    //添加这个函数,你也可以在查看2.3.1中其他模型下的H文档与2.2.1的进行对比,就能发现其中差异。
    
        //- Solve the turbulence equations and correct the turbulence viscosity
        virtual void correct();
    

    然后点击保存,再运行wclean和wmake libso 就可以了,希望可以帮到其他小伙伴~



  • 感谢楼主分享



  • 感谢楼主分享


Log in to reply
 

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