Skip to content

Thermodynamics formulas implementation and user interface in Python for Numworks calculator

Notifications You must be signed in to change notification settings

matthiaszeller/python-calc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

python-calc

Implementation of Physics formulas and a convenient user interface for NumWorks calculator.

This project was motivated by the need to quickly perform redundant calculations of Heat and Mass transfer problems when solving them with paper, a pen and a calculator. In particular, the background theory is based on EPFL course ME-341. For theoretical details, refer to Fundamentals of heat and mass transfer. 6th ed, Frank P. Incropera.

For instance, the Churchill-Bernstein equation for convective heat transfer is used to approximate the dimensionless Nusselt number and thus estimate the average convection coefficient between two fluids in cross-flow around a cylinder. The formula is quiet cumbersome to type in a calculator:

where is the Nusselt number, the Reynolds number and the Prandtl number.

Designing a script running in the Numworks environment and that prompts the user for input variables would make the calculation of such formulas easy.

Design

The calculator has no file explorer, i.e. cannot use directories. It also have very few memory (see below) So we must reduce the amount of code as much as possible by designing an efficent wrapping of mathematical formulas.

To avoid loading too much instructions at once in the calculator, we separate the formulas in sections:

  • Utility functions: used by every other script
  • Linear interpolation (generic)
  • Linear interpolation of thermophysical properties of water (hard-coded data)
  • Linear interpolation of thermophysical properties of air (hard-coded data)
  • Equations for fins
  • Equations for convection (implicitly only free and forced convection)
  • Equations for the boiling part of convection
  • Equations for the condensation part of convection

The idea is to load only two scripts at once: the utility module and the script of interest.

User interaction

  1. The user chooses a script in the list of scripts on the calcultor
  2. The user runs the script
  3. The user is asked to choose which formula (of the loaded module) to use
  4. The user is prompted to enter values of the formula input variable
  5. Results are displayed

Function design

All functions implementing formulas calculations have no input and no output (in the Pythonic sense). The input/output is handled by the utility module, via the function pr (print) out and get_params. In particular:

  • pr(msg, maxlen=29): print some text that properly fits on screen
  • out(desc, val): print value of physical variable, handle scientific notation
  • get_params(lst): prompt the user for the values of the formula variables whose names are given in lst

In particular, functions that implement formulas should perform in order:

  1. Print the name of the equation and the context in which it is used with pr
  2. Prompt the user for the values of the input variables with get_param
  3. Perform calculations
  4. Output the result

Script format

Every script should follow this architecture:

  1. Load the utility module
  2. Set relevant functions that implement formulas (no input, no return)
    • Use utility.get_params to ask the user for the parameter values and load them in a python dictionnary
    • Try to use as few memory as possible
    • Output (numerical) results with utility.out
  3. Create an option map that will allow the user to choose a formula, the map is a python dictionnary (key = display message, value = reference to the corresponding function)
  4. The script ends with utility.choose_opt(optmap)

Specifications of calculator

https://www.numworks.com/specs/

  • Flash ROM: 8MB
  • Static RAM: 256KB

https://www.numworks.com/resources/engineering/software/

3.2 Working with limited memory

Our device has 256 KB of RAM. That’s very little memory by today’s standards. That being said, by writing code carefuly, a huge lot can be achieved in that space. After all, that’s 64 times more memory than the computer of the Apollo mission!

  • Stack memory: 32KB, all local variables + context of code execution
  • Heap memory: ??

About

Thermodynamics formulas implementation and user interface in Python for Numworks calculator

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published