Modelling the change in topology of rivers over time due to bank erosion and sediment transport.
Authors: Thomas Moody, Tara Kasayapanand, Andrew Lau
This project models and simulates river morphodynamics, how rivers change their shape, width, and bed elevation over time due to water flow and sediment transport. The simulation is implemented in Unity for real-time visualisation and physics-based modeling, with results exported to CSV format for detailed analysis in Python.
The simulation models:
- Water flow dynamics using shallow water equations.
- Sediment transport and bed erosion/deposition.
- Bank migration and erosion.
- Long-term river evolution over days, months, or years.
River-Modelling/
├── River-Unity/ # Unity simulation project
│ ├── Assets/
│ │ ├── Scripts/ # Core simulation scripts
│ │ │ ├── RiverMeshPhysicsSolver.cs
│ │ │ ├── LongTermSimulationController.cs
│ │ │ ├── MonteCarloSimulationManager.cs
│ │ │ └── ...
│ │ ├── Scenes/ # Unity scenes
│ │ └── Resources/ # Initial geometry data
│ └── Results/ # Exported simulation results
│ ├── summary_statistics.csv
│ └── Results_YYYYMMDD_HHMMSS/
│
├── csv_files/ # Input geometry data
│ ├── Jurua_19871012.csv
│ └── Jurua_20170710.csv
│
├── Objects/ # Python mesh objects
│ ├── MeshGrid.py
│ └── MeshPoint.py
│
├── data_extraction.ipynb # Extract geometry from CSV
├── monte_carlo_analysis.ipynb # Monte Carlo analysis
├── prediction_analysis.ipynb # Prediction comparison
├── cline_analysis.py # Centerline analysis module
├── visualisation.py # 3D visualisation
├── simulation.py # Python simulation framework
├── physics.py # Physics solver
└── requirements.txt # Python dependencies
- Unity 6000.1.15f1 (or more recent stable version).
-
Install Unity Hub
- Download from unity.com.
- Install Unity Editor version 6000.1.15f1.
-
Open the Project
- Open Unity Hub.
- Click "Add" and select the
River-Unityfolder. - Click "Open" to load the project in Unity Editor.
-
Verify Installation
- Unity should open with the project.
- Check the Console for any import errors.
- Navigate to
Assets/Scenes/SampleScene.unityto see the main scene.
-
Open the Main Scene
- In Unity, open
Assets/Scenes/SampleScene.unity.
- In Unity, open
-
Configure the Simulation Controller
- In the Hierarchy, locate the GameObject with the
LongTermSimulationControllercomponent.Or find the
MonteCarloSimulationManagerfor Monte Carlo simulations. - Check the Inspector panel for configuration options.
- In the Hierarchy, locate the GameObject with the
-
Set Export Path
- By default, results export to
E:\UCL\River-Modelling\River-Unity\Results. - You can change this in the script's
exportBasePathfield.
- By default, results export to
-
Load Initial Geometry
- Initial river geometry can be loaded from CSV files.
- Place CSV files in
Assets/Resources/folder. - Use the
CSVGeometryLoadercomponent to load geometry.
Simulation Parameters:
NumCrossSections: Number of cross-sections along the river.WidthResolution: Resolution of the width dimension.TimeStep: Time step size (in days for long-term simulations).TotalDays: Total simulation duration.
Physics Parameters:
TransportCoefficient: Sediment transport coefficient.CriticalShear: Critical shear stress for sediment motion.BankErosionRate: Rate of bank erosion.BankCriticalShear: Critical shear for bank erosion.
Export Settings:
autoExportOnComplete: Automatically export results when simulation finishes.exportFileName: Base filename for exported CSV files (timestamp appended automatically).
-
Start the Simulation
- Press Play in Unity Editor.
- The simulation will run in real-time.
-
Monitor Progress
- Watch the 3D visualisation of the river evolution.
- Check the Console for log messages.
- UI displays current simulation time and progress.
- Can disable rendering in UI to reduce simulation time.
-
Stop
- Click "Stop" button in the UI.
- The simulation will export results automatically if
autoExportOnCompleteis enabled.Stopping a simulation run before time length is completed will still output final river topology.
-
Configure Monte Carlo Parameters
- Select the GameObject with
MonteCarloSimulationManager. - Set number of realisations.
- Configure parameter ranges for uncertainty analysis.
- Enable "Store Full Ensemble" if you need detailed riveer data for each stage.
- Select the GameObject with
-
Run Ensemble
- Press Play.
- The simulation will run multiple realisations with varying parameters.
- Progress is shown in the UI.
-
Results
- Results are automatically exported to timestamped folders.
- Summary statistics are saved to
summary_statistics.csv. - Full field data (if enabled) is saved for each realisation.
- Camera: Use the
CameraControllerto navigate the 3D view (WASD - horizontal, Space/Shift - vertical, C - lock/unlock cursor). - Heatmaps: Toggle velocity and erosion heatmaps using shaders.
Results are automatically exported when:
- Simulation completes successfully.
- Simulation is manually stopped (if configured).
- Each Monte Carlo realisation finishes (for ensemble runs).
Results are saved as CSV files with the following naming convention:
- Single simulations:
RiverSimulation_YYYY_DDMMYYYY_HHMMSS.csv. - Monte Carlo:
Results_YYYYMMDD_HHMMSS/folder containing:summary_statistics.csv- Aggregated statistics for all realisations.stage_N_bed_elevation.csv- Bed elevation for realisation N.stage_N_velocity_u.csv- U-component of velocity.stage_N_velocity_v.csv- V-component of velocity.stage_N_water_depth.csv- Water depth field.stage_N_cell_type.csv- Cell type classification.
River geometry CSV files follow this format:
cline_x,cline_y,cross_section_index,left_bank_x,left_bank_y,right_bank_x,right_bank_y
Monte Carlo field data CSVs are 2D grids with:
- Rows: Cross-section indices.
- Columns: Width resolution indices.
- Values: Physical quantities (elevation, velocity, depth, etc.).
Install required Python packages:
pip install numpy matplotlib pyvista>=0.40.0 pandas seaborn scipyOr install from requirements.txt:
pip install -r requirements.txtNote: cline_analysis.py must be in the same directory as the analysis notebooks.
The Python analysis scripts are located in the root directory:
data_extraction.ipynb- Extract and process river geometry from CSV files.monte_carlo_analysis.ipynb- Analyze Monte Carlo simulation results.prediction_analysis.ipynb- Compare predicted vs. actual river geometry.cline_analysis.py- Centerline analysis.
Open data_extraction.ipynb:
# Load CSV files
fnames = ['Jurua_19871012.csv', 'Jurua_20170710.csv']
csv_dir = './csv_files/'
# Extract geometry data
# This will parse centerline, bank positions, curvature, width, etc.Outputs:
- Centerline coordinates.
- Left and right bank positions.
- River width.
- Curvature measurements.
- Migration indices.
Open monte_carlo_analysis.ipynb:
# Load summary statistics
df = pd.read_csv('River-Unity/Results/summary_statistics.csv')
# Analyse transport coefficient vs. erosion rate
transport_coeff = df["transport_coefficient_K"]
max_erosion_rate = df["max_erosion_rate"]
# Create correlation plots
plt.scatter(transport_coeff, max_erosion_rate)Key Analyses:
- Parameter sensitivity analysis.
- Correlation between physical parameters.
- Statistical distributions of outcomes.
- Uncertainty quantification.
Open prediction_analysis.ipynb:
# Load actual and predicted geometry
df_actual = pd.read_csv('csv_files/Jurua_20170710.csv')
df_predicted = pd.read_csv('River-Unity/Results/RiverSimulation_2017_YYYYMMDD_HHMMSS.csv')
df_initial = pd.read_csv('csv_files/Jurua_19871012.csv')
# Compare geometries
# Calculate metrics: width change, migration distance, etc.Metrics:
- Width change accuracy.
- Migration distance error.
- Centerline position comparison.
- Bank position errors.
Use visualisation.py for 3D visualization:
from visualisation import visualiseSimulation
# Visualise a single frame
visualiseSimulation(filename="simulation_frames.pkl", frame_index=0)
# Animate through all frames
visualiseSimulation(filename="simulation_frames.pkl", animate=True)Features:
- 3D mesh visualisation (Matplotlib 3D or GPU-accelerated with PyVista).
- Velocity field visualisation.
- Erosion/deposition heatmaps.
- Animated evolution through time.
-
Load Simulation Results
import pandas as pd results = pd.read_csv('River-Unity/Results/RiverSimulation_2017_20251214_205254.csv')
-
Compare with Observed Data
observed = pd.read_csv('csv_files/Jurua_20170710.csv') # Calculate differences
-
Generate Visualisations
import matplotlib.pyplot as plt # Plot width changes, migration, etc.
-
Statistical Analysis
from scipy import stats # Perform correlation analysis, hypothesis testing, etc.
This project is licensed under the MIT License - see the separate LICENSE file for details.
Copyright © 2025 Thomas Moody, Tara Kasayapanand, and Andrew Lau.
