Loading...
Searching...
No Matches
meshinfil.h
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
45
46#ifndef OPENSWMMVIS_MESHINFIL_H
47#define OPENSWMMVIS_MESHINFIL_H
48
49#include <QByteArray>
50#include <QHash>
51#include <QString>
52#include <QStringList>
53#include <QVector>
54#include <QtGlobal>
55#include <QtNumeric>
56
57namespace mesh
58{
59
60struct MeshResult;
61
65enum class InfilMethod : int {
66 None = -1,
67 Horton = 0,
73};
74
76enum class InfilDest : int {
77 Lost = 0,
80};
81
83inline constexpr int kInfilMaxParams = 5;
84
101struct InfilRow {
104 double p[kInfilMaxParams] = {qQNaN(), qQNaN(), qQNaN(), qQNaN(), qQNaN()};
106
113 bool isNone() const { return method == InfilMethod::None; }
123 bool operator==(const InfilRow &o) const;
130 bool operator!=(const InfilRow &o) const { return !(*this == o); }
131};
132
136 QString tag;
138};
139
144 double infilStep = 0.0;
145};
146
150enum class InfilProvenance : int {
151 None = 0,
152 Star = 1,
153 Tag = 2,
155};
156
180
181// ---------------------------------------------------------------------------
182// Resolution
183// ---------------------------------------------------------------------------
184
202ResolvedInfil resolveInfil(const MeshResult &mesh, int tri);
203
213InfilRow starDefault(const MeshResult &mesh);
214
225int indexOfDefault(const MeshResult &mesh, const QString &tag);
226
227// ---------------------------------------------------------------------------
228// Method ↔ parameter masks
229// ---------------------------------------------------------------------------
230
245bool infilUsesParam(InfilMethod method, int slot);
246
256int infilParamCount(InfilMethod method);
257
268QString infilParamLabel(InfilMethod method, int slot);
269
285QByteArray infilParamKey(InfilMethod method, int slot);
286
297int infilSlotForKey(InfilMethod method, const QByteArray &key);
298
309const QVector<QByteArray> &infilParamKeys();
310
311// ---------------------------------------------------------------------------
312// Tokens (must match the engine exactly)
313// ---------------------------------------------------------------------------
314
322QString infilMethodToken(InfilMethod m);
332InfilMethod infilMethodFromToken(const QString &token, bool *ok = nullptr);
339QString infilMethodLabel(InfilMethod m);
346QStringList infilMethodLabels();
347
355QString infilDestToken(InfilDest d);
365InfilDest infilDestFromToken(const QString &token, bool *ok = nullptr);
372QString infilDestLabel(InfilDest d);
379QStringList infilDestLabels();
380
395QString infilDestHint(InfilDest d);
396
397// ---------------------------------------------------------------------------
398// Classified-lookup tables (GUI plan §3.4(a))
399// ---------------------------------------------------------------------------
400
404 QString key1;
405 QString key2;
407};
408
412 QString name;
413 bool twoKey = false;
414 QString key1Label;
415 QString key2Label;
416 QVector<InfilLookupEntry> entries;
418
431 InfilRow lookup(const QString &k1, const QString &k2, bool *matched = nullptr) const;
432};
433
453bool saveLookupTableCsv(const InfilLookupTable &table, const QString &path, QString *err);
469bool loadLookupTableCsv(InfilLookupTable *table, const QString &path, QString *err);
470
471} // namespace mesh
472
473#endif // OPENSWMMVIS_MESHINFIL_H
The Qt-facing MeshKit API (meshkit::core_qt, meshkit::model_qt, meshkit::io_qt): mesh value types and...
QString infilDestHint(InfilDest d)
Translate destination guidance without resolving any open model.
Definition meshinfil.cpp:425
int infilParamCount(InfilMethod method)
Report serialized parameter-column width rather than number of active values.
Definition meshinfil.cpp:173
ResolvedInfil resolveInfil(const MeshResult &mesh, int tri)
Resolve an owned infiltration specification while preserving its authoring provenance.
Definition meshinfil.cpp:112
bool loadLookupTableCsv(InfilLookupTable *table, const QString &path, QString *err)
Load the permissive unquoted classified-lookup CSV format into a fresh table value.
Definition meshinfil.cpp:605
InfilDest
Destination of infiltrated water (engine Infil2DDest).
Definition meshinfil.h:76
@ Aquifer2D
Legacy token, rejected by current engine validation; migrate ownership.
Definition meshinfil.h:79
@ SubcatchAquifer
U3: recharges the containing subcatchment's aquifer.
Definition meshinfil.h:78
@ Lost
Leaves the model.
Definition meshinfil.h:77
int indexOfDefault(const MeshResult &mesh, const QString &tag)
Find the first exact case-sensitive default tag match.
Definition meshinfil.cpp:87
InfilRow starDefault(const MeshResult &mesh)
Copy the first wildcard infiltration default, if present.
Definition meshinfil.cpp:95
int infilSlotForKey(InfilMethod method, const QByteArray &key)
Resolve a named parameter key to its position under one model.
Definition meshinfil.cpp:275
InfilMethod
Infiltration method.
Definition meshinfil.h:65
@ ModHorton
Modified Horton.
Definition meshinfil.h:68
@ CurveNumber
SCS curve number.
Definition meshinfil.h:71
@ None
No infiltration method assigned.
Definition meshinfil.h:66
@ ModGreenAmpt
Modified Green-Ampt.
Definition meshinfil.h:70
@ Horton
Horton.
Definition meshinfil.h:67
@ Constant
Constant infiltration rate.
Definition meshinfil.h:72
@ GreenAmpt
Green-Ampt.
Definition meshinfil.h:69
QString infilMethodLabel(InfilMethod m)
Translate a display label for an infiltration method.
Definition meshinfil.cpp:346
QString infilDestToken(InfilDest d)
Encode a destination enum as its retained uppercase file token.
Definition meshinfil.cpp:375
InfilMethod infilMethodFromToken(const QString &token, bool *ok=nullptr)
Parse a trimmed case-insensitive infiltration method token.
Definition meshinfil.cpp:322
QString infilMethodToken(InfilMethod m)
Encode an infiltration method using the stable uppercase file vocabulary.
Definition meshinfil.cpp:301
constexpr int kInfilMaxParams
Widest positional parameter count (Horton: f0 fmin decay dry_time Fmax).
Definition meshinfil.h:83
QString infilParamLabel(InfilMethod method, int slot)
Translate the model-specific label for an active positional parameter.
Definition meshinfil.cpp:194
QStringList infilMethodLabels()
Build translated method labels in consecutive enum order from None through Constant.
Definition meshinfil.cpp:367
QByteArray infilParamKey(InfilMethod method, int slot)
Map an active model slot to its case-sensitive shared registry key.
Definition meshinfil.cpp:233
const QVector< QByteArray > & infilParamKeys()
Return the immutable union of named infiltration parameter keys in registration order.
Definition meshinfil.cpp:285
InfilProvenance
Where a cell's resolved parameters came from — drives the muted/italic "inherited" rendering in the a...
Definition meshinfil.h:150
@ Star
From the '*' default row.
Definition meshinfil.h:152
@ None
No model resolves for this cell.
Definition meshinfil.h:151
@ Override
From a per-cell override.
Definition meshinfil.h:154
@ Tag
From a tag default row.
Definition meshinfil.h:153
QString infilDestLabel(InfilDest d)
Translate the display label of a retained destination value.
Definition meshinfil.cpp:404
QStringList infilDestLabels()
Build translated destination labels in enum order Lost, SubcatchAquifer, Aquifer2D.
Definition meshinfil.cpp:417
InfilDest infilDestFromToken(const QString &token, bool *ok=nullptr)
Parse a retained destination token independently of current engine support.
Definition meshinfil.cpp:388
bool saveLookupTableCsv(const InfilLookupTable &table, const QString &path, QString *err)
Serialize classified infiltration entries and optional fallback to a QSaveFile CSV replacement.
Definition meshinfil.cpp:555
bool infilUsesParam(InfilMethod method, int slot)
Check whether a model uses a zero-based positional parameter slot.
Definition meshinfil.cpp:149
One [2D_INFILTRATION_DEFAULTS] row.
Definition meshinfil.h:135
InfilRow row
Specification inherited by cells with this tag (may be an explicit None).
Definition meshinfil.h:137
QString tag
Cell tag matched exactly (case-sensitive); "*" = mesh-wide fallback.
Definition meshinfil.h:136
One row of a classified lookup: a key (or key pair, for the Curve-Number landuse×HSG case) mapping to...
Definition meshinfil.h:403
InfilRow row
Specification returned when the key(s) match.
Definition meshinfil.h:406
QString key2
Empty for single-key lookups.
Definition meshinfil.h:405
QString key1
Class key, matched case-insensitively without trimming by lookup()
Definition meshinfil.h:404
An editable, reusable classified lookup table.
Definition meshinfil.h:411
QString key2Label
Caption of the second key column (CSV # KEY2:), two-key only.
Definition meshinfil.h:415
bool twoKey
True: entries match key1 AND key2; false: key2 is ignored.
Definition meshinfil.h:413
QVector< InfilLookupEntry > entries
Searched in order; the first match wins.
Definition meshinfil.h:416
QString key1Label
Caption of the first key column (CSV # KEY1:)
Definition meshinfil.h:414
InfilRow fallback
Applied to unmatched keys.
Definition meshinfil.h:417
InfilRow lookup(const QString &k1, const QString &k2, bool *matched=nullptr) const
Copy the first classified entry matching one or two case-insensitive keys.
Definition meshinfil.cpp:449
QString name
Display name (CSV # NAME:); the loader falls back to the file basename.
Definition meshinfil.h:412
[2D_INFILTRATION_OPTIONS].
Definition meshinfil.h:141
double infilStep
Evaluation cadence in seconds.
Definition meshinfil.h:144
One infiltration specification: method + positional parameters + destination.
Definition meshinfil.h:101
InfilMethod method
Model; None (default) = no infiltration.
Definition meshinfil.h:102
bool operator==(const InfilRow &o) const
Compare method, destination and every positional parameter, treating unset NaNs as equal.
Definition meshinfil.cpp:73
bool operator!=(const InfilRow &o) const
Negate all-slot infiltration-row equality with its NaN-as-unset convention.
Definition meshinfil.h:130
double p[kInfilMaxParams]
Positional parameters p0..p4 in project units (table above); NaN (default) = unset.
Definition meshinfil.h:104
InfilDest dest
Where infiltrated water goes; Lost by default.
Definition meshinfil.h:105
bool isNone() const
Test whether this row explicitly selects no infiltration method.
Definition meshinfil.h:113
Result of MeshGenerator::generate.
Definition meshresult.h:203
Result of resolving one triangle's infiltration.
Definition meshinfil.h:158
InfilProvenance provenance
Which source supplied row.
Definition meshinfil.h:160
InfilRow row
Winning row copied from its source; a None row when nothing resolves.
Definition meshinfil.h:159
bool isOverride() const
Check the resolved row's provenance rather than whether a kernel is enabled.
Definition meshinfil.h:168
bool isInherited() const
Check whether a resolved row came from a tag or wildcard default.
Definition meshinfil.h:175
QString sourceTag
Tag that supplied it (Tag/Star only)
Definition meshinfil.h:161