diff --git a/js/main.js b/js/main.js index 52f5492eabace5a7a39c788eab90b0c20282f39b..2d4eeaf834ec668384ca3364ee87211630bfd4bb 100644 --- a/js/main.js +++ b/js/main.js @@ -13,6 +13,7 @@ require.config({ flatUI: '../dependencies/flatUI/js/flat-ui', bootstrapSlider: '../dependencies/bootstrap-slider/bootstrap-slider', fileSaverLib: '../dependencies/loaders/FileSaver.min', + numeric: '../dependencies/numeric-1.2.6', //three three: '../dependencies/three', @@ -188,7 +189,7 @@ require.config({ gikEndPartLowPolySTL: 'assets/stls/parts/GIKEndPartLowPoly.stl', kennyTeqPartSTL: 'assets/stls/parts/KennyTeqPart.stl', kennyTeqPartHighResSTL: 'assets/stls/parts/KennyTeqPartHighRes.stl', - samTeqPartSTL: 'assets/stls/parts/SamTeqPart.stl', + samTeqPartSTL: 'assets/stls/parts/SamTeqPart.stl' }, @@ -216,6 +217,9 @@ require.config({ }, 'socketio': { exports: 'io' + }, + 'numeric': { + exports: 'numeric' } } diff --git a/js/menus/EStaticMenuView.js b/js/menus/EStaticMenuView.js index 858f3146c461599b8efb082d829bca9af7517708..48e91a86676b9f81b393a6cfba9e4bb334a2c763 100644 --- a/js/menus/EStaticMenuView.js +++ b/js/menus/EStaticMenuView.js @@ -27,7 +27,7 @@ define(['jquery', 'underscore', 'menuParent', 'eSimPlist', 'text!eStaticMenuTemp _calcEField: function(e){ e.preventDefault(); console.log("here"); - lattice.calcEField(eSim.get("conductorGroups"), eSim.get("simulationRes")); + lattice.calcEField(eSim.get("conductorGroups"), eSim.get("simulationRes"), eSim.get("numRelaxationSteps")); }, _calcCapacitance: function(e){ diff --git a/js/menus/templates/EStaticMenuView.html b/js/menus/templates/EStaticMenuView.html index 47e47b685fa87bbbcca3b484e5ea0fad996065bd..89a5a17b9d2fe5ee5a68d6523e5c9fbc03fb074b 100644 --- a/js/menus/templates/EStaticMenuView.html +++ b/js/menus/templates/EStaticMenuView.html @@ -1,6 +1,6 @@ <% if(conductorGroups && _.keys(conductorGroups).length > 0){ %> - Simulation Resolution: <input data-property="simulationRes" value="<%= simulationRes %>" placeholder="Resolution" class="form-control intInput eSim voltageInput" type="text"><br/><br/> - Dielectric Permittivity (k): <input data-property="dielectricPerm" value="<%= dielectricPerm %>" placeholder="k" class="form-control floatInput eSim voltageInput" type="text"><br/> + Simulation Resolution: <input data-property="simulationRes" value="<%= simulationRes %>" placeholder="Resolution" class="form-control intInput eSim" type="text"><br/><br/> + Dielectric Permittivity (k): <input data-property="dielectricPerm" value="<%= dielectricPerm %>" placeholder="k" class="form-control floatInput eSim" type="text"><br/> <label class="radio"> <input type="radio" <% if (visibleConductorGroup == -2){ %>checked<% } %> name="visibleConductorGroup" value="-2" data-toggle="radio" class="custom-radio eSim"><span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span> Show Everything @@ -13,7 +13,7 @@ <label class="radio"> <input type="radio" <% if (id == visibleConductorGroup){ %>checked<% } %> name="visibleConductorGroup" value="<%= id %>" data-toggle="radio" class="custom-radio eSim"><span class="icons"><span class="icon-unchecked"></span><span class="icon-checked"></span></span> Group <%= ++index %> - <input data-property="voltage" data-id="<%= id %>" value="<%= groupData.voltage %>" placeholder="Voltage" class="form-control floatInput eSimGroup voltageInput" type="text"> + <input data-property="voltage" data-id="<%= id %>" value="<%= groupData.voltage %>" placeholder="Voltage" class="form-control floatInput voltageInput eSimGroup" type="text"> <input data-property="current" data-id="<%= id %>" value="<%= groupData.current %>" placeholder="Current" class="form-control floatInput eSimGroup currentInput" type="text"> </label> <% }); %> @@ -38,7 +38,7 @@ Num Relaxation Steps: <input data-property="numRelaxationSteps" value="<%= numRelaxationSteps %>" placeholder="Num Steps" class="form-control floatInput eSim" type="text"><br/><br/> <a href="#" id="calcEField" class="btn btn-block btn-lg btn-default"><% if(electricField){ %>Re-<% } %>Calculate Electric Field</a><br/> <a href="#" id="calcCapacitance" class="btn btn-block btn-lg btn-default"><% if(globalCapacitance){ %>Re-<% } %>Calculate Capacitance</a><br/> - <div class="inlineSwatch capacitance"></div>Global Capacitance:<br/><br/> + Global Capacitance:<br/><br/> <!--<a href="#" id="calcInductance" class="btn btn-block btn-lg btn-default"><% if(globalInductance){ %>Re-<% } %>Calculate Inductance</a><br/>--> Visible Field: <% _.each(visibleStaticSimTypes, function(simType, key){ %> diff --git a/js/plists/ESimPlist.js b/js/plists/ESimPlist.js index ee280354262bb2ab7701ca10fda996daf2fdb6e1..35b00f7045d627d52ede134dc5f0b8118e94497b 100644 --- a/js/plists/ESimPlist.js +++ b/js/plists/ESimPlist.js @@ -20,7 +20,8 @@ define([], function(){ visibleStaticSimTypes: { none: "None", - potentialField: "Input Potentials", + rawPotentialField: "Input Potentials", + potentialField: "Potential Field", electricField: "Electric Field", chargeField: "Charge Distribution", capacitanceField: "Capacitance" diff --git a/js/simulation/electronics/LatticeEsim.js b/js/simulation/electronics/LatticeEsim.js index a988870806d9fbfa710085b0abe70a43c8daddff..4d5357d0476f0c1375a99ecdc458901af3958e27 100644 --- a/js/simulation/electronics/LatticeEsim.js +++ b/js/simulation/electronics/LatticeEsim.js @@ -2,8 +2,8 @@ * Created by aghassaei on 6/30/15. */ -define(['lattice', 'appState', 'three', 'threeModel', 'eSim', 'eSimField', 'eSimCell', 'eSimSuperCell'], - function(lattice, appState, THREE, three, eSim, ESimField){ +define(['lattice', 'appState', 'three', 'threeModel', 'numeric', 'eSim', 'eSimField', 'eSimCell', 'eSimSuperCell'], + function(lattice, appState, THREE, three, numeric, eSim, ESimField){ @@ -70,7 +70,7 @@ define(['lattice', 'appState', 'three', 'threeModel', 'eSim', 'eSimField', 'eSim if (index.y-1 >= 0) callback(this.cells[index.x][index.y-1][index.z]); }, - calcEField: function(conductorGroups, resolution){ + calcEField: function(conductorGroups, resolution, numRelaxationSteps){ if (this.numCells == 0){ console.warn("no cells!"); @@ -110,19 +110,44 @@ define(['lattice', 'appState', 'three', 'threeModel', 'eSim', 'eSimField', 'eSim //create potential field - if (eSim.get("potentialField")){ - eSim.get("potentialField").setData(eFieldMat, offset, resolution, eSim.get("simZHeight"), dataRange); + var potentialData = numeric.clone(eFieldMat); + if (eSim.get("rawPotentialField")){ + eSim.get("rawPotentialField").setData(potentialData, offset, resolution, eSim.get("simZHeight"), dataRange); } else { - eSim.set("potentialField", new ESimField(eFieldMat, offset, resolution, eSim.get("simZHeight"), dataRange)); + eSim.set("rawPotentialField", new ESimField(potentialData, offset, resolution, eSim.get("simZHeight"), dataRange)); + } + eSim.set("visibleStaticSim", "rawPotentialField");//will cause render + + + for (var i=0;i<numRelaxationSteps;i++){ + var temp = numeric.clone(eFieldMat); + console.log(temp[5][5][4]); + for (var x=0;x<temp.length;x++){ + for (var y=0;y<temp[x].length;y++){ + for (var z=0;z<temp[x][y].length;z++){ + if (potentialData[x][y][z] != 0) continue; + var avg = 0; + if (x > 0) avg += eFieldMat[x-1][y][z]; + if (x < temp.length-1) avg += eFieldMat[x+1][y][z]; + if (y > 0) avg += eFieldMat[x][y-1][z]; + if (y < temp[x].length-1) avg += eFieldMat[x][y+1][z]; + if (z > 0) avg += eFieldMat[x][y][z-1]; + if (z < temp[x][y].length-1) avg += eFieldMat[x][y][z+1]; + temp[x][y][z] = avg/6.0; + } + } + } + eFieldMat = numeric.clone(temp); + console.log("hi"); } - //create electric field from potential - if (eSim.get("electricField")){ - eSim.get("electricField").setData(eFieldMat, offset, resolution, eSim.get("simZHeight"), dataRange); + //create electric field + if (eSim.get("potentialField")){ + eSim.get("potentialField").setData(eFieldMat, offset, resolution, eSim.get("simZHeight"), dataRange); } else { - eSim.set("electricField", new ESimField(eFieldMat, offset, resolution, eSim.get("simZHeight"), dataRange)); + eSim.set("potentialField", new ESimField(eFieldMat, offset, resolution, eSim.get("simZHeight"), dataRange)); } - eSim.set("visibleStaticSim", "electricField");//will cause render + eSim.set("visibleStaticSim", "potentialField");//will cause render }, diff --git a/js/simulation/electronics/eSim.js b/js/simulation/electronics/eSim.js index c076767cf9d2d060d1767b6db137e7b48e654f1c..e66f1a794adb699fd71f923089289b4b9f74bd27 100644 --- a/js/simulation/electronics/eSim.js +++ b/js/simulation/electronics/eSim.js @@ -24,7 +24,7 @@ define(['underscore', 'backbone', 'threeModel'], function(_, Backbone, three){ chargeField: null, capacitanceField: null, globalCapacitance: null, - numRelaxationSteps: 5, + numRelaxationSteps: 10, visibleStaticSim: "none"//eField, charge, capacitance }, @@ -36,9 +36,11 @@ define(['underscore', 'backbone', 'threeModel'], function(_, Backbone, three){ }, _hideAllFields: function(){ - if (this.get("electricField")) this.get("electricField").hide(true); - if (this.get("chargeField")) this.get("chargeField").hide(true); - if (this.get("capacitanceField")) this.get("capacitanceField").hide(true); + if (this.get("rawPotentialField")) this.get("rawPotentialField").hide(); + if (this.get("potentialField")) this.get("potentialField").hide(); + if (this.get("electricField")) this.get("electricField").hide(); + if (this.get("chargeField")) this.get("chargeField").hide(); + if (this.get("capacitanceField")) this.get("capacitanceField").hide(); }, _refreshVisibleField: function(){