Extension to foamInfoExec/changeDictionary?
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 |
Quote:
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 |
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 |
BTW, I might have found a way using dictionary::add(...,true)...
|
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 |
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:
Bernhard |
All times are GMT -4. The time now is 10:23. |