Check current time
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!
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...
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
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:
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?
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.
Ok, it's solved.
Finally I added an argument to the method. If someone is interested, at:
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...
|All times are GMT -4. The time now is 18:53.|