CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Writing IOdictionary to user-defined folder (http://www.cfd-online.com/Forums/openfoam-programming-development/98778-writing-iodictionary-user-defined-folder.html)

Arnoldinho March 19, 2012 05:11

Writing IOdictionary to user-defined folder
 
Hi foamers,

I would like to create a specific (new) IOdictionary to store some values and save it in a used-defined folder. Generating the IOdictionary itself works, saving it to the folder does not fully work. I so far did
Quote:

fileName writeDirectory = "constant/boundaryField";
mkDir(writeDirectory);

IOdictionary vectorDict
(
IOobject
(
"a",
writeDirectory,
runTime,
IOobject::NO_READ,
IOobject::AUTO_WRITE
)
);
vectorDict.Foam::regIOobject::write();
This does not write anything to folder "constant/boundaryField" (which itself is created). When I replace "writeDirectory" in IOobject with runTime.constant(), the dict is written in the constant folder. Taking runTime.constant()/"boundaryField" again does not work.
So I guess I have to register this boundaryField folder somehow?
Btw: This is done in a post-processing tool, so not during runtime of a solver.

Arne

olesen March 20, 2012 04:14

Quote:

Originally Posted by Arnoldinho (Post 350156)
Hi foamers,

I would like to create a specific (new) IOdictionary to store some values and save it in a used-defined folder. Generating the IOdictionary itself works, saving it to the folder does not fully work. I so far did
This does not write anything to folder "constant/boundaryField" (which itself is created). When I replace "writeDirectory" in IOobject with runTime.constant(), the dict is written in the constant folder. Taking runTime.constant()/"boundaryField" again does not work.
So I guess I have to register this boundaryField folder somehow?
Btw: This is done in a post-processing tool, so not during runtime of a solver.

Arne

From your description, it sounds like you want to have "constant" as the _instance_ and "boundaryField" as the _local_. From your example, it sounds like you've tried to pack everything into _instance_. Take a look at the IOobject.H for more information about the different types of constructors.

If you *really* know what you are doing, and want to bypass the usual mechanisms, you can also experiment with the following constructor form ... but you are really on your own here (there is a large potential of creating something stupid if you are not careful):

Code:

        //- Construct from path, registry, io options
        //  Uses fileNameComponents() to split path into components.
        IOobject
        (
            const fileName& path,
            const objectRegistry& registry,
            readOption r=NO_READ,
            writeOption w=NO_WRITE,
            bool registerObject=true
        );


Arnoldinho March 20, 2012 04:31

Thanks Mark,

maybe its not that complicated/bad as it sounds. The only reason of using an IOdictionary is that I did not know a better structure for storing several List<vectorField> object entries within one file (including header).

It does not really matter where this dictionary is saved, but I just want to keep the structure clear. Therefore a subfolder with several dictionaries in it. This came to my mind because the folder structure created by the sample tool (folder "surfaces" with subfolders) is similar and I want to create something like that.

Arne


All times are GMT -4. The time now is 00:54.