Commit 02438b60 authored by Morales Hernandez, Mario's avatar Morales Hernandez, Mario
Browse files

Add bundled SWMM for simplified coupling build

  This commit bundles the modified SWMM 5.2 source code directly in
  the TRITON repository, eliminating the need for users to manually
  download, compile, and configure SWMM separately.

  Changes:
  - Bundle modified SWMM source in external/swmm/ (1.6 MB)
  - Simplify CMake configuration - no manual SWMM paths needed
  - Fix missing SWMM headers in swmm_triton.h (TRUE/FALSE macros)
  - Update README with clear build instructions

  SWMM is now compiled automatically when TRITON_ENABLE_SWMM=ON.

  User workflow before:
    - Download SWMM separately
    - Compile SWMM manually
    - Set SWMM_ROOT_DIR or SWMM_INCLUDE_DIR/LIBRARY_DIR

  User workflow after:
    cmake -DTRITON_ENABLE_SWMM=ON ..
    make -j4
parent a176f7e8
Loading
Loading
Loading
Loading
+5 −39
Original line number Diff line number Diff line
@@ -26,43 +26,8 @@ endif()
option(TRITON_ENABLE_SWMM "Enable SWMM coupling for urban drainage" OFF)

if(TRITON_ENABLE_SWMM)
  # Find SWMM library
  set(SWMM_ROOT_DIR "$ENV{SWMM_ROOT_DIR}" CACHE PATH "SWMM installation directory")
  set(SWMM_INCLUDE_DIR "${SWMM_ROOT_DIR}/include" CACHE PATH "SWMM include directory")
  set(SWMM_LIBRARY_DIR "${SWMM_ROOT_DIR}/lib" CACHE PATH "SWMM library directory")

  # Try to find SWMM headers
  find_path(SWMM_INCLUDE_PATH
    NAMES swmm5.h
    PATHS
      ${SWMM_INCLUDE_DIR}
      ${CMAKE_SOURCE_DIR}/external/swmm/include
      /usr/local/include/swmm
      /usr/include/swmm
      ${PROJECT_SOURCE_DIR}/../Stormwater-Management-Model/src/solver/include
    DOC "SWMM include directory"
  )

  # Try to find SWMM library
  find_library(SWMM_LIBRARY
    NAMES swmm5 swmm
    PATHS
      ${SWMM_LIBRARY_DIR}
      ${CMAKE_SOURCE_DIR}/external/swmm/lib
      /usr/local/lib
      /usr/lib
      ${PROJECT_SOURCE_DIR}/../Stormwater-Management-Model/build/bin
    DOC "SWMM library"
  )

  if(SWMM_INCLUDE_PATH AND SWMM_LIBRARY)
    message(STATUS "SWMM include directory: ${SWMM_INCLUDE_PATH}")
    message(STATUS "SWMM library: ${SWMM_LIBRARY}")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTRITON_SWMM")
  else()
    message(FATAL_ERROR "SWMM coupling requested but SWMM library/headers not found. "
                       "Please set SWMM_ROOT_DIR or SWMM_INCLUDE_DIR and SWMM_LIBRARY_DIR")
  endif()
  message(STATUS "SWMM coupling enabled - SWMM will be built from bundled source")
endif()

# add external packages
@@ -84,8 +49,9 @@ if (ENABLE_GDAL)
endif()

if(TRITON_ENABLE_SWMM)
  target_include_directories(${TRITON_EXECUTABLE} PUBLIC ${SWMM_INCLUDE_PATH})
  target_link_libraries(${TRITON_EXECUTABLE} PUBLIC ${SWMM_LIBRARY})
  target_include_directories(${TRITON_EXECUTABLE} PUBLIC ${CMAKE_SOURCE_DIR}/external/swmm/src/solver/include)
  target_include_directories(${TRITON_EXECUTABLE} PUBLIC ${CMAKE_SOURCE_DIR}/external/swmm/src/solver)
  target_link_libraries(${TRITON_EXECUTABLE} PUBLIC swmm5)
endif()

add_build_and_run_scripts()
+15 −30
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ TRITON is an open-source, high-performance software framework for 2D flood simul
triton/
├── doc/           # User guides, API references, and technical documentation
├── src/           # Core simulation source code
├── external/      # Kokkos Git submodule
├── external/      # Kokkos and yaml-cpp Git submodules, bundled SWMM
├── input/         # Sample simulation input data files
├── test/          # Regression test suite based on CTest
├── cmake/         # CMake configuration modules and machine files
@@ -39,17 +39,23 @@ Optional: GDAL for GeoTIFF support
Kokkos is included as a Git submodule. No system install is required.

### **Build Instructions**

```bash
# Clone TRITON
git clone --recursive https://code.ornl.gov/hydro/triton.git
cd triton

# Create build directory
mkdir build && cd build
cmake ..
./triton_build.sh

# Configure
cmake ..

# Build (use -jN for parallel compilation, e.g., -j4)
make -j4
```
On success, triton.exe is created in the build directory.
For more details on cmake configurationa and compiler flags, please see the documentation. 

**On success**, `triton.exe` is created in the build directory. 

### **Using Docker (Optional)**
```bash
@@ -63,22 +69,7 @@ docker pull grnydawn/triton-mpich

TRITON can be coupled with EPA's Stormwater Management Model (SWMM) for integrated surface-subsurface urban drainage simulation.

#### Prerequisites for SWMM Coupling

1. **SWMM Library**: Build SWMM 5.2+ from source:
   ```bash
   # Clone SWMM (if not already available)
   git clone https://github.com/USEPA/Stormwater-Management-Model.git swmm
   cd swmm
   mkdir build && cd build
   cmake ..
   cmake --build .
   ```

2. **Set SWMM_ROOT_DIR** (or CMake will find SWMM in the default location):
   ```bash
   export SWMM_ROOT_DIR=/path/to/swmm
   ```
**SWMM is included with TRITON** - no separate download or compilation needed!

#### Build with SWMM Coupling

@@ -86,17 +77,10 @@ TRITON can be coupled with EPA's Stormwater Management Model (SWMM) for integrat
cd triton
mkdir build && cd build
cmake -DTRITON_ENABLE_SWMM=ON ..
./triton_build.sh
make -j4
```

Or specify SWMM paths explicitly:
```bash
cmake -DTRITON_ENABLE_SWMM=ON \
      -DSWMM_INCLUDE_DIR=/path/to/swmm/src/solver/include \
      -DSWMM_LIBRARY_DIR=/path/to/swmm/build/bin \
      ..
./triton_build.sh
```
That's it! The bundled SWMM library is compiled automatically as part of the TRITON build process.

#### SWMM Configuration

@@ -128,6 +112,7 @@ When SWMM coupling is enabled:
- Ensure manhole diameter is smaller than grid resolution to avoid numerical instabilities
- Multiple SWMM nodes can connect to the same TRITON cell (will cause an error)
- SWMM runs only on rank 0; exchange flow is computed on all ranks
- **Important**: When running with multiple MPI ranks, use 1 or 2 ranks for SWMM coupling (4+ ranks may timeout)

## Running a Simulation

+9 −0
Original line number Diff line number Diff line
@@ -4,6 +4,15 @@ if(${ENSEMBLE_BUILD})
    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/yaml-cpp)
endif()

# Add bundled SWMM if coupling is enabled
if(TRITON_ENABLE_SWMM)
    if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/swmm/CMakeLists.txt)
        add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/swmm)
    else()
        message(FATAL_ERROR "SWMM coupling requested but bundled SWMM source not found in external/swmm")
    endif()
endif()

# Find GDAL
find_package(GDAL)
if(GDAL_FOUND)

external/swmm/Build.md

0 → 100644
+32 −0
Original line number Diff line number Diff line
<!---
   Build.md

   Created: Dec 2, 2019
   Updated:

   Author: Michael E. Tryby
           US EPA - ORD/CESER
--->


## Building SWMM Locally on Windows


### Dependencies

Before the project can be built the required dependencies must be installed.

**Summary of Build Dependencies: Windows**

  - Build
      - Build Tools for Visual Studio 2017
      - CMake 3.13


### Build

SWMM can be built with one simple command.
```
\> cd swmm
\swmm>tools\make.cmd
```
+69 −0
Original line number Diff line number Diff line
#
# CMakeLists.txt - CMake configuration file for swmm-solver
#
# Created: July 11, 2019
# Modified: Aug 16, 2022
#
# Author: Michael E. Tryby
#         US EPA ORD/CESER
#


cmake_minimum_required (VERSION 3.13)

if("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
    message(FATAL_ERROR "In-source builds are disabled.")
endif()


project(swmm-solver
    VERSION 5.2.3
    LANGUAGES C CXX
)

# Append local dir to module search path
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

# Sets the position independent code property for all targets
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# Sets default install prefix when cmakecache is initialized for first time
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
    set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install CACHE PATH "..." FORCE)
endif()


# Define install locations (will be prepended by install prefix)
set(TOOL_DIST "bin")
set(INCLUDE_DIST "include")
set(LIBRARY_DIST "lib")
set(CONFIG_DIST  "cmake")


# Define build options
option(BUILD_TESTS "Builds component tests (requires Boost)" OFF)
option(BUILD_DEF   "Builds library with def file interface" OFF)


# Add project subdirectories
add_subdirectory(src/outfile)
add_subdirectory(src/solver)
add_subdirectory(src/run)

if(BUILD_TESTS)
    enable_testing()
    add_subdirectory(tests)
endif()


# Create install rules for vcruntime.dll, msvcp.dll, vcomp.dll etc.
set(CMAKE_INSTALL_OPENMP_LIBRARIES TRUE)
include(InstallRequiredSystemLibraries)


# Configure CPack driven installer package
set(CPACK_GENERATOR "ZIP")
set(CPACK_PACKAGE_VENDOR "US_EPA")
set(CPACK_ARCHIVE_FILE_NAME "swmm")

include(CPack)
Loading