Skip to content

Instantly share code, notes, and snippets.

@jgphilpott
Last active May 16, 2023 20:16
Show Gist options
  • Save jgphilpott/f859fc640abffc70d385925b98a1a8b0 to your computer and use it in GitHub Desktop.
Save jgphilpott/f859fc640abffc70d385925b98a1a8b0 to your computer and use it in GitHub Desktop.
A collection of functions for converting between different units of pressure.
### Pressure Conversions ###
convertPressure =
bar: {}
pascal: {}
atmospheric: {}
psi: {}
torr: {}
### Bar Conversions ###
convertPressure.bar.bar = bar$bar = (bar) -> bar # Bars to Bars
convertPressure.bar.pascal = bar$pas = (bar) -> bar * 1e+5 # Bars to Pascals
convertPressure.bar.atmospheric = bar$atm = (bar) -> bar / 1.01325 # Bars to Standard Atmospheric Pressure
convertPressure.bar.psi = bar$psi = (bar) -> bar * 14.503774 # Bars to Pounds per Square Inch
convertPressure.bar.torr = bar$tor = (bar) -> bar * 750.061682704 # Bars to Torrs
### Pascal Conversions ###
convertPressure.pascal.bar = pas$bar = (pas) -> pas / 1e+5 # Pascals to Bars
convertPressure.pascal.pascal = pas$pas = (pas) -> pas # Pascals to Pascals
convertPressure.pascal.atmospheric = pas$atm = (pas) -> pas / 101325 # Pascals to Standard Atmospheric Pressure
convertPressure.pascal.psi = pas$psi = (pas) -> pas / 6894.7572932 # Pascals to Pounds per Square Inch
convertPressure.pascal.torr = pas$tor = (pas) -> pas / 133.32236842 # Pascals to Torrs
### Standard Atmospheric Pressure Conversions ###
convertPressure.atmospheric.bar = atm$bar = (atm) -> atm * 1.01325 # Standard Atmospheric Pressure to Bars
convertPressure.atmospheric.pascal = atm$pas = (atm) -> atm * 101325 # Standard Atmospheric Pressure to Pascals
convertPressure.atmospheric.atmospheric = atm$atm = (atm) -> atm # Standard Atmospheric Pressure to Standard Atmospheric Pressure
convertPressure.atmospheric.psi = atm$psi = (atm) -> atm * 14.695948775 # Standard Atmospheric Pressure to Pounds per Square Inch
convertPressure.atmospheric.torr = atm$tor = (atm) -> atm * 76e+1 # Standard Atmospheric Pressure to Torrs
### Pounds per Square Inch Conversions ###
convertPressure.psi.bar = psi$bar = (psi) -> psi / 14.503774 # Pounds per Square Inch to Bars
convertPressure.psi.pascal = psi$pas = (psi) -> psi * 6894.7572932 # Pounds per Square Inch to Pascals
convertPressure.psi.atmospheric = psi$atm = (psi) -> psi / 14.695948775 # Pounds per Square Inch to Standard Atmospheric Pressure
convertPressure.psi.psi = psi$psi = (psi) -> psi # Pounds per Square Inch to Pounds per Square Inch
convertPressure.psi.torr = psi$tor = (psi) -> psi * 51.714932572 # Pounds per Square Inch to Torrs
### Torr Conversions ###
convertPressure.torr.bar = tor$bar = (tor) -> tor / 750.061682704 # Torrs to Bars
convertPressure.torr.pascal = tor$pas = (tor) -> tor * 133.32236842 # Torrs to Pascals
convertPressure.torr.atmospheric = tor$atm = (tor) -> tor / 76e+1 # Torrs to Standard Atmospheric Pressure
convertPressure.torr.psi = tor$psi = (tor) -> tor / 51.714932572 # Torrs to Pounds per Square Inch
convertPressure.torr.torr = tor$tor = (tor) -> tor # Torrs to Torrs
/* Pressure Conversions */
var atm$atm, atm$bar, atm$pas, atm$psi, atm$tor, bar$atm, bar$bar, bar$pas, bar$psi, bar$tor, convertPressure, pas$atm, pas$bar, pas$pas, pas$psi, pas$tor, psi$atm, psi$bar, psi$pas, psi$psi, psi$tor, tor$atm, tor$bar, tor$pas, tor$psi, tor$tor;
convertPressure = {
bar: {},
pascal: {},
atmospheric: {},
psi: {},
torr: {}
};
/* Bar Conversions */
convertPressure.bar.bar = bar$bar = function(bar) {
return bar; // Bars to Bars
};
convertPressure.bar.pascal = bar$pas = function(bar) {
return bar * 1e+5; // Bars to Pascals
};
convertPressure.bar.atmospheric = bar$atm = function(bar) {
return bar / 1.01325; // Bars to Standard Atmospheric Pressure
};
convertPressure.bar.psi = bar$psi = function(bar) {
return bar * 14.503774; // Bars to Pounds per Square Inch
};
convertPressure.bar.torr = bar$tor = function(bar) {
return bar * 750.061682704; // Bars to Torrs
};
/* Pascal Conversions */
convertPressure.pascal.bar = pas$bar = function(pas) {
return pas / 1e+5; // Pascals to Bars
};
convertPressure.pascal.pascal = pas$pas = function(pas) {
return pas; // Pascals to Pascals
};
convertPressure.pascal.atmospheric = pas$atm = function(pas) {
return pas / 101325; // Pascals to Standard Atmospheric Pressure
};
convertPressure.pascal.psi = pas$psi = function(pas) {
return pas / 6894.7572932; // Pascals to Pounds per Square Inch
};
convertPressure.pascal.torr = pas$tor = function(pas) {
return pas / 133.32236842; // Pascals to Torrs
};
/* Standard Atmospheric Pressure Conversions */
convertPressure.atmospheric.bar = atm$bar = function(atm) {
return atm * 1.01325; // Standard Atmospheric Pressure to Bars
};
convertPressure.atmospheric.pascal = atm$pas = function(atm) {
return atm * 101325; // Standard Atmospheric Pressure to Pascals
};
convertPressure.atmospheric.atmospheric = atm$atm = function(atm) {
return atm; // Standard Atmospheric Pressure to Standard Atmospheric Pressure
};
convertPressure.atmospheric.psi = atm$psi = function(atm) {
return atm * 14.695948775; // Standard Atmospheric Pressure to Pounds per Square Inch
};
convertPressure.atmospheric.torr = atm$tor = function(atm) {
return atm * 76e+1; // Standard Atmospheric Pressure to Torrs
};
/* Pounds per Square Inch Conversions */
convertPressure.psi.bar = psi$bar = function(psi) {
return psi / 14.503774; // Pounds per Square Inch to Bars
};
convertPressure.psi.pascal = psi$pas = function(psi) {
return psi * 6894.7572932; // Pounds per Square Inch to Pascals
};
convertPressure.psi.atmospheric = psi$atm = function(psi) {
return psi / 14.695948775; // Pounds per Square Inch to Standard Atmospheric Pressure
};
convertPressure.psi.psi = psi$psi = function(psi) {
return psi; // Pounds per Square Inch to Pounds per Square Inch
};
convertPressure.psi.torr = psi$tor = function(psi) {
return psi * 51.714932572; // Pounds per Square Inch to Torrs
};
/* Torr Conversions */
convertPressure.torr.bar = tor$bar = function(tor) {
return tor / 750.061682704; // Torrs to Bars
};
convertPressure.torr.pascal = tor$pas = function(tor) {
return tor * 133.32236842; // Torrs to Pascals
};
convertPressure.torr.atmospheric = tor$atm = function(tor) {
return tor / 76e+1; // Torrs to Standard Atmospheric Pressure
};
convertPressure.torr.psi = tor$psi = function(tor) {
return tor / 51.714932572; // Torrs to Pounds per Square Inch
};
convertPressure.torr.torr = tor$tor = function(tor) {
return tor; // Torrs to Torrs
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment