SubtractFunction
The SubtractFunction is a utility function that returns the difference of values from its child functions.
Overview
The SubtractFunction is used to subtract the values of other child functions from the first child. It calculates the difference between the first child function and the sum of all subsequent child functions. This is useful when you need to compute a value that is derived from subtracting multiple traits or parameters in plant growth models.
Model Structure
This section describes how this model is positioned within the APSIM framework. It outlines the broader structural and computational components that define its role and interactions in the simulation system.
This model inherits structural and functional behaviour from the following core APSIM components:
The SubtractFunction inherits from the following classes:
Connections to Other Components
This section describes how the model interacts with other components in the APSIM Next Generation framework.
These connections allow the model to exchange information—such as environmental conditions, developmental stage, or physiological responses—with other parts of the simulation system. For a general overview of how model components are connected in APSIM, see the Connections Overview.
| Component | Model | Connection Type | Description |
|---|---|---|---|
| Child Functions | IFunction | Children | Multiple child functions whose values are used in the subtraction calculation. |
Model Variables
This section lists the key variables that describe or control the behaviour of this component. Some variables can be adjusted by the user to modify how the model behaves (configurable), while others are calculated internally and can be viewed as model outputs (reportable). For a general explanation of variable types and how they are used within the APSIM Next Generation framework, see the Model Variables Overview.
Configurable and Reportable Properties
No configurable properties are available for this function.
Read-Only Reportable Properties
| Property | Type | Description |
|---|---|---|
| Value | double | The sum of values from all child functions. |
Processes and Algorithms
This section describes the scientific processes and algorithms represented by this component. Each process corresponds to a biological, physical, or chemical mechanism simulated during a model time step. Where appropriate, equations or conceptual summaries are provided to explain how the process operates within the APSIM Next Generation framework.
Subtraction Calculation
The SubtractFunction takes the value of the first child function and subtracts the values of all subsequent child functions from it. The calculation follows this pattern:
\[ \text{Result} = f_1 - f_2 - f_3 - \ldots - f_n \]
where \(f_1, f_2, \ldots, f_n\) are the values returned by the child functions.
The algorithm operates as follows:
- If no child functions are present, the function returns 0.0
- If only one child function exists, it returns that function’s value
- If multiple child functions exist, it starts with the first child’s value and sequentially subtracts each subsequent child’s value
This sequential subtraction ensures that the operation is equivalent to:
\[ \text{Result} = f_1 - (f_2 + f_3 + \ldots + f_n) \]
User Interface
SubtractFunction can be added as a child of any node that accepts function inputs in the model tree. Right-click the parent node, select “Add Model…”, and search for SubtractFunction in the Filter Box. A symbol for the SubtractFunction is displayed in the user interface to represent the function.

Practical Example
The wheat yield is reduced by frost stress as a ratio of total yield (e.g. FrostDamage). The final yield is calculated by subtracting the frost damage from the total potential yield.
\[ \text{FinalYield} = \text{TotalPotentialYield} \times (1 - \text{FrostDamage}) \]
The SubtractFunction is used to subtract these two values to get the final yield in the equation above.
See Also
- Source code: SubtractFunction.cs on GitHub