OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
TableData.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2//
3// Copyright 2026 Caleb Buahin
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
47
48#ifndef OPENSWMM_ENGINE_TABLE_DATA_HPP
49#define OPENSWMM_ENGINE_TABLE_DATA_HPP
50
53#include <string>
54#include <vector>
55#include <unordered_map>
56#include <cstdio>
57#include <cstdint>
58#include <cassert>
59#include <algorithm>
60#include <cmath>
61
62namespace openswmm {
63
64// ============================================================================
65// Table types (matching legacy SWMM enums.h)
66// ============================================================================
67
87
88// ============================================================================
89// TableCursor
90// ============================================================================
91
104 int index = 0;
105 int direction = +1;
106
107 void reset() noexcept { index = 0; direction = +1; }
108};
109
110// ============================================================================
111// Table
112// ============================================================================
113
129 std::vector<double> x;
130 std::vector<double> y;
131 int num_cols = 1;
132 std::size_t file_row_start = 0;
133
134 std::size_t num_rows() const noexcept { return x.size(); }
135 bool empty() const noexcept { return x.empty(); }
136};
137
138struct Table {
139 std::string id;
141
147 std::string comment;
148 std::vector<double> x;
149 std::vector<double> y;
151
152 // ---- Time-only (relative) timeseries rows ----
153 // Legacy SWMM seeds every timeseries' lastDate with StartDate+StartTime
154 // (input.c:170), so rows authored WITHOUT a date are elapsed times
155 // anchored at the simulation start, until an explicit date re-anchors
156 // the series. The parser counts those leading date-less rows here and
157 // resolve_cross_references() adds options.start_date to exactly those
158 // rows (recording the applied offset in rel_anchor so re-resolution is
159 // idempotent and a later START_DATE change re-anchors by the delta).
160 // InpWriter subtracts rel_anchor to emit the rows back in their
161 // authored time-only form; rows at index >= n_relative are absolute
162 // date/times and are written with explicit dates.
163 int n_relative = 0;
164 double rel_anchor = 0.0;
165
166 // ---- File-backed time series support ----
167 bool is_file_based = false;
168 std::FILE* file_handle = nullptr;
174 double dx_min = 0.0;
175 double x_min = 0.0;
176 double x_max = 0.0;
177 int num_cols = 1;
178 std::size_t total_rows = 0;
179 std::size_t num_cache_rows = 8192;
181 std::vector<long> row_offsets;
182 std::vector<std::string> column_ids;
183 std::unordered_map<std::string, int> column_map;
184
185 static constexpr std::size_t INDEX_STRIDE = 4096;
186
188 std::size_t size() const noexcept { return x.size(); }
189
191 bool empty() const noexcept { return x.empty(); }
192};
193
194// ============================================================================
195// Cursor-optimized lookup
196// ============================================================================
197
219inline double table_lookup_cursor(Table& tbl, double x_query) noexcept {
220 const int n = static_cast<int>(tbl.x.size());
221 if (n == 0) return 0.0;
222 if (n == 1) return tbl.y[0];
223
224 // Clamp below first entry
225 if (x_query <= tbl.x[0]) {
226 tbl.cursor.index = 0;
227 tbl.cursor.direction = +1;
228 return tbl.y[0];
229 }
230
231 // Clamp above last entry — strictly above only: legacy table_lookup
232 // (src/legacy/engine/table.c:400) interpolates the last segment when
233 // x == x[n-1] (its scan condition is `x <= x2`), so equality must fall
234 // through to the interpolation below for bit parity.
235 if (x_query > tbl.x[n - 1]) {
236 tbl.cursor.index = n - 1;
237 tbl.cursor.direction = -1;
238 return tbl.y[n - 1];
239 }
240
241 // Start from cursor position and seek in the most likely direction
242 int idx = std::clamp(tbl.cursor.index, 0, n - 2);
243
244 // Forward seek
245 while (idx < n - 1 && tbl.x[idx + 1] < x_query) {
246 ++idx;
247 tbl.cursor.direction = +1;
248 }
249
250 // Backward seek — `>=` so a query landing exactly on an interior knot
251 // selects the segment ENDING at that knot, matching legacy table_lookup's
252 // first-match linear scan (`if (x <= x2) return table_interpolate(...)`,
253 // src/legacy/engine/table.c:426).
254 while (idx > 0 && tbl.x[idx] >= x_query) {
255 --idx;
256 tbl.cursor.direction = -1;
257 }
258
259 tbl.cursor.index = idx;
260
261 // PARITY: op-for-op transliteration of legacy table_interpolate
262 // (src/legacy/engine/table.c:54-67): multiply THEN divide —
263 // y1 + (x - x1) * (y2 - y1) / dx
264 // (the previous t=(x-x1)/dx; y1+t*(y2-y1) form rounds differently by
265 // 1 ULP), and the legacy degenerate-segment guard |dx| < 1e-20 → mean.
266 const double x1 = tbl.x[idx], y1 = tbl.y[idx];
267 const double x2 = tbl.x[idx + 1], y2 = tbl.y[idx + 1];
268 const double dx = x2 - x1;
269 if (std::fabs(dx) < 1.0e-20) return (y1 + y2) / 2.;
270 return y1 + (x_query - x1) * (y2 - y1) / dx;
271}
272
290inline double table_tseries_lookup_cursor(Table& tbl, double x_query) noexcept {
291 const int n = static_cast<int>(tbl.x.size());
292 if (n == 0) return 0.0;
293
294 // Before first entry or after last entry → 0 (series not active)
295 if (x_query <= tbl.x[0]) {
296 tbl.cursor.index = 0;
297 tbl.cursor.direction = +1;
298 return (x_query < tbl.x[0]) ? 0.0 : tbl.y[0];
299 }
300 if (x_query >= tbl.x[n - 1]) {
301 tbl.cursor.index = n - 1;
302 tbl.cursor.direction = -1;
303 return (x_query > tbl.x[n - 1]) ? 0.0 : tbl.y[n - 1];
304 }
305
306 // Delegate to cursor-based linear interpolation for the in-range case
307 return table_lookup_cursor(tbl, x_query);
308}
309
324inline double table_step_cursor(Table& tbl, double x_query) noexcept {
325 const int n = static_cast<int>(tbl.x.size());
326 if (n == 0) return 0.0;
327 if (n == 1) return tbl.y[0];
328
329 // Before first entry → 0 (no rain before first recorded value)
330 if (x_query < tbl.x[0]) {
331 tbl.cursor.index = 0;
332 tbl.cursor.direction = +1;
333 return 0.0;
334 }
335
336 // At or past last entry → return last value.
337 // The caller (Gage.cpp) handles the rain interval cutoff and returns 0
338 // after entry_time + rainInterval. This allows the last entry's value to
339 // be used for its full recording interval before going to zero.
340 if (x_query >= tbl.x[n - 1]) {
341 tbl.cursor.index = n - 1;
342 tbl.cursor.direction = -1;
343 return tbl.y[n - 1];
344 }
345
346 // Seek to the interval containing x_query: x[idx] <= x_query < x[idx+1]
347 int idx = std::clamp(tbl.cursor.index, 0, n - 2);
348
349 while (idx < n - 1 && tbl.x[idx + 1] <= x_query) {
350 ++idx;
351 tbl.cursor.direction = +1;
352 }
353 while (idx > 0 && tbl.x[idx] > x_query) {
354 --idx;
355 tbl.cursor.direction = -1;
356 }
357
358 tbl.cursor.index = idx;
359 return tbl.y[idx];
360}
361
362// ============================================================================
363// Storage volume by trapezoidal integration of area curve
364// ============================================================================
365
374inline double table_getStorageVolume(Table& tbl, double depth) noexcept {
375 const int n = static_cast<int>(tbl.x.size());
376 if (n == 0 || depth <= 0.0) return 0.0;
377
378 double x1 = tbl.x[0];
379 double a1 = tbl.y[0];
380
381 // Target below first entry — triangular approximation
382 if (depth <= x1) {
383 if (x1 < 1.0e-6) return 0.0;
384 return (a1 / x1) * depth * depth / 2.0;
385 }
386
387 // Traverse entries using end-area (trapezoidal) method
388 double v = 0.0;
389 double dx = 0.0, dy = 0.0;
390 for (int i = 1; i < n; ++i) {
391 double x2 = tbl.x[i];
392 double a2 = tbl.y[i];
393 if (x2 >= depth) {
394 // Bracketed — interpolate area at target depth.
395 // PARITY: legacy table_getStorageVolume (table.c:624) calls
396 // table_interpolate (table.c:54): multiply THEN divide,
397 // |dx| < 1e-20 degenerate guard → mean of end areas.
398 const double dxi = x2 - x1;
399 double a;
400 if (std::fabs(dxi) < 1.0e-20) a = (a1 + a2) / 2.;
401 else a = a1 + (depth - x1) * (a2 - a1) / dxi;
402 return v + (a1 + a) / 2.0 * (depth - x1);
403 }
404 dx = x2 - x1;
405 dy = a2 - a1;
406 v += (a1 + a2) / 2.0 * dx;
407 x1 = x2;
408 a1 = a2;
409 }
410
411 // Extrapolate beyond last entry
412 if (dx > 1.0e-6) {
413 double s = dy / dx;
414 double a = a1 + s * (depth - x1);
415 if (a < 0.0) {
416 v -= a1 * a1 / s / 2.0;
417 } else {
418 v += (a1 + a) / 2.0 * (depth - x1);
419 }
420 }
421 return v;
422}
423
424// ============================================================================
425// Inverse volume-to-depth for storage curves
426// ============================================================================
427
440inline double table_getStorageDepth(Table& tbl, double volume) noexcept {
441 const int n = static_cast<int>(tbl.x.size());
442 if (n == 0 || volume <= 0.0) return 0.0;
443
444 double x1 = tbl.x[0];
445 double a1 = tbl.y[0];
446 double v_accum = 0.0;
447
448 for (int i = 1; i < n; ++i) {
449 double x2 = tbl.x[i];
450 double a2 = tbl.y[i];
451 double dv = (a1 + a2) / 2.0 * (x2 - x1);
452
453 if (v_accum + dv >= volume) {
454 // Solve the quadratic: target volume falls in this interval.
455 // Area varies linearly: a(d) = a1 + s*(d - x1), s = (a2-a1)/(x2-x1)
456 // Volume: dv = a1*(d-x1) + s*(d-x1)^2/2
457 // Rearrange to standard form and apply quadratic formula.
458 double dx = x2 - x1;
459 double dv_need = volume - v_accum;
460 if (dx < 1.0e-10) return x1;
461
462 double s = (a2 - a1) / dx;
463 double depth;
464 if (std::fabs(s) < 1.0e-10) {
465 // Rectangular slice: dv = a1 * dd
466 depth = (a1 > 0.0) ? x1 + dv_need / a1 : x1;
467 } else {
468 // Quadratic: s/2 * dd^2 + a1 * dd - dv_need = 0
469 double disc = a1 * a1 + 2.0 * s * dv_need;
470 if (disc < 0.0) disc = 0.0;
471 depth = x1 + (-a1 + std::sqrt(disc)) / s;
472 }
473 return std::min(depth, x2);
474 }
475
476 v_accum += dv;
477 x1 = x2;
478 a1 = a2;
479 }
480
481 // Volume exceeds curve range — extrapolate linearly using last slope
482 if (tbl.x.size() >= 2) {
483 int last = n - 1;
484 double dx = tbl.x[last] - tbl.x[last - 1];
485 double da = tbl.y[last] - tbl.y[last - 1];
486 double s = (dx > 1.0e-10) ? da / dx : 0.0;
487 double dv_need = volume - v_accum;
488 double a1_ext = tbl.y[last];
489 double depth;
490 if (std::fabs(s) < 1.0e-10) {
491 depth = (a1_ext > 0.0) ? tbl.x[last] + dv_need / a1_ext : tbl.x[last];
492 } else {
493 double disc = a1_ext * a1_ext + 2.0 * s * dv_need;
494 if (disc < 0.0) disc = 0.0;
495 depth = tbl.x[last] + (-a1_ext + std::sqrt(disc)) / s;
496 }
497 return depth;
498 }
499 return tbl.x[n - 1];
500}
501
502// ============================================================================
503// Generic inverse lookup (y → x)
504// ============================================================================
505
516inline double table_inverseLookup(const Table& tbl, double y_query) noexcept {
517 const int n = static_cast<int>(tbl.x.size());
518 if (n == 0) return 0.0;
519 if (n == 1) return tbl.x[0];
520
521 if (y_query <= tbl.y[0]) return tbl.x[0];
522 if (y_query >= tbl.y[n - 1]) return tbl.x[n - 1];
523
524 for (int i = 1; i < n; ++i) {
525 if (tbl.y[i] >= y_query) {
526 double dy = tbl.y[i] - tbl.y[i - 1];
527 if (dy <= 0.0) return tbl.x[i - 1];
528 double t = (y_query - tbl.y[i - 1]) / dy;
529 return tbl.x[i - 1] + t * (tbl.x[i] - tbl.x[i - 1]);
530 }
531 }
532 return tbl.x[n - 1];
533}
534
535// ============================================================================
536// Extrapolating lookup (extends beyond table bounds)
537// ============================================================================
538
551inline double table_lookupEx(const Table& tbl, double x_query) noexcept {
552 // PARITY: op-for-op transliteration of legacy table_lookupEx
553 // (src/legacy/engine/table.c:469-505):
554 // - below first entry: x/x1*y1 when x1 > 0 (line through the origin),
555 // else y1 — NOT first-interval slope extrapolation;
556 // - in range: table_interpolate (multiply THEN divide, |dx| < 1e-20
557 // degenerate guard → mean);
558 // - above last entry: extrapolate with the slope `s` of the last
559 // segment seen during the walk (skipping x2 == x1 segments),
560 // clamped at s >= 0.
561 const int n = static_cast<int>(tbl.x.size());
562 if (n == 0) return 0.0;
563
564 double x1 = tbl.x[0];
565 double y1 = tbl.y[0];
566 double s = 0.0;
567 if (x_query <= x1) {
568 if (x1 > 0.0) return x_query / x1 * y1;
569 else return y1;
570 }
571 for (int i = 1; i < n; ++i) {
572 const double x2 = tbl.x[i];
573 const double y2 = tbl.y[i];
574 if (x2 != x1) s = (y2 - y1) / (x2 - x1);
575 if (x_query <= x2) {
576 const double dx = x2 - x1;
577 if (std::fabs(dx) < 1.0e-20) return (y1 + y2) / 2.;
578 return y1 + (x_query - x1) * (y2 - y1) / dx;
579 }
580 x1 = x2;
581 y1 = y2;
582 }
583 if (s < 0.0) s = 0.0;
584 return y1 + s * (x_query - x1);
585}
586
587// ============================================================================
588// Step-function interval lookup (first entry > x)
589// ============================================================================
590
604inline double table_intervalLookup(const Table& tbl, double x_query) noexcept {
605 const int n = static_cast<int>(tbl.x.size());
606 if (n == 0) return 0.0;
607
608 for (int i = 0; i < n; ++i) {
609 if (tbl.x[i] > x_query) return tbl.y[i];
610 }
611 return tbl.y[n - 1];
612}
613
614// ============================================================================
615// Slope at a point
616// ============================================================================
617
629inline double table_getSlope(const Table& tbl, double x_query) noexcept {
630 const int n = static_cast<int>(tbl.x.size());
631 if (n < 2) return 0.0;
632
633 // Use first interval for x below range
634 if (x_query <= tbl.x[0]) {
635 double dx = tbl.x[1] - tbl.x[0];
636 return (dx > 0.0) ? (tbl.y[1] - tbl.y[0]) / dx : 0.0;
637 }
638
639 // Use last interval for x above range
640 if (x_query >= tbl.x[n - 1]) {
641 double dx = tbl.x[n - 1] - tbl.x[n - 2];
642 return (dx > 0.0) ? (tbl.y[n - 1] - tbl.y[n - 2]) / dx : 0.0;
643 }
644
645 for (int i = 1; i < n; ++i) {
646 if (tbl.x[i] >= x_query) {
647 double dx = tbl.x[i] - tbl.x[i - 1];
648 return (dx > 0.0) ? (tbl.y[i] - tbl.y[i - 1]) / dx : 0.0;
649 }
650 }
651 return 0.0;
652}
653
654// ============================================================================
655// Maximum y in non-decreasing portion
656// ============================================================================
657
667inline double table_getMaxY(const Table& tbl) noexcept {
668 const int n = static_cast<int>(tbl.x.size());
669 if (n == 0) return 0.0;
670 double ymax = tbl.y[0];
671 for (int i = 1; i < n; ++i) {
672 if (tbl.y[i] < ymax) break;
673 ymax = tbl.y[i];
674 }
675 return ymax;
676}
677
678// ============================================================================
679// TableData — SoA collection of all tables
680// ============================================================================
681
690struct TableData {
691 std::vector<Table> tables;
692
711 std::unordered_map<std::string, std::vector<int>, CiHash, CiEqual> by_name;
712
713 std::size_t count() const noexcept { return tables.size(); }
714
715 Table& operator[](int idx) { return tables[static_cast<std::size_t>(idx)]; }
716 const Table& operator[](int idx) const { return tables[static_cast<std::size_t>(idx)]; }
717
722 int add(const std::string& id, TableType type) {
723 Table t;
724 t.id = id;
725 t.type = type;
726 tables.push_back(std::move(t));
727 const int idx = static_cast<int>(tables.size()) - 1;
728 by_name[id].push_back(idx);
729 return idx;
730 }
731
740 by_name.clear();
741 by_name.reserve(tables.size());
742 for (std::size_t i = 0; i < tables.size(); ++i)
743 by_name[tables[i].id].push_back(static_cast<int>(i));
744 }
745
750 int find_by_kind(std::string_view name, bool want_timeseries) const noexcept {
751 const auto it = by_name.find(name);
752 if (it == by_name.end()) return -1;
753 for (const int i : it->second) {
754 const bool is_ts =
755 tables[static_cast<std::size_t>(i)].type == TableType::TIMESERIES;
756 if (is_ts == want_timeseries) return i;
757 }
758 return -1;
759 }
760
764 void reset_cursors() noexcept {
765 for (auto& t : tables) t.cursor.reset();
766 }
767};
768
769// ============================================================================
770// Table validation
771// ============================================================================
772
774 bool valid = true;
775 std::vector<std::string> errors;
776 std::vector<std::string> warnings;
777};
778
780
781// ============================================================================
782// File-backed table API
783// ============================================================================
784
785bool table_open_file(Table& tbl, std::size_t boundary_rows = 128);
786std::size_t table_load_cache(Table& tbl, std::size_t start_row);
787
788// ============================================================================
789// Multicolumn lookup API
790// ============================================================================
791
792double table_lookup_column(Table& tbl, int col_idx, double x_query);
793double table_step_column(Table& tbl, int col_idx, double x_query);
794
795} /* namespace openswmm */
796
797#endif /* OPENSWMM_ENGINE_TABLE_DATA_HPP */
Carrier for an external file reference in a SWMM model.
Case-insensitive string helpers matching legacy SWMM name semantics.
Definition NodeCoupling.cpp:16
double table_getStorageVolume(Table &tbl, double depth) noexcept
Compute storage volume by trapezoidal integration of an area-vs-depth curve, matching legacy table_ge...
Definition TableData.hpp:374
TableType
Type of data stored in a Table.
Definition TableData.hpp:72
@ CURVE_PUMP5
Pump curve type 5 (head vs flow, variable speed)
Definition TableData.hpp:84
@ CURVE_PUMP1
Pump curve type 1 (ON/OFF depth)
Definition TableData.hpp:80
@ TIMESERIES
Rainfall, inflow, or other time-varying values.
Definition TableData.hpp:73
@ CURVE_PUMP4
Pump curve type 4 (depth vs speed)
Definition TableData.hpp:83
@ CURVE_RATING
Outfall/weir rating curve.
Definition TableData.hpp:76
@ CURVE_TIDAL
Tidal stage curve.
Definition TableData.hpp:79
@ CURVE_WEIR
Weir rating curve (legacy CurveTypeWords "WEIR")
Definition TableData.hpp:85
@ CURVE_SHAPE
Cross-section shape curve.
Definition TableData.hpp:77
@ CURVE_STORAGE
Storage node volume-depth curve.
Definition TableData.hpp:74
@ CURVE_DIVERSION
Diversion rating curve.
Definition TableData.hpp:75
@ CURVE_CONTROL
Control rule action curve.
Definition TableData.hpp:78
@ CURVE_PUMP2
Pump curve type 2 (head vs flow)
Definition TableData.hpp:81
@ CURVE_PUMP3
Pump curve type 3 (volume vs time)
Definition TableData.hpp:82
double table_getSlope(const Table &tbl, double x_query) noexcept
Compute the slope (dy/dx) at a given x value.
Definition TableData.hpp:629
double table_getStorageDepth(Table &tbl, double volume) noexcept
Invert a storage area-vs-depth curve to find depth from volume.
Definition TableData.hpp:440
double table_step_cursor(Table &tbl, double x_query) noexcept
Piecewise-constant (step function) table lookup with cursor.
Definition TableData.hpp:324
double table_lookup_column(Table &tbl, int col_idx, double x_query)
Definition TableData.cpp:666
TableValidation validate_table(Table &tbl)
Definition TableData.cpp:298
double table_getMaxY(const Table &tbl) noexcept
Return the maximum y value in the non-decreasing leading portion.
Definition TableData.hpp:667
bool table_open_file(Table &tbl, std::size_t boundary_rows)
Definition TableData.cpp:426
double table_intervalLookup(const Table &tbl, double x_query) noexcept
Step-function lookup: return y for the first x entry > x_query.
Definition TableData.hpp:604
@ TIMESERIES
Data from an in-file [TIMESERIES].
Definition GageData.hpp:58
double table_lookupEx(const Table &tbl, double x_query) noexcept
Linear-interpolating lookup with linear extrapolation outside bounds.
Definition TableData.hpp:551
double table_inverseLookup(const Table &tbl, double y_query) noexcept
Inverse lookup: given y, find corresponding x by linear interpolation.
Definition TableData.hpp:516
double table_lookup_cursor(Table &tbl, double x_query) noexcept
Look up a value in a Table using the bidirectional cursor.
Definition TableData.hpp:219
std::size_t table_load_cache(Table &tbl, std::size_t start_row)
Definition TableData.cpp:551
double table_tseries_lookup_cursor(Table &tbl, double x_query) noexcept
Time-series linear interpolation with out-of-range → 0 behaviour.
Definition TableData.hpp:290
double table_step_column(Table &tbl, int col_idx, double x_query)
Definition TableData.cpp:719
Transparent case-insensitive equality for unordered containers.
Definition StringCase.hpp:79
Transparent case-insensitive hash (FNV-1a over the uppercase fold).
Definition StringCase.hpp:65
Two-string carrier for any external file path that appears in a SWMM .inp file.
Definition FilePathPair.hpp:63
A single time series or rating curve.
Definition TableData.hpp:128
bool empty() const noexcept
Definition TableData.hpp:135
std::size_t num_rows() const noexcept
Definition TableData.hpp:134
std::size_t file_row_start
Row offset in file (cache only)
Definition TableData.hpp:132
std::vector< double > x
Independent variable values.
Definition TableData.hpp:129
int num_cols
Number of value columns.
Definition TableData.hpp:131
std::vector< double > y
Dependent values (flat: row-major, num_cols per row)
Definition TableData.hpp:130
Bidirectional cursor tracking the last accessed index in a Table.
Definition TableData.hpp:103
int index
Index of the last successful lookup entry.
Definition TableData.hpp:104
int direction
Last seek direction: +1 = forward, -1 = backward.
Definition TableData.hpp:105
void reset() noexcept
Definition TableData.hpp:107
SoA collection of all time series and curves in the model.
Definition TableData.hpp:690
std::vector< Table > tables
All tables in index order.
Definition TableData.hpp:691
std::size_t count() const noexcept
Definition TableData.hpp:713
std::unordered_map< std::string, std::vector< int >, CiHash, CiEqual > by_name
Case-insensitive name → table indices, ascending.
Definition TableData.hpp:711
int add(const std::string &id, TableType type)
Add a new empty table with the given ID and type.
Definition TableData.hpp:722
void reset_cursors() noexcept
Reset all cursors (call before re-running a simulation).
Definition TableData.hpp:764
void rebuild_index()
Rebuilds by_name from tables.
Definition TableData.hpp:739
Table & operator[](int idx)
Definition TableData.hpp:715
int find_by_kind(std::string_view name, bool want_timeseries) const noexcept
Lowest-indexed table with this name and kind; -1 if none.
Definition TableData.hpp:750
const Table & operator[](int idx) const
Definition TableData.hpp:716
Definition TableData.hpp:138
long data_start_offset
File offset to first data row.
Definition TableData.hpp:180
std::size_t total_rows
Total data rows in file.
Definition TableData.hpp:178
TableBlock cache
Sliding cache window for file lookups.
Definition TableData.hpp:173
std::vector< long > row_offsets
Sparse byte-offset index into file.
Definition TableData.hpp:181
std::string comment
Object comment from the INP file (';'-prefixed lines immediately above the first row of this table),...
Definition TableData.hpp:147
std::size_t num_cache_rows
Cache window size (rows)
Definition TableData.hpp:179
std::unordered_map< std::string, int > column_map
Column name → index.
Definition TableData.hpp:183
TableCursor cursor
Bidirectional lookup cursor.
Definition TableData.hpp:150
TableType type
Table type (TIMESERIES, CURVE_*, etc.)
Definition TableData.hpp:140
bool empty() const noexcept
True if the table has at least one data point.
Definition TableData.hpp:191
double dx_min
Minimum inter-entry x spacing.
Definition TableData.hpp:174
double rel_anchor
start_date offset currently baked into them
Definition TableData.hpp:164
std::string id
Table identifier (from input file)
Definition TableData.hpp:139
double x_max
Maximum x value in file.
Definition TableData.hpp:176
std::vector< double > y
Dependent variable (flow, volume, etc.)
Definition TableData.hpp:149
std::FILE * file_handle
Open file handle (owned)
Definition TableData.hpp:168
FilePathPair file_path
Definition TableData.hpp:169
bool is_file_based
True if data is read from external file.
Definition TableData.hpp:167
TableBlock last_boundary
Last rows from file (for validation)
Definition TableData.hpp:172
int n_relative
Leading rows authored as elapsed time-of-start.
Definition TableData.hpp:163
static constexpr std::size_t INDEX_STRIDE
Rows between offset index entries.
Definition TableData.hpp:185
std::vector< double > x
Independent variable (time, depth, etc.)
Definition TableData.hpp:148
double x_min
Minimum x value in file.
Definition TableData.hpp:175
TableBlock first_boundary
First rows from file (for validation)
Definition TableData.hpp:171
int num_cols
Number of value columns.
Definition TableData.hpp:177
std::size_t size() const noexcept
Number of data points.
Definition TableData.hpp:188
std::vector< std::string > column_ids
Column identifiers.
Definition TableData.hpp:182
Definition TableData.hpp:773
std::vector< std::string > errors
Definition TableData.hpp:775
std::vector< std::string > warnings
Definition TableData.hpp:776
bool valid
Definition TableData.hpp:774