CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Programming & Development

pyFoam WriteParameterFile: Orders of entries

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   September 21, 2012, 12:31
Default pyFoam WriteParameterFile: Orders of entries
  #1
Member
 
Florian
Join Date: Nov 2009
Posts: 59
Rep Power: 7
Horus is on a distinguished road
Hello,

I use pyFoam's WriteParameterFile to write to the files in 0 directory (U, p, ...)

Code:
field_file = WriteParameterFile(field_name), className=_OF_units[field_name][1])
field_file["internalField"] = internalField
field_file["dimensions"] = dimensions

boundaryField = {}
# Fill boundaryField in a loop

field_file["boundaryField"] = boundaryField
field_file.writeFile()
My problem is that in thesulting field there is the boundaryField first and after that dimensions and internalField. Since I use $internalField as a value to several BCs this a problem since it can't be referenced before used. I also tried and changed the order in which I write I set the dictionaries entries in the field_file but it changed nothing.

Is there a way to change the order? It have to, cause the pyFoamCaseBuilder uses the "correct" order. (though python dictionaries do not have any order...)

Thanks!

Ok, kind of an addendum. I found that piece of code:

Code:
        if type(dic)==DictProxy:
            order=dic._order
        else:
            order=dic.keys()
            order.sort()
in PyFoam.Basics.FoamFileGenerator.FoamFileGenerator. strDict. So it seems to I need to use PyFoam DictProxy objects... Is that correct so far?
Horus is offline   Reply With Quote

Old   September 24, 2012, 18:31
Default
  #2
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,912
Rep Power: 40
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by Horus View Post
Hello,

I use pyFoam's WriteParameterFile to write to the files in 0 directory (U, p, ...)

Code:
field_file = WriteParameterFile(field_name), className=_OF_units[field_name][1])
field_file["internalField"] = internalField
field_file["dimensions"] = dimensions

boundaryField = {}
# Fill boundaryField in a loop

field_file["boundaryField"] = boundaryField
field_file.writeFile()
My problem is that in thesulting field there is the boundaryField first and after that dimensions and internalField. Since I use $internalField as a value to several BCs this a problem since it can't be referenced before used. I also tried and changed the order in which I write I set the dictionaries entries in the field_file but it changed nothing.

Is there a way to change the order? It have to, cause the pyFoamCaseBuilder uses the "correct" order. (though python dictionaries do not have any order...)

Thanks!

Ok, kind of an addendum. I found that piece of code:

Code:
        if type(dic)==DictProxy:
            order=dic._order
        else:
            order=dic.keys()
            order.sort()
in PyFoam.Basics.FoamFileGenerator.FoamFileGenerator. strDict. So it seems to I need to use PyFoam DictProxy objects... Is that correct so far?
You're right in the constructor of WriteParameterFile the line
self.content={}
should be replaced with
self.content=DictProxy()

DictProxy is a wrapper around a regular dictionary whose purpose it is to preserve the order of the entries (and preserve comments) and for purposes of output it will order the entries in the order they were added

Let me know if the fix works for you and I'll add it to the next release
__________________
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   September 26, 2012, 15:01
Default
  #3
Member
 
Florian
Join Date: Nov 2009
Posts: 59
Rep Power: 7
Horus is on a distinguished road
I have worked around it in another way.

After writing the internalField and dimensions I close the file and reopen it (as ParsedParameterFile). This keeps the entries so far in order that the ones that already existed are kept on top.
Horus is offline   Reply With Quote

Old   September 26, 2012, 15:30
Default
  #4
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,912
Rep Power: 40
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by Horus View Post
I have worked around it in another way.

After writing the internalField and dimensions I close the file and reopen it (as ParsedParameterFile). This keeps the entries so far in order that the ones that already existed are kept on top.
OK. But I've already implemented the fix (it was as easy as described above) and it will be in the next release
__________________
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

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
pyFoam and paraview eelcovv OpenFOAM Paraview & paraFoam 27 February 3, 2015 17:38
writeFile problem with PyFoam ganeshv OpenFOAM Running, Solving & CFD 3 August 20, 2012 17:07
pyFoam, pyFlu, extend: How does they relate? Horus OpenFOAM 9 May 21, 2011 12:49
pyFoam batch set up for OF 1.7 eelcovv OpenFOAM Running, Solving & CFD 3 January 19, 2011 09:38
pyFoam setting is not correct? or not compatible with 1.6? seasoul OpenFOAM 2 March 23, 2010 12:42


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