Skip to content

Commit 6134755

Browse files
committed
EPyT: Add new EPANET functions
1 parent ba52b59 commit 6134755

File tree

5 files changed

+71
-0
lines changed

5 files changed

+71
-0
lines changed

epanet_plus/epanet_wrapper.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,20 @@ def setnodevalue(self, index: int, node_property: int, value: float):
857857
return self._process_result(epanet.EN_setnodevalue(self._ph, index, node_property,
858858
value))
859859

860+
def setnodevaluse(self, node_property: int, values: list[float]):
861+
"""
862+
EN_setnodevalues
863+
864+
Parameters
865+
----------
866+
node_property : `int`
867+
values : `list[float]`
868+
"""
869+
if self._use_project is False:
870+
return self._process_result(epanet.ENsetnodevalues(node_property, values))
871+
else:
872+
return self._process_result(epanet.EN_setnodevalues(self._ph, node_property, values))
873+
860874
def setjuncdata(self, index: int, elev: float, dmnd: float, dmnd_pat: str):
861875
"""
862876
EN_setjuncdata

python-extension/pyepanet.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,34 @@ PyObject* method_EN_setnodevalue(PyObject* self, PyObject* args)
10211021
return r;
10221022
}
10231023

1024+
PyObject* method_EN_setnodevalues(PyObject* self, PyObject* args)
1025+
{
1026+
uintptr_t ptr;
1027+
int property;
1028+
PyObject* values = NULL;
1029+
if(!PyArg_ParseTuple(args, "KiO", &ptr, &property, &values)) {
1030+
return NULL;
1031+
}
1032+
EN_Project ph = (EN_Project) ptr;
1033+
1034+
int count = PyList_GET_SIZE(values);
1035+
double* rawValues = (double*) malloc(sizeof(double) * count);
1036+
for(int i=0; i != count; i++) {
1037+
rawValues[i] = PyFloat_AsDouble(PyList_GET_ITEM(values, i));
1038+
}
1039+
1040+
int badIndex;
1041+
PyObject* err = PyLong_FromLong(EN_setnodevalues(ph, property, rawValues, &badIndex));
1042+
PyObject* pyBadIndex = PyLong_FromLong(badIndex);
1043+
free(rawValues);
1044+
1045+
PyObject* r = PyTuple_Pack(1, err, pyBadIndex);
1046+
Py_DECREF(err);
1047+
Py_DECREF(pyBadIndex);
1048+
1049+
return r;
1050+
}
1051+
10241052
PyObject* method_EN_setjuncdata(PyObject* self, PyObject* args)
10251053
{
10261054
uintptr_t ptr;

python-extension/pyepanet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ PyObject* method_EN_setnodeid(PyObject* self, PyObject* args);
5757
PyObject* method_EN_getnodetype(PyObject* self, PyObject* args);
5858
PyObject* method_EN_getnodevalue(PyObject* self, PyObject* args);
5959
PyObject* method_EN_setnodevalue(PyObject* self, PyObject* args);
60+
PyObject* method_EN_setnodevalues(PyObject* self, PyObject* args);
6061
PyObject* method_EN_setjuncdata(PyObject* self, PyObject* args);
6162
PyObject* method_EN_settankdata(PyObject* self, PyObject* args);
6263
PyObject* method_EN_getcoord(PyObject* self, PyObject* args);

python-extension/pyepanet2.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,6 +1833,33 @@ PyObject* method_ENsetnodevalue(PyObject* self, PyObject* args)
18331833
return r;
18341834
}
18351835

1836+
PyObject* method_ENsetnodevalues(PyObject* self, PyObject* args)
1837+
{
1838+
int property;
1839+
PyObject* values = NULL;
1840+
1841+
if(!PyArg_ParseTuple(args, "iO", &property, &values)) {
1842+
return NULL;
1843+
}
1844+
1845+
int count = PyList_GET_SIZE(values);
1846+
float* rawValues = (float*) malloc(sizeof(float) * count);
1847+
for(int i=0; i != count; i++) {
1848+
rawValues[i] = PyFloat_AsDouble(PyList_GET_ITEM(values, i));
1849+
}
1850+
1851+
int badIndex;
1852+
PyObject* err = PyLong_FromLong(ENsetnodevalues(property, rawValues, &badIndex));
1853+
PyObject* pyBadIndex = PyLong_FromLong(badIndex);
1854+
free(rawValues);
1855+
1856+
PyObject* r = PyTuple_Pack(1, err, pyBadIndex);
1857+
Py_DECREF(err);
1858+
Py_DECREF(pyBadIndex);
1859+
1860+
return r;
1861+
}
1862+
18361863
PyObject* method_ENsetoption(PyObject* self, PyObject* args)
18371864
{
18381865
int option;

python-extension/pyepanet2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ PyObject* method_ENsetlinktype(PyObject* self, PyObject* args);
105105
PyObject* method_ENsetlinkvalue(PyObject* self, PyObject* args);
106106
PyObject* method_ENsetnodeid(PyObject* self, PyObject* args);
107107
PyObject* method_ENsetnodevalue(PyObject* self, PyObject* args);
108+
PyObject* method_ENsetnodevalues(PyObject* self, PyObject* args);
108109
PyObject* method_ENsetoption(PyObject* self, PyObject* args);
109110
PyObject* method_ENsetpattern(PyObject* self, PyObject* args);
110111
PyObject* method_ENsetpatternid(PyObject* self, PyObject* args);

0 commit comments

Comments
 (0)