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

How to save a time-dependent scalar variable ?

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By Yann

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 5, 2015, 10:35
Default How to save a time-dependent scalar variable ?
  #1
Senior Member
 
Yann
Join Date: Apr 2012
Location: France
Posts: 1,200
Rep Power: 28
Yann will become famous soon enough
Hello Foamers,

I'm currently working on a custom solver and there is something I can't figure out.

The solver calculates and uses a scalar variable (a rotational speed). It works fine but since this variable isn't written anywhere, I can't stop a case and restart it later.

My first idea was to use an IOobject to write this variable with the other data in each time directory but I can't figure how. Since it's only a single scalar I have to use a IOdictionary but I'm unable to write data in it.

So dear experienced users, how would you deal with this ?
Any suggestions are welcome.

Thanks,
Yann
Kummi likes this.
Yann is offline   Reply With Quote

Old   May 5, 2015, 11:33
Default
  #2
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 try to use UniformDimensionedField [1]. Constructor [2] will fit, if you have scalar value, or [3] if you would like to read it. See $FOAM_SRC/src/finiteVolume/cfdTools/general/include/readGravitationalAcceleration.H for example of syntax.

1. http://foam.sourceforge.net/docs/cpp/a02750.html
2. http://foam.sourceforge.net/docs/cpp...767af9c8b8573a
3. http://foam.sourceforge.net/docs/cpp...12a8bffe2acdf7
alexeym is offline   Reply With Quote

Old   May 6, 2015, 13:19
Default
  #3
Senior Member
 
Yann
Join Date: Apr 2012
Location: France
Posts: 1,200
Rep Power: 28
Yann will become famous soon enough
Thanks for your reply Alexey. I'm going to try it but I might have the same problem.

I worked a bit on this dictionary thing. I work within a modified mixerGgiFvMesh class which inherits from the dynamicFvMesh class.
Here is how my dictionary is declared in myMixerGgiFvMesh.C :

Code:
myVarDict_
(
    IOdictionary
    (
        IOobject
        (
            "myVar",
            time().timeName(),
            *this,
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        )
    )
),
This works great : I can read and write "myVar" entry in the dictionary. But I'd like this dictionary to be written in a file in each time directory of my case. It doesn't work and my guess is that my dictionary isn't in the good registry since I work within the myMixerGgiFvMesh class. (correct me if I'm wrong)

But if I change "*this" to, lets say, "mesh()", I get an error when compiling saying :

Code:
error: ‘mesh’ was not declared in this scope
Am I wrong?
Any idea how to write the dictionary file in each time directory?

Thanks,
Yann
Yann is offline   Reply With Quote

Old   May 6, 2015, 14:01
Default
  #4
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
Example would be great. As if I declare this (quick modification of icoFoam solver)

Code:
    IOdictionary test
    (
        IOobject
        (
            "testVar",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        )
    );
and then do this:

Code:
test.set<scalar>("deltaT", runTime.deltaT().value());
dictionary testVar with line "deltaT <deltaT value>;" is written in every time folder.

Quote:
Code:
error: ‘mesh’ was not declared in this scope
Am I wrong?
Any idea how to write the dictionary file in each time directory?
mixerGgiFvMesh is a child of dynamicFvMesh which in turn is a child of fvMesh, so there is no mesh() method. You can try to use thisDb() instead of *this, it will be registry of the fvMesh class.
alexeym is offline   Reply With Quote

Old   May 7, 2015, 04:56
Default
  #5
Senior Member
 
Yann
Join Date: Apr 2012
Location: France
Posts: 1,200
Rep Power: 28
Yann will become famous soon enough
Thanks again for your kind help Alexey.

I already tried to use thisDb() instead of *this but it doesn't change anything, the dictionary isn't written in time folders.

But I'm sure my dictionary is properly declared since the first value is read from the "0" folder and if I do a :

Code:
Info<< "reading myVarDict : " << readScalar(myVarDict_.lookup("myVar")) << endl;
The correct value is prompted in the terminal during simulation. So it seems it's really a matter of being able to write this dictionary in the proper folder...
Yann is offline   Reply With Quote

Reply


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
Transient simulation not converging skabilan OpenFOAM Running, Solving & CFD 14 December 17, 2019 00:12
AMI interDyMFoam for mixer nu problem danny123 OpenFOAM Programming & Development 8 September 6, 2013 03:34
How to write k and epsilon before the abnormal end xiuying OpenFOAM Running, Solving & CFD 8 August 27, 2013 16:33
dynamic Mesh is faster than MRF???? sharonyue OpenFOAM Running, Solving & CFD 14 August 26, 2013 08:47
emag beta feature: charge density charlotte CFX 4 March 22, 2011 10:14


All times are GMT -4. The time now is 05:59.