关于读取文件的错误



  • 各位大神好,
    在运行我自己写的solver时,遇到了一个关于读取文件的问题。

    我需要在一开始的creatField 时,根据我具体的研究对象,写一个名字为 porosityField的volScalarField到"0" 文件夹。我的具体代码如下:

    Info<< "Before read porosity field " << "\n" << endl;
    volScalarField porosityField
    (
        IOobject
        (
            "porosityField",
            runTime.timeName(),
            mesh,
            IOobject::READ_IF_PRESENT, //NO_READ,
            IOobject::AUTO_WRITE
        ),
        mesh,
        1.0
    );
    Info<< "After read porosity field " << "\n" << endl;
    
    //- update the porosity field
    porousZones.updatePoroField(porosityField, mesh);
    //- write the porosity field
    porosityField.write();
    

    当运行的时候出现了如下的错误:

    Before read porosity field 
    
    --> FOAM FATAL ERROR: 
    cannot find file "/home/hui/OpenFOAM/hui-v1906/run/Te1/0/porosityField"
    
        From function virtual Foam::autoPtr<Foam::ISstream> Foam::fileOperations::uncollatedFileOperation::readStream(Foam::regIOobject&, const Foam::fileName&, const Foam::word&, bool) const
        in file global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.C at line 548.
    
    FOAM exiting
    

    根据错误信息可以看出,这一行“Info<< "After read porosity field " << "\n" << endl;” 还没有运行到。所以就是这个读入这个文件的错误,我将 IOobject::READ_IF_PRESENT, 改为IOobject::NO_READ 后再次尝试,但是给出的是同样的错误信息。另外mesh后面的那个1 .0是默认值,去掉后再编译运行也是跟上面同样错误信息。

    然而根据这一页的openfoamwiki , 我这样生成的volScalarField 应该没有问题。而且如果用READ_IF_PRESENT 或者NO_READ ,不应该给出找不到文件的错误提示。

    • MUST_READ – The object must be read from Istream on construction. An error message is produced if Istream does not exist or can't be read.
    • READ_IF_PRESENT – It reads the object from Istream if Istream exists, otherwise doesn't. An error message is produced only if Istream exists but can't be read.
    • NO_READ – Don't read the object.

    不知道大家有没有类似的经验,帮忙解决一下。
    在此提前感谢!



  • Info<< "Before read porosity field " << "\n" << endl;
    volScalarField porosityField
    (
        IOobject
        (
            "porosityField",
            runTime.timeName(),
            mesh,
            IOobject::READ_IF_PRESENT, //NO_READ,
            IOobject::AUTO_WRITE
        ),
        mesh,
        1.0
    );
    

    确实是没问题的,是不是没编译好



  • @东岳 请问是指的openfoam 的编译问题吗?我注意到在程序开始的时候有一个warning,师兄说一般warning都没啥事。但是我看这个warning也是跟IO的控制相关的。感觉有可能在这里就有问题了。

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
    Create time
    
    --> FOAM Warning : 
        From function static Foam::IOstreamOption::compressionType Foam::IOstreamOption::compressionEnum(const Foam::word&)
        in file db/IOstreams/IOstreams/IOstreamOption.C at line 86
        Unknown compression specifier 'uncompressed', assuming no compression
    Create mesh for time = 0
    
    
    PISO: Operating solver in PISO mode
    
    


  • 问题解决了。将1.0 改为dimless,就可以啦。
    具体可以参考这里


Log in to reply