Jspice3
niinteg.c File Reference
#include "spice.h"
#include <stdio.h>
#include "cktdefs.h"
#include "sperror.h"
#include "util.h"
#include "niext.h"
Include dependency graph for niinteg.c:

Go to the source code of this file.

Macros

#define ccap   qcap+1
 

Functions

int NIintegrate (CKTcircuit *ckt, double *geq, double *ceq, double cap, int qcap)
 
int NIsum (CKTcircuit *ckt, double *ceq, int qcap)
 

Macro Definition Documentation

#define ccap   qcap+1

Definition at line 20 of file niinteg.c.

Function Documentation

int NIintegrate ( CKTcircuit ckt,
double *  geq,
double *  ceq,
double  cap,
int  qcap 
)

Definition at line 23 of file niinteg.c.

30 {
31  int error;
32 
33  error = NIsum(ckt,ceq,qcap);
34  if (error != OK)
35  return (error);
36 
37  *(ckt->CKTstate0 + ccap) =
38  ckt->CKTag[0] * *(ckt->CKTstate0 + qcap) + *ceq;
39 
40  *geq = ckt->CKTag[0] * cap;
41  return(OK);
42 }
#define OK
Definition: iferrmsg.h:17
int NIsum(CKTcircuit *ckt, double *ceq, int qcap)
Definition: niinteg.c:46
double CKTag[7]
Definition: cktdefs.h:83
#define ccap
Definition: niinteg.c:20
int NIsum ( CKTcircuit ckt,
double *  ceq,
int  qcap 
)

Definition at line 46 of file niinteg.c.

57 {
58  static char *ordmsg = "Illegal integration order";
59  static char *methodmsg = "Unknown integration method";
60  double cq = 0;
61 
62  switch (ckt->CKTintegrateMethod) {
63 
64  case TRAPEZOIDAL:
65  switch (ckt->CKTorder) {
66  case 1:
67  cq = ckt->CKTag[1] * (*(ckt->CKTstate1+qcap));
68  break;
69  case 2:
70  cq = - *(ckt->CKTstate1+ccap) * ckt->CKTag[1] -
71  ckt->CKTag[0] * *(ckt->CKTstate1+qcap);
72  break;
73  default:
74  errMsg = MALLOC(strlen(ordmsg)+1);
75  strcpy(errMsg,ordmsg);
76  return (E_ORDER);
77  }
78  break;
79 
80  case GEAR:
81  switch (ckt->CKTorder) {
82 
83  case 6:
84  cq += ckt->CKTag[6]* *(ckt->CKTstate6+qcap);
85  /* fall through */
86  case 5:
87  cq += ckt->CKTag[5]* *(ckt->CKTstate5+qcap);
88  /* fall through */
89  case 4:
90  cq += ckt->CKTag[4]* *(ckt->CKTstate4+qcap);
91  /* fall through */
92  case 3:
93  cq += ckt->CKTag[3]* *(ckt->CKTstate3+qcap);
94  /* fall through */
95  case 2:
96  cq += ckt->CKTag[2]* *(ckt->CKTstate2+qcap);
97  /* fall through */
98  case 1:
99  cq += ckt->CKTag[1]* *(ckt->CKTstate1+qcap);
100  break;
101 
102  default:
103  errMsg = MALLOC(strlen(ordmsg)+1);
104  strcpy(errMsg,ordmsg);
105  return (E_ORDER);
106 
107  }
108  break;
109 
110  default:
111  errMsg = MALLOC(strlen(methodmsg)+1);
112  strcpy(errMsg,methodmsg);
113  return (E_METHOD);
114  }
115  *ceq = cq;
116 
117  return (OK);
118 }
#define E_ORDER
Definition: sperror.h:19
char * strcpy()
#define TRAPEZOIDAL
Definition: cktdefs.h:92
char * errMsg
Definition: main.c:42
int CKTorder
Definition: cktdefs.h:87
#define OK
Definition: iferrmsg.h:17
#define GEAR
Definition: cktdefs.h:93
#define MALLOC(x)
Definition: util.h:9
double CKTag[7]
Definition: cktdefs.h:83
#define ccap
Definition: niinteg.c:20
#define E_METHOD
Definition: sperror.h:20
int CKTintegrateMethod
Definition: cktdefs.h:89