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

Extension to foamInfoExec/changeDictionary?

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

Reply
 
LinkBack Thread Tools Display Modes
Old   November 17, 2009, 08:27
Default Extension to foamInfoExec/changeDictionary?
  #1
Member
 
Niklas Wikstrom
Join Date: Mar 2009
Posts: 85
Rep Power: 8
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: 3,912
Rep Power: 40
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: 85
Rep Power: 8
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: 85
Rep Power: 8
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
 
Fabian Schlegel
Join Date: Apr 2009
Location: Dresden, Germany
Posts: 180
Rep Power: 8
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: 3,912
Rep Power: 40
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

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
Native ParaView Reader Bugs tj22 OpenFOAM Paraview & paraFoam 266 July 1, 2015 02:00
HowTo Make paraFoam from OpenFOAM15 work on OpenSuse11 by installing Qt435 in home directory wenterodt OpenFOAM Installation 52 June 26, 2009 17:01
Xwindows crash with paraview save srinath OpenFOAM Paraview & paraFoam 1 October 15, 2008 09:37
CAPTCHA extension activated Jonas Larsson CFD-Wiki 0 June 15, 2007 18:20
Extension of interpolation files Ale FLUENT 0 October 15, 2003 09:07


All times are GMT -4. The time now is 00:43.