If, Else If, Else, End If
To construct an If statement, in the Geometry toolbar, from the Programming menu, select If + End If (you can also do this by right-clicking the Geometry node in the model tree and opening the Programming submenu). This adds an If node () and an End If node () after the current node. You can optionally add Else If () nodes and an Else node () in a similar way. To add these nodes at an arbitrary position in a geometry sequence, you can right-click a geometry feature node and select If, Else If, Else, or End If on the Add Before or Add After submenu. This adds the selected type of programming feature before or after the selected node, without building the preceding feature node.
An If statement has the following structure:
If
  <branch1>
Else If
  <branch2>
Else If
  <branch3>
...
Else
  <last branch>
End If
where the Else If and Else nodes are optional. There can be an arbitrary number of geometry features in each branch, and there can be an arbitrary number of Else If nodes. The Else node must appear after all Else If nodes and before the End If node.
The Thermal Microactuator Simplified model in the Multiphysics section of the COMSOL Multiphysics Application Library uses If and End If nodes in its geometry sequence to consider different geometry cases.
If you have the CFD Module, the Mixer application’s geometry sequence shows the use of If, Else If, and End If.
If and Else If
The Settings windows for If and Else If have a Condition field, which contains a logical condition in terms of parameters (for example, a+b>0, where a and b are defined as parameters for the geometry sequence). In general, the condition is true if it evaluates to a nonzero value. When building the geometry sequence, the program builds the features in the first branch that has a true condition and treats the other branches as disabled. If none of the conditions are true, the program builds the Else branch.
If you select a feature in a branch and click Build Selected, the software pretends that the chosen branch has a true condition and that all other branches have false conditions. You can use this behavior to try out the different branches without having to change the parameters. If statements can be nested.
To define selections that have different definitions in different branches of an If statement, you can use cumulative selections (see Cumulative Selections).