This article is part of the GoldSim Style Guide. For an introduction, please start here.
GoldSim provides several features that enable you to enter mathematical expressions into input fields. Become familiar with and make use of these features to write expressions efficiently. This section introduces our style recommendations for expressions written in GoldSim.
The way you use white space in your expressions can make a significant difference in readability. Consistent and careful use of white space can significantly increase readability by making math operators more visible, improving text wrapping, and creating emphasis on important parts of the equation. As shown in the ensuing examples, expressions that have no spaces and are more difficult to read.
The general rules of thumb for using white space are:
- Before and after math/logic operators except power (“length^2”)
- After a comma
Below I have listed some various use cases that compare different ways of using white space with the recommended way indicated next to the "Good" label.
Good: Width + Height * (1 + X_Left^2)^0.5 + y * (1 - X_Right^2)^0.5
(note, this is not a real equation)
Good: if(Fraction_of_Treated * Inflow >= Inflow, Pump1, 0 l/s)
Vector and Matrix Expressions
Good: vector(ore, waste[3, 2])
Values with Units
Add a space before a unit that follows a value.
Bad: max(0ft, Max_Pumping - Current_Pumping)
Good: max(0 ft, Max_Pumping - Current_Pumping)
GoldSim allows you to alternatively use words “then” and “else” in IF statements if you want. If you use these words, then obviously, you would need spaces:
IF(Month == 4 then Outflow else 0.0 l/s)
If you choose to do this, you should be consistent (either use it for all IF statements or none). GoldSim uses 2 different data types in expressions: value and condition. You can use a condition type output to express a condition in IF statements. Do not duplicate the condition by checking for equality to True or False. For example, the below equation can be written in 2 different ways:
Bad: IF(Pump_ON == True, Outflow, 0.0 l/s)
Good: IF(Pump_ON, Outflow, 0.0 l/s)
Because the first method is redundant, it is better to write it with only the conditional output.
For whole numbers, either show the integer or a trailing zero after the period. Do not just include the period without a zero because this is harder to read.
Bad: Flow_Rate = 3. l/s
Good: Flow_Rate = 3.0 l/s
Don’t hide the details of your model within long input expressions. It is better to add a few additional elements such that the relationships in the model can be shown graphically and are transparent. It can be difficult to read and understand long equations with layers of sub-expressions buried in parentheses. If you find yourself trying to decipher where your closing parenthesis is, there is a good chance you should consider breaking up the expression into smaller parts. Take the expression below, for example. This expression isn’t terribly long, but it is difficult to make sense of it because of so many embedded expressions within parentheses.
Instead, this expression can be broken out into the following elements: