几个"undefined reference to"错误

Several "undefined reference to" errors

本文关键字:错误 to undefined 几个 reference      更新时间:2023-10-16

我正在编辑一个计算流体动力学程序的源代码,尽管我是C++的新手,但我似乎无法找出错误的来源。它们如下:

Make/linux64GccDPOpt/mySCompressibleInterFoam.o:在函数"main"中:

mySTCompressibleInterFoam.C:

mySTCompressibleInterFoam.C:(.text.startup+0x3580):未定义对`Foam::surfaceTension::surface TensionForce()const'的引用

mySTCompressibleInterFoam.C:(.text.startup+0x3cff):未定义对"泡沫的vtable::surfaceTension"的引用

mySTCompressibleInterFoam.C:(.text.startup+0x8246):未定义对"泡沫的vtable::surfaceTension"的引用

代码结构相当复杂,但我很确定我已经找到了导致问题的代码行,但我不知道如何解决它

因此,顶级文件是:

  #include "fvCFD.H"
  #include "MULES.H"
  #include "subCycle.H"
  #include "rhoThermo.H"
  #include "interfaceProperties.H"
  #include "twoPhaseMixture.H"
  #include "twoPhaseMixtureThermo.H"
  #include "surfaceTension.H"
  #include "turbulenceModel.H"
  #include "pimpleControl.H"
  // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
{
#include "setRootCase.H"
#include "createTime.H"
#include "createMesh.H"
#include "readGravitationalAcceleration.H"
pimpleControl pimple(mesh);
#include "readControls.H"
#include "initContinuityErrs.H"
#include "createFields.H"
#include "CourantNo.H"
#include "setInitialDeltaT.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Info<< "nStarting time loopn" << endl;
while (runTime.run())
{
    #include "readControls.H"
    #include "CourantNo.H"
    #include "alphaCourantNo.H"
    #include "setDeltaT.H"
    runTime++;
    Info<< "Time = " << runTime.timeName() << nl << endl;
    // --- Pressure-velocity PIMPLE corrector loop
    while (pimple.loop())
    {
        #include "alphaEqnsSubCycle.H"
        // correct interface on first PIMPLE corrector
        if (pimple.corr() == 1)
        {
            interface.correct();
        }
        solve(fvm::ddt(rho) + fvc::div(rhoPhi));
        #include "UEqn.H"
        #include "TEqn.H"
        // --- Pressure corrector loop
        while (pimple.correct())
        {
            #include "pEqn.H"
        }
        if (pimple.turbCorr())
        {
            turbulence->correct();
        }
    }
    runTime.write();
    Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
        << "  ClockTime = " << runTime.elapsedClockTime() << " s"
        << nl << endl;
}
Info<< "Endn" << endl;
return 0;
}

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

从这些错误中,我的理解是这些错误来自surfaceTension类和函数。

表面张力.H如下:

#ifndef surfaceTension_H
#define surfaceTension_H
#include "incompressible/transportModel/transportModel.H"
#include "phase.H"
#include "PtrDictionary.H"
#include "volFields.H"
#include "surfaceFields.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*
                  Class surfaceTension Declaration
*---------------------------------------------------------------------------*/
class surfaceTension
:
public transportModel
{
public:
class interfacePair
:
    public Pair<word>
{
public:
    class hash
    :
        public Hash<interfacePair>
    {
    public:
        hash()
        {}
        label operator()(const interfacePair& key) const
        {
            return word::hash()(key.first()) + word::hash()(key.second());
        }
    };

    // Constructors
        interfacePair()
        {}
        interfacePair(const word& alpha1Name, const word& alpha2Name)
        :
            Pair<word>(alpha1Name, alpha2Name)
        {}
        interfacePair(const phase& alpha1, const phase& alpha2)
        :
            Pair<word>(alpha1.name(), alpha2.name())
        {}

    // Friend Operators
        friend bool operator==
        (
            const interfacePair& a,
            const interfacePair& b
        )
        {
            return
            (
                ((a.first() == b.first()) && (a.second() == b.second()))
             || ((a.first() == b.second()) && (a.second() == b.first()))
            );
        }
        friend bool operator!=
        (
            const interfacePair& a,
            const interfacePair& b
        )
        {
            return (!(a == b));
        }
};

private:
// Private data
    //- Dictionary of phases
    PtrDictionary<phase> phases_;
    const fvMesh& mesh_;
    const volVectorField& U_;
    const surfaceScalarField& phi_;
    surfaceScalarField rhoPhi_;
    volScalarField alphas_;
    typedef HashTable<scalar, interfacePair, interfacePair::hash>
        sigmaTable;
    sigmaTable sigmas_;
    dimensionSet dimSigma_;
    //- Stabilisation for normalisation of the interface normal
    const dimensionedScalar deltaN_;
    //- Conversion factor for degrees into radians
    static const scalar convertToRad;

// Private member functions
    tmp<surfaceVectorField> nHatfv
    (
        const volScalarField& alpha1,
        const volScalarField& alpha2
    ) const;
    tmp<surfaceScalarField> nHatf
    (
        const volScalarField& alpha1,
        const volScalarField& alpha2
    ) const;
    void correctContactAngle
    (
        const phase& alpha1,
        const phase& alpha2,
        surfaceVectorField::GeometricBoundaryField& nHatb
    ) const;
    tmp<volScalarField> nabla
    (
        const phase& alpha1,
        const phase& alpha2
    ) const;

 public:
// Constructors
    //- Construct from components
    surfaceTension
    (
        const volVectorField& U,
        const surfaceScalarField& phi
    );

//- Destructor
virtual ~surfaceTension()
{}    

// Member Functions
    //- Return the phases
    const PtrDictionary<phase>& phases() const
    {
        return phases_;
    }
    //- Return the velocity
    const volVectorField& U() const
    {
        return U_;
    }
    //- Return the volumetric flux
    const surfaceScalarField& phi() const
    {
        return phi_;
    }
    const surfaceScalarField& rhoPhi() const
    {
        return rhoPhi_;
    }
    //- Return the mixture density
    tmp<volScalarField> rho() const;
    //- Return the dynamic laminar viscosity
    tmp<volScalarField> mu() const;
    //- Return the kinematic laminar viscosity
    tmp<volScalarField> nu() const;
    //- Return surface Tension Force
    tmp<surfaceScalarField> surfaceTensionForce() const;
    //- Correct the mixture properties
    void correct();
    //- Read base transportProperties dictionary
    bool read();
};

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

表面张力.c即为

#include "surfaceTension.H"
#include "alphaContactAngleFvPatchScalarField.H"
#include "Time.H"
#include "subCycle.H"
#include "MULES.H"
#include "fvcSnGrad.H"
#include "fvcFlux.H"
// * * * * * * * * * * * * * * * Static Member Data  * * * * * * * * * * * * //
const Foam::scalar Foam::surfaceTension::convertToRad =
Foam::constant::mathematical::pi/180.0;
// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
Foam::surfaceTension::surfaceTension
(
const volVectorField& U,
const surfaceScalarField& phi
)
:
transportModel(U, phi),
phases_(lookup("phases"), phase::iNew(U, phi)),
mesh_(U.mesh()),
U_(U),
phi_(phi),
rhoPhi_
(
    IOobject
    (
        "rho*phi",
        mesh_.time().timeName(),
        mesh_,
        IOobject::NO_READ,
        IOobject::NO_WRITE
    ),
    mesh_,
    dimensionedScalar("rho*phi", dimMass/dimTime, 0.0)
),
alphas_
(
    IOobject
    (
        "alphas",
        mesh_.time().timeName(),
        mesh_,
        IOobject::NO_READ,
        IOobject::AUTO_WRITE
    ),
    mesh_,
    dimensionedScalar("alphas", dimless, 0.0),
    zeroGradientFvPatchScalarField::typeName
),
sigmas_(lookup("sigmas")),
dimSigma_(1, 0, -2, 0, 0),
deltaN_
(
    "deltaN",
    1e-8/pow(average(mesh_.V()), 1.0/3.0)
)
{
}
// * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
Foam::tmp<Foam::volScalarField> Foam::surfaceTension::nu() const
{
return mu()/rho();
}
Foam::tmp<Foam::surfaceScalarField>
Foam::surfaceTension::surfaceTensionForce() const
{
tmp<surfaceScalarField> tstf
(
    new surfaceScalarField
    (
        IOobject
        (
            "surfaceTensionForce",
            mesh_.time().timeName(),
            mesh_
        ),
        mesh_,
        dimensionedScalar
        (
            "surfaceTensionForce",
            dimensionSet(1, -2, -2, 0, 0),
            0.0
        )
    )
);
surfaceScalarField& stf = tstf();
forAllConstIter(PtrDictionary<phase>, phases_, iter1)
{
    const phase& alpha1 = iter1();
    PtrDictionary<phase>::const_iterator iter2 = iter1;
    ++iter2;
    for (; iter2 != phases_.end(); ++iter2)
    {
        const phase& alpha2 = iter2();
        sigmaTable::const_iterator sigma =
            sigmas_.find(interfacePair(alpha1, alpha2));
        if (sigma == sigmas_.end())
        {
            FatalErrorIn("surfaceTension::surfaceTensionForce() const")
                << "Cannot find interface " << interfacePair(alpha1, alpha2)
                << " in list of sigma values"
                << exit(FatalError);
        }
        stf += dimensionedScalar("sigma", dimSigma_, sigma())
           *fvc::interpolate(nabla(alpha1, alpha2))*
            (
                fvc::interpolate(alpha2)*fvc::snGrad(alpha1)
              - fvc::interpolate(alpha1)*fvc::snGrad(alpha2)
            );
    }
}
return tstf;
}
void Foam::surfaceTension::correct()
{}
Foam::tmp<Foam::surfaceVectorField> Foam::surfaceTension::nHatfv
(
const volScalarField& alpha1,
const volScalarField& alpha2
) const
{
surfaceVectorField gradAlphaf
(
    fvc::interpolate(alpha2)*fvc::interpolate(fvc::grad(alpha1))
  - fvc::interpolate(alpha1)*fvc::interpolate(fvc::grad(alpha2))
);
// Face unit interface normal
return gradAlphaf/(mag(gradAlphaf) + deltaN_);
}
Foam::tmp<Foam::surfaceScalarField> Foam::surfaceTension::nHatf
(
const volScalarField& alpha1,
const volScalarField& alpha2
) const
{
// Face unit interface normal flux
return nHatfv(alpha1, alpha2) & mesh_.Sf();
}
Foam::tmp<Foam::volScalarField> Foam::surfaceTension::nabla
(
const phase& alpha1,
const phase& alpha2
) const
{
tmp<surfaceVectorField> tnHatfv = nHatfv(alpha1, alpha2);
correctContactAngle(alpha1, alpha2, tnHatfv().boundaryField());
    // Simple expression for curvature
return -fvc::div(tnHatfv & mesh_.Sf());
}
bool Foam::surfaceTension::read()
{
if (transportModel::read())
{
    bool readOK = true;
    PtrList<entry> phaseData(lookup("phases"));
    label phasei = 0;
    forAllIter(PtrDictionary<phase>, phases_, iter)
    {
        readOK &= iter().read(phaseData[phasei++].dict());
    }
    lookup("sigmas") >> sigmas_;
    return readOK;
}
else
{
    return false;
}
}

为了计算每个时间步长的表面张力,在文件UEqn.H中调用surfaceTensionForce函数,如下所示:

surfaceTension mixture(U, phi);
fvVectorMatrix UEqn
(
    fvm::ddt(rho, U)
  + fvm::div(rhoPhi, U)
  + turbulence->divDevRhoReff(U)
);
UEqn.relax();
if (pimple.momentumPredictor())
{
    solve
    (
        UEqn
     ==
        fvc::reconstruct
        (
            (
                mixture.surfaceTensionForce()
              - ghf*fvc::snGrad(rho)
              - fvc::snGrad(p_rgh)
            ) * mesh.magSf()
        )
    );
//        K = 0.5*magSqr(U);
}

如果我删除该文件的第一行,则不会出现未定义的引用错误,并且代码编译良好。我看过很多类似的问题,最常见的解决方案是文件链接不正确,我确信情况并非如此。

提前谢谢。

这几乎是最常见的链接器错误。删除最后一个文件的第一行时,错误消失的原因可能是因为这会导致编译器错误(符号未声明),链接器甚至无法运行。

我只能猜测,但surfaceTension似乎属于另一个二进制文件,在编译UEqn.h时没有正确链接。

我还猜测您正在尝试运行OpenFOAM的示例应用程序。请确保,你已经完成了他们wiki上列出的所有安装步骤。

相关文章: