|
[Sponsors] |
January 31, 2012, 06:10 |
How to access keywords from dictionaries
|
#1 |
Member
Francesco Capuano
Join Date: May 2010
Posts: 81
Rep Power: 15 |
Hi all,
I'm writing a custom application in OF and, just after the typical "include" list of files, I would like to access a keyword from a dictionary, e.g. the divergence scheme for div(phi,U). So I write const dictionary& fvSchemes = db().lookupObject("fvSchemes") so that, afterwards, I could call fvSchemes.lookup("div(phi,U)") However, the compiler complains: db not declared in this scope How can I define the database object? Thanks in advance. |
|
January 31, 2012, 11:37 |
|
#2 | |
Senior Member
Tomislav Maric
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 284
Blog Entries: 5
Rep Power: 21 |
Quote:
Code:
const objectRegistry& db = mesh.thisDb(); And be careful, inside the src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C, you'll see that the lookupObject is a templated function, so, provide the proper template argument (your code above won't work even after you get a ref to db()): Code:
const IOdictionary& fvSchemes = db.lookupObject<IOdictionary>("fvSchemes"); T. Last edited by tomislav_maric; January 31, 2012 at 12:03. |
||
January 31, 2012, 15:34 |
|
#3 |
Member
Francesco Capuano
Join Date: May 2010
Posts: 81
Rep Power: 15 |
Dear Tomislav,
thanks a lot for your clear and accurate reply. Actually there was another mistake in my code: one should use the subDict function of the dictionary class to extract keywords from the divSchemes sub-dictionary. So, for those interested, the final working code is: const objectRegistry& db = mesh.thisDb(); const IOdictionary& fvSchemes = db.lookupObject<IOdictionary>("fvSchemes"); dictionary divSchemes = fvSchemes.subDict("divSchemes"); word scheme(divSchemes.lookup("div(phi,U")); I have one more question: with this method, if the div(phi,U) value is, for instance, "Gauss linear", only "Gauss" is caught. How can you catch the entire entry, even if it consists of more than one word? |
|
October 25, 2014, 17:05 |
|
#4 | |
Senior Member
Yuehan
Join Date: Nov 2012
Posts: 142
Rep Power: 13 |
Quote:
|
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Online libraries - with access to Journals | momentum_waves | Main CFD Forum | 2 | December 12, 2007 10:08 |
UDF Data Access Macro | Woo Meng Wai | FLUENT | 0 | November 6, 2007 20:23 |
Error: access: unbound variable,HELP | sudhakar | FLUENT | 0 | January 15, 2007 23:21 |
Access Density | Allan Walsh | FLUENT | 3 | October 4, 2005 07:55 |
access to variables at interface of porous media? | Mazyar | FLUENT | 0 | October 10, 2003 14:59 |