CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   writing subDict in a dictionary (https://www.cfd-online.com/Forums/openfoam-programming-development/81315-writing-subdict-dictionary.html)

ubaid October 22, 2010 16:21

writing subDict in a dictionary
 
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

ngj October 22, 2010 17:16

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

ubaid October 24, 2010 21:21

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,

wc34071209 October 25, 2014 17:17

Quote:

Originally Posted by ubaid (Post 280568)
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);



All times are GMT -4. The time now is 09:49.