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

Check current time

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By ngj

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 13, 2012, 04:43
Default Check current time
  #1
New Member
 
Jordi Muela
Join Date: Mar 2011
Posts: 27
Rep Power: 16
jordi.muela is on a distinguished road
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!

Thanks!!

Best regards,

Jordi.

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...

Last edited by jordi.muela; March 13, 2012 at 06:05.
jordi.muela is offline   Reply With Quote

Old   March 13, 2012, 04:59
Default
  #2
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,903
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
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

Code:
mesh_.time().value()
or if you are not having the mesh, but some other object, say U, then use

Code:
U_.thisDb().time().value()
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,

Niels
Kummi likes this.
ngj is offline   Reply With Quote

Old   March 13, 2012, 06:03
Default
  #3
New Member
 
Jordi Muela
Join Date: Mar 2011
Posts: 27
Rep Power: 16
jordi.muela is on a distinguished road
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:

/src/postProcessing/functionObjects/forces/pointPatchFields/derived/sixDoFRigidBodyMotion/sixDoFRigidBodyMotionRestraint/linearSpring$

Best regards,

Jordi.
jordi.muela is offline   Reply With Quote

Old   March 13, 2012, 06:20
Default
  #4
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,903
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
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?

Bests,

Niels
ngj is offline   Reply With Quote

Old   March 13, 2012, 07:35
Default
  #5
New Member
 
Jordi Muela
Join Date: Mar 2011
Posts: 27
Rep Power: 16
jordi.muela is on a distinguished road
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.
jordi.muela is offline   Reply With Quote

Old   March 13, 2012, 08:26
Default
  #6
New Member
 
Jordi Muela
Join Date: Mar 2011
Posts: 27
Rep Power: 16
jordi.muela is on a distinguished road
Hi All,

Ok, it's solved.

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

sixDoFRigidBodyDisplacementPointPatchVectorField.C
uncoupledSixDoFRigidBodyDisplacementPointPatchVect orField.C

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

motion_.updateForce
(
fm.first().first() + fm.first().second() + g_*motion_.mass(),
fm.second().first() + fm.second().second(),
t.deltaTValue(),
//Modified
t.value()
);

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

Best regards,

Jordi
jordi.muela 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
Multiple floating objects CKH OpenFOAM Running, Solving & CFD 14 February 20, 2019 10:08
Set current time step tsram90 FLUENT 0 November 11, 2011 11:19
calculation diverge after continue to run zhajingjing OpenFOAM 0 April 28, 2010 05:35
Could anybody help me see this error and give help liugx212 OpenFOAM Running, Solving & CFD 3 January 4, 2006 19:07
How to read out time used for current solution Angelo Sozzi FLUENT 1 July 7, 2004 14:16


All times are GMT -4. The time now is 17:03.