|
[Sponsors] |
November 14, 2014, 20:09 |
CPU Time
|
#1 |
New Member
Will
Join Date: Dec 2011
Posts: 17
Rep Power: 14 |
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() Thanks in advance for any help |
|
November 15, 2014, 03:37 |
|
#2 |
Senior Member
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,900
Rep Power: 37 |
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. |
|
November 15, 2014, 06:05 |
|
#3 |
New Member
Will
Join Date: Dec 2011
Posts: 17
Rep Power: 14 |
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. |
|
November 15, 2014, 06:21 |
|
#4 |
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,974
Blog Entries: 45
Rep Power: 128 |
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 Best regards, Bruno
__________________
|
|
November 15, 2014, 06:57 |
|
#5 |
New Member
Will
Join Date: Dec 2011
Posts: 17
Rep Power: 14 |
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. |
|
November 15, 2014, 09:22 |
|
#6 | ||
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,974
Blog Entries: 45
Rep Power: 128 |
Hi Will,
Well, this first statement of yours was pretty misleading: Quote:
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:
Best regards, Bruno |
|||
November 15, 2014, 13:10 |
|
#7 |
New Member
Will
Join Date: Dec 2011
Posts: 17
Rep Power: 14 |
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() Code:
sixDoFRigidBodyMotion/restraints/CCactiveSpring/CCactiveSpring.C:91:19: error: ‘const class Foam::sixDoFRigidBodyMotionRestraints::CCactiveSpring’ has no member named ‘db’ Thanks for your help though. |
|
November 15, 2014, 14:33 |
|
#8 |
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,974
Blog Entries: 45
Rep Power: 128 |
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; 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
__________________
|
|
February 18, 2016, 13:54 |
|
#9 | |
Member
Camille Bilger
Join Date: Jul 2013
Posts: 43
Rep Power: 12 |
Quote:
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 |
||
March 28, 2016, 14:10 |
|
#10 |
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,974
Blog Entries: 45
Rep Power: 128 |
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 For example, the following code within your boundary condition: Code:
this->db().time() Best regards, Bruno
__________________
|
|
Thread Tools | Search this Thread |
Display Modes | |
|
|
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 |