|
[Sponsors] |
June 5, 2020, 11:10 |
double name entry in dict demanded
|
#1 |
Member
alexander thierfelder
Join Date: Dec 2019
Posts: 71
Rep Power: 7 |
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; // ************************************************************************* // 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") ); Code:
R = plasmaTuningDict.lookup("R"); Vmax = plasmaTuningDict.lookup("Vmax"); Code:
R [1 2 -3 0 0 -2 0] 1320.0; Vmax [1 2 -3 0 0 -1 0] 1000.0; 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 |
|
June 6, 2020, 01:17 |
Problem with the assignment
|
#2 |
New Member
Sen Wang
Join Date: Jul 2018
Location: Singapore / Notre Dame, U.S.
Posts: 20
Blog Entries: 1
Rep Power: 8 |
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) When you call Code:
R = plasmaTuningDict.lookup("R") Code:
[1 2 -3 0 0 -2 0] 1320.0 Code:
dimensioned(Istream &is) 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')) Last edited by wangsen992; June 6, 2020 at 04:31. Reason: Suggestion for code modification |
|
June 6, 2020, 06:34 |
|
#3 |
Member
alexander thierfelder
Join Date: Dec 2019
Posts: 71
Rep Power: 7 |
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; 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") ); 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 Code:
dimensioned ( const primitiveEntry & e) https://www.openfoam.com/documentati...tiveEntry.html I am no pro in OF and C++, so feel free to correct me ^^. |
|
Tags |
dictionaries |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
fvOptions | npatricia | OpenFOAM | 6 | May 23, 2018 06:21 |
CFD by anderson, chp 10.... supersonic flow over flat plate | varunjain89 | Main CFD Forum | 18 | May 11, 2018 08:31 |
Warning message C4133 while compiling | Arminius | Fluent UDF and Scheme Programming | 0 | October 2, 2017 12:44 |
Missing math.h header | Travis | FLUENT | 4 | January 15, 2009 12:48 |
REAL GAS UDF | brian | FLUENT | 6 | September 11, 2006 09:23 |