Esempio n. 1
0
def makeWire(pixels):
	left = getLeftMostPixel(pixels)
	right = getRightMostPixel(pixels)
	top = getTopMostPixel(pixels)
	bottom = getBottomMostPixel(pixels)
	LRdist = abs(left[0] - right[0])
	UDdist = abs(top[1] - bottom[1])
	if UDdist > LRdist:
		return w.Wire(top[1], top[0], bottom[1], bottom[0])
	else:
		return w.Wire(left[1], left[0], right[1], right[0])
Esempio n. 2
0
def part_two(args, input_lines):
    "Process part two of the puzzle"

    # 1. Generate the wires
    wire1 = wire.Wire(input_lines[0])
    wire2 = wire.Wire(input_lines[1])

    if args.verbose:
        print("Wire 1 ends at (%d, %d)" % wire1.end())
        print("Wire 2 ends at (%d, %d)" % wire2.end())

    # 9. Return result
    inter = wire1.intersections(wire2)
    solution = wire.fastest(inter, [wire1, wire2])

    print("Solution is %d" % (solution))
    return solution is not None
Esempio n. 3
0
def part_one(args, input_lines):
    "Process part one of the puzzle"

    # 1. Generate the wires
    wire1 = wire.Wire(input_lines[0])
    wire2 = wire.Wire(input_lines[1])

    if args.verbose:
        print("Wire 1 ends at (%d, %d)" % wire1.end())
        print("Wire 2 ends at (%d, %d)" % wire2.end())

    # 9. Return result
    inter = wire1.intersections(wire2)
    solution = wire.manhattan((0, 0), wire.closest((0, 0), inter))

    print("Solution is %d" % (solution))
    return solution is not None
Esempio n. 4
0
def calcBpol(pf_coils, points, nx=3, ny=3):
    '''
    function calculates poloidal magnetic field from a toroidal coil
    pf_coils - dictionary with information about coils
    points - np array with points
    nx - number of filaments along x
    ny - number of filaments along y
    '''
    print('Calculating Poloidal Field')

    disc_len = 0.2  # discretisation length for wire [m]
    B = {}
    wires = []
    for coil in pf_coils.keys():

        print(coil)
        xc = pf_coils[coil][0]
        yc = pf_coils[coil][1]
        dx = pf_coils[coil][2]
        dy = pf_coils[coil][3]
        curr_tot = 1e6  # Total Current [A]
        curr = curr_tot / (nx * ny)
        # define toroidal angle
        nfi = 40  #number of steps along toroidal angle
        dfi = 2 * np.pi / nfi
        fi = np.arange(0, 2 * np.pi + dfi, dfi)

        # -> x cycle start ---------------------------------------------------
        for k_x in range(0, nx):
            # single wire is a circle in xz plane
            # set wire radius
            r = xc + dx / 2 - k_x * dx / (nx - 1)
            x = np.sin(fi) * r
            z = np.cos(fi) * r

            # -> y cycle start -----------------------------------------------
            for k_y in range(0, ny):
                # set y value
                y = np.full_like(x, yc + dy / 2 - k_y * dy / (ny - 1))
                # concatenate in one np array
                new_coil = np.c_[x, y, z]
                # create new wire object for calculation by Biotsavart script
                new_w = wire.Wire(path=new_coil,
                                  discretization_length=disc_len,
                                  current=curr)
                wires.append(new_w)
            # -> y cycle end -------------------------------------------------

        # -> x cycle end -----------------------------------------------------
        B_coil = BiotSavart(points, wires)
        B[coil] = B_coil
    return B, wires
Esempio n. 5
0
def calcBplasma(points, filename, CurrTot):
    ''' calculate plasma field in points
    filename - Tokameq file with Jpl distribution
    CurrTot - total plasma current in [MA] '''
    print('Calculating Plasma Field')
    J_vals, x_vals, y_vals = ImportJpl(filename)

    Jtot = np.sum(J_vals)  # total J, used for normalisation
    disc_len = 0.2  # discretisation length for wire [m]

    # define toroidal angle
    nfi = 40  #number of steps along toroidal angle

    dfi = 2 * np.pi / nfi
    fi = np.arange(0, 2 * np.pi + dfi, dfi)
    wires = []
    # -> x cycle start ---------------------------------------------------
    for i in range(x_vals.shape[0]):
        # single wire is a circle in xz plane
        # set wire radius as a value from x_vals
        x = np.sin(fi) * x_vals[i]
        z = np.cos(fi) * x_vals[i]
        # -> y cycle start -----------------------------------------------
        for j in range(y_vals.shape[0]):
            if J_vals[j, i] != 0.0:
                # set y value
                y = np.full_like(x, y_vals[j])
                # concatenate in one np array
                new_coil = np.c_[x, y, z]
                # create new wire object for calculation by Biotsavart script
                new_w = wire.Wire(path=new_coil,
                                  discretization_length=disc_len,
                                  current=1e6 * CurrTot * J_vals[j, i] / Jtot)
                wires.append(new_w)
    B = BiotSavart(points, wires)
    return B, wires
Esempio n. 6
0
# [email protected]

# tested with python 3.4.3

# some basic calculations for testing

import numpy as np

import visvis as vv

import wire
import biotsavart

# simple solenoid
w = wire.Wire(path=wire.Wire.SolenoidPath(),
              discretization_length=0.01,
              current=100).Translate((0.1, 0.1, 0)).Rotate(axis=(1, 0, 0),
                                                           deg=45)
sol = biotsavart.BiotSavart(wire=w)

resolution = 0.02
volume_corner1 = (-.2, -.3, -.2)
volume_corner2 = (.3, .3, .4)

grid = np.mgrid[volume_corner1[0]:volume_corner2[0]:resolution,
                volume_corner1[1]:volume_corner2[1]:resolution,
                volume_corner1[2]:volume_corner2[2]:resolution]

# create list of grid points
points = np.vstack(map(np.ravel, grid)).T

# calculate B field at given points
Esempio n. 7
0
# [email protected]

# tested with python 3.4.3

# some basic calculations for testing

import numpy as np
import matplotlib.pyplot as plt

import wire
import biotsavart

# simple wire
w = wire.Wire(path=wire.Wire.SinusoidalCircularPath(radius=0.5,
                                                    amplitude=0.0,
                                                    frequency=12.0,
                                                    pts=200),
              discretization_length=0.01,
              current=50000)
sol = biotsavart.BiotSavart(wire=w)

resolution = 0.1
volume_corner1 = (-0.975, -0.975, -0.09725)
volume_corner2 = (0.875, 0.875, 0.08725)

grid = np.mgrid[volume_corner1[0]:volume_corner2[0]:resolution,
                volume_corner1[1]:volume_corner2[1]:resolution,
                volume_corner1[2]:volume_corner2[2]:resolution / 10]

# create list of grid points
points = np.vstack(map(np.ravel, grid)).T
Esempio n. 8
0
# tested with python 3.4.3

# some basic calculations for testing

import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import wire
import biotsavart

# simple solenoid
# approximated analytical solution: B = mu0 * I * n / l = 4*pi*1e-7[T*m/A] * 100[A] * 10 / 0.5[m] = 2.5mT

w = wire.Wire(path=wire.Wire.SolenoidPath(pitch=0.005, turns=100),
              discretization_length=0.01,
              current=10000).Rotate(axis=(1, 0, 0),
                                    deg=90)  #.Translate((0.1, 0.1, 0)).
sol = biotsavart.BiotSavart(wire=w)

resolution = 0.04
volume_corner1 = (-.2, -.8, -.2)
volume_corner2 = (.2 + 1e-10, .3, .2)

# matplotlib plot 2D
# create list of xy coordinates
grid = np.mgrid[volume_corner1[0]:volume_corner2[0]:resolution,
                volume_corner1[1]:volume_corner2[1]:resolution]

# create list of grid points
points = np.vstack(map(np.ravel, grid)).T
points = np.hstack([points, np.zeros([len(points), 1])])
Esempio n. 9
0
G['E'] = []
G['F'] = []
G['N'] = []
G['pts'] = []
Gs = []

# Ellipsoid Object
r = 3  # radius of cross section
ppath = [[0, 0, 0], [-10, 20, 0], [20, 30, 10], [30, 10, 20], [35, 5, 30],
         [40, 10, 20], [50, 30, 10], [70, 20, 20], [60, 0, 30], [55, 130, 40],
         [45, 120, 50], [35, 110, 45], [25, 110, 30], [20, 110, -25],
         [10, 130, -15], [10, 110, 0]]
t = [-80., 0., 50.]
degrees = 0
axis = [0, 1, 0]
q = aff.HH.rotation_quaternion(degrees, axis[0], axis[1], axis[2])
scale = 1.
s = [scale, scale, scale]  # the same scale as previous for caps
# n is length
H0 = wi.Wire(r, ppath, t, q, s, m=10, n=100)
Gs = ext.Append(Gs, H0)
G = ext.GraphUnionS(G, H0)
#################################

# Save Scene 1
ext.Graphs2OBJ(BIGDATA + "Wire1.obj", Gs, "scene")

# Double-Click on OBJ file
import os
os.system(BIGDATA + "Wire1.obj")
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import axes3d

import wire
import biotsavart

npts = 200
radius = .07
amp = .01
ncycle = 12.0

# define wires
w1 = wire.Wire(path=wire.Wire.SinusoidalCircularPath(radius=radius,
                                                     amplitude=amp,
                                                     frequency=ncycle,
                                                     pts=npts),
               discretization_length=0.01,
               current=100.0)
w2 = wire.Wire(path=wire.Wire.SinusoidalCircularPath(radius=radius,
                                                     amplitude=amp,
                                                     frequency=ncycle,
                                                     pts=npts),
               discretization_length=0.01,
               current=-100.0).Rotate(axis=(0, 0, 1), deg=360.0 / ncycle / 2.0)

# prepare data grid and calculate B in volume
resolution = 0.005
# volume to examine
volume_corner1 = (0, 0, 0)
volume_corner2 = (.12, .12, .05)
Esempio n. 11
0
# [email protected]

# tested with python 3.4.3

# calculate fields needed for an palint oven

import numpy as np
import matplotlib.pyplot as plt
from copy import deepcopy
import wire
import biotsavart

# two solenoids

w1 = wire.Wire(path=wire.Wire.SolenoidPath(radius=0.1, pitch=0.02, turns=20),
               discretization_length=0.01,
               current=10).Rotate(axis=(0, 1, 0), deg=90)
w2 = wire.Wire(path=wire.Wire.SolenoidPath(radius=0.1, pitch=0.02, turns=30),
               discretization_length=0.01,
               current=20).Rotate(axis=(0, 1, 0),
                                  deg=90).Translate([.45, 0, 0])

sol = biotsavart.BiotSavart(wire=w1)
sol.AddWire(w2)

resolution = 0.01
xy_corner1 = (-.2, -.09)
xy_corner2 = (.8 + 1e-10, .09)

# matplotlib plot 2D
# create list of xy coordinates
Esempio n. 12
0
def calcBtor(points):
    '''
    function calculates toroidal field in points
    points - np array with x,y,z of n points
    '''
    print('Calculating Toroidal Field')
    n_coils = 16  # total number of coils in TOKAMAK
    coil_width = 0.196  # coil width [m]
    curr_tot = 0.484503 * 1e6  # Total Current in coil [A]

    n_xy = 4  # number of circuits in poloidal direction
    n_z = 4  # number of circuits in toroidal direction
    disc_len = 0.2  # discretisation length for wire [m]
    curr = curr_tot / (n_xy * n_z)  # current in one circuit
    initial_coil_angle = (360 / n_coils) * 0.5  # initial toroidal angle of
    # the first coil

    # get coil inner and outer profile
    filename = 'coildata.dat'
    array = np.loadtxt(filename)  # [m]
    N_rows = array.shape[0]
    #array has only x and y columns, so soon we need to add a zero column for z
    # (because we have no z column in coildata)
    outer_coil_array = np.array(array[:, [2, 3]])
    inner_coil_array = np.array(array[:, [0, 1]])
    # Creating a missing "z" coordinate column
    z_column0 = [-coil_width * 0.5] * N_rows
    wires = []
    # -> Coil cycle start ------------------------------------------------------
    for current_coil_number in range(n_coils):
        # toroidal angle of coil (0 means it is the first coil)
        z_column = z_column0
        coil_angle = initial_coil_angle + (360 /
                                           n_coils) * (current_coil_number)

        # -> Toroidal cycle start ----------------------------------------------
        for k_z in range(1, n_z + 1):
            new_coil = np.c_[np.array(array[:, [2, 3]]), np.array(z_column)]

            # -> Poloidal cycle start ------------------------------------------
            for k_xy in range(1, n_xy + 1):
                new_coil[:, 0:2] = outer_coil_array - (k_xy/n_xy)* \
                                (outer_coil_array - inner_coil_array)
                # We add new wires for calculation by Biotsavart script
                new_w = wire.Wire(path=new_coil,
                                  discretization_length=disc_len,
                                  current=curr).Rotate(axis=(0, 1, 0),
                                                       deg=coil_angle)
                wires.append(new_w)

            # now we make a step in toroidal (z) direction:
            z_column = [-coil_width / 2 + (coil_width /
                                           (n_z - 1)) * k_z] * N_rows
            # -> Poloidal cycle end---------------------------------------------

        # -> Toroidal cycle end ------------------------------------------------

    # -> Coil cycle end --------------------------------------------------------

    B = BiotSavart(points, wires)
    return B, wires
Esempio n. 13
0
# [email protected]

# tested with python 3.4.3

# some basic calculations for testing

import numpy as np
import matplotlib.pyplot as plt

import wire
import biotsavart

# simple wire
#w = wire.Wire(path=wire.Wire.SolenoidPath(), discretization_length=0.01, current=100).Translate((0.0, 0.0, 0.0)).Rotate(axis=(1.0, 0.0, 0.0), deg=0.0)
w = wire.Wire(path=wire.Wire.LinearPath([0.5, 0.5, 0.0], [0.5, 0.5, 1.0],
                                        pts=200),
              discretization_length=0.01,
              current=1000000)
sol = biotsavart.BiotSavart(wire=w)

resolution = 0.1
volume_corner1 = (.2, .2, .2)
volume_corner2 = (.8, .8, .8)

grid = np.mgrid[volume_corner1[0]:volume_corner2[0]:resolution,
                volume_corner1[1]:volume_corner2[1]:resolution,
                volume_corner1[2]:volume_corner2[2]:resolution]

# create list of grid points
points = np.vstack(map(np.ravel, grid)).T

# calculate B field at given points
Esempio n. 14
0
# tested with python 3.4.3

# some basic calculations for testing

import numpy as np

import visvis as vv

import wire
import biotsavart

wirelist = []
# simple wire
for i in range(21):
    wirelist.append(wire.Wire(path=wire.Wire.SinusoidalCircularPath(radius=0.5,amplitude=0.0,frequency=12.0,pts=200), discretization_length=0.01,current=2000).Translate([0.0,0.0,-0.5+i*0.05]))

sol = biotsavart.BiotSavart(wire=wirelist[0])

for i in range(1,21):
    sol.AddWire(wirelist[i])

resolution = 0.1
volume_corner1 = (-0.9, -0.9, -0.9)
volume_corner2 = (0.9, 0.9, 0.9)

grid = np.mgrid[volume_corner1[0]:volume_corner2[0]:resolution, volume_corner1[1]:volume_corner2[1]:resolution, volume_corner1[2]:volume_corner2[2]:resolution]

# create list of grid points
points = np.vstack(map(np.ravel, grid)).T