Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace if statement with if expression in smoothTransition #1019

Closed
dhblum opened this issue Sep 12, 2018 · 2 comments
Closed

Replace if statement with if expression in smoothTransition #1019

dhblum opened this issue Sep 12, 2018 · 2 comments

Comments

@dhblum
Copy link
Contributor

dhblum commented Sep 12, 2018

I was wondering if the following if statement in the function IBPSA.Utilities.Math.Functions.BaseClasses.smoothTransition could be replaced by the suggested if expression? This would allow its use in JModelica optimization for MPC. Namely, the model IBPSA.Fluid.MixingVolumes.BaseClasses.PartialMixingVolume if the parameter prescribedHeatFlowRate = true.

from:

algorithm 
 aX:= abs(x);
 y := a + aX*(b + aX*(c + aX*(d + aX*(e + aX*f))));
 if x < 0 then
    y := -y;
 end if;

to:

algorithm 
 aX:= abs(x);
 y := if x >= 0 then a + aX*(b + aX*(c + aX*(d + aX*(e + aX*f)))) else 
 -(a + aX*(b + aX*(c + aX*(d + aX*(e + aX*f)))));

I could submit a pull request.

@Mathadon
Copy link
Member

Mathadon commented Sep 12, 2018

fine by me, although this would require fewer operations in CasADi:

algorithm 
 aX:= abs(x);
 y := (if x >= 0 then 1 else -1) * (a + aX*(b + aX*(c + aX*(d + aX*(e + aX*f)))));

@dhblum
Copy link
Contributor Author

dhblum commented Sep 12, 2018

Sounds good, that works too.

@mwetter mwetter closed this as completed Sep 14, 2018
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

No branches or pull requests

3 participants