Skip to content

Commit

Permalink
Merge pull request pyswmm#1 from katmratliff/trackpollut
Browse files Browse the repository at this point in the history
add subcatchment surface buildup API function
  • Loading branch information
katmratliff authored Oct 25, 2017
2 parents 932281f + 993023b commit 32c1613
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
Binary file modified pyswmm/lib/windows/swmm5.dll
Binary file not shown.
11 changes: 11 additions & 0 deletions pyswmm/subcatchments.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,3 +579,14 @@ def statistics(self):
:rtype: dict
"""
return self._model.subcatch_statistics(self.subcatchmentid)

@property
def buildup(self):
"""
Subcatchment surface buildup.
Number of values present depends on number of pollutants present.
:return: Group of subcatchment surface buildup values/counts.
:rtype: dict
"""
return self._model.subcatch_buildup(self.subcatchmentid)
49 changes: 49 additions & 0 deletions pyswmm/swmm5.py
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,55 @@ def subcatch_statistics(self, ID):
object_stats, attr)
return out_dict

def subcatch_buildup(self, ID):
"""
Get surface buildup for a Subcatchment.
:param str ID: Subcatchment ID
:return: Subcatchment surface buildup.
:rtype: dict
"""
index = self.getObjectIDIndex(tka.ObjectType.SUBCATCH.value, ID)

# SWMM function handle.
swmm_subcbuildup_func = self.SWMMlibobj.swmm_getSubcatchBuildup
# SWMM function handle argument output structure.
swmm_subcbuildup_func_arg = ctypes.POINTER(tka.SubcBuildup)
# Define argument.
swmm_subcbuildup_func.argtypes = (
ctypes.c_int,
swmm_subcbuildup_func_arg, )

object_buildup = tka.SubcBuildup()
errcode = swmm_subcbuildup_func(
ctypes.c_int(index), ctypes.byref(object_buildup))

self._error_check(errcode)
# Copy Items to Dictionary using Alias Names.
out_dict = {}
for attr in dir(object_buildup):
if "_" not in attr:
# Pollutant Array.
if attr == "subcatchBuildup":
out_dict[object_buildup._py_alias_ids[attr]] = {}
buildup_array = getattr(object_buildup, attr)
pollut_ids = self.getObjectIDList(
tka.ObjectType.POLLUT.value)
if len(pollut_ids) > 0:
for ind in range(len(pollut_ids)):
out_dict[object_buildup._py_alias_ids[attr]][
pollut_ids[ind]] = buildup_array[ind]
else:
out_dict[object_buildup._py_alias_ids[attr]] = getattr(
object_buildup, attr)

# Free Subcatchment Buildup Pollutant Array.
freesubcatchbuildup = self.SWMMlibobj.swmm_freeSubcatchBuildup
freesubcatchbuildup.argtypes = (swmm_subcbuildup_func_arg, )
freesubcatchbuildup(object_buildup)

return out_dict

def flow_routing_stats(self):
"""
Get Flow Routing System stats.
Expand Down
7 changes: 7 additions & 0 deletions pyswmm/toolkitapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,13 @@ class SubcStats(ctypes.Structure):
"maxFlow": "peak_runoff_rate"
}


class SubcBuildup(ctypes.Structure):
_fields_ = [("subcatchBuildup", PollutArray)]
_py_alias_ids = {
"subcatchBuildup": "subcatchment_surface_buildup"
}


class RoutingTotals(ctypes.Structure):
_fields_ = [("dwInflow", ctypes.c_double), ("wwInflow", ctypes.c_double),
Expand Down

0 comments on commit 32c1613

Please sign in to comment.