CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Programming & Development (
-   -   Check current time (

jordi.muela March 13, 2012 04:43

Check current time
Hi all,

I'm programming a new class for six DoF motion to allow socket comunication for cosimulation with other tool (exchanging force data..). And I'm having a trouble, how can I consult the current time value?

Now I'm doing a little (...big!) trick using system():

system("grep 'Time = ' log.interDyMFoam | tail -n 1 | sed 's/Time = //g' > calcTime");

and then I can read the time from file calcTime, but I thought must be a better and elegant way... I've taked a look to "timeVaryingUniformFixedValuePointPatchField" since this BC must consult the time to do the proper interpolation, and it looks like the solution must come from a function called db(), which is declared in "pointPatchField"... but I'm falling in black-hole of classes and I can't see the light. So please, if somebody can show me the way of do this I'll be very pleased!


Best regards,


Edit: now I see that I've had a lapsus with thread title, I'm interested in the actual time, no in time step! Thanks! And sorry the mistake...

ngj March 13, 2012 04:59

Hi Jordi

I do not know if I completely understand your problem. Do you want to have the current time in seconds? Then you can merely write


or if you are not having the mesh, but some other object, say U, then use


If you omit the "value()" part of the call, you will get a dimensionedScalar, however, if you add value(), the dimensional information is stripped and you achieve a scalar.

Best regards,


jordi.muela March 13, 2012 06:03

Hi Niels!

First of all, thanks for your quick answer.

Yes, that's exactly what I want, the current time in seconds.

Unfortunatelly, I don't have the mesh or some other object like U or p, I only have some vars like "int port_; string host_; ...". I've tried "thisDb().time().value()" but as I thought doesn't compile... To make you an idea, my C files are similar to:


Best regards,


ngj March 13, 2012 06:20

Hi Jordi

I do not know if will work, but try doing the thisDb on the dictionary. It is not a IOdictionary, but you might be able to exploit it.

Otherwise, you need to call the object with the current time as an argument? Or construct with e.g. the mesh?



jordi.muela March 13, 2012 07:35

Hi Niels,

I've added an object "const dictionary sDoFRBMLDict_;" and at constructor assigned the value of the dictionary "sDoFRBMLDict_(sDoFRBMLDict)", and used sDoFRBMLDict_.thisDb().time().value(); but the compiler says:

error: ‘const class Foam::dictionary’ has no member named ‘thisDb’

So I guess that I have two options, continue using the actual "dirty" way or as you propose construct the object for example with the mesh.... but I intended to modify less layers of code as possible... I have to look how to do it!
Well it looks that will be harder than I thought :) As "backup method" the dirty way works jeje.

Thanks for your help Niels.


jordi.muela March 13, 2012 08:26

Hi All,

Ok, it's solved.

Finally I added an argument to the method. If someone is interested, at:

uncoupledSixDoFRigidBodyDisplacementPointPatchVect orField.C

in updateCoeffs() function you can find const Time& t = mesh.time(); and when call motion_.updateForce:

fm.first().first() + fm.first().second() + g_*motion_.mass(),
fm.second().first() + fm.second().second(),

then make the appropriate modifications to sixDoFRigidBodyMotion.C, sixDoFRigidBodyMotion.H and proper subfiles...

Best regards,


All times are GMT -4. The time now is 07:58.