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

Extension to foamInfoExec/changeDictionary?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 17, 2009, 08:27
Default Extension to foamInfoExec/changeDictionary?
  #1
Member
 
Niklas Wikstrom
Join Date: Mar 2009
Posts: 86
Rep Power: 17
wikstrom is on a distinguished road
Hi,

I'd like a utility to add or change values of entries in a dictionary. I.e. I would like to write an application similar to foamInfoExec but with a "-set" (and possibly an "-insert") option. This would be a changeDictionary-ish util reading the command line.

Does someone have something similar for me to learn from? I keep getting tangled up in pointers and virtuals...

best regards
Niklas
wikstrom is offline   Reply With Quote

Old   November 18, 2009, 14:01
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 wikstrom View Post
Hi,

I'd like a utility to add or change values of entries in a dictionary. I.e. I would like to write an application similar to foamInfoExec but with a "-set" (and possibly an "-insert") option. This would be a changeDictionary-ish util reading the command line.

Does someone have something similar for me to learn from? I keep getting tangled up in pointers and virtuals...

best regards
Niklas
Why do you want to bring a gun to knife-fight? In other words: write a C++-program for something that can be easily (without compiling) done with a script (those who know me will say "Oh, my god. There he goes again with that PyFoam" and they are right).
A simple example for manipulating dictionaries can be found at
http://openfoamwiki.net/index.php/Co...ions_for_walls

There is a read-made utility pyFoamWriteDictionary.py for setting single values in a dictionary, but it has its drawbacks

Bernhard
gschaider is offline   Reply With Quote

Old   November 19, 2009, 04:34
Default
  #3
Member
 
Niklas Wikstrom
Join Date: Mar 2009
Posts: 86
Rep Power: 17
wikstrom is on a distinguished road
Hi Bernhard,

simply because the dictionary and IO framework is already there in OpenFOAM. I really appreciate PyFOAM (encores!) and love python, but nevertheless find it neat to do OpenFOAM stuff within OpenFOAM.


Cheers
Niklas
wikstrom is offline   Reply With Quote

Old   November 19, 2009, 04:40
Default
  #4
Member
 
Niklas Wikstrom
Join Date: Mar 2009
Posts: 86
Rep Power: 17
wikstrom is on a distinguished road
BTW, I might have found a way using dictionary::add(...,true)...
wikstrom is offline   Reply With Quote

Old   November 19, 2009, 05:10
Default
  #5
Senior Member
 
Dr. Fabian Schlegel
Join Date: Apr 2009
Location: Dresden, Germany
Posts: 222
Rep Power: 18
fs82 is on a distinguished road
Check your OpenFoam Source directory. There are bash scripts which manipulate the dictionaries. They provide a whole bunch of functions for this task: For example the script: foamEndJob. There you could find for example:

setRawEntry() {
oldNumLine=`getNumberedLine $1 "$2"`
lineNo=`echo "$oldNumLine" | sed -e 's/:.*//'`
oldLine=`echo "$oldNumLine" | sed -e 's/^[^:]*://'`
oldKey=`getKey "$oldLine"`
oldVal=`getRawEntry $1 "$2"`
if [ ! "$oldKey" -o ! "$oldVal" -o ! "$oldLine" ]; then
echo "setRawStringEntry: entry $2 not found in $1"
echo "oldKey=$oldKey"
echo "lineNo=$lineNo"
echo "oldLine=$oldLine"
exit 1
fi
#echo "oldKey=$oldKey"
#echo "lineNo=$lineNo"
#echo "oldLine=$oldLine"
#echo "oldVal=$oldVal"
mv $1 ${1}_tmp
sed -e "${lineNo}s/ ${oldVal}/ $3;/" ${1}_tmp > $1
rm -f ${1}_tmp
}

This function sets an exiting entry to a new value. But there are many more and it should be easy to adopt this to your case :-D
fs82 is offline   Reply With Quote

Old   November 19, 2009, 05:23
Default
  #6
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 Niklas

Don't get me wrong. This is not about advertising Python/PyFoam it was about choosing the appropriate language for the job. If you have a look at http://wwwipd.ira.uka.de/~prechelt/Biblio/jccpprtTR.pdf Figure 15 (just the first example I stumbled upon) you will see that if you want to get a programming job done quickly almost any scripting language is better than C++. The advantage of C++ is the pure speed (and you don't need that for dictionary manipulation)

Quote:
Originally Posted by wikstrom View Post
simply because the dictionary and IO framework is already there in OpenFOAM. I really appreciate PyFOAM (encores!) and love python, but nevertheless find it neat to do OpenFOAM stuff within OpenFOAM.
So if you see it as a way to get to know the OF-classes it is alright

Bernhard
gschaider 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
[OpenFOAM] Native ParaView Reader Bugs tj22 ParaView 270 January 4, 2016 12:39
HowTo Make paraFoam from OpenFOAM15 work on OpenSuse11 by installing Qt435 in home directory wenterodt OpenFOAM Installation 52 June 26, 2009 18:01
[OpenFOAM] Xwindows crash with paraview save srinath ParaView 1 October 15, 2008 10:37
CAPTCHA extension activated Jonas Larsson CFD-Wiki 0 June 15, 2007 19:20
Extension of interpolation files Ale FLUENT 0 October 15, 2003 10:07


All times are GMT -4. The time now is 08:17.