An error of using multi-mode DAEs in Dymola

Viewed 249

I build a simple model in Dymola, using different equations during different periods, but it surprises me that Dymola could NOT handle this simple model. It seems the system is singular after index reduction.

My questions are:

  • Is this a usual question when using Modelica?
  • If so, how should I modify this model, I know when I replace the equation x=100 with der(x)=0, the model works fine, but I am wondering if there is a universal rule for more complicated cases. I would appreciate it if a detailed explanation provided.

Here is the code of the model:

    model ErrorWhenUsingIf
      Real x(start=100);
    equation 
      if time<=0.5 then
        x=100;
      else
       der(x)=5;
      end if;
    end ErrorWhenUsingIf;

The error message is :

Failed to evaluate model for ODE-Jacobian
Error: The following error was detected at time: 7.62939453125E-012
Error: Singular inconsistent scalar system for der(x) = ( -(if time <= 0.5 then x-100 else -5.0))/((if time <= 0.5 then 0.0 else 1.0)) = 8e-008/0
Solver will attempt to handle this problem.

Failed to evaluate model for ODE-Jacobian

enter image description here

2 Answers

The given model does not obey one of the current rules following the common typical straight-forward approach for realizing simulate-able / compilable Modelica models:

a model shall not change its differential index throughout the simulation

Realizing such models is not explicitly prevented by the actual version of Modelica language specification guide and there is nothing against realizing that.

Common simulation environments won't simulate apparently such a simple model, unless it is explicitly stated that multi-modes of DAEs are allowed.

Now going a bit into details, the differential index informally corresponds to the inherent degree of implicit / explicit dependencies among state variables. There are two ways a differential index can change throughout the simulation, a structural way or numerical way.

In the structural way, the model (similar to the given one) is stated in terms of several branches of equation systems. Each branch corresponds to a different differential index. In the given model, a branch corresponds to a linear equation while the other corresponds to a differential equation. A typical implementation of structural analysis would reveal that the model corresponds to an ODE system (which is not true for the first branch). My guess here is that the linear equation is submitted to the ODE solver. If we add a dummy differential equation outside the if condition such as der(z) = -1, the system will be simulated since the structural analysis is accidentally (semi-)correct.

If we are dealing with higher-index DAEs in different branches, we may get a numerically imprecise solution, since the index reduction is not seperately conducted for each possible branch. Applying the solver to a non-reduced DAE may cause a draft in the numerical solution since an implicit algebraic equation was not explicitly revealed in the resulting reduced equation that is passed to the solver.

In the numerical way there are cases where different values of model parameters lead to different differential indices (think about a parameter value that changes a sophisticated equation to a trivial one). Similarly, the differential index may change its value during simulation runtime. This type is difficult to capture using the common ways of treating higher-index differential equations.

The structural index:The common approach is to approximate the differential index using s.c. structural index: which is a graph-based representation of the equation system out of which the differential index can be approximated. An ODE system has a structural index 0 while a non-differential equation system has a structural index -1. Index reduction is conducted using a combination of Pantelides algorithm and dummy derivatives methods, cf. relevant literatures. Such graph-based methods don't capture the numerical aspects of a varying differential index that is not the same during a simulation or different values of parameters.

Multi-modes DAEs, resulting from both types, are subject to active research and there have been novel publications dealing with multimode DAEs, cf. Hilding Elmqvist' publications at Modelica conferences and journals among other related publications to multi-mode DAEs (As a note I am not identifying what is the best publication regarding this topic).

If there is a universal role to follow, then this would be that all branches of a model should have the same structural index (and ideally the same differential index during a simulation). In the former, the structural index can be easily approximated by the modeler for small models. For large models, it is beneficial if the simulation environment can dump information regarding the graph-based structure (i.e. computational graph) of a given model, its differential index, etc. In the later type, this is difficult for the modeler to capture. It is ideal if the simulation environment can dump such information regarding a numerically varying differential index.

This is related to the ongoing discussion of https://github.com/modelica/ModelicaSpecification/issues/2411, where (in Modelica Language Specification version 3.4) it is not specified if variable-structure models are legal or rather tool-specific or illegal. There are tools (and proof of concepts) with DAE solvers that can successfully simulate such models.

Related