Template:Exeter/js/fmr5

//INPUTS //metals


var data; var options;

function metaltype(metals) { switch (metals) { case "Zinc": atomicmass=65.39; break ;

case "Nickel": atomicmass=58.6934; break ;

case "Magnesium": atomicmass=24.305; break ;

case "Iron": atomicmass=55.845; break ;

case "Cobalt": atomicmass=58.9332; break ;

case "Copper": atomicmass=63.546; break ;

default: break; } return(atomicmass); }

//Metalconc function inputconcunits(units,metalconc,atomicmass) { switch (units) { case "mols": metalconc=metalconc*atomicmass*1000; //is metalconc right here? break;

case "mg/L": metalconc=metalconc ; break;

default: break; } return(metalconc); }

//Reg function regunits(units,reg,atomicmass) { switch (units) { case "mols": reg=reg*atomicmass*1000; break;

case "mg/L": reg=reg ; break;

default: break; } return(reg); }

//Flowrate function flowrateunits(units,flowrate) { switch (units) { case "m^3/s": flowrate=flowrate*1000; break;

case "L/s": flowrate=flowrate; break;

default: break; } return(flowrate); }

//FMR volume function FMRvolumeunits(units, FMRvolume) { switch (units) { case "m^3": FMRvolume=FMRvolume*1000; break;

case "gallons": //do we want to do gallons? FMRvolume=FMRvolume*4.54609; break;

case "L": FMRvolume=FMRvolume; break;

default: break; } return(FMRvolume); } //OUTPUTS //Output concentration

//Metalmass function metalmassunits(units,metalmass) { switch (units) { case "tonnes": metalmass=metalmass*0.001; break;

case "kg": metalmass=metalmass; break;

default: break; } return(metalmass); }


  function drawChart() {
       options = {

title: 'A Graph of Ion Concentration Leaving the Reactor (mg/L) Over Time (s)',

         curveType: 'none',
         legend: { position: 'bottom' }
       };


  }

var timestep = 1; function FMRmodel(timestep)


{ // grabs elements from textboxes and converts values using switch statements var atomicmass = metaltype(document.getElementById("metal").value); // console.log(atomicmass);


var metalconc=document.getElementById("inputconc").value; //grabs input concentration value from textbox and assigns to metalconc--> console.log(metalconc); metalconc = inputconcunits(document.getElementById("inputconc2").value, metalconc,atomicmass); // console.log(metalconc);

var reg=document.getElementById("reg").value; console.log(reg); reg =regunits(document.getElementById("reg2").value, reg, atomicmass); console.log(reg);

var flowrate=document.getElementById("flowrate").value; console.log(flowrate); flowrate = flowrateunits(document.getElementById("flowrate2").value, flowrate); console.log(flowrate)

var FMRvolume=document.getElementById("FMRvolume").value; console.log(FMRvolume); FMRvolume = FMRvolumeunits(document.getElementById("FMRvolume2").value, FMRvolume); console.log(FMRvolume);

const spongeSA=3618.6*0.0001 ; //this is m squared

const spongeV=150*Math.pow(10,-6) ; //in m cubed
const ecoliperunitA=9.22*Math.pow(10,16) ; //in m^-2 the ecoli per unit SA on sponge 
const avpili=250 ; //average number of pili on ecoli 
//const timestep=1 ; //timestep of 10 mintutes, 600 seconds was 60
const avg=6.022*Math.pow(10,23) ;

 var remove = [0,0];//array
 var N = [0,0];//array
 var R = [0,0];//array
 var numremoved = [0,0];//array
 var efficiency = [0,0];//array
 var concleft = [0,0];//array
 var graphconc=[];//emptyarray
 var graphtime=[];//emptyarray
 

var graphdata = new Array(2); graphconc[0]="Output Concentration"; graphtime[0]="Time";

var ratio=spongeSA/spongeV ; //the ratio of sponge volume to are

var totalSA=FMRvolume*ratio ; //finds the total surface area of sponge available

var numEcoli= totalSA*ecoliperunitA ; //number of ecoli in FMR

var totalpili=numEcoli*avpili ; //number of pili in FMR in total

N[1]=totalpili ; //number of pili remaining at each timestep

R[1]=N[1]/totalpili ; //ratio of remaining pili to intial number available: to be changed at each timestep

var timestepV=flowrate*timestep ; //volume of water flowing through during timestep

var molarconc=metalconc/(atomicmass*1000) ; //assuming density of water is 1 g/mL

var totalmoles=molarconc*timestepV; //volume needs to be litres/consistent. molarity is in g/l

var numions=avg*totalmoles/(0.0741) ; //number of ions per timestep

var k=0; //number of iterations

var kis=1 ;

while (concleft[1]<reg*(1.2)) //stops when ratio less that the modified target { if (concleft[1]<reg) { remove[0] = remove[1]; // saves N[0] = N[1]; R[0] = R[1]; numremoved[0] = numremoved[1]; efficiency[0] = efficiency[1]; concleft[0] = concleft[1]; console.log(concleft[0]) kis=k; } else if (k>kis*(1.2)) { break; }


var rem = numions*R[1]*0.0117*FMRvolume/flowrate ; if(rem > numions) { remove[1] = numions; } else { remove[1]=rem; }//number of ions being removed per timestep N[1]-=remove[1] ; //number of pili available R[1]=N[1]/totalpili ;//ratio of avaiable pili to total pili

k++ ;

numremoved[1]+=remove[1]; totalions = k*numions; efficiency[1] = numremoved[1]/totalions; concleft[1] = metalconc*(1-efficiency[1]);

graphconc[k]=concleft[1]; graphtime[k]=k*timestep;

if(k>150000) { break; } }

var graphdata = [];


   for(var i = 0; i < graphtime.length; i++)

{

       graphdata[i]=[];

/*if (i>0){ graphdata[i][0]=graphtime[i]/13.48640214;} else {*/ graphdata[i][0]=graphtime[i];

graphdata[i][1]=graphconc[i]; graphdata[i][2]=concleft[0];

   };

graphdata[0][2]="Allowed Concentration";



console.log(graphdata);


var totalremoved=totalpili*(1-R[0]) ; //number of ions removed

var graphinputs=[graphtime, graphconc];

var metalmass=(totalremoved*atomicmass)/(1000*avg) ; //metal mass removed in kg

var time=timestep*kis; //calculates total time to run for

var outputefficiency=efficiency[0]*100 ;

var outputconc = concleft[0] ; //concentration of metal in output water

var outputs=[ time, metalmass] ; console.log(outputs);

metalmass=metalmassunits(document.getElementById("metalmass2"),metalmass); switch(true) { case k<5||k>=150000: document.getElementById("time").value="Unphysical Response"; document.getElementById("metalmass").value="Unphysical Response"; if(k<5) { document.getElementById("ErrorComment").innerHTML = "The volume of the reactor is too small to achieve the specified concentration reduction."; } else { document.getElementById("ErrorComment").innerHTML = "The model ran for more than 173 days without the reactor needing to be changed. This exceeds the time limit for the online version of this model."; timestep*=10; if(timestep>100) { break; } FMRmodel(timestep); } break; default: document.getElementById("time").value=time; document.getElementById("metalmass").value=metalmass; document.getElementById("ErrorComment").innerHTML = "No errors."; break; } //doesnt yet have change in units



if(k<150000) { var chart = new google.visualization.LineChart(document.getElementById('curve_chart')); data = google.visualization.arrayToDataTable(graphdata); chart.draw(data, options); }


return(outputs); } function reAp(Find) { //var Find = document.getElementById("test");//event.target Find.style.visibility = 'visible'; } function dis(Find) { //var Find = document.getElementById("test");//event.target Find.style.visibility = 'hidden'; }


/*function visible() {

}

function notvisible() { class="mouseout" }*/