Changeset 8506
- Timestamp:
- Aug 13, 2012, 3:47:51 PM (13 years ago)
- Location:
- trunk/anuga_core/source/anuga
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga/operators/run_polygon_erosion.py
r8486 r8506 149 149 150 150 151 152 151 153 #------------------------------------------------------------------------------- 152 154 # Evolve system through time -
trunk/anuga_core/source/anuga/operators/set_stage_operators.py
r8475 r8506 93 93 msg = '%s: ANUGA is trying to run longer than specified data.\n' %str(e) 94 94 msg += 'You can specify keyword argument default_rate in the ' 95 msg += ' rate operatorto tell it what to do in the absence of time data.'95 msg += 'stage function to tell it what to do in the absence of time data.' 96 96 raise Modeltime_too_late(msg) 97 97 else: -
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 -
trunk/anuga_core/source/anuga/structures/test_inlet_operator.py
r8198 r8506 183 183 184 184 vol1 = domain.compute_total_volume() 185 186 #print vol1-vol0 185 187 186 188 assert numpy.allclose(13.5, vol1-vol0, rtol=1.0e-8) 187 189 188 190 def test_inlet_variable_Q_default(self): 191 """test_inlet_Q 192 193 This tests that the inlet operator adds the correct amount of water 194 """ 195 196 stage_0 = 11.0 197 stage_1 = 10.0 198 elevation_0 = 10.0 199 elevation_1 = 10.0 200 201 domain_length = 200.0 202 domain_width = 200.0 203 204 205 domain = self._create_domain(d_length=domain_length, 206 d_width=domain_width, 207 dx = 10.0, 208 dy = 10.0, 209 elevation_0 = elevation_0, 210 elevation_1 = elevation_1, 211 stage_0 = stage_0, 212 stage_1 = stage_1) 213 214 vol0 = domain.compute_total_volume() 215 216 finaltime = 5.0 217 218 #Make sure we are inthe right directory to find the 219 #time series data for the inlets 220 import os 221 baseDir = os.getcwd() 222 223 try: 224 os.chdir('structures') 225 except: 226 pass 227 228 line1 = [[95.0, 10.0], [105.0, 10.0]] 229 Q1 = file_function(filename='inlet_operator_test1.tms', quantities=['hydrograph']) 230 231 line2 = [[10.0, 90.0], [20.0, 90.0]] 232 Q2 = file_function(filename='inlet_operator_test2.tms', quantities=['hydrograph']) 233 234 os.chdir(baseDir) 235 236 Inlet_operator(domain, line1, Q1, default=6) 237 Inlet_operator(domain, line2, Q2, default=3) 238 239 for t in domain.evolve(yieldstep = 1.0, finaltime = finaltime): 240 #domain.write_time() 241 #print domain.volumetric_balance_statistics() 242 pass 243 244 245 vol1 = domain.compute_total_volume() 246 247 #print vol1-vol0 248 249 assert numpy.allclose(31.5, vol1-vol0, rtol=1.0e-8) 189 250 190 251 # =========================================================================
Note: See TracChangeset
for help on using the changeset viewer.