Skip to content

Latest commit

 

History

286 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Engineering-Solver

Is a tool for doing numerical calculations fast and easy. It includes units, thermodynamic properties and many more.

MainFigure

Quick start

Open this site Engineering-Solver.

Write a few statements like:

2+2
3 m to mm
3 m + 2 in to mm
force = 10 N
mass = 10 lb
acceleration = force / mass
acceleration to yard/s^2

You will notice you get instant results as you are typing your expressions.

Install and develop locally

Clone this repository and run the following command to install dependencies.

npm install

To run locally

npm run dev

To run the automated tests

npm test

To build

npm run build

Interface

The interface includes a document manager, an editor and output panel, plus a tab for each open document. Documents are saved automatically; use Download text to export the active document as a .txt file. The sidebar also includes an example selector, execution settings, and view/theme controls.

When switching documents, the output is cleared. With auto-run enabled, the active document runs automatically; with auto-run disabled, use Run now or Cmd/Ctrl+Enter to run it.

Output expressions are grouped by block, with separate highlighting for the current block and expression. Markdown between expressions remains in its original order, so it can split a block's output into multiple groups.

In the example selector you can find:

  • Numbers
  • Matrices
  • Objects
  • Variables
  • Units
  • Thermodynamic properties
  • Psychrometric properties

You can work with up to 20 open documents, and your progress will be saved automatically after a few seconds of inactivity.

Does all the calculations and unit conversions. Here are some useful topics from the docs.

Chemistry molar mass: MM()

To call this function use MM('H2O') and this will get an object with the data of the compound, including totalMass, number of atoms of each element, mass fraction for each element, etc. The formula can include a notation with parenthesis and dot notation for hydrates.

In:

borax = MM('Na2(B4O5(OH)4).8H2O');
borax.elements
borax.totalMass
borax.fraction
borax.fraction.Na

Out:

{"Na": 2, "B": 4, "O": 17, "H": 20}
381.37214 g / mol
{"Na": 0.12056344755545, "B": 0.11339055862864, "O": 0.71318738699686, "H": 0.052858606819051}
0.12056344755545

Uses the coolprop-wasm package to call PropsSI and HAPropsSI in a browser worker. Unit handling is done with MathJS, so the functions are not exactly the same as in CoolProp.

Fluid Properties: props()

In:

# Saturated vapor enthalpy [J/kg] of R134a at 25C
props('H', 'R134a', {T:25 celsius, Q:1})

Out: 4.1233395323186804e+5 J / kg

References

It can be useful to know what the phase of a given state point is.

In:

# Phase of Water at 1 atmosphere and 0% Quality
phase('Water', {P:1 atm, Q:0 %})

Out: twophase

In:

#Enthalpy (J per kg dry air) as a function of temperature, pressure,
#    and relative humidity at dry bulb temperature T of 25C, pressure
#    P of one atmosphere, relative humidity R of 50%
HAprops('H', {T:25 degC, P:1 atm, R:50%})

Out: 50423.45039102888 J / kg

CodeMirror is used for editing the mathjs code in the browser and includes:

  • Syntax Highlighting
  • Autocompletion
    • Functions
    • Physical Constants
    • Prefixed Units
    • Variables in Scope
  • Drag and Drop text documents
  • Other key bindings

Is used to do plots. Uses the main interface of plotly without many changes, but running first through mathjs simplifications.

Plot hello world example

plot([{x:1:5, y:2.^(1:5)}])

HelloWorldPlot

Plot functions

x = 0: pi/8: 2 pi;

plot([
  {x:x, y:sin(x), name:"sin"},
  {x:x, y:atan(x), name:"atan"}
])

Two traces plot

Plot advanced functions

sigma = 10;
beta = 2.7;
rho = 28;

lorenz(t, u) = 
  [ 
    sigma * (u[2] - u[1]),
    u[1] * (rho - u[3]) - u[2],
    u[1] * u[2] - beta * u[3]
  ];

sol = solveODE(lorenz, [0, 100], [1, 1, 1]);

plot(
 [{
    x: flatten(sol.y[:,1]),
    y: flatten(sol.y[:,2]),
    z: flatten(sol.y[:,3]),
    type: "scatter3d",
    mode: "lines"
}])

Lorenz Plot

Plot iso surfaces for TPMS

# Diamond

dx = pi/8;
Xlims = [0, 4pi];
X = Xlims[1]:dx:Xlims[2];
Y = reshape(X, [-1, 1]);
Z = reshape(X, [-1, 1, 1]);

diamond(x,y,z) = cos(x)cos(y)cos(z)-sin(x)sin(y)sin(z);

iso = map(X, Y, Z, _(x,y,z) = {x:x, y:y, z:z, v:diamond(x,y,z)});
iso = flatten(iso);

data = [
  {
    type: "isosurface",
    x: map(iso, _(point) = point.x),
    y: map(iso, _(point) = point.y),
    z: map(iso, _(point) = point.z),
    value: map(iso, _(point) = point.v),
    isomin: -1/16,
    isomax: 1/18,
  }
];

layout = ({
  margin: { t: 0, l: 0, b: 0 },
  scene: {
    camera: {
      eye: {
        x: 1.88,
        y: -2.12,
        z: 0.96
      }
    }
  }
});

plot(data, layout)

TPMS

Chaos game

# # Chaos game
#. Configure to use Arrays
config({matrix:"Array"});

#. Define tetrahedron vertices
x = [cos(pi/6), 0, -cos(pi/6), 0];
y = [-sin(pi/6), 1, -sin(pi/6), 0];
z = [0, 0, 0, 1 + sin(pi/6)];

#. Initial point (could be random)
x.push(0); y.push(0); z.push(sin(pi/6));

#. Generate random sequence
randomPoints = randomInt([2000], 1, 5);

#. Midpoint between current point and random
rule(id) = [
  x.push((x[end] + x[id]) / 2),
  y.push((y[end] + y[id]) / 2),
  z.push((z[end] + z[id]) / 2),
];

#. Chaos game iterations
forEach(randomPoints, rule)

#. Plot
trace = {
  x: x, y: y, z: z,
  type: "scatter3d",
  mode: "markers",
  marker: { size: 1, color: z, colorscale: "Viridis" }
};

plot([trace])

Chaos game

Warnings

  • All calculations are done locally
  • There is no server saving your calculations
  • Don't run code that you don't trust