|
[Sponsors] |
Programmatically create fvSolution dictionary |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
February 3, 2009, 10:22 |
Hi all,
I'm trying to program
|
#1 |
Member
Ivor Clifford
Join Date: Mar 2009
Location: Switzerland
Posts: 94
Rep Power: 17 |
Hi all,
I'm trying to programmatically create the fvSolution dictionary on OF-1.4.1-dev but I'm getting stuck with the individual solver entries since they consist of a keyword, token and dictionary, e.g. T PCG { ...... } I am able to create an entry with either the token ( T PCG; )or dictionary ( T { .... } ) but not one with both. I'm trying to avoid using the low level stream classes (ITstream, etc). I had a look in the FoamX source code for ideas on how they do it and they seem to have rewritten a lot of the working code using the low level stream classes for creating the dictionaries so I didn't have much luck there. My guess is I need to use the dictionary::add(const tokenList&) method but I don't know how to retrieve the token list for the subdictionary. Any suggestions would be appreciated. Thanks Ivor |
|
February 3, 2009, 10:31 |
Hi Ivor,
If you look closel
|
#2 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
Hi Ivor,
If you look closely, you'll see that they are not actually a 'dictionaryEntry', but rather a 'primitiveEntry' at the moment - the trailing ';' after the closing '}' is a hint here. Take a look under src/OpenFOAM/db/dictionary for the associated classes. |
|
February 3, 2009, 10:35 |
Hi, Have you looked at the PyF
|
#3 |
Senior Member
Kevin Smith
Join Date: Mar 2009
Posts: 104
Rep Power: 17 |
Hi, Have you looked at the PyFOAM utilities? I'm not sure if this accomplishes your goal but it is relatively easy to manipulate dictionaries using those libraries.
|
|
February 6, 2009, 11:06 |
Thanks for the responses.
Mar
|
#4 |
Member
Ivor Clifford
Join Date: Mar 2009
Location: Switzerland
Posts: 94
Rep Power: 17 |
Thanks for the responses.
Mark, I'd ideally like to create the dictionary portion of the primitiveEntry using the dictionary class, which will make the programming easier but I'm unable to convert that dictionary object to a tokenList so that I can append it to the solver type name. Any ideas? Kevin, this is exactly the approach I'm taking. Thanks for the PyFOAM idea though since oddly enough I was completely unaware of the existence of this contribution and am currently working on my own Swig wrappings for OF. Seems the work is being duplicated. I'll take a closer look at PyFoam. |
|
February 6, 2009, 11:44 |
Hi Ivor,
This file contains
|
#5 |
Senior Member
Eugene de Villiers
Join Date: Mar 2009
Posts: 725
Rep Power: 21 |
Hi Ivor,
This file contains some simple functions I use to write dictionaries so that they look "nice". I'm not 100% sure it will have everything you need, but it should give you a few clues. Let me know if you get stuck. |
|
February 6, 2009, 11:51 |
Hi Ivor,
Why not the really
|
#6 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
Hi Ivor,
Why not the really simple solution? os.writeKeyword("variableName"); os.write("solverName"); solverDict.write(os, true); os ... // write semi-colon Of course I would actually cheat a little bit and add the solver name directly into the dictionary of settings. It shows up twice on the output, but the solver itself will just ignore it and it make it much easier to write into a loop. The above code then looks like this os.writeKeyword("variableName"); os.write( solverDict.lookupOrDefault lt; word gt;("solver", "something") ); solverDict.write(os, true); os ... // write semi-colon Wrap all of this into a larger dictionary and/or class and it should work. |
|
February 8, 2009, 07:44 |
Hi Ivor!
If you're wrapping
|
#7 |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
Hi Ivor!
If you're wrapping OpenFOAM using Swig then PyFoam is NOT duplicating your effort. PyFoam only tries to control an OpenFOAM-run "from the outside": by reading it's output and manipulating directories. OK. It does a number of different things too, but I draw the line at anything that requires compilation to keep it as portable as possible and OF-version-agnostic. However: Hrv Jasak demonstrated a Python Wrapping to OpenFOAM at the Workshop in Milan this summer. So that might be a duplcation Bernhard
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request |
|
February 9, 2009, 03:24 |
Hi Ivor,
Maybe you want to
|
#8 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
Hi Ivor,
Maybe you want to look into cint as well. If you get it working with OpenFOAM, you could prototype (script) in interpreted C++, which could be compiled later as required. |
|
February 9, 2009, 05:33 |
Thanks Mark, but I must be mis
|
#9 |
Member
Ivor Clifford
Join Date: Mar 2009
Location: Switzerland
Posts: 94
Rep Power: 17 |
Thanks Mark, but I must be missing some intermediate step here. I now have an OStringStream which I can't add directly as an entry to the dictionary. Am I expected to go via file?
Bernhard, the Swig wrappings are based on Hrv's wrappings so no worries there, thanks. |
|
February 9, 2009, 05:37 |
Heya,
How about we add this
|
#10 |
Senior Member
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,907
Rep Power: 33 |
Heya,
How about we add this functionality into the solution.C so if you call it without the solver, the basic layout will be given. Hrv
__________________
Hrvoje Jasak Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk |
|
February 9, 2009, 05:51 |
Hi Hrv,
The thought of someth
|
#11 |
Member
Ivor Clifford
Join Date: Mar 2009
Location: Switzerland
Posts: 94
Rep Power: 17 |
Hi Hrv,
The thought of something along these lines had crossed my mind. We could potentially construct from a dictionary with an empty "solvers" subdictionary and include an addSolver method. Is this what you had in mind? Ivor |
|
February 9, 2009, 10:43 |
Yes, exactly: just give it an
|
#12 |
Senior Member
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,907
Rep Power: 33 |
Yes, exactly: just give it an empty constructor and create dictionaries on the fly.
I guess you can do that easily (please pass it over for a check-in). Hrv
__________________
Hrvoje Jasak Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk |
|
February 10, 2009, 10:17 |
Hi Ivor,
To convert a OStri
|
#13 |
Senior Member
Eugene de Villiers
Join Date: Mar 2009
Posts: 725
Rep Power: 21 |
Hi Ivor,
To convert a OStringStream to an entry: OStringStream something(<something>); primitiveEntry MyEntry ( "myEntryKeyWord", IStringStream(something.str())() ); Then it is simply: myDict.add(MyEntry); Easy! |
|
February 11, 2009, 08:40 |
Dear Hrvoje and all,
I read t
|
#14 |
New Member
Mariam Winkler
Join Date: Mar 2009
Posts: 4
Rep Power: 17 |
Dear Hrvoje and all,
I read the remarks about Swig wrappings with great interest. What kept me from getting proficient with Openfoam is to a good extent the solver codes and their use of included snippets that makes them difficult to understand - for me. Scripted Openfoam has definitely the potential to change that. Is the scripted version included in the openfoam-extend repositories? Mariam |
|
February 12, 2009, 03:50 |
Thanks all for your suggestion
|
#15 |
Member
Ivor Clifford
Join Date: Mar 2009
Location: Switzerland
Posts: 94
Rep Power: 17 |
Thanks all for your suggestions. I have updated the solution class with a NO_READ constructor and included addSolver and addRelaxationFactor methods.
solution-2009-02-12.tar.gz Also included in the archive is a test application. Regards Ivor |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
FvSolution pRefCell and pRefValue | maka | OpenFOAM Pre-Processing | 5 | February 17, 2015 04:00 |
General help for fvSchemes and fvSolution settings | harly | OpenFOAM Running, Solving & CFD | 4 | September 7, 2009 11:31 |
Dictionary | maka | OpenFOAM Bugs | 3 | February 18, 2009 11:26 |
[swak4Foam] FunkySetFields dictionary | gschaider | OpenFOAM Community Contributions | 14 | December 3, 2008 22:13 |
What must be defined in fvSolution | Marco Kupiainen (Kupiainen) | OpenFOAM Running, Solving & CFD | 1 | February 21, 2005 06:03 |