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

Programmatically create fvSolution dictionary

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 3, 2009, 09:22
Default Hi all, I'm trying to program
  #1
Member
 
Ivor Clifford
Join Date: Mar 2009
Location: Switzerland
Posts: 94
Rep Power: 17
cliffoi is on a distinguished road
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
cliffoi is offline   Reply With Quote

Old   February 3, 2009, 09:31
Default Hi Ivor, If you look closel
  #2
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,685
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
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.
olesen is offline   Reply With Quote

Old   February 3, 2009, 09:35
Default Hi, Have you looked at the PyF
  #3
Senior Member
 
Kevin Smith
Join Date: Mar 2009
Posts: 104
Rep Power: 17
kev4573 is on a distinguished road
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.
kev4573 is offline   Reply With Quote

Old   February 6, 2009, 10:06
Default Thanks for the responses. Mar
  #4
Member
 
Ivor Clifford
Join Date: Mar 2009
Location: Switzerland
Posts: 94
Rep Power: 17
cliffoi is on a distinguished road
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.
cliffoi is offline   Reply With Quote

Old   February 6, 2009, 10:44
Default Hi Ivor, This file contains
  #5
Senior Member
 
Eugene de Villiers
Join Date: Mar 2009
Posts: 725
Rep Power: 21
eugene is on a distinguished road
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.


eugene is offline   Reply With Quote

Old   February 6, 2009, 10:51
Default Hi Ivor, Why not the really
  #6
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,685
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
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.
olesen is offline   Reply With Quote

Old   February 8, 2009, 06:44
Default Hi Ivor! If you're wrapping
  #7
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
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
gschaider is offline   Reply With Quote

Old   February 9, 2009, 02:24
Default Hi Ivor, Maybe you want to
  #8
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,685
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
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.
olesen is offline   Reply With Quote

Old   February 9, 2009, 04:33
Default Thanks Mark, but I must be mis
  #9
Member
 
Ivor Clifford
Join Date: Mar 2009
Location: Switzerland
Posts: 94
Rep Power: 17
cliffoi is on a distinguished road
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.
cliffoi is offline   Reply With Quote

Old   February 9, 2009, 04:37
Default Heya, How about we add this
  #10
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,905
Rep Power: 33
hjasak will become famous soon enough
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
hjasak is offline   Reply With Quote

Old   February 9, 2009, 04:51
Default Hi Hrv, The thought of someth
  #11
Member
 
Ivor Clifford
Join Date: Mar 2009
Location: Switzerland
Posts: 94
Rep Power: 17
cliffoi is on a distinguished road
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
cliffoi is offline   Reply With Quote

Old   February 9, 2009, 09:43
Default Yes, exactly: just give it an
  #12
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,905
Rep Power: 33
hjasak will become famous soon enough
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
hjasak is offline   Reply With Quote

Old   February 10, 2009, 09:17
Default Hi Ivor, To convert a OStri
  #13
Senior Member
 
Eugene de Villiers
Join Date: Mar 2009
Posts: 725
Rep Power: 21
eugene is on a distinguished road
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!
eugene is offline   Reply With Quote

Old   February 11, 2009, 07:40
Default Dear Hrvoje and all, I read t
  #14
New Member
 
Mariam Winkler
Join Date: Mar 2009
Posts: 4
Rep Power: 17
mariam is on a distinguished road
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
mariam is offline   Reply With Quote

Old   February 12, 2009, 02:50
Default Thanks all for your suggestion
  #15
Member
 
Ivor Clifford
Join Date: Mar 2009
Location: Switzerland
Posts: 94
Rep Power: 17
cliffoi is on a distinguished road
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
cliffoi is offline   Reply With Quote

Reply


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
FvSolution pRefCell and pRefValue maka OpenFOAM Pre-Processing 5 February 17, 2015 03:00
General help for fvSchemes and fvSolution settings harly OpenFOAM Running, Solving & CFD 4 September 7, 2009 10:31
Dictionary maka OpenFOAM Bugs 3 February 18, 2009 10:26
[swak4Foam] FunkySetFields dictionary gschaider OpenFOAM Community Contributions 14 December 3, 2008 21:13
What must be defined in fvSolution Marco Kupiainen (Kupiainen) OpenFOAM Running, Solving & CFD 1 February 21, 2005 05:03


All times are GMT -4. The time now is 03:43.