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

AdditionalSqrt #4396

Merged
merged 3 commits into from
Jul 5, 2024
Merged

AdditionalSqrt #4396

merged 3 commits into from
Jul 5, 2024

Conversation

HansOlsson
Copy link
Contributor

Follow-up to #4358
Making it a draft PR in case there is more missing.

@HansOlsson HansOlsson marked this pull request as ready for review April 24, 2024 10:04
@HansOlsson HansOlsson added L: Complex* Issue addresses Complex, Modelica.ComplexBlocks or Modelica.ComplexMath L: Media Issue addresses Modelica.Media labels Apr 24, 2024
@henrikt-ma
Copy link
Contributor

Here are some regexp search results, including matches both in code and documentation:

  • \^[ ]*[-]?[ ]*0.5 : 58 matches
  • \^[ ]*[-]?[ ]*\([ ]*1[ ]*/[ ]*2[ ]*\) : 18 matches

Many of these are not in documentation, and I'm wondering if there could be any cases where raising to 0.5 is more correct than using sqrt?

@HansOlsson
Copy link
Contributor Author

HansOlsson commented Apr 25, 2024

Will recheck.
For the 2nd regexp in terms of unit-checking most don't seem to matter:

  • Modelica.Media.Water.IF97_Utilities.BaseIF97.Transport.cond_dTp: lambdaREL0 := TREL^(1/2)*sum(a[i]*TREL^(i - 1) for i in 1:4); Where TREL has unit 1
  • Modelica.Thermal.HeatTransfer.Components.Convection documentation Nu = 0.453*Re^(1/2)*Pr^(1/3);
  • Modelica.Media.IdealGases.Common.MixtureGasNasa.gasMixtureViscosity (8*(1 + M[i]/M[j]))^(1/2)
  • Modelica.Fluid.Dissipation.Utilities.SharedDocumentation.HeatTransfer.Channel.kc_evenGapLaminar Nu_3 = [2/(1+22*Pr)]^(1/6)*(Re*Pr*d_hyd/L)^(1/2) documentation-class
  • Modelica.Fluid.Dissipation.HeatTransfer.StraightPipe.kc_laminar_KC(Re*IN_con.d_hyd/IN_con.L)^(1/2)- which has unit 1.

The following seem more concerning - but involve other exponents as well so should probably be a separate PR:

  • Modelica.Media.IdealGases.Common.MixtureGasNasa.lowPressureThermalConductivity but there are lots of other unit-issues as well including other exponents.
  • Modelica.Media.IdealGases.Common.MixtureGasNasa.mixtureViscosityChung all kinds of exponents

Remaining are: documentation, or combined with other fractional exponents.
@HansOlsson
Copy link
Contributor Author

Have now gone through all of them, the remaining ones are:

  • Documentation
  • Part of class with other non-integer exponents as well. To me the minor benefit of having sqrt(x) instead of x^0.5 is outweighed by the confusion caused by mixing sqrt(x) and x^(1/3)

Modelica/Fluid/Dissipation.mo Outdated Show resolved Hide resolved
@maltelenz maltelenz dismissed their stale review May 2, 2024 07:10

The obvious thing I noticed was fixed, but I do not have enough background to give an actual approving review. Dismissing my change request.

@casella
Copy link
Contributor

casella commented Jun 22, 2024

@HansOlsson would you suggest some other reviewers to get this through?

@HansOlsson
Copy link
Contributor Author

@HansOlsson would you suggest some other reviewers to get this through?

I believe you can review it, as some are part of media and possibly @AHaumer as it relates to complex numbers.

@casella casella self-requested a review July 2, 2024 21:02
@casella
Copy link
Contributor

casella commented Jul 2, 2024

I have no strong opinion about this, I need to think about it.

@MartinOtter
Copy link
Member

I have no strong opinion about this, I need to think about it.

In general sqrt(x) should be preferred over x^0.5 (assuming both are directly mapped to the corresponding C-expressions):

  • If x^0.5 is mapped to pow(x,0.5), then sqrt(x) is a specialized algorithm that is more efficient, might have better precision, and most CPUs have even dedicated square root instructions.
  • Readability is better - it is much clearer that the computation is a square root computation

Copy link
Contributor

@casella casella left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@HansOlsson HansOlsson merged commit ea28ae3 into modelica:master Jul 5, 2024
2 checks passed
@HansOlsson HansOlsson deleted the AdditionalSqrt branch July 5, 2024 14:24
@Esther-Devakirubai
Copy link
Contributor

@casella Can this be backported to maint/4.1.0? No milestone either.

@casella
Copy link
Contributor

casella commented Jul 31, 2024

@casella Can this be backported to maint/4.1.0? No milestone either.

Given @HansOlsson's comment, you can do that. It's not critical but it doesn't harm.

@Esther-Devakirubai
Copy link
Contributor

Esther-Devakirubai commented Aug 16, 2024

Backporting this to maintenance branch by #4452

@beutlich beutlich added this to the maintenance milestone Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L: Complex* Issue addresses Complex, Modelica.ComplexBlocks or Modelica.ComplexMath L: Media Issue addresses Modelica.Media
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants