CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Community Contributions

[PyFoam] WriteParameterFile: Orders of entries

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 21, 2012, 13:31
Default WriteParameterFile: Orders of entries
  #1
Member
 
Florian
Join Date: Nov 2009
Posts: 59
Rep Power: 16
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, 19:31
Default
  #2
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
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, 16:01
Default
  #3
Member
 
Florian
Join Date: Nov 2009
Posts: 59
Rep Power: 16
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, 16:30
Default
  #4
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
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 Search this Thread
Search this Thread:

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[snappyHexMesh] Not all entries in refinementSurfaces dictionary were used will_ca OpenFOAM Meshing & Mesh Conversion 5 November 4, 2021 22:04
ill defined primitiveEntry starting at keyword 'value' on line 197 ChangeDictionary Struggle_Achieve OpenFOAM Pre-Processing 2 December 20, 2017 04:58
[Gmsh] different orders of mesh refinement using gmsh tjliang OpenFOAM Meshing & Mesh Conversion 0 August 14, 2016 13:38
How to divide all entries in 0/p by rho lentschi OpenFOAM 1 March 16, 2011 14:42
Accessing Individual entries in a post register sdwijeya STAR-CD 0 April 29, 2010 15:18


All times are GMT -4. The time now is 19:59.