[Prev][Next][Index][Thread]

Re: (source code)Tesla coil voltage and electric field simulation in DOS



    [The following text is in the "ISO-8859-1" character set]
    [Your display is set for the "US-ASCII" character set]
    [Some characters may be displayed incorrectly]



> Subscriber: ed-at-alumni.caltech.edu Fri Jan 17 22:40:38 1997
> Date: Fri, 17 Jan 1997 08:25:27 -0800 (PST)
> From: "Edward V. Phillips" <ed-at-alumni.caltech.edu>
> To: tesla-at-pupman-dot-com
> Subject: Re: Tesla coil voltage and electric field simulation in DOS
> 
> Ed:
> 	Had intended to ask you if you could compute capacitance.
> "I hope to have a version (or Wes B will)
> which can actually compute some realistic numbers for system
(coil+torriod)
> capacitance sometime. "
> 	Also, since beggers can be choosers, if it would be possible
> to get the output in tabular form in addition to the graphic display.
> The displayed results must be stored in a table.  Also, it would be
> nice to be able to enter the terminal (and coil) parameters numerically.
> Again, many thanks.
> Ed Phillips

Hi Ed, all,

I guess you could get rudimentary capacitance numbers from the thing right
now, but I kinda wanted to do something better first. It looks like from
conversations with Wes, that most likely he'll have the better program
before me.

As for the other enhancements, beg and ye shall receive! (almost) Actually
since I know that you're a QB programmer I'll just send along the
source code with all the embarrasing "fluff" code. It's juts a simple
relaxation computation with a special grid suited for cylindrical
symmetery.
All the boundries are reset after each iteration. Anyway, by adjusting the
boundry resetting you can put in anyterminal you like -- as long as its
got symmetry of rotation about the coil axis.


For your further amusement,
-Ed Harris

-------------------------- begin source code
----------------------------------------------
CLS
PRINT "Program to solve laplace's equation in cylindrical"
PRINT "coordinates. Boundry conditions are chosen in the present"
PRINT "case to simulate a tesla coil with a torroid on top at the"
PRINT "same voltage as the top of the coil."
PRINT "The boundry for the 'roof' and 'walls' is approximated"
PRINT "physically by a high dielectric constant  material"
PRINT "Voltage along coil assumed to rise linearly"
PRINT "Fields computed without presence of corona"
PRINT
PRINT "Voltages and field magnitudes are displayed in bands of color"
PRINT "The plot shows a 2-d cross section of the coil and torroid"
PRINT "for decent accuracy program should 'relax' for over 5000 iterations"
PRINT
PRINT "Discharge terminal type :torroid,sphere, none can be toggled(t key)"
PRINT "while the program runs. The terminal height, major and minor"
PRINT "diameters may also be adjusted (keys 1-6)."
PRINT "Voltage plot (v key) or E-field magnitude (e key) may be toggled."
PRINT "DO NOT hold keys down - press them only once per change"

PRINT
PRINT "Ed Harris (harris.26-at-osu.edu) sept 1995 version 1.0"


PRINT
INPUT "press enter to continue"; k$


SCREEN 7
CLS
DIM v(100, 120)


LOCATE 8, 1
PRINT "Magnitudes"
PRINT "0-10 black"
COLOR 1
PRINT "10-20"
COLOR 2
PRINT "20-30"
COLOR 3
PRINT "30-40"
COLOR 4
PRINT "40-50"
COLOR 5
PRINT "50-60"
COLOR 6
PRINT "60-70"
COLOR 7
PRINT "70-80"
COLOR 8
PRINT "80-90"
COLOR 9
PRINT "90-100"
COLOR 10
PRINT "100-110"

'torroid/sphere dimensions
radius = 30
height = 70
rcross = 10

' terminal flag
' t%=0 no terminal
' t%=1 torroid
' t%=2 sphere
t% = 1

'display map flag
dm% = 1     'potential


i = 0
count = 0
gloop:
i = i + 1
count = count + 1
IF i > 10 THEN GOTO display
'********************* boundry reset ****************************

'draw the ground ,coil and terminal
LINE (100, 180)-(400, 180), 9
LINE (180 + 15, 180 - 10)-(180 + 15, 180 - 55), 0
LINE (180 - 15, 180 - 10)-(180 - 15, 180 - 55), 0

IF t% = 1 THEN
CIRCLE (180 - radius, 180 - height), rcross, 0
CIRCLE (180 + radius, 180 - height), rcross, 0
END IF

IF t% = 2 THEN
CIRCLE (180, 180 - height), rcross, 0
END IF

'resest boundries
'ground and sky
FOR r% = 1 TO 100
v(r%, 1) = 0: v(r%, 120) = v(r%, 119)
NEXT r%

'center and outside
FOR z% = 1 TO 119
v(1, z%) = v(2, z%): v(100, z%) = v(99, z%)
NEXT z%

'coil
FOR z% = 10 TO 55
FOR r% = 14 TO 15
v(r%, z%) = (100 / 45) * (z% - 10)
NEXT r%
NEXT z%

'torroid
IF t% = 1 THEN
FOR p = 0 TO 6.28 STEP .05
r% = INT(rcross * COS(p) + radius)
z% = INT(rcross * SIN(p) + height)
v(r%, z%) = 100
NEXT p
END IF

'sphere
IF t% = 2 THEN
FOR p = 0 TO 6.28 STEP .05
r% = ABS(INT(rcross * COS(p)))
z% = INT(rcross * SIN(p) + height)
v(r%, z%) = 100
NEXT p
END IF

'relaxes the potential to satisfy the discrete laplace's
'equation for cylindrical coordinates
FOR r% = 2 TO 99
FOR z% = 2 TO 119
v(r%, z%) = -.5 * v(r%, z%) + 1.5 * .25 * (v(r%, z% + 1) + v(r%, z% - 1) +
((r% - .5) * v(r% - 1, z%) + (r% + .5) * v(r% + 1, z%)) / r%)
'v(r%, z%) = .25 * (v(r%, z% + 1) + v(r%, z% - 1) + ((r% - .5) * v(r% - 1,
z%) + (r% + .5) * v(r% + 1, z%)) / r%)
NEXT z%
NEXT r%


GOTO gloop
display:
'********************* boundry reset ****************************
'ground and sky
FOR r% = 1 TO 100
v(r%, 1) = 0: v(r%, 120) = v(r%, 119)
NEXT r%

'center and outside
FOR z% = 1 TO 119
v(1, z%) = v(2, z%): v(100, z%) = v(99, z%)
NEXT z%

'coil
FOR z% = 10 TO 55
v(15, z%) = (100 / 45) * (z% - 10)
NEXT z%

'torroid
IF t% = 1 THEN
FOR p = 0 TO 6.28 STEP .05
r% = INT(rcross * COS(p) + radius)
z% = INT(rcross * SIN(p) + height)
v(r%, z%) = 100
NEXT p
END IF

'sphere
IF t% = 2 THEN
FOR p = 0 TO 6.28 STEP .05
r% = ABS(INT(rcross * COS(p)))
z% = INT(rcross * SIN(p) + height)
v(r%, z%) = 100
NEXT p
END IF



b$ = INKEY$
IF b$ <> "" AND b$ <> "v" AND b$ <> "e" THEN count = 0

' dimensional change commands
IF b$ = "1" AND height + rcross < 115 THEN height = height + 5
IF b$ = "2" AND height - rcross > 45 THEN height = height - 5
IF b$ = "3" AND rcross + radius < 95 AND rcross + height < 115 AND height -
rcross > 5 AND radius - rcross > 5 THEN rcross = rcross + 3
IF b$ = "4" AND rcross >= 3 THEN rcross = rcross - 3
IF b$ = "5" AND rcross + radius < 95 THEN radius = radius + 3
IF b$ = "6" AND radius - rcross > 4 THEN radius = radius - 3

' terminal choice
IF b$ = "t" THEN t% = t% + 1
IF t% > 2 THEN t% = 0
LOCATE 20, 1
COLOR 4
PRINT "TERMINAL "
IF t% = 0 THEN PRINT "none   "
IF t% = 1 THEN PRINT "Torroid"
IF t% = 2 THEN PRINT "Sphere "
COLOR 6
PRINT "DISPLAY"
IF dm% = 1 THEN PRINT "Voltage"
IF dm% = 2 THEN PRINT "E-Field"

'exit
IF b$ = "q" THEN STOP

' disply map flag
IF b$ = "e" THEN dm% = 2
IF b$ = "v" THEN dm% = 1

LOCATE 1, 1
PRINT "Error", "Iteration"
PRINT s, count; "    "
PRINT "Press v> potential map, e> E field map"
COLOR 3
PRINT "Terminal height: press 1> up 2> down"
PRINT "Terminal radius:  3> larger 4>smaller"
PRINT "Torroid major dia: 5> larger 6>smaller"
COLOR 5
PRINT "Press t> toggle terminal type, q> exit"

' plots the voltage in color bands
IF dm% = 1 THEN
s = 0
FOR r% = 2 TO 99
FOR z% = 2 TO 119
o = -.5 * v(r%, z%) + 1.5 * .25 * (v(r%, z% + 1) + v(r%, z% - 1) + ((r% -
.5) * v(r% - 1, z%) + (r% + .5) * v(r% + 1, z%)) / r%)
'o = .25 * (v(r%, z% + 1) + v(r%, z% - 1) + ((r% - .5) * v(r% - 1, z%) +
(r% + .5) * v(r% + 1, z%)) / r%)
d = (v(r%, z%) - o)
d = d * d
s = s + d
v(r%, z%) = o
modv = INT(o / 10)
PSET (180 + r%, 180 - z%), modv
PSET (180 - r%, 180 - z%), modv
NEXT z%
NEXT r%


END IF

IF dm% = 2 THEN
' computes the r and z components of the electric field and
'displays only their magnitude
FOR r% = 2 TO 99
FOR z% = 2 TO 119
ez = v(r%, z% + 1) - v(r%, z% - 1)
er = v(r% + 1, z%) - v(r% - 1, z%)
l = INT(SQR(ez * ez + er * er))
PSET (180 + r%, 180 - z%), l
PSET (180 - r%, 180 - z%), l
NEXT z%
NEXT r%
END IF

i = 0
GOTO gloop