A digital twin application for simulating and monitoring a water supply system without physical sensors. This project creates a virtual representation of a hydraulic water distribution network with real-time monitoring, 3D visualization, and scenario management capabilities.
This application simulates a complete water supply system including:
- 2 Pumps (PMP01, PMP02)
- 10 Valves (VLV01-VLV10)
- 2 Water Tanks (Tank 1, Tank 2)
- Multiple Conduits with flow monitoring
- Pressure sensors and flow meters
The system uses a mathematical hydraulic model based on Euler Forward integration to simulate water flow, pressure, and tank levels in real-time.
The codebase is organized into four main modules:
-
application/- Main GUI application with monitoring and control panelsapp.py- Main application window with navigationtwin_app.py- Real-time monitoring interfacescenario_app.py- Scenario management and testingHydraulicModel.py- Hydraulic simulation modelcommunication.py- Inter-process communication
-
model/- Mathematical models and equationsHydraulicModel.py- Core hydraulic simulation engineModel_math.py- Mathematical equations
-
visualisation/- 3D visualizationvisualisation3D.py- 3D scene with interactive valves and pumpsvirtual3D.py- Alternative 3D viewobjet/- 3D models (OBJ files)texture/- Textures for 3D models
-
communication/- File-based IPCcommand.txt- Commands from GUI to modelcapture.txt- Sensor values from model to visualization
- Python 3.7 or higher
- Windows/Linux/macOS
-
Clone or navigate to the project directory:
cd watertwin-main -
Install required dependencies:
pip install -r requirements.txt
-
Verify the communication directory exists: The
communication/folder should containcommand.txtandcapture.txtfiles.
Option 1: Run from main entry point (with splash screen):
python main.pyOption 2: Run directly (without splash screen):
cd application
python app.pyOption 3: Run 3D visualization separately:
cd visualisation
python visualisation3D.py-
Twin Model (Real-time Monitoring)
- Start/Stop simulation
- Monitor pump status, valve positions, tank levels
- View flow rates and pressures
- Real-time graphs and gauges (8 different monitoring graphs)
- Launch 3D visualization window
- Command Monitoring Tab:
- Clickable valve controls (VLVC01-VLVC10) - click to toggle open/closed
- Pump control buttons (Toggle PMP01/PMP02)
- Data capture functionality - save current sensor readings
- Scenario capture functionality - save current system state
-
Scenarios
- Create and save operational scenarios
- Test different valve/pump configurations
- Replay recorded scenarios
- 3D inspection mode - view scenarios in 3D visualization
- Plot simulation results with customizable parameters
-
Training Mode
- Interactive learning interface
- System operation tutorials (coming soon)
-
Profiles
- User profile management
- Session preferences (coming soon)
-
Settings
- Application configuration
- Display preferences (coming soon)
- Pumps: Toggle PMP01 and PMP02 on/off from Command Monitoring tab
- Valves:
- Click directly on valve indicators in Command Monitoring tab to toggle
- Control VLV01-VLV10 (open/closed) with visual feedback
- 3D View: Click on valves in 3D to toggle them
- Monitoring: View real-time sensor data and system status
- Data Capture: Save sensor readings to
data_captures/directory - Scenario Capture: Save system state to
scenario_folder/directory
The simulation uses a physics-based model with:
- Euler Forward integration for time-stepping
- Resistance calculations for pipes and valves
- Pressure dynamics based on flow rates
- Tank capacity and level tracking
- Junction flow calculations
Key parameters:
- Time step: 0.1 seconds (configurable)
- Tank areas: 54 mยฒ each
- Multiple pipe resistances and inertias
- Valve resistance: 13,985,716.43 when closed
The application uses file-based inter-process communication:
communication/command.txt- Commands (valve/pump states)communication/capture.txt- Sensor readings (flows, pressures, levels)
Built with Ursina Engine:
- Interactive 3D models
- Real-time water level visualization
- Clickable valves and equipment
- Visual flow indicators
watertwin-main/
โโโ main.py # Entry point with splash screen
โโโ application/ # Main GUI application
โ โโโ app.py # Main window
โ โโโ twin_app.py # Monitoring interface
โ โโโ scenario_app.py # Scenario management
โ โโโ HydraulicModel.py # Simulation model
โ โโโ communication.py # IPC module
โ โโโ assets/ # Icons and images
โโโ model/ # Mathematical models
โ โโโ HydraulicModel.py # Core simulation engine
โโโ visualisation/ # 3D visualization
โ โโโ visualisation3D.py # Main 3D scene
โ โโโ objet/ # 3D models (OBJ/MTL)
โ โโโ texture/ # Textures
โโโ communication/ # IPC files
โโโ command.txt # Commands
โโโ capture.txt # Sensor data
-
Import errors: Make sure all dependencies are installed
pip install -r requirements.txt
-
File not found errors: Check that
communication/directory exists- The application will create it automatically if missing
- Ensure
command.txtandcapture.txtfiles are present
-
3D models not loading:
- Verify
visualisation/objet/andvisualisation/texture/paths exist - Note: Corrupted or missing textures are handled gracefully - models will display with gray fallback colors
- Verify
-
Splash screen/image loading errors:
- Missing or corrupted images are handled gracefully
- Application will continue with text-only buttons if icons are missing
- Check
application/assets/directory for icon files
-
Tkinter callback errors after closing windows:
- Fixed in latest version - callbacks are properly cleaned up when windows close
- If you see these errors, ensure you're using the latest code
-
Scenario file errors:
- Invalid scenario files show helpful error messages
- Empty or invalid parameter inputs use default values
- Scenario files are saved to
application/scenario_folder/
The application now includes robust error handling for:
- โ Missing or corrupted image files (icons, splash screen)
- โ Corrupted 3D model textures (automatic fallback to gray)
- โ Invalid user inputs (default values applied)
- โ Missing scenario files (helpful error messages)
- โ Widget destruction callbacks (proper cleanup)
- โ Empty command dictionaries (graceful handling)
MEME ANDERMON JUNIOR
This project appears to be a research/educational project. Please check with the author for licensing information.
New Features:
- โ Command Monitoring Tab: Fully functional with clickable valve controls
- โ
Data Capture: Save sensor readings with timestamps to
data_captures/directory - โ Scenario Capture: Save current system state as scenarios with user-defined names
- โ 3D Inspection: Launch 3D visualization from scenario testing interface
- โ Pump Controls: Dedicated buttons for toggling PMP01 and PMP02
- โ English Translation: All UI text converted from French to English
Bug Fixes:
- โ Fixed image loading errors (missing/corrupted icons handled gracefully)
- โ Fixed texture loading in 3D visualization (fallback to gray when textures fail)
- โ Fixed Tkinter callback errors when windows are closed
- โ Fixed scenario file handling (proper error messages, filename sanitization)
- โ Fixed input validation (default values for empty fields)
- โ Fixed deprecation warnings (updated ttkbootstrap imports)
- โ Fixed path handling (using pathlib for portability)
Improvements:
- โ Robust error handling throughout the application
- โ Better user feedback with informative error messages
- โ Graceful degradation when assets are missing
- โ Improved code organization and maintainability
- Error Handling: All image/texture loading wrapped in try-except blocks
- Path Management: Standardized on
pathlibfor cross-platform compatibility - Callback Management: Proper cleanup of Tkinter callbacks to prevent errors
- Input Validation: Comprehensive validation for user inputs with sensible defaults
- File I/O: Robust file handling with proper error messages
- Machine learning integration for predictive maintenance
- Cloud connectivity for remote monitoring
- Advanced scenario analysis and comparison
- Export/import configurations
- Real-time data export (CSV, JSON)
- Historical data analysis and trending
- Multi-user support with profile management