/*-----------------------Start user-defined code ---------------------*/ let sim; var a = 0.05 var e = 0.005 var b = 4.5 var dt = 3 var disruption = 0.3 function cacatoo() { let config = { title: "Fitzhugh Nagumo PDE", description: "Disrupt action potential with button / drawing with the mouse", maxtime: 1000000, ncol: 200, nrow: 128, // dimensions of the grid to build wrap: [false, false], // Wrap boundary [COLS, ROWS] scale: 2, // scale of the grid (nxn pixels per grid cell bgcolour:'white', graph_interval: 5, graph_update: 25 } sim = new Simulation(config) sim.makeGridmodel("Fitz"); sim.Fitz.colourGradient('V', 100, [255, 255, 255], [0, 0, 255]) // Will contain the ODEs, and show the abundance of PREDATORS sim.Fitz.colourGradient('W', 100, [255, 255, 255], [255, 0, 0]) // Will contain the ODEs, and show the abundance of PREDATORS sim.createDisplay_continuous({model:"Fitz", property:"V", label:"Action potential", minval:0, maxval:1, decimals:3, nticks:3}) sim.createDisplay_continuous({model:"Fitz", property:"W", label:"Refractory tissue", minval:0, maxval:0.3, decimals:3, nticks:3}) sim.reset = function(all=true){ sim.time=0 if(all)sim.Fitz.resetPlots() for (let i = 0; i < sim.Fitz.nc; i++) { for (let j = 0; j < sim.Fitz.nr; j++) { if(all){ sim.Fitz.grid[i][j].V = i == 0 ? 1 : 0.0 sim.Fitz.grid[i][j].W = 0.0 } else{ if(i==0) sim.Fitz.grid[i][j].V = 1 } } } } sim.reset() sim.Fitz.nextState = function (i, j) // Define the next-state function. { let V = this.grid[i][j].V let W = this.grid[i][j].W this.grid[i][j].V += dt*( -V*(V-a)*(V-1) - W ) this.grid[i][j].W += dt*( e*(V-b*W) ) if(this.grid[i][j].V < 0.001) this.grid[i][j].V = 0 } sim.Fitz.update = function () { //if(sim.time==100) sim.Fitz.wrap=[true,false] if(sim.time%300==0) sim.reset(false) if(sim.time>0 && sim.time%sim.config.graph_update*10==0) { let g = sim.Fitz.graphs['Average ation potential at right-hand side'] let dat = g.data.slice(-sim.config.graph_update*10) g.data = dat g.g.updateOptions( { 'file': this.data }); } this.synchronous() this.diffuseStates('V',0.2) let sumV=0 //for(let i=0; i<sim.Fitz.nc; i++){ for(let j=0; j<sim.Fitz.nr; j++){ //console.log(i,j) sumV += this.grid[sim.Fitz.nc-1][j].V } //} this.plotArray(["V"], [sumV/(sim.Fitz.nr)], ["blue"], "Average ation potential at right-hand side") } /* sim.addButton("pause", function () { sim.toggle_play() })*/ sim.addSlider("disruption",0,1) sim.addButton("disrupt", function () { for (let i = 0; i < sim.Fitz.nc; i++){ for (let j = 0; j < sim.Fitz.nr; j++){ if(sim.rng.random()<disruption) sim.Fitz.grid[i][j].V = 0 } } }) sim.addButton("CLEAR!", function () { for (let i = 0; i < sim.Fitz.nc; i++){ for (let j = 0; j < sim.Fitz.nr; j++){ sim.Fitz.grid[i][j].V = 1 } } }) sim.addButton("reset", function () { sim.reset() }) sim.addStatebrush("Fitz","V", 0.0, 40) sim.start() /* sim.display() sim.toggle_play() */ } /*-------------------------End user-defined code ---------------------*/