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

CPU Time

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 14, 2014, 20:09
Default CPU Time
  #1
New Member
 
Will
Join Date: Dec 2011
Posts: 17
Rep Power: 14
willzyba is on a distinguished road
Ever since we upgraded to OpenFOAM 2.3.x I've struggled to understand how I can get the simulation Time.

I'm trying to make an active spring, with a force component that depends on the model time.

In older versions of OpenFOAM I could use
Code:
runTime.elapsedClockTime()
But this no longer works. I'm just not sure how within one of the sizDoFRigidBodyMotion codes, i.e. linearAxialAngularSpring.C, I can get the sytem time.

Thanks in advance for any help
willzyba is offline   Reply With Quote

Old   November 15, 2014, 03:37
Default
  #2
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,900
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
Hi,

I cannot answer your question, but be careful. If the properties changes based on the CPU time and not the simulated time, then you will no longer have a deterministic model. The results will change per simulation, architechture, discretisation, etc.

Kind regards,

Niels
__________________
Please note that I do not use the Friend-feature, so do not be offended, if I do not accept a request.
ngj is offline   Reply With Quote

Old   November 15, 2014, 06:05
Default
  #3
New Member
 
Will
Join Date: Dec 2011
Posts: 17
Rep Power: 14
willzyba is on a distinguished road
Agreed, I do want simulation time, which is what I though elapsedClickTime gave.

But at this point I just want anything, I'm going to start using the system clock soon and that will be terrible.
willzyba is offline   Reply With Quote

Old   November 15, 2014, 06:21
Default
  #4
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,974
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Greetings to all!

This is one of those questions that have seemly pretty direct answers which is to tell you what exact question should be asked and to whom. The answer is: Ask the code documentation - http://www.openfoam.org/docs/cpp/ - about "Time" and it will tell you all about it, as shown below:



There you'll be shown that the following methods might be of interest to you:
Code:
time_t     elapsedClockTime () const
time_t     clockTimeIncrement () const
double     elapsedCpuTime () const
double     cpuTimeIncrement () const
virtual scalar     userTimeToTime (const scalar theta) const
virtual scalar     timeToUserTime (const scalar t) const
scalar     timeOutputValue () const
label     timeIndex () const
scalar     deltaTValue () const
scalar     deltaT0Value () const
dimensionedScalar     deltaT () const
dimensionedScalar     deltaT0 () const
bool     outputTime () const
I'm not giving a direct link to the page for the Time class, because the link will change with each new release of OpenFOAM.

Best regards,
Bruno
Attached Images
File Type: png Ask Code Documentation about Time.png (9.5 KB, 560 views)
__________________
wyldckat is offline   Reply With Quote

Old   November 15, 2014, 06:57
Default
  #5
New Member
 
Will
Join Date: Dec 2011
Posts: 17
Rep Power: 14
willzyba is on a distinguished road
I get the documentation. The issue isn't the list of available function within the Time class, its getting access to the Time class.

i.e. How do I get an instance of class Time (rather than just make a new instance) that is linked to the main application and the times it is using.

Once upon a time this was just 'runTime'. But this is no longer accessible within libraries I'm writing - where I'm simply modifying one of the 6DOF restraints.
willzyba is offline   Reply With Quote

Old   November 15, 2014, 09:22
Default
  #6
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,974
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Hi Will,

Well, this first statement of yours was pretty misleading:
Quote:
Originally Posted by willzyba View Post
Ever since we upgraded to OpenFOAM 2.3.x I've struggled to understand how I can get the simulation Time.
because it lead me to think that you had this feature working in an older version of OpenFOAM.

The other problem is that you didn't give us the exact context, or better yet, show us what you're seeing. And the thread title is also misleading

OK, so the problem is that you're trying to get access to the time controls from within a class for dynamic meshing. This would conceptually be similar to having this feature in a boundary condition, because the way the accesses to the mesh and fields are done in a similar way.
This leads me to this thread: http://www.cfd-online.com/Forums/ope...tml#post513962 - specifically post #7, where I mention the class "uniformFixedValue", which is the class/BC that is able to handle the table lookup dependant on time. The specific code that does this is here: https://github.com/OpenFOAM/OpenFOAM...chField.C#L117
Quote:
Code:
template<class Type>
uniformFixedValueFvPatchField<Type>::uniformFixedValueFvPatchField
(
    const uniformFixedValueFvPatchField<Type>& ptf,
    const DimensionedField<Type, volMesh>& iF
)
:
    fixedValueFvPatchField<Type>(ptf, iF),
    uniformValue_
    (
        ptf.uniformValue_.valid()
      ? ptf.uniformValue_().clone().ptr()
      : NULL
    )
{
    // For safety re-evaluate
    const scalar t = this->db().time().timeOutputValue();

    if (ptf.uniformValue_.valid())
    {
        fvPatchField<Type>::operator==(uniformValue_->value(t));
    }
}
See anything familiar that you might be looking for?

Best regards,
Bruno
wyldckat is offline   Reply With Quote

Old   November 15, 2014, 13:10
Default
  #7
New Member
 
Will
Join Date: Dec 2011
Posts: 17
Rep Power: 14
willzyba is on a distinguished road
Hi Bruno,

My first posting was correct. The code I showed used to work in OpenFoam 2.2.2, where we used it in a custom class based directly on sixDoFRigidBodyMotion/restraint/linearSpring class.

Using
Code:
this->db().time().timeOutputValue()
also doesn't work. We get the compiler error:
Code:
sixDoFRigidBodyMotion/restraints/CCactiveSpring/CCactiveSpring.C:91:19: error: ‘const class Foam::sixDoFRigidBodyMotionRestraints::CCactiveSpring’ has no member named ‘db’
I'm not surprised, since these 6DOF/restraint classes don't have many base classes, and certainly nothing that links back to the Time. I suspect what happened before was there was a global variable define which was accessible across the all the code. I'm still trying to get my head around how OpenFOAM is structure and the changes that took place from 2.2.2 to 2.3.x and I guess that is the fundamental problem.

Thanks for your help though.
willzyba is offline   Reply With Quote

Old   November 15, 2014, 14:33
Default
  #8
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,974
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Hi Will,

Sorry, I was in too much of a hurry and didn't check the OpenFOAM source code myself. But you didn't mention which was the previous version OpenFOAM you had used

I've taken a look at the source code for OpenFOAM 2.2.x at Github and I believe that you had more modifications in your older code than you remember using, because there is no occurrence in the whole source code of something like this:
Code:
extern Foam::Time runTime;
at least in OpenFOAM 2.2.x.

But as you mentioned, one solution is to rely on a globally shared value between the solver and your classes. This requires you to also create a modified version of your solver, which will have to depend on the new library you're creating, so that the solver can access the global variable in your class/library that has a global pointer for "runTime".

2nd solution would be to access a global instance of the object registry... which would then give you access to "db()" or "thisDb()"... but I haven't found it yet.

3rd solution is to hack the class "sixDoFRigidBodyMotion" to calculate the total time that has passed since it started, and register said time in the class "sixDoFRigidBodyMotionState". Then it would be possible to use the variable "motion" within the "restrain" method to access the current total time for this particular state.

4th solution is to actually reverse engineer the time between two states, based in the position of each state for the previous restraint and the current restraint. The "motion.state()" gives a complete snapshot... er, wait, it's only a partial snapshot... never mind.


5th solution is to overhaul the whole library "sixDoFRigidBodyMotion" to support this requirement you have. It's probably the best and correct way to fix this.

You might also want to open a feature request for this on the OpenFOAM bug tracker, because the current solid motion is only dealing with relative time steps and doesn't even allow to send these time steps to the restrain mechanism.

Best regards,
Bruno
__________________
wyldckat is offline   Reply With Quote

Old   February 18, 2016, 13:54
Default
  #9
Member
 
Camille Bilger
Join Date: Jul 2013
Posts: 43
Rep Power: 12
kmou is on a distinguished road
Quote:
Originally Posted by wyldckat View Post
Hi Will,


I've taken a look at the source code for OpenFOAM 2.2.x at Github and I believe that you had more modifications in your older code than you remember using, because there is no occurrence in the whole source code of something like this:
Code:
extern Foam::Time runTime;
at least in OpenFOAM 2.2.x.

But as you mentioned, one solution is to rely on a globally shared value between the solver and your classes. This requires you to also create a modified version of your solver, which will have to depend on the new library you're creating, so that the solver can access the global variable in your class/library that has a global pointer for "runTime".


Hi Bruno,

I have been trying exactly this working: making the runTime variable global within my solver directory.
It is a modified interFoam solver.
runTime is set inside interFoam.C
and used as we wish, runTime.timeName(), etc...

Within my solver directory, I created a sub-directory which is a personalised boundary condition.
It contains two files: MyBoundaryCondition.C
and myBoundaryCondition.H


I would like to be able to store variables created in the .C file within the time directories of my simulation.
To do so, I would need runTime to be global, or "extern"

but I don't seem to manage to understand where to use "extern Foam::Time runTime;"
or if this is actually a wrong code line to use...

Thank you for your support
kmou is offline   Reply With Quote

Old   March 28, 2016, 14:10
Default
  #10
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,974
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Greetings Camille,

Sorry for the late reply, but only now did I finally manage to look into this.

And I recently went for a debugging session on a feature related to this: http://www.openfoam.org/mantisbt/view.php?id=2030

What happens is that whenever we have access to a field object or the main "mesh" object, we are automatically able to access the "runTime" object indirectly. Funnily enough, I went searching for this very same topic and I ended up on my previous post above

In specific, since you have a boundary condition, all you need to do is use the same exact strategy that a lot of other boundary conditions already use. If you run the following command in the terminal/console window:
Code:
grep -r "db()" $FOAM_SRC/finiteVolume/fields/fvPatchFields
you will find a lot of these examples.
For example, the following code within your boundary condition:
Code:
this->db().time()
is the indirect access to the "runTime" object.

Best regards,
Bruno
__________________
wyldckat is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
TimeVaryingMappedFixedValue irishdave OpenFOAM Running, Solving & CFD 32 June 16, 2021 07:55
Sudden jump in Courant number NJG OpenFOAM Running, Solving & CFD 7 May 15, 2014 14:52
Micro Scale Pore, icoFoam gooya_kabir OpenFOAM Running, Solving & CFD 2 November 2, 2013 14:58
CPU time Vs Wall clock time HMR CFX 2 February 28, 2012 20:06
IcoFoam parallel woes msrinath80 OpenFOAM Running, Solving & CFD 9 July 22, 2007 03:58


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