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
13 帖子 5 发布者 13.5k 浏览
  • 从旧到新
  • 从新到旧
  • 最多赞同
回复
  • 在新帖中回复
登录后回复
此主题已被删除。只有拥有主题管理权限的用户可以查看。
  • 影 离线
    影 离线
    影川风
    写于 最后由 影川风 编辑
    #1

    eg.

     fvVectorMatrix UEqn
     (
         fvm::ddt(rho, U)
       + fvm::div(rhoPhi, U)
       + turbulence->divDevRhoReff(U)
     );   
    

    中的divDevRhoReff(U)

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

    ->表示指针,因此在createFields.H里面应该有turbulence指针的声明,turbulence->divDevRhoReff(U)调用turbulence指针的divDevRhoReff(U)函数。因此你需要去turbulence类型下面去找函数。再往下,涉及到类继承等。

    同时,OpenFOAM里面的函数名称很直观,divDevRhoReff(U)就是对有效RhoReff的rhoU做Dev操作同时求Div散度。这个divDevRhoReff(U)在各个具体的湍流模型里面各不相同,你可以去src下面的Turbulence下面找可压缩的湍流模型,里面应该有这个函数的定义。也可以试试这个操作,切换到src下键入:

    grep -R divDevRhoReff(U)
    

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

    影 1 条回复 最后回复
  • 影 离线
    影 离线
    影川风
    在 中回复了 李东岳 最后由 编辑
    #3

    @李东岳 谢谢东岳老师。我找到了它的定义。请教一个问题,我想修改psi,我看了下of下psi 的定义是

    const Foam::volScalarField& Foam::rhoThermo::psi() const
    {
        return psi_;
    }
    

    我想修改成变量psi, 我该怎么做呢?

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

    带_的在OpenFOAM里面一般表示私有成员,私有成员一般在类初始化里面设定。你看看你的类构造函数怎么初始化的。但是这个psi_应该表示可压缩性,可能在更底层的代码里面定义了,没记错的话应该是这个 http://dyfluid.com/sonicLiquidFoam.html Eq. (7)

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

    影 1 条回复 最后回复
  • 影 离线
    影 离线
    影川风
    在 中回复了 李东岳 最后由 李东岳 编辑
    #5

    @李东岳 我目前在看官方版本4.1下的compressibleInterFoam求解器
    在twoPhaseMixtureThermo类中,我没弄错的话它的定义是这个,有错还请纠正我。

    void Foam::twoPhaseMixtureThermo::correct()
    {
        thermo1_->he() = thermo1_->he(p_, T_);
        thermo1_->correct();
    
        thermo2_->he() = thermo2_->he(p_, T_);
        thermo2_->correct();
    
        psi_ = alpha1()*thermo1_->psi() + alpha2()*thermo2_->psi();
        mu_ = alpha1()*thermo1_->mu() + alpha2()*thermo2_->mu();
        alpha_ = alpha1()*thermo1_->alpha() + alpha2()*thermo2_->alpha();
    }
    

    我想看下 thermo1_->psi() 是怎么定义的,我在psiThermo.C下看到
    Foam::psiThermo::psiThermo(const fvMesh& mesh, const word& phaseName)

        fluidThermo(mesh, phaseName),
    
        psi_
        (
            IOobject
            (
                phasePropertyName("thermo:psi"),
                mesh.time().timeName(),
                mesh,
                IOobject::NO_READ,
                IOobject::NO_WRITE
            ),
            mesh,
            dimensionSet(0, -2, 2, 0, 0)
        ),
    
        mu_
        (
            IOobject
            (
                phasePropertyName("thermo:mu"),
                mesh.time().timeName(),
                mesh,
                IOobject::NO_READ,
                IOobject::NO_WRITE
            ),
            mesh,
            dimensionSet(1, -1, -1, 0, 0)
        )
    {}
    

    找到这儿,我不是很清楚了接下来该怎么查看各相psi的s定义,我知道它的定义会在equation of state 里,就是不清楚怎么联系的。

    1 条回复 最后回复
  • J 离线
    J 离线
    Jacobian
    写于 最后由 李东岳 编辑
    #6

    @影川风
    请看twoPhaseMixtureThermo.H 的59~63行,

        //- Thermo-package of phase 1
        autoPtr<rhoThermo> thermo1_;
        //- Thermo-package of phase 2
        autoPtr<rhoThermo> thermo2_;
    

    如果没说错的话,thermo1_,thermo2_是指向rhoThermo类的智能指针,所以你应该参考的是rhoThermo类
    那么,在rhoThermo.C 的 176~179行,

    const Foam::volScalarField& Foam::rhoThermo::psi() const
     {
         return psi_;
     }
    

    而这个psi_,是rhoThermo类里面的成员变量
    我不能理解的是,he( )定义在哪里?我仅仅在basicThermo类(rhoThermo基类)里面看到过这个纯虚函数。求问东岳老师此问题作何解答 @李东岳

    1 条回复 最后回复
  • J 离线
    J 离线
    Jacobian
    写于 最后由 编辑
    #7

    @影川风 sorry没认真看前面的回复,说了几句废话请忽略。不过还是想问一下,he( )这个函数在哪?

    影 1 条回复 最后回复
  • 影 离线
    影 离线
    影川风
    在 中回复了 Jacobian 最后由 编辑
    #8

    @jacobian twoPhaseMixtureThermo.C下就有它的定义,单独每相的可以顺着往下找就能看见

    J 1 2 条回复 最后回复
  • J 离线
    J 离线
    Jacobian
    在 中回复了 影川风 最后由 编辑
    #9

    @影川风
    twoPhaseMixtureThermo.C里面确实有,但是,,

    void Foam::twoPhaseMixtureThermo::correct()
    {
        thermo1_->he() = thermo1_->he(p_, T_);
        thermo1_->correct();
    
        thermo2_->he() = thermo2_->he(p_, T_);
        thermo2_->correct();
    
        psi_ = alpha1()*thermo1_->psi() + alpha2()*thermo2_->psi();
        mu_ = alpha1()*thermo1_->mu() + alpha2()*thermo2_->mu();
        alpha_ = alpha1()*thermo1_->alpha() + alpha2()*thermo2_->alpha();
    }
    

    这里的thermo1_是指向rhoThermo类的,真的可以调用twoPhaseMixtureThermo类里面的函数吗?我在twoPhaseMixtureThermo::he()里面加了一句Info,运行求解器的时候貌似没有在终端里看到那句Info。c++基础不牢求指导

    1 条回复 最后回复
  • 1 离线
    1 离线
    100yearsalone
    在 中回复了 影川风 最后由 编辑
    #10

    @影川风
    我在研究的是rhoPimpleFoam,虽然不一样,但是在rhopimpleFoam也出现了psi,我也想对其进行修改,
    我之前也是找不到修改的地方所以我是直接thermo的代码给//掉,自己写了一个状态方程,
    但在pEqn里面求解时还是有psi,觉得自己修改得不完全。

    Y 1 条回复 最后回复
  • Y 离线
    Y 离线
    youmengtian
    在 中回复了 100yearsalone 最后由 编辑
    #11

    刚好最近在看thermophysicalmodels这一部分。感觉的确复杂,大家可以参考userguide中的定义部分。特别是1.x版本更接近C++的书写习惯,一步步查下去就能找到了。特别需要搞清楚的就是每一层到底定义了些什么

    天命之谓性;率性之谓道;修道之谓教。
    道也者,不可须臾离也;可离,非道也。是故君子戒慎乎其所不睹,恐惧乎其所不闻。
    莫见乎隐,莫显乎微。故君子慎其独也

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

    针对5楼 @影川风 的问题,如果下面是你双流体模型调用的热动力包:

    thermoType
    {
        type              heRhoThermo;
        mixture         pureMixture;
        transport       const;
        thermo          hConst;
        equationOfState perfectGas;
        specie          specie;
        energy          sensibleInternalEnergy;
    }
    

    在perfectGasI.H中,有

    inline Foam::scalar Foam::perfectGas<Specie>::psi(scalar p, scalar T) const
    {
        return 1.0/(this->R()*T);
    }
    

    其中的this->R()定义在specieI.H

    inline scalar specie::R() const
    {
        return RR/molWeight_;
    }
    

    In the following I switch to English which is more convenient to code, molWeight_ is the Molecular weight of specie which is the given by the user. RR is the Universal gas constant which is defined in thermodynamicConstants.H, it is calculated by the following (defined in thermodynamicConstants.C):

    // Note: the 1e3 converts from /mol to /kmol for consistency with the
        // SI choice of kg rather than g for mass.
        // This is not appropriate for USCS and will be changed to an entry in
        // the DimensionedConstants dictionary in etc/controlDict
        const scalar RR = 1e3*physicoChemical::R.value();
    

    where R.value() is calculated by

    physicoChemical::NA*physicoChemical::k
    

    which is defined in physicoChemicalConstants.C. physicoChemical::NA is defined in fundamentalConstants.C:

    defineDimensionedConstantWithDefault
    (
        physicoChemical::group,
        physicoChemical::NA,
        Foam::dimensionedScalar
        (
            "NA",
            dimensionSet(0, 0, 0, 0, -1), //Foam::dimless/Foam::dimMoles,
            6.0221417930e+23
        ),
        constantphysicoChemicalNA,
        "NA"
    );
    

    and physicoChemical::k is defined in etc/controlDict:

    physicoChemical
            {
                mu              mu [1 0 0 0 0 0 0] 1.66054e-27;
                k               k [1 2 -2 -1 0 0 0] 1.38065e-23;
            }
    

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

    影 1 条回复 最后回复
  • 影 离线
    影 离线
    影川风
    在 中回复了 李东岳 最后由 编辑
    #13

    @李东岳 感谢东岳老师,非常详细的步骤。我会好好看看这块

    1 条回复 最后回复

  • 登录

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