- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
eps=0.001;
s1=new Source(1000,0.17);
mx=new Mixer(1000);
mb=new Mem(0.15,0.95);
sp=new Splitter(0.80);
s2=new Sink();
s3=new Sink();
mx.in1=s1.out1;
mx.in2=sp.out2;
mb.in1=mx.out1;
sp.in1=mb.out2;
s3.in1=sp.out1;
s2.in1=mb.out1;
for (i=0;i<50;i++){
mx.calc();
mb.calc();
sp.calc();
}
function Stream(v,c){
this.v=v||null;
this.c=c||null;
this.selfCheck=false;
this.Show=function(){//how to add default values?
return "volume="+this.v+",conc="+this.c+",selfCheck:"+this.selfCheck+"; ";
}
}
function Source(v,c){
this.out1=new Stream(v,c);
this.calc=function(){};
}
function Sink(){
this.in1=null;
this.calc=function(){};
}
function Mixer(fixedV){
this.fv=fixedV;
this.in1=null;
this.in2=null;
this.out1=new Stream();
this.calc=function(){
this.out1.v=this.fv;//||this.in1.v+this.in2.v;
this.in2.v=this.in2.v||0;
this.in2.c=this.in2.c||0;
this.in1.v=this.out1.v-this.in2.v;
this.out1.c =(this.in1.v*this.in1.c+this.in2.v*this.in2.c)/this.out1.v;
this.out1.selfCheck=Math.abs
((this.in1.v*this.in1.c+this.in2.v*this.in2.c)-(this.out1.v*this.out1.c))<eps;
}
}
function Splitter(kS){
this.in1=null;
this.ks=kS||0.05;
this.out1=new Stream();
this.out2=new Stream();
this.calc=function(){
this.out1.v=this.in1.v*(1-this.ks);
this.out2.v=this.in1.v*(this.ks);
this.out1.c=this.in1.c;
this.out2.c=this.in1.c;
}
}
function Mem(kV,kC) {
this.kv = kV||0.15;
this.kc = kC||0.95;
this.in1 = null;
this.out1 = new Stream();
this.out2 = new Stream();
this.calc = function () {
this.out1.v = this.in1.v * this.kv;
this.out1.c = this.in1.c * (1 - this.kc);
this.out2.v = this.in1.v * (1 - this.kv);
this.out2.c = (this.in1.v * this.in1.c - this.out1.v * this.out1.c) / this.out2.v;
this.out1.selfCheck = this.out2.selfCheck = Math.abs
(this.in1.v * this.in1.c - (this.out1.v * this.out1.c + this.out2.v * this.out2.c)) < eps;
}
}
xtfkpi 16.03.2015 13:38 # 0
tirinox 16.03.2015 15:22 # 0
Fike 16.03.2015 16:05 # 0
/300