Modelica Boolean variable in continuous time The Next CEO of Stack OverflowCalculate relative time in C#Which MySQL data type to use for storing boolean valuesHow to get the current time in PythonWhat do 'real', 'user' and 'sys' mean in the output of time(1)?Convert a Unix timestamp to time in JavaScriptUsing boolean values in CHow to declare and use boolean variables in shell script?Get current time and date on AndroidUsing coupled system of PDEs in modelicaNon-discrete assignments to integer variables
Is it a good idea to use COLUMN AS (left([Another_Column],(4)) instead of LEFT in the select?
Does it take more energy to get to Venus or to Mars?
Why doesn't a table tennis ball float on the surface? How do we calculate buoyancy here?
How to Reset Passwords on Multiple Websites Easily?
Inappropriate reference requests from Journal reviewers
Why is there a PLL in CPU?
Horror movie/show or scene where a horse creature opens its mouth really wide and devours a man in a stables
How can I open an app using Terminal?
Term for the "extreme-extension" version of a straw man fallacy?
Does the Brexit deal have to be agreed by both Houses?
Why here is plural "We went to the movies last night."
Whats the best way to handle refactoring a big file?
How to start emacs in "nothing" mode (`fundamental-mode`)
How do we know the LHC results are robust?
Why do professional authors make "consistency" mistakes? And how to avoid them?
Return the Closest Prime Number
Science fiction (dystopian) short story set after WWIII
If I blow insulation everywhere in my attic except the door trap, will heat escape through it?
What can we do to stop prior company from asking us questions?
How do I get the green key off the shelf in the Dobby level of Lego Harry Potter 2?
Implement the Thanos sorting algorithm
Unreliable Magic - Is it worth it?
Trouble understanding the speech of overseas colleagues
How to write papers efficiently when English isn't my first language?
Modelica Boolean variable in continuous time
The Next CEO of Stack OverflowCalculate relative time in C#Which MySQL data type to use for storing boolean valuesHow to get the current time in PythonWhat do 'real', 'user' and 'sys' mean in the output of time(1)?Convert a Unix timestamp to time in JavaScriptUsing boolean values in CHow to declare and use boolean variables in shell script?Get current time and date on AndroidUsing coupled system of PDEs in modelicaNon-discrete assignments to integer variables
The following Modelica model checks and simulates.
model boolCheck_OK1
Real a = sin(time);
Real b = cos(time);
Real c;
//protected
// Boolean isInReg = inRegionCheck(a, b);
equation
c = if inRegionCheck(a, b) then 1.3*a^b else 0.7*b^a;
end boolCheck_OK1;
The function inRegionCheck() returns a Boolean, here is a simplified version:
function inRegionCheck
input Real a;
input Real b;
output Boolean c;
algorithm
c := a>b;
end inRegionCheck;
In the actual code, the function has more inputs and a longer name and is several lines long and the same check is used several times, so for readability I would like to introduce an intermediate variable as shown in the commented protected section, but that results in an error "Non-real equation in continuous time are not legal".
Any suggestions for an elegant workaround?
time boolean modelica continuous
add a comment |
The following Modelica model checks and simulates.
model boolCheck_OK1
Real a = sin(time);
Real b = cos(time);
Real c;
//protected
// Boolean isInReg = inRegionCheck(a, b);
equation
c = if inRegionCheck(a, b) then 1.3*a^b else 0.7*b^a;
end boolCheck_OK1;
The function inRegionCheck() returns a Boolean, here is a simplified version:
function inRegionCheck
input Real a;
input Real b;
output Boolean c;
algorithm
c := a>b;
end inRegionCheck;
In the actual code, the function has more inputs and a longer name and is several lines long and the same check is used several times, so for readability I would like to introduce an intermediate variable as shown in the commented protected section, but that results in an error "Non-real equation in continuous time are not legal".
Any suggestions for an elegant workaround?
time boolean modelica continuous
add a comment |
The following Modelica model checks and simulates.
model boolCheck_OK1
Real a = sin(time);
Real b = cos(time);
Real c;
//protected
// Boolean isInReg = inRegionCheck(a, b);
equation
c = if inRegionCheck(a, b) then 1.3*a^b else 0.7*b^a;
end boolCheck_OK1;
The function inRegionCheck() returns a Boolean, here is a simplified version:
function inRegionCheck
input Real a;
input Real b;
output Boolean c;
algorithm
c := a>b;
end inRegionCheck;
In the actual code, the function has more inputs and a longer name and is several lines long and the same check is used several times, so for readability I would like to introduce an intermediate variable as shown in the commented protected section, but that results in an error "Non-real equation in continuous time are not legal".
Any suggestions for an elegant workaround?
time boolean modelica continuous
The following Modelica model checks and simulates.
model boolCheck_OK1
Real a = sin(time);
Real b = cos(time);
Real c;
//protected
// Boolean isInReg = inRegionCheck(a, b);
equation
c = if inRegionCheck(a, b) then 1.3*a^b else 0.7*b^a;
end boolCheck_OK1;
The function inRegionCheck() returns a Boolean, here is a simplified version:
function inRegionCheck
input Real a;
input Real b;
output Boolean c;
algorithm
c := a>b;
end inRegionCheck;
In the actual code, the function has more inputs and a longer name and is several lines long and the same check is used several times, so for readability I would like to introduce an intermediate variable as shown in the commented protected section, but that results in an error "Non-real equation in continuous time are not legal".
Any suggestions for an elegant workaround?
time boolean modelica continuous
time boolean modelica continuous
asked Mar 8 at 12:49
matthmatth
1,26311234
1,26311234
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Works in SimulationX (with protected Boolean variable isInReg) if the function inRegionCheck is annotated by annotation(GenerateEvents=true);
. In Dymola, you need to set annotation(Inline=true,GenerateEvents=true);
to make it working.
Nice. Didn't know about the GenerateEvents annotation. The Modelica Reference package does not contain it. But it links to trac.modelica.org/Modelica/ticket/1048 and says that it was removed in Modelica 3.2 rev2!?
– marco
Mar 12 at 6:39
2
Note that Modelica 3.2r2 was released after Modelica 3.3. GenerateEvents was first introduced in Modelica 3.3. When backporting features of Modelica 3.3 to Modelica 3.2r2 it was first considered, but later removed again. This is what github.com/modelica/ModelicaSpecification/issues/1048 is about. And since the ModelicaReference is based on Modelica 3.2r2 it is not yet there.
– tbeu
Mar 12 at 6:57
add a comment |
The function call introduces a noEvent
in your equation for isInReg
.
This is what Dymola 2019 FD01 reports if the boolean is used:
Non-real equation in continuous time are not legal:
isInReg = noEvent(a > b);
Hence, your equation reduces to
isInReg = noEvent(a > b)
which is not allowed, as boolean values can only change on events.
You have to get rid of the function call and thus the noEvent.
Maybe there is a better solution, but you could try to define the check in a block instead of a function. At least for your minimal example it works perfectly fine.
Then your code could look like this:
model boolCheck_OK1
Real a = sin(time);
Real b = cos(time);
Real c;
protected
InRegionCheck check(a=a, b=b);
Boolean isInReg=check.c;
equation
c = if isInReg then 1.3*a^b else 0.7*b^a;
end boolCheck_OK1;
block InRegionCheck
input Real a;
input Real b;
output Boolean c;
equation
c = a>b;
end InRegionCheck;
add a comment |
Based on the fact that there is no function to convert to boolean but only a block, i would suggest marco's answer is the way to go.
With a workaround you can still do it inside a function, but not with the type Boolean
. Instead use Real
and compare in the if-clause if it's greater zero. For showing the switching behaviour of the boolean this works fine. If you rely on the function and don't use the boolean too often, this could be an option.
model boolCheck_OK1
Real a = sin(time);
Real b = cos(time);
Real c;
function inRegionCheck
input Real a;
input Real b;
output Real c;
algorithm
c := if a>b then 1 else 0;
end inRegionCheck;
protected
Real isInReg = inRegionCheck(a, b);
equation
c = if inRegionCheck(a, b)>Modelica.Constants.eps then 1.3*a^b else 0.7*b^a;
end boolCheck_OK1;
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55063596%2fmodelica-boolean-variable-in-continuous-time%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Works in SimulationX (with protected Boolean variable isInReg) if the function inRegionCheck is annotated by annotation(GenerateEvents=true);
. In Dymola, you need to set annotation(Inline=true,GenerateEvents=true);
to make it working.
Nice. Didn't know about the GenerateEvents annotation. The Modelica Reference package does not contain it. But it links to trac.modelica.org/Modelica/ticket/1048 and says that it was removed in Modelica 3.2 rev2!?
– marco
Mar 12 at 6:39
2
Note that Modelica 3.2r2 was released after Modelica 3.3. GenerateEvents was first introduced in Modelica 3.3. When backporting features of Modelica 3.3 to Modelica 3.2r2 it was first considered, but later removed again. This is what github.com/modelica/ModelicaSpecification/issues/1048 is about. And since the ModelicaReference is based on Modelica 3.2r2 it is not yet there.
– tbeu
Mar 12 at 6:57
add a comment |
Works in SimulationX (with protected Boolean variable isInReg) if the function inRegionCheck is annotated by annotation(GenerateEvents=true);
. In Dymola, you need to set annotation(Inline=true,GenerateEvents=true);
to make it working.
Nice. Didn't know about the GenerateEvents annotation. The Modelica Reference package does not contain it. But it links to trac.modelica.org/Modelica/ticket/1048 and says that it was removed in Modelica 3.2 rev2!?
– marco
Mar 12 at 6:39
2
Note that Modelica 3.2r2 was released after Modelica 3.3. GenerateEvents was first introduced in Modelica 3.3. When backporting features of Modelica 3.3 to Modelica 3.2r2 it was first considered, but later removed again. This is what github.com/modelica/ModelicaSpecification/issues/1048 is about. And since the ModelicaReference is based on Modelica 3.2r2 it is not yet there.
– tbeu
Mar 12 at 6:57
add a comment |
Works in SimulationX (with protected Boolean variable isInReg) if the function inRegionCheck is annotated by annotation(GenerateEvents=true);
. In Dymola, you need to set annotation(Inline=true,GenerateEvents=true);
to make it working.
Works in SimulationX (with protected Boolean variable isInReg) if the function inRegionCheck is annotated by annotation(GenerateEvents=true);
. In Dymola, you need to set annotation(Inline=true,GenerateEvents=true);
to make it working.
answered Mar 11 at 10:58
tbeutbeu
42526
42526
Nice. Didn't know about the GenerateEvents annotation. The Modelica Reference package does not contain it. But it links to trac.modelica.org/Modelica/ticket/1048 and says that it was removed in Modelica 3.2 rev2!?
– marco
Mar 12 at 6:39
2
Note that Modelica 3.2r2 was released after Modelica 3.3. GenerateEvents was first introduced in Modelica 3.3. When backporting features of Modelica 3.3 to Modelica 3.2r2 it was first considered, but later removed again. This is what github.com/modelica/ModelicaSpecification/issues/1048 is about. And since the ModelicaReference is based on Modelica 3.2r2 it is not yet there.
– tbeu
Mar 12 at 6:57
add a comment |
Nice. Didn't know about the GenerateEvents annotation. The Modelica Reference package does not contain it. But it links to trac.modelica.org/Modelica/ticket/1048 and says that it was removed in Modelica 3.2 rev2!?
– marco
Mar 12 at 6:39
2
Note that Modelica 3.2r2 was released after Modelica 3.3. GenerateEvents was first introduced in Modelica 3.3. When backporting features of Modelica 3.3 to Modelica 3.2r2 it was first considered, but later removed again. This is what github.com/modelica/ModelicaSpecification/issues/1048 is about. And since the ModelicaReference is based on Modelica 3.2r2 it is not yet there.
– tbeu
Mar 12 at 6:57
Nice. Didn't know about the GenerateEvents annotation. The Modelica Reference package does not contain it. But it links to trac.modelica.org/Modelica/ticket/1048 and says that it was removed in Modelica 3.2 rev2!?
– marco
Mar 12 at 6:39
Nice. Didn't know about the GenerateEvents annotation. The Modelica Reference package does not contain it. But it links to trac.modelica.org/Modelica/ticket/1048 and says that it was removed in Modelica 3.2 rev2!?
– marco
Mar 12 at 6:39
2
2
Note that Modelica 3.2r2 was released after Modelica 3.3. GenerateEvents was first introduced in Modelica 3.3. When backporting features of Modelica 3.3 to Modelica 3.2r2 it was first considered, but later removed again. This is what github.com/modelica/ModelicaSpecification/issues/1048 is about. And since the ModelicaReference is based on Modelica 3.2r2 it is not yet there.
– tbeu
Mar 12 at 6:57
Note that Modelica 3.2r2 was released after Modelica 3.3. GenerateEvents was first introduced in Modelica 3.3. When backporting features of Modelica 3.3 to Modelica 3.2r2 it was first considered, but later removed again. This is what github.com/modelica/ModelicaSpecification/issues/1048 is about. And since the ModelicaReference is based on Modelica 3.2r2 it is not yet there.
– tbeu
Mar 12 at 6:57
add a comment |
The function call introduces a noEvent
in your equation for isInReg
.
This is what Dymola 2019 FD01 reports if the boolean is used:
Non-real equation in continuous time are not legal:
isInReg = noEvent(a > b);
Hence, your equation reduces to
isInReg = noEvent(a > b)
which is not allowed, as boolean values can only change on events.
You have to get rid of the function call and thus the noEvent.
Maybe there is a better solution, but you could try to define the check in a block instead of a function. At least for your minimal example it works perfectly fine.
Then your code could look like this:
model boolCheck_OK1
Real a = sin(time);
Real b = cos(time);
Real c;
protected
InRegionCheck check(a=a, b=b);
Boolean isInReg=check.c;
equation
c = if isInReg then 1.3*a^b else 0.7*b^a;
end boolCheck_OK1;
block InRegionCheck
input Real a;
input Real b;
output Boolean c;
equation
c = a>b;
end InRegionCheck;
add a comment |
The function call introduces a noEvent
in your equation for isInReg
.
This is what Dymola 2019 FD01 reports if the boolean is used:
Non-real equation in continuous time are not legal:
isInReg = noEvent(a > b);
Hence, your equation reduces to
isInReg = noEvent(a > b)
which is not allowed, as boolean values can only change on events.
You have to get rid of the function call and thus the noEvent.
Maybe there is a better solution, but you could try to define the check in a block instead of a function. At least for your minimal example it works perfectly fine.
Then your code could look like this:
model boolCheck_OK1
Real a = sin(time);
Real b = cos(time);
Real c;
protected
InRegionCheck check(a=a, b=b);
Boolean isInReg=check.c;
equation
c = if isInReg then 1.3*a^b else 0.7*b^a;
end boolCheck_OK1;
block InRegionCheck
input Real a;
input Real b;
output Boolean c;
equation
c = a>b;
end InRegionCheck;
add a comment |
The function call introduces a noEvent
in your equation for isInReg
.
This is what Dymola 2019 FD01 reports if the boolean is used:
Non-real equation in continuous time are not legal:
isInReg = noEvent(a > b);
Hence, your equation reduces to
isInReg = noEvent(a > b)
which is not allowed, as boolean values can only change on events.
You have to get rid of the function call and thus the noEvent.
Maybe there is a better solution, but you could try to define the check in a block instead of a function. At least for your minimal example it works perfectly fine.
Then your code could look like this:
model boolCheck_OK1
Real a = sin(time);
Real b = cos(time);
Real c;
protected
InRegionCheck check(a=a, b=b);
Boolean isInReg=check.c;
equation
c = if isInReg then 1.3*a^b else 0.7*b^a;
end boolCheck_OK1;
block InRegionCheck
input Real a;
input Real b;
output Boolean c;
equation
c = a>b;
end InRegionCheck;
The function call introduces a noEvent
in your equation for isInReg
.
This is what Dymola 2019 FD01 reports if the boolean is used:
Non-real equation in continuous time are not legal:
isInReg = noEvent(a > b);
Hence, your equation reduces to
isInReg = noEvent(a > b)
which is not allowed, as boolean values can only change on events.
You have to get rid of the function call and thus the noEvent.
Maybe there is a better solution, but you could try to define the check in a block instead of a function. At least for your minimal example it works perfectly fine.
Then your code could look like this:
model boolCheck_OK1
Real a = sin(time);
Real b = cos(time);
Real c;
protected
InRegionCheck check(a=a, b=b);
Boolean isInReg=check.c;
equation
c = if isInReg then 1.3*a^b else 0.7*b^a;
end boolCheck_OK1;
block InRegionCheck
input Real a;
input Real b;
output Boolean c;
equation
c = a>b;
end InRegionCheck;
edited Mar 8 at 13:58
answered Mar 8 at 13:31
marcomarco
922211
922211
add a comment |
add a comment |
Based on the fact that there is no function to convert to boolean but only a block, i would suggest marco's answer is the way to go.
With a workaround you can still do it inside a function, but not with the type Boolean
. Instead use Real
and compare in the if-clause if it's greater zero. For showing the switching behaviour of the boolean this works fine. If you rely on the function and don't use the boolean too often, this could be an option.
model boolCheck_OK1
Real a = sin(time);
Real b = cos(time);
Real c;
function inRegionCheck
input Real a;
input Real b;
output Real c;
algorithm
c := if a>b then 1 else 0;
end inRegionCheck;
protected
Real isInReg = inRegionCheck(a, b);
equation
c = if inRegionCheck(a, b)>Modelica.Constants.eps then 1.3*a^b else 0.7*b^a;
end boolCheck_OK1;
add a comment |
Based on the fact that there is no function to convert to boolean but only a block, i would suggest marco's answer is the way to go.
With a workaround you can still do it inside a function, but not with the type Boolean
. Instead use Real
and compare in the if-clause if it's greater zero. For showing the switching behaviour of the boolean this works fine. If you rely on the function and don't use the boolean too often, this could be an option.
model boolCheck_OK1
Real a = sin(time);
Real b = cos(time);
Real c;
function inRegionCheck
input Real a;
input Real b;
output Real c;
algorithm
c := if a>b then 1 else 0;
end inRegionCheck;
protected
Real isInReg = inRegionCheck(a, b);
equation
c = if inRegionCheck(a, b)>Modelica.Constants.eps then 1.3*a^b else 0.7*b^a;
end boolCheck_OK1;
add a comment |
Based on the fact that there is no function to convert to boolean but only a block, i would suggest marco's answer is the way to go.
With a workaround you can still do it inside a function, but not with the type Boolean
. Instead use Real
and compare in the if-clause if it's greater zero. For showing the switching behaviour of the boolean this works fine. If you rely on the function and don't use the boolean too often, this could be an option.
model boolCheck_OK1
Real a = sin(time);
Real b = cos(time);
Real c;
function inRegionCheck
input Real a;
input Real b;
output Real c;
algorithm
c := if a>b then 1 else 0;
end inRegionCheck;
protected
Real isInReg = inRegionCheck(a, b);
equation
c = if inRegionCheck(a, b)>Modelica.Constants.eps then 1.3*a^b else 0.7*b^a;
end boolCheck_OK1;
Based on the fact that there is no function to convert to boolean but only a block, i would suggest marco's answer is the way to go.
With a workaround you can still do it inside a function, but not with the type Boolean
. Instead use Real
and compare in the if-clause if it's greater zero. For showing the switching behaviour of the boolean this works fine. If you rely on the function and don't use the boolean too often, this could be an option.
model boolCheck_OK1
Real a = sin(time);
Real b = cos(time);
Real c;
function inRegionCheck
input Real a;
input Real b;
output Real c;
algorithm
c := if a>b then 1 else 0;
end inRegionCheck;
protected
Real isInReg = inRegionCheck(a, b);
equation
c = if inRegionCheck(a, b)>Modelica.Constants.eps then 1.3*a^b else 0.7*b^a;
end boolCheck_OK1;
answered Mar 11 at 8:55
f.wuef.wue
543413
543413
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55063596%2fmodelica-boolean-variable-in-continuous-time%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown