diff --git a/js/main.js b/js/main.js index 4b15527a744e25284a1c92eaa01cffccc6476490..52f5492eabace5a7a39c788eab90b0c20282f39b 100644 --- a/js/main.js +++ b/js/main.js @@ -160,6 +160,7 @@ require.config({ latticeESim: 'simulation/electronics/LatticeEsim', eSimCell: 'simulation/electronics/cells/eSimCell', eSimSuperCell: 'simulation/electronics/cells/eSimSuperCell', + eSimField: 'simulation/electronics/eSimField', //cam diff --git a/js/simulation/electronics/LatticeEsim.js b/js/simulation/electronics/LatticeEsim.js index d8f099b76e6baca84ad0349a3d6a17dd31a50013..c2c58827009a3c9d7179bb39728d4da2dc889769 100644 --- a/js/simulation/electronics/LatticeEsim.js +++ b/js/simulation/electronics/LatticeEsim.js @@ -2,7 +2,8 @@ * Created by aghassaei on 6/30/15. */ -define(['lattice', 'appState', 'threeModel', 'eSim', 'eSimCell', 'eSimSuperCell'], function(lattice, appState, three, eSim){ +define(['lattice', 'appState', 'three', 'threeModel', 'eSim', 'eSimCell', 'eSimSuperCell'], + function(lattice, appState, THREE, three, eSim){ @@ -70,6 +71,12 @@ define(['lattice', 'appState', 'threeModel', 'eSim', 'eSimCell', 'eSimSuperCell' }, calcEField: function(conductorGroups, resolution){ + + if (this.numCells == 0){ + console.warn("no cells!"); + return; + } + var eFieldMat = []; //init size of field mat and fill with zeros, +2 puts a shell of zeros at boundary (infinity) for (var x=0;x<resolution*this.cells.length+2;x++){ @@ -82,6 +89,7 @@ define(['lattice', 'appState', 'threeModel', 'eSim', 'eSimCell', 'eSimSuperCell' } } + //input conductor potentials this._loopCells(this.cells, function(cell, x, y, z){ if (!cell) return; for (var i=0;i<resolution;i++){ @@ -94,6 +102,13 @@ define(['lattice', 'appState', 'threeModel', 'eSim', 'eSimCell', 'eSimSuperCell' }); console.log(eFieldMat); + console.log(this.get("cellsMin")); + 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)); + console.log(offset); + require(['eSimField'], function(ESimField){ + eSim.set("electricField", new ESimField(eFieldMat, offset, resolution)); + }); + }, calcCapacitance: function(){ diff --git a/js/simulation/electronics/eSimField.js b/js/simulation/electronics/eSimField.js new file mode 100644 index 0000000000000000000000000000000000000000..7f70d5da78751c20fce14b05e63ade0adebf7d21 --- /dev/null +++ b/js/simulation/electronics/eSimField.js @@ -0,0 +1,65 @@ +/** + * Created by aghassaei on 8/10/15. + */ + + +//hold and display data for various fields + +define(['underscore', 'threeModel'], function(_, threeModel){ + + function ESimField(data, offset, resolution){ + + this._data = data; + this._offset = offset; + + this._createThreeObjects(data, offset, 1/resolution); + + } + + ESimField.prototype._createThreeObjects = function(data, offset, size){ + var threeObjects = []; + for (var x=0;x<data.length;x++){ + threeObjects.push([]); + for (var y=0;y<data[0].length;y++){ + threeObjects[x].push([]); + for (var z=0;z<data[0][0].length;z++){ + var box = new THREE.Mesh(new THREE.BoxGeometry(size, size, size), new THREE.MeshLambertMaterial({color:"#ff0000"})); + box.position.set(x*size+offset.x, y*size+offset.y, z*size+offset.z); + threeModel.sceneAdd(box); + threeObjects[x][y].push(box); + } + } + } + threeModel.render(); + }; + + ESimField.prototype.show = function(height){ + var data = []; + for (var x=0;x<this._data.length;x++){ + data.push([]); + for (var y=0;y<this._data[x].length;y++){ + data[x].push(this._data[x][y][height]); + } + } + + }; + + ESimField.prototype.hide = function(){ + + + }; + + ESimField.prototype._loopCells = function(data, callback){ + for (var x=0;x<data.length;x++){ + for (var y=0;y<data[0].length;y++){ + for (var z=0;z<data[0][0].length;z++){ + callback(data[x][y][z], x, y, z, this); + } + } + } + }; + + + return ESimField; + +}); \ No newline at end of file