1

我是使用 OpenFOAM-6 的新手。我正在尝试阅读 GDB 的源代码。但是,我不明白为什么 GDB 不能进入某些类的构造函数,例如fvMesh. GDB 也报告类似

(gdb) p mesh
$1 = <incomplete type>

rhoSimpleFoam我首先在调试模式下编译了一个应用程序。基本上,我将变量WM_COMPILE_OPTION从 Opt 导出到 Debug,然后编译应用程序。我还尝试在调试模式下编译整个 OpenFOAM。对我将在下面描述的内容没有影响。Debug 模式rhoSimpleFoam为 3.8MB,Opt 版本为 889KB。

rhoSimpleFoam然后我使用gdb 运行

gdb <ThePathToDebugMode>/rhoSimpleFoam

rhoSimpleFoam.C如下,

#include "fvCFD.H"
#include "fluidThermo.H"
#include "turbulentFluidThermoModel.H"
#include "simpleControl.H"
#include "pressureControl.H"
#include "fvOptions.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

int main(int argc, char *argv[])
{
    #include "postProcess.H"

    #include "setRootCaseLists.H"
    #include "createTime.H"
    #include "createMesh.H"
    #include "createControl.H"
    #include "createFields.H"
    #include "createFieldRefs.H"
    #include "initContinuityErrs.H"

    turbulence->validate();

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

    Info<< "\nStarting time loop\n" << endl;

    while (simple.loop(runTime))
    {
        Info<< "Time = " << runTime.timeName() << nl << endl;

        // Pressure-velocity SIMPLE corrector
        #include "UEqn.H"
        #include "EEqn.H"

        if (simple.consistent())
        {
            #include "pcEqn.H"
        }
        else
        {
            #include "pEqn.H"
        }

        turbulence->correct();

        runTime.write();

        Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
            << "  ClockTime = " << runTime.elapsedClockTime() << " s"
            << nl << endl;
    }

    Info<< "End\n" << endl;

    return 0;

我想知道的是如何fvMesh初始化的,应该在#include "createMesh.H". 文件createMesh.H如下,

Foam::Info
    << "Create mesh for time = "
    << runTime.timeName() << Foam::nl << Foam::endl;

Foam::fvMesh mesh
(
    Foam::IOobject
    (
        Foam::fvMesh::defaultRegion,
        runTime.timeName(),
        runTime,
        Foam::IOobject::MUST_READ
    )
);

我在 GDB 中设置了一个断点Foam::fvMesh mesh并运行到那里。但是,GDB 不能进入那个fvMesh. 相反,GDB 进入runTime.timeName(). 之后,GDB 退出该文件createMesh.H。那对应的构造函数fvMesh如下,

Foam::fvMesh::fvMesh(const IOobject& io)
:
    polyMesh(io),
    surfaceInterpolation(*this),
    fvSchemes(static_cast<const objectRegistry&>(*this)),
    fvSolution(static_cast<const objectRegistry&>(*this)),
    data(static_cast<const objectRegistry&>(*this)),
    boundary_(*this, boundaryMesh()),
    lduPtr_(nullptr),
    curTimeIndex_(time().timeIndex()),
    VPtr_(nullptr),
    V0Ptr_(nullptr),
    V00Ptr_(nullptr),
    SfPtr_(nullptr),
    magSfPtr_(nullptr),
    CPtr_(nullptr),
    CfPtr_(nullptr),
    phiPtr_(nullptr)
{
    if (debug)
    {
        InfoInFunction << "Constructing fvMesh from IOobject" << endl;
    }

    // Check the existence of the cell volumes and read if present
    // and set the storage of V00
    if (fileHandler().isFile(time().timePath()/"V0"))
    {
        V0Ptr_ = new DimensionedField<scalar, volMesh>
        (
            IOobject
            (
                "V0",
                time().timeName(),
                *this,
                IOobject::MUST_READ,
                IOobject::NO_WRITE,
                false
            ),
            *this
        );

        V00();
    }

    // Check the existence of the mesh fluxes, read if present and set the
    // mesh to be moving
    if (fileHandler().isFile(time().timePath()/"meshPhi"))
    {
        phiPtr_ = new surfaceScalarField
        (
            IOobject
            (
                "meshPhi",
                time().timeName(),
                *this,
                IOobject::MUST_READ,
                IOobject::NO_WRITE,
                false
            ),
            *this
        );

        // The mesh is now considered moving so the old-time cell volumes
        // will be required for the time derivatives so if they haven't been
        // read initialise to the current cell volumes
        if (!V0Ptr_)
        {
            V0Ptr_ = new DimensionedField<scalar, volMesh>
            (
                IOobject
                (
                    "V0",
                    time().timeName(),
                    *this,
                    IOobject::NO_READ,
                    IOobject::NO_WRITE,
                    false
                ),
                V()
            );
        }

        moving(true);
    }
}

另一个我无法理解的问题如下。GDB 仍在文件中createMesh.H。GDB 对某些变量一无所知,就像下面的输出一样。

(gdb) p runTime
$1 = <incomplete type>
(gdb) p runTime.timeName()
Couldn't find method Foam::Time::timeName

事实上,我info sources在 GDB 中使用来显示加载的符号。有关参考info sources,请查看此网页。符号已加载。

因此,GDB 似乎对 OpenFOAM 了解甚少。GDB 不能进入某些 OpenFOAM 类中的函数体。GDB 在 OpenFOAM 中也找不到一些方法。

任何人都可以帮助我了解发生了什么?谢谢!

京昌

4

0 回答 0