(Note: this readme is autogenerated)
This library provides tools for modeling and analyzing fluid flow in directed networks. It is designed for scenarios where the edges represent physical connections (e.g., pipes) with associated parameters (e.g., length, diameter, resistance), and nodes represent points where flows converge or diverge.
- Represent a network as a directed graph using
networkx. - Calculate node heads (pressure) and edge flows based on boundary conditions.
- Propagate rates and heads through the network.
- Support for single-inflow and single-outflow networks.
- Flexible handling of boundary conditions for heads and rates.
To use the library, clone the repository and install the required dependencies:
pip install -r requirements.txtDependencies:
numpyscipynetworkx
from src.fluid_functions import single_phase_head_gradient
from src.network import Network
# Define edges as (node1, node2, edge_data)
edges = [
('A', 'B', {'length': 10, 'diameter': 0.5}),
('B', 'C', {'length': 5, 'diameter': 0.5}),
]
# Define node attributes
node_attributes = {
'A': {'elevation': 10},
'C': {'elevation': 0},
}
# Initialize the network
network = Network(edges, node_attributes)
# Set boundary conditions
network.set_boundary_conditions(
head_bc={'A': 100}, # Head at node A
rate_bc={'C': -10}, # Flow rate out of node C
)
# Calculate node heads and edge flows
Hs = network.balance()
print("Node Heads:", Hs)Propagates flow rates through the network and optionally calculates node heads.
node_rates, edge_rates, node_heads = network.propagate_rates(rate_bc={'A': 50}, H0=0)Balances the network based on boundary conditions and solves for node heads.
Hs = network.balance()Calculates the inflow and outflow for each node based on edge flows.
edge_flows = [10, -10] # Example flows through edges
flow_in, flow_out = network.get_node_flows(edge_flows)Computes node heads based on edge rates and an end head value.
node_heads = network.get_head_from_edge_rates(edge_rates={'A': 10, 'B': -10}, end_head=100)project/
├── src/
│ ├── __init__.py
│ ├── fluid_functions.py # Core fluid dynamics functions
│ ├── network.py # Network class and associated methods
│ ├── aux_func.py # auxiliary functions
├── tests/
│ ├── __init__.py
│ ├── test_fluid_functions.py # Unit tests for fluid functions
│ ├── test_aux_func.py # Unit tests for aux functions
│ ├── test_network_1.py # Unit tests for the Network class
│ ├── test_network_2.py # Unit tests for the Network class
│ ├── test_network_3.py # Unit tests for the Network class
├── requirements.txt # Dependencies
├── README.md # Project documentation
Tests are written using pytest. To run the tests, execute:
pytest tests/Common edge parameters (e.g., fluid density, viscosity) can be shared across all edges:
common_params = {
'density': 1000,
'viscosity': 0.001,
}
network = Network(edges, common_parameters=common_params)Enable debug mode to get verbose outputs during calculations:
network = Network(edges, debug=True)This library is open source and available under the MIT License. See the LICENSE file for more details.