-
Notifications
You must be signed in to change notification settings - Fork 93
Units Conversion #91
Hello everyone,
I'm writing this post mainly to gather feedback — both from users and developers — regarding the possibility of supporting SI metric units within the code.
As things stand, the pyCycle source code is written almost exclusively using imperial units, and, to the best of my knowledge, there is no straightforward way to produce output in SI units without implementing a wrapper that performs the conversion downstream.
This post is not meant to spark a debate over which unit system is preferable, but simply to highlight the fact that, as of now, pyCycle does not allow for an easy switch between the two systems.
I strongly believe that both the code and the community would benefit greatly from addressing this limitation, for several reasons:
-
Native support for the metric system would make the code significantly more accessible and could greatly expand the community, with all the long-term advantages this would entail.
-
The current implementation of imperial units is, in my opinion, questionable (though I’m open to discussion on this point). Conversion factors are hard-coded directly into the equations, which results in, for instance, many partial derivatives in the Jacobians being cluttered with unit conversion constants — reducing both the elegance and readability of the code.
Compressor jacobian
Even when speaking with U.S.-based companies — typically more inclined toward imperial units — there was a shared perception that relying on a unit-dependent tool constitutes a limitation and is not considered best practice. -
What I find even more paradoxical is that OpenMDAO already provides symbolic unit conversion capabilities by default. As a result, pyCycle can generally handle metric inputs without major issues. However, since there is no way to specify the units of the outputs, the results are always returned in imperial units. By directly modifying the source code, it is possible to force pyCycle to produce output in SI units fairly easily, but the ideal solution would be to allow the user to specify the desired unit system and obtain dynamically adapted outputs.
I’m convinced that improving the code’s architecture in this direction is entirely feasible, but I’d really like to hear the opinion of those with more experience with the pyCycle codebase.
All reactions
Replies: 1 comment 1 reply
Hi @Pietro-Colonna,
I share your pain with the units. This is probably the first questions I asked myself when running pycycle for the first time: what units are these results in?
I started to look at it in more details and I have the following answers for you:
- for inputs you can specify the units using the functions
prob.set_input_defaults('DESIGN.Nmech', 8070.0, units='rpm')
prob.set_val('DESIGN.fc.alt', 00, units='m')
-
for results, you cannot get the unit by using the short dictionnary version:
prob['DESIGN.fc.alt']
but you can access a directly converted value using get_val ->prob.get_val('DESIGN.fc.alt',units='m') -
to learn what are the default units, I spent some time searching for it on openmdao forums and all the solutions were found there
full_name is the parameter you are looking for the unit
this command will give you the units: prob.model.get_io_metadata(iotypes=('input','output'))[prom_name_to_abs[full_name]]['units']
this command did not work for few of the typical parameters shown in the viewer because some of them were promoted variables: the workaround is to create a dictionary from promoted to absolute names (prom_name_to_abs)
prom_name_to_abs = {meta['prom_name']: abs_name for abs_name, meta in prob.model.get_io_metadata(iotypes=('input', 'output')).items()}
I created a version of the viewers that adds the units in the output
and I also modified the functions in viewers.py to output into specified units
I got stuck with the compressor and turbine maps and got sidetracked.
maybe someone can point me towards a guide on how to push my version of the viewers to the repo and get it accepted? maybe @Kenneth-T-Moore
hope this helps
Cheers
Benoit
All reactions
Hi Benoit, to create a pull request (PR), you need to fork the pycycle repo to your own github account, then you your repo, do the changes and from there create the PR. See this link