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

Problem writing to dictionary

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 14, 2016, 11:17
Question Problem writing to dictionary
  #1
New Member
 
Rasmus Andersson
Join Date: Apr 2016
Posts: 3
Rep Power: 10
MrAndersson is on a distinguished road
Hello!

I am developing an OpenFOAM model for electrolytes and in this context one module predicts diffusivities and is supposed to write its results to a dictionary for others to read. Writing to dictionaries seems straight-forward enough, but for some reason I can't get it to work. This is how I define the IODictionary to be written to:

Code:
IOdictionary electrolyteProperties
(
    IOobject
    (
        "electrolyteProperties",
        runTime.constant(),
        mesh,
        IOobject::MUST_READ_IF_MODIFIED,
        IOobject::NO_WRITE
    )
);
I then define a subdictionary "DDict" inside "electrolyteDict":

Code:
dictionary& DDict = electrolyteProperties.subDict("D");
DDict contains dimensions and values of diffusivities for different species and may look something like this:

Code:
D
{
    dimensions    [ 0  2 -1  0  0  0  0];
    values
        (
            1e-12
            1e-12
            1e-12
        );
}
I try to write the entry by using set:

Code:
 electrolyteProperties.set("values",DVals);
A printout of DVals gives:

Code:
DVals: 3(4.34118e-12 4.56812e-12 3.49564e-12)
which is what I want to write to the dictionary. The whole thing compiles without warning and runs without problems, the values just never get changed to the calculated ones. I have also tried to write directly to the parent dictionary (electrolyteProperties) to see whether the problem has to do with the usage of subDict, but that doesn't work either.

Anyone have an idea of what may cause my problem?
MrAndersson is offline   Reply With Quote

Old   April 14, 2016, 11:54
Default
  #2
New Member
 
Rasmus Andersson
Join Date: Apr 2016
Posts: 3
Rep Power: 10
MrAndersson is on a distinguished road
Actually, printing the dictionary (using Info) gives exactly what I want, but it never ends up in the file. Do I need to call some write function of some sort? Just writing DDict.write() or electrolyteProperties.write() does not work, then the compiler complains that function call is ambiguous.
MrAndersson is offline   Reply With Quote

Old   April 14, 2016, 16:57
Default
  #3
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,938
Rep Power: 39
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

You can resolve write method ambiguity, for example, like this:

Code:
  IOdictionary electrolyteProperties
  (
      IOobject
      (
          "electrolyteProperties",
          runTime.constant(),
          mesh,
          IOobject::MUST_READ_IF_MODIFIED,
          IOobject::NO_WRITE
      )
  );

  dictionary& DDict = electrolyteProperties.subDict("D");

  scalarList DVals;
  ... fill DVals ...
  DDict.set("values", DVals);
  electrolyteProperties.regIOobject::write();
alexeym is offline   Reply With Quote

Old   April 15, 2016, 07:00
Default
  #4
New Member
 
Rasmus Andersson
Join Date: Apr 2016
Posts: 3
Rep Power: 10
MrAndersson is on a distinguished road
Thanks a lot Alexey! That solved my problem.

/Rasmus
MrAndersson is offline   Reply With Quote

Old   September 12, 2017, 16:46
Default declaration issues with update code
  #5
Senior Member
 
Klaus
Join Date: Mar 2009
Posts: 281
Rep Power: 22
klausb will become famous soon enough
Hello,

I run into compile errors with this code which I want to use to update some values in a dictionary:

code:

Code:
// IO test changing p-minIter value in fvSolutions file

// Declare dictionary
IOdictionary fvSolution(IOobject("fvSolution",runTime.system(),mesh,IOobject::NO_READ,IOobject::AUTO_WRITE));

// Declare subdictionary
dictionary mySubDictUpdate(fvSolution.subDict("p"));

// Update some values
mySubDictUpdate.set("minIter", 33 );
mySubDictUpdate.set("maxIter", 500 );
errors:

myPCG_solve.C:111:1: error: ‘IOdictionary’ was not declared in this scope
IOdictionary fvSolution(IOobject("fvSolution",runTime.system(), mesh,IOobject::NO_READ,IOobject::AUTO_WRITE));
^
myPCG_solve.C:114:1: error: ‘dictionary’ was not declared in this scope
dictionary mySubDictUpdate(fvSolution.subDict("p"));

myPCG_solve.C:117:1: error: ‘mySubDictUpdate’ was not declared in this scope
mySubDictUpdate.set("minIter", 33 );
^
myPCG_solve.C:122:1: error: ‘fvSolution’ was not declared in this scope
fvSolution.Foam::IOobject::write();
^
myPCG_solve.C:122:18: error: ‘Foam::IOobject’ has not been declared
fvSolution.Foam::IOobject::write();

How can I declare the object and dictionaries "in this scope"?

Klaus
klausb is offline   Reply With Quote

Reply

Tags
dictionaries, write data, write to file


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
How to Mix AIR and WATER Elvis1991 FLUENT 12 December 1, 2016 13:28
Writing udf for Transient Heat conduction boundary value problem abhi12019 FLUENT 3 October 7, 2015 10:10
writing subDict in a dictionary ubaid OpenFOAM Programming & Development 3 October 25, 2014 18:17
[Other] Problem with the dictionary file sfigato OpenFOAM Meshing & Mesh Conversion 5 January 17, 2013 09:55
Problem while writing pressure file "buoyantPressure" ubaid OpenFOAM 0 October 2, 2010 15:07


All times are GMT -4. The time now is 16:24.