CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Read properties per component from an input file dictionary

Register Blogs Community New Posts Updated Threads Search

Like Tree27Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 2, 2013, 10:31
Default
  #21
Member
 
P.A.
Join Date: Mar 2009
Location: Germany
Posts: 83
Rep Power: 17
blaise is on a distinguished road
Hi Matvej,

I must apologize, this is all rubbish!!! Please forget this, I have to think over it again!

Sorry for wasting your time with this! I will come back to you when I cleared things up.

I wish I could somehow delete a posting...

Thank you,

Cheers,

Pascal.
blaise is offline   Reply With Quote

Old   September 3, 2013, 04:07
Default
  #22
Member
 
P.A.
Join Date: Mar 2009
Location: Germany
Posts: 83
Rep Power: 17
blaise is on a distinguished road
Hi Matvej,

I thought over my whole approach again and again, and I came to the conclusion, that my
posting with the attached flake.tar.gz wasn't as much rubbish as I thought. I thought I mixed
up two different ways to handle the data, but in fact the application I attached in my reply is almost
what I want. To make things clearer:

When we look at the dictionary file:
Code:
setFormat raw;
lambda 2.0;
flakeVelocity (1.9 0 0); 
sym false; 

flakeProps
(
    flakeOne
    {
        flakeD 4.5;
        radii ( 0.1 0.2 0.3 0.4 0.5 );
    }
    flakeTwo
    {
        flakeD 4.5;
        radii ( 0.1 0.2 0.3 0.4 0.5 );
    }
);
I want to load all the data into a single object containing the general data like "setFormat" or "lambda",
and the list "flakeProps" shall go into a list of dictionaries variable. In my code I declare this list of
dictionaries, but I don't do anything with it as I do not know how to get the data into this list using the >>operator.

For the main application the code should be something like this:

Code:
// All the include stuff remains as it is.

IOdictionary flakeProperties
(
    IOobject
        (
            "flakeDict",
            runTime.system(),
            mesh,
            IOobject::MUST_READ_IF_MODIFIED,
            IOobject::NO_WRITE
         )
);

flake flakes();
flakeProperties.lookupEntryPtr(".*", false, true)->stream() >> flakes;

Info << "Flakes: " << flakes << nl;

return 0;
This does not compile, but I would like to learn how to make it work. Can you help, or is this a stupid
approach anyway?

Of course I could simply pass the IOdictionary to a constructor and handle the loading of the variables
in this constructor. But I think it would be more elegant to have the >>operator do all this work.

I hope you can help me on this once more!

Thanks and best regards,

Pascal.
blaise is offline   Reply With Quote

Old   May 27, 2015, 09:48
Default
  #23
New Member
 
Milad MU
Join Date: Feb 2013
Posts: 9
Rep Power: 13
Milad06 is on a distinguished road
Hi,

I am having similar case where I want to change from constant lewis number to using different values for different species. Therefore, I have introduced Lewis number (Le) by using a speciesDict in constant folder for all the species of my case as follow:
Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  1.6                                   |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "constant";
    object      speciesDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

species
(
  H
  H2
  O
  O2
  OH
  H2O
  N2
  HO2
  H2O2
  AR
  );

H
{
    Le      Le  [0 0 0 0 0 0 0] 0.18;
    D      D  [0 2 -1 0 0 0 0] 1e-5;
    DD   DD [0 2 -1 0 0 0 0] (1.e-5 0 0 0 1.4e-5 0 0 0 1.e-5);
}

H2
{
    Le      Le  [0 0 0 0 0 0 0] 0.29;
    D      D  [0 2 -1 0 0 0 0] 1e-5;
    DD   DD [0 2 -1 0 0 0 0] (1.e-5 0 0 0 1.4e-5 0 0 0 1.e-5);
}

O
{
    Le      Le  [0 0 0 0 0 0 0] 0.70; //assumed
    D      D  [0 2 -1 0 0 0 0] 1e-5;
    DD   DD [0 2 -1 0 0 0 0] (1.e-5 0 0 0 1.4e-5 0 0 0 1.e-5);
}

O2
{
    Le      Le  [0 0 0 0 0 0 0] 1.10;
    D      D  [0 2 -1 0 0 0 0] 1e-5;
    DD   DD [0 2 -1 0 0 0 0] (1.e-5 0 0 0 1.4e-5 0 0 0 1.e-5);
}

OH
{
    Le      Le  [0 0 0 0 0 0 0] 0.71;
    D      D  [0 2 -1 0 0 0 0] 1e-5;
    DD   DD [0 2 -1 0 0 0 0] (1.e-5 0 0 0 1.4e-5 0 0 0 1.e-5);
}

H2O
{
    Le      Le  [0 0 0 0 0 0 0] 0.89;
    D      D  [0 2 -1 0 0 0 0] 1e-5;
    DD   DD [0 2 -1 0 0 0 0] (1.e-5 0 0 0 1.4e-5 0 0 0 1.e-5);
}

N2
{
    Le      Le  [0 0 0 0 0 0 0] 1.04;
    D      D  [0 2 -1 0 0 0 0] 1e-5;
    DD   DD [0 2 -1 0 0 0 0] (1.e-5 0 0 0 1.4e-5 0 0 0 1.e-5);
}

HO2
{
    Le      Le  [0 0 0 0 0 0 0] 1.08;
    D      D  [0 2 -1 0 0 0 0] 1e-5;
    DD   DD [0 2 -1 0 0 0 0] (1.e-5 0 0 0 1.4e-5 0 0 0 1.e-5);
}

H2O2
{
    Le      Le  [0 0 0 0 0 0 0] 1.09;
    D      D  [0 2 -1 0 0 0 0] 1e-5;
    DD   DD [0 2 -1 0 0 0 0] (1.e-5 0 0 0 1.4e-5 0 0 0 1.e-5);
}

AR
{
    Le      Le  [0 0 0 0 0 0 0] 0.18; //assumed
    D      D  [0 2 -1 0 0 0 0] 1e-5;
    DD   DD [0 2 -1 0 0 0 0] (1.e-5 0 0 0 1.4e-5 0 0 0 1.e-5);
}
and my createFields.H is as follow:

Code:
IOdictionary speciesDict
    (
        IOobject
        (
            "speciesDict",    // dictionary name
            runTime.constant(),     // dict is found in "constant"
            mesh,                   // registry for the dict
            IOobject::MUST_READ,    // must exist, otherwise failure
            IOobject::NO_WRITE      // dict is only read by the solver
        )
    );
    
    wordList speciesNames
    (
        speciesDict.lookup("species")
    );
    forAll(speciesNames, i)
    {
        word currentSpecie = speciesNames[i];
        Info<< "Doing stuff for specie: " << currentSpecie << endl;

        const dictionary& subDict = speciesDict.subDict(currentSpecie);

        dimensionedScalar Le_("Le", dimensionSet(0,0,0,0,0,0,0), scalar(0.0));
                Info<< "uliuli1: "  << endl;

    dimensionedScalar D_("D", dimensionSet(0,2,-1,0,0,0,0), scalar(0.0));
        dimensionedTensor DD_("DD", dimensionSet(0,2,-1,0,0,0,0), tensor(0.0));
        Le_ = subDict.lookup("Le");
        D_ = subDict.lookup("D");
        DD_ = subDict.lookup("DD");
            

    
        Info<< "Le = " << Le_ << endl;
        Info<< "D = " << D_ << endl;
        Info<< "DD = " << DD_ << endl;
    }
    
            Info<< "uliuli2: "  << endl;


    PtrList<dimensionedScalar> Leval(speciesNames.size());

    forAll(speciesNames, i)
    {
        word specieName = speciesNames[i];
        Info<< "uliuli3: " << specieName << endl;

        const dictionary& subDict2 = speciesDict.subDict(specieName);
          Info<< "uliuli4: " << endl;

        Leval.set
        (
             i,
             new dimensionedScalar(subDict2.lookup("Le"))
        );
    }
//end
Info<< "list " << Leval << endl;
So now my Leval is the Lewis number I want however, it gives me both the word ''Le'' and the dimension in addition of the value itself as follow:
Code:
10
(
Le [0 0 0 0 0 0 0] 0.18
Le [0 0 0 0 0 0 0] 0.29
Le [0 0 0 0 0 0 0] 0.7
Le [0 0 0 0 0 0 0] 1.1
Le [0 0 0 0 0 0 0] 0.71
Le [0 0 0 0 0 0 0] 0.89
Le [0 0 0 0 0 0 0] 1.04
Le [0 0 0 0 0 0 0] 1.08
Le [0 0 0 0 0 0 0] 1.09
Le [0 0 0 0 0 0 0] 0.18
)
1. How can I get only the values like (0.18 or 0.29 or ...) and not all the Le and dimensions ?

2. How can I use these 10 species Le numbers in the following equation as I want to divide my alphaEff by Le[i] of each specie in the loop.

Code:
forAll(Y, i)
    {
        if (Y[i].name() != inertSpecie)
        {
            volScalarField& Yi = Y[i];
        
               
        fvScalarMatrix YiEqn
            (
                fvm::ddt(rho, Yi)
              + mvConvection->fvmDiv(phi, Yi)
              - fvm::laplacian(turbulence->alphaEff()/Leval[i] ,Yi)   
             ==
                reaction->R(Yi)
              + fvOptions(rho, Yi)
            );
Thanks guys,
Milad
Zhiheng Wang likes this.
Milad06 is offline   Reply With Quote

Old   November 1, 2015, 07:34
Default
  #24
Member
 
Karelke Yu
Join Date: Dec 2014
Posts: 96
Rep Power: 12
cfdopenfoam is on a distinguished road
Quote:
Originally Posted by mkraposhin View Post
Another good example for your problem is OF file: functionObjectList.C
hello, Matvey.

i wonder how to read the following istream and use the parameters:
Code:
// the following code is part of myDict
listName 3  // name of this list and its size
(
    name0  1.0;   // a word and a scalar (value)
    name1  2.0;   // NOTE there is a ;
    name2  3.0;
);
// could i use PtrList<...> ... and how:confused:
if this is a very simple problem, please forgive me.
thank you in advance.
Zhiheng Wang likes this.
cfdopenfoam is offline   Reply With Quote

Old   November 1, 2015, 08:02
Default
  #25
Senior Member
 
mkraposhin's Avatar
 
Matvey Kraposhin
Join Date: Mar 2009
Location: Moscow, Russian Federation
Posts: 355
Rep Power: 21
mkraposhin is on a distinguished road
Hi,
List and PtrList are used to store objects of the same type, but in your list there are two types - word and scalar

So, may be you need to combine List and Tuple2 classes. Then your dictionary will look like:

Code:
listName 3  // name of this list and its size
(
    (name0  1.0)   // a word and a scalar (value)
    (name1  2.0)   // NOTE there is a ;
    (name2  3.0)
);
Then you can read it to variable of type List<Tuple2<label, word> >
Zhiheng Wang likes this.
mkraposhin is offline   Reply With Quote

Old   November 1, 2015, 08:47
Default
  #26
Member
 
Karelke Yu
Join Date: Dec 2014
Posts: 96
Rep Power: 12
cfdopenfoam is on a distinguished road
Quote:
Originally Posted by mkraposhin View Post
Hi,
List and PtrList are used to store objects of the same type, but in your list there are two types - word and scalar

So, may be you need to combine List and Tuple2 classes. Then your dictionary will look like:

Code:
listName 3  // name of this list and its size
(
    (name0  1.0)   // a word and a scalar (value)
    (name1  2.0)   // NOTE there is a ;
    (name2  3.0)
);
Then you can read it to variable of type List<Tuple2<label, word> >
thanks very much for your clear guidance.
but, if the problem is more complicated:
Code:
//the following code is part of myIODict
variableName [0 -1 1 0 0 0 0] 1.0; // this is the default value 1.0
// below is the zoned value for cellSet or cellZone computing
variableNameZoned 3  // name of this list and its size
(
    cellSetName0  1.5;  // for cellSetName0 the value is 1.5
    cellSetName1  2.0;  // the dimension here is the same as that of the default value
    cellSetName2  3.0;  // for cellSetName2 the value is 3.0
);
and now i guess i could use PtrList<dimensionedScalar> ...(but how, i am sorry i am new to OF coding)
the reason why i omit the default dimension in the list is that the list size maybe large and i think this may help reduce error. and also easy to modify the dimension. So in mySolver.C, how could i read and access to the above
maybe something like
Code:
dimensionedScalar variableName(myIODict.lookup("variableName"));
PtrList<dimensionedScalar> pvn(myIODict.lookup("variableNameZoned "));
....(how to read??)
thanks again.
Zhiheng Wang likes this.
cfdopenfoam is offline   Reply With Quote

Old   November 1, 2015, 09:22
Default
  #27
Senior Member
 
mkraposhin's Avatar
 
Matvey Kraposhin
Join Date: Mar 2009
Location: Moscow, Russian Federation
Posts: 355
Rep Power: 21
mkraposhin is on a distinguished road
Hi again, you can't read variables of different types in List, because List can store objects of only similar type.

Also, according to OF format definition List is stored as a set of values, separated by space (' '). And i think that ';' is not allowed inside the List dictionary

Why PtrList<Tuple2<word, label> > is not suitable for you?
mkraposhin is offline   Reply With Quote

Old   November 1, 2015, 10:43
Default
  #28
Member
 
Karelke Yu
Join Date: Dec 2014
Posts: 96
Rep Power: 12
cfdopenfoam is on a distinguished road
Quote:
Originally Posted by mkraposhin View Post
Hi again, you can't read variables of different types in List, because List can store objects of only similar type.

Also, according to OF format definition List is stored as a set of values, separated by space (' '). And i think that ';' is not allowed inside the List dictionary

Why PtrList<Tuple2<word, label> > is not suitable for you?
thanks for your valuable time. maybe i made some mistakes. i just wonder what is the data type of the variableNameZoned (delimited by ";"). i now think it is not a list (could it be istream or something else?) and i guess the values are accessed by something like
Code:
variableName = unknownType.lookup("cellSetName0");
what you have kindly provided is adequate to the problem. but i just want to learn more about the I/O in OF. since this dictionary file comes from someone else, i am struggling to understand how it works (i have no source code).
thanks again for your hints.
cfdopenfoam is offline   Reply With Quote

Old   November 1, 2015, 13:48
Default
  #29
Senior Member
 
mkraposhin's Avatar
 
Matvey Kraposhin
Join Date: Mar 2009
Location: Moscow, Russian Federation
Posts: 355
Rep Power: 21
mkraposhin is on a distinguished road
If you want to load data, separated by ';', you can use subdictionaries

For example, if you have data like this:

Code:
variableNameZoned
{
    name0 value0;
    name1 value1;
    name2 value2;
    //and so on
}
Then, you can read it with toc() and lookup() methods.
Code:
List<word> names = dict.subDict("variableNameZoned").toc();
List<scalar> values(names.size());
forAll(names, iName)
{
    values[iName] = readScalar(dict.subDict("variableNameZoned").lookup(names[iName]));
}
Zhiheng Wang likes this.
mkraposhin is offline   Reply With Quote

Old   November 1, 2015, 22:41
Default
  #30
Member
 
Karelke Yu
Join Date: Dec 2014
Posts: 96
Rep Power: 12
cfdopenfoam is on a distinguished road
Quote:
Originally Posted by mkraposhin View Post
If you want to load data, separated by ';', you can use subdictionaries
thanks very much for your typein. now this is clear and i think i have learned a lot. hope that helps others.
thanks again.
cfdopenfoam is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
1.7.x Environment Variables on Linux 10.04 rasma OpenFOAM Installation 9 July 30, 2010 05:43
Installation of OpenFOAM-1.6 on Ubuntu 9.10 marval OpenFOAM Installation 2 March 17, 2010 09:33
[OpenFOAM] ParaView 33 canbt open OpenFoam file hariya03 ParaView 7 September 25, 2008 18:33
DxFoam reader update hjasak OpenFOAM Post-Processing 69 April 24, 2008 02:24
Results saving in CFD hawk Main CFD Forum 16 July 21, 2005 21:51


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