Numerical Device Interface
This commit is contained in:
parent
57b40c8470
commit
e98da264e1
|
|
@ -0,0 +1,30 @@
|
|||
## Process this file with automake to produce Makefile.in
|
||||
|
||||
noinst_LIBRARIES = libndev.a
|
||||
|
||||
libndev_a_SOURCES = \
|
||||
ndev.c \
|
||||
ndevacld.c \
|
||||
ndevaccept.c \
|
||||
ndevask.c \
|
||||
ndevdefs.h \
|
||||
ndevdel.c \
|
||||
ndevdest.c \
|
||||
ndevdump.c \
|
||||
ndevext.h \
|
||||
ndevinit.c \
|
||||
ndevinit.h \
|
||||
ndevitf.h \
|
||||
ndevload.c \
|
||||
ndevmdel.c \
|
||||
ndevmpar.c \
|
||||
ndevparm.c \
|
||||
ndevpzld.c \
|
||||
ndevset.c \
|
||||
ndevtemp.c \
|
||||
ndevtrun.c
|
||||
|
||||
|
||||
INCLUDES = -I$(top_srcdir)/src/include
|
||||
|
||||
MAINTAINERCLEANFILES = Makefile.in
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/**********
|
||||
Permit to use it as your wish.
|
||||
Author: 2007 Gong Ding, gdiso@ustc.edu
|
||||
University of Science and Technology of China
|
||||
**********/
|
||||
|
||||
#include "ngspice.h"
|
||||
#include "devdefs.h"
|
||||
#include "ndevdefs.h"
|
||||
#include "suffix.h"
|
||||
|
||||
|
||||
IFparm NDEVpTable[] = { /* parameters */
|
||||
/* numerical-device models no longer have parameters */
|
||||
/* one is left behind to keep the table from being empty */
|
||||
IP("ndev", NDEV_MOD_NDEV, IF_FLAG, "Numerical Device"),
|
||||
};
|
||||
|
||||
IFparm NDEVmPTable[] = { /* model parameters */
|
||||
IP("ndev", NDEV_MOD_NDEV, IF_FLAG, "Numerical Device"),
|
||||
IP("remote", NDEV_REMOTE, IF_STRING, "Remote computer run device simulation"),
|
||||
IP("port", NDEV_PORT, IF_INTEGER, "Remote port")
|
||||
};
|
||||
|
||||
char *NDEVnames[] = {
|
||||
"pin1",
|
||||
"pin2",
|
||||
"pin3",
|
||||
"pin4",
|
||||
"pin5",
|
||||
"pin6",
|
||||
"pin7"
|
||||
};
|
||||
|
||||
int NDEVnSize = NUMELEMS(NDEVnames);
|
||||
int NDEVpTSize = NUMELEMS(NDEVpTable);
|
||||
int NDEVmPTSize = NUMELEMS(NDEVmPTable);
|
||||
int NDEViSize = sizeof(NDEVinstance);
|
||||
int NDEVmSize = sizeof(NDEVmodel);
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
/**********
|
||||
Copyright 1990 Regents of the University of California. All rights reserved.
|
||||
Author: 1987 Thomas L. Quarles
|
||||
**********/
|
||||
|
||||
#include "ngspice.h"
|
||||
#include "const.h"
|
||||
#include "ifsim.h"
|
||||
#include "cktdefs.h"
|
||||
#include "devdefs.h"
|
||||
#include "ndevdefs.h"
|
||||
#include "complex.h"
|
||||
#include "sperror.h"
|
||||
#include "suffix.h"
|
||||
|
||||
|
||||
|
||||
int NDEVaccept(CKTcircuit *ckt, GENmodel *inModel)
|
||||
{
|
||||
NDEVmodel *model = (NDEVmodel *)inModel;
|
||||
NDEVinstance *here;
|
||||
/* loop through all the ndev models */
|
||||
for( ; model != NULL; model = model->NDEVnextModel )
|
||||
{
|
||||
/* loop through all the instances of the model */
|
||||
for (here = model->NDEVinstances; here != NULL ; here=here->NDEVnextInstance)
|
||||
{
|
||||
|
||||
if (here->NDEVowner != ARCHme) continue;
|
||||
|
||||
/* set ckt accept_flag */
|
||||
here->CKTInfo.DEV_CALL = NDEV_ACCEPT;
|
||||
here->CKTInfo.CKTmode = ckt->CKTmode;
|
||||
here->CKTInfo.time = ckt->CKTtime;
|
||||
here->CKTInfo.dt = ckt->CKTdelta;
|
||||
here->CKTInfo.dt_old = ckt->CKTdeltaOld[0];
|
||||
here->CKTInfo.accept_flag = 1;
|
||||
send(model->sock,&here->CKTInfo,sizeof(sCKTinfo),0);
|
||||
}
|
||||
}
|
||||
return (OK);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
|
||||
int NDEVconvTest(GENmodel *inModel, CKTcircuit *ckt)
|
||||
{
|
||||
NDEVmodel *model = (NDEVmodel *)inModel;
|
||||
NDEVinstance *here;
|
||||
|
||||
for( ; model != NULL; model = model->NDEVnextModel) {
|
||||
for(here=model->NDEVinstances;here!=NULL;here = here->NDEVnextInstance){
|
||||
if (here->NDEVowner != ARCHme) continue;
|
||||
/*
|
||||
* get convergence information from ndev
|
||||
*/
|
||||
here->CKTInfo.DEV_CALL = NDEV_CONVERGINCE_TEST;
|
||||
send(model->sock,&here->CKTInfo,sizeof(sCKTinfo),0);
|
||||
recv(model->sock,&here->CKTInfo,sizeof(sCKTinfo),MSG_WAITALL);
|
||||
|
||||
if (here->CKTInfo.convergence_flag<0) {
|
||||
/* no reason to continue - we've failed... */
|
||||
ckt->CKTnoncon++;
|
||||
ckt->CKTtroubleElt = (GENinstance *) here;
|
||||
return(OK);
|
||||
}
|
||||
}
|
||||
}
|
||||
return(OK);
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
/**********
|
||||
Copyright 1992 Regents of the University of California. All rights reserved.
|
||||
Author: 1987 Kartikeya Mayaram, U. C. Berkeley CAD Group
|
||||
**********/
|
||||
|
||||
/*
|
||||
* Function to load the COMPLEX circuit matrix using the small signal
|
||||
* parameters saved during a previous DC operating point analysis.
|
||||
*/
|
||||
|
||||
#include "ngspice.h"
|
||||
#include "cktdefs.h"
|
||||
#include "ndevdefs.h"
|
||||
#include "sperror.h"
|
||||
#include "complex.h"
|
||||
#include "suffix.h"
|
||||
|
||||
|
||||
int
|
||||
NDEVacLoad(inModel, ckt)
|
||||
GENmodel *inModel;
|
||||
CKTcircuit *ckt;
|
||||
{
|
||||
|
||||
return (OK);
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
/**********
|
||||
Copyright 1990 Regents of the University of California. All rights reserved.
|
||||
Author: 1987 Thomas L. Quarles
|
||||
**********/
|
||||
|
||||
#include "ngspice.h"
|
||||
#include "const.h"
|
||||
#include "ifsim.h"
|
||||
#include "cktdefs.h"
|
||||
#include "devdefs.h"
|
||||
#include "ndevdefs.h"
|
||||
#include "complex.h"
|
||||
#include "sperror.h"
|
||||
#include "suffix.h"
|
||||
|
||||
|
||||
/* ARGSUSED */
|
||||
int
|
||||
NDEVask(ckt, inInst, which, value, select)
|
||||
CKTcircuit *ckt;
|
||||
GENinstance *inInst;
|
||||
int which;
|
||||
IFvalue *value;
|
||||
IFvalue *select;
|
||||
{
|
||||
return (OK);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
/**********
|
||||
Permit to use it as your wish.
|
||||
Author: 2007 Gong Ding, gdiso@ustc.edu
|
||||
University of Science and Technology of China
|
||||
**********/
|
||||
|
||||
#ifndef NDEV_H
|
||||
#define NDEV_H
|
||||
|
||||
|
||||
/* circuit level includes */
|
||||
#include "ifsim.h"
|
||||
#include "inpmacs.h"
|
||||
#include "cktdefs.h"
|
||||
#include "gendefs.h"
|
||||
#include "ndevexch.h"
|
||||
|
||||
/* network function */
|
||||
#include <errno.h>
|
||||
#include <netinet/in.h> /* IPv4 socket address structres. */
|
||||
#include <netdb.h> /* Access to DNS lookups. */
|
||||
#include <arpa/inet.h> /* inet_ntop function. */
|
||||
#include <sys/socket.h> /* Socket functions. */
|
||||
|
||||
/* information needed per instance */
|
||||
typedef struct sNDEVinstance {
|
||||
struct sNDEVmodel *NDEVmodPtr;/* back pointer to model */
|
||||
struct sNDEVinstance *NDEVnextInstance; /* pointer to next instance
|
||||
* of current model */
|
||||
IFuid NDEVname; /* pointer to character string naming this
|
||||
* instance */
|
||||
int NDEVowner; /* number of owner process */
|
||||
int NDEVstate; /* pointer to start of state vector for diode */
|
||||
int pin[7]; /* max 7 terminals are allowed */
|
||||
int term; /* the real number of terminals */
|
||||
void *node[7]; /* the array of CKT node's node pointer */
|
||||
char *bname[7]; /* the electrode boundary label for numerical solver */
|
||||
sCKTinfo CKTInfo;
|
||||
sDeviceinfo Ndevinfo;
|
||||
sPINinfo PINinfos[7];
|
||||
double * mat_pointer[49]; /* the pointer array to matrix */
|
||||
} NDEVinstance;
|
||||
|
||||
|
||||
/* per model data */
|
||||
|
||||
typedef struct sNDEVmodel { /* model structure for a diode */
|
||||
/* the following 4 entries should always exist */
|
||||
int NDEVmodType; /* type index of this device type */
|
||||
struct sNDEVmodel *NDEVnextModel; /* pointer to next possible model in linked list */
|
||||
NDEVinstance *NDEVinstances; /* pointer to list of instances that have this model */
|
||||
IFuid NDEVmodName; /* pointer to character string naming this model */
|
||||
/* here can be freely defined as your wish*/
|
||||
|
||||
char * NDEVmodelfile;
|
||||
char * host;
|
||||
int port; /* Port number. */
|
||||
int sock; /* Our connection socket. */
|
||||
|
||||
} NDEVmodel;
|
||||
|
||||
|
||||
|
||||
|
||||
/* device parameters */
|
||||
#define NDEV_MODEL_FILE 1
|
||||
/* model parameters */
|
||||
#define NDEV_MOD_NDEV 101
|
||||
#define NDEV_REMOTE 102
|
||||
#define NDEV_PORT 103
|
||||
|
||||
#include "ndevext.h"
|
||||
|
||||
|
||||
#endif /* NDEV_H */
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
/**********
|
||||
Permit to use it as your wish.
|
||||
Author: 2007 Gong Ding, gdiso@ustc.edu
|
||||
University of Science and Technology of China
|
||||
**********/
|
||||
|
||||
#include "ngspice.h"
|
||||
#include "ndevdefs.h"
|
||||
#include "sperror.h"
|
||||
#include "suffix.h"
|
||||
|
||||
int
|
||||
NDEVdelete(inModel, name, kill)
|
||||
GENmodel *inModel;
|
||||
IFuid name;
|
||||
GENinstance **kill;
|
||||
|
||||
{
|
||||
NDEVmodel *model = (NDEVmodel *)inModel;
|
||||
NDEVinstance **fast = (NDEVinstance **)kill;
|
||||
NDEVinstance **prev = NULL;
|
||||
NDEVinstance *here;
|
||||
|
||||
for( ; model ; model = model->NDEVnextModel) {
|
||||
prev = &(model->NDEVinstances);
|
||||
for(here = *prev; here ; here = *prev) {
|
||||
if(here->NDEVname == name || (fast && here==*fast) ) {
|
||||
*prev= here->NDEVnextInstance;
|
||||
FREE(here);
|
||||
return(OK);
|
||||
}
|
||||
prev = &(here->NDEVnextInstance);
|
||||
}
|
||||
}
|
||||
return(E_NODEV);
|
||||
|
||||
return (E_NODEV);
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
/**********
|
||||
Permit to use it as your wish.
|
||||
Author: 2007 Gong Ding, gdiso@ustc.edu
|
||||
University of Science and Technology of China
|
||||
**********/
|
||||
|
||||
|
||||
#include "ngspice.h"
|
||||
#include "ndevdefs.h"
|
||||
#include "suffix.h"
|
||||
|
||||
void
|
||||
NDEVdestroy(GENmodel **inModel)
|
||||
{
|
||||
|
||||
NDEVmodel **model = (NDEVmodel **)inModel;
|
||||
NDEVinstance *here;
|
||||
NDEVinstance *prev = NULL;
|
||||
NDEVmodel *mod = *model;
|
||||
NDEVmodel *oldmod = NULL;
|
||||
|
||||
for( ; mod ; mod = mod->NDEVnextModel) {
|
||||
if(oldmod) FREE(oldmod);
|
||||
oldmod = mod;
|
||||
prev = (NDEVinstance *)NULL;
|
||||
for(here = mod->NDEVinstances ; here ; here = here->NDEVnextInstance) {
|
||||
if(prev) FREE(prev);
|
||||
prev = here;
|
||||
}
|
||||
if(prev) FREE(prev);
|
||||
close(mod->sock);
|
||||
fprintf(stdout,"Disconnect to remote NDEV server %s:%d\n",mod->host,mod->port);
|
||||
}
|
||||
if(oldmod) FREE(oldmod);
|
||||
*model = NULL;
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
/**********
|
||||
Copyright 1992 Regents of the University of California. All rights reserved.
|
||||
Author: 1987 Kartikeya Mayaram, U. C. Berkeley CAD Group
|
||||
Author: 1991 David A. Gates, U. C. Berkeley CAD Group
|
||||
**********/
|
||||
|
||||
/*
|
||||
* This is a simple routine to dump the internal device states. It produces
|
||||
* states for .OP, .DC, & .TRAN simulations.
|
||||
*/
|
||||
|
||||
#include "ngspice.h"
|
||||
#include "cktdefs.h"
|
||||
#include "ndevdefs.h"
|
||||
#include "suffix.h"
|
||||
|
||||
|
||||
/* State Counter */
|
||||
static int state_numOP = 0;
|
||||
static int state_numDC = 0;
|
||||
static int state_numTR = 0;
|
||||
|
||||
void
|
||||
NDEV_dump(inModel, ckt)
|
||||
GENmodel *inModel;
|
||||
CKTcircuit *ckt;
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
NDEV_acct(inModel, ckt, file)
|
||||
GENmodel *inModel;
|
||||
CKTcircuit *ckt;
|
||||
FILE *file;
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
#ifndef _netexchange_h_
|
||||
#define _netexchange_h_
|
||||
|
||||
#define NG_QUERY "This is ngspice. Are you ready?"
|
||||
#define NDEV_REPLY "Waiting orders!"
|
||||
#define NG_STOP "Ngspice finished, goodbye."
|
||||
|
||||
#define NDEV_LOAD 0x0001
|
||||
#define NDEV_ACCEPT 0x0002
|
||||
#define NDEV_CONVERGINCE_TEST 0x0004
|
||||
#define NDEV_TRUNCATION_ERROR 0x0008
|
||||
|
||||
#define NDEV_TEMPERATURE 0x1000
|
||||
#define NDEV_AC_LOAD 0x0010
|
||||
#define NDEV_PZ_LOAD 0x0020
|
||||
|
||||
#ifndef CKT
|
||||
/* defines for CKTmode */
|
||||
/* this should be the same as cktdefs.h */
|
||||
/* old 'mode' parameters */
|
||||
#define MODE 0x3
|
||||
#define MODETRAN 0x1
|
||||
#define MODEAC 0x2
|
||||
|
||||
/* old 'modedc' parameters */
|
||||
#define MODEDC 0x70
|
||||
#define MODEDCOP 0x10
|
||||
#define MODETRANOP 0x20
|
||||
#define MODEDCTRANCURVE 0x40
|
||||
|
||||
/* old 'initf' parameters */
|
||||
#define INITF 0x3f00
|
||||
#define MODEINITFLOAT 0x100
|
||||
#define MODEINITJCT 0x200
|
||||
#define MODEINITFIX 0x400
|
||||
#define MODEINITSMSIG 0x800
|
||||
#define MODEINITTRAN 0x1000
|
||||
#define MODEINITPRED 0x2000
|
||||
|
||||
/* old 'nosolv' paramater */
|
||||
#define MODEUIC 0x10000l
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
char NDEVname[32];
|
||||
int term;
|
||||
}sDeviceinfo;
|
||||
|
||||
|
||||
typedef struct {
|
||||
int pin;
|
||||
char name[32];
|
||||
double V,I;
|
||||
double V_old;
|
||||
double dI_dV[7];
|
||||
} sPINinfo;
|
||||
|
||||
typedef struct {
|
||||
long DEV_CALL;
|
||||
long CKTmode;
|
||||
double time;
|
||||
double dt;
|
||||
double dt_old;
|
||||
double omega;
|
||||
int accept_flag;
|
||||
int convergence_flag;
|
||||
}sCKTinfo;
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
/**********
|
||||
Copyright 1990 Regents of the University of California. All rights reserved.
|
||||
Author: 1987 Karti Mayaram
|
||||
**********/
|
||||
|
||||
#ifndef NDEVEXT_H
|
||||
#define NDEVEXT_H
|
||||
|
||||
|
||||
extern int NDEVacLoad(GENmodel *, CKTcircuit *);
|
||||
extern int NDEVask(CKTcircuit *, GENinstance *, int, IFvalue *, IFvalue *);
|
||||
extern int NDEVdelete(GENmodel *, IFuid, GENinstance **);
|
||||
extern void NDEVdestroy(GENmodel **);
|
||||
extern int NDEVgetic(GENmodel *, CKTcircuit *);
|
||||
extern int NDEVload(GENmodel *, CKTcircuit *);
|
||||
extern int NDEVaccept(CKTcircuit *, GENmodel *);
|
||||
extern int NDEVconvTest(GENmodel *, CKTcircuit *);
|
||||
extern int NDEVmDelete(GENmodel **, IFuid, GENmodel *);
|
||||
extern int NDEVmParam(int, IFvalue *, GENmodel *);
|
||||
extern int NDEVparam(int, IFvalue *, GENinstance *, IFvalue *);
|
||||
extern int NDEVpzLoad(GENmodel *, CKTcircuit *, SPcomplex *);
|
||||
extern int NDEVsetup(SMPmatrix *, GENmodel *, CKTcircuit *, int *);
|
||||
extern int NDEVtemp(GENmodel *, CKTcircuit *);
|
||||
extern int NDEVtrunc(GENmodel *, CKTcircuit *, double *);
|
||||
|
||||
extern void NDEV_dump(GENmodel *, CKTcircuit *);
|
||||
extern void NDEV_acct(GENmodel *, CKTcircuit *, FILE *);
|
||||
|
||||
#endif /* NDEVEXT_H */
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
#include <config.h>
|
||||
|
||||
#include <devdefs.h>
|
||||
|
||||
#include "ndevitf.h"
|
||||
#include "ndevext.h"
|
||||
#include "ndevinit.h"
|
||||
|
||||
|
||||
SPICEdev NDEVinfo = {
|
||||
{
|
||||
"NDEV",
|
||||
"Numerical Device",
|
||||
|
||||
&NDEVnSize, /* number of terminals */
|
||||
&NDEVnSize,
|
||||
NDEVnames, /* the name of terminals*/
|
||||
|
||||
&NDEVpTSize, /*number of instance parameters */
|
||||
NDEVpTable, /*the array of instance parameters */
|
||||
|
||||
&NDEVmPTSize, /* number of model parameter, NDEV does not have this parameter */
|
||||
NDEVmPTable, /*the array of model parameters */
|
||||
|
||||
#ifdef XSPICE
|
||||
/*---- Fixed by SDB 5.2.2003 to enable XSPICE/tclspice integration -----*/
|
||||
NULL, /* This is a SPICE device, it has no MIF info data */
|
||||
|
||||
0, /* This is a SPICE device, it has no MIF info data */
|
||||
NULL, /* This is a SPICE device, it has no MIF info data */
|
||||
|
||||
0, /* This is a SPICE device, it has no MIF info data */
|
||||
NULL, /* This is a SPICE device, it has no MIF info data */
|
||||
|
||||
0, /* This is a SPICE device, it has no MIF info data */
|
||||
NULL, /* This is a SPICE device, it has no MIF info data */
|
||||
/*--------------------------- End of SDB fix -------------------------*/
|
||||
#endif
|
||||
|
||||
DEV_DEFAULT
|
||||
},
|
||||
|
||||
DEVparam : NDEVparam,
|
||||
DEVmodParam : NDEVmParam,
|
||||
DEVload : NDEVload,
|
||||
DEVsetup : NDEVsetup,
|
||||
DEVunsetup : NULL,
|
||||
DEVpzSetup : NDEVsetup,
|
||||
DEVtemperature: NDEVtemp,
|
||||
DEVtrunc : NDEVtrunc,
|
||||
DEVfindBranch : NULL,
|
||||
DEVacLoad : NDEVacLoad,
|
||||
DEVaccept : NDEVaccept,
|
||||
DEVdestroy : NDEVdestroy,
|
||||
DEVmodDelete : NDEVmDelete,
|
||||
DEVdelete : NDEVdelete,
|
||||
DEVsetic : NDEVgetic,
|
||||
DEVask : NDEVask,
|
||||
DEVmodAsk : NULL,
|
||||
DEVpzLoad : NDEVpzLoad,
|
||||
DEVconvTest : NDEVconvTest,
|
||||
DEVsenSetup : NULL,
|
||||
DEVsenLoad : NULL,
|
||||
DEVsenUpdate : NULL,
|
||||
DEVsenAcLoad : NULL,
|
||||
DEVsenPrint : NULL,
|
||||
DEVsenTrunc : NULL,
|
||||
DEVdisto : NULL,
|
||||
DEVnoise : NULL,
|
||||
#ifdef CIDER
|
||||
DEVdump : NULL,
|
||||
DEVacct : NULL,
|
||||
#endif
|
||||
|
||||
DEVinstSize : &NDEViSize,
|
||||
DEVmodSize : &NDEVmSize
|
||||
|
||||
};
|
||||
|
||||
|
||||
SPICEdev *
|
||||
get_ndev_info(void)
|
||||
{
|
||||
return &NDEVinfo;
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
#ifndef _NDEVINIT_H
|
||||
#define _NDEVINIT_H
|
||||
|
||||
extern IFparm NDEVpTable[ ];
|
||||
extern IFparm NDEVmPTable[ ];
|
||||
extern char *NDEVnames[ ];
|
||||
extern int NDEVpTSize;
|
||||
extern int NDEVmPTSize;
|
||||
extern int NDEVnSize;
|
||||
extern int NDEViSize;
|
||||
extern int NDEVmSize;
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
/**********
|
||||
Copyright 1991 Regents of the University of California. All rights reserved.
|
||||
**********/
|
||||
|
||||
#ifndef DEV_NDEV
|
||||
#define DEV_NDEV
|
||||
|
||||
extern SPICEdev *get_ndev_info(void);
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
/**********
|
||||
Permit to use it as your wish.
|
||||
Author: 2007 Gong Ding, gdiso@ustc.edu
|
||||
University of Science and Technology of China
|
||||
**********/
|
||||
|
||||
#include "ngspice.h"
|
||||
#include "devdefs.h"
|
||||
#include "cktdefs.h"
|
||||
#include "ndevdefs.h"
|
||||
#include "numenum.h"
|
||||
#include "trandefs.h"
|
||||
#include "complex.h"
|
||||
#include "sperror.h"
|
||||
#include "suffix.h"
|
||||
|
||||
|
||||
int
|
||||
NDEVload(GENmodel * inModel, CKTcircuit * ckt)
|
||||
{
|
||||
NDEVmodel *model = (NDEVmodel *)inModel;
|
||||
NDEVinstance *here;
|
||||
int i,j;
|
||||
|
||||
/* loop through all the ndev models */
|
||||
for( ; model != NULL; model = model->NDEVnextModel )
|
||||
{
|
||||
|
||||
/* loop through all the instances of the model */
|
||||
for (here = model->NDEVinstances; here != NULL ; here=here->NDEVnextInstance)
|
||||
{
|
||||
|
||||
if (here->NDEVowner != ARCHme) continue;
|
||||
|
||||
/* sent ckt information to device simulator */
|
||||
here->CKTInfo.DEV_CALL = NDEV_LOAD;
|
||||
here->CKTInfo.CKTmode = ckt->CKTmode;
|
||||
here->CKTInfo.time = ckt->CKTtime;
|
||||
here->CKTInfo.dt = ckt->CKTdelta;
|
||||
here->CKTInfo.dt_old = ckt->CKTdeltaOld[0];
|
||||
here->CKTInfo.accept_flag = 0;
|
||||
send(model->sock,&here->CKTInfo,sizeof(sCKTinfo),0);
|
||||
|
||||
/* send terminal voltage to device simulator */
|
||||
for(i=0;i<here->term;i++)
|
||||
{
|
||||
here->PINinfos[i].V_old = here->PINinfos[i].V;
|
||||
here->PINinfos[i].V = *(ckt->CKTrhsOld+here->pin[i]);
|
||||
send(model->sock,&here->PINinfos[i],sizeof(here->PINinfos[i]),0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* loop through all the ndev models */
|
||||
|
||||
for(model = (NDEVmodel *)inModel; model != NULL; model = model->NDEVnextModel )
|
||||
{
|
||||
|
||||
/* loop through all the instances of the model */
|
||||
for (here = model->NDEVinstances; here != NULL ; here=here->NDEVnextInstance)
|
||||
{
|
||||
if (here->NDEVowner != ARCHme) continue;
|
||||
/* reveive terminal current and conductional matrix from device simulator */
|
||||
for(i=0;i<here->term;i++)
|
||||
{
|
||||
recv(model->sock,&here->PINinfos[i],sizeof(here->PINinfos[i]),MSG_WAITALL);
|
||||
*(ckt->CKTrhs+here->pin[i]) += here->PINinfos[i].I;
|
||||
for(j=0;j<here->term;j++)
|
||||
*(here->mat_pointer[i*here->term+j]) += here->PINinfos[i].dI_dV[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return(OK);
|
||||
}
|
||||
|
||||
int NDEVgetic(GENmodel *inModel, CKTcircuit *ckt)
|
||||
{
|
||||
NDEVmodel *model = (NDEVmodel*)inModel;
|
||||
NDEVinstance *here;
|
||||
/*
|
||||
* grab initial conditions out of rhs array. User specified, so use
|
||||
* external nodes to get values
|
||||
*/
|
||||
|
||||
printf("set ic\n");
|
||||
|
||||
for( ; model ; model = model->NDEVnextModel) {
|
||||
for(here = model->NDEVinstances; here ; here = here->NDEVnextInstance) {
|
||||
if (here->NDEVowner != ARCHme) continue;
|
||||
/*
|
||||
if(!here->DIOinitCondGiven) {
|
||||
here->DIOinitCond =
|
||||
*(ckt->CKTrhs + here->DIOposNode) -
|
||||
*(ckt->CKTrhs + here->DIOnegNode);
|
||||
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
return(OK);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
/**********
|
||||
Copyright 1992 Regents of the University of California. All rights reserved.
|
||||
Author: 1987 Kartikeya Mayaram, U. C. Berkeley CAD Group
|
||||
**********/
|
||||
|
||||
#include "ngspice.h"
|
||||
#include "ndevdefs.h"
|
||||
#include "sperror.h"
|
||||
#include "suffix.h"
|
||||
|
||||
int
|
||||
NDEVmDelete(inModel, modname, kill)
|
||||
GENmodel **inModel;
|
||||
IFuid modname;
|
||||
GENmodel *kill;
|
||||
{
|
||||
|
||||
|
||||
return (OK);
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
/**********
|
||||
Copyright 1992 Regents of the University of California. All rights reserved.
|
||||
Author: 1987 Kartikeya Mayaram, U. C. Berkeley CAD Group
|
||||
**********/
|
||||
|
||||
/*
|
||||
* This routine sets model parameters for NDEVs in the circuit.
|
||||
*/
|
||||
|
||||
#include "ngspice.h"
|
||||
#include "const.h"
|
||||
#include "ifsim.h"
|
||||
#include "ndevdefs.h"
|
||||
#include "sperror.h"
|
||||
#include "suffix.h"
|
||||
|
||||
int
|
||||
NDEVmParam(int param, IFvalue * value, GENmodel * inModel)
|
||||
{
|
||||
|
||||
NDEVmodel *model = (NDEVmodel *) inModel;
|
||||
switch (param) {
|
||||
case NDEV_REMOTE:
|
||||
model->host = value->sValue;
|
||||
break;
|
||||
case NDEV_PORT:
|
||||
model->port = value->iValue;
|
||||
break;
|
||||
case NDEV_MOD_NDEV:
|
||||
/* no action , but this */
|
||||
/* makes life easier for spice-2 like parsers */
|
||||
break;
|
||||
default:
|
||||
return (E_BADPARM);
|
||||
}
|
||||
|
||||
return (OK);
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
/**********
|
||||
Copyright 1992 Regents of the University of California. All rights reserved.
|
||||
Author: 1987 Kartikeya Mayaram, U. C. Berkeley CAD Group
|
||||
**********/
|
||||
|
||||
#include "ngspice.h"
|
||||
#include "ifsim.h"
|
||||
#include "const.h"
|
||||
#include "ndevdefs.h"
|
||||
#include "sperror.h"
|
||||
#include "suffix.h"
|
||||
|
||||
int
|
||||
NDEVparam(param, value, inInst, select)
|
||||
int param;
|
||||
IFvalue *value;
|
||||
GENinstance *inInst;
|
||||
IFvalue *select;
|
||||
{
|
||||
NDEVinstance *inst = (NDEVinstance *) inInst;
|
||||
switch (param) {
|
||||
case NDEV_MOD_NDEV:
|
||||
/* no action , but this */
|
||||
/* makes life easier for spice-2 like parsers */
|
||||
break;
|
||||
default:
|
||||
return (E_BADPARM);
|
||||
}
|
||||
return (OK);
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
/**********
|
||||
Copyright 1992 Regents of the University of California. All rights reserved.
|
||||
Author: 1987 Kartikeya Mayaram, U. C. Berkeley CAD Group
|
||||
**********/
|
||||
|
||||
#include "ngspice.h"
|
||||
#include "cktdefs.h"
|
||||
#include "complex.h"
|
||||
#include "sperror.h"
|
||||
#include "ndevdefs.h"
|
||||
#include "suffix.h"
|
||||
|
||||
|
||||
int
|
||||
NDEVpzLoad(inModel, ckt, s)
|
||||
GENmodel *inModel;
|
||||
register CKTcircuit *ckt;
|
||||
SPcomplex *s;
|
||||
{
|
||||
|
||||
return (OK);
|
||||
}
|
||||
|
|
@ -0,0 +1,161 @@
|
|||
/**********
|
||||
Permit to use it as your wish.
|
||||
Author: 2007 Gong Ding, gdiso@ustc.edu
|
||||
University of Science and Technology of China
|
||||
**********/
|
||||
|
||||
#include "ngspice.h"
|
||||
#include "cktdefs.h"
|
||||
#include "smpdefs.h"
|
||||
#include "ndevdefs.h"
|
||||
#include "numconst.h"
|
||||
#include "numenum.h"
|
||||
#include "sperror.h"
|
||||
#include "suffix.h"
|
||||
|
||||
#define NIL(type) ((type *)0)
|
||||
#define TSCALLOC(var, size, type)\
|
||||
if (size && (!(var =(type *)calloc(1, (unsigned)(size)*sizeof(type))))) {\
|
||||
return(E_NOMEM);\
|
||||
}
|
||||
|
||||
int NDEVmodelConnect(GENmodel *inModel);
|
||||
|
||||
|
||||
int NDEVsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states)
|
||||
/*
|
||||
* load the structure with those pointers needed later for fast matrix
|
||||
* loading
|
||||
*/
|
||||
{
|
||||
NDEVmodel *model = (NDEVmodel *)inModel;
|
||||
NDEVinstance *here;
|
||||
int i,j;
|
||||
CKTnode *node;
|
||||
|
||||
/* loop through all the ndev models */
|
||||
for( ; model != NULL; model = model->NDEVnextModel ) {
|
||||
|
||||
/* connect to remote device simulator */
|
||||
if(NDEVmodelConnect(model)) return E_PRIVATE;
|
||||
|
||||
/* loop through all the instances of the model */
|
||||
for (here = model->NDEVinstances; here != NULL ;
|
||||
here=here->NDEVnextInstance) {
|
||||
|
||||
here->Ndevinfo.term = here->term;
|
||||
strncpy(here->Ndevinfo.NDEVname,here->NDEVname,32);
|
||||
send(model->sock,&(here->Ndevinfo),sizeof(here->Ndevinfo),0);
|
||||
/* macro to make elements with built in test for out of memory */
|
||||
#define TSTALLOC(ptr,first,second) \
|
||||
if((here->ptr = SMPmakeElt(matrix,here->first,here->second))==(double *)NULL){\
|
||||
return(E_NOMEM);\
|
||||
}
|
||||
|
||||
for(i=0;i<here->term;i++)
|
||||
for(j=0;j<here->term;j++)
|
||||
{
|
||||
TSTALLOC(mat_pointer[i*here->term+j], pin[i], pin[j]);
|
||||
}
|
||||
|
||||
for(i=0;i<here->term;i++)
|
||||
{
|
||||
node = (CKTnode *)here->node[i];
|
||||
here->PINinfos[i].pin=node->number;
|
||||
strncpy(here->PINinfos[i].name,here->bname[i],32);
|
||||
here->PINinfos[i].V = 0.0;
|
||||
send(model->sock,&here->PINinfos[i],sizeof(here->PINinfos[i]),0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return(OK);
|
||||
|
||||
}
|
||||
|
||||
int NDEVmodelConnect(GENmodel *inModel)
|
||||
{
|
||||
NDEVmodel *model = (NDEVmodel *)inModel;
|
||||
struct hostent *hostlist; /* List of hosts returned by gethostbyname. */
|
||||
char dotted_ip[15]; /* Buffer for converting
|
||||
the resolved address to
|
||||
a readable format. */
|
||||
struct sockaddr_in sa; /* Connection address. */
|
||||
void * buf = malloc(128);
|
||||
|
||||
/* Look up the hostname with DNS. gethostbyname
|
||||
(at least most UNIX versions of it) properly
|
||||
handles dotted IP addresses as well as hostnames. */
|
||||
hostlist = gethostbyname(model->host);
|
||||
if (hostlist == NULL)
|
||||
{
|
||||
fprintf(stderr,"NDEV: Unable to resolve host %s.\n", model->host);
|
||||
return E_PRIVATE;
|
||||
}
|
||||
/* Good, we have an address. However, some sites
|
||||
are moving over to IPv6 (the newer version of
|
||||
IP), and we're not ready for it (since it uses
|
||||
a new address format). It's a good idea to check
|
||||
for this. */
|
||||
if (hostlist->h_addrtype != AF_INET)
|
||||
{
|
||||
fprintf(stderr,"NDEV: Host %s doesn't seem to be an IPv4 address.\n",model->host);
|
||||
return E_PRIVATE;
|
||||
}
|
||||
|
||||
/* inet_ntop converts a 32-bit IP address to
|
||||
the dotted string notation (suitable for printing).
|
||||
hostlist->h_addr_list is an array of possible addresses
|
||||
(in case a name resolves to more than on IP). In most
|
||||
cases we just want the first. */
|
||||
inet_ntop(AF_INET, hostlist->h_addr_list[0], dotted_ip, 15);
|
||||
/* Create a socket for the connection. */
|
||||
model->sock = socket(PF_INET, SOCK_STREAM, IPPROTO_IP);
|
||||
|
||||
if (model->sock < 0)
|
||||
{
|
||||
fprintf(stderr, "NDEV: Unable to create a socket %s.\n", strerror(errno));
|
||||
return E_PRIVATE;
|
||||
}
|
||||
/* Fill in the sockaddr_in structure. The address is
|
||||
already in network byte order (from the gethostbyname
|
||||
call). We need to convert the port number with the htons
|
||||
macro. Before we do anything else, we'll zero out the
|
||||
entire structure. */
|
||||
|
||||
memset(&sa, 0, sizeof(struct sockaddr_in));
|
||||
sa.sin_port = htons(model->port);
|
||||
/* The IP address was returned as a char * for
|
||||
various reasons.
|
||||
Just memcpy it into the sockaddr_in structure. */
|
||||
memcpy(&sa.sin_addr, hostlist->h_addr_list[0],
|
||||
hostlist->h_length);
|
||||
/* This is an Internet socket. */
|
||||
sa.sin_family = AF_INET;
|
||||
/* Connect! */
|
||||
if (connect(model->sock, (struct sockaddr *)&sa, sizeof(sa)) < 0)
|
||||
{
|
||||
fprintf(stderr, "NDEV: Unable to connect %s\n",strerror(errno));
|
||||
return E_PRIVATE;
|
||||
}
|
||||
|
||||
sprintf((char *)buf,NG_QUERY);
|
||||
send(model->sock,buf,128,0);
|
||||
if(recv(model->sock,buf,128,MSG_WAITALL)<128)
|
||||
{
|
||||
fprintf(stderr, "NDEV: Remote answer error. %s\n",strerror(errno));
|
||||
return E_PRIVATE;
|
||||
}
|
||||
|
||||
if(strncmp((char *)buf,NDEV_REPLY,sizeof(NDEV_REPLY)))
|
||||
{
|
||||
fprintf(stderr, "NDEV: Remote answer error. %s\n",(char *)buf);
|
||||
return E_PRIVATE;
|
||||
}
|
||||
|
||||
|
||||
free(buf);
|
||||
return (OK);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
/**********
|
||||
Copyright 1992 Regents of the University of California. All rights reserved.
|
||||
Author: 1987 Kartikeya Mayaram, U. C. Berkeley CAD Group
|
||||
Author: 1992 David A. Gates, U. C. Berkeley CAD Group
|
||||
**********/
|
||||
|
||||
#include "ngspice.h"
|
||||
#include "cktdefs.h"
|
||||
#include "ndevdefs.h"
|
||||
#include "numenum.h"
|
||||
#include "carddefs.h"
|
||||
#include "sperror.h"
|
||||
#include "suffix.h"
|
||||
|
||||
#define NIL(type) ((type *)0)
|
||||
|
||||
int
|
||||
NDEVtemp(inModel, ckt)
|
||||
GENmodel *inModel;
|
||||
register CKTcircuit *ckt;
|
||||
/*
|
||||
* perform the temperature update to the diode
|
||||
*/
|
||||
{
|
||||
|
||||
return (OK);
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
/**********
|
||||
Copyright 1992 Regents of the University of California. All rights reserved.
|
||||
Author: 1987 Kartikeya Mayaram, U. C. Berkeley CAD Group
|
||||
**********/
|
||||
|
||||
#include "ngspice.h"
|
||||
#include "cktdefs.h"
|
||||
#include "ndevdefs.h"
|
||||
#include "sperror.h"
|
||||
#include "suffix.h"
|
||||
|
||||
|
||||
|
||||
int
|
||||
NDEVtrunc(inModel, ckt, timeStep)
|
||||
GENmodel *inModel;
|
||||
register CKTcircuit *ckt;
|
||||
double *timeStep;
|
||||
|
||||
{
|
||||
|
||||
return (OK);
|
||||
}
|
||||
Loading…
Reference in New Issue