Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
d470bc53
Commit
d470bc53
authored
Feb 08, 2012
by
Reda Lemeden
Browse files
Options
Browse Files
Download
Plain Diff
Merge with head
parents
52715238
9201fbe6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
27 deletions
+35
-27
js/cktsim.js
+11
-13
js/schematic.js
+24
-14
No files found.
js/cktsim.js
View file @
d470bc53
...
@@ -323,7 +323,7 @@ cktsim = (function() {
...
@@ -323,7 +323,7 @@ cktsim = (function() {
// Standard to do a dc analysis before transient
// Standard to do a dc analysis before transient
// Otherwise, do the setup also done in dc.
// Otherwise, do the setup also done in dc.
//
no_dc = true;
no_dc
=
true
;
if
((
this
.
diddc
==
false
)
&&
(
no_dc
==
false
))
this
.
dc
();
if
((
this
.
diddc
==
false
)
&&
(
no_dc
==
false
))
this
.
dc
();
else
{
else
{
// Allocate matrices and vectors.
// Allocate matrices and vectors.
...
@@ -394,9 +394,10 @@ cktsim = (function() {
...
@@ -394,9 +394,10 @@ cktsim = (function() {
this
.
oldc
[
i
]
=
this
.
c
[
i
];
this
.
oldc
[
i
]
=
this
.
c
[
i
];
}
}
var
step_index
=
-
2
;
// Start with two pseudo-Euler steps
var
beta0
,
beta1
;
var
beta0
,
beta1
;
while
(
this
.
time
<=
tstop
)
{
// Start with two pseudo-Euler steps, maximum 50000 steps
for
(
var
step_index
=
-
3
;
step_index
<
50000
;
step_index
++
)
{
// Save the just computed solution, and move back q and c.
// Save the just computed solution, and move back q and c.
for
(
var
i
=
this
.
N
-
1
;
i
>=
0
;
--
i
)
{
for
(
var
i
=
this
.
N
-
1
;
i
>=
0
;
--
i
)
{
if
(
step_index
>=
0
)
if
(
step_index
>=
0
)
...
@@ -437,9 +438,6 @@ cktsim = (function() {
...
@@ -437,9 +438,6 @@ cktsim = (function() {
beta1
=
0.5
;
beta1
=
0.5
;
}
}
// Keep track of step index.
step_index
+=
1
;
// For trap rule, turn off current avging for algebraic eqns
// For trap rule, turn off current avging for algebraic eqns
for
(
var
i
=
this
.
N
-
1
;
i
>=
0
;
--
i
)
{
for
(
var
i
=
this
.
N
-
1
;
i
>=
0
;
--
i
)
{
this
.
beta0
[
i
]
=
beta0
+
this
.
ar
[
i
]
*
beta1
;
this
.
beta0
[
i
]
=
beta0
+
this
.
ar
[
i
]
*
beta1
;
...
@@ -1301,8 +1299,8 @@ cktsim = (function() {
...
@@ -1301,8 +1299,8 @@ cktsim = (function() {
// MNA stamp for independent voltage source
// MNA stamp for independent voltage source
ckt
.
add_to_Gl
(
this
.
branch
,
this
.
npos
,
1.0
);
ckt
.
add_to_Gl
(
this
.
branch
,
this
.
npos
,
1.0
);
ckt
.
add_to_Gl
(
this
.
branch
,
this
.
nneg
,
-
1.0
);
ckt
.
add_to_Gl
(
this
.
branch
,
this
.
nneg
,
-
1.0
);
ckt
.
add_to_Gl
(
this
.
npos
,
this
.
branch
,
-
1.0
);
ckt
.
add_to_Gl
(
this
.
npos
,
this
.
branch
,
1.0
);
ckt
.
add_to_Gl
(
this
.
nneg
,
this
.
branch
,
1.0
);
ckt
.
add_to_Gl
(
this
.
nneg
,
this
.
branch
,
-
1.0
);
}
}
// Source voltage added to b.
// Source voltage added to b.
...
@@ -1486,8 +1484,8 @@ cktsim = (function() {
...
@@ -1486,8 +1484,8 @@ cktsim = (function() {
// MNA stamp for inductor linear part
// MNA stamp for inductor linear part
// L on diag of C because L di/dt = v(n1) - v(n2)
// L on diag of C because L di/dt = v(n1) - v(n2)
ckt
.
add_to_Gl
(
this
.
n1
,
this
.
branch
,
1
);
ckt
.
add_to_Gl
(
this
.
n1
,
this
.
branch
,
1
);
ckt
.
add_to_Gl
(
this
.
branch
,
this
.
n1
,
-
1
);
ckt
.
add_to_Gl
(
this
.
n2
,
this
.
branch
,
-
1
);
ckt
.
add_to_Gl
(
this
.
n2
,
this
.
branch
,
-
1
);
ckt
.
add_to_Gl
(
this
.
branch
,
this
.
n1
,
-
1
);
ckt
.
add_to_Gl
(
this
.
branch
,
this
.
n2
,
1
);
ckt
.
add_to_Gl
(
this
.
branch
,
this
.
n2
,
1
);
ckt
.
add_to_C
(
this
.
branch
,
this
.
branch
,
this
.
value
)
ckt
.
add_to_C
(
this
.
branch
,
this
.
branch
,
this
.
value
)
}
}
...
@@ -1529,10 +1527,10 @@ cktsim = (function() {
...
@@ -1529,10 +1527,10 @@ cktsim = (function() {
var
invA
=
1.0
/
this
.
gain
;
var
invA
=
1.0
/
this
.
gain
;
ckt
.
add_to_Gl
(
this
.
no
,
this
.
branch
,
1
);
ckt
.
add_to_Gl
(
this
.
no
,
this
.
branch
,
1
);
ckt
.
add_to_Gl
(
this
.
ng
,
this
.
branch
,
-
1
);
ckt
.
add_to_Gl
(
this
.
ng
,
this
.
branch
,
-
1
);
ckt
.
add_to_Gl
(
this
.
branch
,
this
.
no
,
-
invA
);
ckt
.
add_to_Gl
(
this
.
branch
,
this
.
no
,
invA
);
ckt
.
add_to_Gl
(
this
.
branch
,
this
.
ng
,
invA
);
ckt
.
add_to_Gl
(
this
.
branch
,
this
.
ng
,
-
invA
);
ckt
.
add_to_Gl
(
this
.
branch
,
this
.
np
,
1
);
ckt
.
add_to_Gl
(
this
.
branch
,
this
.
np
,
-
1
);
ckt
.
add_to_Gl
(
this
.
branch
,
this
.
nn
,
-
1
);
ckt
.
add_to_Gl
(
this
.
branch
,
this
.
nn
,
1
);
}
}
Opamp
.
prototype
.
load_dc
=
function
(
ckt
,
soln
,
rhs
)
{
Opamp
.
prototype
.
load_dc
=
function
(
ckt
,
soln
,
rhs
)
{
...
...
js/schematic.js
View file @
d470bc53
...
@@ -71,7 +71,7 @@ schematic = (function() {
...
@@ -71,7 +71,7 @@ schematic = (function() {
annotation_style
=
'rgb(255,64,64)'
;
// color for diagram annotations
annotation_style
=
'rgb(255,64,64)'
;
// color for diagram annotations
property_size
=
5
;
// point size for Component property text
property_size
=
5
;
// point size for Component property text
annotation_size
=
7
;
// point size for diagram annotations
annotation_size
=
6
;
// point size for diagram annotations
// list of all the defined parts
// list of all the defined parts
parts_map
=
{
parts_map
=
{
...
@@ -282,13 +282,11 @@ schematic = (function() {
...
@@ -282,13 +282,11 @@ schematic = (function() {
tr
=
document
.
createElement
(
'tr'
);
tr
=
document
.
createElement
(
'tr'
);
table
.
appendChild
(
tr
);
table
.
appendChild
(
tr
);
td
=
document
.
createElement
(
'td'
);
td
=
document
.
createElement
(
'td'
);
td
.
style
.
left
=
'0'
;
td
.
style
.
top
=
'0'
;
tr
.
appendChild
(
td
);
tr
.
appendChild
(
td
);
var
wrapper
=
document
.
createElement
(
'div'
);
var
wrapper
=
document
.
createElement
(
'div'
);
td
.
appendChild
(
wrapper
);
wrapper
.
style
.
position
=
'relative'
;
// so we can position subwindows
wrapper
.
style
.
position
=
'relative'
;
// so we can position subwindows
wrapper
.
appendChild
(
this
.
canvas
);
wrapper
.
appendChild
(
this
.
canvas
);
td
.
appendChild
(
wrapper
);
td
=
document
.
createElement
(
'td'
);
td
=
document
.
createElement
(
'td'
);
td
.
style
.
verticalAlign
=
'top'
;
td
.
style
.
verticalAlign
=
'top'
;
tr
.
appendChild
(
td
);
tr
.
appendChild
(
td
);
...
@@ -1182,7 +1180,7 @@ schematic = (function() {
...
@@ -1182,7 +1180,7 @@ schematic = (function() {
if
(
code
==
16
)
sch
.
shiftKey
=
false
;
if
(
code
==
16
)
sch
.
shiftKey
=
false
;
else
if
(
code
==
17
)
sch
.
ctrlKey
=
false
;
else
if
(
code
==
17
)
sch
.
ctrlKey
=
false
;
else
if
(
code
==
18
)
sch
.
altKey
=
false
;
else
if
(
code
==
18
)
sch
.
altKey
=
false
;
else
if
(
code
==
91
)
sch
.
c
omman
dKey
=
false
;
else
if
(
code
==
91
)
sch
.
c
m
dKey
=
false
;
}
}
function
schematic_mouse_enter
(
event
)
{
function
schematic_mouse_enter
(
event
)
{
...
@@ -1779,12 +1777,22 @@ schematic = (function() {
...
@@ -1779,12 +1777,22 @@ schematic = (function() {
// given a range of values, return a new range [vmin',vmax'] where the limits
// given a range of values, return a new range [vmin',vmax'] where the limits
// have been chosen "nicely". Taken from matplotlib.ticker.LinearLocator
// have been chosen "nicely". Taken from matplotlib.ticker.LinearLocator
function
view_limits
(
vmin
,
vmax
)
{
function
view_limits
(
vmin
,
vmax
)
{
// deal with degenerate case...
if
(
vmin
==
vmax
)
{
if
(
vmin
==
0
)
{
vmin
=
-
0.5
;
vmax
=
0.5
;
}
else
{
vmin
=
vmin
>
0
?
0.9
*
vmin
:
1.1
*
vmin
;
vmax
=
vmax
>
0
?
1.1
*
vmax
:
0.9
*
vmax
;
}
}
var
log_range
=
Math
.
log
(
vmax
-
vmin
)
/
Math
.
LN10
;
var
log_range
=
Math
.
log
(
vmax
-
vmin
)
/
Math
.
LN10
;
var
exponent
=
Math
.
floor
(
log_range
);
var
exponent
=
Math
.
floor
(
log_range
);
//if (log_range - exponent < 0.5) exponent -= 1;
//if (log_range - exponent < 0.5) exponent -= 1;
var
scale
=
Math
.
pow
(
10
,
-
exponent
);
var
scale
=
Math
.
pow
(
10
,
-
exponent
);
vmin
=
Math
.
floor
(
scale
*
vmin
)
/
scale
;
vmin
=
Math
.
floor
(
scale
*
vmin
)
/
scale
;
vmax
=
Math
.
ceil
(
scale
*
vmax
)
/
scale
;
vmax
=
Math
.
ceil
(
scale
*
vmax
)
/
scale
;
return
[
vmin
,
vmax
,
1.0
/
scale
];
return
[
vmin
,
vmax
,
1.0
/
scale
];
}
}
...
@@ -3192,7 +3200,7 @@ schematic = (function() {
...
@@ -3192,7 +3200,7 @@ schematic = (function() {
function
OpAmp
(
x
,
y
,
rotation
,
name
,
A
)
{
function
OpAmp
(
x
,
y
,
rotation
,
name
,
A
)
{
Component
.
call
(
this
,
'o'
,
x
,
y
,
rotation
);
Component
.
call
(
this
,
'o'
,
x
,
y
,
rotation
);
this
.
properties
[
'name'
]
=
name
;
this
.
properties
[
'name'
]
=
name
;
this
.
properties
[
'A'
]
=
A
?
A
:
'30000
0
'
;
this
.
properties
[
'A'
]
=
A
?
A
:
'30000'
;
this
.
add_connection
(
0
,
0
);
// +
this
.
add_connection
(
0
,
0
);
// +
this
.
add_connection
(
0
,
16
);
// -
this
.
add_connection
(
0
,
16
);
// -
this
.
add_connection
(
48
,
8
);
// output
this
.
add_connection
(
48
,
8
);
// output
...
@@ -3274,9 +3282,9 @@ schematic = (function() {
...
@@ -3274,9 +3282,9 @@ schematic = (function() {
//this.draw_line(c,3,20,0,28);
//this.draw_line(c,3,20,0,28);
}
else
if
(
this
.
type
==
'i'
)
{
// current source
}
else
if
(
this
.
type
==
'i'
)
{
// current source
// draw arrow: pos to neg
// draw arrow: pos to neg
this
.
draw_line
(
c
,
0
,
1
6
,
0
,
32
);
this
.
draw_line
(
c
,
0
,
1
5
,
0
,
32
);
this
.
draw_line
(
c
,
-
3
,
2
4
,
0
,
32
);
this
.
draw_line
(
c
,
-
3
,
2
6
,
0
,
32
);
this
.
draw_line
(
c
,
3
,
2
4
,
0
,
32
);
this
.
draw_line
(
c
,
3
,
2
6
,
0
,
32
);
}
}
if
(
this
.
properties
[
'name'
])
if
(
this
.
properties
[
'name'
])
...
@@ -3442,14 +3450,16 @@ schematic = (function() {
...
@@ -3442,14 +3450,16 @@ schematic = (function() {
var
v
=
vmap
[
label
];
var
v
=
vmap
[
label
];
if
(
v
!=
undefined
)
{
if
(
v
!=
undefined
)
{
// first draw some solid blocks in the background
// first draw some solid blocks in the background
c
.
globalAlpha
=
0.
8
5
;
c
.
globalAlpha
=
0.5
;
this
.
draw_text
(
c
,
'
\
u2588
\
u2588
\
u2588'
,
0
,
24
,
4
,
annotation_size
,
element_style
);
this
.
draw_text
(
c
,
'
\
u2588
\
u2588
\
u2588'
,
-
8
,
8
,
4
,
annotation_size
,
element_style
);
c
.
globalAlpha
=
1.0
;
c
.
globalAlpha
=
1.0
;
// display the
node voltage at this connection point
// display the
element current
var
i
=
engineering_notation
(
v
,
2
)
+
'A'
;
var
i
=
engineering_notation
(
v
,
2
)
+
'A'
;
this
.
draw_text
(
c
,
i
,
0
,
24
,
4
,
annotation_size
,
annotation_style
);
this
.
draw_text
(
c
,
i
,
-
3
,
5
,
5
,
annotation_size
,
annotation_style
);
// draw arrow for current
this
.
draw_line
(
c
,
-
3
,
4
,
0
,
8
);
this
.
draw_line
(
c
,
3
,
4
,
0
,
8
);
// only display each current once
// only display each current once
delete
vmap
[
label
];
delete
vmap
[
label
];
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment