OpenSWMM Engine  6.0.0-alpha.1
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.1)
Loading...
Searching...
No Matches
TableData.hpp File Reference

Time series and rating curve data with bidirectional cursor. More...

#include <string>
#include <vector>
#include <unordered_map>
#include <cstdio>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <cmath>
Include dependency graph for TableData.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  openswmm::TableCursor
 Bidirectional cursor tracking the last accessed index in a Table. More...
 
struct  openswmm::TableBlock
 A single time series or rating curve. More...
 
struct  openswmm::Table
 
struct  openswmm::TableData
 SoA collection of all time series and curves in the model. More...
 
struct  openswmm::TableValidation
 

Namespaces

namespace  openswmm
 

Enumerations

enum class  openswmm::TableType : int {
  openswmm::TIMESERIES = 0 ,
  openswmm::CURVE_STORAGE = 1 ,
  openswmm::CURVE_DIVERSION = 2 ,
  openswmm::CURVE_RATING = 3 ,
  openswmm::CURVE_SHAPE = 4 ,
  openswmm::CURVE_CONTROL = 5 ,
  openswmm::CURVE_TIDAL = 6 ,
  openswmm::CURVE_PUMP1 = 7 ,
  openswmm::CURVE_PUMP2 = 8 ,
  openswmm::CURVE_PUMP3 = 9 ,
  openswmm::CURVE_PUMP4 = 10 ,
  openswmm::CURVE_PUMP5 = 11
}
 Type of data stored in a Table. More...
 

Functions

double openswmm::table_lookup_cursor (Table &tbl, double x_query) noexcept
 Look up a value in a Table using the bidirectional cursor.
 
double openswmm::table_tseries_lookup_cursor (Table &tbl, double x_query) noexcept
 Time-series linear interpolation with out-of-range → 0 behaviour.
 
double openswmm::table_step_cursor (Table &tbl, double x_query) noexcept
 Piecewise-constant (step function) table lookup with cursor.
 
double openswmm::table_getStorageVolume (Table &tbl, double depth) noexcept
 Compute storage volume by trapezoidal integration of an area-vs-depth curve, matching legacy table_getStorageVolume() in table.c.
 
double openswmm::table_getStorageDepth (Table &tbl, double volume) noexcept
 Invert a storage area-vs-depth curve to find depth from volume.
 
double openswmm::table_inverseLookup (const Table &tbl, double y_query) noexcept
 Inverse lookup: given y, find corresponding x by linear interpolation.
 
double openswmm::table_lookupEx (const Table &tbl, double x_query) noexcept
 Linear-interpolating lookup with linear extrapolation outside bounds.
 
double openswmm::table_intervalLookup (const Table &tbl, double x_query) noexcept
 Step-function lookup: return y for the first x entry > x_query.
 
double openswmm::table_getSlope (const Table &tbl, double x_query) noexcept
 Compute the slope (dy/dx) at a given x value.
 
double openswmm::table_getMaxY (const Table &tbl) noexcept
 Return the maximum y value in the non-decreasing leading portion.
 
TableValidation openswmm::validate_table (Table &tbl)
 
bool openswmm::table_open_file (Table &tbl, std::size_t boundary_rows)
 
std::size_t openswmm::table_load_cache (Table &tbl, std::size_t start_row)
 
double openswmm::table_lookup_column (Table &tbl, int col_idx, double x_query)
 
double openswmm::table_step_column (Table &tbl, int col_idx, double x_query)
 

Detailed Description

Time series and rating curve data with bidirectional cursor.

Provides the Table struct (a single time series or curve) and TableData (the SoA collection of all tables in the model), plus the cursor-optimized lookup function.

Cursor Optimization

The legacy SWMM table_lookup() in src/solver/table.c performs a linear scan from index 0 on every call. For a simulation with many output steps and long time series, this becomes O(N*T) total work where N is the number of table entries and T is the number of timesteps.

The new engine uses a bidirectional cursor that remembers where the last lookup landed. For monotonically advancing simulation time (the common case), each lookup costs O(1) — the cursor simply advances one or a few positions. For backward seeks (e.g., restart scenarios), the cursor retreats.

See also
Legacy reference: src/solver/table.c — table_lookup()
tests/unit/test_timeseries_cursor.cpp
tests/benchmarks/bench_timeseries_lookup.cpp
Author
Caleb Buahin caleb.nosp@m..bua.nosp@m.hin@g.nosp@m.mail.nosp@m..com
License\n MIT License