Ejemplo n.º 1
0
 def __init__(self,
              name,
              IS=None,
              N=None,
              ISR=None,
              NR=None,
              RS=None,
              CJ0=None,
              M=None,
              VJ=None,
              FC=None,
              CP=None,
              TT=None,
              BV=None,
              IBV=None,
              KF=None,
              AF=None,
              FFE=None,
              TEMP=None,
              XTI=None,
              EG=None,
              TBV=None,
              TRS=None,
              TTT1=None,
              TTT2=None,
              TM1=None,
              TM2=None):
     self.name = name
     self.IS = float(IS) if IS is not None else IS_DEFAULT
     self.N = float(N) if N is not None else N_DEFAULT
     self.ISR = float(ISR) if ISR is not None else ISR_DEFAULT
     self.NR = float(NR) if NR is not None else NR_DEFAULT
     self.RS = float(RS) if RS is not None else RS_DEFAULT
     self.CJ0 = float(CJ0) if CJ0 is not None else CJ0_DEFAULT
     self.M = float(M) if M is not None else M_DEFAULT
     self.VJ = float(VJ) if VJ is not None else VJ_DEFAULT
     self.FC = float(FC) if FC is not None else FC_DEFAULT
     self.CP = float(CP) if CP is not None else CP_DEFAULT
     self.TT = float(TT) if TT is not None else TT_DEFAULT
     self.BV = float(BV) if BV is not None else BV_DEFAULT
     self.IBV = float(IBV) if IBV is not None else IBV_DEFAULT
     self.KF = float(KF) if KF is not None else KF_DEFAULT
     self.AF = float(AF) if AF is not None else AF_DEFAULT
     self.FFE = float(FFE) if FFE is not None else FFE_DEFAULT
     self.TEMP = utilities.Celsius2Kelvin(
         float(TEMP)) if TEMP is not None else TEMP_DEFAULT
     self.XTI = float(XTI) if XTI is not None else XTI_DEFAULT
     self.EG = float(EG) if EG is not None else EG_DEFAULT
     self.TBV = float(TBV) if TBV is not None else TBV_DEFAULT
     self.TRS = float(TRS) if TRS is not None else TRS_DEFAULT
     self.TTT1 = float(TTT1) if TTT1 is not None else TTT1_DEFAULT
     self.TTT2 = float(TTT2) if TTT2 is not None else TTT2_DEFAULT
     self.TM1 = float(TM1) if TM1 is not None else TM1_DEFAULT
     self.TM2 = float(TM2) if TM2 is not None else TM2_DEFAULT
     self.T = T_DEFAULT
     self.last_vd = None
     self.VT = constants.Vth(self.T)
Ejemplo n.º 2
0
def process_analysis(an_list,
                     circ,
                     outfile,
                     verbose,
                     cli_tran_method=None,
                     guess=True,
                     disable_step_control=False):
    """ Processes an analysis vector:
	an_list: the list of analysis to be performed, as returned by netlist_parser
	circ: the circuit instance, returned by netlist_parser
	outfile: a filename. Results will be written to it. If set to stdout, prints to stdout
	verbose: verbosity level
	cli_tran_method: force the specified method in each tran analysis (see transient.py)
	guess: use the builtin method get_dc_guess to guess x0
	
	Returns: None
	"""
    x0_op = None
    x0_ic_dict = {}
    results = {}

    for directive in [x for x in an_list if x["type"] == "ic"]:
        x0_ic_dict.update({
         directive["name"]:\
         dc_analysis.build_x0_from_user_supplied_ic(circ, voltages_dict=directive["vdict"], currents_dict=directive["cdict"])
         })

    for an in an_list:
        if outfile != 'stdout':
            data_filename = outfile + "." + an["type"]
        else:
            data_filename = outfile

        if an["type"] == "ic":
            continue

        if an["type"] == "op":
            if not an.has_key('guess_label') or an["guess_label"] is None:
                x0_op = dc_analysis.op_analysis(circ,
                                                guess=guess,
                                                data_filename=data_filename,
                                                verbose=verbose)
            else:
                if not an["guess_label"] in x0_ic_dict:
                    printing.print_warning(
                        "op: guess is set but no matching .ic directive was found."
                    )
                    printing.print_warning(
                        "op: using built-in guess method: " + str(guess))
                    x0_op = dc_analysis.op_analysis(circ,
                                                    guess=guess,
                                                    verbose=verbose)
                else:
                    x0_op = dc_analysis.op_analysis(
                        circ,
                        guess=False,
                        x0=x0_ic_dict[an["guess_label"]],
                        verbose=verbose)
            sol = x0_op

        elif an["type"] == "dc":
            if an["source_name"][0].lower() == "v":
                elem_type = "vsource"
            elif an["source_name"][0].lower() == "i":
                elem_type = "isource"
            else:
                printing.print_general_error(
                    "Type of sweep source is unknown: " + an[1][0])
                sys.exit(1)
            sol = dc_analysis.dc_analysis(
              circ, start=an["start"], stop=an["stop"], step=an["step"], \
              type_descr=(elem_type, an["source_name"][1:]),
              xguess=x0_op, data_filename=data_filename, guess=guess,
              stype=an['stype'], verbose=verbose)

        #{"type":"tran", "tstart":tstart, "tstop":tstop, "tstep":tstep, "uic":uic, "method":method, "ic_label":ic_label}
        elif an["type"] == "tran":
            if cli_tran_method is not None:
                tran_method = cli_tran_method.upper()
            elif an["method"] is not None:
                tran_method = an["method"].upper()
            else:
                tran_method = options.default_tran_method

            # setup the initial condition (t=0) according to uic
            # uic = 0 -> all node voltages and currents are zero
            # uic = 1 -> node voltages and currents are those computed in the last OP analysis
            # uic = 2 -> node voltages and currents are those computed in the last OP analysis
            #            combined with the ic=XX directive found in capacitors and inductors
            # uic = 3 -> use a .ic directive defined by the user
            uic = an["uic"]
            if uic == 0:
                x0 = None
            elif uic == 1:
                if x0_op is None:
                    printing.print_general_error(
                        "uic is set to 1, but no op has been calculated yet.")
                    sys.exit(51)
                x0 = x0_op
            elif uic == 2:
                if x0_op is None:
                    printing.print_general_error(
                        "uic is set to 2, but no op has been calculated yet.")
                    sys.exit(51)
                x0 = dc_analysis.modify_x0_for_ic(circ, x0_op)
            elif uic == 3:
                if an["ic_label"] is None:
                    printing.print_general_error(
                        "uic is set to 3, but param ic=<ic_label> was not defined."
                    )
                    sys.exit(53)
                elif not an["ic_label"] in x0_ic_dict:
                    printing.print_general_error("uic is set to 3, but no .ic directive named %s was found." \
                     %(str(an["ic_label"]),))
                    sys.exit(54)
                x0 = x0_ic_dict[an["ic_label"]]

            sol = transient.transient_analysis(circ, \
             tstart=an["tstart"], tstep=an["tstep"], tstop=an["tstop"], \
             x0=x0, mna=None, N=None, verbose=verbose, data_filename=data_filename, \
             use_step_control=(not disable_step_control), method=tran_method)

        elif an["type"] == "shooting":
            if an["method"] == "brute-force":
                sol = bfpss.bfpss(circ, period=an["period"], step=an["step"], mna=None, Tf=None, \
                 D=None, points=an["points"], autonomous=an["autonomous"], x0=x0_op, \
                 data_filename=data_filename, verbose=verbose)
            elif an["method"] == "shooting":
                sol = shooting.shooting(circ, period=an["period"], step=an["step"], mna=None, \
                 Tf=None, D=None, points=an["points"], autonomous=an["autonomous"], \
                 data_filename=data_filename, verbose=verbose)
        elif an["type"] == "symbolic":
            if not 'subs' in an.keys():
                an.update({'subs': None})
            sol = symbolic.solve(circ,
                                 an['source'],
                                 opts={'ac': an['ac']},
                                 subs=an['subs'],
                                 verbose=verbose)
        elif an["type"] == "ac":
            sol = ac.ac_analysis(circ=circ, start=an['start'], nsteps=an['nsteps'], \
             stop=an['stop'], step_type='LOG', xop=x0_op, mna=None,\
                    data_filename=data_filename, verbose=verbose)
        elif an["type"] == "temp":
            constants.T = utilities.Celsius2Kelvin(an['temp'])
        results.update({an["type"]: sol})
    return results
Ejemplo n.º 3
0
TT_DEFAULT = .0
BV_DEFAULT = float('inf')
IBV_DEFAULT = 1e-3
KF_DEFAULT = .0
AF_DEFAULT = 1.
FFE_DEFAULT = 1.
TEMP_DEFAULT = 26.85
XTI_DEFAULT = 3.0
EG_DEFAULT = 1.11
TBV_DEFAULT = 0.0
TRS_DEFAULT = 0.0
TTT1_DEFAULT = 0.0
TTT2_DEFAULT = 0.0
TM1_DEFAULT = 0.0
TM2_DEFAULT = 0.0
T_DEFAULT = utilities.Celsius2Kelvin(26.85)
AREA_DEFAULT = 1.0


class diode_model:
    def __init__(self,
                 name,
                 IS=None,
                 N=None,
                 ISR=None,
                 NR=None,
                 RS=None,
                 CJ0=None,
                 M=None,
                 VJ=None,
                 FC=None,
Ejemplo n.º 4
0
def set_temperature(T):
    T = float(T)
    if T > 300:
        printing.print_warning(u"The temperature will be set to %f \xB0 C.")
    constants.T = utilities.Celsius2Kelvin(T)