Beispiel #1
0
from math import *

from vectorfieldplot import FieldplotDocument, Field, FieldLine

# ... https://github.com/CD3/VectorFieldPlot

# based on https://commons.wikimedia.org/wiki/File:VFPt_cylindrical_coil.svg
# author Geek3, GFDL

size = 0.6
proportion = 4
l = size * proportion
r = size * 1.0
exponent = 1.0 / 2.0  # run with exponent=1 to get a physically correct version

doc = FieldplotDocument('naughty-solenoid')
field = Field({'coils': [[0, 0, 0, r, l, 1]]})
n = 15
for i in range(n):
    a = (0.5 + i) / n
    a = (-1. + 2. * a)
    # ... after this, a ranges approximately from -1 to 1
    a = copysign(abs(a)**exponent, a)
    # unphysical version for pedagogical use, students explain why it's impossible
    # makes field more intense near the walls
    # re copysign, see https://stackoverflow.com/questions/1986152/why-doesnt-python-have-a-sign-function
    a = a * size
    line = FieldLine(field, [0.0, a], directions='both', maxr=15.0)
    doc.draw_line(line, arrows_style={'dist': 3, 'offsets': [0., .5, .5, 1.]})
doc.draw_object(
    'path', {
Beispiel #2
0
#!/usr/bin/python3

# This is based on the code snippet at https://commons.wikimedia.org/wiki/File:VFPt_dipole.svg .

from math import *
from vectorfieldplot import FieldplotDocument,Field,FieldLine
# ... https://github.com/CD3/VectorFieldPlot

import logging
logging.basicConfig(level=logging.ERROR) # can be DEBUG, INFO, WARNING, or ERROR


doc = FieldplotDocument('dipole', width=800, height=600, commons=True)
k=1 # 3 for first panel
field = Field({'dipoles':[[k,0,1,0]]})
n = 16
for i in range(n):
    a = 2.0 * pi * (0.5 + i) / n
    line = FieldLine(field, [1+k+cos(a), sin(a)],
        maxr=1000, directions='both', pass_dipoles=0)
    doc.draw_line(line, arrows_style=None)
doc.write()
Beispiel #3
0
#!/usr/bin/python3
from math import *
from vectorfieldplot import FieldplotDocument, Field, FieldLine
# ... https://github.com/CD3/VectorFieldPlot

print("generating files a.svg")

# paste this code at the end of VectorFieldPlot 1.0
doc = FieldplotDocument('a', width=600, height=600, commons=True)
#field = Field({'homogeneous':[[1,3]]})
a = 0.33  # ratio of constant field to current in wire
curr = 0.045  # current in wire
field = Field({'wires': [[0, 0, -curr]], 'homogeneous': [[a * curr, 0]]})
m = 10000  # controls resolution of search for appropriate starting points
# spacing of field lines is dr/di propto 1/B propto r; this integrates to r=(const)exp(const*i)
h = 3  # half-height of square box; is this right?
spacing = 0.01  # extra factor to scale spacing, smaller gives smaller spacing
last_nn = 999
f = 0.2  # .235 was too big
# why is this needed???; bigger f excludes more double-counted lines; if f is too small, uniform
#    spacing at left side is disrupted by extra lines; if too big, disrupted by missing lines
# Presumably this is because the software uses some units for I and B; if it was SI, then I would
# expect this to be 0.5e-7...?
for i in range(m):
    q = (i - m / 2.0) * 2.0 / m  # ranges from -1 to 1
    y = q * h
    r = abs(y) + 1.0e-6
    if y > 0.0:
        s = 1.0
    else:
        s = -1.0
Beispiel #4
0
#!/usr/bin/python3
from math import *
from vectorfieldplot import FieldplotDocument, Field, FieldLine
# ... https://github.com/CD3/VectorFieldPlot

print("generating file field-lines.svg")

# paste this code at the end of VectorFieldPlot 1.0
doc = FieldplotDocument('field-lines', width=800, height=800)
field = Field({'monopoles': [[0, -1, 1], [0, 1, -1]]})
n = 16
for i in range(n):
    a = (0.5 + i) / n
    a = 2.0 * pi * a
    line = FieldLine(field, [0, -1],
                     start_v=[cos(a), sin(a)],
                     directions='forward')
    doc.draw_line(line)
doc.write()
Beispiel #5
0
#!/usr/bin/python3
from math import *
from vectorfieldplot import FieldplotDocument, Field, FieldLine
# ... https://github.com/CD3/VectorFieldPlot

print("generating files u.svg, like charges")

# paste this code at the end of VectorFieldPlot 1.0
doc = FieldplotDocument('u', width=800, height=800)
field = Field({'monopoles': [[-1, 0, -1], [1, 0, -1]]})
doc.draw_charges(field)
for x in [-1, 1]:
    line = FieldLine(field, [x, 0], start_v=[x, 0], directions='backward')
    doc.draw_line(line)
n = 32
for i in range(n):
    a = 2.0 * pi * (0.5 + i) / n
    line = FieldLine(field, [10. * cos(a), 10. * sin(a)], directions='forward')
    doc.draw_line(line)
doc.write()

print("generating files v.svg, opposite charges")

# paste this code at the end of VectorFieldPlot 1.0
doc = FieldplotDocument('v', width=800, height=800)
field = Field({'monopoles': [[-1, 0, 1], [1, 0, -1]]})
doc.draw_charges(field)
n = 16
for i in range(n):
    a = (0.5 + i) / n
    a = 2.0 * pi * a
Beispiel #6
0
#!/usr/bin/python3

# https://commons.wikimedia.org/wiki/File:VFPt_superconductor_ball_E-field.svg
# Original code by Geek3, CC-BY. Modifications by B. Crowell under the same license.

from math import *
from vectorfieldplot import FieldplotDocument, Field, FieldLine
# ... https://github.com/CD3/VectorFieldPlot

scale = 1

doc = FieldplotDocument('hw-conducting-sphere-in-uniform-field',
                        width=600,
                        height=600)
field_direction = [0.0, -1.0]
ball_radius = 1.2 * scale
field = Field({
    'homogeneous': [field_direction],
    'dipoles': [[
        0, 0, 4 * pi * ball_radius**3 * field_direction[0],
        4 * pi * ball_radius**3 * field_direction[1]
    ]]
})
n = 20
for i in range(n):
    a = -3 + 6 * (0.5 + i) / n
    line = FieldLine(field, [a * scale, 6 * scale], maxr=12, pass_dipoles=1)
    if abs((n - 1.) / 2. - i) > 7: off = 4 * [0.5]
    else: off = 4 * [0.25]
    doc.draw_line(line,
                  arrows_style={
Beispiel #7
0
#!/usr/bin/python3

from math import *
from vectorfieldplot import FieldplotDocument, Field, FieldLine
# ... https://github.com/CD3/VectorFieldPlot

print("generating files a.svg")

# paste this code at the end of VectorFieldPlot 1.0
s = 1  # scale-down factor
doc = FieldplotDocument('a', unit=100 / s)
m = [[-0.3, 0, 1], [0.5, 0, -1], [0, -0.3, -1], [0.1, 1.3, 1]]
field = Field({'monopoles': m})
doc.draw_charges(field)
n = 64
k = 4
for i in range(n):
    a = (0.5 + i) / n
    a = 2.0 * pi * a
    for j in range(k):
        line = FieldLine(field, [m[j][0], m[j][1]],
                         start_v=[cos(a), sin(a)],
                         directions='forward')
        doc.draw_line(line, arrows_style=None)
doc.write()