diff --git a/js/menus/EStaticMenuView.js b/js/menus/EStaticMenuView.js index b536655a6616a1f2a1838d1a15b1f0b242620b85..858f3146c461599b8efb082d829bca9af7517708 100644 --- a/js/menus/EStaticMenuView.js +++ b/js/menus/EStaticMenuView.js @@ -26,6 +26,7 @@ define(['jquery', 'underscore', 'menuParent', 'eSimPlist', 'text!eStaticMenuTemp _calcEField: function(e){ e.preventDefault(); + console.log("here"); lattice.calcEField(eSim.get("conductorGroups"), eSim.get("simulationRes")); }, diff --git a/js/plists/ESimPlist.js b/js/plists/ESimPlist.js index ff8321ba45cc5e99104926f314a3e4d6573d2cf3..ee280354262bb2ab7701ca10fda996daf2fdb6e1 100644 --- a/js/plists/ESimPlist.js +++ b/js/plists/ESimPlist.js @@ -20,7 +20,7 @@ define([], function(){ visibleStaticSimTypes: { none: "None", - voltageField: "Input Potentials", + potentialField: "Input Potentials", electricField: "Electric Field", chargeField: "Charge Distribution", capacitanceField: "Capacitance" diff --git a/js/simulation/electronics/LatticeEsim.js b/js/simulation/electronics/LatticeEsim.js index 31585bca11e99b12a1efad0a2177239ca143b2de..a988870806d9fbfa710085b0abe70a43c8daddff 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', 'eSimCell', 'eSimSuperCell'], - function(lattice, appState, THREE, three, eSim){ +define(['lattice', 'appState', 'three', 'threeModel', 'eSim', 'eSimField', 'eSimCell', 'eSimSuperCell'], + function(lattice, appState, THREE, three, eSim, ESimField){ @@ -103,11 +103,28 @@ define(['lattice', 'appState', 'three', 'threeModel', 'eSim', 'eSimCell', 'eSimS }); var offset = this.get("cellsMin").clone().sub(new THREE.Vector3(1/(2*resolution)+this.xScale(0)/2, 1/(2*resolution)+this.yScale(0)/2, 1/(2*resolution)+this.zScale(0)/2)); - require(['eSimField'], function(ESimField){ - eSim.set("electricField", new ESimField(eFieldMat, offset, resolution, eSim.get("simZHeight"), _.keys(conductorGroups))); - eSim.set("visibleStaticSim", "electricField"); + var dataRange = []; + _.each(conductorGroups, function(group){ + dataRange.push(group.voltage); }); + + //create potential field + if (eSim.get("potentialField")){ + eSim.get("potentialField").setData(eFieldMat, offset, resolution, eSim.get("simZHeight"), dataRange); + } else { + eSim.set("potentialField", new ESimField(eFieldMat, offset, resolution, eSim.get("simZHeight"), dataRange)); + } + + //create electric field from potential + if (eSim.get("electricField")){ + eSim.get("electricField").setData(eFieldMat, offset, resolution, eSim.get("simZHeight"), dataRange); + } else { + eSim.set("electricField", new ESimField(eFieldMat, offset, resolution, eSim.get("simZHeight"), dataRange)); + } + eSim.set("visibleStaticSim", "electricField");//will cause render + + }, calcCapacitance: function(){ diff --git a/js/simulation/electronics/eSim.js b/js/simulation/electronics/eSim.js index ea9cf5cfc07160f1e0976f5085928f4b259d51bf..c076767cf9d2d060d1767b6db137e7b48e654f1c 100644 --- a/js/simulation/electronics/eSim.js +++ b/js/simulation/electronics/eSim.js @@ -19,6 +19,7 @@ define(['underscore', 'backbone', 'threeModel'], function(_, Backbone, three){ simZHeight: 1, //statics + potentialField: null, electricField: null, chargeField: null, capacitanceField: null, diff --git a/js/simulation/electronics/eSimField.js b/js/simulation/electronics/eSimField.js index 0d2ac8b06dafc90b61821f747206baf000bceeb1..7659963b727943fb994ef72da222357273f8a0de 100644 --- a/js/simulation/electronics/eSimField.js +++ b/js/simulation/electronics/eSimField.js @@ -10,17 +10,18 @@ define(['underscore', 'threeModel'], function(_, three){ function ESimField(data, offset, resolution, height, dataRange){ this._object3D = new THREE.Object3D(); - this._setData(data, offset, resolution, height, dataRange); + this.setData(data, offset, resolution, height, dataRange); three.sceneAdd(this._object3D); this.hide(); } - ESimField.prototype._setData = function(data, offset, resolution, height, dataRange){ + ESimField.prototype.setData = function(data, offset, resolution, height, dataRange){ this._destroyData(); this._data = data; this._max = _.max(dataRange); - this._min = 0; + console.log(this._max); + this._min = Math.min(0, _.min(dataRange)); this._resolution = resolution; this._offset = offset; @@ -59,7 +60,6 @@ define(['underscore', 'threeModel'], function(_, three){ }; ESimField.prototype.show = function(height){ - console.log(height); if (height < 0 || this._data[0][0][height] === undefined) { console.warn("height " + height + " is out of range"); return;