View Issue Details

IDProjectCategoryView StatusLast Update
0001136OpenFOAMBugpublic2015-01-01 14:12
Reportermonto Assigned Tohenry  
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionno change required 
Summary0001136: faceList cannot be read from dictionary when using binary IO format
DescriptionThis problem appears when one uses binary IO format and tries to read/write a faceList from a dictionary.

The list is (apparently) correctly written to file, but the subsequent read instruction fails with a "FatalIOError: ill-defined entry".


Steps To Reproducerun the attached "Test-dictionary" test application on any OpenFOAM case (e.g. cavity tutorial).

When using ASCII write format, everything works fine. When using BINARY, application fails with:


--> FOAM FATAL IO ERROR:
"ill defined primitiveEntry starting at keyword 'testFaces' on line 19 and ending at line 110"
TagsNo tags attached.

Activities

monto

2014-01-23 14:27

reporter  

Test-dictionary.tgz (1,404 bytes)

user4

2014-01-23 15:17

 

Test-dictionary.C (2,962 bytes)   
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | Copyright (C) 2011-2012 OpenFOAM Foundation
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

Application
    dictionaryTest

Description

\*---------------------------------------------------------------------------*/

#include "argList.H"

#include "fvCFD.H"

#include "IOstreams.H"
#include "IOobject.H"
#include "IFstream.H"
#include "OFstream.H"
#include "IOdictionary.H"
#include "stringOps.H"

#include "polyTopoChanger.H"
#include "IOPtrList.H"


using namespace Foam;

namespace Foam
{
defineCompoundTypeName(List<face>, faceList);
addCompoundToRunTimeSelectionTable(List<face>, faceList);
}


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//  Main program:

int main(int argc, char *argv[])
{
    argList::noParallel();
    argList::validArgs.insert("dict .. dictN");
    argList args(argc, argv, false, true);

    #include "createTime.H"
    #include "createMesh.H"

    // create a faceList
    const faceList& faces = mesh.faces();

    // write on dictionary constant/testFaces
    IOdictionary out
    (
        IOobject
        (
            "testFaces",
            runTime.constant(),
            runTime,
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        )
    );
    
    OFstream os
    (
        out.objectPath(),
        runTime.writeFormat(),
        runTime.writeVersion(),
        runTime.writeCompression()
    );

    out.writeHeader(os);

    faces.writeEntry("testFaces",os);
    
    out.writeEndDivider(os);
    os.flush();

    // try reading from constant/testFaces
    IOdictionary dict
    (
        IOobject 
        (
            "testFaces",
            runTime.constant(),
            runTime,
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        )
    );

   
    faceList testFaces(dict.lookup("testFaces"));

    Info << "size: " << testFaces.size() << endl;

    return 0;
}


// ************************************************************************* //
Test-dictionary.C (2,962 bytes)   

user4

2014-01-23 15:18

  ~0002779

You'll have to tell dictionary that it can write/read the faceList as a binary block. This is done through a compound token. I've uploaded a modified test file.

monto

2014-01-23 15:31

reporter   ~0002780

Thanks Mattijs, this definitely works! Actually I thought it was something related to compound types but I didn't know how to define it.

Regards,
M

Issue History

Date Modified Username Field Change
2014-01-23 14:27 monto New Issue
2014-01-23 14:27 monto File Added: Test-dictionary.tgz
2014-01-23 15:17 user4 File Added: Test-dictionary.C
2014-01-23 15:18 user4 Note Added: 0002779
2014-01-23 15:31 monto Note Added: 0002780
2015-01-01 14:12 henry Status new => closed
2015-01-01 14:12 henry Assigned To => henry
2015-01-01 14:12 henry Resolution open => no change required