Esempio n. 1
0
    def insert_points(self, indices):
        """
        Insert points at new_pos_x before indices.
        """
        old_pos_x = self.positions[:, 0]
        new_pos_x, new_pos_z = super(RectilinearSurface2D,
                                     self).insert_points(indices)

        new_material_indexes = self.mat_track.get_materials(
            np.array([new_pos_x,
                      np.zeros(new_pos_x.shape), new_pos_z]))
        new_material_names = extract_names(new_material_indexes)
        new_densities = extract_densities(new_material_indexes)
        self.material_names = np.insert(self.material_names, indices,
                                        new_material_names)
        self.material_densities = np.insert(self.material_densities, indices,
                                            new_densities)

        #TOCHECK: Why do the following if not valid?
        new_beam_fluxes = interpolate_linear1d(old_pos_x, self.beam_fluxes,
                                               new_pos_x)
        self.beam_fluxes = np.insert(self.beam_fluxes, indices,
                                     new_beam_fluxes)

        new_fluxes = interpolate_linear1d(old_pos_x, self.fluxes, new_pos_x)
        #if np.any(np.isnan(new_fluxes)):  #bug chasing code.
        #    print 'new fluxes'
        #    print new_fluxes

        self.fluxes = np.insert(self.fluxes, indices, new_fluxes)
        self.flux_is_valid = np.insert(self.flux_is_valid, indices, False)
        self.calc_point_directions()
        self.calc_point_areas()
Esempio n. 2
0
    def advance(self, time,
                time_step):  # TOCHECK: can we take advance out of this class?
        """
        Advance the surface by one time step.
        """
        # move points along point direction
        while True:
            try:
                new_surface = deepcopy(self)

                normal_velocities = -new_surface.fluxes / new_surface.material_densities
                displacements = normal_velocities * time_step
                new_surface.old_positions = copy(new_surface.positions)
                new_surface.positions[:,
                                      0] += new_surface.directions[:,
                                                                   0] * displacements
                # change shape direction ?
                new_surface.positions[:,
                                      1] += new_surface.directions[:,
                                                                   1] * displacements
                # change shape direction ?

                new_pos_x = new_surface.positions[:, 0]
                new_pos_z = new_surface.positions[:, 1]

                new_surface.material_indexes = self.mat_track.get_materials(
                    np.array([new_pos_x,
                              np.zeros(new_pos_x.shape), new_pos_z]))
                new_surface.material_names = extract_names(
                    new_surface.material_indexes)
                new_surface.material_densities = extract_densities(
                    new_surface.material_indexes)

                if par.INTERPOLATE:
                    new_surface.detect_loops()

                break
            except CrossedPointsError:
                time_step = time_step / 2
                print_log('time, reduced time step:', time, time_step)

        # interpolate surface back to original grid
        if par.INTERPOLATE:
            new_surface.interpolate_to_grid_of(self)

        # refine grid if necessary
        if par.ADAPTIVE_GRID:
            while True:
                try:
                    refined = new_surface.adapt_grid()
                    if not refined:
                        break
                except TooLargeSegmentError:
                    #go back to old surface
                    new_surface = deepcopy(self)
                    raise HasUndefinedFluxError

        return new_surface, time_step
Esempio n. 3
0
    def __init__(self, pos_x, pos_z):
        self.mat_track = Materials_Tracker()
        super(RectilinearSurface2D, self).__init__(pos_x, pos_z)
        #initialize materials
        material_indexes = self.mat_track.get_materials(
            np.array([pos_x, np.zeros(pos_x.shape), pos_z]))
        self.material_names = extract_names(
            material_indexes
        )  #TODO: convert to using only material indexes internally
        self.material_densities = extract_densities(material_indexes)

        self.beam_fluxes = np.zeros(self.len_x, float)
        self.fluxes = np.zeros(self.len_x, float)
        self.flux_is_valid = np.repeat((False, ), self.len_x)
        self.coverages = np.repeat((1.0, ), self.len_x)  #from parameters?
Esempio n. 4
0
 def __init__(self, pos_x, pos_y, pos_z, len_x, len_y):
     self.mat_track = Materials_Tracker()
     super(RectilinearSurface3D, self).__init__(pos_x, pos_y, pos_z, len_x,
                                                len_y)
     self.material_indexes = self.mat_track.get_materials(
         np.array([pos_x, pos_y, pos_z]))
     self.material_names = extract_names(
         self.material_indexes
     )  #TODO: convert to using only material indexes internally
     self.material_densities = extract_densities(self.material_indexes)
     #self.material_names, self.material_densities = get_materials(self.positions[:,2])
     self.coverages = np.repeat((1.0, ), self.len_xy)
     self.beam_fluxes = np.zeros(self.len_xy, float)
     self.fluxes = np.empty(self.len_xy, float)
     self.thetas = np.empty(self.len_xy, float)
     self.flux_is_valid = np.repeat((False, ), self.len_xy)
Esempio n. 5
0
    def insert_points(self, indices, axis):
        """
        Insert points at new_pos_x before indices.
        """
        material_densities = self.material_densities.reshape(
            self.len_x, self.len_y)
        material_names = self.material_names.reshape(self.len_x, self.len_y)
        beam_fluxes = self.beam_fluxes.reshape(self.len_x, self.len_y)
        fluxes = self.fluxes.reshape(self.len_x, self.len_y)
        flux_is_valid = self.flux_is_valid.reshape(self.len_x, self.len_y)
        #if par.ETCHING | par.DEPOSITION:
        coverages = self.coverages.reshape(self.len_x, self.len_y)

        # super.insert_points changes self.len_x or self.len_y, so we must call it only AFTER
        # reshaping the attributes
        new_pos_x, new_pos_y, new_pos_z = super(RectilinearSurface3D,
                                                self).insert_points(
                                                    indices, axis)

        #new_material_names, new_densities = get_materials(new_pos_z)
        #material_names = np.insert(material_names, indices, new_material_names, axis)
        #densities = np.insert(densities, indices, new_densities, axis)
        ### TODO: check insertion in 3D
        if axis == 1:
            new_pos_x = new_pos_x.T
            new_pos_y = new_pos_y.T
            new_pos_zt = new_pos_z.T
        else:
            new_pos_zt = new_pos_z
        for index in range(len(indices)):
            new_material_indexes = self.mat_track.get_materials(
                np.array(
                    [new_pos_x[index], new_pos_y[index], new_pos_zt[index]]))
            new_material_names = extract_names(new_material_indexes)
            new_densities = extract_densities(new_material_indexes)
            material_names = np.insert(material_names, indices[index],
                                       new_material_names, axis)
            material_densities = np.insert(material_densities, indices[index],
                                           new_densities, axis)

        if axis == 0:
            new_beam_fluxes = (beam_fluxes[indices - 1, :] +
                               beam_fluxes[indices, :]) / 2
            new_fluxes = (fluxes[indices - 1, :] + fluxes[indices, :]) / 2
        elif axis == 1:
            new_beam_fluxes = (beam_fluxes[:, indices - 1] +
                               beam_fluxes[:, indices]) / 2
            new_fluxes = (fluxes[:, indices - 1] + fluxes[:, indices]) / 2
        beam_fluxes = np.insert(beam_fluxes, indices, new_beam_fluxes, axis)
        fluxes = np.insert(fluxes, indices, new_fluxes, axis)
        flux_is_valid = np.insert(flux_is_valid, indices, False, axis)

        #if par.ETCHING | par.DEPOSITION:
        if axis == 0:
            new_coverages = (coverages[indices - 1, :] +
                             coverages[indices, :]) / 2
        else:
            new_coverages = (coverages[:, indices - 1] +
                             coverages[:, indices]) / 2
        coverages = np.insert(coverages, indices, new_coverages, axis)
        self.coverages = coverages.reshape(self.len_xy)

        self.material_names = material_names.reshape(self.len_xy)
        self.material_densities = material_densities.reshape(self.len_xy)
        self.beam_fluxes = beam_fluxes.reshape(self.len_xy)
        self.fluxes = fluxes.reshape(self.len_xy)
        self.flux_is_valid = flux_is_valid.reshape(self.len_xy)
        #if par.ETCHING | par.DEPOSITION:
        self.coverages = coverages.reshape(self.len_xy)