functionupdateEquation
Replaces an equation with another equation in a class.
Information
Syntax
updateEquation(MyModel, "x = 1", "x = 2")
Description
updateEquation takes two equations, given as strings that are parsed as Modelica equations, and replaces an equation in the given class that matches the first equation with the second. If
newEqis an empty string, then the matching equation is removed instead of replaced.
Optional arguments
- matchAll
-
If
matchAll
is true, then updateEquation replaces all equations that matches. Otherwise it only replaces the first matching equation. - matchShallow
-
If
matchShallow
is true, then equations are only matched shallowly, ignoring any nested equations. I.e.updateEquation(M, "if b then end if", ...)
will replace any if-equation that matchesif b then
, regardless of what equations the if-equation contains. IfmatchShallow
is false, then the equations must match recursively. - matchDescription
-
If
matchDescription
is true, then the description strings and annotations of the equations must match. Otherwise these are ignored when matching equations. - mergeDescription
-
If
mergeDescription
is true, then the description string and/or annotations of the replaced equation are copied to the new equation if these are missing on the new equation. This requires thatmatchDescription
is false, otherwise there will be nothing to merge since the equations must have the same description to match. IfmergeDescription
is false, then the new equation overwrites the old completely, including description strings and annotations.
Inputs
| Type | Name | Default | Description |
|---|---|---|---|
| TypeName | className | The name of the class | |
| String | oldEq | The equation to replace | |
| String | newEq | The equation to replace with | |
| Boolean | matchAll | false | Update all matching equations if true, otherwise only the first matching |
| Boolean | matchShallow | true | Ignore nested equations if true, otherwise match the equations recursively |
| Boolean | matchDescription | false | Match description strings/annotations if true, otherwise ignore them |
| Boolean | mergeDescription | false | Keep description string/annotations from the old equation if true |
Outputs
| Type | Name | Default | Description |
|---|---|---|---|
| Boolean | success | true if any equation was updated, otherwise false |