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/)
-   -   How to read a list from a dictionary? (http://www.cfd-online.com/Forums/openfoam-programming-development/71390-how-read-list-dictionary.html)

ivan_cozza December 29, 2009 14:12

How to read a list from a dictionary?
 
Hi Foamers,
I need to read a list of lists from a dictionary composed as follows:

listName
number of elements
(
(a b c d e f)
(g h i l m n)
....
)


where letters are labels. Something like blockMesh does when reading the blocks in blockMeshDict.
Can someone suggest me how to do it?
Thank you in advance,
Ivan

olwi December 29, 2009 15:22

Hi Ivan,

Knowing there's another piece of code that already does what you want is half the answer: If I was you, I would have a look at the source code for blockMesh, and see what it does to read the blockMeshDict.

/Ola

l_r_mcglashan December 29, 2009 18:33

I read in labels from a file using labelIOList, which is just a typedef for IOList<label>, so I imagine labelListIOList (IOList<labelList>) is what you want. It's probably used as follows:

labelListIOList listListName
(
IOobject
(
"listListName",
runTime.time().constant(), // Assuming your dictionary is in constant/
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
),
variable of type List<labelList>
);

It looks like the functionality you looking for with reading the listList from a dictionary is in the file createTopology.C in the blockMesh folder.

ivan_cozza January 2, 2010 12:11

Thank you Laurence,
I tested your solution, and it works fine for me!
Ivan

Quote:

Originally Posted by l_r_mcglashan (Post 241122)
I read in labels from a file using labelIOList, which is just a typedef for IOList<label>, so I imagine labelListIOList (IOList<labelList>) is what you want. It's probably used as follows:

labelListIOList listListName
(
IOobject
(
"listListName",
runTime.time().constant(), // Assuming your dictionary is in constant/
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
),
variable of type List<labelList>
);

It looks like the functionality you looking for with reading the listList from a dictionary is in the file createTopology.C in the blockMesh folder.


PicklER August 29, 2014 09:48

Hello

Could you (Laurence or Ivan) please elaborate a little bit more how to achieve the reading in of a list. Say I want to read in the list "datP" that is (0.5 5.0 10.0) from the a file called "Data" in the constant directory. I followed the solution of Laurence but my lack of knowledge of C++ is not helping

In my my main program (solver):

#include "labelListIOList.H"

and

#include "readData.H"

readData.H looks as follows:

labelListIOList Data
(
IOobject
(
"Data",
runTime.time().constant(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
),
labelList(datP)
);


I know the labelList(datP) is not correct. My Data file looks as follows (all files include headers):

datP (0.5 5.0 10.0);

Kind regards

vigneshTG November 7, 2014 05:13

IO object syntax for labelListList
 
Dear All,

I tried to create IO object of type labelListList using the information i found in this thread which is given below

Code:

labelListIOList proxCells
(
IOobject
(
"proxCells",
runTime.time().constant(), // Assuming your dictionary is in constant/
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),

);

I tried compiling it but i get an error as shown below
Code:


 p, li { white-space: pre-wrap; }  findProxCells.C: In function 'int main(int, char**)':
 findProxCells.C:95:1: error: expected primary-expression before ')' token
 make: *** [Make/linux64GccDPOpt/findProxCells.o] Error 1

Can some one tell me what i am missing in definition ?

Have a nice weekend !!

vigneshTG November 7, 2014 09:31

Dear All,

Finally i found a solution, here it is !!

Code:

IOList<labelList> proximityCells(
      IOobject(
                "proximityCells",
                runTime.time().constant(),
                mesh,
                IOobject::MUST_READ,
                IOobject::NO_WRITE
            )
    );

Please correct me if i am wrong !


All times are GMT -4. The time now is 18:23.