-
Notifications
You must be signed in to change notification settings - Fork 546
Add sgnsqr external function f(X) = sgn(x)*x^2 #3622
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
Conversation
Overall, I don't see a huge problem with supporting a library of useful external functions; however, some concerns with this implementation:
|
@jsiirola, I agree that if we decide that there are useful external functions we should add a new library. I was thinking that but then decided to see if I could get away with a short cut. The fact that the function isn't second order smooth is bothersome, but then again so is getting a solution with the wrong sign. I'm still not sure if this is a good idea or not. I know we could also do things with bounds and constraints, but I do a fair number of straight forward square simulations where bounds and constraints are harder to manage. |
I have a general question about this functionality: Would this even work with IPOPT currently, which is using the NL interface (via files) to communicate the problem? |
Yes. In fact, that is it's primary use case. It should also work with any other local nonlinear solver that accepts NL file inputs. |
Thanks, I was unaware of the possibility and we have that same expression in our models, actually. |
@eslickj, we discussed this at yesterday's dev call. The consensus was that we should move this to a separate contrib package. The package could host multiple ASL external libraries, and this should go into one that explicitly calls out that it is not a function in C2. We did not pick a name (although several were tossed around, like |
@jsiirola. thanks. I'll close this and open a new PR soon. |
Fixes None
Summary/Motivation:
This adds a signed square function to the contributed external function demonstration.
Here is an example of where this can be useful.
Say you have a pressure-flow relationship that says the mass flow is proportional to the square root of pressure drop, where pa is inlet pressure and pb is outlet pressure. Like this: mdot^2 = k(pb - pa).
The direction of flow is forward if the pressure drop is positive or backward if the pressure drop is negative. There are both positive and negative solutions to the equation. If we use the proposed sgnsqr function, there is now only one solution to the equation, and the sign of flow matches the sign of pressure drop.
The sign squared function is still smooth and replacing square with sgnsqr still gives us solutions to the original equation. It just limits us to one correct solution instead of two possibilities. I expect there could be many situations where it would be useful to limit the solutions of y = x^2 to a single solution.
Changes proposed in this PR:
Legal Acknowledgement
By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution: