Exemplo n.º 1
0
Arquivo: bfpss.py Projeto: vovkd/ahkab
def build_CMAT(mna, D, step, points, tick, n_of_var=None, verbose=3):
	if n_of_var is None: 
		n_of_var = mna.shape[0]
	printing.print_info_line(("Building CMAT (%dx%d)... " % (n_of_var*points, n_of_var*points), 5), verbose, print_nl=False)
	tick.reset()
	tick.display(verbose > 2)
	(C1, C0) = implicit_euler.get_df_coeff(step)
	I = numpy.mat(numpy.eye(n_of_var))
	M = mna + C1*D
	N = C0 * D
	#Z = numpy.mat(numpy.zeros((n_of_var, n_of_var)))
	CMAT = numpy.mat(numpy.zeros((n_of_var*points, n_of_var*points)))
	for li in xrange(points): #li = line index
		for ci in xrange(points):
			if li == 0:
				if ci == 0:
					temp = 1.0 * I
				elif ci == points - 1:
					temp = -1.0 * I
				else:
					continue #temp = Z
			else:
				if ci == li:
					temp = M
				elif ci == li -1:
					temp = N
				else:
					continue #temp = Z
			CMAT = set_submatrix(row=li*n_of_var, col=ci*n_of_var, dest_matrix=CMAT, source_matrix=temp)
		tick.step(verbose > 2)
	tick.hide(verbose > 2)
	printing.print_info_line(("done.", 5), verbose)

	return CMAT
Exemplo n.º 2
0
def get_variable_MAass_and_Tass(circ, xi, xi_minus_1, M, D, step, n_of_var):
    Tass = numpy.zeros((n_of_var, 1))
    J = numpy.zeros((n_of_var, n_of_var))
    (C1, C0) = implicit_euler.get_df_coeff(step)

    for elem in circ:
        # build all dT(xn)/dxn (stored in J) and T(x)
        if elem.is_nonlinear:
            output_ports = elem.get_output_ports()
            for index in range(len(output_ports)):
                n1, n2 = output_ports[index]
                ports = elem.get_drive_ports(index)
                v_ports = []
                for port in ports:
                    v = 0  # build v: remember we trashed the 0 row and 0 col of mna -> -1
                    if port[0]:
                        v = v + xi[port[0] - 1, 0]
                    if port[1]:
                        v = v - xi[port[1] - 1, 0]
                    v_ports.append(v)
                if n1:
                    Tass[n1 - 1, 0] = Tass[n1 - 1, 0] + elem.i(index, v_ports)
                if n2:
                    Tass[n2 - 1, 0] = Tass[n2 - 1, 0] - elem.i(index, v_ports)
                for pindex in xrange(len(ports)):
                    if n1:
                        if ports[pindex][0]:
                            J[n1 - 1, ports[pindex][0] - 1] = \
                                J[n1 - 1, ports[pindex][0] - 1] + elem.g(
                                    index, v_ports, pindex)
                        if ports[pindex][1]:
                            J[n1 - 1, ports[pindex][1] - 1] =\
                                J[n1 - 1, ports[pindex][1] - 1] - 1.0 * elem.g(
                                    index, v_ports, pindex)
                    if n2:
                        if ports[pindex][0]:
                            J[n2 - 1, ports[pindex][0] - 1] = \
                                J[n2 - 1, ports[pindex][0] - 1] - 1.0 * elem.g(
                                    index, v_ports, pindex)
                        if ports[pindex][1]:
                            J[n2 - 1, ports[pindex][1] - 1] =\
                                J[n2 - 1, ports[pindex][1] - 1] + elem.g(
                                    index, v_ports, pindex)

    Tass = Tass + D * C1 * xi + M * xi + D * C0 * xi_minus_1

    return (J, Tass)
Exemplo n.º 3
0
def get_variable_MAass_and_Tass(circ, xi, xi_minus_1, M, D, step, n_of_var):
    Tass = numpy.zeros((n_of_var, 1))
    J = numpy.zeros((n_of_var, n_of_var))
    (C1, C0) = implicit_euler.get_df_coeff(step)

    for elem in circ:
        # build all dT(xn)/dxn (stored in J) and T(x)
        if elem.is_nonlinear:
            output_ports = elem.get_output_ports()
            for index in range(len(output_ports)):
                n1, n2 = output_ports[index]
                ports = elem.get_drive_ports(index)
                v_ports = []
                for port in ports:
                    v = 0  # build v: remember we trashed the 0 row and 0 col of mna -> -1
                    if port[0]:
                        v = v + xi[port[0] - 1, 0]
                    if port[1]:
                        v = v - xi[port[1] - 1, 0]
                    v_ports.append(v)
                if n1:
                    Tass[n1 - 1, 0] = Tass[n1 - 1, 0] + elem.i(index, v_ports)
                if n2:
                    Tass[n2 - 1, 0] = Tass[n2 - 1, 0] - elem.i(index, v_ports)
                for pindex in xrange(len(ports)):
                    if n1:
                        if ports[pindex][0]:
                            J[n1 - 1, ports[pindex][0] - 1] = \
                                J[n1 - 1, ports[pindex][0] - 1] + elem.g(
                                    index, v_ports, pindex)
                        if ports[pindex][1]:
                            J[n1 - 1, ports[pindex][1] - 1] =\
                                J[n1 - 1, ports[pindex][1] - 1] - 1.0 * elem.g(
                                    index, v_ports, pindex)
                    if n2:
                        if ports[pindex][0]:
                            J[n2 - 1, ports[pindex][0] - 1] = \
                                J[n2 - 1, ports[pindex][0] - 1] - 1.0 * elem.g(
                                    index, v_ports, pindex)
                        if ports[pindex][1]:
                            J[n2 - 1, ports[pindex][1] - 1] =\
                                J[n2 - 1, ports[pindex][1] - 1] + elem.g(
                                    index, v_ports, pindex)

    Tass = Tass + D * C1 * xi + M * xi + D * C0 * xi_minus_1

    return (J, Tass)
Exemplo n.º 4
0
def build_CMAT(mna, D, step, points, tick, n_of_var=None, verbose=3):
    if n_of_var is None:
        n_of_var = mna.shape[0]
    printing.print_info_line(("Building CMAT (%dx%d)... " %
                              (n_of_var * points, n_of_var * points), 5),
                             verbose,
                             print_nl=False)
    tick.reset()
    tick.display(verbose > 2)
    (C1, C0) = implicit_euler.get_df_coeff(step)
    I = numpy.mat(numpy.eye(n_of_var))
    M = mna + C1 * D
    N = C0 * D
    # Z = numpy.mat(numpy.zeros((n_of_var, n_of_var)))
    CMAT = numpy.mat(numpy.zeros((n_of_var * points, n_of_var * points)))
    for li in xrange(points):  # li = line index
        for ci in xrange(points):
            if li == 0:
                if ci == 0:
                    temp = 1.0 * I
                elif ci == points - 1:
                    temp = -1.0 * I
                else:
                    continue  # temp = Z
            else:
                if ci == li:
                    temp = M
                elif ci == li - 1:
                    temp = N
                else:
                    continue  # temp = Z
            CMAT = set_submatrix(row=li * n_of_var,
                                 col=ci * n_of_var,
                                 dest_matrix=CMAT,
                                 source_matrix=temp)
        tick.step(verbose > 2)
    tick.hide(verbose > 2)
    printing.print_info_line(("done.", 5), verbose)

    return CMAT
Exemplo n.º 5
0
def build_static_MAass_and_MBass(mna, D, step):
    (C1, C0) = implicit_euler.get_df_coeff(step)
    MAass = mna + D * C1
    MBass = D * C0
    return (MAass, MBass)
Exemplo n.º 6
0
def build_static_MAass_and_MBass(mna, D, step):
    (C1, C0) = implicit_euler.get_df_coeff(step)
    MAass = mna + D * C1
    MBass = D * C0
    return (MAass, MBass)