예제 #1
0
    def checkPositionInBoundary(self, pos, surface=False):
        xmin = self.xmin
        xmax = self.xmax
        ymin = self.ymin
        ymax = self.ymax
        #Inner boundary
        if surface:
            mask2 = af.geq_2D_p(pos, xmin, xmax, ymin, ymax)
        else:
            mask2 = af.g_2D_p(pos, xmin, xmax, ymin, ymax)

        return mask2
예제 #2
0
 def applyParticleOpenBoundary(self, species):
     #Just for convenience in writing and for use of accelerated functions
     np = species.part_values.current_n
     xmin = self.xmin
     xmax = self.xmax
     ymin = self.ymin
     ymax = self.ymax
     #Finding the particles
     ind = numpy.flatnonzero(af.geq_2D_p(species.part_values.position[:np,:], xmin, xmax, ymin, ymax))
     # Eliminating particles
     super().removeParticles(species,ind)
     count2 = numpy.shape(ind)[0]
     print('Number of {} eliminated - outer:'.format(species.name), count2)
     return {'del_ind': ind}
예제 #3
0
    def injectParticlesDummyBox(self, location, part_solver, field, species, delta_n, n_vel, shift_vel):
        # Creating temporary species
        ghost = Species("temporary species", species.dt, species.q, species.m, species.debye, species.spwt, \
                        int(species.part_values.max_n/10), species.pos_dim, species.vel_dim, species.mesh_values.nPoints, numpy.asarray([0]))
        ghost.mesh_values.residuals = species.mesh_values.residuals
        self.createDummyBox(location, part_solver.pic, ghost, delta_n, n_vel, shift_vel)
        species.mesh_values.residuals[location] = copy.copy(ghost.mesh_values.residuals[location])
        #Preparing variables
        np = ghost.part_values.current_n
        xmin = self.xmin
        xmax = self.xmax
        ymin = self.ymin
        ymax = self.ymax
        #Entering particles into the mesh and adjusting them according to motion_solver
        ghost.part_values.position[:np,:] += ghost.part_values.velocity[:np,:]*ghost.dt
        ind = numpy.flatnonzero(af.geq_2D_p(ghost.part_values.position[:np,:], xmin, xmax, ymin, ymax))

        self.removeParticles(ghost, ind)
        ##Test
        #np = ghost.part_values.current_n
        ##Test positioning
        #fig = plt.figure(figsize=(8,8))
        #plt.scatter(ghost.part_values.position[:np, 0], ghost.part_values.position[:np,1], marker = '.')
        #plt.title(self.type+" - "+species.name)
        #plt.show()
        ##Test velocity
        #fig = plt.figure(figsize=(8,8))
        #datamag = plt.hist(numpy.sqrt((ghost.part_values.velocity[:np,0]-shift_vel[0,0])*(ghost.part_values.velocity[:np,0]-shift_vel[0,0])+ \
        #                              ghost.part_values.velocity[:np,1]*ghost.part_values.velocity[:np,1]), 41, alpha=0.5, label=species.name)
        #plt.axvline(x=c.P_V_TH_MP*numpy.sqrt(2/3), label = 'protons', color = 'red')
        #plt.axvline(x=c.E_V_TH_MP*numpy.sqrt(2/3), label = 'electrons', color = 'blue')
        #plt.axvline(x=c.PHE_V_TH_MP*numpy.sqrt(2/3), label = 'photoelectrons', color = 'black')
        #plt.axvline(x=c.SEE_V_TH_MP*numpy.sqrt(2/3), label = 'SEE', color = 'purple')
        #plt.title(self.type+" - "+species.name)
        #plt.legend()
        #plt.show()
        #Test with more precision
        #filename = self.type+"_"+species.name+".txt"
        #with open(filename, 'ab') as f:
        #    np = ghost.part_values.current_n
        #    array = numpy.append(ghost.part_values.position[:np,:], ghost.part_values.velocity[:np,:], axis = 1)
        #    numpy.savetxt(f, array)

        part_solver.initialConfiguration(ghost, field)
        #Adding particles
        self.addParticles(species, ghost.part_values.position[:ghost.part_values.current_n,:], ghost.part_values.velocity[:ghost.part_values.current_n,:])
        self.updateTrackers(species, ghost.part_values.current_n)
        print("Injected particles: ",ghost.part_values.current_n)
        print("Total {}".format(species.name),": ", species.part_values.current_n)