📄 evtsetup.c
字号:
int num_outputs; Mif_Boolean_t invert; Evt_Node_Data_t *node_data; Evt_State_Data_t *state_data; Evt_Msg_Data_t *msg_data; /* Evt_Statistic_t *statistics_data;*/ Evt_Node_t *rhs; Evt_Node_t *rhsold; Evt_Node_Info_t *node_info; /* Allocate main substructures of data */ /* Note that we don't free any old structures */ /* since they are pointed to by jobs and need */ /* to be maintained so that results from multiple */ /* jobs are kept around like SPICE does */ data = &(ckt->evt->data); CKALLOC(data->node, 1, Evt_Node_Data_t) CKALLOC(data->state, 1, Evt_State_Data_t) CKALLOC(data->msg, 1, Evt_Msg_Data_t) CKALLOC(data->statistics, 1, Evt_Statistic_t) /* Allocate node data */ num_nodes = ckt->evt->counts.num_nodes; node_data = data->node; CKALLOC(node_data->head, num_nodes, void *) CKALLOC(node_data->tail, num_nodes, void *) CKALLOC(node_data->last_step, num_nodes, void *) CKALLOC(node_data->free, num_nodes, void *) CKALLOC(node_data->modified_index, num_nodes, int) CKALLOC(node_data->modified, num_nodes, Mif_Boolean_t) CKALLOC(node_data->rhs, num_nodes, Evt_Node_t) CKALLOC(node_data->rhsold, num_nodes, Evt_Node_t) CKALLOC(node_data->total_load, num_nodes, double) /* Initialize the node data */ for(i = 0; i < num_nodes; i++) { node_data->tail[i] = &(node_data->head[i]); node_data->last_step[i] = &(node_data->head[i]); } for(i = 0; i < num_nodes; i++) { /* Get pointers to rhs & rhsold, the user-defined node type index, */ /* the number of outputs on the node and the invert flag */ rhs = &(node_data->rhs[i]); rhsold = &(node_data->rhsold[i]); node_info = ckt->evt->info.node_table[i]; udn_index = node_info->udn_index; num_outputs = node_info->num_outputs; invert = node_info->invert; /* Initialize the elements within rhs and rhsold */ rhs->step = 0.0; rhsold->step = 0.0; if(num_outputs > 1) { CKALLOC(rhs->output_value, num_outputs, void *) CKALLOC(rhsold->output_value, num_outputs, void *) for(j = 0; j < num_outputs; j++) { (*(g_evt_udn_info[udn_index]->create)) (&(rhs->output_value[j])); (*(g_evt_udn_info[udn_index]->initialize)) (rhs->output_value[j]); (*(g_evt_udn_info[udn_index]->create)) (&(rhsold->output_value[j])); (*(g_evt_udn_info[udn_index]->initialize)) (rhsold->output_value[j]); } } (*(g_evt_udn_info[udn_index]->create)) (&(rhs->node_value)); (*(g_evt_udn_info[udn_index]->initialize)) (rhs->node_value); (*(g_evt_udn_info[udn_index]->create)) (&(rhsold->node_value)); (*(g_evt_udn_info[udn_index]->initialize)) (rhsold->node_value); if(invert) { (*(g_evt_udn_info[udn_index]->create)) (&(rhs->inverted_value)); (*(g_evt_udn_info[udn_index]->initialize)) (rhs->inverted_value); (*(g_evt_udn_info[udn_index]->create)) (&(rhsold->inverted_value)); (*(g_evt_udn_info[udn_index]->initialize)) (rhsold->inverted_value); } /* Initialize the total load value to zero */ node_data->total_load[i] = 0.0; } /* Allocate and initialize state data */ num_insts = ckt->evt->counts.num_insts; state_data = data->state; CKALLOC(state_data->head, num_insts, void *) CKALLOC(state_data->tail, num_insts, void *) CKALLOC(state_data->last_step, num_insts, void *) CKALLOC(state_data->free, num_insts, void *) CKALLOC(state_data->modified_index, num_insts, int) CKALLOC(state_data->modified, num_insts, Mif_Boolean_t) CKALLOC(state_data->total_size, num_insts, int) CKALLOC(state_data->desc, num_insts, void *) for(i = 0; i < num_insts; i++) { state_data->tail[i] = &(state_data->head[i]); state_data->last_step[i] = &(state_data->head[i]); } /* Allocate and initialize msg data */ num_ports = ckt->evt->counts.num_ports; msg_data = data->msg; CKALLOC(msg_data->head, num_ports, void *) CKALLOC(msg_data->tail, num_ports, void *) CKALLOC(msg_data->last_step, num_ports, void *) CKALLOC(msg_data->free, num_ports, void *) CKALLOC(msg_data->modified_index, num_ports, int) CKALLOC(msg_data->modified, num_ports, Mif_Boolean_t) for(i = 0; i < num_ports; i++) { msg_data->tail[i] = &(msg_data->head[i]); msg_data->last_step[i] = &(msg_data->head[i]); } /* Don't need to initialize statistics since they were */ /* calloc'ed above */ return(OK);}/*EVTsetup_jobsThis function prepares the jobs data for a new simulation.*/static int EVTsetup_jobs( CKTcircuit *ckt) /* The circuit structure */{ int i; int num_jobs; Evt_Job_t *jobs; Evt_Data_t *data; jobs = &(ckt->evt->jobs); data = &(ckt->evt->data); /* Increment the number of jobs */ num_jobs = ++(jobs->num_jobs); /* Allocate/reallocate necessary pointers */ CKREALLOC(jobs->job_name, num_jobs, void *) CKREALLOC(jobs->node_data, num_jobs, void *) CKREALLOC(jobs->state_data, num_jobs, void *) CKREALLOC(jobs->msg_data, num_jobs, void *) CKREALLOC(jobs->statistics, num_jobs, void *) /* Fill in the pointers, etc. for this new job */ i = num_jobs - 1; jobs->job_name[i] = MIFcopy((char *) ckt->CKTcurJob->JOBname); jobs->node_data[i] = data->node; jobs->state_data[i] = data->state; jobs->msg_data[i] = data->msg; jobs->statistics[i] = data->statistics; return(OK);}/*EVTsetup_load_ptrsThis function setups up the required data in the MIFinstancestructure of event-driven and hybrid instances.*/static int EVTsetup_load_ptrs( CKTcircuit *ckt) /* The circuit structure */{ int i; int j; int k; int num_insts; int num_conn; int num_port; int num_outputs; int node_index; int output_subindex; MIFinstance *fast; Mif_Conn_Data_t *conn; Mif_Port_Type_t type; Mif_Port_Data_t *port; Evt_Node_Data_t *node_data; /* This function setups up the required data in the MIFinstance */ /* structure of event-driven and hybrid instances */ /* Loop through all event-driven and hybrid instances */ num_insts = ckt->evt->counts.num_insts; for(i = 0; i < num_insts; i++) { /* Get the MIFinstance pointer */ fast = ckt->evt->info.inst_table[i]->inst_ptr; /* Loop through all connections */ num_conn = fast->num_conn; for(j = 0; j < num_conn; j++) { /* Skip if connection is null */ if(fast->conn[j]->is_null) continue; conn = fast->conn[j]; /* Loop through all ports */ num_port = conn->size; for(k = 0; k < num_port; k++) { /* Get port data pointer for quick access */ port = conn->port[k]; if(port->is_null) continue; /* Skip if port is not digital or user-defined type */ type = port->type; if((type != MIF_DIGITAL) && (type != MIF_USER_DEFINED)) continue; /* Set input.pvalue to point to rhsold.node_value or to */ /* rhsold.inverted_value as appropriate */ node_index = port->evt_data.node_index; node_data = ckt->evt->data.node; if(conn->is_input) { if(port->invert) { port->input.pvalue = node_data->rhsold[node_index]. inverted_value; } else { port->input.pvalue = node_data->rhsold[node_index]. node_value; } } /* Set output.pvalue to point to rhs.node_value or rhs.output_value[i] */ /* where i is given by the output_subindex in output info */ /* depending on whether more than one output is connected to the node. */ /* Note that this is only for the DCOP analysis. During a transient */ /* analysis, new structures will be created and the pointers will */ /* be set by EVTload */ if(conn->is_output) { num_outputs = ckt->evt->info.node_table[node_index]->num_outputs; if(num_outputs <= 1) { port->output.pvalue = node_data->rhs[node_index]. node_value; } else { output_subindex = port->evt_data.output_subindex; port->output.pvalue = node_data->rhs[node_index]. output_value[output_subindex]; } } } /* end for number of ports */ } /* end for number of connections */ } /* end for number of insts */ return(OK);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -