Reference
This section is a comprehensive reference for the WRESL+ language. Use it to look up exact syntax, available keywords, and supported functions.
Keywords
The following keywords are recognized by the WRESL+ parser (case-insensitive):
Category |
Keywords |
Variable definition |
|
Variable content |
|
Bounds |
|
Metadata |
|
Goals/Objectives |
|
Table lookups |
|
Summation |
|
Conditions |
|
Logical operators |
|
Control flow |
|
Model structure |
|
Special identifiers |
|
Unit conversions |
|
Calendar months |
|
Previous months |
|
Variable Definition Syntax
TimeArray — An optional parenthesized integer or identifier, e.g., (12), that declares the variable as a time array with multiple slots (one per sub-timestep). When omitted, the variable holds a single value per timestep. This is used for variables that need to store values across multiple sub-periods within a timestep.
State Variable
define|svar [(TimeArray)] [[local]] Name { SvarContent }
Where SvarContent is one of:
value Expressiontimeseries ['BPart'] kind 'K' units 'U' [convert 'C']select Column from Table [given Assign use ID] [where Assignments]sum(i=Expr1,Expr2) ExpressionOne or more
case Name { condition LogicalExpr|always value|select|sum ... }
Examples:
! Source: CalSim3 DCR 9.5.0 — arcs-Inflows.wresl
define I_SHSTA {timeseries kind 'INFLOW' units 'TAF' convert 'CFS'}
! Source: CalSim3 DCR 9.5.0 — arcs-Reservoirs.wresl
define S_SHSTAlevel1 {value 550}
! Source: CalSim3 DCR 9.5.0 — arcs-Reservoirs.wresl
define A_SHSTAlast {
select area from res_info
given storage = 1000*S_SHSTA(-1)
use linear
where res_num = 4
}
! Source: WRESL+ Language Reference (2018)
svar Z {sum(i=1, 5, 1) S03(-i) + I10(-i)}
! Source: WRESL+ Language Reference (2018)
svar NMTest {
case February {
condition month == feb
value S10(-12) + sumI10_part
}
case Others {
condition always
value S10(prevfeb) + sumI10_part
}
}
Decision Variable
define|dvar [(TimeArray)] [[local]] Name { DvarContent }
Where DvarContent is one of:
std kind 'K' units 'U'[lower Expr] [upper Expr] kind 'K' units 'U'binary kind 'K' units 'U'integer std kind 'K' units 'U'integer [lower Expr] [upper Expr] kind 'K' units 'U'
Examples:
! Source: WRESL+ Language Reference (2018)
dvar C_Delta_SWP {std kind 'FLOW-CHANNEL' units 'CFS'}
dvar QPD {lower -100. upper unbounded kind 'FLOW' units 'CFS'}
dvar Integer2 {integer lower 0 upper 3 kind 'INTEGER' units 'NA'}
Constant
const [[local]] Name { Number }
Example:
! Source: CalSim3 DCR 9.5.0 — arcs-Reservoirs.wresl
define S_SHSTAlevel1 {value 550}
Alias
define [(TimeArray)] [[local]] Name { alias Expression [kind 'K'] [units 'U'] }
Example:
! Source: CalSim3 DCR 9.5.0 — SoDeltaChannels.wresl
define OMFlow {alias C_OMR014 kind 'FLOW-CHANNEL' units 'CFS'}
! Source: WRESL+ Language Reference (2018)
alias Estlim3 {max(300., Est_rel) kind 'DEBUG' units 'CFS'}
External
define [[local]] Name { external LibraryName[.dll|.f90] }
Where LibraryName is the filename of an external DLL or Fortran 90 library. The external function is called by the evaluator at runtime.
Example:
! Source: CalSim3 DCR 9.5.0 — CVGroundwater_ExtFuncs.wresl
define InitGWSystem {EXTERNAL interfacetogw_x64.dll}
Goal Syntax
Simple goal
goal [(TimeArray)] [[local]] Name { Expression < | > | = Expression }
Examples:
! Source: CalSim3 DCR 9.5.0 — constraints-Connectivity.wresl
goal continuitySHSTA {I_SHSTA - C_SHSTA - D_SHSTA_WTPJMS - E_SHSTA = S_SHSTA * taf_cfs - S_SHSTA(-1) * taf_cfs + 0.}
! Source: WRESL+ Language Reference (2018)
goal Test {X > Y}
Complex goal with LHS/RHS
goal [(TimeArray)] [[local]] Name {
lhs Expression
rhs Expression
[lhs > rhs constrain | penalty Expression]
[lhs < rhs constrain | penalty Expression]
}
Example:
! Source: WRESL+ Language Reference (2018)
goal NMTest {
lhs X + Y
rhs Z
lhs > rhs constrain
lhs < rhs penalty 0
}
Complex goal with cases
goal [(TimeArray)] [[local]] Name {
lhs Expression
case CaseName {
condition LogicalExpression | always
rhs Expression
[lhs > rhs constrain | penalty Expression]
[lhs < rhs constrain | penalty Expression]
}
...
}
Example:
! Source: WRESL+ Language Reference (2018)
goal TestAction1 {
lhs D_J1 + D_B1
case April {
condition month == apr
rhs CNW + X
lhs < rhs penalty 0
}
case Others {
condition always
rhs 3000. * 16.0 / daysin + Z
lhs < rhs penalty 0
lhs > rhs constrain
}
}
Objective Syntax
objective [[local]] Name [=] {
[VarRef [(TimeArray)], WeightExpression],
...
}
Notes:
For Decision Variables declared as a time array, the
(TimeArray)in the objective entry must match the declaration.For non-time-array Decision Variables, omit the time array specifier.
Example:
! Source: WRESL+ Language Reference (2018)
objective XGroup {[X1, 10] [X2, 20]}
! Source: CalSim3 DCR 9.5.0 — Weight-table.wresl (abbreviated)
Objective obj_SYS = {
[S_TRNTY_1, 200000*taf_cfs],
[S_TRNTY_2, 93*taf_cfs],
[S_SHSTA_1, 200000*taf_cfs],
[S_SHSTA_2, 93*taf_cfs]
}
Model Structure Syntax
Sequence
sequence Name { model ModelRef [condition LogicalExpr] [order INT] [timestep 1MON|1DAY] }
Example:
! Source: WRESL+ Language Reference (2018)
sequence CYCLE1 {model Upstream order 1}
sequence CYCLE4 {model Test2 condition MON==jun order 4}
! Source: CalSim3 DCR 9.5.0 — mainCS3_ReOrg_UWplusVF.wresl
SEQUENCE CYCLE33 {model UPSTREAM condition simulateSacramentoValley >= 0.5 order 33}
Model
model Name { (Pattern | IfIncItems)+ }
Example:
! Source: CalSim3 DCR 9.5.0 — mainCS3_ReOrg_UWplusVF.wresl (abbreviated)
model UPSTREAM {
include group Tdomain
include group Common_All
include 'System\System_Sac_cycle1.wresl'
if simulateSacVA_TisdaleWeir < 0.5 {
include 'SystemTables_Sac\constraints-Weirs2.wresl'
}
}
Group
group Name { (Pattern | IfIncItems)+ }
Example:
! Source: CalSim3 DCR 9.5.0 — mainCS3_ReOrg_UWplusVF.wresl
group Common_All {
include 'CVGroundwater\CalSim3GWregionIndex.wresl'
include 'Other\NewFacilitySwitches.wresl'
include 'Other\wytypes\WyTypesGeneral.wresl'
}
Initial
initial { (SimpleValueSvar | LookupTableSvar | IncludeStatement)+ }
Notes:
Runs once before the main simulation loop.
Only simple value or lookup table state variables are allowed.
Include statements are often used to bring in files with these variables.
Example:
! Source: WRESL+ Language Reference (2018)
initial {
svar A {value 10.}
svar B {value A * 5}
svar C {value B + 6.0}
}
! Source: CalSim3 DCR 9.5.0 — mainCS3_ReOrg_UWplusVF.wresl (abbreviated)
initial {
include 'System\SystemTables_Sac\arcs-Reservoirs.wresl'
include 'CVGroundwater\CVGroundwater_init1_SJRBASE.wresl'
}
Include
include [[local]] 'filepath.wresl'
include model ModelName
include group GroupName
Data Types
Integer (e.g.,
42,550)Float (e.g.,
3.14,.5,1.98347)
Operators
Type |
Operators |
Arithmetic |
|
Comparison |
|
Logical |
|
Strings
Strings use single quotes:
kind 'FLOW-CHANNEL'
units 'CFS'
include 'System\SystemTables_Sac\arcs-Reservoirs.wresl'
Supported Functions
Function |
Description |
Example |
|
Minimum of values |
|
|
Maximum of values |
|
|
Absolute value |
|
|
Round to nearest integer |
|
|
Truncate to integer |
|
|
Modulo (remainder) |
|
|
Power (a raised to b) |
|
|
Logarithm (also |
|
|
Sine |
|
|
Cosine |
|
|
Tangent |
|
|
Cotangent |
|
|
Arc sine |
|
|
Arc cosine |
|
|
Arc tangent |
|
|
Arc cotangent |
|
|
Check if month/year is in range |
|
Special Built-in Identifiers
Identifier |
Description |
|
Current simulation month (numeric) |
|
Current water year |
|
Current simulation day |
|
Number of days in current month |
|
Number of days in current timestep. Note: This is a built-in evaluator keyword, not a parser-level keyword. It is case-sensitive and must be written in lowercase only. |
|
Calendar month constants |
|
Previous year’s month references |
|
TAF to CFS conversion factor for the current timestep |
|
CFS to TAF conversion factor for the current timestep |
|
AF to CFS conversion factor for the current timestep |
|
CFS to AF conversion factor for the current timestep |
|
Multi-step reference |
|
Loop variable (used inside |
Variable Cross-References
Syntax |
Meaning |
Example |
|
Reference variable as solved in another model cycle |
|
|
Reference variable from the previous time step |
|
|
Cross-model reference with time offset |
|
|
Index-based variable reference |
|
Comments
Single-line comments begin with
!: