Add sgnsqr external function f(X) = sgn(x)*x^2 #3622
+47
−9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: