Hi all,
I'm trying to program
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 |
Hi Ivor,
If you look closel
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. |
Hi, Have you looked at the PyF
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.
|
Thanks for the responses.
Mar
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. |
Hi Ivor,
This file contains
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. |
Hi Ivor,
Why not the really
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. |
Hi Ivor!
If you're wrapping
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 |
Hi Ivor,
Maybe you want to
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. |
Thanks Mark, but I must be mis
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. |
Heya,
How about we add this
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 |
Hi Hrv,
The thought of someth
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 |
Yes, exactly: just give it an
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 |
Hi Ivor,
To convert a OStri
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! |
Dear Hrvoje and all,
I read t
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 |
Thanks all for your suggestion
Thanks all for your suggestions. I have updated the solution class with a NO_READ constructor and included addSolver and addRelaxationFactor methods.
http://www.cfd-online.com/OpenFOAM_D...hment_icon.gif solution-2009-02-12.tar.gz Also included in the archive is a test application. Regards Ivor |
All times are GMT -4. The time now is 18:19. |