예제 #1
0
    def update_magnetic(self, iteration, updatecoeffsH, ID, Hx, Hy, Hz, G):
        """Updates current value in transmission line from magnetic field values in the main grid.

        Args:
            iteration (int): Current iteration (timestep).
            updatecoeffsH (memory view): numpy array of magnetic field update coefficients.
            ID (memory view): numpy array of numeric IDs corresponding to materials in the model.
            Hx, Hy, Hz (memory view): numpy array of magnetic field values.
            G (class): Grid class instance - holds essential parameters describing the model.
        """

        if iteration * G.dt >= self.start and iteration * G.dt <= self.stop:
            i = self.xcoord
            j = self.ycoord
            k = self.zcoord

            if self.polarisation == 'x':
                self.current[self.antpos] = Ix(i, j, k, G.Hx, G.Hy, G.Hz, G)

            elif self.polarisation == 'y':
                self.current[self.antpos] = Iy(i, j, k, G.Hx, G.Hy, G.Hz, G)

            elif self.polarisation == 'z':
                self.current[self.antpos] = Iz(i, j, k, G.Hx, G.Hy, G.Hz, G)

            self.update_current(iteration, G)
예제 #2
0
    def update_magnetic(self, abstime, updatecoeffsH, ID, Hx, Hy, Hz, G):
        """Updates current value in transmission line from magnetic field values in the main grid.

        Args:
            abstime (float): Absolute time.
            updatecoeffsH (memory view): numpy array of magnetic field update coefficients.
            ID (memory view): numpy array of numeric IDs corresponding to materials in the model.
            Hx, Hy, Hz (memory view): numpy array of magnetic field values.
            G (class): Grid class instance - holds essential parameters describing the model.
        """

        if abstime >= self.start and abstime <= self.stop:
            # Set the time of the waveform evaluation to account for any delay in the start
            time = abstime - self.start
            i = self.xcoord
            j = self.ycoord
            k = self.zcoord

            if self.polarisation == 'x':
                self.current[self.antpos] = Ix(i, j, k, G.Hy, G.Hz, G)

            elif self.polarisation == 'y':
                self.current[self.antpos] = Iy(i, j, k, G.Hx, G.Hz, G)

            elif self.polarisation == 'z':
                self.current[self.antpos] = Iz(i, j, k, G.Hx, G.Hy, G)

            self.update_current(time, G)
예제 #3
0
def write_output(f, timestep, Ex, Ey, Ez, Hx, Hy, Hz, G):
    """Writes field component values to an output file in HDF5 format.
        
    Args:
        f (file object): File object for the file to be written to.
        timestep (int): Current iteration number.
        Ex, Ey, Ez, Hx, Hy, Hz (memory view): Current electric and magnetic field values.
        G (class): Grid class instance - holds essential parameters describing the model.
    """

    # For each rx, write field component values at current timestep
    for rxindex, rx in enumerate(G.rxs):
        if 'Ex' in rx.outputs:
            f['/rxs/rx' + str(rxindex + 1) + '/Ex'][timestep] = Ex[rx.xcoord,
                                                                   rx.ycoord,
                                                                   rx.zcoord]
        if 'Ey' in rx.outputs:
            f['/rxs/rx' + str(rxindex + 1) + '/Ey'][timestep] = Ey[rx.xcoord,
                                                                   rx.ycoord,
                                                                   rx.zcoord]
        if 'Ez' in rx.outputs:
            f['/rxs/rx' + str(rxindex + 1) + '/Ez'][timestep] = Ez[rx.xcoord,
                                                                   rx.ycoord,
                                                                   rx.zcoord]
        if 'Hx' in rx.outputs:
            f['/rxs/rx' + str(rxindex + 1) + '/Hx'][timestep] = Hx[rx.xcoord,
                                                                   rx.ycoord,
                                                                   rx.zcoord]
        if 'Hy' in rx.outputs:
            f['/rxs/rx' + str(rxindex + 1) + '/Hy'][timestep] = Hy[rx.xcoord,
                                                                   rx.ycoord,
                                                                   rx.zcoord]
        if 'Hz' in rx.outputs:
            f['/rxs/rx' + str(rxindex + 1) + '/Hz'][timestep] = Hz[rx.xcoord,
                                                                   rx.ycoord,
                                                                   rx.zcoord]
        if 'Ix' in rx.outputs:
            f['/rxs/rx' + str(rxindex + 1) + '/Ix'][timestep] = Ix(
                rx.xcoord, rx.ycoord, rx.zcoord, G.Hy, G.Hz, G)
        if 'Iy' in rx.outputs:
            f['/rxs/rx' + str(rxindex + 1) + '/Iy'][timestep] = Iy(
                rx.xcoord, rx.ycoord, rx.zcoord, G.Hx, G.Hz, G)
        if 'Iz' in rx.outputs:
            f['/rxs/rx' + str(rxindex + 1) + '/Iz'][timestep] = Iz(
                rx.xcoord, rx.ycoord, rx.zcoord, G.Hx, G.Hy, G)

    if G.transmissionlines:
        for tlindex, tl in enumerate(G.transmissionlines):
            f['/tls/tl' + str(tlindex + 1) +
              '/Vtotal'][timestep] = tl.voltage[tl.antpos]
            f['/tls/tl' + str(tlindex + 1) +
              '/Itotal'][timestep] = tl.current[tl.antpos]
예제 #4
0
    def write_vtk_imagedata(self, Ex, Ey, Ez, Hx, Hy, Hz, G, pbar):
        """Writes electric and magnetic field values to VTK ImageData (.vti) file.

        Args:
            Ex, Ey, Ez, Hx, Hy, Hz (memory view): Electric and magnetic field values.
            G (class): Grid class instance - holds essential parameters describing the model.
            pbar (class): Progress bar class instance.
        """

        self.filehandle = open(self.filename, 'ab')

        datasize = 3 * np.dtype(floattype).itemsize * (self.vtk_xfcells - self.vtk_xscells) * (self.vtk_yfcells - self.vtk_yscells) * (self.vtk_zfcells - self.vtk_zscells)
        # Write number of bytes of appended data as UInt32
        self.filehandle.write(pack('I', datasize))
        for k in range(self.zs, self.zf, self.dz):
            for j in range(self.ys, self.yf, self.dy):
                for i in range(self.xs, self.xf, self.dx):
                    pbar.update(n=12)
                    # The electric field component value at a point comes from average of the 4 electric field component values in that cell
                    self.filehandle.write(pack(Snapshot.floatstring, (Ex[i, j, k] + Ex[i, j + 1, k] + Ex[i, j, k + 1] + Ex[i, j + 1, k + 1]) / 4))
                    self.filehandle.write(pack(Snapshot.floatstring, (Ey[i, j, k] + Ey[i + 1, j, k] + Ey[i, j, k + 1] + Ey[i + 1, j, k + 1]) / 4))
                    self.filehandle.write(pack(Snapshot.floatstring, (Ez[i, j, k] + Ez[i + 1, j, k] + Ez[i, j + 1, k] + Ez[i + 1, j + 1, k]) / 4))

        self.filehandle.write(pack('I', datasize))
        for k in range(self.zs, self.zf, self.dz):
            for j in range(self.ys, self.yf, self.dy):
                for i in range(self.xs, self.xf, self.dx):
                    pbar.update(n=12)
                    # The magnetic field component value at a point comes from average
                    # of 2 magnetic field component values in that cell and the following cell
                    self.filehandle.write(pack(Snapshot.floatstring, (Hx[i, j, k] + Hx[i + 1, j, k]) / 2))
                    self.filehandle.write(pack(Snapshot.floatstring, (Hy[i, j, k] + Hy[i, j + 1, k]) / 2))
                    self.filehandle.write(pack(Snapshot.floatstring, (Hz[i, j, k] + Hz[i, j, k + 1]) / 2))

        self.filehandle.write(pack('I', datasize))
        for k in range(self.zs, self.zf, self.dz):
            for j in range(self.ys, self.yf, self.dy):
                for i in range(self.xs, self.xf, self.dx):
                    pbar.update(n=12)
                    self.filehandle.write(pack(Snapshot.floatstring, Ix(i, j, k, Hx, Hy, Hz, G)))
                    self.filehandle.write(pack(Snapshot.floatstring, Iy(i, j, k, Hx, Hy, Hz, G)))
                    self.filehandle.write(pack(Snapshot.floatstring, Iz(i, j, k, Hx, Hy, Hz, G)))

        self.filehandle.write('\n</AppendedData>\n</VTKFile>'.encode('utf-8'))
        self.filehandle.close()