{"id":16917954,"url":"https://github.com/dvd101x/web-thermodynamics","last_synced_at":"2025-04-12T22:20:39.751Z","repository":{"id":116532974,"uuid":"443159070","full_name":"dvd101x/web-thermodynamics","owner":"dvd101x","description":"This is a simple example of how to run CoolProp Javascript wrapper with Units handled by mathjs","archived":false,"fork":false,"pushed_at":"2025-01-08T16:23:10.000Z","size":6961,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-06T15:15:06.810Z","etag":null,"topics":["ashrae","calculator-javascript","coolprop","dew-point","engineering","humidity","hvac","javascript","mathjs","moist-air","physics","psychrometrics","relative-humidity","thermodynamic-calculations","thermodynamic-properties"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dvd101x.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-12-30T18:49:23.000Z","updated_at":"2025-01-08T16:22:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"d009f52c-59b9-4618-b42e-7a0b6b502e47","html_url":"https://github.com/dvd101x/web-thermodynamics","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvd101x%2Fweb-thermodynamics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvd101x%2Fweb-thermodynamics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvd101x%2Fweb-thermodynamics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvd101x%2Fweb-thermodynamics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dvd101x","download_url":"https://codeload.github.com/dvd101x/web-thermodynamics/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248638435,"owners_count":21137663,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ashrae","calculator-javascript","coolprop","dew-point","engineering","humidity","hvac","javascript","mathjs","moist-air","physics","psychrometrics","relative-humidity","thermodynamic-calculations","thermodynamic-properties"],"created_at":"2024-10-13T19:38:22.235Z","updated_at":"2025-04-12T22:20:39.718Z","avatar_url":"https://github.com/dvd101x.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Web Thermodynamics\n\nThis is an example of how to run CoolProp Javascript wrapper with units handled by mathjs, including a code editor.\n\n[![interface](interface.png)](https://dvd101x.github.io/web-thermodynamics/\n)\n\n# Getting started\n\nClone this repository and run the following command to install dependencies.\n```\nnpm install\n```\nTo test run\n```\nnpm run dev\n````\nTo build \n````\nnpm run build\n````\n \n# Basic example\n\nIt loads with three example expressions for each of the CoolProp functions available:\n\n* *Density* of **nitrogen** at a *temperature* **25 °C** and a *pressure* **1 atmosphere**: `props('D', 'Nitrogen', {T:25 degC, P:1 atm})`\n  ```\n  1.1452448929367 kg / m^3\n  ```\n* *Phase* of **water** at a *pressure* of **1 atmosphere** and **0%** *Quality*: `phase('Water', {P:1 atm, Q: 0 %})`\n  ```\n  twophase\n  ```\n* *Enthalpy* $[\\frac{J}{kg_{dry\\ air}}]$ as a function of *temperature*, *pressure* and *relative humidity* at STP `HAprops('H', {T: 25 degC, P:1 atm, R:90 %})`\n  ```\n  50423.450391029 J / kg\n  ```\n\nOn this example we mix the outputs with **markdown** and equations with **latex** if we start the comment with a `# ` this is a nice way to make present the results including some input markdown.\n\n# Getting started\n\nOpen this link:\n\nhttps://dvd101x.github.io/web-thermodynamics/\n\n# How does it work\n\n```mermaid\nflowchart LR\n    Start((Start)) --\u003e Code[Write Problem]\n    Thermo[Thermodynamic Properties]--\u003eMath[Evaluate Math]\n    Code --\u003e Math\n    Math--\u003eRender[Render Report]\n    Code --\u003e Markdown\n    Latex --\u003e Markdown\n    Markdown --\u003e Render\n```\n\n\n# Intermediate example\n\nThis demo uses libraries with many capabilities. There are many conversions available for inputs and outputs and the results can be stored on variables, arrays and objects to be used later.\n\n``` python\n# Density of carbon dioxide at 100 bar and 25C in lbm/in^3\nrho = props('D', 'CO2', {T:25 degC, P:100 bar}) in lbm/in^3\n\n# Saturated vapor enthalpy [J/kg] of R134a at 25C\nenthalpy = props('H', 'R134a', {T:25 celsius, Q:100%})\n\n# Enthalpy (J per kg dry air) as a function of temperature, pressure, \n#    and relative humidity at STP\nenthalpyDry = HAprops('H', {T:298.15 K, P:101325 Pa, R:0.5})\n\n# Create an array with empty objects\ncycle = [{},{}];\n\n# Temperature of saturated air at the previous enthalpy\ncycle[1].T = HAprops('T', {P:1 atm, H:enthalpyDry, R:1.0})\n\n# Temperature of saturated air in Fahrenheit\ncycle[2].T = HAprops('T', {H:enthalpyDry, R:1.0, P:1 atm}) to degF\n\n```\nShall return:\n```javascript\n0.029538663149234 lbm / in^3\n4.1233395323187e+5 J / kg\n50423.450391029 J / kg\n290.96209246917 K\n64.0617664445 degF\n[17.812092469167 degC, 17.812092469167 degC]\n```\n\n# Advanced examples\n\nIt can solve many other problems based con [CoolProp High Level API documentation](http://www.coolprop.org/coolprop/HighLevelAPI.html#high-level-api):\n\n```python\n# Saturation temperature of Water at 1 atm in K\nprops('T', 'Water', {P:101325 Pa, Q: 0})\n\n# Saturated vapor enthalpy of Water at 1 atm in J/kg\nH_V = props('H', 'Water', {P:101325 Pa, Q: 1})\n\n# Saturated liquid enthalpy of Water at 1 atm in J/kg\nH_L = props('H', 'Water', {P:101325 Pa, Q: 0})\n\n# Latent heat of vaporization of Water at 1 atm in J/kg\nH_V - H_L\n# Get the density of Water at T = 461.1 K and P = 5.0e6 Pa, imposing the liquid phase\nprops('D', 'Water', {'T|liquid':461.1 K, P: 5e6 Pa})\n\n# Get the density of Water at T = 597.9 K and P = 5.0e6 Pa, imposing the gas phase\nprops('D', 'Water', {T:597.9 K, 'P|gas': 5e6 Pa})\n\n# You can call the props function directly using an empty object:\nprops('Tcrit', 'Water', {})\n\n# It can be useful to know what the phase of a given state point is\nphase('Water', {P:101325 Pa, Q:0})\n\n# The phase index (as floating point number) can also be obtained using the props function:\nprops('Phase', 'Water', {P:101325 Pa, Q: 0})\n\n# c_p using c_p\nprops('C', 'Water', {P:101325 Pa, T: 300 K})\n\n# c_p using derivate\nprops('d(Hmass)/d(T)|P', 'Water', {P:101325 Pa, T: 300 K})\n\n# c_p using second partial derivative\nprops('d(d(Hmass)/d(T)|P)/d(Hmass)|P', 'Water', {P:101325 Pa, T: 300 K})\n```\nShall return\n```javascript\n373.12429584768 K\n2.6755293255007e+6 J / kg\n4.1905773309408e+5 J / kg\n2.2564715924067e+6 J / kg\n881.00085333474 kg / m^3\n20.50849607058 kg / m^3\n647.096 K\ntwophase\n6\n4180.6357765552 J / (kg K)\n4180.6357765552 J / (kg K)\n-7.7679894680327e-5 (J kg) / (kg K J)\n```\n\nThese concepts can be used to calculate complete thermodynamic cycles.\n\n``` python\n# # Vapor compression cycle\n# Specifies all states of a typical vapor compression cycle\n\n# ## Inputs\n# \n# Fluid and mass flow\nfluid = 'R134a'\nmDot  = 1 kg/minute\n\n# Component data\nevap  = {T: -20 degC, P_drop: 0 Pa, superHeating: 10 K}\ncond  = {T:  40 degC, P_drop: 0 Pa, subCooling  : 10 K}\netaS  = 0.75\n\n# ## Process\n\n#- Define an empty array to add the cycle steps\nc = [];\n\n#- Make a function for this specific fluid\np(desiredProperty, currentState) = props(desiredProperty, fluid, currentState);\n\n#- Define low and high pressure\npLow  = p('P', {'T|gas': evap.T, Q: 100%});\npHigh = p('P', {'T|liquid': cond.T, Q: 0%  });\n\n# 4 to 1 Evaporation\nc[1] = {};\nc[1].P = pLow;\nc[1].T = evap.T+ evap.superHeating;\nc[1].D = p('D', {'T|gas':c[1].T, P:c[1].P});\nc[1].H = p('H', {'T|gas':c[1].T, P:c[1].P});\nc[1].S = p('S', {'T|gas':c[1].T, P:c[1].P});\nc[1]\n\n# 1 to 2 Compression of vapor\nc[2] = {};\nc[2].P = pHigh;\nH_i        = p('H',{P:c[2].P, S:c[1].S});\nc[2].H = (H_i-c[1].H)/etaS + c[1].H;\nc[2].T = p('T', c[2]);\nc[2].D = p('D', c[2]);\nc[2].S = p('S', c[2]);\nc[2]\n\n# 2 to 3 Condensation\nc[3] = {};\nc[3].P = c[2].P - cond.P_drop;\nc[3].T = cond.T-cond.subCooling;\nc[3].D = p('D', {'T|liquid':c[3].T, P:c[3].P});\nc[3].H = p('H', {'T|liquid':c[3].T, P:c[3].P});\nc[3].S = p('S', {'T|liquid':c[3].T, P:c[3].P});\nc[3]\n\n# 3 to 4 Expansion\nc[4] = {};\nc[4].H = c[3].H;\nc[4].P = c[1].P + evap.P_drop;\nc[4].T = p('T', c[4]);\nc[4].D = p('D', c[4]);\nc[4].S = p('S', c[4]);\nc[4]\n\n# ## Work, Energy and Performance\n# $W_{comp}$\nW_comp   = mDot*(c[2].H - c[1].H)\n\n# $Q_h$\nQ_h      = mDot*(c[2].H - c[3].H)\n# $Q_c$\nQ_c      = mDot*(c[1].H - c[4].H)\n\n# $COP_{evaporator}$\nevap_COP = Q_c/W_comp\n\n# $COP_{condenser}$\ncond_COP = Q_h/W_comp\n\n# # Final results\n\nprint('Compressor power   : $1 \\t$2\\t$3', W_comp to [W, BTU/h, TR], 4)\nprint('Condenser heat out : $1 \\t$2\\t$3', Q_h    to [W, BTU/h, TR], 4)\nprint('Evaporator heat in : $1 \\t$2\\t$3', Q_c    to [W, BTU/h, TR], 4)\n\nprint('COP(cooling)       : $1', [evap_COP], 3)\nprint('COP(heating)       : $1', [cond_COP], 3)\n```\nShall return:\n\n``` javascript\nR134a\n1 kg / minute\n{\"T\": -20 degC, \"P_drop\": 0 Pa, \"superHeating\": 10 K}\n{\"T\": 40 degC, \"P_drop\": 0 Pa, \"subCooling\": 10 K}\n0.75\nCompressor power   : 992.1 W \t3385 BTU / h\t0.2821 TR\nCondenser heat out : 3542 W \t12090 BTU / h\t1.007 TR\nEvaporator heat in : 2550 W \t8701 BTU / h\t0.7251 TR\nCOP(cooling)       : 2.57\nCOP(heating)       : 3.57\n```\n\n# Additional features\n\nHere is a similar project [Engineering-Solver](https://github.com/dvd101x/Engineering-Solver) that includes additional features:\n\n* Saves in the browser (you can continue where you left off)\n* 20 workspaces, so you can try different things\n* Uses a webworker to avoid freezing during big calculations\n* A few more examples focused on the many features of mathjs\n\n# Dependencies\n\nUses the following js libraries\n\n* Calculations\n  * [Mathjs](https://mathjs.org/)\n  * [CoolProp](http://www.coolprop.org/)\n* Editing\n  * [CodeMirror](https://codemirror.net/)\n* Rendering results\n  * [Markdown-it](https://github.com/markdown-it/markdown-it)\n  * [markdown-it-katex](https://github.com/waylonflinn/markdown-it-katex)\n  * [katex](https://katex.org/)\n  * [alpinejs](https://alpinejs.dev/)\n\n# References\n\n* [Example of fluid properties function **props** and **phase**](http://coolprop.sourceforge.net/coolprop/HighLevelAPI.html#high-level-api)\n* [List of fluids](http://coolprop.sourceforge.net/fluid_properties/PurePseudoPure.html#list-of-fluids)\n* [List of fluid properties](http://www.coolprop.org/coolprop/HighLevelAPI.html#table-of-string-inputs-to-propssi-function)\n* [Example of psychrometric function **HAprops**](http://coolprop.sourceforge.net/fluid_properties/HumidAir.html#sample-hapropssi-code)\n* [List of psychometric properties](http://coolprop.sourceforge.net/fluid_properties/HumidAir.html#table-of-inputs-outputs-to-hapropssi)\n* [List of units](https://mathjs.org/docs/datatypes/units.html#reference)\n* [List of extra functions](https://mathjs.org/docs/reference/functions.html)\n* [Syntax](https://mathjs.org/docs/expressions/syntax.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdvd101x%2Fweb-thermodynamics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdvd101x%2Fweb-thermodynamics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdvd101x%2Fweb-thermodynamics/lists"}