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

physics.units - dimensional analysis/nondimensionalization addition #20832

Open
cheind opened this issue Jan 20, 2021 · 8 comments
Open

physics.units - dimensional analysis/nondimensionalization addition #20832

cheind opened this issue Jan 20, 2021 · 8 comments
Labels
physics.units Units and dimensions physics

Comments

@cheind
Copy link

cheind commented Jan 20, 2021

Hey!

I have developed a prototype Python package that deals with physical dimensional analysis:

https://github.com/cheind/sympy-nondim

In particular, sympy-nondim calculates from an unknown relation of (dimensional) variables, a new relation of (usually fewer) dimensionless variables.

While dimensional analysis seems to be part of sympy.physics, it seems such a particular application of it is missing. Hence I wanted to know whether there is potential interest in having this as an addition to sympy.physics?

@asmeurer
Copy link
Member

CC @Upabjojr

@Upabjojr
Copy link
Contributor

Hence I wanted to know whether there is potential interest in having this as an addition to sympy.physics?

Yes, improvements are welcome. Especially, if the code gets included into SymPy, it's more likely that people will notice it.

One only thing about nondim, do you assume the SI unit system per default? The current goal is to make sympy.physics.units independent of any unit system (users should choose which unit system to use, either SI, cgs, gauss, natural units or others). The choice of the unit system may change the behavior of dimensional analysis.

@cheind
Copy link
Author

cheind commented Jan 27, 2021

One only thing about nondim, do you assume the SI unit system per default?

Yes and no. The current implementation takes a units.DimensionalSystem as optional input. If not specified, it targets si.dimsys_default. As far as I understood the implementation, all relations between dimensions are stored in units.DimensionalSystem and not in Dimension itself. As you said, dimensional analysis results will change dependending on the dimensional system used, but the current implementation should be able to cope with this already.

I would also like to discuss the current interface of nondim. Currently it takes an sympy.Equation[Symbol, Function[Sequence[Symbol]] as input. It uses the information to infer dependent and independent variables which are used for 'smart' output processing. The output of the current implementation depends on the number of pi-groups found and whether the dependent variable appears in zero/one/more than one of those groups. Internally, the function nondim calls pi_groups which does all the heavy computation. The function is agnostic to dependent/independent variables and returns just a list of pi-factors.

@Upabjojr
Copy link
Contributor

As far as I understood the implementation, all relations between dimensions are stored in units.DimensionalSystem and not in Dimension itself.

Yes, we have moved to dimension systems in order to make the implementation independent of SI. At the beginning SI was assumed by default, but that was a bad design because it limits the potential applicability of this module. Moving away from SI is not yet 100% complete, I would also like to make it mandatory to declare the unit system you use, instead of assuming a default unit system.

I would also like to discuss the current interface of nondim. Currently it takes an sympy.Equation[Symbol, Function[Sequence[Symbol]] as input. It uses the information to infer dependent and independent variables which are used for 'smart' output processing. The output of the current implementation depends on the number of pi-groups found and whether the dependent variable appears in zero/one/more than one of those groups. Internally, the function nondim calls pi_groups which does all the heavy computation. The function is agnostic to dependent/independent variables and returns just a list of pi-factors.

Wouldn't it be simpler to declare the exponent variables and solve for those? Instead of

eq = sympy.Eq(t, sympy.Function('f')(m,l,g,theta))

what about:

a1, a2, a3, a4 = symbols("a1:5")
eq = sympy.Eq(i, m**a1*l**a2*g**a3*theta**a4)

and then solving for the a 's?

I'm also interested in expanding the units module by adding support for cross-unit system conversions. For example, you have a formula expressed in natural units and would like to get the equivalent in SI units, how do you convert that? That could be useful.

@sidhu1012
Copy link
Contributor

I'm also interested in expanding the units module by adding support for cross-unit system conversions. For example, you have a formula expressed in natural units and would like to get the equivalent in SI units, how do you convert that? That could be useful.

This could be very helpful. It's a nice idea to be implemented.

@cheind
Copy link
Author

cheind commented Jan 28, 2021

@Upabjojr Francesco, thanks for your input.

what about:
a1, a2, a3, a4 = symbols("a1:5")
eq = sympy.Eq(i, ma1*la2g**a3theta**a4)

Are you referring to API of nondimensionalization or how it should be implemented internally?

If it concerns the API. As I understood the pi-theoreom: every dimensional homogeneous equation
$f(x,y,z...)=0$, can be equivalently be written as another unknown function of dimensionless variable products $g(\pi_1, \pi_2,...)=0.$ If I understand your suggestion correctly, your solution would yield the pi-factors in terms of N values for each of the exponents of the original variables. This may disguise the fact that you are still actually searching for a function of these products. I believe your API is semantically equivalent to what the function pi_groups in my code does, but with a different syntax.

Moving away from SI is not yet 100% complete
Yes, I believe I have encountered such an issue. You can call Dimension.get_dimensional_dependencies which will try to resolve the base-dimensions using the default units system. I've tried to overcome this limitations by creating a free function that is passed the dimensional system:

https://github.com/cheind/sympy-nondim/blob/develop/nondim/utils.py

Also, utils adds a utility method to quickly create a dimensional system with new derived dimensions, as I didn't find an easy way to add new 'named' derived dimensions using the official API. I'm using it in these tests

https://github.com/cheind/sympy-nondim/blob/develop/nondim/tests/test_buckpi.py

@Maelstrom6 Maelstrom6 added physics physics.units Units and dimensions labels Feb 2, 2021
@jzy3d
Copy link

jzy3d commented Sep 9, 2022

Looks great! Did this finally reached the official Sympy distribution?

@cheind
Copy link
Author

cheind commented Sep 12, 2022

Hey @jzy3d,

no I did not find the time to start integration towards sympy. In case you are interested, please feel free to take the lead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
physics.units Units and dimensions physics
Projects
None yet
Development

No branches or pull requests

6 participants