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

📄 mifsetup.c

📁 ngspice又一个电子CAD仿真软件代码.功能更全
💻 C
📖 第 1 页 / 共 2 页
字号:
/*============================================================================FILE    MIFsetup.cMEMBER OF process XSPICECopyright 1991Georgia Tech Research CorporationAtlanta, Georgia 30332All Rights ReservedPROJECT A-8503AUTHORS    9/12/91  Bill KuhnMODIFICATIONS    <date> <person name> <nature of modifications>SUMMARY    This file contains the function called by SPICE to setup data structures    of a code model after parsing, but prior to beginning a simulation.  The    major responsibilities of this function are to default values for model    parameters not given on the .model card, create equations in the matrix    for any voltage sources, and setup the matrix pointers used during    simulation to load the matrix.INTERFACES    MIFsetup()REFERENCED FILES    None.NON-STANDARD FEATURES    None.============================================================================*//* #include "prefix.h"  */#include "ngspice.h"#include "smpdefs.h"#include "devdefs.h"#include "sperror.h"#include "mifproto.h"#include "mifparse.h"#include "mifdefs.h"#include "mifcmdat.h"/* #include "suffix.h"  */extern SPICEdev **DEVices;        /* info about all device types */Mif_Boolean_t mif_UNSET=MIF_TRUE;/* define macro for easy creation of matrix entries/pointers for outputs */#define TSTALLOC(ptr,first,second) \        if((smp_data_out->ptr = \            SMPmakeElt(matrix, smp_data_out->first, smp_data_out->second)) == NULL) { \            return(E_NOMEM); \        }/* define macro for easy creation of matrix entries/pointers for inputs */#define CTSTALLOC(ptr,first,second) \        if((smp_data_out->input[k].port[l].ptr = \            SMPmakeElt(matrix, smp_data_out->first, smp_data_cntl->second)) == NULL) { \            return(E_NOMEM); \        }/*MIFsetupThis function is called by the CKTsetup() driver function toprepare all code model structures and all code model instancestructures for simulation.  It loops through all models of aparticular code model type and provides defaults for anyparameters not specified on a .model card.  It loops through allinstances of the model and prepares the instance structures forsimulation.  The most important setup task is the creation ofentries in the SPICE matrix and the storage of pointers tolocations of the matrix used by MIFload during a simulation.*/intMIFsetup(    SMPmatrix     *matrix,    /* The analog simulation matrix structure */    GENmodel      *inModel,   /* The head of the model list */    CKTcircuit    *ckt,       /* The circuit structure */    int           *states)    /* The states vector */{    MIFmodel    *model;    MIFinstance *here;    int         mod_type;    int         max_size;    int         size;    int         error;    int         num_conn;    int         num_port;    int         num_port_k;    int         i;    int         j;    int         k;    int         l;    Mif_Port_Type_t  type;    Mif_Port_Type_t  in_type;    Mif_Port_Type_t  out_type;    Mif_Cntl_Src_Type_t  cntl_src_type;    Mif_Smp_Ptr_t  *smp_data_out;    Mif_Smp_Ptr_t  *smp_data_cntl;    Mif_Param_Info_t  *param_info;    /* Mif_Conn_Info_t   *conn_info;*/    Mif_Boolean_t   is_input;    Mif_Boolean_t   is_output;    char        *suffix;    CKTnode     *tmp;    /* Setup for access into MIF specific model data */    model = (MIFmodel *) inModel;    mod_type = model->MIFmodType;    /* loop through all models of this type */    for( ; model != NULL; model = model->MIFnextModel) {        /* For each parameter not given explicitly on the .model */        /* card, default it                                      */        for(i = 0; i < model->num_param; i++) {            if(model->param[i]->is_null) {                /* setup a pointer for quick access */                param_info = &(DEVices[mod_type]->DEVpublic.param[i]);                /* determine the size and allocate the parameter element(s) */                if(! param_info->is_array) {                    model->param[i]->size = 1;                    model->param[i]->element = (void *) MALLOC(sizeof(Mif_Value_t));                }                else {  /* parameter is an array */                    /* MIF_INP2A() parser assures that there is an associated array connection */                    /* Since several instances may share this model, we have to create an array    */                    /* big enough for the instance with the biggest connection array               */                    max_size = 0;                    for(here = model->MIFinstances; here != NULL; here = here->MIFnextInstance) {                        size = here->conn[param_info->conn_ref]->size;                        if(size > max_size)                            max_size = size;                    }                    model->param[i]->size = max_size;                    model->param[i]->element = (void *) MALLOC(max_size * sizeof(Mif_Value_t));                }  /* end if parameter is an array */                /* set the parameter element(s) to default value */                for(j = 0; j < model->param[i]->size; j++) {                    switch(param_info->type) {                    case MIF_BOOLEAN:                        model->param[i]->element[j].bvalue = param_info->default_value.bvalue;                        break;                    case MIF_INTEGER:                        model->param[i]->element[j].ivalue = param_info->default_value.ivalue;                        break;                    case MIF_REAL:                        model->param[i]->element[j].rvalue = param_info->default_value.rvalue;                        break;                    case MIF_COMPLEX:                        model->param[i]->element[j].cvalue = param_info->default_value.cvalue;                        break;                    case MIF_STRING:                        model->param[i]->element[j].svalue = param_info->default_value.svalue;                        break;                    default:                        return(E_BADPARM);                    }                } /* end for number of elements in param array */            }  /* end if null */        }  /* end for number of parameters */        /* For each instance, initialize stuff used by cm_... functions */        for(here = model->MIFinstances; here != NULL; here = here->MIFnextInstance) {            here->num_state = 0;            here->state = NULL;            here->num_intgr = 0;            here->intgr = NULL;            here->num_conv = 0;            here->conv = NULL;        }        /* For each instance, allocate runtime structs for output connections/ports */        /* and grab a place in the state vector for all input connections/ports */        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;	  for(i = 0; i < num_conn; i++) {	    if((here->conn[i]->is_null) || (! here->conn[i]->is_output) )	      continue;	    num_port = here->conn[i]->size;	    for(j = 0; j < num_port; j++) {	      here->conn[i]->port[j]->partial =		(void *) MALLOC(num_conn * sizeof(Mif_Partial_t));	      here->conn[i]->port[j]->ac_gain =		(void *) MALLOC(num_conn * sizeof(Mif_AC_Gain_t));	      here->conn[i]->port[j]->smp_data.input =		(void *) MALLOC(num_conn * sizeof(Mif_Conn_Ptr_t));	      for(k = 0; k < num_conn; k++) {		if((here->conn[k]->is_null) || (! here->conn[k]->is_input) )		  continue;		num_port_k = here->conn[k]->size;		here->conn[i]->port[j]->partial[k].port =		  (void *) MALLOC(num_port_k * sizeof(double));		here->conn[i]->port[j]->ac_gain[k].port =		  (void *) MALLOC(num_port_k * sizeof(Mif_Complex_t));                        here->conn[i]->port[j]->smp_data.input[k].port =			  (void *) MALLOC(num_port_k * sizeof(Mif_Port_Ptr_t));	      }	    }	  }	              num_conn = here->num_conn;            for(i = 0; i < num_conn; i++) {	      if((here->conn[i]->is_null) || (! here->conn[i]->is_input) )		continue;	      num_port = here->conn[i]->size;	      for(j = 0; j < num_port; j++) {                    here->conn[i]->port[j]->old_input = *states;                    (*states)++;	      }

⌨️ 快捷键说明

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