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

double name entry in dict demanded

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes
  • 2 Post By wangsen992
  • 1 Post By superkelle

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 5, 2020, 10:10
Question double name entry in dict demanded
  #1
Member
 
alexander thierfelder
Join Date: Dec 2019
Posts: 71
Rep Power: 6
superkelle is on a distinguished road
Hi I wonder why I need a double naming for a dictionary value, when IO wont to update it on runtime. My dict now looks like this:


Code:
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "system";
    object      plasmaTuningDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //


R      R [1 2 -3 0 0 -2 0] 1320.0;

Vmax     Vmax [1 2 -3 0 0 -1 0] 1000.0;

// ************************************************************************* //
In createFields.H I loaded it like this:



Code:
IOdictionary plasmaTuningDict
    (
        IOobject
        (
            "plasmaTuningDict",
            runTime.system(),
            mesh,
            IOobject::MUST_READ_IF_MODIFIED,
            IOobject::NO_WRITE
        )
    );
    

    dimensionedScalar R
    (
        "R",
        dimensionSet(1, 2, -3, 0, 0, -2, 0),
        plasmaTuningDict.lookup("R")
    );
       
    dimensionedScalar Vmax 
    (
        "Vmax", 
        dimensionSet(1, 2, -3, 0, 0, -1, 0), 
        plasmaTuningDict.lookup("Vmax")
    );
In my solver I use following for updating:



Code:
R = plasmaTuningDict.lookup("R");
Vmax = plasmaTuningDict.lookup("Vmax");
If I don't do this double naming like:


Code:
R     [1 2 -3 0 0 -2 0] 1320.0;

Vmax    [1 2 -3 0 0 -1 0] 1000.0;
I get an error:


Code:
wrong token type - expected word, found on line 19 the punctuation token '['

file: /home/kelle/OpenFOAM/kelle-7/run/plasmaTestCase8/plasmaSimulation/system/plasmaTuningDict.R at line 19.

    From function Foam::Istream& Foam::operator>>(Foam::Istream&, Foam::word&)
    in file primitives/strings/word/wordIO.C at line 74.

FOAM exiting
It is just out of interest,. (and it looks a little bit stupid so it would be nice if there is a way to name it just once in the dict)
superkelle is offline   Reply With Quote

Old   June 6, 2020, 00:17
Default Problem with the assignment
  #2
New Member
 
Sen Wang
Join Date: Jul 2018
Location: Singapore / Notre Dame, U.S.
Posts: 19
Blog Entries: 1
Rep Power: 7
wangsen992 is on a distinguished road
Hi there,

I did some digging and this is an interesting question. I think the problem is that, when you initialized your dimensionedScalar R and Vmax, you used the constructor method,
Code:
dimensioned(const word &name, const dimensionSet & dims, const Istream &is)
which is actually a currently deprecated constructor method since 2018-11.

When you call
Code:
R = plasmaTuningDict.lookup("R")
, it again returns an Istream object from the dictionary containing the line
Code:
[1 2 -3 0 0 -2 0] 1320.0
, then this assignment is actually called with
Code:
dimensioned(Istream &is)
which is also deprecated since 2018-11.

If you trace it to the documentation here, you will see that expects the Istream to contain (name, dimensions, value). Since you don't have name, then dimensions will be parsed as a name which causes the problem.

And if you don't want to have the stupid double name, you can use the constructor methods from [7-12/15] which all provides the optional input for name and dims. Probably the easiest one is just [7/15] where you can simply do
Code:
dimensionedScalar R ( dict.lookup('R'))
since i believe the return type is a child class of entry so it should work by automatically parsing the ITstream to a entry object. And then update following your original code.
superkelle and Juan Daniel like this.

Last edited by wangsen992; June 6, 2020 at 03:31. Reason: Suggestion for code modification
wangsen992 is offline   Reply With Quote

Old   June 6, 2020, 05:34
Default
  #3
Member
 
alexander thierfelder
Join Date: Dec 2019
Posts: 71
Rep Power: 6
superkelle is on a distinguished road
Thank you for your advise and your time. I forgot to say that this was tested with OF7.

So now it is working without double naming, it is interesting what I think use to work but does not, and what does. So I deleted the entrys in createFields so that only the IO dict was constructed and initialized like above. And then I construct and initialize the Vmax and R in the time loop, so it goes out of scope every cycle and a new Vmax and R get constructed. Then you can construct it like:


Code:
dimensionedScalar Vmax 
    (
        "Vmax", 
        dimensionSet(1, 2, -3, 0, 0, -1, 0), 
        plasmaTuningDict.lookup("Vmax")
    );
Info << Vmax << endl;
dimensionedScalar R
    (
        "R",
        dimensionSet(1, 2, -3, 0, 0, -2, 0),
        plasmaTuningDict.lookup("R")
    );
Info << R << endl;
You can omit the dimensionSet entry, but the name entry "R" is mandatory.
So you are just not allowed to construct it out of the time loop and you are fine. What does not work is to construct it like:
Code:
dimensionedScalar R
    (
        plasmaTuningDict.lookup("R")
    );
Then I get again:
Code:
 --> FOAM FATAL IO ERROR: 
wrong token type - expected word, found on line 21 the punctuation token '['

file: /home/kelle/OpenFOAM/kelle-7/run/plasmaTestCase12/plasmaSimulation/system/plasmaTuningDict.Vmax at line 21.

    From function Foam::Istream& Foam::operator>>(Foam::Istream&, Foam::word&)
    in file primitives/strings/word/wordIO.C at line 74.

FOAM exiting
If I understand it correct in 7/15, it needs a primitive "e"
Code:
dimensioned            (           const primitiveEntry &            e)
But If I understand it correct a primitive is nothing else than a pair of a key and again a stream. So you have always to give the name as the key.
https://www.openfoam.com/documentati...tiveEntry.html

I am no pro in OF and C++, so feel free to correct me ^^.
Juan Daniel likes this.
superkelle is offline   Reply With Quote

Reply

Tags
dictionaries


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
fvOptions npatricia OpenFOAM 6 May 23, 2018 05:21
CFD by anderson, chp 10.... supersonic flow over flat plate varunjain89 Main CFD Forum 18 May 11, 2018 07:31
Warning message C4133 while compiling Arminius Fluent UDF and Scheme Programming 0 October 2, 2017 11:44
Missing math.h header Travis FLUENT 4 January 15, 2009 11:48
REAL GAS UDF brian FLUENT 6 September 11, 2006 08:23


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