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

OF-2.3.x: Get "latestTime" in a shell script?

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By alexeym
  • 1 Post By floquation

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 4, 2014, 05:35
Default OF-2.3.x: Get "latestTime" in a shell script?
  #1
Member
 
Join Date: Jul 2011
Posts: 54
Rep Power: 15
A_Pete is on a distinguished road
This is maybe a mix of a general UNIX question and an OF problem. During my meshing process, different time directories get created based on the meshing operations. Since they depend on the time step, which is set in the system/controlDict I would like to know how to get the directory of the latest time step into a variable. Since the formats of the time steps can be very different (1e-05, 0.001, etc.) it seems difficult, to compare these. Is there some way I can access the "latestTime" variable, which is used for many different OF tools, in my shell script? I want to do something like this:

Code:
sed -i "s/foo/bar/g" $latestTime/constant/polyMesh/boundary
Thanks in advance.
A_Pete is offline   Reply With Quote

Old   November 4, 2014, 06:25
Default
  #2
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,938
Rep Power: 39
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

if you'd like to modify boundary dictionary it's easier to use changeDictionary utility (with -latestTime flag). Also you can use -overwrite flag for your mesh operations if you don't need intermediate results.
A_Pete likes this.
alexeym is offline   Reply With Quote

Old   November 4, 2014, 06:27
Default
  #3
Senior Member
 
floquation's Avatar
 
Kevin van As
Join Date: Sep 2014
Location: TU Delft, The Netherlands
Posts: 252
Rep Power: 21
floquation will become famous soon enough
I do not have a full answer for you, but the following can take care of scientific notation:

Code:
$  bubRadius=20e-3
$ 
$   bubRadiusStr=`echo ${bubRadius} | sed -e 's/[eE]+*/\\*10\\^/'` #decode exponential notation into a mathematical string
$   bubRadiusx1=$(echo 1*$bubRadiusStr | bc -l) #floating point math, convert the string into a floating point number

Output:
.02000000000000000000

So if you can loop over all directories, you should be able to find the maximum value somehow.

Code:
cd $caseDir
for someDir in *
do
    stuff #$someDir is a file in your case file. It may be a number (timeDir), or e.g. "constant"
done
I hope that can get you started. Remember: Google is your best friend when shell scripting; Or with anything, really.
A_Pete likes this.
floquation is offline   Reply With Quote

Old   November 4, 2014, 06:41
Default
  #4
Member
 
Join Date: Jul 2011
Posts: 54
Rep Power: 15
A_Pete is on a distinguished road
Thanks to both of you for your answers.

@alexeym: The changeDictionary tool might be an option. This is not the only thing I want to change, though. The overwriting option is definately my first choice once I have figured out the correct way to build my mesh and case. So far, I have to keep the intermediate meshes during the "development stage".

@floquation: Yes this is probably what I will use first of all. But I just thought, that there is maybe an OF way to output/access the "latestTime" variable and to then use that in my shell script. I thought that would've been a nicer way to get the maximum time value.
A_Pete is offline   Reply With Quote

Old   September 29, 2020, 05:19
Default New OpenFOAM versions functionality
  #5
New Member
 
Aaron Endres
Join Date: Jun 2016
Posts: 13
Rep Power: 10
aendres is on a distinguished road
In newer OpenFOAM versions, you can use the foamListTimes function object.


latestTime=$(foamListTimes -latestTime | tail -n 1)
aendres 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
[ICEM] Script: problems with face names Maweil ANSYS Meshing & Geometry 3 April 16, 2019 10:10
CentFOAM Python Script Installation: Error socon009 OpenFOAM Installation 2 May 26, 2012 10:36
paraView in shell mode (python script running) Prosiaczek OpenFOAM 2 March 19, 2012 08:54
shell conduction ezabille FLUENT 2 December 15, 2010 18:42
Perl script for intialisation pratik mehta CFX 2 September 10, 2008 04:09


All times are GMT -4. The time now is 18:16.