OpenWQ

Open-Source Water Quality Modeling Framework
A flexible, modular platform for simulating biogeochemical processes
coupled with any hydrological model
Diogo Costa
University of Γ‰vora, Portugal

Contents

β€’ What is OpenWQ?

β€’ Core Capabilities

β€’ Available Modules

β€’ Coupled Host Models

Section 01: Theoretical Framework

β€’ Governing Equation

β€’ Compartment Structure

β€’ Module Architecture

Supported Processes

β€’ Biogeochemical Processes

β€’ Pre-Built Templates

Section 03: Applications

β€’ Application Areas

β€’ Technical Stack

β€’ AI-Powered Assistance

β€’ Summary

What is OpenWQ?

OpenWQ is an open-source water quality modeling framework designed to simulate the transport and transformation of chemical species in aquatic environments.

Key Innovation:
Biogeochemistry is defined in JSON configuration files, not hardcoded. Users can modify reactions without recompiling!
  • Modular β€” Couples with any hydrological model
  • Flexible β€” User-defined reaction networks
  • Scalable β€” From hillslope to continental
  • Open β€” Community-driven development
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚        HOST MODEL               β”‚
β”‚  (SUMMA, mizuRoute, CRHM, ...)  β”‚
β”‚                                 β”‚
β”‚   Provides:                     β”‚
β”‚   β€’ Water fluxes                β”‚
β”‚   β€’ Storage volumes             β”‚
β”‚   β€’ Temperature                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                β”‚
                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚          OpenWQ                 β”‚
β”‚                                 β”‚
β”‚   Computes:                     β”‚
β”‚   β€’ Chemical transport          β”‚
β”‚   β€’ Biogeochemical reactions    β”‚
β”‚   β€’ Source/sink dynamics        β”‚
β”‚   β€’ Concentrations & loads      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            

Core Capabilities

πŸ§ͺ

Bio/Geochemistry

Two engines: NATIVE_BGC_FLEX for user-defined kinetic reactions (JSON-based) and PHREEQC for thermodynamic equilibrium geochemistry.

πŸ“Š

Sources & Sinks

Flexible loading from CSV, JSON, HDF5, land-use coefficients, or ML predictions.

πŸ”§

Calibration

DDS optimizer with Morris screening and Sobol sensitivity analysis.

Available Modules

Transport Advection & dispersion
Lateral Exchange Inter-compartment fluxes
Isotherms Freundlich, Langmuir sorption
Erosion Sediment-bound transport
Consumptive Use Irrigation, withdrawals
External Fluxes Precipitation, inflows

Available Modules

OpenWQ provides a comprehensive set of modules for water quality modeling:

πŸ§ͺ Biogeochemistry

NATIVE_BGC_FLEXUser-defined kinetics
BGC_FLEX_THERMOWith FT factor
PHREEQCEquilibrium geochemistry

🌊 Transport & Exchange

ADVDISPAdvection + Dispersion
ADVAdvection only
BOUNDMIXLateral exchange

πŸ“Ž Sorption & Sediment

LANGMUIRSorption isotherm
FREUNDLICHSorption isotherm
HYPE_HBVSEDSediment transport
HYPE_MMFSediment transport
All modules configured via JSON β€” swap modules by changing configuration, not code!
See "Other Modules" presentation for detailed theory and configuration.

Coupled Host Models

OpenWQ integrates with established hydrological models via C++/Fortran wrappers:

Model Domain Description
SUMMA Land Surface Structure for Unifying Multiple Modeling Alternatives β€” multi-physics land model
mizuRoute River Routing Continental-scale river routing with lakes and reservoirs
mizuRoute-CSLM River + Lakes mizuRoute with Community Surface and Lake Model integration
FLUXOS Overland Flow 2D overland flow and sediment transport model
CRHM Cold Regions Cold Regions Hydrological Model β€” snow, frozen soils, prairie hydrology
Custom Any Straightforward API for coupling with any model
Coupling Approach: OpenWQ receives water fluxes and volumes from the host model, then computes solute mass balance and returns updated concentrations.
01

Theoretical Framework

Governing Equation: Mass Balance

Mass Conservation for Species i in Compartment j
dMij/dt = Ξ£(QinΒ·Cin) - Ξ£(QoutΒ·Cij) + Sij + Rij
Term Description
Mij Mass of species i in compartment j [g]
Qin, Qout Water fluxes from host model [L/s]
Cin, Cij Concentrations [mg/L]
Sij External sources/sinks [g/s]
Rij Biogeochemical reactions [g/s]

Key Processes

  • Advection β€” Transport with water flow
  • Dispersion β€” Spreading due to velocity gradients
  • Reactions β€” Chemical transformations
  • Exchange β€” Lateral mixing between compartments

Compartment Structure

OpenWQ organizes the domain into compartments β€” hydrological units that store and transport water.

Example Compartments

  • SOIL (multiple layers)
  • RUNOFF (surface flow)
  • GROUNDWATER (aquifers)
  • RIVER_REACHES
  • LAKES / RESERVOIRS
Each compartment has its own cycling framework β€” the set of biogeochemical reactions active within it.
     PRECIPITATION
          ↓ (External Flux)
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚   CANOPY    β”‚
    β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
           ↓
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚   RUNOFF    │────→ RIVER
    β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜        ↓
           ↓            LAKE
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚  SOIL_L1    β”‚
    β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
           ↓ (Exchange)
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚  SOIL_L2    β”‚
    β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
           ↓
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚ GROUNDWATER β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            

Module Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                                    OpenWQ MODULES                                       β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                                         β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”‚
β”‚   β”‚   BIOGEOCHEMISTRY   β”‚    β”‚      TRANSPORT      β”‚    β”‚   SOURCES/SINKS     β”‚        β”‚
β”‚   β”‚                     β”‚    β”‚                     β”‚    β”‚                     β”‚        β”‚
β”‚   β”‚ β€’ NATIVE_BGC_FLEX   β”‚    β”‚ β€’ Advection         β”‚    β”‚ β€’ JSON/CSV/HDF5     β”‚        β”‚
β”‚   β”‚   (user kinetics)   β”‚    β”‚ β€’ Dispersion        β”‚    β”‚ β€’ Land-use based    β”‚        β”‚
β”‚   β”‚                     β”‚    β”‚ β€’ Lateral exchange  β”‚    β”‚ β€’ ML predictions    β”‚        β”‚
β”‚   β”‚ β€’ PHREEQC           β”‚    β”‚                     β”‚    β”‚                     β”‚        β”‚
β”‚   β”‚   (equilibrium)     β”‚    β”‚                     β”‚    β”‚                     β”‚        β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β”‚
β”‚                                                                                         β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”‚
β”‚   β”‚     SORPTION        β”‚    β”‚  SEDIMENT TRANSPORT β”‚    β”‚      OUTPUT         β”‚        β”‚
β”‚   β”‚                     β”‚    β”‚                     β”‚    β”‚                     β”‚        β”‚
β”‚   β”‚ β€’ Freundlich        β”‚    β”‚ β€’ HYPE_HBVSED       β”‚    β”‚ β€’ HDF5              β”‚        β”‚
β”‚   β”‚ β€’ Langmuir          β”‚    β”‚ β€’ HYPE_MMF          β”‚    β”‚ β€’ CSV               β”‚        β”‚
β”‚   β”‚                     β”‚    β”‚                     β”‚    β”‚                     β”‚        β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β”‚
β”‚                                                                                         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                    
All modules are configured via JSON files β€” swap modules by changing configuration, not code!
02

Supported Processes

Biogeochemical Processes

🌿

Nitrogen Cycle

Nitrification, denitrification, mineralization, immobilization, volatilization

🧫

Phosphorus Cycle

Sorption, desorption, mineralization, sediment binding

πŸ‚

Carbon Cycle

DOC production, BOD decay, organic matter decomposition

πŸ’¨

Dissolved Oxygen

Reaeration, respiration, photosynthesis, SOD

πŸ”©

Heavy Metals

Sorption isotherms, complexation, precipitation

🦠

Pathogens

Die-off, settling, resuspension, UV inactivation

🧴

Pesticides

Degradation, volatilization, sorption, hydrolysis

βš—οΈ

Geochemistry

pH, speciation, mineral equilibria (PHREEQC)

All processes use the same framework β€” define consumed/produced species + kinetic expression

Pre-Built Model Templates

Popular Model Frameworks

SWAT N & P cycling with erosion
QUAL2E/QUAL2K Stream water quality
HYPE Large-scale nutrient modeling
WASP8 Lakes and estuaries
INCA Integrated catchment N & C
SPARROW Regional nutrient export

NATIVE_BGC_FLEX Templates (.json)

  • Inorganic nitrogen (NO₃, NHβ‚„)
  • Phosphorus (POβ‚„, sediment-P)
  • Carbon (DOC, POC) & Dissolved oxygen
  • Heavy metals, Pathogens, Tracers

PHREEQC Templates (.pqi)

  • Major ions equilibrium
  • Mineral saturation indices
  • Kinetic processes (DO, algae)
03

Applications

Application Areas

🌾 Agricultural Watersheds

  • Nutrient export from croplands
  • Fertilizer management
  • Best management practices
  • Tile drainage impacts

πŸ”οΈ Cold Regions

  • Snowmelt-driven transport
  • Freeze-thaw effects
  • Permafrost dynamics
  • Spring freshet loading

πŸ™οΈ Urban Systems

  • Stormwater quality
  • Point source impacts
  • Green infrastructure
  • Combined sewer overflows

🌊 Lakes & Reservoirs

  • Eutrophication
  • Algal blooms
  • Stratification effects
  • Reservoir operations

⛏️ Mining Impacts

  • Acid mine drainage
  • Metal contamination
  • Tailings pond seepage
  • Remediation modeling

🌍 Large-Scale Studies

  • Continental nutrient budgets
  • Climate change impacts
  • Land-use scenarios
  • Policy evaluation

Technical Stack

Languages & Libraries

C++ Core simulation engine
Fortran Host model coupling (SUMMA, mizuRoute)
Python Configuration, calibration, post-processing
Armadillo Linear algebra
exprtk Mathematical expression parsing
PhreeqcRM Geochemical reactions

I/O & Deployment

NetCDF/HDF5 Input/output data
JSON Configuration files
CMake Build system
Docker Container deployment
Apptainer HPC deployment
OpenMP parallelization for multi-core performance

AI-Powered Assistance

OpenWQ includes built-in support for AI-powered assistance using Claude and other LLMs.

πŸ–₯️ Claude Code CLI (Users & Developers)

# macOS/Linux: Install + add to PATH
curl -fsSL https://claude.ai/install.sh | sh
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc && source ~/.zshrc

# Windows: Install using winget, then restart terminal
winget install Anthropic.ClaudeCode

# Navigate to OpenWQ & start Claude
cd /path/to/openwq/ && claude

# CLAUDE.md auto-loaded - ask anything:
> How do I set up nitrification?

Can read, write & edit files directly

🌐 Web/API Users (Everyone)

Copy prompt from docs/OPENWQ_ASSISTANT_PROMPT.md

Paste into claude.ai or any AI assistant

What AI Can Help With

  • BGC reaction configuration
  • Calibration framework setup
  • Troubleshooting errors
  • Understanding source code
  • Writing JSON configurations
Pro Tip: Create a Claude Project with uploaded docs for persistent context across conversations

Summary

πŸ”§ Flexible

User-defined reactions without recompiling. JSON-based configuration.

πŸ”— Coupled

Works with SUMMA, mizuRoute, CRHM, and custom hydrological models.

🌐 Open

Open-source, community-driven, actively developed.

OpenWQ bridges the gap between hydrological modeling and water quality science
β€” bringing flexible biogeochemistry to any water model

Thank You

Questions & Resources

GitHub: github.com/ue-hydro/openwq

Documentation: openwq.readthedocs.io

Contact: diogo.costa@uevora.pt