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)
def single_ground_solver(G, src, dst, solver_type, ml): """Solver used for pairwise mode.""" n = G.shape[0] rhs = np.zeros(n, dtype = 'float64') if src==dst: voltages = np.zeros(n, dtype = 'float64') else: rhs[dst] = -1 rhs[src] = 1 voltages = ComputeBase.solve_linear_system (G, rhs, solver_type, ml) return voltages