Skip to content

Commit

Permalink
Merge pull request #39 from OpenWaterAnalytics/dev
Browse files Browse the repository at this point in the history
EPyT 1.0.9-beta.4
  • Loading branch information
Mariosmsk authored Apr 16, 2024
2 parents 3c961f3 + c9ecf49 commit 4f1731b
Show file tree
Hide file tree
Showing 23 changed files with 863 additions and 457 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ jobs:
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
pytest -v
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ If you want to contribute, please check out our [Code of Conduct](https://github
|<b> MSX Functions </b>
|loadMSXFile|Opens the EPANET-MSX toolkit system|
|unloadMSX|Closes the EPANET-MSX toolkit system|
|addMSXPattern|Adds a new, empty MSX source time pattern to the project|
|initializeMSXQualityAnalysis|Initializes the MSX system before solving for water quality results in step-wise fashion|
|stepMSXQualityAnalysisTimeLeft|Advances the water quality solution through a single water quality time step when performing a step-wise simulation|
|saveMSXFile|Saves the data associated with the current MSX project into a new MSX input file|
Expand Down Expand Up @@ -584,6 +585,8 @@ If you want to contribute, please check out our [Code of Conduct](https://github
|setMSXTimeStep|Sets time step|
|setMSXPatternValue|Assigns a new value to the multiplier for a specific time period in a given MSX source time pattern|
|setMSXPattern|Sets all of the multiplier factors for a specific time pattern|
|setMSXParametersPipesValue|Assigns a value to a particular reaction parameter for given pipes|
|setMSXParametersTanksValue|Assigns a value to a particular reaction parameter for given tanks|
|setMSXConstantsValue|Assigns a new value to a specific reaction constant|
|useMSXHydraulicFile|Uses a previously saved EPANET hydraulics file as the source of hydraulic information|

Expand Down
3 changes: 2 additions & 1 deletion epyt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
__author__ = """Marios S. Kyriakou"""
__email__ = "[email protected]"
__version__ = "1.0.9-beta.2"
__version__ = "1.0.9-beta.4"
__msxversion__ = "2.0.0"
__copyright__ = """Copyright 2022, KIOS Research and Innovation Center of Excellence (KIOS CoE),
University of Cyprus (www.kios.org.cy)."""
__license__ = "EUPL License, Version 1.2"
Expand Down
1,026 changes: 712 additions & 314 deletions epyt/epanet.py

Large diffs are not rendered by default.

Binary file removed epyt/libraries/glnx/epanetmsx
Binary file not shown.
Binary file modified epyt/libraries/glnx/epanetmsx.so
Binary file not shown.
Binary file added epyt/libraries/glnx/libepanet2.so
Binary file not shown.
Binary file removed epyt/libraries/glnx/libepanet2_2
Binary file not shown.
Binary file removed epyt/libraries/glnx/libepanet2_2.so
Binary file not shown.
Binary file added epyt/libraries/mac/epanetmsx.dylib
Binary file not shown.
Binary file added epyt/libraries/mac/libepanet2.dylib
Binary file not shown.
Binary file removed epyt/libraries/mac/libepanet2_2
Binary file not shown.
Binary file removed epyt/libraries/mac/libepanet2_2.dylib
Binary file not shown.
File renamed without changes.
File renamed without changes.
Binary file removed epyt/libraries/win/epanet2_2/32bit/epanet2.dll
Binary file not shown.
Binary file removed epyt/libraries/win/epanet2_2/32bit/epanet2.exe
Binary file not shown.
Binary file removed epyt/libraries/win/epanet2_2/64bit/epanetmsx.dll
Binary file not shown.
Binary file added epyt/libraries/win/epanetmsx.dll
Binary file not shown.
File renamed without changes.
56 changes: 32 additions & 24 deletions epyt/tests/net1_unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def testStepByStepAnalysis(self):
9.452347598503036e-07, 9.28221894076609e-07, 9.084721628771827e-07, 2.416368471024177,
2.4073945733540967,
2.3857323225219194])
np.testing.assert_array_almost_equal(velocity, v_desired, err_msg="Wrong Velocity output")
np.testing.assert_array_almost_equal(velocity, v_desired, decimal=3, err_msg="Wrong Velocity output")
h_desired = np.array(
[19.117018607743262, 18.784557106294415, 18.575821630530413, 18.350323106559813, 18.247536420722895,
18.125096976393024, 18.12282340051479, 18.099494697653654, 17.95951292501252, 17.843745116056084,
Expand All @@ -202,9 +202,9 @@ def testStepByStepAnalysis(self):
2.637534635141492e-11,
2.5352164811920375e-11, 20.08353269330769, 19.945617762391066,
19.61450487894149])
np.testing.assert_array_almost_equal(head_loss, h_desired, err_msg="Wrong HeadLoss output")
f_desired = [np.array(1866.17582999), np.array(1848.5811499), np.array(1837.46107838)]
np.testing.assert_array_almost_equal(flow[0:3], f_desired, err_msg="Wrong Flows output")
np.testing.assert_array_almost_equal(head_loss, h_desired, decimal=3, err_msg="Wrong HeadLoss output")
f_desired = [np.array(1866.17578125), np.array(1848.58117676), np.array(1837.46105957)]
np.testing.assert_array_almost_equal(flow[0:3], f_desired, decimal=3, err_msg="Wrong Flows output")

""" ------------------------------------------------------------------------- """

Expand Down Expand Up @@ -274,20 +274,21 @@ def testSetLinkRoughnessCoefficientIndex(self):

def testSetLinkMinorLossCoefficientAll(self):
self.epanetClass.setLinkMinorLossCoeff([1.2 for _ in self.epanetClass.getLinkMinorLossCoeff()])
assert all(self.epanetClass.getLinkMinorLossCoeff() == [1.2, 1.2000000000000002, 1.2000000000000002,
1.2000000000000002, 1.2, 1.2,
1.2, 1.2000000000000002, 1.2, 1.2, 1.2, 1.2,
0.0]), "Wrong set minor loss output"
expected_values = [1.2, 1.2000000000000002, 1.2000000000000002, 1.2000000000000002, 1.2, 1.2,
1.2, 1.2000000000000002, 1.2, 1.2, 1.2, 1.2, 0.0]
actual_values = self.epanetClass.getLinkMinorLossCoeff()
assert np.isclose(actual_values, expected_values).all(), "Wrong set minor loss output"

def testSetLinkMinorLossCoefficientIndices(self):
self.epanetClass.setLinkMinorLossCoeff([2, 3, 4], [1.01, 1.02, 1.01]) # index, value
assert all(self.epanetClass.getLinkMinorLossCoeff([2, 3, 4]) == [1.01, 1.02,
1.01]), "Wrong set minor loss output"
expected_values = [1.01, 1.02, 1.01]
self.epanetClass.setLinkMinorLossCoeff([2, 3, 4], expected_values) # index, value
actual_values = self.epanetClass.getLinkMinorLossCoeff([2, 3, 4])
for expected, actual in zip(expected_values, actual_values):
self.assertAlmostEqual(expected, actual, places=2, msg="Wrong set minor loss output")

def testSetLinkMinorLossCoefficientIndex(self):
self.epanetClass.setLinkMinorLossCoeff(2, 1.01) # index, value
assert self.epanetClass.getLinkMinorLossCoeff(2) == 1.01, "Wrong set minor loss output"

assert np.isclose(self.epanetClass.getLinkMinorLossCoeff(2), 1.01, atol=1e-6), "Wrong set minor loss output"
""" ------------------------------------------------------------------------- """

def testSetLinkInitialStatusAll(self):
Expand All @@ -306,28 +307,35 @@ def testSetLinkInitialStatusIndex(self):

def testSetLinkBulkReactionCoefficientAll(self):
self.epanetClass.setLinkBulkReactionCoeff([i - 0.055 for i in self.epanetClass.getLinkBulkReactionCoeff()])
assert all(
self.epanetClass.getLinkBulkReactionCoeff() == [-0.555, -0.555, -0.555, -0.555, -0.555, -0.555, -0.555,
-0.555, -0.555, -0.555, -0.555, -0.555,
0.0]), "Wrong set link bulk reaction output"

def assert_almost_equal(actual, expected, tolerance, message):
for a, e in zip(actual, expected):
assert abs(a - e) <= tolerance, message

expected_values = [-0.555, -0.555, -0.555, -0.555, -0.555, -0.555, -0.555,
-0.555, -0.555, -0.555, -0.555, -0.555, 0.0]
actual_values = self.epanetClass.getLinkBulkReactionCoeff()
assert_almost_equal(actual_values, expected_values, tolerance=1e-3, message="Wrong set link bulk reaction "
"output")

def testSetLinkBulkReactionCoefficientIndices(self):
self.epanetClass.setLinkBulkReactionCoeff([2, 3, 13], [0.1] * 3) # index, value
assert all(self.epanetClass.getLinkBulkReactionCoeff([2, 3, 13]) == [0.1, 0.1,
0.0]), "Wrong set link bulk reaction " \
"output"
expected_values = np.array([0.1, 0.1, 0.0])
actual_values = self.epanetClass.getLinkBulkReactionCoeff([2, 3, 13])
assert np.isclose(actual_values, expected_values).all(), "Wrong set link bulk reaction output"

def testSetLinkBulkReactionCoefficientIndex(self):
self.epanetClass.setLinkBulkReactionCoeff(1, 0.2) # index, value
assert self.epanetClass.getLinkBulkReactionCoeff(1) == 0.2, "Wrong set link bulk reaction output"
assert np.isclose(self.epanetClass.getLinkBulkReactionCoeff(1),
0.2).all(), "Wrong set link bulk reaction output"

""" ------------------------------------------------------------------------- """

def testSetLinkWallReactionCoefficientAll(self):
self.epanetClass.setLinkWallReactionCoeff([i * (-1.1) for i in self.epanetClass.getLinkWallReactionCoeff()])
assert all(self.epanetClass.getLinkWallReactionCoeff() == [1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1,
1.1, 1.1,
0.0]), "Wrong set link wall reaction output"
expected_values = [1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 0.0]
actual_values = self.epanetClass.getLinkWallReactionCoeff()
assert np.isclose(actual_values, expected_values).all(), "Wrong set link wall reaction output"

def testSetLinkWallReactionCoefficientIndices(self):
self.epanetClass.setLinkWallReactionCoeff([2, 3, 13], [-2] * 3) # index, value
Expand Down
Loading

0 comments on commit 4f1731b

Please sign in to comment.