CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Transfer elements of dictionary into List<dimensionedScalar> (https://www.cfd-online.com/Forums/openfoam-programming-development/130412-transfer-elements-dictionary-into-list-dimensionedscalar.html)

maybee February 25, 2014 12:07

Transfer elements of dictionary into List<dimensionedScalar>
 
hi,

in one of my files, let s call the file "properties" I have a subdict like

Code:

ValueV1
{
V1S1  [0 1 1 0 0 0 0] 888888;   
V1S2  [0 1 1 0 0 0 0] 7777; 
.                                //no constant number of entries
.
.
}

This subdict consists of dimensioned scalars where the number is not constant and can change. I need to transfer the dimensioned scalars into a list of dimensioned scalars -> "List<dimensionedScalar>"
I tried something like

Code:

List<dimensionedScalar> List_V1 = properties.subDict("ValueV1");
Unfortunately this does not work since

Code:

error: no match for ‘operator=’
Later on in my code I need to access the dimensioned scalars of the list by their element position - therefore I need the list.

I know that I can stream the subdict into an object of class dictionary or create a reference to it like

Code:

const dictionary& subDict = properties.subDict("Value1");
but how can I transfer the dimensioned scalars into a list afterwards?

greetings
maybee

A_Pete February 26, 2014 07:09

I would think that this is not possible since the subDict type has some other properties compared to the List type. Maybe you should try to run a forAll loop over the entries of the subDict and then assign them to a List<dimensioned scalar>. But are these really all entries of type dimensionedScalar?

If that is not possible then you can maybe just read the scalar values out of the subDict with the readScalar() function.

Can't guarantee that this works, but maybe something like this:

Code:

//Get name of dictionary before
List<dimensionedScalar> list(dict.size());
forAll(dictName, i)
{
    //Get name of actual entry before
    dimensionedScalar listElement =
        (entryName, dimensionset(0, 1, 1, 0, 0, 0, 0), readScalar(properties.lookup(entryName)));
    list[i]=listElement;
}

Maybe you don't even need to assign to a dimensionedScalar first and can directly assign the value to list[i].

maybee February 27, 2014 04:55

hi,

thx for the help. Unfortunately I can t use your code since the number of elements/entries within the subdict is not constant. Therefore I can t write the code using the list entries.
I edited my intitial quesiton now.

Edit: I guess I have found a solution that works like this:

Code:

wordList VALUES
    (
        properties.lookup("VALUES")
    );

forAll(VALUES, i)
    {
        const word& Current = VALUES[i];
        dictionary& subDict_Values = properties.subDict("TheValues");
        List_Values[i] = dimensionedScalar(subDict_Values.lookup(Current));
    }

Guess this will work fine :)

greetings
maybee


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