diff --git a/src/xspice/mif/mifsetup.c b/src/xspice/mif/mifsetup.c index 3cf93fb2d..901528877 100644 --- a/src/xspice/mif/mifsetup.c +++ b/src/xspice/mif/mifsetup.c @@ -459,6 +459,97 @@ MIFunsetup(GENmodel *inModel,CKTcircuit *ckt) for (model = (MIFmodel *)inModel; model != NULL; model = model->MIFnextModel) { + 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 = tprintf("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 = tprintf("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 == 0) { + SPfrontEnd->IFerrorf (ERR_FATAL, + "%s: unknown controlling source %s", here->MIFname, here->conn[i]->port[j]->vsource_str); + return(E_BADPARM); + } + } /* end if vsource current input */ + + } /* end for number of ports */ + } /* end for number of connections */ + } /* end for all instances */ } /* printf("MIFunsetup completed.\n");*/ return OK;