Skip to content

Add implcit DAE dependencies and peterson example for implicit DAE - #75

Open
masoud-najafi wants to merge 12 commits into
mainfrom
implicit_dae
Open

masoud-najafi wants to merge 12 commits into
mainfrom
implicit_dae

Conversation

@masoud-najafi

Copy link
Copy Markdown
Contributor

Related Issues

Changes

Checklist

@elmir-nahodovic elmir-nahodovic left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for writing this up! Please see my comments and suggestions below

Comment thread docs/3____layeredManifest.adoc Resolved
Comment thread docs/3____layeredManifest.adoc Resolved
Comment thread docs/3____layeredManifest.adoc Resolved
Comment thread docs/3____layeredManifest.adoc Resolved
Comment thread docs/3____layeredManifest.adoc Resolved
masoud-najafi and others added 6 commits November 9, 2026 12:29
Co-authored-by: Elmir Nahodovic <210350926+elmir-nahodovic@users.noreply.github.com>
Co-authored-by: Elmir Nahodovic <210350926+elmir-nahodovic@users.noreply.github.com>
Co-authored-by: Elmir Nahodovic <210350926+elmir-nahodovic@users.noreply.github.com>
Co-authored-by: Elmir Nahodovic <210350926+elmir-nahodovic@users.noreply.github.com>
Co-authored-by: Elmir Nahodovic <210350926+elmir-nahodovic@users.noreply.github.com>
@elmir-nahodovic

Copy link
Copy Markdown
Contributor

@masoud-najafi it seems you applied my suggested changes, but then you reverted some of the changes with commit 8abe5fe

do you want me to re-suggest the changes I proposed, or should I just commit them directly?

@masoud-najafi

Copy link
Copy Markdown
Contributor Author

@masoud-najafi it seems you applied my suggested changes, but then you reverted some of the changes with commit 8abe5fe

do you want me to re-suggest the changes I proposed, or should I just commit them directly?

wierd. go ahead.

* Clarify that derivatives of states that appear as knowns in the residual equations MUST NOT be declared as ContinuousStateDerivative elements in the ModelStructure, since a ContinuousStateDerivative is defined as an unknown and we can't have a variable being known and unknown at the same time
* Remove duplicated text
* Reformulate that states, derivatives, algebraic are treated as knowns if they appear as dependencies of residual equations
* Update dependenciesKind for implicit Roberts DAE
* Remove text on semi-explicit restriction
* Update to 1.0.0.alpha.2 everywhere

@elmir-nahodovic elmir-nahodovic left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some more updates to remove mention of semi-explicit as a restriction, and that we speak of alpha.2 in the main branch. In case users who read the dev version are not confused about whats in alpha.1 vs alpha.2

Otherwise it looks good to me now! Thanks @masoud-najafi

@AnHeuermann AnHeuermann added this to the Alpha-2 milestone Nov 13, 2026
@AnHeuermann AnHeuermann linked an issue Nov 13, 2026 that may be closed by this pull request
@AnHeuermann AnHeuermann removed this from the Alpha-2 milestone Nov 13, 2026

@AnHeuermann AnHeuermann left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch to move to v1.0.0-apha.2.

I like the option to have implicit formulation as well. Less work for me implementing this in my tool 😇

I did run @CodeRabbit on my machine to catch stuff like small typos. Instead it pointed out some inconsistencies we should have a look at.

Comment thread docs/2_2__mathematical_formulation.adoc Resolved
Comment thread docs/2_2__mathematical_formulation.adoc Resolved
All elements defined in the core standard (https://fmi-standard.org/docs/3.0.2/#Output[`<Output>`], https://fmi-standard.org/docs/3.0.2/#ContinuousStateDerivative[`<ContinuousStateDerivative>`], https://fmi-standard.org/docs/3.0.2/#ClockedState[`<ClockedState>`], https://fmi-standard.org/docs/3.0.2/#InitialUnknown[`<InitialUnknown>`], https://fmi-standard.org/docs/3.0.2/#EventIndicator[`<EventIndicator>`]) retain their existing semantics in this manifest, with the additions that:

* Each element's `dependencies` attribute may now also reference <<AlgebraicVariable, algebraic variables>>.
* Each element's `dependencies` attribute may now also reference <<AlgebraicVariable, algebraic variables>>. For an implicit DAE formulation the <<Residual>> could have a dependency on a https://fmi-standard.org/docs/3.0.2/#derivative[`derivative` of a state]. In this case the `derivative` of that state *must not* appear as a https://fmi-standard.org/docs/3.0.2/#ContinuousStateDerivative[`<ContinuousStateDerivative>`] element under the <<ModelStructure>> defined here.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

CodeRabbit review on a local checkout

Preserve the state-vector declaration for implicit states.

FMI 3.0.2 uses entries to identify continuous states and define their API order. This rule removes those entries for implicit derivatives. (fmi-standard.org)

Line 24 says that this manifest replaces the core ModelStructure. The new Robertson manifest consequently declares neither differential state through the inherited mechanism. Define how importers identify and order implicit states before prohibiting these entries. Keep state declaration separate from explicit derivative computation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do now know the best way to handle this. In my opinion if the derivatives are knowns in the implicit formulation, they should not appear as ModelStructure elements, since that is reserved for the unknowns of the model. @AnHeuermann you are right here that then the importer does not know the order of the derivatives and states.

Maybe we can include an element like the AlgebraicVariables for implicit DAEs, but for the derivatives or states, so that order is preserved. We should discuss this at the next meeting

(Or if someone has a good idea please commit one and we can discuss that at the meeting as well)

Comment thread docs/3____layeredManifest.adoc Resolved
@elmir-nahodovic

Copy link
Copy Markdown
Contributor

Thank you @AnHeuermann - although I usually don't like the way LLMs review - these comments are actually good and accurate. I will fix

* Splitting mathematical_formulation in headers semi-explicit, implicit and constraints
    * Defining index-1 for implicit DAEs
    * You can call fmi3Set on derivatives if implicit
* Clarifying that algebraic variables are variables that appear as knowns and not differentiated in any unknown
* Updating partial derivative section for implicit that derivatives can appear as knowns
@elmir-nahodovic

elmir-nahodovic commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

@AnHeuermann @masoud-najafi I have now updated according to the points from CodeRabbit. I resolved the conversations that I think are resolved, please review again and check if it is more consistent now.

One point left: I don't know how we should handle the ordering for the API like fmi3GetContinuousStateDerivative. See my response to the "Preserve the state-vector declaration for implicit states." comment above

@masoud-najafi

Copy link
Copy Markdown
Contributor Author

Preserve the state-vector declaration for implicit states." comment above

The order of states in an ODE is determined by the order of the ContinuousStateDerivative elements in ModelStructure. We can preserve this ordering for the differential variables (i.e., they retain the same order as in the ODE), while ordering the algebraic variables according to their declaration order in the manifest file. Similarly, the residual vector follows the order in which the residuals are declared in the manifest file. Once this is finished, I wwould implement the implicit DAE to check if something else is required.

@elmir-nahodovic

Copy link
Copy Markdown
Contributor

The order of states in an ODE is determined by the order of the ContinuousStateDerivative elements in ModelStructure

I don't think this is the case in general for index-1 DAEs. The derivatives that appear in the implicit form and the derivatives that can be integrated in the semi-explicit form (or more directly the ODE form) don't have to be the same, depending on how the tool transforms the DAE. Say you start with the equations

0 = der(x1) + der(x2) + x1;
0 = x2 - x1^3;

This is an implicit index-1 DAE, and the der(x2) variable can be eliminated completely since der(x2) = 3x1^2 * der(x1), such that the exporter of the FMU has this as the ODE form:

 der(x1) = -x1 / (1 + 3x1^2);
// with solved residual x2 := x1^3;

(i.e. no der(x2) is declared as ContinuousStateDerivative)

but might have exported the implicit DAE as above:

0 = der(x1) + der(x2) + x1;
0 = x2 - x1^3;

I think this is what CodeRabbit meant with "Keep state declaration separate from explicit derivative computation"

@elmir-nahodovic

Copy link
Copy Markdown
Contributor

@masoud-najafi @AnHeuermann I think we can do as follows: The API for get/set continuous state derivatives are only allowed to be used for implicit DAEs if the FMU exposes these derivatives and states semi-explicitly through ContinuousStateDerivative elements (so a semi-implicit DAE ?). What I mean is that we must separate

  • what the FMU exposes for integration (ContinuousStateDeriavtive elements, these are the ones defining the fmi3GetContinuousStateDerivative API and ordering)
  • what the FMU exposes as derivatives of variables. This is the derivative attribute in the modelstructure and in implicit DAEs could be knowns of the residual elements

I added a commit for it but we can remove it if we have a better way of describing or doing this

@masoud-najafi

masoud-najafi commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

-- The variables with the derivative attribute are not necessirily listed in the modelStructure, we do not care about those that are not listed in the ModelStruture, in ls-DAE. The order of states (which is also the order of state-derivatives) is defined in the modelStrcuture. This order is essential to communicate with the FMU via state-related APIs.
-- It's a good idea to limit setStateDerivates to ImplicitDAE.

If new xsd files are provided, I can start convert my test FMUs to implicit DAE and testing them. That would help to validate and find possible issues of the implicit DAE cases.

@elmir-nahodovic

Copy link
Copy Markdown
Contributor

@masoud-najafi I am no xsd expert, but from what I can tell we don't need to change anything in the xsd, right? The xsd doesn't add any restrictions on the dependencies for the <Residual> element (i.e. that derivatives can be knowns for residuals), and I think that is the only practical change this pull request addresses for the xml

@elmir-nahodovic

Copy link
Copy Markdown
Contributor

After discussion on fmi-design in Munich, I am now more in favor of dropping support for implicit DAEs. Even though it is in principle not that complicated. We have to consider how it is combined with semi-explicit index 1 form, ode mode, and eventually initialization, event handling, higher index problems...

The problems/considerations we have now to support implicit DAEs:

  • the algebraic variables element must be augmented to provide which variables are to be treated as knowns
    • which in turn affects the partial derivatives
  • how to initialize the implicit DAE - impacting pr Specify initialization in DAE mode #72 which is already quite a big feature
  • the specification, since we would have to have parallel formulations throughout. Combine this with ODE mode and we are getting a very bloated standard

@HansOlsson

Copy link
Copy Markdown

Looking through the issue I noticed that it seems that one of reasons for why transforming from implicit DAE to explicit DAE was problematic:

State derivatives, which have a well-defined physical meaning, are reclassified as algebraic variables, requiring the importer to provide initial guesses for them as it would for ordinary algebraic variables.

I agree with the second part. However, there are examples of implicit DAE that have multiple solutions where you select the solution only based on the guesses of the state derivatives (the simplest would be $\dot{y}^2=y$ ). Thus, to me, I don't view that as argument for adding implicit DAEs - but more the opposite.

I now realized that "linearly implicit DAEs" would be an interesting option without that drawback (with constant mass-matrix or potentially a varying one).

As discussed at the meeting we might still add an example.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implicit index-1 DAE

4 participants