-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex1.js
1749 lines (1589 loc) · 62.8 KB
/
index1.js
1
2
3
4
5
6
7
8
9
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// //Popup
// $(window).load(function () {
// $(".trigger_popup_fricc").click(function () {
// $(".hover_bkgr_fricc").show();
// });
// $(".hover_bkgr_fricc").click(function () {
// $(".hover_bkgr_fricc").hide();
// });
// $(".popupCloseButton").click(function () {
// $(".hover_bkgr_fricc").hide();
// });
// });
// Dictionary to store the count of individual elements
var field_values_final = [];
async function inputReset() {
console.log("Comes");
cond_matrix = [];
console.log("Proceed");
}
var cond_matrix = [];
ele_count = {
resistor: 0,
curr_src: 0,
volt_src: 0,
vccs: 0,
vcvs: 0,
cccs_gen: 0,
cccs_vs: 0,
ccvs_gen: 0,
ccvs_vs: 0,
};
resistor_list = [];
curr_src_list = [];
volt_src_list = [];
vccs_list = [];
vcvs_list = [];
cccs_gen_list = [];
cccs_vs_list = [];
ccvs_gen_list = [];
ccvs_vs_list = [];
var input_fields = [];
var ele_code = [];
var ele_code_value = {
1: "Resistor",
2: "Current Source",
3: "Voltage Source",
4: "Voltage Controlled Current Source",
5: "Voltage Controlled Voltage Source",
6: "Current Controlled Current Source(General)",
7: "Current Controlled Current Source(Vs)",
8: "Current Controlled Voltage Source(General)",
9: "Current Controlled Voltage Source(Vs)",
};
var img_dir = {
1: "./images/Resistor.png",
2: "./images/IS.png",
3: "./images/Vs.png",
4: "./images/VCCS.png",
5: "./images/VCVS.png",
6: "./images/CCCS_gen.png",
7: "./images/CCCS_Vs.png",
8: "./images/CCVS.png",
9: "./images/CCVS_Vs.png",
};
class resistor {
constructor(ele_code, resistor_value, node_high, node_low) {
this.ele_code = ele_code;
this.resistor_value = resistor_value;
this.node_high = node_high;
this.node_low = node_low;
}
}
class curr_src {
constructor(ele_code, current, node_high, node_low) {
this.ele_code = ele_code;
this.current = current;
this.node_high = node_high;
this.node_low = node_low;
}
}
class volt_src {
constructor(ele_code, voltage, node_high, node_low) {
this.ele_code = ele_code;
this.voltage = voltage;
this.node_high = node_high;
this.node_low = node_low;
}
}
class vccs {
constructor(
ele_code,
trans_conductance,
node_high,
node_low,
control_vol_node_high,
control_vol_node_low
) {
this.ele_code = ele_code;
this.trans_conductance = trans_conductance;
this.node_high = node_high;
this.node_low = node_low;
this.control_vol_node_high = control_vol_node_high;
this.control_vol_node_low = control_vol_node_low;
}
}
class vcvs {
constructor(
ele_code,
control_factor,
node_high,
node_low,
control_vol_node_high,
control_vol_node_low
) {
this.ele_code = ele_code;
this.control_factor = control_factor;
this.node_high = node_high;
this.node_low = node_low;
this.control_vol_node_high = control_vol_node_high;
this.control_vol_node_low = control_vol_node_low;
}
}
class cccs_gen {
constructor(
ele_code,
control_factor,
node_high,
node_low,
control_vol_node_high,
control_vol_node_low
) {
this.ele_code = ele_code;
this.control_factor = control_factor;
this.node_high = node_high;
this.node_low = node_low;
this.control_vol_node_high = control_vol_node_high;
this.control_vol_node_low = control_vol_node_low;
}
}
class cccs_vs {
constructor(
ele_code,
control_factor,
node_high,
node_low,
control_vol_node_high,
control_vol_node_low
) {
this.ele_code = ele_code;
this.control_factor = control_factor;
this.node_high = node_high;
this.node_low = node_low;
this.control_vol_node_high = control_vol_node_high;
this.control_vol_node_low = control_vol_node_low;
}
}
class ccvs_gen {
constructor(
ele_code,
trans_resistance,
node_high,
node_low,
control_vol_node_high,
control_vol_node_low
) {
this.ele_code = ele_code;
this.trans_resistance = trans_resistance;
this.node_high = node_high;
this.node_low = node_low;
this.control_vol_node_high = control_vol_node_high;
this.control_vol_node_low = control_vol_node_low;
}
}
class ccvs_vs {
constructor(
ele_code,
trans_resistance,
node_high,
node_low,
control_vol_node_high,
control_vol_node_low
) {
this.ele_code = ele_code;
this.trans_resistance = trans_resistance;
this.node_high = node_high;
this.node_low = node_low;
this.control_vol_node_high = control_vol_node_high;
this.control_vol_node_low = control_vol_node_low;
}
}
function get_input_fields(ele_code) {
if (ele_code == 1) {
ele_count["resistor"] = ele_count["resistor"] + 1;
var fields_to_ask = [
"Enter the resistance value (in ohms):",
"Enter one terminal node value of the resistance: ",
"Enter other terminal node value of the resistance: ",
];
return fields_to_ask;
}
if (ele_code == 2) {
ele_count["curr_src"] = ele_count["curr_src"] + 1;
var fields_to_ask = [
"Enter the current value (in amperes): ",
"Enter the high potential(k) node to which the current source is connected:",
"Enter the low potential node(l) to which the current source is connected: ",
];
return fields_to_ask;
}
if (ele_code == 3) {
ele_count["volt_src"] = ele_count["volt_src"] + 1;
var fields_to_ask = [
"Enter the voltage value (in volts):",
"Enter the high potential node(k) to which the voltage source is connected:",
"Enter the low potential node(l) to which the voltage source is connected: ",
];
return fields_to_ask;
}
if (ele_code == 4) {
ele_count["vccs"] = ele_count["vccs"] + 1;
var fields_to_ask = [
"Enter the trans-conductance value (Gm in siemens): ",
"Enter the high potential node(k) to which the controlled current source is connected: ",
"Enter the low potential node(l) to which the controlled current source is connected: ",
"Enter the high potential node(m) to which the controlling voltage is connected: ",
"Enter the low potential node(n) to which the controlling voltage is connected: ",
];
return fields_to_ask;
}
if (ele_code == 5) {
ele_count["vcvs"] = ele_count["vcvs"] + 1;
var fields_to_ask = [
"Enter the control-factor value(Av): ",
"Enter the high potential node(k) to which the controlled voltage source is connected: ",
"Enter the low potential node(l) to which the controlled voltage source is connected: ",
"Enter the high potential node(m) to which the controlling voltage is connected: ",
"Enter the low potential node(n) to which the controlling voltage is connected: ",
];
return fields_to_ask;
}
if (ele_code == 6) {
ele_count["cccs_gen"] = ele_count["cccs_gen"] + 1;
var fields_to_ask = [
"Enter the control-factor value(Al): ",
"Enter the high potential node(k) to which the controlled current source is connected: ",
"Enter the low potential node(l) to which the controlled current source is connected: ",
"Enter the high potential node(m) from which the controlling current flows: ",
"Enter the low potential node(n) from which the controlling current flows: ",
];
return fields_to_ask;
}
if (ele_code == 7) {
ele_count["cccs_vs"] = ele_count["cccs_vs"] + 1;
var fields_to_ask = [
"Enter the control-factor value:(Al) ",
"Enter the high potential node(k) to which the controlled current source is connected: ",
"Enter the low potential node(l) to which the controlled current source is connected: ",
"Enter the high potential node(m) from which the controlling current flows:",
"Enter the low potential node(n) from which the controlling current flows: ",
];
return fields_to_ask;
}
if (ele_code == 8) {
ele_count["ccvs_gen"] = ele_count["ccvs_gen"] + 1;
var fields_to_ask = [
"Enter the trans-resistance value (Rm in ohms): ",
"Enter the high potential node(k) to which the controlled voltage source is connected: ",
"Enter the low potential node(l) to which the controlled voltage source is connected: ",
"Enter the high potential node(m) from which the controlling current flows: ",
"Enter the low potential node(n) from which the controlling current flows: ",
];
return fields_to_ask;
}
if (ele_code == 9) {
ele_count["ccvs_vs"] = ele_count["ccvs_vs"] + 1;
var fields_to_ask = [
"Enter the trans-resistance value(Rm): ",
"Enter the high potential node(k) to which the controlled voltage source is connected: ",
"Enter the low potential node(l) to which the controlled voltage source is connected: ",
"Enter the high potential node(m) from which the controlling current flows: ",
"Enter the low potential node(n) from which the controlling current flows: ",
];
return fields_to_ask;
}
}
function showdialog() {
var elements = parseFloat(document.getElementById("elements").value);
var nodes = parseFloat(document.getElementById("nodes").value);
if (
Number.isInteger(elements) &&
Number.isInteger(nodes) &&
elements > 0 &&
nodes > 0
) {
if (
document.getElementById("ele-code") &&
document.getElementById("final-inputs")
) {
document.getElementById("ele-code").remove();
document.getElementById("final-inputs").remove();
var form = document.createElement("form");
form.setAttribute("id", "ele-code");
form.setAttribute("class", "animate__animated animate__backInUp");
for (i = 0; i < elements; i++) {
var div = document.createElement("div");
div.setAttribute("class", "input-group row ");
var span = document.createElement("span");
span.setAttribute(
"class",
"input-group-text input-group-prepend col-md-5"
);
span.setAttribute("id", "basic-addon1");
span.innerHTML = "Element of kind " + (i + 1);
div.appendChild(span);
var dropdown = document.createElement("div");
dropdown.setAttribute("class", "btn-group dropdown col-md-7");
var button = document.createElement("button");
button.setAttribute("type", "button");
button.setAttribute(
"class",
"btn btn-secondary btn-lg dropdown-toggle"
);
var menu = document.createElement("select");
menu.setAttribute("class", "");
menu.setAttribute("id", "ele_code" + (i + 1));
menu.required = true;
var selected = document.createElement("option");
selected.innerHTML = "";
menu.appendChild(selected);
var option1 = document.createElement("option");
option1.innerHTML = "Resistor";
menu.appendChild(option1);
var option2 = document.createElement("option");
option2.innerHTML = "Current Source";
menu.appendChild(option2);
var option3 = document.createElement("option");
option3.innerHTML = "Voltage Source";
menu.appendChild(option3);
var option4 = document.createElement("option");
option4.innerHTML = "Voltage Controlled Current Source";
menu.appendChild(option4);
var option5 = document.createElement("option");
option5.innerHTML = "Voltage Controlled Voltage Source";
menu.appendChild(option5);
var option6 = document.createElement("option");
option6.innerHTML = "Current Controlled Current Source(General)";
menu.appendChild(option6);
var option7 = document.createElement("option");
option7.innerHTML = "Current Controlled Current Source(Vs)";
menu.appendChild(option7);
var option8 = document.createElement("option");
option8.innerHTML = "Current Controlled Voltage Source(General)";
menu.appendChild(option8);
var option9 = document.createElement("option");
option9.innerHTML = "Current Controlled Voltage Source(Vs)";
menu.appendChild(option9);
dropdown.appendChild(menu);
div.appendChild(dropdown);
form.appendChild(div);
}
var div_btn = document.createElement("div");
div_btn.setAttribute("class", "col-md-12 text-center");
var s = document.createElement("button");
s.innerHTML = "Submit";
s.setAttribute("onclick", "getInputs()");
s.setAttribute("type", "button");
s.setAttribute("class", "btn btn-green submit");
div_btn.appendChild(s);
form.appendChild(div_btn);
document.body.appendChild(form);
} else if (document.getElementById("ele-code")) {
document.getElementById("ele-code").remove();
var form = document.createElement("form");
form.setAttribute("id", "ele-code");
form.setAttribute("class", "animate__animated animate__backInUp");
for (i = 0; i < elements; i++) {
var div = document.createElement("div");
div.setAttribute("class", "input-group row ");
var span = document.createElement("span");
span.setAttribute(
"class",
"input-group-text input-group-prepend col-md-5"
);
span.setAttribute("id", "basic-addon1");
span.innerHTML = "Element kind of " + (i + 1);
div.appendChild(span);
var dropdown = document.createElement("div");
dropdown.setAttribute("class", "btn-group dropdown col-md-7");
var button = document.createElement("button");
button.setAttribute("type", "button");
button.setAttribute(
"class",
"btn btn-secondary btn-lg dropdown-toggle"
);
var menu = document.createElement("select");
menu.setAttribute("class", "");
menu.setAttribute("id", "ele_code" + (i + 1));
menu.required = true;
var selected = document.createElement("option");
selected.innerHTML = "";
menu.appendChild(selected);
var option1 = document.createElement("option");
option1.innerHTML = "Resistor";
menu.appendChild(option1);
var option2 = document.createElement("option");
option2.innerHTML = "Current Source";
menu.appendChild(option2);
var option3 = document.createElement("option");
option3.innerHTML = "Voltage Source";
menu.appendChild(option3);
var option4 = document.createElement("option");
option4.innerHTML = "Voltage Controlled Current Source";
menu.appendChild(option4);
var option5 = document.createElement("option");
option5.innerHTML = "Voltage Controlled Voltage Source";
menu.appendChild(option5);
var option6 = document.createElement("option");
option6.innerHTML = "Current Controlled Current Source(General)";
menu.appendChild(option6);
var option7 = document.createElement("option");
option7.innerHTML = "Current Controlled Current Source(Vs)";
menu.appendChild(option7);
var option8 = document.createElement("option");
option8.innerHTML = "Current Controlled Voltage Source(General)";
menu.appendChild(option8);
var option9 = document.createElement("option");
option9.innerHTML = "Current Controlled Voltage Source(Vs)";
menu.appendChild(option9);
dropdown.appendChild(menu);
div.appendChild(dropdown);
form.appendChild(div);
}
var div_btn = document.createElement("div");
div_btn.setAttribute("class", "col-md-12 text-center");
var s = document.createElement("button");
s.innerHTML = "Submit";
s.setAttribute("onclick", "getInputs()");
s.setAttribute("type", "button");
s.setAttribute("class", "btn btn-green submit");
div_btn.appendChild(s);
form.appendChild(div_btn);
document.body.appendChild(form);
} else {
var form = document.createElement("form");
form.setAttribute("id", "ele-code");
form.setAttribute("class", "animate__animated animate__backInUp");
for (i = 0; i < elements; i++) {
var div = document.createElement("div");
div.setAttribute("class", "input-group row ");
var span = document.createElement("span");
span.setAttribute(
"class",
"input-group-text input-group-prepend col-md-5"
);
span.setAttribute("id", "basic-addon1");
span.innerHTML = "Element kind of " + (i + 1);
div.appendChild(span);
var dropdown = document.createElement("div");
dropdown.setAttribute("class", "btn-group dropdown col-md-7");
var button = document.createElement("button");
button.setAttribute("type", "button");
button.setAttribute(
"class",
"btn btn-secondary btn-lg dropdown-toggle"
);
var menu = document.createElement("select");
menu.setAttribute("class", "");
menu.setAttribute("id", "ele_code" + (i + 1));
menu.required = true;
var selected = document.createElement("option");
selected.innerHTML = "";
menu.appendChild(selected);
var option1 = document.createElement("option");
option1.innerHTML = "Resistor";
menu.appendChild(option1);
var option2 = document.createElement("option");
option2.innerHTML = "Current Source";
menu.appendChild(option2);
var option3 = document.createElement("option");
option3.innerHTML = "Voltage Source";
menu.appendChild(option3);
var option4 = document.createElement("option");
option4.innerHTML = "Voltage Controlled Current Source";
menu.appendChild(option4);
var option5 = document.createElement("option");
option5.innerHTML = "Voltage Controlled Voltage Source";
menu.appendChild(option5);
var option6 = document.createElement("option");
option6.innerHTML = "Current Controlled Current Source(General)";
menu.appendChild(option6);
var option7 = document.createElement("option");
option7.innerHTML = "Current Controlled Current Source(Vs)";
menu.appendChild(option7);
var option8 = document.createElement("option");
option8.innerHTML = "Current Controlled Voltage Source(General)";
menu.appendChild(option8);
var option9 = document.createElement("option");
option9.innerHTML = "Current Controlled Voltage Source(Vs)";
menu.appendChild(option9);
dropdown.appendChild(menu);
div.appendChild(dropdown);
form.appendChild(div);
}
var div_btn = document.createElement("div");
div_btn.setAttribute("class", "col-md-12 text-center");
var s = document.createElement("button");
s.innerHTML = "Submit";
s.setAttribute("onclick", "getInputs()");
s.setAttribute("type", "button");
s.setAttribute("class", "btn btn-green submit");
div_btn.appendChild(s);
form.appendChild(div_btn);
document.body.appendChild(form);
}
} else {
alert(
"Please enter valid inputs!! \nInstructions: \n1.No fields must be empty \n2.Inputs must be positive integers"
);
}
}
function getInputs() {
ele_code = [];
function getKeyByValue(object, value) {
return Object.keys(object).find((key) => object[key] === value);
}
var elements = parseInt(document.getElementById("elements").value);
for (var i = 0; i < parseInt(elements); i++) {
var code = getKeyByValue(
ele_code_value,
document.getElementById("ele_code" + (i + 1)).value
);
ele_code.push(code);
}
function checkcode(code) {
return code >= 1 && code <= 9;
}
if (!ele_code.some(isNaN) && ele_code.every(checkcode)) {
if (document.getElementById("final-inputs")) {
input_fields = [];
document.getElementById("final-inputs").remove();
for (var i = 0; i < ele_code.length; i++) {
var input_field = get_input_fields(ele_code[i]);
input_fields.push(input_field);
}
var form = document.createElement("form");
form.setAttribute(
"class",
"container values animate__animated animate__fadeInUp"
);
form.setAttribute("id", "final-inputs");
// form.setAttribute("id", "scrollto");
form.setAttribute("autocomplete", "off");
for (i = 0; i < input_fields.length; i++) {
var div1 = document.createElement("div");
div1.setAttribute("class", "input");
var heading = document.createElement("h4");
heading.innerHTML =
"Element" + (i + 1) + " : " + ele_code_value[ele_code[i]];
div1.appendChild(heading);
var div_close = document.createElement("div");
div_close.setAttribute("class", "row");
// var img = document.createElement("div")
// img.setAttribute("class", "row")
var img_div = document.createElement("div");
img_div.setAttribute("class", "col-md-6");
var img_src = document.createElement("img");
img_src.setAttribute("src", img_dir[ele_code[i]]);
img_src.setAttribute("class", "image");
img_div.appendChild(img_src);
// img.appendChild(img_div)
div_close.appendChild(img_div);
var input_div = document.createElement("div");
input_div.setAttribute("class", "col-md-6 input-div");
for (var j = 0; j < input_fields[i].length; j++) {
var div_row = document.createElement("div");
div_row.setAttribute("class", "row py-4");
var div_2 = document.createElement("div");
div_2.setAttribute("class", "col-lg-8");
var div = document.createElement("div");
div.setAttribute("class", "row");
var span = document.createElement("span");
span.setAttribute("class", "col-md-8 span-text");
// span.setAttribute("id", "basic-addon1");
span.innerHTML = input_fields[i][j];
div.appendChild(span);
var IN = document.createElement("input");
IN.setAttribute("type", "text");
IN.setAttribute("id", i + "&" + j);
IN.setAttribute("class", "col-md-4 input-reset");
div.appendChild(IN);
div_2.appendChild(div);
div_row.appendChild(div_2);
// div1.appendChild(div_row);
input_div.appendChild(div_row);
}
div_close.appendChild(input_div);
div1.appendChild(div_close);
form.appendChild(div1);
}
var s = document.createElement("button");
s.innerHTML = "Submit";
s.setAttribute("onclick", "printResults()");
s.setAttribute("type", "button");
s.setAttribute("class", "btn btn-green submit");
s.setAttribute("data-toggle", "modal");
s.setAttribute("data-target", "#output");
form.appendChild(s);
document.body.appendChild(form);
var container = document.body,
element = document.getElementById("final-inputs");
container.scrollTop = element.offsetTop;
} else {
input_fields = [];
for (var i = 0; i < ele_code.length; i++) {
var input_field = get_input_fields(ele_code[i]);
input_fields.push(input_field);
}
var form = document.createElement("form");
form.setAttribute(
"class",
"container values animate__animated animate__fadeInUp"
);
form.setAttribute("id", "final-inputs");
// form.setAttribute("id", "scrollto");
form.setAttribute("autocomplete", "off");
// for (i = 0; i < input_fields.length; i++) {
// var div1 = document.createElement("div");
// div1.setAttribute("class", "input");
// var heading = document.createElement("h4");
// heading.innerHTML =
// "Element" + (i + 1) + " :" + ele_code_value[ele_code[i]];
// div1.appendChild(heading);
// for (var j = 0; j < input_fields[i].length; j++) {
// var div_row = document.createElement("div");
// div_row.setAttribute("class", "row py-4");
// var div_2 = document.createElement("div");
// div_2.setAttribute("class", "col-lg-8");
// var div = document.createElement("div");
// div.setAttribute("class", "row");
// var span = document.createElement("span");
// span.setAttribute("class", "col-md-8 span-text");
// // span.setAttribute("id", "basic-addon1");
// span.innerHTML = input_fields[i][j];
// div.appendChild(span);
// var IN = document.createElement("input");
// IN.setAttribute("type", "text");
// IN.setAttribute("id", i + "&" + j);
// IN.setAttribute("class", "col-md-4");
// div.appendChild(IN);
// div_2.appendChild(div);
// div_row.appendChild(div_2);
// div1.appendChild(div_row);
// }
// form.appendChild(div1);
// }
for (i = 0; i < input_fields.length; i++) {
var div1 = document.createElement("div");
div1.setAttribute("class", "input");
var heading = document.createElement("h4");
heading.innerHTML =
"Element" + (i + 1) + " : " + ele_code_value[ele_code[i]];
div1.appendChild(heading);
var div_close = document.createElement("div");
div_close.setAttribute("class", "row");
// var img = document.createElement("div")
// img.setAttribute("class", "row")
var img_div = document.createElement("div");
img_div.setAttribute("class", "col-md-6");
var img_src = document.createElement("img");
img_src.setAttribute("class", "image");
img_src.setAttribute("src", img_dir[ele_code[i]]);
img_div.appendChild(img_src);
// img.appendChild(img_div)
div_close.appendChild(img_div);
var input_div = document.createElement("div");
input_div.setAttribute("class", "col-md-6 input-div");
for (var j = 0; j < input_fields[i].length; j++) {
var div_row = document.createElement("div");
div_row.setAttribute("class", "row py-4");
var div_2 = document.createElement("div");
div_2.setAttribute("class", "col-lg-8");
var div = document.createElement("div");
div.setAttribute("class", "row");
var span = document.createElement("span");
span.setAttribute("class", "col-md-8 span-text");
// span.setAttribute("id", "basic-addon1");
span.innerHTML = input_fields[i][j];
div.appendChild(span);
var IN = document.createElement("input");
IN.setAttribute("type", "text");
IN.setAttribute("id", i + "&" + j);
IN.setAttribute("class", "col-md-4 input-reset");
div.appendChild(IN);
div_2.appendChild(div);
div_row.appendChild(div_2);
// div1.appendChild(div_row);
input_div.appendChild(div_row);
}
div_close.appendChild(input_div);
div1.appendChild(div_close);
form.appendChild(div1);
}
var s = document.createElement("button");
s.innerHTML = "Submit";
s.setAttribute("onclick", "printResults()");
s.setAttribute("type", "button");
s.setAttribute("class", "btn btn-green submit");
s.setAttribute("data-toggle", "modal");
s.setAttribute("data-target", "#output");
form.appendChild(s);
document.body.appendChild(form);
var container = document.body,
element = document.getElementById("final-inputs");
container.scrollTop = element.offsetTop;
}
} else {
// var error = document.createElement("h4");
// error.innerHTML = "Please enter valid inputs";
// error.setAttribute("id", "error1");
// document.body.appendChild(error);
alert("Please enter valid inputs");
}
}
function printResults() {
var elements = parseInt(document.getElementById("elements").value);
//Static method of creating the matrix and fixing the size
var nodes = parseInt(document.getElementById("nodes").value);
var size = parseInt(nodes) + ele_count["volt_src"] + ele_count["vcvs"];
console.log("cond_matrix1: ", JSON.stringify(cond_matrix));
cond_matrix = Array(size)
.fill()
.map(() => Array(size).fill(0));
console.log("cond_matrix2: ", JSON.stringify(cond_matrix));
var curr_matrix = Array(size)
.fill()
.map(() => Array(1).fill(0));
var var_matrix = Array(size)
.fill()
.map(() => Array(1).fill(0));
var var_list = [];
for (let i = 0; i < nodes; i++) {
var_list.push("V_" + String(i + 1));
}
// Variable for selecting apt the column of conductance and current matrix
var obj_volt_src_cnt = 0;
var obj_vccs_cnt = 0; // Variable for selecting the apt column if the element is a vccs
var obj_vcvs_cnt = 0;
var obj_cccs_gen_cnt = 0;
var obj_cccs_vs_cnt = 0;
var obj_ccvs_gen_cnt = 0;
var obj_ccvs_vs_cnt = 0;
for (i = 0; i < input_fields.length; i++) {
var field_values = [];
for (var j = 0; j < input_fields[i].length; j++) {
var field_value = parseFloat(document.getElementById(i + "&" + j).value);
field_values.push(field_value);
}
field_values_final.push(field_values);
}
for (var k = 0; k < elements; k++) {
if (ele_code[k] == 1) {
var code = 1;
var r_val = field_values_final[k][0];
var n_h = field_values_final[k][1];
var n_l = field_values_final[k][2];
const res = new resistor(code, r_val, n_h, n_l);
resistor_list.push(res);
} else if (ele_code[k] == 2) {
var code = 2;
var i_val = field_values_final[k][0];
var n_h = field_values_final[k][1];
var n_l = field_values_final[k][2];
var curr = new curr_src(code, i_val, n_h, n_l);
curr_src_list.push(curr);
} else if (ele_code[k] == 3) {
var code = 3;
var v_val = field_values_final[k][0];
var n_h = field_values_final[k][1];
var n_l = field_values_final[k][2];
var volt = new volt_src(code, v_val, n_h, n_l);
volt_src_list.push(volt);
} else if (ele_code[k] == 4) {
var code = 4;
var tr_con = field_values_final[k][0];
var n_h = field_values_final[k][1];
var n_l = field_values_final[k][2];
var cont_n_h = field_values_final[k][3];
var cont_n_l = field_values_final[k][4];
var vccsList = new vccs(code, tr_con, n_h, n_l, cont_n_h, cont_n_l);
vccs_list.push(vccsList);
} else if (ele_code[k] == 5) {
var code = 5;
var cont_ftr = field_values_final[k][0];
var n_h = field_values_final[k][1];
var n_l = field_values_final[k][2];
var cont_n_h = field_values_final[k][3];
var cont_n_l = field_values_final[k][4];
var vcvsList = new vcvs(code, cont_ftr, n_h, n_l, cont_n_h, cont_n_l);
vcvs_list.push(vcvsList);
} else if (ele_code[k] == 6) {
var code = 6;
var con_ftr = field_values_final[k][0];
var n_h = field_values_final[k][1];
var n_l = field_values_final[k][2];
var cont_n_h = field_values_final[k][3];
var cont_n_l = field_values_final[k][4];
var cccsGen = new cccs_gen(code, con_ftr, n_h, n_l, cont_n_h, cont_n_l);
cccs_gen_list.push(cccsGen);
} else if (ele_code[k] == 7) {
var code = 7;
var con_ftr = field_values_final[k][0];
var n_h = field_values_final[k][1];
var n_l = field_values_final[k][2];
var cont_n_h = field_values_final[k][3];
var cont_n_l = field_values_final[k][4];
var cccsVs = new cccs_vs(code, con_ftr, n_h, n_l, cont_n_h, cont_n_l);
cccs_vs_list.push(cccsVs);
} else if (ele_code[k] == 8) {
var code = 8;
var tr_res = field_values_final[k][0];
var n_h = field_values_final[k][1];
var n_l = field_values_final[k][2];
var cont_n_h = field_values_final[k][3];
var cont_n_l = field_values_final[k][4];
var ccvsGen = new ccvs_gen(code, tr_res, n_h, n_l, cont_n_h, cont_n_l);
ccvs_gen_list.push(ccvsGen);
} else if (ele_code[k] == 9) {
var code = 9;
var tr_res = field_values_final[k][0];
var n_h = field_values_final[k][1];
var n_l = field_values_final[k][2];
var cont_n_h = field_values_final[k][3];
var cont_n_l = field_values_final[k][4];
var ccvsVs = new ccvs_vs(code, tr_res, n_h, n_l, cont_n_h, cont_n_l);
ccvs_vs_list.push(ccvsVs);
}
}
for (var obj = 0; obj < curr_src_list.length; obj++) {
// Contributes only to cuurent matrix
var n_k = parseInt(curr_src_list[obj].node_high) - 1;
var n_l = parseInt(curr_src_list[obj].node_low) - 1;
var current = parseFloat(curr_src_list[obj].current);
if (n_k != -1 && n_l != -1) {
curr_matrix[n_k][0] += current;
curr_matrix[n_l][0] -= current;
} else if (n_k == -1 && n_l != -1) {
curr_matrix[n_l][0] -= current;
} else if (n_k != -1 && n_l == -1) {
curr_matrix[n_k][0] += current;
}
}
for (var obj = 0; obj < volt_src_list.length; obj++) {
// The following code is only when there is one voltage source in the circuit
// Contributes to both current and conductance matrix
var n_k = parseInt(volt_src_list[obj].node_high) - 1;
var n_l = parseInt(volt_src_list[obj].node_low) - 1;
var voltage = parseFloat(volt_src_list[obj].voltage);
var count = 0;
var new_var = "I_" + String(n_k + 1) + "_" + String(n_l + 1);
for (var i = 0; i < var_list.length; i++) {
if (var_list[i] == new_var) {
count = count + 1;
}
}
if (count == 0) {
var_list.push(new_var);
}
var idx = var_list.indexOf(new_var);
if (n_k != -1 && n_l != -1) {
cond_matrix[n_k][idx] += 1;
cond_matrix[n_l][idx] -= 1;
cond_matrix[idx][n_k] += 1;
cond_matrix[idx][n_l] -= 1;
curr_matrix[idx][0] += voltage;
obj_volt_src_cnt += 1;
} else if (n_k == -1 && n_l != -1) {
cond_matrix[n_l][idx] -= 1;
cond_matrix[idx][n_l] -= 1;
curr_matrix[idx][0] += voltage;
obj_volt_src_cnt += 1;
} else if (n_l == -1 && n_k != -1) {
cond_matrix[n_k][idx] += 1;
cond_matrix[idx][n_k] += 1;
curr_matrix[idx][0] += voltage;
obj_volt_src_cnt += 1;
}
}
for (var obj = 0; obj < vccs_list.length; obj++) {
var n_k = parseInt(vccs_list[obj].node_high) - 1;
var n_l = parseInt(vccs_list[obj].node_low) - 1;
var ctrl_n_m = parseInt(vccs_list[obj].control_vol_node_high) - 1;
var ctrl_n_n = parseInt(vccs_list[obj].control_vol_node_low) - 1;
var transconductance = parseFloat(vccs_list[obj].trans_conductance);
if (n_k != -1 && n_l != -1 && ctrl_n_m != -1 && ctrl_n_n != -1) {
cond_matrix[n_k][ctrl_n_m] += transconductance;
cond_matrix[n_k][ctrl_n_n] -= transconductance;
cond_matrix[n_l][ctrl_n_m] -= transconductance;
cond_matrix[n_l][ctrl_n_n] += transconductance;
} else if (n_k == -1 && n_l != -1 && ctrl_n_m != -1 && ctrl_n_n != -1) {
cond_matrix[n_l][ctrl_n_m] -= transconductance;
cond_matrix[n_l][ctrl_n_n] += transconductance;
} else if (n_k != -1 && n_l == -1 && ctrl_n_m != -1 && ctrl_n_n != -1) {
cond_matrix[n_k][ctrl_n_m] += transconductance;
cond_matrix[n_k][ctrl_n_n] -= transconductance;
} else if (n_k != -1 && n_l != -1 && ctrl_n_m == -1 && ctrl_n_n != -1) {
cond_matrix[n_k][ctrl_n_n] -= transconductance;
cond_matrix[n_l][ctrl_n_n] += transconductance;
} else if (n_k != -1 && n_l != -1 && ctrl_n_m != -1 && ctrl_n_n == -1) {
cond_matrix[n_k][ctrl_n_m] += transconductance;
cond_matrix[n_l][ctrl_n_m] -= transconductance;
} else if (n_k == -1 && n_l != -1 && ctrl_n_m == -1 && ctrl_n_n != -1) {
cond_matrix[n_l][ctrl_n_n] += transconductance;
} else if (n_k == -1 && n_l != -1 && ctrl_n_m != -1 && ctrl_n_n == -1) {
cond_matrix[n_l][ctrl_n_m] -= transconductance;
} else if (n_k != -1 && n_l == -1 && ctrl_n_m == -1 && ctrl_n_n != -1) {
cond_matrix[n_k][ctrl_n_n] -= transconductance;
} else if (n_k != -1 && n_l == -1 && ctrl_n_m != -1 && ctrl_n_n == -1) {
cond_matrix[n_k][ctrl_n_m] += transconductance;