Giter VIP home page Giter VIP logo

hansolsson / modelica_stategraph2 Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 3.0 1.43 MB

Free library providing components to model discrete event, reactive and hybrid systems in a convenient way with deterministic hierarchical state diagrams. Modelica_StateGraph2 is not fully Modelica compliant and might never be. For clocked system Modelica 3.3 introduced state machines, but for non-clocked systems this is still a good alternative.

Motoko 100.00%
modelica modelica-library

modelica_stategraph2's People

Contributors

hansolsson avatar martinotter avatar tobolar avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

modelica_stategraph2's Issues

Examples.Applications.ControlledTanks.ControlledTanks1 and 2 easily fail when refilling tank1

These two example models are very sensitive when tank1 is to be refilled about t = 521 s. The simulation may fail.

For example in Dymola 2020x, just changing the tolerance to 1e-5 results in a failed simulation with Dassl.

The problem is the energy balance when tank1 is empty.

A simple suggestion to avoid the problem in these examples would be to move the outlet ports slightly above 0. Then, tank1 will never be empty. Note that the example Modelica.Fluid.Examples.ControlledTankSystem.ControlledTanks uses the same tanks and avoids these problems by specifying in the controller that there should always be at least 1 cm of liquid in the tanks.

Replace Modelica.SIunits by Modelica.Units.SI hence StateGraph2 work with Modelica-nighlt building

Just simply test StateGraph2 with latest openmodelica nightly building package, to make it works , just to replace Modelica.SIunits by Modelica.Units.SI is enough.

--- package.mo.orig	2022-06-14 16:34:23.027300648 +0800
+++ package.mo	2022-06-14 16:36:14.488418483 +0800
@@ -3632,14 +3632,14 @@
         model TankController1
           "Controller 1 for tank system (using expressions to control the valves)"
           extends Modelica.Blocks.Interfaces.BlockIcon;
-          parameter Modelica.SIunits.Height limit1(min=0) = 0.98
+          parameter Modelica.Units.SI.Height limit1(min=0) = 0.98
             "Maximum level of tank 1";
-          parameter Modelica.SIunits.Height limit2(min=0) = 0.98
+          parameter Modelica.Units.SI.Height limit2(min=0) = 0.98
             "Maximum level of tank 2";
-          parameter Modelica.SIunits.Height minLevel(min=0) = 0.01
+          parameter Modelica.Units.SI.Height minLevel(min=0) = 0.01
             "Minimum fill level of a tank";
 
-          parameter Modelica.SIunits.Time waitTime=3
+          parameter Modelica.Units.SI.Time waitTime=3
             "Wait time to newly open a valve";
 
           Modelica.Blocks.Interfaces.BooleanInput start annotation (Placement(
@@ -4078,13 +4078,13 @@
         model TankController2
           "Controller 2 for tank system (using expressions to control the valves)"
           extends Modelica.Blocks.Interfaces.BlockIcon;
-          parameter Modelica.SIunits.Height limit1(min=0) = 0.98
+          parameter Modelica.Units.SI.Height limit1(min=0) = 0.98
             "Maximum level of tank 1";
-          parameter Modelica.SIunits.Height limit2(min=0) = 0.98
+          parameter Modelica.Units.SI.Height limit2(min=0) = 0.98
             "Maximum level of tank 2";
-          parameter Modelica.SIunits.Height minLevel(min=0) = 0.01
+          parameter Modelica.Units.SI.Height minLevel(min=0) = 0.01
             "Minimum fill level of a tank";
-          parameter Modelica.SIunits.Time waitTime=3
+          parameter Modelica.Units.SI.Time waitTime=3
             "Wait time to newly open a valve";
 
           Modelica_StateGraph2.Step stopStep1(nIn=1, nOut=2)
@@ -4312,13 +4312,13 @@
             final use_outPort=false,
             nEntry=1,
             nExit=1);
-          parameter Modelica.SIunits.Height limit1(min=0) = 0.98
+          parameter Modelica.Units.SI.Height limit1(min=0) = 0.98
             "Maximum level of tank 1";
-          parameter Modelica.SIunits.Height limit2(min=0) = 0.98
+          parameter Modelica.Units.SI.Height limit2(min=0) = 0.98
             "Maximum level of tank 2";
-          parameter Modelica.SIunits.Height minLevel(min=0) = 0.01
+          parameter Modelica.Units.SI.Height minLevel(min=0) = 0.01
             "Minimum fill level of a tank";
-          parameter Modelica.SIunits.Time waitTime=3
+          parameter Modelica.Units.SI.Time waitTime=3
             "Wait time to newly open a valve";
 
           SignalBus bus annotation (Placement(transformation(
@@ -4491,7 +4491,7 @@
             final use_outPort=true,
             final nEntry=2,
             final nExit=2);
-          parameter Modelica.SIunits.Height minLevel(min=0) = 0.01
+          parameter Modelica.Units.SI.Height minLevel(min=0) = 0.01
             "Minimum fill level of a tank";
 
           SignalBus bus annotation (Placement(transformation(
@@ -4602,8 +4602,8 @@
           Boolean start annotation (HideResult=false);
           Boolean stop annotation (HideResult=false);
           Boolean shut annotation (HideResult=false);
-          Modelica.SIunits.Length level1 annotation (HideResult=false);
-          Modelica.SIunits.Length level2 annotation (HideResult=false);
+          Modelica.Units.SI.Length level1 annotation (HideResult=false);
+          Modelica.Units.SI.Length level2 annotation (HideResult=false);
 
           annotation (Icon(graphics={Rectangle(
                             extent={{0,0},{0,0}},
@@ -12332,7 +12332,7 @@
     Evaluate=true,
     HideResult=true,
     choices(__Dymola_checkBox=true));
-  parameter Modelica.SIunits.Time waitTime=0
+  parameter Modelica.Units.SI.Time waitTime=0
     "Wait time before transition fires (> 0 required)"
     annotation (Dialog(enable=delayedTransition));
 
@@ -12369,8 +12369,8 @@
   output Boolean enableFire "= true, if firing condition is true";
 
 protected
-  constant Modelica.SIunits.Time minimumWaitTime=100*Modelica.Constants.eps;
-  Modelica.SIunits.Time t_start
+  constant Modelica.Units.SI.Time minimumWaitTime=100*Modelica.Constants.eps;
+  Modelica.Units.SI.Time t_start
     "Time instant at which the transition would fire, if waitTime would be zero";
   Modelica.Blocks.Interfaces.BooleanInput localCondition;
 initial equation
@@ -12589,7 +12589,7 @@
     "Fire condition (time varying Boolean expression)"
     annotation (Dialog(enable=not use_conditionPort));
 
-  parameter Modelica.SIunits.Time waitTime(min=1e-8) = 0.001
+  parameter Modelica.Units.SI.Time waitTime(min=1e-8) = 0.001
     "Time to wait in internal step after transition fired";
 
   Modelica_StateGraph2.Internal.Interfaces.Transition_in inPort
@@ -13337,11 +13337,11 @@
     block OnDelay
       "Delay a rising edge of the input, but do not delay a falling edge."
       extends Interfaces.PartialBooleanSISO;
-      parameter Modelica.SIunits.Time delayTime "Delay time";
+      parameter Modelica.Units.SI.Time delayTime "Delay time";
 
     protected
       Boolean delaySignal(start=false, fixed=true);
-      discrete Modelica.SIunits.Time t_next;
+      discrete Modelica.Units.SI.Time t_next;
     initial equation
       pre(u) = false;
       pre(t_next) = time - 1;
@@ -13850,7 +13850,7 @@
 
     block RadioButtonSource "Boolean signal source that mimis a radio button"
 
-      parameter Modelica.SIunits.Time buttonTimeTable[:]
+      parameter Modelica.Units.SI.Time buttonTimeTable[:]
         "Time instants where button is pressed";
       input Boolean reset[:]={false}
         "Reset button to false, if an element of reset becomes true"
@@ -14385,7 +14385,7 @@
         choices(__Dymola_checkBox=true));
       input Boolean guard=true "y not changing, if guard=false (time varying)"
         annotation (Dialog(group="Other options", enable=use_guard));
-      parameter Modelica.SIunits.Time samplePeriod=0
+      parameter Modelica.Units.SI.Time samplePeriod=0
         "Sample period if active=true (only temporarily)"
         annotation (Dialog(group="Other options", enable=active));

OpenModelica fails with StateGraph2.Transition

I filed a bug report at OpenModelica, getting the comment from Adrian Pop:
The error message in the new front-end is correct. The line reads:
{{{#!mo
Connections.branch(inPort[i].node, node);
}}}
which is not according to the Modelica Specification because {{{node}}} is
not of the form {{{connectorName.overconstrainedRecord}}}. One would need
to put the node inside a connector and use that to make it correct. Or the
Modelica spec needs changing.

Transition Issue when startTime not equal to zero

In the Modelica_StateGraph2.Transition component, there is the following code:

initial equation 
  pre(enableFire) = false;
  if delayedTransition then
    pre(t_start) = 0;
  end if;

As far as I can tell, the equation should be pre(t_start) = time; (not 0), otherwise when startTime != 0, the following fire condition check is wrong: fire = enableFire and time >= t_start + waitTime;

Note that in StateGraph1, the equivalent code is correct as far as I can tell and the issues i'm seeing aren't present:

initial equation 
  pre(t_start) = time;
  pre(enableFire) = false;

Illegal tag for StateGraph2 v2.0.3

Reported by dietmarw on 12 Apr 2016 12:58 UTC
I was just about to sync the GitHub mirror with the latest release of the StateGraph2 library when I noticed that it contains the non-defined versionBuild=0. This should be changed to versionBuild=1 and then re-tagged. Ideally simply v2.0.3 (i.e., no +build since that really is not necessary and just adds noise to the name).

The old tag should simply be removed.


Migrated-From: https://trac.modelica.org/Modelica/ticket/1983

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.