Ruralwater¶
Hydraulic engineering webapp.
Free software: Apache license
Documentation: https://ruralwater.readthedocs.io/en/latest/
Source: https://bitbucket.org/ruralwater/ruralwater/src/master/
Contributing: https://github.com/PyCQA/bandit/blob/master/CONTRIBUTING.md
Purpose of the project¶
Motivation¶
How to install ‘ruralwater’ on your local machine¶
Python 3.7+
Redis
webapp.core.settings.redis.py
:
USE_REDIS = True
and set it to False
.clone the
development
branch on you local machinerun the script
setup_linux_complete.sh
(linux) orsetup_win_complete.ps1
(windows)Navigate to localhost (http://127.0.0.1:8000/)
Manual installation
clone the “development” branch on you local machine
create and activate a virtual environment
install the requirements at requirements/development.txt
run the script
setup_linux_database.sh
(linux) orsetup_win_database.ps1
(windows)Navigate to localhost (http://127.0.0.1:8000/)
setup_*_database
implements
the following operations:generates the database (using the django framework)
populates the database with the hydraulic hardware data
creates a superuser and two mock users:
‘demo’, who is the superuser, with password: pippo121
‘cat’, with password: meow
‘dog’, with password: bark
Contributing¶
XXX for an introduction to the ‘application programming interface’ exposed by the ‘business logic’
For contributors more interested in “test-driven development” XXX provides the description of the tests currently included in this repository.
XXX provides the issues tracker.
Current status of the project¶
the algorithm to optimize the design of dendridic gravity-fed water supplies
the design of the user interface, more specifically the javascript for the client side controls to define the water supply.|
Tech/framework used¶
Ruralwater is built with:
Tests¶
cd into the ‘webapp’ folder
run:
python manage.py runserver
run:
python manage.py test
testing
forlder
and specifically inside the file howto_casestudies.md.
cd into the ‘webapp’ folder
run:
python manage.py runserver
Authors¶
Claudio Finizio (Initial work)
Manual¶
Hydraulics¶
been enhaced to make it more evident all calculations based on altimetric elevation and hydraulic energy. So, the slopes of the pathways appear very steep, much more than the reality found walking on the ground.
here is a pdf file pdf
What the software does¶
The software tackles two distinct kinds of hydraulic problems:
the hydraulic design problem - given the required water flow, find the pipes that will provide such water at the minimum cost
the hydraulic check problem - given the pipes, find the water flows and perform a control to see whether the working conditions do not exceed the rated limits of the installed hydraulic hardware.
Gravity¶
Warning
Linear programming techniques work well for pipe sizing problems involving branched systems with one directional flow (see Robinson, 1976). However, discrete pipe and discrete pipe pressure classes mean that in a hilly profile we have to design a gravity system by use of systematic search of the best solution. We outline that cost of pipes and hydraulic friction depend heavily of the second and fifth power of the pipes’ radii, so it is warranted that a suitable design may result in remarkable gains on the invested money.
The physical system¶
Warning
Remark: in this document, for the sake of clarity, we espose the hydaulic thory unsing as an example a simple water supply made of a spring, a single junction that bisects in two and two water tanks. The whole system is made of three trenches. In a real system the topology may be more complex than this; there may be more junctions. Also, some water tanks may receive water and then discarge it in another water supply, as if they were “springs”. We kept this example simple to ease the reader getting used to the water supply; in the next section, algorithms, we will instead make use of a “generic” water supply, made of a “generic” number of junctions.
General concepts¶
The equations that model the system¶
the continuity of water flows.
the continuity of hydraulic energy.
there is a spring
from th spring the pipeline goes to a junction where the pipe branches in two
the two branches go to Tank1 and Tank2 respectively.
the conservation of water flows
the energy difference in each of the 3 branches is the hydraulic friction in the pipes
We start with the conservation of flows:
Next comes the conservation of energy:
\(L_1\) would be 600 \(D_1\) would be the internal diameter of a 2 inches pipe \(L_2\) would be 600 \(D_2\) would be the internal diameter of a 2 inches pipe
In the ‘hydraulic design problem’ the unknowns are: \(Q_{Spring\rightarrow{Tee}}\) \(Q_{Tee\rightarrow{Tank1}}\) \(Q_{Tee\rightarrow{Tank2}}\) The known data are all the other symbols. Therefore we have 4 equations and 4 unknowns and the system can be solved.
Check¶
Design¶
algorithms_gravity_design
how this translates in an algorithm.Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Borehole’s station¶
I link with the module gravity
now i link with the class GravityDesign
and even the method solve_hydraulic_design_problem()
I want to refer to the equations (system_of_equations) and to the algorithm (the_algorithm)
We now move to the second typology of rural water supply system: a small pumping station that connects a borehole, with a water reservoir which is far from the borehole and usually at higher that that of the site where the borehole is located.
We deal with two kinds of borehole stations: with and without electric power. The reason is because this software is dedicated to rural solutions and, as such, it must consider the case where electric power is not available.
Remark: with ‘not available’ here we mean an arrangement that works entirely *without electric power. With ‘electricless’ we mean a solution that is not *making use of electric power because it is preferred to have a rural plant
Where electric current is not available, it can nonetheless be produced by an electric generator set.
However, when we speak of ‘electricless’ pumping station, we mean that the presence of electric power is intentionally avoided (and so it is avoided to use an electric generator) despite it can always be generated even in remote area by a generating set. The logic is that electric power is both a difficult subject and it introduces complexity in the hardware and the need for spare parts.
The key point is that electric power might be tricky in a rural context. Knowledge about how to run the maintenance of an electric pumping station is hard and could be not available locally; perhaps the spare parts could be difficult to find on the local market. For these reasons, this software allows you to design a pumping station composed of electricity-free parts, and more precisely: a diesel engine with manual start, that drives directly a pump, with no need of electric motor in the pump (since it is driven directly by the engine through a system of belts and pulleys) nor of electric start in the diesel engine itself (which is indeed started manually with a handle keyed on the crankshaft). Readers who have experience in humanitarian water supply interventions in rural areas of the world will recognise in this ‘electricless’ station the arrangement with a Listeroid diesel engine and a monopump. We provide more information about such equipment in these pages: LINK engine and LINK pump.
the ‘electric’ arrangement, where we may use electric power.
IMPORTANT: this a work in progress so the sections below are now kept as stubs for future implementation.
Electric Station¶
Check problem¶
Design problem¶
Will it be preferable to adopt small bore feeders (and therefore limit the cost of pipes) and consequently have a high hydraulic energy to overcome (and therefore install more expensive pumps) or adopt the opposite solution (larger pipes and smaller pumps)?
Note
If only I had written down why I had done this. Life would be so much simpler. Documentation allows you to transfer the why behind code. Much in the same way code comments explain the why, and not the how, documentation serves the same purpose
Algorithms¶
Gravity¶
Warning
So far, in the fydraulcis section, we described the theory using a simple water supply composed of a simple Y shape and three trenches. REF FIGURE LA PRIMA Now onwards, we follow a more generic approach, typical of mathematiccs, to describe the algorithm and we will consider a water supply system of a generic tree topology: it may therefore makde of more tahn 3 threnches. Starting from FIGURE we see a susystem of 7 trenches. In real life cases, this case of seven trenches and 5 reserovirs is likely one of the most difficutl cases you could face. Hpwever, the algorithm we describe here are balid of any numer of trenches and any topology, provied it has the topological shape of a tree.
here is a pdf file pdf
Check problem¶
create the hydraulic energy equations of the law of Bernoulli, where the known data are: the friction per unit water flow, the elevation at the spring and at all the reservoirs.
create the water flow continuity equations for each pathway that has children.
the unknowns are: the water flow in each pathway
create the symbolic equations of the law of Bernoulli
create the symbolic equations of the law conservation of water flow
consider the equations above as a system of equations and solve it.
once the system of equation is solved, consider the water flow obtained in each pathway and calculate the hydraulic energy along each pathway.
detect if at any point in any of the pathways, the resulting water pressure (hydraulic energy minus elevation) exceeds the pressure limit for the pipe used in that position.
Design problem¶
The algorithm in a nutshell¶
Before illustrating the algorithm in detail, we outline it. This will make the comprehension of the steps, detailed below, more straightforward. In essence, the hydraulic design problem is an optimization problem, where the objective function is the cost of the piped segments, the variables are the hydraulic energy at each junction where the pipeline bisects and the constraints are the elevation, where the hydraulic energy is tied to be equal to the elevation at the root (the spring) and at the leaves (the reservoirs). The approach we adopt to solve the hydraulic design problem is to perform a “systematic search” (the reader may want to perform a search off the internet about such topics). This means that:
the physical water supply is a tree of trunks; a trunk is a trench where the pipes are laid down and a sequence of ‘segments’ which describe the pipe material, its diameter and the pressure it can withstand and the linear length where such pipe is used along the trench. Along the trunk the flow of water is constant, there are no abstraction points. Each trench has a ‘tail end’ which lies upstream (so, closer to the spring) and a ‘head end’. Water always flows from tail to head. Water flow is different from trunk to trunk since a trunk at its head end may bifurcate into two (or more) trunks, whose tail end correspond with the head end of the parent trunk. What we have described it the topology of a tree or, in more technical terms, an acyclic directed graph of node and each trunk is a node.
a spurious case of the tree is the water supply system composed by a single trunk. In this case we only have one trench, no bifurcations and the pipes connect a spring to a reservoir.
we model the water supply as a tree of trunks. Therefore each trunk is a ‘node’ of a ‘tree’ (aka an acyclic direcyed graph) in mathematical lingo. Each node has an adjancency set which is the list of trunks that stem from a trunk head end.
The equations of hydraulics are therefore translated as follows:
the continuity of water flow translates as: the water flow in a trunk is the sum of the water flows from each trunk in its adjacency list
the continuity of hydraulic energy translates as: for each trunk has a value of energy at its head end and the trunks belongin to its adjacncey list all have this value of energy at theit tails
we call a ‘inner junctions’ all the junctions where a trunk bisects into two or more trunks. Therefore, if we keep in mind the description of the tree of trunks, the junctions are the ‘head end’ of the root trunk (whose tail end is the water spring), the tail end of all trunks that discharge water into a reservoir (we can call them leaf trunks by similarity with the tree) and both the ends of all other trunks.
we keep the energy fixed at the spring and at the tanks; the fixed value is that of the elevation at such points (spring and tanks),
we perform a permutation of all possible values of energy in the the junctions. A permutation is valid only if, for each junction, its parent junction has a higher value of energy, otherwise the water could not flow. Remember that water flows from ‘tail’ to ‘head’ so the ‘tail junction’ must have higher energy than ‘head junction’.
for each permutation which is valid, we then solve the hydraulic design problem in each trunk with the tail and head values of energy fixed. The solution inside the single trunk may differ if the elevation profile is hilly and several algorithms are taken in account to try finding the optimal solution.
The we collect the cost from each trunk for the current permutation and continue looping in all permutations.
Once all permutations have been inspected, we identify the one which leads to the least economic cost.

So far for the logical steps of the algorithm. However, when dealing with the ‘actual’ programming language (python) here we describe how we translated the above logic into language instructions:
to loop over all permutations we adopted the python’s concept of coroutine.
The overbanking energy, an introductory concept, is now introduced.
Overbanking energy¶
Water flows from higher to lower hydraulic energy… 💪 Therefore we set recursively the minimum hydraulic energy at a pathway’s tail end to be the energy at the head end plus “some energy” to allow a difference of hydraulic energy along the pathway and therefore the water flow. Typically the overbanking energy is the elevation plus “some energy”, but in the case that the pathway climbs a hill then the overbanking energy is the highest elevation point downstream plus “some energy”.
Steps of the algorithm¶
The idea is then to perform a “search” by inspecting all possible combinations of hydraulic energy the pathways. This is therefore a permutation. For the allowed value of energy, the root pathway has a tail end energy fixed (it is the elevation), each of the leaves have a head end fixed energy (their elevations). The permutations regard therefore the head energy of the root pathway, the tail energy of the leaves pathways and both tail and head energy of each pathway that are neither root nor leaf. Also, the permutation must be limited to those combinations that allow an energy differential between tail and head end. The goal of the coroutine is exactly to ensure the above conditions. This is so because the coroutine is a generator that allow to loop and ensure the above conditions. Since this process must be valid for each possible topology of the branched network, then the coroutine is in charge of tackling this problem in a generic approach valid for each topology.
Image “5_pathways_overbank - only maxmin hydr energy” shows this idea.
the “Tee Up” may have a max energy of X otherwise water could not flow from the spring
the “Tee left” must
the same logic applies to “Tee right”
The pathways are nodes and some of them are leaves.
the algorithm breaks down the tree of pathways into the pressure zones
for each pressure zone it executes the steps below
it sets the hydraulic energy at the tail end of the root node to be identical to the elevation at that end
it sets the hydraulic energy at the head end of each leaf node to be identical to the elevation at that end
it traverses the tree with a ‘depth-first search’ methodology
while performing such depth-first search, it sets the ‘over-banking’ hydraulic energy to each node (apart from the leaves nodes) tail end. QUESTA FRASE IN MAIUSCOLO EST INCOMPLETA : THIS OVERBANKING ENERGY IS SET RECURSIVELY TO BE “A BIT” GREATER THAN THE OVERBANKING ENERGY AT THE LEAF NODES. COSA FAI AI NODI INTERNI? NON LO HA DETTO
it permutes through all the combinations of over-banking energy at each non-leaf node. At this point each pathway has a value of tail end and head end hydraulic energy set.
it evaluates the most economic pipes for those values of energy; this is the XXX algorithm and is still source of study. The evaluation of which are the most economic pipes cannot be solved by use of the simplex algorithm (as other software do) because we are dealing with hilly profiles (rural indeed) and therefore the pipe pressure classes must be taken in account and the problem to solve becomes non-convex. So, no simplex algorithm of use here…. 😞
it sums the economic cost from each pathway
it selects the solution which led to the lowest economic cost.
Warning
This is currently a work in progress (API wil not be stable before 1.0) so don’t expect it to be perfect but please submit an issue for any bug you find or any feature you want.
The hydraulic problem¶
Here we talk about the problem in the hydraulicn theory. See Hydraulics to know what the water engineer must do.
The computer software algorithm¶
Here we talk about the computer algorithm to tackle the hydraulic theory. See algorithms to know what the computer scientist must do.
Glossary¶
- pathlength
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum..
- downrange
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum..
- elevation
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
- hcp
the hydraulic check problem
- hdp
the hydraulic design problem
- hydraulic_energy
why energy is expressed in meters SPIEGARE NELLA DOCUMENTAIZONE ESTERNA AL CODICE RICORDA CHE WIKIPEDIA LO SPIEGA BENE
- swivel_point
Intersection between the HGL from a pipe
..see some-label-name for more detail