Replace lengthy call to CKTcircuit by new TSTOP and TSTEP macros

This commit is contained in:
Holger Vogt 2026-06-07 19:22:40 +02:00
parent 28df521b11
commit d7db4192a8
1 changed files with 11 additions and 91 deletions

View File

@ -81,85 +81,6 @@ typedef struct {
double start_val; /* signal time 0 value */
} mLocal_Data_t;
struct CKTcircuitmin {
/* This is a minimum re-definition of the circuit structure defined in
cktdefs.h. We are interested in TSTEP and TSTOP */
GENmodel **CKThead;
STATistics *CKTstat; /* The STATistics structure */
double *CKTstates[8]; /* Used as memory of past steps ??? */
double CKTtime; /* Current transient simulation time */
double CKTdelta; /* next time step in transient simulation */
double CKTdeltaOld[7]; /* Memory for the 7 most recent CKTdelta */
double CKTtemp; /* Actual temperature of CKT, initialzed to 300.15 K in cktinit.c*/
double CKTnomTemp; /* Reference temperature 300.15 K set in cktinit.c */
double CKTvt; /* Thernmal voltage at CKTtemp */
double CKTag[7]; /* the gear variable coefficient matrix */
#ifdef PREDICTOR
double CKTagp[7]; /* the gear predictor variable coefficient matrix */
#endif /*PREDICTOR*/
int CKTorder; /* the integration method order */
int CKTmaxOrder; /* maximum integration method order */
int CKTintegrateMethod; /* the integration method to be used */
double CKTxmu; /* for trapezoidal method */
int CKTindverbosity; /* control check of inductive couplings */
SMPmatrix *CKTmatrix; /* pointer to sparse matrix */
int CKTniState; /* internal state */
double *CKTrhs; /* current rhs value - being loaded */
double *CKTrhsOld; /* previous rhs value for convergence testing */
double *CKTrhsSpare; /* spare rhs value for reordering */
double *CKTirhs; /* current rhs value - being loaded imag) */
double *CKTirhsOld; /* previous rhs value (imaginary)*/
double *CKTirhsSpare; /* spare rhs value (imaginary)*/
#ifdef PREDICTOR
double *CKTpred; /* predicted solution vector */
double *CKTsols[8]; /* previous 8 solutions */
#endif /* PREDICTOR */
double *CKTrhsOp; /* opearating point values */
double *CKTsenRhs; /* current sensitivity rhs values */
double *CKTseniRhs; /* current sensitivity rhs values (imag)*/
int CKTmaxEqNum; /* And this ? */
int CKTcurrentAnalysis; /* the analysis in progress (if any) */
CKTnode *CKTnodes; /* ??? */
CKTnode *CKTlastNode; /* ??? */
CKTnode *prev_CKTlastNode; /* just before model setup */
int CKTnumStates; /* Number of sates effectively valid ??? */
long CKTmode; /* Mode of operation of the circuit ??? */
int CKTbypass; /* bypass option, how does it work ? */
int CKTdcMaxIter; /* iteration limit for dc op. (itl1) */
int CKTdcTrcvMaxIter; /* iteration limit for dc tran. curv (itl2) */
int CKTtranMaxIter; /* iteration limit for each timepoint for tran*/
int CKTbreakSize; /* ??? */
int CKTbreak; /* ??? */
double CKTsaveDelta; /* ??? */
double CKTminBreak; /* ??? */
double *CKTbreaks; /* List of breakpoints ??? */
double CKTabstol; /* --- */
double CKTpivotAbsTol; /* --- */
double CKTpivotRelTol; /* --- */
double CKTreltol; /* --- */
double CKTchgtol; /* --- */
double CKTvoltTol; /* --- */
double CKTlteReltol; /* relative error in voltage based truncation error estimation */
double CKTlteAbstol; /* absolute error in voltage based truncation error estimation */
double CKTlteTrtol; /* scaling time step in voltage based truncation error estimation */
int CKTnewtrunc; /* enable lte (local truncation error) based on voltages */
double CKTgmin; /* .options GMIN */
double CKTgshunt; /* .options RSHUNT */
double CKTcshunt; /* .options CSHUNT */
double CKTdelmin; /* minimum time step for tran analysis */
double CKTtrtol; /* .options TRTOL */
double CKTfinalTime; /* TSTOP */
double CKTstep; /* TSTEP */
double CKTmaxStep; /* TMAX */
double CKTinitTime; /* TSTART */
/* struct is truncated here */
};
typedef struct CKTcircuitmin CKTcircuitmin;
/*=== FUNCTION PROTOTYPE DEFINITIONS ===*/
static void cm_delay_callback(ARGS, Mif_Callback_Reason_t reason);
@ -174,8 +95,6 @@ void cm_delay(ARGS)
mLocal_Data_t *loc; /* Pointer to local static data, not to be included
in the state vector */
CKTcircuitmin *ckt;
if (ANALYSIS != MIF_AC) { /**** only Transient Analysis and dc ****/
@ -185,11 +104,12 @@ void cm_delay(ARGS)
CALLBACK = cm_delay_callback;
ckt = (CKTcircuitmin*)cm_get_circuit();
if (PARAM_NULL(buffer_size)) {
/* size depends on TSTOP/TSTEP, if no parameter given */
buffer_size = (int) (ckt->CKTfinalTime / ckt->CKTstep) + 1;
if (TSTEP > 0) /* called from tran analysis */
buffer_size = (int) (TSTOP/TSTEP) + 1;
else /* called from op or dc analysis */
buffer_size = 1;
}
else {
buffer_size = PARAM(buffer_size);
@ -232,22 +152,22 @@ void cm_delay(ARGS)
loc->tdelmin = 0.0;
cm_message_send("Negative min delay not allowed, set to 0");
}
else if (loc->tdelmin > ckt->CKTfinalTime) {
loc->tdelmin = ckt->CKTfinalTime;
else if (loc->tdelmin > TSTOP) {
loc->tdelmin = TSTOP;
cm_message_send("min delay greater than final sim time not allowed, set to final time");
}
}
if (PARAM_NULL(delmax))
loc->tdelmax = ckt->CKTfinalTime;
loc->tdelmax = TSTOP;
else {
loc->tdelmax = PARAM(delmax);
if (loc->tdelmax < 0) {
loc->tdelmin = 0.0;
cm_message_send("Negative max delay not allowed, set to 0");
}
else if (loc->tdelmax > ckt->CKTfinalTime) {
loc->tdelmax = ckt->CKTfinalTime;
else if (loc->tdelmax > TSTOP) {
loc->tdelmax = TSTOP;
cm_message_send("max delay greater than final sim time not allowed, set to final time");
}
}
@ -261,8 +181,8 @@ void cm_delay(ARGS)
loc->buff_del = 0;
loc->step_count = 0;
loc->tdelay = delay;
loc->tstop = ckt->CKTfinalTime;
loc->tstep = ckt->CKTstep;
loc->tstop = TSTOP;
loc->tstep = TSTEP;
loc->tprev = 0.0;
loc->prev_val = 0.0;
}