Foam TRise
Quick Start
To be written
Credits
To be written
Foam T-Rise
K mW/mK
Tlo °C
Thi °C
h mm
ρ kg/m³
Cp J/kg.K
Probe1 mm
Probe2 mm
tmax s
Plus/Minus
Tdata °C
Data T s
tdata s
Data t °C
//One universal basic required here to get things going once loaded
window.onload = function () {
//restoreDefaultValues(); //Un-comment this if you want to start with defaults
Main();
};
//Main() is hard wired as THE place to start calculating when inputs change
//It does no calculations itself, it merely sets them up, sends off variables, gets results and, if necessary, plots them.
function Main() {
//Save settings every time you calculate, so they're always ready on a reload
saveSettings();
//Send all the inputs as a structured object
//If you need to convert to, say, SI units, do it here!
const inputs = {
K: sliders.SlideK.value / 1000,//mW to W
Tlo: sliders.SlideTlo.value,
Thi: sliders.SlideThi.value,
rho: sliders.Sliderho.value,
Cp: sliders.SlideCp.value,
h: sliders.Slideh.value / 1000, //mm to m
Probe1: sliders.SlideProbe1.value / 1000, //from mm to m
Probe2: sliders.SlideProbe2.value / 1000, //from mm to m
tmax: sliders.Slidetmax.value,
tdata: sliders.Slidetdata.value,
dataT: sliders.SlidedataT.value,
PlusMinus: sliders.SlidePlusMinus.value,
Floating: true // document.getElementById('Floating').checked,
};
//Send inputs off to CalcIt where the names are instantly available
//Get all the resonses as an object, result
//console.time("Calc")
const result = CalcIt(inputs)
// console.timeEnd("Calc")
//Set all the text box outputs
document.getElementById('Data').value = result.Data;
document.getElementById('DataT').value = result.DataT;
// document.getElementById('Solid').value = result.sInfo;
//Do all relevant plots by calling plotIt - if there's no plot, nothing happens
//plotIt is part of the app infrastructure in app.new.js
if (result.plots) {
for (let i = 0; i < result.plots.length; i++) {
plotIt(result.plots[i], result.canvas[i]);
}
}
//You might have some other stuff to do here, but for most apps that's it for Main!
}
//Here's the app calculation
//The inputs are just the names provided - their order in the curly brackets is unimportant!
//By convention the input values are provided with the correct units within Main
function CalcIt({ K, Tlo, Thi, rho, Cp, h, Probe1, Probe2, tmax, tdata, dataT, PlusMinus, Floating }) {
let Data = "", DataT = "Undefined"
const KmW = K * 1000
const D = K / (rho * Cp)
const tstep = 0.025, nsteps = Math.max(50, Math.floor(50 * h * 1000 / 10)), hstep = h / nsteps, hstep2 = hstep * hstep
let tmp = [], t = [], plotProbe1 = [], plotProbe1Minus = [], plotProbe1Plus = [], plotProbe2 = [], plotProbe2Minus = [], plotProbe2Plus = []
const pProbe1 = Math.floor(nsteps * Probe1 / h), pProbe2 = Math.floor(nsteps * Probe2 / h)
let i = 0
t[0] = Thi
for (i = 1; i < nsteps; i++) {
t[i] = Tlo
}
t[nsteps] = Tlo
tcount = 0
DPM = []
DPM[0] = (K - PlusMinus / 1000) / (rho * Cp)
DPM[1] = D
DPM[2] = (K + PlusMinus / 1000) / (rho * Cp)
if (PlusMinus > 0) { PMS = 0; PME = 3 } else { PMS = 1; PME = 2 }
const tdata0 = tdata
let tread = [], readT = [0,0,0,0,0,0]
for (let PM = PMS; PM < PME; PM++) {
TooHot = false
for (time = 0; time < tmax; time += tstep) {
for (i = 1; i < nsteps; i++) {
tmp[i] = t[i] + (t[i - 1] - 2 * t[i] + t[i + 1]) * DPM[PM] * tstep / hstep2
}
if (Floating) {
t[nsteps] += (t[nsteps - 1] - t[nsteps]) * DPM[PM] * tstep / hstep2
}
for (i = 1; i < nsteps; i++) {
t[i] = tmp[i]
}
tcount += 1
if (tcount > 50) { //Don't want to plot too much
tcount = 0
if (PM == 0) plotProbe1Minus.push({ x: time, y: t[pProbe1] })
if (PM == 1) plotProbe1.push({ x: time, y: t[pProbe1] })
if (PM == 2) plotProbe1Plus.push({ x: time, y: t[pProbe1] })
if (PM == 0) plotProbe2Minus.push({ x: time, y: t[pProbe2] })
if (PM == 1) plotProbe2.push({ x: time, y: t[pProbe2] })
if (PM == 2) plotProbe2Plus.push({ x: time, y: t[pProbe2] })
if (time >= tdata) {
tdata = 9999 //One off!
if (PM == 0) tread.push(t[pProbe1])
if (PM == 1) tread.push(t[pProbe1])
if (PM == 2) tread.push(t[pProbe1])
if (PM == 0) tread.push(t[pProbe2])
if (PM == 1) tread.push(t[pProbe2])
if (PM == 2) tread.push(t[pProbe2])
}
if (t[pProbe1] >= dataT) {
if (PM == 0 && readT[2]==0) readT[2]=time
if (PM == 1 && readT[1]==0) readT[1]=time
if (PM == 2 && readT[0]==0) readT[0]=time
}
if (t[pProbe2] >= dataT) {
if (PM == 0 && readT[5]==0) readT[5]=time
if (PM == 1 && readT[4]==0) readT[4]=time
if (PM == 2 && readT[3]==0) readT[3]=time
}
if (t[nsteps] > Tlo + 1) break //Exact ΔT not critical
}
}
tdata = tdata0
for (i = 1; i <= nsteps; i++) {
t[i] = Tlo
}
}
try {
if (tread.length == 2 && tread[1] == undefined) Data = tread[0].toFixed(1)
if (tread.length == 2 && tread[1] != undefined) Data = tread[0].toFixed(1) + " " + tread[1].toFixed(1) + " Δ= " + (tread[0] - tread[1]).toFixed(1)
if (tread.length == 6 && tread[1] == undefined) Data = "1=" + tread[2].toFixed(1) + " Δ1=" + (tread[4] - tread[0]).toFixed(1)
if (tread.length == 6 && tread[1] != undefined) Data = "1=" + tread[2].toFixed(1) + " 2=" + tread[3].toFixed(1) + " Δ1=" + (tread[4] - tread[0]).toFixed(1) + " Δ2=" + (tread[5] - tread[1]).toFixed(1)
} catch { Data = "Undefined" }
if (Math.max(...readT)>0){
DataT=""
for (let i=0;i 0) DataT+=readT[i].toFixed(1)
}
}
// try {
// if (readT.length == 2 && readT[1] == undefined) DataT = readT[0].toFixed(1)
// if (readT.length == 2 && readT[1] != undefined) DataT = readT[0].toFixed(1) + " " + readT[1].toFixed(1) + " Δ= " + (readT[0] - readT[1]).toFixed(1)
// if (readT.length == 6 && readT[1] == undefined) DataT = "1=" + readT[2].toFixed(1) + " Δ1=" + (readT[4] - readT[0]).toFixed(1)
// if (readT.length == 6 && readT[1] != undefined) DataT = "1=" + readT[2].toFixed(1) + " 2=" + readT[3].toFixed(1) + " Δ1=" + (readT[4] - readT[0]).toFixed(1) + " Δ2=" + (readT[5] - readT[1]).toFixed(1)
// } catch { DataT = "Undefined" }
let plotData = [plotProbe1, plotProbe2]
let lineLabels = [(Probe1 * 1000).toFixed(1) + "mm", (Probe2 * 1000).toFixed(1) + "mm"]
let myColors = ["red", "blue"]
const P1 = (Probe1 * 1000).toFixed() + "mm: ", P2 = (Probe2 * 1000).toFixed() + "mm: "
if (PlusMinus > 0) {
plotData = [plotProbe1Minus, plotProbe1, plotProbe1Plus, plotProbe2Minus, plotProbe2, plotProbe2Plus]
lineLabels = [P1 + (KmW - PlusMinus).toFixed(1), P1 + (KmW).toFixed(1), P1 + (KmW + PlusMinus).toFixed(1), P2 + (KmW - PlusMinus).toFixed(1), P2 + (KmW).toFixed(1), P2 + (KmW + PlusMinus).toFixed(1)]
myColors = ["magenta", "cyan", "red", "blue", "orange", "green"]
}
//Now set up all the graphing data detail by detail.
const prmap = {
plotData: plotData, //An array of 1 or more datasets
lineLabels: lineLabels, //An array of labels for each dataset
colors: myColors, //An array of colors for each dataset
hideLegend: false,
borderWidth: [2, 2, 2, 2, 2, 2],
xLabel: 't&s', //Label for the x axis, with an & to separate the units
yLabel: 'T&°C', //Label for the y axis, with an & to separate the units
y2Label: null, //Label for the y2 axis, null if not needed
yAxisL1R2: [], //Array to say which axis each dataset goes on. Blank=Left=1
logX: false, //Is the x-axis in log form?
xTicks: undefined,
logY: false, //Is the y-axis in log form?
yTicks: undefined, //We can define a tick function if we're being fancy
legendPosition: 'top', //Where we want the legend - top, bottom, left, right
xMinMax: [,], //Set min and max, e.g. [-10,100], leave one or both blank for auto
yMinMax: [,], //Set min and max, e.g. [-10,100], leave one or both blank for auto
y2MinMax: [,], //Set min and max, e.g. [-10,100], leave one or both blank for auto
xSigFigs: 'F1', //These are the sig figs for the Tooltip readout. A wide choice!
ySigFigs: 'F1', //F for Fixed, P for Precision, E for exponential
};
//Now we return everything - text boxes, plot and the name of the canvas, which is 'canvas' for a single plot
return {
plots: [prmap],
canvas: ['canvas'],
Data: Data,
DataT: DataT,
};
}
To be written