Package PyFoam :: Package Applications :: Module CommonSelectTimesteps
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.Applications.CommonSelectTimesteps

  1  #  ICE Revision: $Id$ 
  2  """ 
  3  Class that implements common functionality for selecting timesteps 
  4  """ 
  5   
  6  from optparse import OptionGroup 
  7   
  8  from PyFoam.ThirdParty.six import print_ 
  9   
10 -class CommonSelectTimesteps(object):
11 """ 12 This class compiles a list of timesteps that should be processed 13 """
14 - def __init__(self):
15 pass
16
17 - def addOptions(self,defaultUnique):
18 """Add the necessary options 19 @param defaultUnique: whether timesteps are unique by default""" 20 21 time=OptionGroup(self.parser, 22 "Time Specification", 23 "Which times should be processed") 24 time.add_option("--time", 25 type="float", 26 dest="time", 27 default=[], 28 action="append", 29 help="Timestep that should be processed. Can be used more than once") 30 time.add_option("--latest-time", 31 dest="latest", 32 action="store_true", 33 default=False, 34 help="Use the latest time") 35 time.add_option("--all-times", 36 dest="all", 37 action="store_true", 38 default=False, 39 help="Process all times") 40 time.add_option("--after-time", 41 type="float", 42 dest="afterTime", 43 action="store", 44 default=None, 45 help="Process all after this time") 46 time.add_option("--before-time", 47 type="float", 48 dest="beforeTime", 49 action="store", 50 default=None, 51 help="Process all before this time") 52 53 if defaultUnique: 54 time.add_option("--duplicate-times", 55 dest="unique", 56 action="store_false", 57 default=True, 58 help="Allow using a time-directory onlymore than once") 59 else: 60 time.add_option("--unique-times", 61 dest="unique", 62 action="store_true", 63 default=False, 64 help="Use each time-directory only once") 65 66 time.add_option("--show-times", 67 dest="showTimes", 68 action="store_true", 69 default=False, 70 help="Show the times in the case and the times that will be used") 71 72 time.add_option("--parallel-times", 73 dest="parallelTimes", 74 action="store_true", 75 default=False, 76 help="Use the information from 'processor0' to determine the available times") 77 78 self.parser.add_option_group(time)
79
80 - def processTimestepOptions(self, 81 sol):
82 """Process the options 83 @param sol: the solution-directory that is to be worked with""" 84 85 if self.opts.parallelTimes: 86 sol.setToParallel() 87 88 if self.opts.latest: 89 self.opts.time.append(float(sol.getLast())) 90 if self.opts.all: 91 for t in sol.getTimes(): 92 self.opts.time.append(float(t)) 93 if self.opts.beforeTime or self.opts.afterTime: 94 start=float(sol.getFirst()) 95 end=float(sol.getLast()) 96 if self.opts.beforeTime: 97 end=self.opts.beforeTime 98 if self.opts.afterTime: 99 start=self.opts.afterTime 100 for t in sol.getTimes(): 101 tVal=float(t) 102 if tVal>=start and tVal<=end: 103 self.opts.time.append(tVal) 104 105 self.opts.time.sort() 106 107 times=[] 108 109 for s in self.opts.time: 110 times.append(sol.timeName(s,minTime=True)) 111 112 if self.opts.unique: 113 tmp=[] 114 last=None 115 cnt=0 116 for s in times: 117 if last!=s: 118 tmp.append(s) 119 else: 120 cnt+=1 121 last=s 122 if cnt>0: 123 self.warning("Removed",cnt,"duplicate times") 124 times=tmp 125 126 if len(times)==0: 127 self.warning("No valid times specified") 128 129 if self.opts.showTimes: 130 print_("Times in case:",sol.getTimes()) 131 print_("Used times:",times) 132 133 return times
134 135 # Should work with Python3 and Python2 136