|
[Sponsors] |
November 17, 2009, 08:27 |
Extension to foamInfoExec/changeDictionary?
|
#1 |
Member
Niklas Wikstrom
Join Date: Mar 2009
Posts: 86
Rep Power: 17 |
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 |
|
November 18, 2009, 14:01 |
|
#2 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
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 |
||
November 19, 2009, 04:34 |
|
#3 |
Member
Niklas Wikstrom
Join Date: Mar 2009
Posts: 86
Rep Power: 17 |
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 |
|
November 19, 2009, 04:40 |
|
#4 |
Member
Niklas Wikstrom
Join Date: Mar 2009
Posts: 86
Rep Power: 17 |
BTW, I might have found a way using dictionary::add(...,true)...
|
|
November 19, 2009, 05:10 |
|
#5 |
Senior Member
Dr. Fabian Schlegel
Join Date: Apr 2009
Location: Dresden, Germany
Posts: 222
Rep Power: 18 |
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 |
|
November 19, 2009, 05:23 |
|
#6 | |
Assistant Moderator
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51 |
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 |
||
Thread Tools | Search this Thread |
Display Modes | |
|
|
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 |