1 | import anuga |
---|
2 | import numpy as num |
---|
3 | import math |
---|
4 | import inlet_enquiry |
---|
5 | |
---|
6 | from anuga.utilities.system_tools import log_to_file |
---|
7 | from anuga.utilities.numerical_tools import ensure_numeric |
---|
8 | |
---|
9 | |
---|
10 | |
---|
11 | class Structure_operator(anuga.Operator): |
---|
12 | """Structure Operator - transfer water from one rectangular box to another. |
---|
13 | Sets up the geometry of problem |
---|
14 | |
---|
15 | This is the base class for structures (culverts, pipes, bridges etc). Inherit from this class (and overwrite |
---|
16 | discharge_routine method for specific subclasses) |
---|
17 | |
---|
18 | Input: Two points, pipe_size (either diameter or width, depth), |
---|
19 | mannings_rougness, |
---|
20 | """ |
---|
21 | |
---|
22 | counter = 0 |
---|
23 | |
---|
24 | def __init__(self, |
---|
25 | domain, |
---|
26 | end_points=None, |
---|
27 | exchange_lines=None, |
---|
28 | enquiry_points=None, |
---|
29 | invert_elevations=None, |
---|
30 | width=None, |
---|
31 | height=None, |
---|
32 | diameter=None, |
---|
33 | z1=None,#added by PM 4/10/2013 |
---|
34 | z2=None,#added by PM 4/10/2013 |
---|
35 | apron=None, |
---|
36 | manning=None, |
---|
37 | enquiry_gap=None, |
---|
38 | use_momentum_jet=False, |
---|
39 | zero_outflow_momentum=True, |
---|
40 | use_old_momentum_method=True, |
---|
41 | force_constant_inlet_elevations=False, |
---|
42 | description=None, |
---|
43 | label=None, |
---|
44 | structure_type=None, |
---|
45 | logging=None, |
---|
46 | verbose=None): |
---|
47 | |
---|
48 | """ |
---|
49 | exchange_lines define the input lines for each inlet. |
---|
50 | |
---|
51 | If end_points = None, then the culvert_vector is calculated in the |
---|
52 | directions from the centre of echange_line[0] to centre of exchange_line[1} |
---|
53 | |
---|
54 | If end_points != None, then culvert_vector is unit vector in direction |
---|
55 | end_point[1] - end_point[0] |
---|
56 | """ |
---|
57 | |
---|
58 | anuga.Operator.__init__(self,domain) |
---|
59 | |
---|
60 | self.master_proc = 0 |
---|
61 | self.end_points = ensure_numeric(end_points) |
---|
62 | self.exchange_lines = ensure_numeric(exchange_lines) |
---|
63 | self.enquiry_points = ensure_numeric(enquiry_points) |
---|
64 | self.invert_elevations = ensure_numeric(invert_elevations) |
---|
65 | |
---|
66 | assert self.end_points == None or self.exchange_lines == None |
---|
67 | |
---|
68 | |
---|
69 | if height is None: |
---|
70 | height = width |
---|
71 | |
---|
72 | if width is None: |
---|
73 | width = diameter |
---|
74 | |
---|
75 | if apron is None: |
---|
76 | apron = width |
---|
77 | |
---|
78 | |
---|
79 | assert width is not None |
---|
80 | |
---|
81 | |
---|
82 | self.width = width |
---|
83 | self.height = height |
---|
84 | self.diameter = diameter |
---|
85 | self.z1 = z1 #added by PM 4/10/2013 |
---|
86 | self.z2 = z2 #added by PM 4/10/2013 |
---|
87 | self.apron = apron |
---|
88 | self.manning = manning |
---|
89 | self.enquiry_gap = enquiry_gap |
---|
90 | self.use_momentum_jet = use_momentum_jet |
---|
91 | self.zero_outflow_momentum = zero_outflow_momentum |
---|
92 | if use_momentum_jet and zero_outflow_momentum: |
---|
93 | msg = "Can't have use_momentum_jet and zero_outflow_momentum both True" |
---|
94 | raise Exception(msg) |
---|
95 | self.use_old_momentum_method = use_old_momentum_method |
---|
96 | |
---|
97 | |
---|
98 | if description == None: |
---|
99 | self.description = ' ' |
---|
100 | else: |
---|
101 | self.description = description |
---|
102 | |
---|
103 | if label == None: |
---|
104 | self.label = "structure_%g" % Structure_operator.counter |
---|
105 | else: |
---|
106 | self.label = label + '_%g' % Structure_operator.counter |
---|
107 | |
---|
108 | if structure_type == None: |
---|
109 | self.structure_type = 'generic structure' |
---|
110 | else: |
---|
111 | self.structure_type = structure_type |
---|
112 | |
---|
113 | self.verbose = verbose |
---|
114 | |
---|
115 | # Keep count of structures |
---|
116 | Structure_operator.counter += 1 |
---|
117 | |
---|
118 | # Slots for recording current statistics |
---|
119 | self.accumulated_flow = 0.0 |
---|
120 | self.discharge = 0.0 |
---|
121 | self.velocity = 0.0 |
---|
122 | self.outlet_depth = 0.0 |
---|
123 | self.delta_total_energy = 0.0 |
---|
124 | self.driving_energy = 0.0 |
---|
125 | |
---|
126 | if exchange_lines is not None: |
---|
127 | self.__process_skew_culvert() |
---|
128 | elif end_points is not None: |
---|
129 | self.__process_non_skew_culvert() |
---|
130 | else: |
---|
131 | raise Exception, 'Define either exchange_lines or end_points' |
---|
132 | |
---|
133 | |
---|
134 | self.inlets = [] |
---|
135 | line0 = self.exchange_lines[0] #self.inlet_lines[0] |
---|
136 | if self.apron is None: |
---|
137 | poly0 = line0 |
---|
138 | else: |
---|
139 | offset = -self.apron*self.outward_vector_0 |
---|
140 | #print line0 |
---|
141 | #print offset |
---|
142 | poly0 = num.array([ line0[0], line0[1], line0[1]+offset, line0[0]+offset]) |
---|
143 | #print poly0 |
---|
144 | if self.invert_elevations is None: |
---|
145 | invert_elevation0 = None |
---|
146 | else: |
---|
147 | invert_elevation0 = self.invert_elevations[0] |
---|
148 | |
---|
149 | enquiry_point0 = self.enquiry_points[0] |
---|
150 | |
---|
151 | #outward_vector0 = - self.culvert_vector |
---|
152 | self.inlets.append(inlet_enquiry.Inlet_enquiry( |
---|
153 | self.domain, |
---|
154 | poly0, |
---|
155 | enquiry_point0, |
---|
156 | invert_elevation = invert_elevation0, |
---|
157 | outward_culvert_vector = self.outward_vector_0, |
---|
158 | verbose = self.verbose)) |
---|
159 | |
---|
160 | if force_constant_inlet_elevations: |
---|
161 | # Try to enforce a constant inlet elevation |
---|
162 | inlet_global_elevation = self.inlets[-1].get_average_elevation() |
---|
163 | self.inlets[-1].set_elevations(inlet_global_elevation) |
---|
164 | |
---|
165 | tris_0 = self.inlets[0].triangle_indices |
---|
166 | #print tris_0 |
---|
167 | #print self.domain.centroid_coordinates[tris_0] |
---|
168 | |
---|
169 | line1 = self.exchange_lines[1] |
---|
170 | if self.apron is None: |
---|
171 | poly1 = line1 |
---|
172 | else: |
---|
173 | offset = -self.apron*self.outward_vector_1 |
---|
174 | #print line1 |
---|
175 | #print offset |
---|
176 | poly1 = num.array([ line1[0], line1[1], line1[1]+offset, line1[0]+offset]) |
---|
177 | #print poly1 |
---|
178 | |
---|
179 | if self.invert_elevations is None: |
---|
180 | invert_elevation1 = None |
---|
181 | else: |
---|
182 | invert_elevation1 = self.invert_elevations[1] |
---|
183 | enquiry_point1 = self.enquiry_points[1] |
---|
184 | |
---|
185 | #outward_vector1 = - self.culvert_vector |
---|
186 | self.inlets.append(inlet_enquiry.Inlet_enquiry( |
---|
187 | self.domain, |
---|
188 | poly1, |
---|
189 | enquiry_point1, |
---|
190 | invert_elevation = invert_elevation1, |
---|
191 | outward_culvert_vector = self.outward_vector_1, |
---|
192 | verbose = self.verbose)) |
---|
193 | |
---|
194 | |
---|
195 | tris_1 = self.inlets[1].triangle_indices |
---|
196 | #print tris_1 |
---|
197 | #print self.domain.centroid_coordinates[tris_1] |
---|
198 | |
---|
199 | self.set_logging(logging) |
---|
200 | |
---|
201 | if force_constant_inlet_elevations: |
---|
202 | # Try to enforce a constant inlet elevation |
---|
203 | inlet_global_elevation = self.inlets[-1].get_average_elevation() |
---|
204 | self.inlets[-1].set_elevations(inlet_global_elevation) |
---|
205 | |
---|
206 | |
---|
207 | |
---|
208 | |
---|
209 | def __call__(self): |
---|
210 | |
---|
211 | timestep = self.domain.get_timestep() |
---|
212 | |
---|
213 | Q, barrel_speed, outlet_depth = self.discharge_routine() |
---|
214 | |
---|
215 | old_inflow_depth = self.inflow.get_average_depth() |
---|
216 | old_inflow_stage = self.inflow.get_average_stage() |
---|
217 | old_inflow_xmom = self.inflow.get_average_xmom() |
---|
218 | old_inflow_ymom = self.inflow.get_average_ymom() |
---|
219 | |
---|
220 | #semi_implicit = True |
---|
221 | #if semi_implicit: |
---|
222 | |
---|
223 | # FIXME: This update replaces Q with Q*new_inflow_depth/old_inflow_depth |
---|
224 | # This has good wetting and drying properties but means that |
---|
225 | # discharge != Q. |
---|
226 | # We should be able to check if old_inflow_depth*old_inflow_area > Q*dt, |
---|
227 | # and in that case we don't need this implicit trick, and could |
---|
228 | # have the discharge = Q (whereas in the nearly-dry case we want |
---|
229 | # the trick). |
---|
230 | |
---|
231 | # Implement the update of flow over a timestep by |
---|
232 | # using a semi-implict update. This ensures that |
---|
233 | # the update does not create a negative depth |
---|
234 | if old_inflow_depth > 0.0 : |
---|
235 | dt_Q_on_d = timestep*Q/old_inflow_depth |
---|
236 | else: |
---|
237 | dt_Q_on_d = 0.0 |
---|
238 | |
---|
239 | # The depth update is: |
---|
240 | # new_inflow_depth*inflow_area = |
---|
241 | # old_inflow_depth*inflow_area - |
---|
242 | # timestep*Q*(new_inflow_depth/old_inflow_depth) |
---|
243 | # The last term in () is a wet-dry improvement trick |
---|
244 | # Note inflow_area is the area of all triangles in the inflow |
---|
245 | # region -- so this is a volumetric balance equation |
---|
246 | # |
---|
247 | factor = 1.0/(1.0 + dt_Q_on_d/self.inflow.get_area()) |
---|
248 | new_inflow_depth = old_inflow_depth*factor |
---|
249 | |
---|
250 | if(self.use_old_momentum_method): |
---|
251 | # This method is here for consistency with the old version of the |
---|
252 | # routine |
---|
253 | new_inflow_xmom = old_inflow_xmom*factor |
---|
254 | new_inflow_ymom = old_inflow_ymom*factor |
---|
255 | |
---|
256 | else: |
---|
257 | # For the momentum balance, note that Q also advects the momentum, |
---|
258 | # The volumetric momentum flux should be Q*momentum, where |
---|
259 | # momentum has an average value of new_inflow_mom (or |
---|
260 | # old_inflow_mom). For consistency we keep using the |
---|
261 | # (new_inflow_depth/old_inflow_depth) factor for discharge: |
---|
262 | # |
---|
263 | # new_inflow_xmom*inflow_area = |
---|
264 | # old_inflow_xmom*inflow_area - |
---|
265 | # [timestep*Q*(new_inflow_depth/old_inflow_depth)]*new_inflow_xmom |
---|
266 | # and: |
---|
267 | # new_inflow_ymom*inflow_area = |
---|
268 | # old_inflow_ymom*inflow_area - |
---|
269 | # [timestep*Q*(new_inflow_depth/old_inflow_depth)]*new_inflow_ymom |
---|
270 | # |
---|
271 | # The choice of new_inflow_mom in the final term at the end might be |
---|
272 | # replaced with old_inflow_mom |
---|
273 | # |
---|
274 | factor2 = 1.0/(1.0 + dt_Q_on_d*new_inflow_depth/self.inflow.get_area()) |
---|
275 | new_inflow_xmom = old_inflow_xmom*factor2 |
---|
276 | new_inflow_ymom = old_inflow_ymom*factor2 |
---|
277 | |
---|
278 | self.inflow.set_depths(new_inflow_depth) |
---|
279 | |
---|
280 | #inflow.set_xmoms(Q/inflow.get_area()) |
---|
281 | #inflow.set_ymoms(0.0) |
---|
282 | |
---|
283 | self.inflow.set_xmoms(new_inflow_xmom) |
---|
284 | self.inflow.set_ymoms(new_inflow_ymom) |
---|
285 | |
---|
286 | loss = (old_inflow_depth - new_inflow_depth)*self.inflow.get_area() |
---|
287 | xmom_loss = (old_inflow_xmom - new_inflow_xmom)*self.inflow.get_area() |
---|
288 | ymom_loss = (old_inflow_ymom - new_inflow_ymom)*self.inflow.get_area() |
---|
289 | |
---|
290 | # set outflow |
---|
291 | if old_inflow_depth > 0.0 : |
---|
292 | timestep_star = timestep*new_inflow_depth/old_inflow_depth |
---|
293 | else: |
---|
294 | timestep_star = 0.0 |
---|
295 | |
---|
296 | outflow_extra_depth = Q*timestep_star/self.outflow.get_area() |
---|
297 | outflow_direction = - self.outflow.outward_culvert_vector |
---|
298 | #outflow_extra_momentum = outflow_extra_depth*barrel_speed*outflow_direction |
---|
299 | |
---|
300 | gain = outflow_extra_depth*self.outflow.get_area() |
---|
301 | |
---|
302 | #print gain, loss |
---|
303 | assert num.allclose(gain-loss, 0.0) |
---|
304 | |
---|
305 | # Stats |
---|
306 | self.accumulated_flow += gain |
---|
307 | self.discharge = Q*timestep_star/timestep |
---|
308 | self.velocity = barrel_speed |
---|
309 | self.outlet_depth = outlet_depth |
---|
310 | |
---|
311 | new_outflow_depth = self.outflow.get_average_depth() + outflow_extra_depth |
---|
312 | |
---|
313 | self.outflow.set_depths(new_outflow_depth) |
---|
314 | |
---|
315 | if self.use_momentum_jet: |
---|
316 | # FIXME (SR) Review momentum to account for possible hydraulic jumps at outlet |
---|
317 | # FIXME (GD) Depending on barrel speed I think this will be either |
---|
318 | # a source or sink of momentum (considering the momentum losses |
---|
319 | # above). Might not always be reasonable. |
---|
320 | #new_outflow_xmom = self.outflow.get_average_xmom() + outflow_extra_momentum[0] |
---|
321 | #new_outflow_ymom = self.outflow.get_average_ymom() + outflow_extra_momentum[1] |
---|
322 | new_outflow_xmom = barrel_speed*new_outflow_depth*outflow_direction[0] |
---|
323 | new_outflow_ymom = barrel_speed*new_outflow_depth*outflow_direction[1] |
---|
324 | |
---|
325 | elif self.zero_outflow_momentum: |
---|
326 | new_outflow_xmom = 0.0 |
---|
327 | new_outflow_ymom = 0.0 |
---|
328 | #new_outflow_xmom = outflow.get_average_xmom() |
---|
329 | #new_outflow_ymom = outflow.get_average_ymom() |
---|
330 | |
---|
331 | else: |
---|
332 | # Add the momentum lost from the inflow to the outflow. For |
---|
333 | # structures where barrel_speed is unknown + direction doesn't |
---|
334 | # change from inflow to outflow |
---|
335 | new_outflow_xmom = self.outflow.get_average_xmom() + xmom_loss/self.outflow.get_area() |
---|
336 | new_outflow_ymom = self.outflow.get_average_ymom() + ymom_loss/self.outflow.get_area() |
---|
337 | |
---|
338 | self.outflow.set_xmoms(new_outflow_xmom) |
---|
339 | self.outflow.set_ymoms(new_outflow_ymom) |
---|
340 | |
---|
341 | |
---|
342 | |
---|
343 | def set_culvert_height(self, height): |
---|
344 | |
---|
345 | self.culvert_height = height |
---|
346 | |
---|
347 | def set_culvert_width(self, width): |
---|
348 | |
---|
349 | self.culvert_width = width |
---|
350 | |
---|
351 | def set_culvert_z1(self, z1): #added by PM 4/10/2013 |
---|
352 | |
---|
353 | self.culvert_z1 = z1 #added by PM 4/10/2013 |
---|
354 | |
---|
355 | def set_culvert_z2(self, z2): #added by PM 4/10/2013 |
---|
356 | |
---|
357 | self.culvert_z2 = z2 #added by PM 4/10/2013 |
---|
358 | |
---|
359 | def __process_non_skew_culvert(self): |
---|
360 | |
---|
361 | """Create lines at the end of a culvert inlet and outlet. |
---|
362 | At either end two lines will be created; one for the actual flow to pass through and one a little further away |
---|
363 | for enquiring the total energy at both ends of the culvert and transferring flow. |
---|
364 | """ |
---|
365 | |
---|
366 | self.culvert_vector = self.end_points[1] - self.end_points[0] |
---|
367 | self.culvert_length = math.sqrt(num.sum(self.culvert_vector**2)) |
---|
368 | assert self.culvert_length > 0.0, 'The length of culvert is less than 0' |
---|
369 | |
---|
370 | self.culvert_vector /= self.culvert_length |
---|
371 | self.outward_vector_0 = self.culvert_vector |
---|
372 | self.outward_vector_1 = - self.culvert_vector |
---|
373 | |
---|
374 | |
---|
375 | culvert_normal = num.array([-self.culvert_vector[1], self.culvert_vector[0]]) # Normal vector |
---|
376 | w = 0.5*self.width*culvert_normal # Perpendicular vector of 1/2 width |
---|
377 | |
---|
378 | self.exchange_lines = [] |
---|
379 | |
---|
380 | # Build exchange polyline and enquiry point |
---|
381 | if self.enquiry_points is None: |
---|
382 | |
---|
383 | gap = (self.apron + self.enquiry_gap)*self.culvert_vector |
---|
384 | self.enquiry_points = [] |
---|
385 | |
---|
386 | for i in [0, 1]: |
---|
387 | p0 = self.end_points[i] + w |
---|
388 | p1 = self.end_points[i] - w |
---|
389 | self.exchange_lines.append(num.array([p0, p1])) |
---|
390 | ep = self.end_points[i] + (2*i - 1)*gap #(2*i - 1) determines the sign of the points |
---|
391 | self.enquiry_points.append(ep) |
---|
392 | |
---|
393 | else: |
---|
394 | for i in [0, 1]: |
---|
395 | p0 = self.end_points[i] + w |
---|
396 | p1 = self.end_points[i] - w |
---|
397 | self.exchange_lines.append(num.array([p0, p1])) |
---|
398 | |
---|
399 | |
---|
400 | def __process_skew_culvert(self): |
---|
401 | |
---|
402 | """Compute skew culvert. |
---|
403 | If exchange lines are given, the enquiry points are determined. This is for enquiring |
---|
404 | the total energy at both ends of the culvert and transferring flow. |
---|
405 | """ |
---|
406 | |
---|
407 | centre_point0 = 0.5*(self.exchange_lines[0][0] + self.exchange_lines[0][1]) |
---|
408 | centre_point1 = 0.5*(self.exchange_lines[1][0] + self.exchange_lines[1][1]) |
---|
409 | |
---|
410 | n_exchange_0 = len(self.exchange_lines[0]) |
---|
411 | n_exchange_1 = len(self.exchange_lines[1]) |
---|
412 | |
---|
413 | assert n_exchange_0 == n_exchange_1, 'There should be the same number of points in both exchange_lines' |
---|
414 | |
---|
415 | if n_exchange_0 == 2: |
---|
416 | |
---|
417 | if self.end_points is None: |
---|
418 | self.culvert_vector = centre_point1 - centre_point0 |
---|
419 | else: |
---|
420 | self.culvert_vector = self.end_points[1] - self.end_points[0] |
---|
421 | |
---|
422 | self.outward_vector_0 = self.culvert_vector |
---|
423 | self.outward_vector_1 = - self.culvert_vector |
---|
424 | |
---|
425 | |
---|
426 | elif n_exchange_0 == 4: |
---|
427 | |
---|
428 | self.outward_vector_0 = self.exchange_lines[0][3] - self.exchange_lines[0][2] |
---|
429 | self.outward_vector_1 = self.exchange_lines[1][3] - self.exchange_lines[1][2] |
---|
430 | |
---|
431 | self.culvert_vector = centre_point1 - centre_point0 |
---|
432 | |
---|
433 | else: |
---|
434 | raise Exception, 'n_exchange_0 != 2 or 4' |
---|
435 | |
---|
436 | |
---|
437 | self.culvert_length = math.sqrt(num.sum(self.culvert_vector**2)) |
---|
438 | assert self.culvert_length > 0.0, 'The length of culvert is less than 0' |
---|
439 | self.culvert_vector /= self.culvert_length |
---|
440 | |
---|
441 | outward_vector_0_length = math.sqrt(num.sum(self.outward_vector_0**2)) |
---|
442 | assert outward_vector_0_length > 0.0, 'The length of outlet_vector_0 is less than 0' |
---|
443 | self.outward_vector_0 /= outward_vector_0_length |
---|
444 | |
---|
445 | outward_vector_1_length = math.sqrt(num.sum(self.outward_vector_1**2)) |
---|
446 | assert outward_vector_1_length > 0.0, 'The length of outlet_vector_1 is less than 0' |
---|
447 | self.outward_vector_1 /= outward_vector_1_length |
---|
448 | |
---|
449 | |
---|
450 | if self.enquiry_points is None: |
---|
451 | |
---|
452 | gap = (self.apron + self.enquiry_gap)*self.culvert_vector |
---|
453 | |
---|
454 | self.enquiry_points = [] |
---|
455 | |
---|
456 | self.enquiry_points.append(centre_point0 - gap) |
---|
457 | self.enquiry_points.append(centre_point1 + gap) |
---|
458 | |
---|
459 | |
---|
460 | def discharge_routine(self): |
---|
461 | |
---|
462 | msg = 'Need to impelement ' |
---|
463 | raise |
---|
464 | |
---|
465 | |
---|
466 | def statistics(self): |
---|
467 | |
---|
468 | |
---|
469 | message = '=====================================\n' |
---|
470 | message += 'Structure Operator: %s\n' % self.label |
---|
471 | message += '=====================================\n' |
---|
472 | |
---|
473 | message += 'Structure Type: %s\n' % self.structure_type |
---|
474 | |
---|
475 | message += 'Description\n' |
---|
476 | message += '%s' % self.description |
---|
477 | message += '\n' |
---|
478 | |
---|
479 | for i, inlet in enumerate(self.inlets): |
---|
480 | message += '-------------------------------------\n' |
---|
481 | message += 'Inlet %i\n' % i |
---|
482 | message += '-------------------------------------\n' |
---|
483 | |
---|
484 | message += 'inlet triangle indices and centres and elevations\n' |
---|
485 | message += '%s' % inlet.triangle_indices |
---|
486 | message += '\n' |
---|
487 | |
---|
488 | message += '%s' % self.domain.get_centroid_coordinates()[inlet.triangle_indices] |
---|
489 | message += '\n' |
---|
490 | |
---|
491 | elev = self.domain.quantities['elevation'].centroid_values[inlet.triangle_indices] |
---|
492 | message += '%s' % elev |
---|
493 | message += '\n' |
---|
494 | |
---|
495 | elevation_range = elev.max() - elev.min() |
---|
496 | if not num.allclose(elevation_range, 0.): |
---|
497 | message += 'Warning: non-constant inlet elevation can cause well-balancing problems' |
---|
498 | |
---|
499 | message += 'region\n' |
---|
500 | message += '%s' % inlet.region |
---|
501 | message += '\n' |
---|
502 | |
---|
503 | message += '=====================================\n' |
---|
504 | |
---|
505 | return message |
---|
506 | |
---|
507 | |
---|
508 | def print_statistics(self): |
---|
509 | |
---|
510 | print self.statistics() |
---|
511 | |
---|
512 | |
---|
513 | def print_timestepping_statistics(self): |
---|
514 | |
---|
515 | message = '---------------------------\n' |
---|
516 | message += 'Structure report for %s:\n' % self.label |
---|
517 | message += '--------------------------\n' |
---|
518 | message += 'Type: %s\n' % self.structure_type |
---|
519 | |
---|
520 | message += 'inlets[0]_enquiry_depth [m]: %.2f\n' %self.inlets[0].get_enquiry_depth() |
---|
521 | message += 'inlets[0]_enquiry_speed [m/s]: %.2f\n' %self.inlets[0].get_enquiry_speed() |
---|
522 | message += 'inlets[0]_enquiry_stage [m]: %.2f\n' %self.inlets[0].get_enquiry_stage() |
---|
523 | message += 'inlets[0]_enquiry_elevation [m]: %.2f\n' %self.inlets[0].get_enquiry_elevation() |
---|
524 | message += 'inlets[0]_average_depth [m]: %.2f\n' %self.inlets[0].get_average_depth() |
---|
525 | message += 'inlets[0]_average_speed [m/s]: %.2f\n' %self.inlets[0].get_average_speed() |
---|
526 | message += 'inlets[0]_average_stage [m]: %.2f\n' %self.inlets[0].get_average_stage() |
---|
527 | message += 'inlets[0]_average_elevation [m]: %.2f\n' %self.inlets[0].get_average_elevation() |
---|
528 | |
---|
529 | message += '\n' |
---|
530 | |
---|
531 | message += 'inlets[1]_enquiry_depth [m]: %.2f\n' %self.inlets[1].get_enquiry_depth() |
---|
532 | message += 'inlets[1]_enquiry_speed [m/s]: %.2f\n' %self.inlets[1].get_enquiry_speed() |
---|
533 | message += 'inlets[1]_enquiry_stage [m]: %.2f\n' %self.inlets[1].get_enquiry_stage() |
---|
534 | message += 'inlets[1]_enquiry_elevation [m]: %.2f\n' %self.inlets[1].get_enquiry_elevation() |
---|
535 | |
---|
536 | message += 'inlets[1]_average_depth [m]: %.2f\n' %self.inlets[1].get_average_depth() |
---|
537 | message += 'inlets[1]_average_speed [m/s]: %.2f\n' %self.inlets[1].get_average_speed() |
---|
538 | message += 'inlets[1]_average_stage [m]: %.2f\n' %self.inlets[1].get_average_stage() |
---|
539 | message += 'inlets[1]_average_elevation [m]: %.2f\n' %self.inlets[1].get_average_elevation() |
---|
540 | |
---|
541 | |
---|
542 | message += 'Discharge [m^3/s]: %.2f\n' % self.discharge |
---|
543 | message += 'Velocity [m/s]: %.2f\n' % self.velocity |
---|
544 | message += 'Outlet Depth [m]: %.2f\n' % self.outlet_depth |
---|
545 | message += 'Accumulated Flow [m^3]: %.2f\n' % self.accumulated_flow |
---|
546 | message += 'Inlet Driving Energy %.2f\n' % self.driving_energy |
---|
547 | message += 'Delta Total Energy %.2f\n' % self.delta_total_energy |
---|
548 | message += 'Control at this instant: %s\n' % self.case |
---|
549 | |
---|
550 | |
---|
551 | |
---|
552 | |
---|
553 | print message |
---|
554 | |
---|
555 | |
---|
556 | def set_logging(self, flag=True): |
---|
557 | |
---|
558 | self.logging = flag |
---|
559 | |
---|
560 | # If flag is true open file with mode = "w" to form a clean file for logging |
---|
561 | if self.logging: |
---|
562 | self.log_filename = self.domain.get_datadir() + '/' + self.label + '.log' |
---|
563 | log_to_file(self.log_filename, self.statistics(), mode='w') |
---|
564 | log_to_file(self.log_filename, 'time, discharge, velocity, accumulated_flow, driving_energy, delta_total_energy') |
---|
565 | |
---|
566 | #log_to_file(self.log_filename, self.culvert_type) |
---|
567 | |
---|
568 | |
---|
569 | def timestepping_statistics(self): |
---|
570 | |
---|
571 | message = '%.5f, ' % self.domain.get_time() |
---|
572 | message += '%.5f, ' % self.discharge |
---|
573 | message += '%.5f, ' % self.velocity |
---|
574 | message += '%.5f, ' % self.accumulated_flow |
---|
575 | message += '%.5f, ' % self.driving_energy |
---|
576 | message += '%.5f' % self.delta_total_energy |
---|
577 | |
---|
578 | |
---|
579 | |
---|
580 | return message |
---|
581 | |
---|
582 | |
---|
583 | def get_inlets(self): |
---|
584 | |
---|
585 | return self.inlets |
---|
586 | |
---|
587 | |
---|
588 | def get_culvert_length(self): |
---|
589 | |
---|
590 | return self.culvert_length |
---|
591 | |
---|
592 | |
---|
593 | |
---|
594 | def get_culvert_slope(self): |
---|
595 | |
---|
596 | inlet0 = self.inlets[0] |
---|
597 | inlet1 = self.inlets[1] |
---|
598 | |
---|
599 | elev0 = inlet0.get_enquiry_invert_elevation() |
---|
600 | elev1 = inlet1.get_enquiry_invert_elevation() |
---|
601 | |
---|
602 | return (elev1-elev0)/self.get_culvert_length() |
---|
603 | |
---|
604 | |
---|
605 | |
---|
606 | def get_culvert_width(self): |
---|
607 | |
---|
608 | return self.width |
---|
609 | |
---|
610 | |
---|
611 | def get_culvert_diameter(self): |
---|
612 | |
---|
613 | return self.diameter |
---|
614 | |
---|
615 | |
---|
616 | def get_culvert_height(self): |
---|
617 | |
---|
618 | return self.height |
---|
619 | |
---|
620 | def get_culvert_z1(self): #added by PM 4/10/2013 |
---|
621 | |
---|
622 | return self.z1 #added by PM 4/10/2013 |
---|
623 | |
---|
624 | def get_culvert_z2(self): #added by PM 4/10/2013 |
---|
625 | |
---|
626 | return self.z2 #added by PM 4/10/2013 |
---|
627 | |
---|
628 | def get_culvert_apron(self): |
---|
629 | |
---|
630 | return self.apron |
---|
631 | |
---|
632 | |
---|
633 | def get_master_proc(self): |
---|
634 | |
---|
635 | return 0 |
---|
636 | |
---|
637 | |
---|
638 | |
---|
639 | #-------------------------------------------------------- |
---|
640 | # Set of enquiry functions so that in the sequential and paralle case |
---|
641 | # we can get equiry info fron the master Proc |
---|
642 | #--------------------------------------------------------- |
---|
643 | |
---|
644 | def get_enquiry_stages(self): |
---|
645 | |
---|
646 | enq0 = self.inlets[0].get_enquiry_stage() |
---|
647 | enq1 = self.inlets[1].get_enquiry_stage() |
---|
648 | |
---|
649 | return [enq0, enq1] |
---|
650 | |
---|
651 | |
---|
652 | def get_enquiry_depths(self): |
---|
653 | |
---|
654 | enq0 = self.inlets[0].get_enquiry_depth() |
---|
655 | enq1 = self.inlets[1].get_enquiry_depth() |
---|
656 | |
---|
657 | return [enq0, enq1] |
---|
658 | |
---|
659 | |
---|
660 | def get_enquiry_positions(self): |
---|
661 | |
---|
662 | enq0 = self.inlets[0].get_enquiry_position() |
---|
663 | enq1 = self.inlets[1].get_enquiry_position() |
---|
664 | |
---|
665 | return [enq0, enq1] |
---|
666 | |
---|
667 | |
---|
668 | def get_enquiry_xmoms(self): |
---|
669 | |
---|
670 | enq0 = self.inlets[0].get_enquiry_xmom() |
---|
671 | enq1 = self.inlets[1].get_enquiry_xmom() |
---|
672 | |
---|
673 | return [enq0, enq1] |
---|
674 | |
---|
675 | def get_enquiry_ymoms(self): |
---|
676 | |
---|
677 | enq0 = self.inlets[0].get_enquiry_ymom() |
---|
678 | enq1 = self.inlets[1].get_enquiry_ymom() |
---|
679 | |
---|
680 | return [enq0, enq1] |
---|
681 | |
---|
682 | |
---|
683 | def get_enquiry_elevations(self): |
---|
684 | |
---|
685 | enq0 = self.inlets[0].get_enquiry_elevation() |
---|
686 | enq1 = self.inlets[1].get_enquiry_elevation() |
---|
687 | |
---|
688 | return [enq0, enq1] |
---|
689 | |
---|
690 | |
---|
691 | |
---|
692 | def get_enquiry_water_depths(self): |
---|
693 | |
---|
694 | enq0 = self.inlets[0].get_enquiry_water_depth() |
---|
695 | enq1 = self.inlets[1].get_enquiry_water_depth() |
---|
696 | |
---|
697 | return [enq0, enq1] |
---|
698 | |
---|
699 | |
---|
700 | def get_enquiry_invert_elevations(self): |
---|
701 | |
---|
702 | enq0 = self.inlets[0].get_enquiry_invert_elevation() |
---|
703 | enq1 = self.inlets[1].get_enquiry_invert_elevation() |
---|
704 | |
---|
705 | return [enq0, enq1] |
---|
706 | |
---|
707 | |
---|
708 | def get_enquiry_velocitys(self): |
---|
709 | |
---|
710 | enq0 = self.inlets[0].get_enquiry_velocity() |
---|
711 | enq1 = self.inlets[1].get_enquiry_velocity() |
---|
712 | |
---|
713 | return [enq0, enq1] |
---|
714 | |
---|
715 | |
---|
716 | def get_enquiry_xvelocitys(self): |
---|
717 | |
---|
718 | enq0 = self.inlets[0].get_enquiry_xvelocity() |
---|
719 | enq1 = self.inlets[1].get_enquiry_xvelocity() |
---|
720 | |
---|
721 | return [enq0, enq1] |
---|
722 | |
---|
723 | def get_enquiry_yvelocitys(self): |
---|
724 | |
---|
725 | enq0 = self.inlets[0].get_enquiry_yvelocity() |
---|
726 | enq1 = self.inlets[1].get_enquiry_yvelocity() |
---|
727 | |
---|
728 | return [enq0, enq1] |
---|
729 | |
---|
730 | |
---|
731 | def get_enquiry_speeds(self): |
---|
732 | |
---|
733 | enq0 = self.inlets[0].get_enquiry_speed() |
---|
734 | enq1 = self.inlets[1].get_enquiry_speed() |
---|
735 | |
---|
736 | return [enq0, enq1] |
---|
737 | |
---|
738 | |
---|
739 | def get_enquiry_velocity_heads(self): |
---|
740 | |
---|
741 | enq0 = self.inlets[0].get_enquiry_velocity_head() |
---|
742 | enq1 = self.inlets[1].get_enquiry_velocity_head() |
---|
743 | |
---|
744 | return [enq0, enq1] |
---|
745 | |
---|
746 | |
---|
747 | def get_enquiry_total_energys(self): |
---|
748 | |
---|
749 | enq0 = self.inlets[0].get_enquiry_total_energy() |
---|
750 | enq1 = self.inlets[1].get_enquiry_total_energy() |
---|
751 | |
---|
752 | return [enq0, enq1] |
---|
753 | |
---|
754 | |
---|
755 | def get_enquiry_specific_energys(self): |
---|
756 | |
---|
757 | enq0 = self.inlets[0].get_enquiry_specific_energy() |
---|
758 | enq1 = self.inlets[1].get_enquiry_specific_energy() |
---|
759 | |
---|
760 | return [enq0, enq1] |
---|
761 | |
---|