Example #1
0
 def trim(self, Rloop, Zloop, R, Z):
     Rloop, Zloop = geom.order(Rloop, Zloop)
     L = geom.length(R, Z)
     index = np.append(np.diff(L) != 0, True)
     R, Z = R[index], Z[index]  # remove duplicates
     nRloop, nZloop, Rloop, Zloop = geom.normal(Rloop, Zloop)
     Rin, Zin = np.array([]), np.array([])
     for r, z in zip(R, Z):
         i = np.argmin((r - Rloop)**2 + (z - Zloop)**2)
         dr = [Rloop[i] - r, Zloop[i] - z]
         dn = [nRloop[i], nZloop[i]]
         if np.dot(dr, dn) > 0:
             Rin, Zin = np.append(Rin, r), np.append(Zin, z)
     i = np.argmin((Rin[-1] - R)**2 + (Zin[-1] - Z)**2)
     Rin, Zin = R[:i + 2], Z[:i + 2]  # extend past target
     i = np.argmin(
         (Rin[-1] - R)**2 + (Zin[-1] - Z)**2)  # sol crossing bndry
     jo = np.argmin((R[i] - Rloop)**2 + (Z[i] - Zloop)**2)
     j = np.array([jo, jo + 1])
     s = np.array([R[i], Z[i]])
     ds = np.array([R[i] - R[i - 1], Z[i] - Z[i - 1]])
     b = np.array([Rloop[j[0]], Zloop[j[0]]])
     bstep, db = self.get_bstep(s, ds, b, Rloop, Zloop, j)
     if bstep < 0:
         j = np.array([jo - 1, jo])  # switch target pannel
         bstep, db = self.get_bstep(s, ds, b, Rloop, Zloop, j)
     step = np.cross(b - s, db) / np.cross(ds, db)
     intersect = s + step * ds  # predict - correct
     if step < 0:  # step back
         Rin, Zin = Rin[:-1], Zin[:-1]
     Rin, Zin = np.append(Rin, intersect[0]), np.append(Zin, intersect[1])
     return Rin, Zin, db
Example #2
0
 def Cshift(self, coil, side, dL):  # shift pf coils to tf track
     if 'in' in side:
         R, Z = self.x['in']['r'], self.x['in']['z']
     else:
         R, Z = self.x['out']['r'], self.x['out']['z']
     rc, zc = coil['r'], coil['z']
     drc, dzc = coil['dr'], coil['dz']
     rp = rc + np.array([-drc, drc, drc, -drc]) / 2
     zp = zc + np.array([-dzc, -dzc, dzc, dzc]) / 2
     nR, nZ = geom.normal(R, Z)[:2]
     mag = np.sqrt(nR**2 + nZ**2)
     nR /= mag
     nZ /= mag
     i = []
     L = np.empty(len(rp))
     dn = np.empty((2, len(rp)))
     for j, (r, z) in enumerate(zip(rp, zp)):
         i.append(np.argmin((R - r)**2 + (Z - z)**2))
         dr = [r - R[i[-1]], z - Z[i[-1]]]
         dn[:, j] = [nR[i[-1]], nZ[i[-1]]]
         L[j] = np.dot(dr, dn[:, j])
         if 'in' in side: L[j] *= -1
     jc = np.argmin(L)
     fact = dL - L[jc]
     if 'in' in side: fact *= -1
     delta = fact * dn[:, jc]
     return delta[0], delta[1]
Example #3
0
 def dot_diffrence(self,x,side):
     Rloop,Zloop = x['r'],x['z']  # inside coil loop
     switch = 1 if side is 'internal' else -1
     nRloop,nZloop,Rloop,Zloop = geom.normal(Rloop,Zloop)
     R,Z = self.bound[side]['r'],self.bound[side]['z']
     dot = np.zeros(len(R))
     for j,(r,z) in enumerate(zip(R,Z)):
         i = np.argmin((r-Rloop)**2+(z-Zloop)**2)
         dr = [Rloop[i]-r,Zloop[i]-z]  
         dn = [nRloop[i],nZloop[i]]
         dot[j] = switch*np.dot(dr,dn)
     return dot
Example #4
0
def Dshape(x, r1=4.486, r2=15.708, npoints=120):
    #zscale = x[0]
    b = x[1:]
    b = np.append(np.append(0, b), 0)  # zero offset
    #b = np.append(np.append(0,b),0)  # zero gradient
    rd, zd = Dcoil.pD(r1, r2, npoints=npoints)  # referance D-coil
    r, z = np.copy(rd), np.copy(zd)
    #z = zscale*z  # scale height
    L = geom.length(r, z)
    bern = bernstein(L, n=len(b) - 1)
    dn = bern.gen(b)  # calculate bernstein polynomials
    nr, nz = geom.normal(r, z)  # offset shape
    r += nr * dn
    z += nz * dn
    r, z = geom.space(r, z, npoints=npoints)

    zshift = np.mean([z.min(), z.max()])
    z -= zshift
    znorm = zd.max() / z.max()
    z *= znorm
    return r, z
Example #5
0
    def blanket_thickness(self, Nt=100, plot=False):
        bl, loop = {}, {}  # read blanket
        for side in ['in', 'out']:
            bl[side], c = {}, {}
            for x in ['r', 'z']:
                c[x] = self.parts['Blanket'][side][x]
            r, z = geom.order(c['r'], c['z'], anti=True)
            r, z, l = geom.unique(r, z)  # remove repeats
            bl[side]['r'], bl[side]['z'] = r, z
            loop[side] = {'r': IUS(l, r), 'z': IUS(l, z)}  # interpolator

        def thickness(L, Lo, loop, norm):
            r = loop['in']['r'](Lo) + L[0] * norm['nr'](Lo)
            z = loop['in']['z'](Lo) + L[0] * norm['nz'](Lo)
            err = (r-loop['out']['r'](L[1]))**2+\
                  (z-loop['out']['z'](L[1]))**2
            return err

        r, z = geom.unique(bl['in']['r'], bl['in']['z'])[:2]  # remove repeats
        nr, nz, r, z = geom.normal(r, z)
        l = geom.length(r, z)
        norm = {'nr': IUS(l, nr), 'nz': IUS(l, nz)}  # interpolator

        dt, Lo = np.zeros(Nt), np.linspace(0, 1, Nt)
        for i, lo in enumerate(Lo):
            L = minimize(thickness, [0, lo],
                         method='L-BFGS-B',
                         bounds=([0, 5], [0, 1]),
                         args=(lo, loop, norm)).x
            dt[i] = np.sqrt((loop['in']['r'](lo) - loop['out']['r'](L[1]))**2 +
                            (loop['in']['z'](lo) - loop['out']['z'](L[1]))**2)
            dt[i] = L[0]
        dt = savgol_filter(dt, 7, 2)  # filter
        if plot:
            pl.plot(Lo, dt)
        return [np.min(dt), np.max(dt)]