Ejemplo n.º 1
0
    def multiple_solver(self, G, sources, grounds, finitegrounds):
        """Solver used for advanced mode."""  
        Gsolve = G
        if finitegrounds[0] != -9999:
            Gsolve = G + sparse.spdiags(finitegrounds.T, 0, G.shape[0], G.shape[0])
        
        ##remove infinite grounds from graph
        infgroundlist = np.where(grounds==np.Inf)
        infgroundlist = infgroundlist[0]
        numinfgrounds = infgroundlist.shape[0]
        
        dst_to_delete = []
        for ground in range(1, numinfgrounds+1):
            dst = infgroundlist[numinfgrounds-ground]
            dst_to_delete.append(dst)
            #Gsolve = deleterowcol(Gsolve, delrow = dst, delcol = dst)
            keep = np.delete(np.arange(0, sources.shape[0]), dst)
            sources = sources[keep]            
        Gsolve = ComputeBase.deleterowcol(Gsolve, delrow = dst_to_delete, delcol = dst_to_delete)
        
        self.state.create_amg_hierarchy(Gsolve, self.options.solver)
        voltages = ComputeBase.solve_linear_system(Gsolve, sources, self.options.solver, self.state.amg_hierarchy)
        del Gsolve
        self.state.del_amg_hierarchy()

        numinfgrounds = infgroundlist.shape[0]
        if numinfgrounds>0:
            #replace infinite grounds in voltage vector
            for ground in range(numinfgrounds,0, -1): 
                node = infgroundlist[numinfgrounds - ground] 
                voltages = np.asmatrix(np.insert(voltages,node,0)).T
        return np.asarray(voltages).reshape(voltages.size)