| 153 | |
| 154 | == Switcher for equations == |
| 155 | |
| 156 | Currently, continuous-discrete modeling is supported in EMSO using the '''if''' statement. |
| 157 | But some more complex situations cannot be modeled with '''if'''. |
| 158 | |
| 159 | For example, a safety valve which opens if the pressure is higher than 2 atm but closes only when the pressure is lower than 1 atm. |
| 160 | This situation cannot be modeled by a simply '''if'''. For this case, a State Transition Network (STN) is needed. |
| 161 | |
| 162 | For this case the '''Switcher''' is proposed, usage: |
| 163 | {{{ |
| 164 | #!mso |
| 165 | Model SafetyValve |
| 166 | PARAMETERS |
| 167 | mode as Switcher(Valid = ["closed", "opened"], Default = "closed") |
| 168 | ... |
| 169 | EQUATIONS |
| 170 | switch(mode) |
| 171 | case "closed": |
| 172 | flow = 0 * "mol/h"; |
| 173 | change to "opened" if P>2*"atm"; |
| 174 | case "opened": |
| 175 | flow = k*sqrt(P - Pout); |
| 176 | change to "closed" if P<1*"atm"; |
| 177 | end |
| 178 | ... |
| 179 | end |
| 180 | }}} |
| 181 | |
| 182 | In the piece of code above there are the following news: |
| 183 | * A new basic type called '''Switcher''' |
| 184 | * The '''Switcher''' type has an extra attribute called '''Valid''' which are the valid values for the switcher |
| 185 | * There is a '''switch''' command which can be used in the EQUATIONS |
| 186 | * There is a '''change to''' command which can be used inside a '''case''' of a '''switch''' |
| 187 | |
| 188 | ||Who || Opinion || Why || |
| 189 | ||Rafael || '''agreed''' || proposed the change || |