- Timestamp:
- Aug 13, 2012, 3:47:51 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga/structures/inlet_operator.py
r8488 r8506 3 3 import inlet 4 4 5 from warnings import warn 5 6 6 7 class Inlet_operator(anuga.Operator): … … 19 20 line, 20 21 Q = 0.0, 22 default = None, 21 23 description = None, 22 24 label = None, … … 40 42 self.applied_Q = 0.0 41 43 44 self.set_default(default) 45 46 42 47 def __call__(self): 43 48 … … 71 76 """Allowing local modifications of Q 72 77 """ 78 from anuga.fit_interpolate.interpolate import Modeltime_too_early, Modeltime_too_late 73 79 74 80 if callable(self.Q): 75 Q = self.Q(t)[0] 81 try: 82 Q = self.Q(t)[0] 83 except Modeltime_too_early, e: 84 raise Modeltime_too_early(e) 85 except Modeltime_too_late, e: 86 Q = self.get_default(t,err_msg=e) 76 87 else: 77 88 Q = self.Q … … 122 133 123 134 135 def set_default(self, default=None): 136 137 """ Either leave default as None or change it into a function""" 138 139 if default is not None: 140 # If it is a constant, make it a function 141 if not callable(default): 142 tmp = default 143 default = lambda t: tmp 144 145 # Check that default_rate is a function of one argument 146 try: 147 default(0.0) 148 except: 149 raise Exception(msg) 150 151 self.default = default 152 self.default_invoked = False 153 154 155 156 def get_default(self,t, err_msg=' '): 157 """ Call get_default only if exception 158 Modeltime_too_late(msg) has been raised 159 """ 160 161 from anuga.fit_interpolate.interpolate import Modeltime_too_early, Modeltime_too_late 162 163 164 if self.default is None: 165 msg = '%s: ANUGA is trying to run longer than specified data.\n' %str(err_msg) 166 msg += 'You can specify keyword argument default in the ' 167 msg += 'operator to tell it what to do in the absence of time data.' 168 raise Modeltime_too_late(msg) 169 else: 170 # Pass control to default rate function 171 value = self.default(t) 172 173 if self.default_invoked is False: 174 # Issue warning the first time 175 msg = ('%s\n' 176 'Instead I will use the default rate: %s\n' 177 'Note: Further warnings will be supressed' 178 % (str(err_msg), str(self.default(t)))) 179 warn(msg) 180 181 # FIXME (Ole): Replace this crude flag with 182 # Python's ability to print warnings only once. 183 # See http://docs.python.org/lib/warning-filter.html 184 self.default_invoked = True 185 186 return value 187 188 124 189 def set_Q(self, Q): 125 190
Note: See TracChangeset
for help on using the changeset viewer.