|
[Sponsors] |
September 21, 2018, 13:09 |
How to get the value of latestTime?
|
#1 |
New Member
|
Hello,
Somehow, I need to use the value of latestTime in my code. More explanation: I have set the stratTime to latestTime in controlDict. In controlDict: Code:
startTime latestTime; Bests, Reza |
|
September 24, 2018, 05:49 |
|
#2 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
Hi,
so in order to get the fields from the latest time step (as real time or incremental), you have to store them such as: Code:
T.storeOldTime(); // To get the old time T.oldTime()
__________________
Keep foaming, Tobias Holzmann |
|
September 24, 2018, 10:40 |
|
#3 |
New Member
|
Thank you Tobi for the reply but it is not I was looking for. I am going to explain more. In my solver, I have these lines:
Code:
scalar eTime( readScalar(runTime.controlDict().lookup("endTime"))/nPoints ); scalar staTime( readScalar(runTime.controlDict().lookup("startTime"))); I checked Time.C and found this part: Code:
{ controlDict_.lookup("startTime") >> startTime_; } else { // Search directory for valid time directories instantList timeDirs = findTimes(path(), constant()); if (startFrom == "firstTime") { if (timeDirs.size()) { if (timeDirs[0].name() == constant() && timeDirs.size() >= 2) { startTime_ = timeDirs[1].value(); } else { startTime_ = timeDirs[0].value(); } } } else if (startFrom == "latestTime") { if (timeDirs.size()) { startTime_ = timeDirs.last().value(); } } } Reza |
|
September 24, 2018, 12:04 |
|
#4 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
You want to read the time value? I still did not get your point.
Getting the time value of the "latest Time" is explained in the code you wrote: Code:
latestTime = timeDirs.last().value()
__________________
Keep foaming, Tobias Holzmann |
|
September 24, 2018, 12:55 |
|
#5 |
New Member
|
That piece of code is from Time.C (source code for time)
https://github.com/OpenFOAM/OpenFOAM...db/Time/Time.C I can write the below line in my code (It's a solver based on pisoFoam): Code:
scalar latestTime = timeDirs.last().value(); Code:
error: ‘timeDirs’ was not declared in this scope So, how can I use this part of the Time.C and use it in my code? I want to continue a case from a previous state. The problem is that I use the startTime as a scalar in my code to do some some calculation.So I need to change the startTime every time I want to resume a case from a previous time. I am looking to do it automatically, writing latestTime in controlDict but my code should somehow reads the latesTime as a scalar, otherwise I get this error: Code:
--> FOAM FATAL IO ERROR: wrong token type - expected Scalar, found on line 22 the word 'LatestTime' Code:
scalar staTime( readScalar(runTime.controlDict().lookup("startTime"))); Reza |
|
September 24, 2018, 13:01 |
|
#6 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
Got it now. Yes it should be possible. The problem you have is related to the fact, that you do not have the object timeDir in your code. You should have access to that object via runTime.whateverFunction(); to get the function, doxygen is the proper way to look at.
__________________
Keep foaming, Tobias Holzmann |
|
January 31, 2019, 15:10 |
|
#7 |
Senior Member
Reviewer #2
Join Date: Jul 2015
Location: Knoxville, TN
Posts: 141
Rep Power: 11 |
db().time().startTime().value()
|
|
April 15, 2020, 12:24 |
question
|
#8 |
New Member
Ningyi Li
Join Date: Jun 2018
Location: Germany
Posts: 6
Rep Power: 8 |
Hi, Reza
Did you solve this problem? I also want to know how to get the value of latestTime in the controlDict as one scalar in the main programming? Best regards, Ningyi |
|
May 5, 2020, 00:16 |
|
#9 | |
Senior Member
|
Quote:
Can you just add the line to access timeDirs? instantList timeDirs = findTimes(path(), constant()); scalar latestTime = timeDirs.last().value(); latestTime is just a word for the if else control. |
||
May 10, 2020, 13:21 |
|
#10 |
Senior Member
Franco
Join Date: Nov 2019
Location: Compiègne, France
Posts: 129
Rep Power: 7 |
hello, not sure if the correct place to ask, I am looking to copy the last folder time from my case to use it as the 0 folder in the next (it is a two-step case)where the first I calculate the steady-state velocity and pressure fields and in the second doing a scalarTransport in transient so I can measure the RTD (residence time distribution) of steady-state flow in micromixer.
so I want to use simpleFoam to simulate the flow and when the residuals are low enought (from the residualControl in fvSoluion) copy the "lastTime folder" and renamed to a second case folder where I will do a scalarTransport. but as the lastTime is controlled by the residualControl I not going to be able to know from the beginning of the simulation when it is going to be converged. best regards, franco |
|
May 10, 2020, 13:28 |
|
#11 |
Senior Member
Reviewer #2
Join Date: Jul 2015
Location: Knoxville, TN
Posts: 141
Rep Power: 11 |
Franco,
I think you have two solutions: 1. just simply use the bash command with some regular expression to copy the last time step folder to your new case. 2. use the mapFields with sourceTime option to map the solution from the flow solution to your new case. Thanks, Rdf |
|
May 10, 2020, 14:02 |
|
#13 | ||
Senior Member
Franco
Join Date: Nov 2019
Location: Compiègne, France
Posts: 129
Rep Power: 7 |
Quote:
thanks for the answers, yes as tobi said, i think the first option is better as it is going to be exactly the same mesh, but my issue is how to setup a command to do it (as i wanted to integrated in an Allrun file) sorry as linux is new to me i am learning at the same time: i wanted to have this structure of folder: Simulation ------AllrunSimulation +----sim1 ---------+----0 ---------+----lastTime ---------+----constant ---------+----system ----------Allrunsim1 ----------Allclean +----sim2 ---------+----constant ---------+----system ----------Allrunsim2 ----------Allclean and for my AllrunSimulation file have a code like this: Quote:
thanks for the help, franco |
|||
May 10, 2020, 14:23 |
|
#15 | |
Senior Member
Franco
Join Date: Nov 2019
Location: Compiègne, France
Posts: 129
Rep Power: 7 |
Quote:
run first case, when finish copy the last folder to the second case (as 0 folder) and run the second case. as my idea is to leave it running during the nights, it would be my "ideal" case so it does not need intervention in middle of it. franco |
||
May 10, 2020, 15:29 |
|
#17 |
Senior Member
Franco
Join Date: Nov 2019
Location: Compiègne, France
Posts: 129
Rep Power: 7 |
||
May 10, 2020, 20:10 |
|
#18 |
Senior Member
Reviewer #2
Join Date: Jul 2015
Location: Knoxville, TN
Posts: 141
Rep Power: 11 |
Franco,
If you want go with the second solution, you can run this command in your transport case folder mapFields <origional case with flow solution> -sourceTime latestTime -consistent The argument latestTime will automatically parse the latest solution in that folder. Thank, Rdf |
|
May 11, 2020, 05:20 |
|
#19 | |||||
Senior Member
Franco
Join Date: Nov 2019
Location: Compiègne, France
Posts: 129
Rep Power: 7 |
Quote:
hello tobi, sorry to bother you, but when i do this in the bash it works correctly but when i do it from an allrun file it begings coping...; i think the Ubuntu subsystem? not sure... (but at least a lot of files... and not the correct ones...) Quote:
any idea? thanks. hello, i just came back to give an answer to my problem, for anyone that could need it and also so no one waste time in answering it :credits to https://unix.stackexchange.com/quest...shell-variable to stock the correct output the syntaxis is Quote:
Quote:
Quote:
Last edited by otaolafr; May 13, 2020 at 04:40. Reason: find the answer to the issue i was having |
||||||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to make sure to continue running from a complete time dir with latestTime ? | eric-meng | OpenFOAM | 4 | May 22, 2018 05:52 |
dirvergence of simulations after resuming pimpleDyMFoam with latestTime | rcastilla | OpenFOAM Running, Solving & CFD | 3 | October 9, 2017 10:01 |
Restarting a case using latestTime in parallel | arieljeds | OpenFOAM Running, Solving & CFD | 2 | May 11, 2016 12:30 |
pimpleDyMFoam won't restart from latestTime | xixchubbsxix | OpenFOAM Running, Solving & CFD | 1 | September 30, 2015 06:26 |
DieselFoam does not restart from latestTime | lord_kossity | OpenFOAM Bugs | 8 | February 21, 2009 14:54 |