Skip to content

mstainoh/fluidnet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fluidnet - a flow Analysis Library

(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.

Features

  • 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.

Installation

To use the library, clone the repository and install the required dependencies:

pip install -r requirements.txt

Dependencies:

  • numpy
  • scipy
  • networkx

Usage

Example: Basic Network Setup

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)

Key Methods

propagate_rates

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)

balance

Balances the network based on boundary conditions and solves for node heads.

Hs = network.balance()

get_node_flows

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)

get_head_from_edge_rates

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 Structure

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

Tests are written using pytest. To run the tests, execute:

pytest tests/

Advanced Configuration

Common Parameters

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)

Debugging

Enable debug mode to get verbose outputs during calculations:

network = Network(edges, debug=True)

License

This library is open source and available under the MIT License. See the LICENSE file for more details.

About

python code for nodal analysis for oil / gas / water wells

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages