|
[Sponsors] |
March 13, 2012, 04:43 |
Check current time
|
#1 |
New Member
Jordi Muela
Join Date: Mar 2011
Posts: 27
Rep Power: 16 |
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. |
|
March 13, 2012, 04:59 |
|
#2 |
Senior Member
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,903
Rep Power: 37 |
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() Code:
U_.thisDb().time().value() Best regards, Niels |
|
March 13, 2012, 06:03 |
|
#3 |
New Member
Jordi Muela
Join Date: Mar 2011
Posts: 27
Rep Power: 16 |
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. |
|
March 13, 2012, 06:20 |
|
#4 |
Senior Member
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,903
Rep Power: 37 |
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 |
|
March 13, 2012, 07:35 |
|
#5 |
New Member
Jordi Muela
Join Date: Mar 2011
Posts: 27
Rep Power: 16 |
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. |
|
March 13, 2012, 08:26 |
|
#6 |
New Member
Jordi Muela
Join Date: Mar 2011
Posts: 27
Rep Power: 16 |
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 |
|
|
|
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 |