def main(args): if len(args) < 2: print('Usage: python ' + args[0] + ' input.txt [output.txt]') sys.exit() parser = Parser() comps_linear = [] comps_diodes = [] with open(args[1]) as file: for line in file: comp = parser.next_entry(line) if comp is not None: if isinstance(comp, spicemix.Diode): comps_diodes.append(comp) else: comps_linear.append(comp) n, m = find_n_m_size(comps_linear + comps_diodes) builder = StampBuilder(n, m) for comp in comps_linear: builder.add_component(comp) prev = start_appr for d in comps_diodes: d.set_vol_zero(start_appr) if len(comps_diodes) > 0: # the_p = comps_diodes[len(comps_diodes) - 1].get_p_node() min = start_appr while True: prepared_builder = deepcopy(builder) for d in comps_diodes: prepared_builder.add_component(d) prepared_builder.clear_zer() a, z = prepared_builder.get_a_z() solution = gaussian_elimintaion(a, z) for d in comps_diodes: kek = d.get_p_node() - 1 if solution[kek] < min: min = solution[kek] for d in comps_diodes: d.set_vol_zero(min) dx = fabs(comps_diodes[0].get_value() - prev) prev = comps_diodes[0].get_value() if dx < eps: break # why python hasnt do while ? else: builder.clear_zer() a, z = builder.get_a_z() solution = gaussian_elimintaion(a, z) if len(args) > 2: form_output(args[2], solution, n, m) else: print_matrix(solution)
def setUp(self): self.entries = { '* Whole line comment': None, 'R1 1 2 1000 * Это комментарий': (spicemix.Resistor, 1, 1, 2, 1000), 'R2 2 0 1000': (spicemix.Resistor, 2, 2, 0, 1000), 'V1 1 0 2': (spicemix.Voltage, 1, 1, 0, 2), 'D1 2 0': (spicemix.Diode, 1, 2, 0, None), } self.n = 3 self.m = 1 self.v0 = 0.8 i = 1e-12 * (exp(self.v0 / 25.85e-3) - 1) self.cut_matrix_a = [ [1e-3, -1e-3, 1], [-1e-3, 1e-3 + 1e-3 + i / 25.85e-3, 0], [1, 0, 0], ] self.cut_matrix_z = [0, -(i - i / 25.85e-3 * self.v0), 2] self.parser = parser.Parser() self.builder = StampBuilder(self.n, self.m)