From 47d6ead344097a72ea5cf0342222674b8b43a98d Mon Sep 17 00:00:00 2001 From: Robert Chen Date: Sun, 1 Dec 2013 16:34:07 -0800 Subject: [PATCH] updated model --- index.html | 2 +- js/main.js | 2 +- js/model.js | 305 +++++++++++++++++++++++++--------------------------- 3 files changed, 150 insertions(+), 159 deletions(-) diff --git a/index.html b/index.html index 5e1e89d..c297709 100755 --- a/index.html +++ b/index.html @@ -12,7 +12,7 @@ - + diff --git a/js/main.js b/js/main.js index add9849..e39bcab 100755 --- a/js/main.js +++ b/js/main.js @@ -1,6 +1,6 @@ // Robert- Here be dragons -var DEBUG = 1; +var DEBUG = 0; function GameState(){ var that = this; diff --git a/js/model.js b/js/model.js index a31dd8d..6629526 100755 --- a/js/model.js +++ b/js/model.js @@ -1,31 +1,20 @@ -function TurkeyLayer( name, percentRadius, turkeyModel, ovenModel ){ +function TurkeyLayer( name, layerNumber1, turkeyModel, ovenModel ){ var that = this; this.name = name; - this.percentRadius=percentRadius; - this.initialTemp = 20; + this.layerNumber=layerNumber1; this.waterLost = 0; this.finalTemperature = 20; - this.cookCondition = "Raw"; + this.cookCondition = "Raw"; return { updateTemperatureTick: function(){ - that.finalTemperature = UtilityFunctions.transientSphereSeries( turkeyModel.density, - turkeyModel.thermalConduct, - turkeyModel.heatConvection, - turkeyModel.cp, - percentRadius * turkeyModel.totalRadius, - turkeyModel.totalRadius, - that.initialTemp, - ovenModel.steadyTemp, - ovenModel.globalTime ); + that.finalTemperature = turkeyModel.globTemp[that.layerNumber] + console.log(turkeyModel.globTemp) that.waterLost = that.waterLost + UtilityFunctions.waterLoss( that.finalTemperature ); - that.cookCondition = UtilityFunctions.cookCondition(that.waterLost); - if(DEBUG) console.log( that.name + ": "+ that.waterLost + " " + that.cookCondition); + that.cookCondition = UtilityFunctions.cookCondition(that.waterLost, that.name); + if(DEBUG) console.log( that.name + ": "+ that.waterLost + " " + that.cookCondition + " " + that.finalTemperature + " C" ); }, - resetLayerTemps: function(){ - that.initialTemp = that.finalTemperature; - }, getCondition: function(){ return that.cookCondition; }, @@ -38,45 +27,71 @@ function TurkeyLayer( name, percentRadius, turkeyModel, ovenModel ){ function TurkeyModel( weight, ovenModel ){ - this.density = 1050; // kg/m3 Assuming Density of Water 1000 kg/m3 - this.cp = 2000; // 2810 J/kg K for Turkey. Extra is to semi-account for water evaporation energy + this.density = 700; // kg/m3 Assuming Density of Water 1000 kg/m3 + this.cp = 2810; // 2810 J/kg K for Turkey. Extra is to semi-account for water evaporation energy this.heatConvection = 9; // W/m2 K Some Reasonable estimate for natural Convection. Change as needed. 5-25 this.thermalConduct = 0.412; // W/m K // Chicken this.skin = {}; this.body = {}; this.core = {}; - - this.totalRadius = UtilityFunctions.calculateRadius( weight, this.density ); + this.splitsNum = 20; + console.log(UtilityFunctions.lbs2kgs(weight)) + this.totalRadius = UtilityFunctions.calculateRadius( UtilityFunctions.lbs2kgs(weight), this.density ); - this.totalLayers = [ new TurkeyLayer("Skin", 0.85, this, ovenModel ), - new TurkeyLayer("Body", 0.45, this, ovenModel ), - new TurkeyLayer("Core", 0.01, this, ovenModel ) ]; + this.totalLayers = [ new TurkeyLayer("Skin", this.splitsNum-1, this, ovenModel ), + new TurkeyLayer("Body", this.splitsNum-4, this, ovenModel ), + new TurkeyLayer("Core", 0, this, ovenModel ) ]; // Whenever temperature is changed - this.updateLayerTemps = function(){ + this.updateLayerTemps = function() { + this.globTemp = UtilityFunctions.transientSphereSeries( this.density, + this.thermalConduct, + this.heatConvection, + this.cp, + this.totalRadius, + ovenModel.tempInfini, + this.splitsNum, + this.deltar, + this.globTemp, + this.pointRadius + ); for (var i in this.totalLayers ){ this.totalLayers[i].updateTemperatureTick(); } }; - this.resetLayerTemps = function(){ - for (var i in this.totalLayers ){ + this.resetLayerTemps = function() { + for (var i in this.totalLayers ) { this.totalLayers[i].resetLayerTemps(); } }; + + //Sheen Model Stuff + this.globTemp=[]; + this.pointRadius = [] + this.splitsNum = 20; + this.deltar = this.totalRadius/this.splitsNum; //20 Data Points + + this.initializePoints = function() { + var step = ( this.totalRadius - this.deltar ) / ( this.splitsNum - 1 ); + for (var i = 0; ierrorTolerance ) { - if (this.steadyTimer>=80) { - //Reset the model's time calculation if there are major changes in the tolerance of the temperature or the steady timer expires - this.steadyTimer = 0; - this.globalTime = 0; - this.steadyTemp = this.tempInfini - turkey.resetLayerTemps(); - } return(true); } } @@ -134,19 +142,15 @@ function OvenModel( turkeyWeight, gameState ) { }, secondTick: function(){ that.globalTime = that.globalTime + 1; - that.steadyTimer = that.steadyTimer + 1; if ( that.equalizeTemp() ) { // Turn on oven light gameState.pubsub.publish( "OvenLight", "On" ); } else { - that.steadyTemp = that.tempInfini; // Turn off oven light gameState.pubsub.publish( "OvenLight", "Off" ); } - if(DEBUG) console.log("Steady Temp " + that.steadyTemp) - if(DEBUG) console.log("Steady Timer " + that.steadyTimer) if(DEBUG) console.log("Oven Temp " + that.tempInfini ) turkey.updateLayerTemps(); } @@ -179,26 +183,6 @@ UtilityFunctions = { return complexRadius; }, - findAllRoots: function(min,max,splitsNum,Biot) { - var step = ( max - min ) / ( splitsNum - 1 ); - var answer; - var negativeTest; - var storage = []; - for (var i = step; i < max; i=i+step ) { - negativeTest = this.lambdaFormula(i-step, Biot)*this.lambdaFormula(i, Biot); - if (negativeTest <= 0) { - answer = this.bisectionMethod(i-step,i,Biot); - if (answer !=undefined) { - storage.push(answer); - } - } - else { - //if(DEBUG) console.log("No Bracketed Root " + negativeTest) - } - } - return storage; - }, - sphereVolume: function(radius) { return((4/3)*Math.PI*Math.pow(radius,3)) }, @@ -207,74 +191,50 @@ UtilityFunctions = { return (Math.pow(10,(temperature-20)/80)-1) }, + transientSphereSeries: function( density, thermalConduct, heatConvection, cp, rTotal, tempInfinity, splitsNum, deltar, globTemp,pointRadius) { + +//Not Global Stuff + var r0 = rTotal; + var deltat = 0.1 + + var alpha = thermalConduct/(density*cp) + var h=heatConvection; + + for (var j=0; j<(1/deltat); j++ ) { + var dTdr=[] + // globTemp[splitsNum-1] should be last entry in globtemp + for (var k=0; k errorTolerance && antiFreeze<=500) { //The greater the antiFreeze, the more wasted cycles around a singularity - lambdaN = (min+max)/2 - result=this.lambdaFormula(lambdaN, Biot) - if (Math.abs(result) <= errorTolerance && result<=errorTolerance) { - return (lambdaN); //At Root - } - else if ((this.lambdaFormula(min, Biot)*this.lambdaFormula(lambdaN, Biot))>=0) { - min=lambdaN; - } - else if ((this.lambdaFormula(max, Biot)*this.lambdaFormula(lambdaN, Biot))>=0) { - max=lambdaN; - } - antiFreeze++ - } - } - }, - - lambdaFormula: function( lambdaN, Biot ) { - var result = 1-lambdaN*(1/Math.tan(lambdaN))-Biot; - return(result) - }, - - transientSphereSeries: function( density, thermalConduct, heatConvection, cp, rPosition, rTotal, tempInitial, tempInfini, t ){ - var min = 0; - var max = 10000; // This are for setting Lambda boundaries and nothing else - - var sum=0; - var alpha = thermalConduct/(density*cp); - var lambdaN; - var sinPortion; - var exponentialPortion; - var frontCoefficientPortion; - - - //if(DEBUG) console.log("Alpha is " + alpha) - - var Fourier = (alpha*t)/Math.pow(rTotal,2) - //if(DEBUG) console.log("Fourier is " + Fourier) - - var biotNum = heatConvection * rTotal/thermalConduct - - if ( biotNum != this.cachedBiot ) { - if(DEBUG) console.log("Recalculating Lambda Terms") - this.cachedLambda = this.findAllRoots(min,max,max*Math.PI*10,biotNum) - this.cachedBiot = biotNum; - } - - //if(DEBUG) console.log("The Biot Value is " + biotNum) - - for (var i = 0; i=multiplier*600000) { - return ["Fire", (cookValue-600000)/(multiplier*600000),"fire"]; - } - else if(cookValue>=multiplier*250000) { - return ["Burnt", (cookValue-250000)/(multiplier*600000), "burnt"]; - } - else if (cookValue>=multiplier*150000) { - return ["Dry", (cookValue-150000)/(multiplier*250000), "dry"]; - } - else if (cookValue>=multiplier*85000){ - return ["Cooked", (cookValue-12000)/(multiplier*150000), "overcooked"]; - } - else if (cookValue>=multiplier*12000) { - return ["Cooked", (cookValue-12000)/(multiplier*150000), "cooked"]; - } - else if (cookValue>=multiplier*10000){ - return ["Undercooked", (cookValue-5000)/(multiplier*12000), "slightly cooked"]; - } - else if (cookValue>=multiplier*5000) { - return ["Undercooked", (cookValue-5000)/(multiplier*12000), "undercooked"]; + cookCondition: function(cookValue, layerName){ + + if( layerName == "skin" ){ + var multiplier = 1; + if (cookValue>=multiplier*600000) { + return ["Fire", (cookValue-600000)/(multiplier*600000),"fire"]; + } + else if(cookValue>=multiplier*250000) { + return ["Burnt", (cookValue-250000)/(multiplier*600000), "burnt"]; + } + else if (cookValue>=multiplier*150000) { + return ["Dry", (cookValue-150000)/(multiplier*250000), "dry"]; + } + else if (cookValue>=multiplier*85000){ + return ["Cooked", (cookValue-12000)/(multiplier*150000), "overcooked"]; + } + else if (cookValue>=multiplier*12000) { + return ["Cooked", (cookValue-12000)/(multiplier*150000), "cooked"]; + } + else if (cookValue>=multiplier*10000){ + return ["Undercooked", (cookValue-5000)/(multiplier*12000), "slightly cooked"]; + } + else if (cookValue>=multiplier*5000) { + return ["Undercooked", (cookValue-5000)/(multiplier*12000), "undercooked"]; + } + else { + return ["Raw", 1, "raw"]; + } } - else { - return ["Raw", 1, "raw"]; + else{ + var multiplier = 1; + if (cookValue>=multiplier*600000) { + return ["Fire", (cookValue-600000)/(multiplier*600000),"fire"]; + } + else if(cookValue>=multiplier*250000) { + return ["Burnt", (cookValue-250000)/(multiplier*600000), "burnt"]; + } + else if (cookValue>=multiplier*150000) { + return ["Dry", (cookValue-150000)/(multiplier*250000), "dry"]; + } + else if (cookValue>=multiplier*85000){ + return ["Cooked", (cookValue-12000)/(multiplier*150000), "overcooked"]; + } + else if (cookValue>=multiplier*12000) { + return ["Cooked", (cookValue-12000)/(multiplier*150000), "cooked"]; + } + else if (cookValue>=multiplier*10000){ + return ["Undercooked", (cookValue-5000)/(multiplier*12000), "slightly cooked"]; + } + else if (cookValue>=multiplier*5000) { + return ["Undercooked", (cookValue-5000)/(multiplier*12000), "undercooked"]; + } + else { + return ["Raw", 1, "raw"]; + } + } } } @@ -322,8 +313,8 @@ UtilityFunctions = { //Running the Program Stuff /* var ovenObject = new OvenModel(); -var turkey = new TurkeyModel(9.07185, ovenObject ); +var turkey = new TurkeyModel(9, ovenObject); globalTime=0; -setInterval(function(){ovenObject.secondTick();},10); +setInterval(function(){ovenObject.secondTick();},1000); */