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

writing subDict in a dictionary

Register Blogs Community New Posts Updated Threads Search

Like Tree6Likes
  • 1 Post By ngj
  • 4 Post By ubaid
  • 1 Post By wc34071209

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 22, 2010, 17:21
Default writing subDict in a dictionary
  #1
New Member
 
Nadeem
Join Date: Mar 2009
Location: München, Bavarian, Deutschland
Posts: 24
Rep Power: 17
ubaid is on a distinguished road
Hello Everybody,

I am trying to write subDict inside a dictionary. I know how to setup a dictionary but dont know how to add a subDict inside the dictionary.

Say for example, i want to write RASProperties file as below.

RASModel laminar;
turbulence off;

KOmegaCoeffs
{
beta = 0.04;
}

for declaring dictionary one do as follows.

IOdictionary RASProperties(IOobject("RASProperties",runTime.con stant(),mesh,IOobject::NO_READ,IOobject::AUTO_WRIT E));

RASProperties.set("RASModel","laminar");
RASProperties.ser("turbulence","off");

this write the file.
RASProperties.Foam::IOobject::write();

I did till here...

But i am not getting how to add following section inside this same dictionary.

KOmegaCoeffs
{
beta = 0.04;
}

Please let me know how to add subDict inside a IOdictionary.

Thanks a lot in advance
ubaid is offline   Reply With Quote

Old   October 22, 2010, 18:16
Default
  #2
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,903
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
Hi Nadeem

I assume you mean that you want to figure out how to access a sub-dictionary? Just apply the subDict method of, e.g.

dictionary mySubDict(RASProperties.subDict("subDictName"));

Good luck

Niels
ykanani likes this.
ngj is offline   Reply With Quote

Old   October 24, 2010, 22:21
Default
  #3
New Member
 
Nadeem
Join Date: Mar 2009
Location: München, Bavarian, Deutschland
Posts: 24
Rep Power: 17
ubaid is on a distinguished road
Thanks a lot for the reply.

Well, I know how to read, but i wanted to add a directory inside another directory. but now i got it, how to do it. its like following.

IOdictionary dict1;
IOdictionary dict2;

dict1.add("x",x_value);
dict1.add("y",y_value);

dict2.add("z",value);

dict1.add("dict2asSUBDICT",dict2);

output will be...

x x_value;
y y_value;

dict2asSUBDICT
{
z z_value;
}

I hope it works if someone else needs it...

Best Regards,
ubaid is offline   Reply With Quote

Old   October 25, 2014, 18:17
Default
  #4
Senior Member
 
Yuehan
Join Date: Nov 2012
Posts: 142
Rep Power: 14
wc34071209 is on a distinguished road
Quote:
Originally Posted by ubaid View Post
Thanks a lot for the reply.

Well, I know how to read, but i wanted to add a directory inside another directory. but now i got it, how to do it. its like following.

IOdictionary dict1;
IOdictionary dict2;

dict1.add("x",x_value);
dict1.add("y",y_value);

dict2.add("z",value);

dict1.add("dict2asSUBDICT",dict2);

output will be...

x x_value;
y y_value;

dict2asSUBDICT
{
z z_value;
}

I hope it works if someone else needs it...

Best Regards,
I think the more decent way might be

Code:
IOdictionary RASProperties(IOobject("RASProperties",runTime.con  stant(),mesh,IOobject::NO_READ,IOobject::AUTO_WRIT  E));

dictioanry  tmpDict;

RASProperties.add("RASModel","laminar");
RASProperties.add("turbulence","off");

tmpDict.add("beta", "0.04");


RASProperties.add("KOmegaCoeffs", tmpDict);
bowen likes this.
wc34071209 is offline   Reply With Quote

Reply

Tags
dictionary, iodictionary, komegacoeffs, subdict


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
solid to fluid heattransfer with chtMultiRegionFoam nakor OpenFOAM 11 March 21, 2011 09:28
Reading from User Defined Dictionary File brosemu OpenFOAM Running, Solving & CFD 2 March 30, 2009 16:25
Problem with rhoSimpleFoam matteo_gautero OpenFOAM Running, Solving & CFD 0 February 28, 2008 07:51
Fatal error error writing to tmp No space left on device maka OpenFOAM Installation 2 April 3, 2006 09:48
FoamX error aachenBomb case Ervin Adorean (Adorean) OpenFOAM Pre-Processing 13 March 7, 2005 04:50


All times are GMT -4. The time now is 14:34.