Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const GATES = 4;
- const T = 1000;
- // fast, slow
- go_ = 1.179709368300604e-06 * 2.017070982139932 * 2.678224120996112 * 2.786216107542795 * 1.5;
- var A = [.1, .1, .1, .1];
- var V0 = [36, 36, 48, 48];
- var go = [go_, go_, 1e10, 1e10];
- var gc = [go_ / 1e10, go_ / 1e10, go_ / 1e10, go_ / 1e10];
- var ro = [1e10, 1e10, 1e10, 1e10];
- var rc = [1e10, 1e10, 1e10, 1e10];
- var P = [-1, 1, -1, 1];
- var pt = .03;
- par = [...A, ...V0, ...go, ...gc, ...ro, ...rc, ...P];
- let q = new Array(36).fill(0);
- q[0] = 1;
- let vj = new Array(T);
- let gj = new Array(T);
- let pc1c2 = 0.01;
- let pc2c1 = 0.00001;
- let ggg = new Array(36);
- // postMessage([1, { text: "Hello from worker..\n" }]);
- console.log("Starting..");
- for (let t = 0; t < T; t++) {
- if (t < 250)
- vj[t] = 0;
- else if (t < 500)
- vj[t] = 60 * (t - 250) / 250;
- else if (t < 750)
- vj[t] = 0;
- else if (t < T)
- vj[t] = -60 * (t - 750) / 250;
- gj[t] = 0;
- }
- const t_start = Date.now();
- for (let t = 0; t < T; t++) {
- if ((t + 1) * 100 / T % 10 === 0) {
- // postMessage([3, { text: (t + 1) * 100 / T }]);
- }
- // code
- gj[t] = MC36SM_Mindaugo_SS(vj[t], par, q, pt, pc1c2, pc2c1);
- }
- t_end = Date.now();
- // postMessage([2, { T: T, gj: gj, vj: vj, text: "Time required for execution: " + (t_end - t_start) / 1000 + " seconds." }]);
- console.log("Time required for execution: " + (t_end - t_start) / 1000 + " seconds.");
- function MC36SM_Mindaugo_SS(vj, par, p, Pt, pc1c2, pc2c1) {
- A = par.slice(0, 4);
- v0 = par.slice(4, 8);
- Go = par.slice(8, 12);
- Gc = par.slice(12, 16);
- Ro = par.slice(16, 20);
- Rc = par.slice(20, 24);
- P = par.slice(24, 28);
- // let g[36][4] = {};// initialize to 0
- let g = new Array(36);
- let v = new Array(36);
- let k = new Array(36);
- let R = new Array(36);
- for (let i = 0; i < 36; i++) {
- g[i] = new Array(4).fill(0);
- v[i] = new Array(4).fill(0);
- k[i] = new Array(4).fill(0);
- R[i] = new Array(4).fill(0);
- }
- //states conductances
- for (let i1 = 0; i1 < 2; i1++)
- for (let i2 = 0; i2 < 3; i2++)
- for (let i3 = 0; i3 < 3; i3++)
- for (let i4 = 0; i4 < 2; i4++) {
- if (i1 == 0) {
- g[i1 * 18 + i2 * 6 + i3 * 2 + i4 * 1][0] = Go[0];
- R[i1 * 18 + i2 * 6 + i3 * 2 + i4 * 1][0] = Ro[0];
- }
- else {
- g[i1 * 18 + i2 * 6 + i3 * 2 + i4 * 1][0] = Gc[0];
- R[i1 * 18 + i2 * 6 + i3 * 2 + i4 * 1][0] = Rc[0];
- }
- if (i2 == 0) {
- g[i1 * 18 + i2 * 6 + i3 * 2 + i4 * 1][1] = Go[1];
- R[i1 * 18 + i2 * 6 + i3 * 2 + i4 * 1][1] = Ro[1];
- }
- else {
- g[i1 * 18 + i2 * 6 + i3 * 2 + i4 * 1][1] = Gc[1];
- R[i1 * 18 + i2 * 6 + i3 * 2 + i4 * 1][1] = Rc[1];
- }
- if (i3 == 0) {
- g[i1 * 18 + i2 * 6 + i3 * 2 + i4 * 1][2] = Go[2];
- R[i1 * 18 + i2 * 6 + i3 * 2 + i4 * 1][2] = Ro[2];
- }
- else {
- g[i1 * 18 + i2 * 6 + i3 * 2 + i4 * 1][2] = Gc[2];
- R[i1 * 18 + i2 * 6 + i3 * 2 + i4 * 1][2] = Rc[2];
- }
- if (i4 == 0) {
- g[i1 * 18 + i2 * 6 + i3 * 2 + i4 * 1][3] = Go[3];
- R[i1 * 18 + i2 * 6 + i3 * 2 + i4 * 1][3] = Ro[3];
- }
- else {
- g[i1 * 18 + i2 * 6 + i3 * 2 + i4 * 1][3] = Gc[3];
- R[i1 * 18 + i2 * 6 + i3 * 2 + i4 * 1][3] = Rc[3];
- }
- }
- let h = new Array(36);
- for (let i = 0; i < 36; i++) {
- h[i] = new Array(4).fill(0);
- }
- for (let i = 0; i < 4; i++) for (let j = 0; j < 36; j++) h[j][i] = g[j][i];
- for (let a = 0; a < 4; a++) // voltages and rectification
- {
- let gg = new Array(36).fill(0);
- for (let i = 0; i < 36; i++) //gg = 1. / sum(1. / g, 2); %sums rows
- {
- for (let j = 0; j < 4; j++)
- gg[i] += 1 / g[i][j];
- gg[i] = 1 / gg[i];
- }
- for (let i = 0; i < 4; i++) //v=vj*[gg gg gg gg]./g;
- for (let j = 0; j < 36; j++)
- v[j][i] = vj * gg[j] / g[j][i];
- for (let i = 0; i < 4; i++) //g=g.*Math.exp(v./R);
- for (let j = 0; j < 36; j++)
- g[j][i] = h[j][i] * Math.exp(v[j][i] / R[j][i]);
- }
- for (let i = 0; i < 36; i++) //k=Math.exp(repmat(A,16,1).*(v.*repmat(P,16,1)-repmat(v0,16,1)));
- for (let j = 0; j < 4; j++)
- k[i][j] = Math.exp(A[j] * (v[i][j] * P[j] - v0[j]));
- let K = Pt;
- let PPP = new Array(36);
- for (let i = 0; i < 36; i++) {
- PPP[i] = new Array(36).fill(0);
- }
- //------------Matrica P-------------------------------------------------
- let l = pc1c2 / pc2c1;
- let p1, p2, p3, p4;
- for (let i1 = 0; i1 < 2; i1++)
- for (let i2 = 0; i2 < 3; i2++)
- for (let i3 = 0; i3 < 3; i3++)
- for (let i4 = 0; i4 < 2; i4++)
- for (let j1 = 0; j1 < 2; j1++)
- for (let j2 = 0; j2 < 3; j2++)
- for (let j3 = 0; j3 < 3; j3++)
- for (let j4 = 0; j4 < 2; j4++) {
- let i = i1 * 18 + i2 * 6 + i3 * 2 + i4 * 1;
- let j = j1 * 18 + j2 * 6 + j3 * 2 + j4 * 1;
- ////////////// p1
- if (i1 == 0) {
- if (j1 == 0)
- p1 = (1 - K * k[i][0] / (1 + k[i][0]));
- else
- p1 = K * k[i][0] / (1 + k[i][0]);
- }
- else {
- if (j1 == 1)
- p1 = (1 - K / (1 + k[i][0]));
- else
- p1 = K / (1 + k[i][0]);
- }
- ///////////////p2
- if (i2 == 0) {
- if (j2 == 0)
- p2 = (1 - K * k[i][1] / (1 + k[i][1]));
- if (j2 == 1)
- p2 = K * k[i][1] / (1 + k[i][1]);
- if (j2 == 2)
- p2 = 0;
- }
- else if (i2 == 1) {
- if (j2 == 0)
- p2 = (K / (1 + k[i][1])) * (1 - pc1c2);
- if (j2 == 1)
- p2 = (1 - K / (1 + k[i][1])) * (1 - pc1c2);
- if (j2 == 2)
- p2 = pc1c2;
- }
- else if (i2 == 2) {
- if (j2 == 0)
- p2 = 0;
- if (j2 == 1)
- p2 = pc2c1;
- if (j2 == 2)
- p2 = 1 - pc2c1;
- }
- ////////////////p3
- if (i3 == 0) {
- if (j3 == 0)
- p3 = (1 - K * k[i][2] / (1 + k[i][2]));
- if (j3 == 1)
- p3 = K * k[i][2] / (1 + k[i][2]);
- if (j3 == 2)
- p3 = 0;
- }
- else if (i3 == 1) {
- if (j3 == 0) //c1->o
- p3 = (K / (1 + k[i][2])) * (1 - pc1c2);
- if (j3 == 1)
- p3 = (1 - K / (1 + k[i][2])) * (1 - pc1c2);
- if (j3 == 2)
- p3 = pc1c2;
- }
- else if (i3 == 2) {
- if (j3 == 0)
- p3 = 0;
- if (j3 == 1)
- p3 = pc2c1;
- if (j3 == 2)
- p3 = 1 - pc2c1;
- }
- /////////////////p4
- if (i4 == 0) {
- if (j4 == 0)
- p4 = (1 - K * k[i][3] / (1 + k[i][3]));
- else
- p4 = K * k[i][3] / (1 + k[i][3]);
- }
- else {
- if (j4 == 1)
- p4 = (1 - K / (1 + k[i][3]));
- else
- p4 = K / (1 + k[i][3]);
- }
- PPP[i][j] = p1 * p2 * p3 * p4;
- }
- // -------------- SS skaiciavimas
- let d_g = 100000;
- let g_old = 100000;
- let g_final = 0;
- let i = 0;
- while (d_g / (g_old + g_final) > .001e-5) {
- i++;
- let q = new Array(36).fill(0);
- for (let j = 0; j < 36; j++) for (let i = 0; i < 36; i++) q[j] += p[i] * PPP[i][j]; // q=p*PPP;
- for (let j = 0; j < 36; j++) ggg[j] = 0;
- for (let i = 0; i < 36; i++) //ggg = 1. / sum(1. / g, 2); %sums rows
- {
- for (let j = 0; j < 4; j++) ggg[i] += 1 / g[i][j];
- ggg[i] = 1 / ggg[i];
- }
- g_final = 0;
- for (let j = 0; j < 36; j++) //g_final = q*ggg';
- g_final += q[j] * ggg[j];
- for (let i = 0; i < 36; i++) p[i] = q[i]; //grazina p
- d_g = Math.abs(g_old - g_final);
- g_old = g_final;
- }
- return g_final;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement