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

Source Code for Module PyFoam.Applications.CommonSelectTimesteps

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