|
[Sponsors] |
February 6, 2015, 04:50 |
Add to a list in IOdictionary
|
#1 |
New Member
Sindre Tosse
Join Date: Sep 2014
Posts: 6
Rep Power: 11 |
Hi fellow foamers,
I am trying to figure out how to add an entry to a list in an IOdictionary. Specifically, I am trying to add a dictionary to the "actions" list in an allready existing topoSetDict (see example below), possibly also modifying an existing entry. How would I do this? I know how to add to and modify a dictionary, but I can't figure out how to do the same with a list. before: Code:
actions ( { name foo; etc. } ); Code:
actions ( { name foo; etc. } { name bar; etc. } ); Sindre |
|
February 6, 2015, 12:02 |
|
#2 |
New Member
Ramon
Join Date: Feb 2014
Location: Eindhoven
Posts: 25
Rep Power: 12 |
Hello Sindre,
I am not sure how to do what you requested (and perhaps I misunderstood your request), but is it not possible to make your dict like this? Code:
names ( foo bar ); foo { action_foo; }; bar { action_bar; }; Kind regards, Ramon |
|
February 9, 2015, 02:49 |
|
#3 |
New Member
Sindre Tosse
Join Date: Sep 2014
Posts: 6
Rep Power: 11 |
Hi Ramon,
No, the formatting of the dictionary is set. I figured out how to modify entries in a list of dictionaries. The below example adds a field "test" which is true if the name of the dict is "baffleFaces" and false otherwise. However, when the dictionary is written, all formatting (e.g. line breaks and whitespace) disappears, so the topoSetDict becomes very ugly Code:
IOdictionary topoSetDict ( IOobject ( "topoSetDict", runTime.system(), runTime, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE ) ); PtrList<dictionary> actions(topoSetDict.lookup("actions")); const word bfname = "baffleFaces"; for(int i; i<actions.size(); i++){ const word name = actions[i].lookup("name"); if (name.compare(bfname)==0){ actions[i].add("test", "true", true); } else{ actions[i].add("test", "false", true); } } topoSetDict.add("actions", actions, true); //true flag merges dictionaries topoSetDict.regIOobject::write(); |
|
March 17, 2021, 05:11 |
write list of dictionaries as one keyword per line
|
#4 |
New Member
Sarath
Join Date: Mar 2017
Location: Spain
Posts: 22
Rep Power: 9 |
I could do this using creating a list of dictionaries and adding them by append().
for example : Code:
List<dictionary> actions; dictionary actionDict; actionDict.add("name",foo); ... actions.append(actionDict); topoSetSict.add("actions",actions,true); topoSetDict.regIOobject::write(); Is there a way to control how lists of dictionaries (or entries) are written to the file? for example, cellSet dict files generated by topoSet contains a list of labels with one label per line. |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[swak4Foam] difficulties installing swak4foam | newbie29 | OpenFOAM Community Contributions | 120 | October 21, 2022 04:01 |
Help for the small implementation in turbulence model | shipman | OpenFOAM Programming & Development | 25 | March 19, 2014 10:08 |
[swak4Foam] funkySetFields compilation error | tayo | OpenFOAM Community Contributions | 39 | December 3, 2012 05:18 |
CFX problem in ubuntu (linux) | Vigneshramaero | CFX | 0 | July 13, 2012 10:22 |
Read inside a class | tonyuprm | OpenFOAM | 12 | July 14, 2010 02:35 |