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

High level interface for numbers #75

Open
googhgoo opened this issue Jun 23, 2019 · 1 comment
Open

High level interface for numbers #75

googhgoo opened this issue Jun 23, 2019 · 1 comment
Labels
enhancement New feature or request

Comments

@googhgoo
Copy link
Member

googhgoo commented Jun 23, 2019

Instead of using python floats for variables (wavenumbers, energy, etc, ...), we can build a physical variable class. This class would automatically takes care of unit mismatch.
For example, we initialize energy quantity:

from pmutt import var
E = var(-6.77,'eV')
print(E)
-6.77 eV

and the class has orders of various unit type (mass, temperature, length, time...) as well as names

E.unitorders
[1,0,2,-2,0] # in the order of mass, temperature, length, time, quantity of molecules
E.unitnames
['ev','','ev','ev',''] # since eV is a lumped unit it all shows eV, but for nonlumped unit, it would show name of the unit for each unit type.

When we perform operation then these unit orders can be added and subtracted (for multiplication and division, respectively):

R = pmutt.constants.R('J/mol/K')
8.3145 J mol-1 K-1
R.unitnames
['J','K','J',','J','mol']
R.unitorders
[1,-1,2,-2,1]
T = var(32,'F')
print(T)
32 F
print(T.unitnames)
['','F','','','']
EoRT = E/R/T # unit mismatch automatically taken care of under the hood
print(EoRT.unitorders)
[0,0,0,0,0]

In above case, this var class would take care of unit mismatch automatically by comparing unitorders and unitnames between var. For what would get outputted in the class mismatch, we can set a class variable for what would be default unit. What we can additional do is, if we try to construct a statmech class:

pmutt.statmech.vib.HarmonicVib(vib_wavenumbers=[wave1,wave2])

Even if wave1 is not in the required unit cm-1, it can automatically also does conversion as well.
The current noninvasive variables should be kept, but this function can be additionally handled as a "high-level" language within pmutt which would help minimize mistakes in the unit conversions.

@googhgoo googhgoo added the enhancement New feature or request label Jun 23, 2019
@jonlym
Copy link
Member

jonlym commented Dec 26, 2019

Implemented VUnits, which has a generic Quantity class for arithmetic and logic operations. Under the hood, it converts inputted values to SI base quantities to simplify unit management. It also supports a variety of units and their prefixes (complete list here) and a unit parser to support compounded units.

Next steps will involve integrating VUnits into pMuTT.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants