⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mifsetup.c

📁 ngspice又一个电子CAD仿真软件代码.功能更全
💻 C
📖 第 1 页 / 共 2 页
字号:
            }        }		        /* Loop through all instances of this model and for each port of each connection */        /* create current equations, matrix entries, and matrix pointers as necessary.   */	        for(here = model->MIFinstances; here != NULL; here = here->MIFnextInstance) {	  /* Skip these expensive allocations if the instance is not analog */	  if(! here->analog)	    continue;	  	  num_conn = here->num_conn;            /* loop through all connections on this instance */            /* and create matrix data needed for outputs and */            /* V sources associated with I inputs            */            for(i = 0; i < num_conn; i++) {                /* if the connection is null, skip to next connection */                if(here->conn[i]->is_null)                    continue;                /* prepare things for convenient access later */                is_input = here->conn[i]->is_input;                is_output = here->conn[i]->is_output;                num_port = here->conn[i]->size;                /* loop through all ports on this connection */                for(j = 0; j < num_port; j++) {                    /* if port is null, skip to next */                    if(here->conn[i]->port[j]->is_null)                        continue;                    /* determine the type of this port */                    type = here->conn[i]->port[j]->type;                    /* create a pointer to the smp data for quick access */                    smp_data_out = &(here->conn[i]->port[j]->smp_data);                    /* if it has a voltage source output, */                    /* create the matrix data needed      */                    if( (is_output && (type == MIF_VOLTAGE || type == MIF_DIFF_VOLTAGE)) ||                                     (type == MIF_RESISTANCE || type == MIF_DIFF_RESISTANCE) ) {                        /* first, make the current equation */                        suffix = (void *) MALLOC(strlen((char *) here->MIFname) + 100);                        sprintf(suffix, "branch_%d_%d", i, j);                        error = CKTmkCur(ckt, &tmp, here->MIFname, suffix);                        FREE(suffix);                        if(error)                            return(error);                        smp_data_out->branch = tmp->number;                        /* ibranch is needed to find the input equation for RESISTANCE type */                        smp_data_out->ibranch = tmp->number;                        /* then make the matrix pointers */                        TSTALLOC(pos_branch, pos_node, branch);                        TSTALLOC(neg_branch, neg_node, branch);                        TSTALLOC(branch_pos, branch,  pos_node);                        TSTALLOC(branch_neg, branch,  neg_node);                    } /* end if current input */                    /* if it is a current input */                    /* create the matrix data needed for the associated zero-valued V source */                    if(is_input && (type == MIF_CURRENT || type == MIF_DIFF_CURRENT)) {                        /* first, make the current equation */                        suffix = (void *) MALLOC(strlen((char *) here->MIFname) + 100);                        sprintf(suffix, "ibranch_%d_%d", i, j);                        error = CKTmkCur(ckt, &tmp, here->MIFname, suffix);                        FREE(suffix);                        if(error)                            return(error);                        smp_data_out->ibranch = tmp->number;                        /* then make the matrix pointers */                        TSTALLOC(pos_ibranch, pos_node, ibranch);                        TSTALLOC(neg_ibranch, neg_node, ibranch);                        TSTALLOC(ibranch_pos, ibranch,  pos_node);                        TSTALLOC(ibranch_neg, ibranch,  neg_node);                    } /* end if current input */                    /* if it is a vsource current input (refers to a vsource elsewhere */                    /* in the circuit), locate the source and get its equation number  */                    if(is_input && (type == MIF_VSOURCE_CURRENT)) {                        smp_data_out->ibranch = CKTfndBranch(ckt,                                                 here->conn[i]->port[j]->vsource_str);                        if(smp_data_out->ibranch == (int)NULL) {                            IFuid names[2];                            names[0] = here->MIFname;                            names[1] = (IFuid) here->conn[i]->port[j]->vsource_str;                            (*(SPfrontEnd->IFerror))(ERR_FATAL,                                    "%s: unknown controlling source %s",names);                            return(E_BADPARM);                        }                    } /* end if vsource current input */                } /* end for number of ports */            } /* end for number of connections */            /* now loop through all connections on the instance and create */            /* matrix data needed for partial derivatives of outputs       */            for(i = 0; i < num_conn; i++) {                /* if the connection is null or is not an output */                /* skip to next connection */                if((here->conn[i]->is_null) || (! here->conn[i]->is_output))                    continue;                /* loop through all ports on this connection */                num_port = here->conn[i]->size;                for(j = 0; j < num_port; j++) {                    /* if port is null, skip to next */                    if(here->conn[i]->port[j]->is_null)                        continue;                    /* determine the type of this output port */                    out_type = here->conn[i]->port[j]->type;                    /* create a pointer to the smp data for quick access */                    smp_data_out = &(here->conn[i]->port[j]->smp_data);                    /* for this port, loop through all connections */                    /* and all ports to touch on each possible input */                    for(k = 0; k < num_conn; k++) {                        /* if the connection is null or is not an input */                        /* skip to next connection */                        if((here->conn[k]->is_null) || (! here->conn[k]->is_input))                            continue;                        num_port_k = here->conn[k]->size;                        /* loop through all the ports of this connection */                        for(l = 0; l < num_port_k; l++) {                            /* if port is null, skip to next */                            if(here->conn[k]->port[l]->is_null)                                continue;                            /* determine the type of this input port */                            in_type = here->conn[k]->port[l]->type;                            /* create a pointer to the smp data for quick access */                            smp_data_cntl = &(here->conn[k]->port[l]->smp_data);                            /* determine type of controlled source according */                            /* to input and output types */                            cntl_src_type = MIFget_cntl_src_type(in_type, out_type);                            switch(cntl_src_type) {                            case MIF_VCVS:                                CTSTALLOC(e.branch_poscntl, branch, pos_node);                                CTSTALLOC(e.branch_negcntl, branch, neg_node);                                break;                            case MIF_ICIS:                                CTSTALLOC(f.pos_ibranchcntl, pos_node, ibranch);                                CTSTALLOC(f.neg_ibranchcntl, neg_node, ibranch);                                break;                            case MIF_VCIS:                                CTSTALLOC(g.pos_poscntl, pos_node, pos_node);                                CTSTALLOC(g.pos_negcntl, pos_node, neg_node);                                CTSTALLOC(g.neg_poscntl, neg_node, pos_node);                                CTSTALLOC(g.neg_negcntl, neg_node, neg_node);                                break;                            case MIF_ICVS:                                CTSTALLOC(h.branch_ibranchcntl, branch, ibranch);                                break;                            } /* end switch on controlled source type */                        } /* end for number of input ports */                    } /* end for number of input connections */                } /* end for number of output ports */            } /* end for number of output connections */        } /* end for all instances */    }  /* end for all models of this type */    return(OK);}intMIFunsetup(GENmodel *inModel,CKTcircuit *ckt){    MIFmodel *model;    MIFinstance *here;    Mif_Smp_Ptr_t  *smp_data_out;    Mif_Smp_Ptr_t  *smp_data_cntl;    Mif_Port_Type_t  type,in_type,out_type;    Mif_Cntl_Src_Type_t  cntl_src_type;    int num_conn,num_port,i,j,k,l,num_port_k;    for (model = (MIFmodel *)inModel; model != NULL;                              model = model->MIFnextModel)    {      for(here = model->MIFinstances; here != NULL;			here = here->MIFnextInstance)      {        num_conn=here->num_conn;        for(i = 0; i < num_conn; i++) {           // if the connection is null, skip to next connection           if(here->conn[i]->is_null) continue;           // prepare things for convenient access later           num_port = here->conn[i]->size;           // loop through all ports on this connection           for(j = 0; j < num_port; j++) {           // determine the type of this output port           out_type = here->conn[i]->port[j]->type;           // create a pointer to the smp data for quick access           smp_data_out = &(here->conn[i]->port[j]->smp_data);           for(k = 0; k < num_conn; k++) {                // if the connection is null or is not an input                // skip to next connection                if((here->conn[k]->is_null) || (! here->conn[k]->is_input))                            continue;                num_port_k = here->conn[k]->size;                // determine the type of this input port                for(l = 0; l < num_port_k; l++) {                  // if port is null, skip to next                  if(here->conn[k]->port[l]->is_null)                                continue;                  in_type = here->conn[i]->port[j]->type;                  cntl_src_type = MIFget_cntl_src_type(in_type, out_type);                  switch(cntl_src_type)                   {                    case MIF_VCVS:                    case MIF_ICVS:                    case MIF_VCIS:                    case MIF_ICIS:                    case -1:                      if(smp_data_out->branch)                      {                        CKTdltNNum(ckt, smp_data_out->branch);                        smp_data_out->branch = 0;                      }                      if(smp_data_out->ibranch)                      {                        CKTdltNNum(ckt, smp_data_out->ibranch);                        smp_data_out->ibranch = 0;                      }                      here->initialized=MIF_FALSE;                      break;                  }                }              }             }            }          }	}    //printf("MIFunsetup completed.\n");    return OK;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -