Browse Source

GENmodel, GENinstance, change layout, #4/4, complete the change

currently each and every device specific instance and model structure
  duplicates the memory layout of a struct GENmodel / GENinstance

further the first structure elements behind a GENinstance header
  are reinterpreted as a sort of a generic "node" array.

This business is very error prone, and makes it difficult to
  extend struct GENmodel / struct GENinstance.

This patch makes this business much more bearable.
pre-master-46
rlar 8 years ago
parent
commit
8c7d7051ae
  1. 13
      src/include/ngspice/gendefs.h
  2. 1
      src/include/ngspice/mifdefs.h
  3. 5
      src/include/ngspice/numgen.h
  4. 2
      src/spicelib/analysis/ckti2nod.c
  5. 8
      src/spicelib/analysis/tfanal.c
  6. 21
      src/spicelib/devices/adms/admst/ngspiceMODULEdefs.h.xml
  7. 2
      src/spicelib/devices/cktbindnode.c
  8. 1
      src/spicelib/devices/ndev/ndevdefs.h
  9. 2
      src/spicelib/devices/ndev/ndevset.c
  10. 2
      src/spicelib/devices/urc/urcsetup.c
  11. 2
      src/spicelib/parser/inp2m.c

13
src/include/ngspice/gendefs.h

@ -21,10 +21,19 @@ struct GENinstance {
* current model*/ * current model*/
IFuid GENname; /* pointer to character string naming this instance */ IFuid GENname; /* pointer to character string naming this instance */
int GENstate; /* state index number */ int GENstate; /* state index number */
int GENnode[7]; /* node numbers to which this instance is connected to */
/* carefull, thats overlayed into the actual device structs */
/* The actual device instance structs have to place their node elements
* right after the the end of struct GENinstance
* where they will be accessed by generic GENnode()[]
* A notable exception is the XSPICE MIF device
*/
}; };
static inline int *
GENnode(struct GENinstance *inst) {
return (int*)(inst + 1);
}
/* per model data */ /* per model data */

1
src/include/ngspice/mifdefs.h

@ -44,6 +44,7 @@ NON-STANDARD FEATURES
#include "ngspice/mifcmdat.h" #include "ngspice/mifcmdat.h"
#include "ngspice/gendefs.h"
#include "ngspice/ifsim.h" #include "ngspice/ifsim.h"

5
src/include/ngspice/numgen.h

@ -22,11 +22,6 @@ typedef struct sGENnumModel { /* model structure for a numerical device */
struct GENmodel gen; struct GENmodel gen;
#define GENmodType gen.GENmodType
#define GENnextModel(inst) ((struct sGENnumModel *)((inst)->gen.GENnextModel))
#define GENinstances(inst) ((GENinstance *)((inst)->gen.GENinstances))
#define GENmodName gen.GENmodName
MESHcard *GENxMeshes; /* list of xmesh cards */ MESHcard *GENxMeshes; /* list of xmesh cards */
MESHcard *GENyMeshes; /* list of ymesh cards */ MESHcard *GENyMeshes; /* list of ymesh cards */
DOMNcard *GENdomains; /* list of domain cards */ DOMNcard *GENdomains; /* list of domain cards */

2
src/spicelib/analysis/ckti2nod.c

@ -26,7 +26,7 @@ CKTinst2Node(CKTcircuit *ckt, void *instPtr, int terminal, CKTnode **node, IFuid
if (*(DEVices[type]->DEVpublic.terms) >= terminal && terminal > 0) { if (*(DEVices[type]->DEVpublic.terms) >= terminal && terminal > 0) {
/* argh, terminals are counted from 1 */ /* argh, terminals are counted from 1 */
int nodenum = inst->GENnode[terminal - 1];
int nodenum = GENnode(inst)[terminal - 1];
for (here = ckt->CKTnodes; here; here = here->next) for (here = ckt->CKTnodes; here; here = here->next)
if (here->number == nodenum) { if (here->number == nodenum) {

8
src/spicelib/analysis/tfanal.c

@ -76,8 +76,8 @@ TFanal(CKTcircuit *ckt, int restart)
} }
if (job->TFinIsI) { if (job->TFinIsI) {
ckt->CKTrhs[ptr->GENnode[0]] -= 1;
ckt->CKTrhs[ptr->GENnode[1]] += 1;
ckt->CKTrhs[GENnode(ptr)[0]] -= 1;
ckt->CKTrhs[GENnode(ptr)[1]] += 1;
} else { } else {
insrc = CKTfndBranch(ckt, job->TFinSrc); insrc = CKTfndBranch(ckt, job->TFinSrc);
ckt->CKTrhs[insrc] += 1; ckt->CKTrhs[insrc] += 1;
@ -119,8 +119,8 @@ TFanal(CKTcircuit *ckt, int restart)
/* now for input resistance */ /* now for input resistance */
if (job->TFinIsI) { if (job->TFinIsI) {
outputs[1] = ckt->CKTrhs[ptr->GENnode[1]] -
ckt->CKTrhs[ptr->GENnode[0]];
outputs[1] = ckt->CKTrhs[GENnode(ptr)[1]] -
ckt->CKTrhs[GENnode(ptr)[0]];
} else { } else {
if(fabs(ckt->CKTrhs[insrc])<1e-20) { if(fabs(ckt->CKTrhs[insrc])<1e-20) {
outputs[1]=1e20; outputs[1]=1e20;

21
src/spicelib/devices/adms/admst/ngspiceMODULEdefs.h.xml

@ -188,10 +188,13 @@ if(isinf((double) var)) \\
/* information needed for each instance */ /* information needed for each instance */
typedef struct s$(module)instance { typedef struct s$(module)instance {
struct s$(module)model *$(module)modPtr; /* pointer to model */
struct s$(module)instance *$(module)nextInstance; /* pointer to next instance of current model*/
IFuid $(module)name; /* pointer to character string naming this instance */
int $(module)state; /* index into state table for this device */
struct GENinstance gen;
#define $(module)modPtr(inst) (($(module)model *)((inst)-&gt;gen.GENmodPtr))
#define $(module)nextInstance(inst) (($(module)instance *)((inst)-&gt;gen.GENnextInstance))
#define $(module)name gen.GENname
#define $(module)states gen.GENstate
/* node */ /* node */
<admst:for-each select="node[grounded='no']"> <admst:for-each select="node[grounded='no']">
@ -265,12 +268,12 @@ typedef struct s$(module)instance {
/* per model data */ /* per model data */
typedef struct s$(module)model { /* model structure */ typedef struct s$(module)model { /* model structure */
int $(module)modType; /* type index of this device type */
struct s$(module)model *$(module)nextModel; /* pointer to next possible model in linked list */
$(module)instance * $(module)instances; /* pointer to list of instances that have this model */
IFuid $(module)modName; /* pointer to the name of this model */
struct GENmodel gen;
/* --- end of generic struct GENmodel --- */
#define $(module)modType gen.GENmodType
#define $(module)nextModel(inst) (($(module)model*)((inst)->gen.GENnextModel))
#define $(module)instances(inst) (($(module)instance*)((inst)->gen.GENinstances))
#define $(module)modName gen.GENmodName
/* model parameters */ /* model parameters */
<admst:for-each select="variable[parametertype='model' and input='yes']"> <admst:for-each select="variable[parametertype='model' and input='yes']">

2
src/spicelib/devices/cktbindnode.c

@ -26,7 +26,7 @@ CKTbindNode(CKTcircuit *ckt, GENinstance *instance, int term, CKTnode *node)
if (*(devs[type]->DEVpublic.terms) >= term && term > 0) { if (*(devs[type]->DEVpublic.terms) >= term && term > 0) {
/* argh, terminals are counted from 1 */ /* argh, terminals are counted from 1 */
instance->GENnode[term - 1] = node->number;
GENnode(instance)[term - 1] = node->number;
return OK; return OK;
} else { } else {
return E_NOTERM; return E_NOTERM;

1
src/spicelib/devices/ndev/ndevdefs.h

@ -29,7 +29,6 @@ typedef struct sNDEVinstance {
#define NDEVmodPtr(inst) ((struct sNDEVmodel *)((inst)->gen.GENmodPtr)) #define NDEVmodPtr(inst) ((struct sNDEVmodel *)((inst)->gen.GENmodPtr))
#define NDEVnextInstance(inst) ((struct sNDEVinstance *)((inst)->gen.GENnextInstance)) #define NDEVnextInstance(inst) ((struct sNDEVinstance *)((inst)->gen.GENnextInstance))
#define NDEVname gen.GENname
#define NDEVstate gen.GENstate #define NDEVstate gen.GENstate
const int pin[7]; /* max 7 terminals are allowed */ const int pin[7]; /* max 7 terminals are allowed */

2
src/spicelib/devices/ndev/ndevset.c

@ -46,7 +46,7 @@ int NDEVsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states
here=NDEVnextInstance(here)) { here=NDEVnextInstance(here)) {
here->Ndevinfo.term = here->term; here->Ndevinfo.term = here->term;
strncpy(here->Ndevinfo.NDEVname,here->NDEVname,32);
strncpy(here->Ndevinfo.NDEVname, here->gen.GENname, 32);
send(model->sock,&(here->Ndevinfo),sizeof(here->Ndevinfo),0); send(model->sock,&(here->Ndevinfo),sizeof(here->Ndevinfo),0);
/* macro to make elements with built in test for out of memory */ /* macro to make elements with built in test for out of memory */
#define TSTALLOC(ptr,first,second) \ #define TSTALLOC(ptr,first,second) \

2
src/spicelib/devices/urc/urcsetup.c

@ -302,7 +302,7 @@ URCunsetup(GENmodel *inModel, CKTcircuit *ckt)
return E_NOMOD; return E_NOMOD;
for (in = modfast->GENinstances; in; in = in->GENnextInstance) for (in = modfast->GENinstances; in; in = in->GENnextInstance)
CKTdltNNum(ckt, in->GENnode[0]);
CKTdltNNum(ckt, GENnode(in)[0]);
CKTdltMod(ckt, modfast); /* Does the elements too */ CKTdltMod(ckt, modfast); /* Does the elements too */

2
src/spicelib/parser/inp2m.c

@ -142,7 +142,7 @@ INP2M(CKTcircuit *ckt, INPtables *tab, card *current)
if (i < numnodes) if (i < numnodes)
IFC (bindNode, (ckt, fast, i + 1, node[i])); IFC (bindNode, (ckt, fast, i + 1, node[i]));
else else
fast->GENnode[i] = -1;
GENnode(fast)[i] = -1;
PARSECALL ((&line, ckt, type, fast, &leadval, &waslead, tab)); PARSECALL ((&line, ckt, type, fast, &leadval, &waslead, tab));
if (waslead) if (waslead)

Loading…
Cancel
Save