cccs, vccs, isrc, untested ...

This commit is contained in:
rlar 2015-04-25 11:18:20 +02:00
parent 6e2673d243
commit 55e7774128
24 changed files with 303 additions and 19 deletions

View File

@ -13,6 +13,7 @@ libcccs_la_SOURCES = \
cccsinit.h \
cccsitf.h \
cccsload.c \
cccsfindbr.c \
cccsmdel.c \
cccspar.c \
cccspzld.c \

View File

@ -25,6 +25,8 @@ typedef struct sCCCSinstance {
int CCCSposNode; /* number of positive node of source */
int CCCSnegNode; /* number of negative node of source */
int CCCScontBranch; /* number of branch eq of controlling source */
int CCCSposPrimeNode; /* number of node between resistor and vprobe */
int CCCSbranch; /* number of vprobe branch current node */
char *CCCScontName; /* pointer to name of controlling instance */
@ -36,6 +38,9 @@ typedef struct sCCCSinstance {
*(positive node, control branch eq)*/
double *CCCSnegContBrptr; /* pointer to sparse matrix element at
*(negative node, control branch eq)*/
double *CCCS_pos_ibr;
double *CCCS_posPrime_ibr;
unsigned CCCScoeffGiven :1 ; /* flag to indicate coeff given */
unsigned CCCSmGiven :1 ; /* flag to indicate multiplier given */

View File

@ -16,4 +16,6 @@ extern int CCCSsLoad(GENmodel*,CKTcircuit*);
extern void CCCSsPrint(GENmodel*,CKTcircuit*);
extern int CCCSsSetup(SENstruct*,GENmodel*);
extern int CCCSsetup(SMPmatrix*,GENmodel*,CKTcircuit*,int*);
extern int CCCSunsetup(GENmodel*,CKTcircuit*);
extern int CCCSfindBr(CKTcircuit*, GENmodel*, IFuid);

View File

@ -0,0 +1,36 @@
/***********************************
* Author: Marcel Hendrix, Feb 2015 *
***********************************/
#include "ngspice/ngspice.h"
#include "ngspice/cktdefs.h"
#include "cccsdefs.h"
#include "ngspice/sperror.h"
#include "ngspice/suffix.h"
int
CCCSfindBr (CKTcircuit *ckt, GENmodel *inModel, IFuid name)
{
CCCSmodel *model = (CCCSmodel *) inModel;
CCCSinstance *here;
for (; model; model = model->CCCSnextModel)
for (here = model->CCCSinstances; here; here = here->CCCSnextInstance)
if (here->CCCSname == name) {
if (!here->CCCSbranch) {
CKTnode *tmp;
int error;
error = CKTmkCur(ckt, &tmp, here->CCCSname, "branch");
if (error)
return error;
here->CCCSbranch = tmp->number;
}
return here->CCCSbranch;
}
return 0;
}

View File

@ -43,11 +43,11 @@ SPICEdev CCCSinfo = {
/* DEVmodParam */ NULL,
/* DEVload */ CCCSload,
/* DEVsetup */ CCCSsetup,
/* DEVunsetup */ NULL,
/* DEVunsetup */ CCCSunsetup,
/* DEVpzSetup */ CCCSsetup,
/* DEVtemperature*/ NULL,
/* DEVtrunc */ NULL,
/* DEVfindBranch */ NULL,
/* DEVfindBranch */ CCCSfindBr,
/* DEVacLoad */ CCCSload,
/* DEVaccept */ NULL,
/* DEVdestroy */ CCCSdestroy,

View File

@ -34,6 +34,12 @@ CCCSload(GENmodel *inModel, CKTcircuit *ckt)
*(here->CCCSposContBrptr) += here->CCCScoeff ;
*(here->CCCSnegContBrptr) -= here->CCCScoeff ;
if (here->CCCSbranch) {
*(here->CCCS_pos_ibr) += 1.0;
*(here->CCCS_posPrime_ibr) -= 1.0;
}
}
}
return(OK);

View File

@ -36,6 +36,11 @@ CCCSpzLoad(GENmodel *inModel, CKTcircuit *ckt, SPcomplex *s)
*(here->CCCSposContBrptr) += here->CCCScoeff ;
*(here->CCCSnegContBrptr) -= here->CCCScoeff ;
if (here->CCCSbranch) {
*(here->CCCS_pos_ibr) += 1.0;
*(here->CCCS_posPrime_ibr) -= 1.0;
}
}
}
return(OK);

View File

@ -46,9 +46,35 @@ do { if((here->ptr = SMPmakeElt(matrix, here->first, here->second)) == NULL){\
return(E_NOMEM);\
} } while(0)
TSTALLOC(CCCSposContBrptr,CCCSposNode,CCCScontBranch);
TSTALLOC(CCCSnegContBrptr,CCCSnegNode,CCCScontBranch);
if (here->CCCSbranch == 0) {
here->CCCSposPrimeNode = here->CCCSposNode;
} else {
here->CCCSposPrimeNode = here->CCCSbranch;
TSTALLOC(CCCS_pos_ibr, CCCSposNode, CCCSbranch);
TSTALLOC(CCCS_posPrime_ibr, CCCSposPrimeNode, CCCSbranch);
}
TSTALLOC(CCCSposContBrptr, CCCSposPrimeNode, CCCScontBranch);
TSTALLOC(CCCSnegContBrptr, CCCSnegNode, CCCScontBranch);
}
}
return(OK);
}
int
CCCSunsetup(GENmodel *inModel, CKTcircuit *ckt)
{
CCCSmodel *model = (CCCSmodel *) inModel;
CCCSinstance *here;
for (; model; model = model->CCCSnextModel)
for (here = model->CCCSinstances; here; here = here->CCCSnextInstance)
if (here->CCCSbranch) {
CKTdltNNum(ckt, here->CCCSbranch);
here->CCCSbranch = 0;
here->CCCSposPrimeNode = 0;
}
return OK;
}

View File

@ -141,7 +141,7 @@ int add_udn(int,Evt_Udn_Info_t **);
static SPICEdev *(*static_devices[])(void) = {
/* URC device MUST precede both resistors and capacitors */
get_urc_info,
get_asrc_info, /* asrc must precede res, cap, ind and dio */
get_asrc_info, /* asrc must precede res, cap, ind, dio, cccs, vccs, isrc */
get_bjt_info,
get_bsim1_info,
get_bsim2_info,

View File

@ -11,12 +11,14 @@ libisrc_la_SOURCES = \
isrcdel.c \
isrcdest.c \
isrcext.h \
isrcfindbr.c \
isrcinit.c \
isrcinit.h \
isrcitf.h \
isrcload.c \
isrcmdel.c \
isrcpar.c \
isrcsetup.c \
isrctemp.c

View File

@ -28,6 +28,12 @@ typedef struct sISRCinstance {
int ISRCnegNode; /* number of negative node of source */
int ISRCposNode; /* number of positive node of source */
int ISRCposPrimeNode; /* number of node between resistor and vprobe */
int ISRCbranch; /* number of vprobe branch current node */
double *ISRC_pos_ibr;
double *ISRC_posPrime_ibr;
int ISRCfunctionType; /* code number of function type for source */
int ISRCfunctionOrder; /* order of the function for the source */
double *ISRCcoeffs; /* pointer to array of coefficients */

View File

@ -8,8 +8,11 @@ extern int ISRCacLoad(GENmodel*,CKTcircuit*);
extern int ISRCask(CKTcircuit*,GENinstance*,int,IFvalue*,IFvalue*);
extern int ISRCdelete(GENmodel*,IFuid,GENinstance**);
extern void ISRCdestroy(GENmodel**);
extern int ISRCfindBr(CKTcircuit*, GENmodel*, IFuid);
extern int ISRCload(GENmodel*,CKTcircuit*);
extern int ISRCmDelete(GENmodel**,IFuid,GENmodel*);
extern int ISRCparam(int,IFvalue*,GENinstance*,IFvalue*);
extern int ISRCpzLoad(GENmodel*,CKTcircuit*,SPcomplex*);
extern int ISRCsetup(SMPmatrix*,GENmodel*,CKTcircuit*,int*);
extern int ISRCtemp(GENmodel*,CKTcircuit*);
extern int ISRCunsetup(GENmodel*,CKTcircuit*);

View File

@ -0,0 +1,36 @@
/***********************************
* Author: Marcel Hendrix, Feb 2015 *
***********************************/
#include "ngspice/ngspice.h"
#include "ngspice/cktdefs.h"
#include "isrcdefs.h"
#include "ngspice/sperror.h"
#include "ngspice/suffix.h"
int
ISRCfindBr (CKTcircuit *ckt, GENmodel *inModel, IFuid name)
{
ISRCmodel *model = (ISRCmodel *) inModel;
ISRCinstance *here;
for (; model; model = model->ISRCnextModel)
for (here = model->ISRCinstances; here; here = here->ISRCnextInstance)
if (here->ISRCname == name) {
if (here->ISRCbranch == 0) {
CKTnode *tmp;
int error;
error = CKTmkCur(ckt, &tmp, here->ISRCname, "branch");
if (error)
return error;
here->ISRCbranch = tmp->number;
}
return here->ISRCbranch;
}
return 0;
}

View File

@ -43,12 +43,12 @@ SPICEdev ISRCinfo = {
/* DEVparam */ ISRCparam,
/* DEVmodParam */ NULL,
/* DEVload */ ISRCload,
/* DEVsetup */ NULL,
/* DEVunsetup */ NULL,
/* DEVsetup */ ISRCsetup,
/* DEVunsetup */ ISRCunsetup,
/* DEVpzSetup */ NULL,
/* DEVtemperature*/ ISRCtemp,
/* DEVtrunc */ NULL,
/* DEVfindBranch */ NULL,
/* DEVfindBranch */ ISRCfindBr,
/* DEVacLoad */ ISRCacLoad,
/* DEVaccept */ ISRCaccept,
/* DEVdestroy */ ISRCdestroy,

View File

@ -396,9 +396,14 @@ loadDone:
#endif
/* gtri - end - wbk - modify for supply ramping option */
*(ckt->CKTrhs + (here->ISRCposNode)) += m * value;
*(ckt->CKTrhs + (here->ISRCposPrimeNode)) += m * value;
*(ckt->CKTrhs + (here->ISRCnegNode)) -= m * value;
if (here->ISRCbranch) {
*(here->ISRC_pos_ibr) += 1.0;
*(here->ISRC_posPrime_ibr) -= 1.0;
}
/* gtri - end - wbk - modify to process srcFact, etc. for all sources */
#ifdef XSPICE

View File

@ -0,0 +1,71 @@
/**********
Copyright 1990 Regents of the University of California. All rights reserved.
Author: 1985 Thomas L. Quarles
**********/
/*
*/
/* load the current source structure with those pointers needed later
* for fast matrix loading
*/
#include "ngspice/ngspice.h"
#include "ngspice/smpdefs.h"
#include "ngspice/cktdefs.h"
#include "isrcdefs.h"
#include "ngspice/sperror.h"
#include "ngspice/suffix.h"
/*ARGSUSED*/
int
ISRCsetup(SMPmatrix *matrix, GENmodel *inModel, CKTcircuit *ckt, int *states)
{
ISRCmodel *model = (ISRCmodel *)inModel;
ISRCinstance *here;
NG_IGNORE(states);
NG_IGNORE(ckt);
/* loop through all the current source models */
for( ; model != NULL; model = model->ISRCnextModel ) {
/* loop through all the instances of the model */
for (here = model->ISRCinstances; here != NULL ;
here=here->ISRCnextInstance) {
/* macro to make elements with built in test for out of memory */
#define TSTALLOC(ptr,first,second) \
do { if((here->ptr = SMPmakeElt(matrix, here->first, here->second)) == NULL){\
return(E_NOMEM);\
} } while(0)
if (here->ISRCbranch == 0) {
here->ISRCposPrimeNode = here->ISRCposNode;
} else {
here->ISRCposPrimeNode = here->ISRCbranch;
TSTALLOC(ISRC_pos_ibr, ISRCposNode, ISRCbranch);
TSTALLOC(ISRC_posPrime_ibr, ISRCposPrimeNode, ISRCbranch);
}
}
}
return(OK);
}
int
ISRCunsetup(GENmodel *inModel, CKTcircuit *ckt)
{
ISRCmodel *model = (ISRCmodel *) inModel;
ISRCinstance *here;
for (; model; model = model->ISRCnextModel)
for (here = model->ISRCinstances; here; here = here->ISRCnextInstance)
if (here->ISRCbranch) {
CKTdltNNum(ckt, here->ISRCbranch);
here->ISRCbranch = 0;
here->ISRCposPrimeNode = 0;
}
return OK;
}

View File

@ -13,6 +13,7 @@ libvccs_la_SOURCES = \
vccsinit.h \
vccsitf.h \
vccsload.c \
vccsfindbr.c \
vccsmdel.c \
vccspar.c \
vccspzld.c \

View File

@ -28,19 +28,24 @@ typedef struct sVCCSinstance {
int VCCSnegNode; /* number of negative node of source */
int VCCScontPosNode; /* number of positive node of controlling source */
int VCCScontNegNode; /* number of negative node of controlling source */
int VCCSposPrimeNode; /* number of node between resistor and vprobe */
int VCCSbranch; /* number of vprobe branch current node */
double VCCSinitCond; /* initial condition (of controlling source) */
double VCCScoeff; /* coefficient */
double VCCSmValue; /* Parallel multiplier */
double *VCCSposContPosptr; /* pointer to sparse matrix element at
double *VCCSposPrimeContPosptr; /* pointer to sparse matrix element at
* (positive node, control positive node) */
double *VCCSposContNegptr; /* pointer to sparse matrix element at
double *VCCSposPrimeContNegptr; /* pointer to sparse matrix element at
* (negative node, control negative node) */
double *VCCSnegContPosptr; /* pointer to sparse matrix element at
* (positive node, control positive node) */
double *VCCSnegContNegptr; /* pointer to sparse matrix element at
* (negative node, control negative node) */
double *VCCS_pos_ibr;
double *VCCS_posPrime_ibr;
unsigned VCCScoeffGiven :1 ;/* flag to indicate function coeffs given */
unsigned VCCSmGiven :1 ;/* flag to indicate multiplier given */

View File

@ -15,3 +15,5 @@ extern int VCCSsLoad(GENmodel*,CKTcircuit*);
extern int VCCSsSetup(SENstruct*,GENmodel*);
extern void VCCSsPrint(GENmodel*,CKTcircuit*);
extern int VCCSsetup(SMPmatrix*,GENmodel*,CKTcircuit*,int*);
extern int VCCSunsetup(GENmodel*,CKTcircuit*);
extern int VCCSfindBr(CKTcircuit*, GENmodel*, IFuid);

View File

@ -0,0 +1,36 @@
/***********************************
* Author: Marcel Hendrix, Feb 2015 *
***********************************/
#include "ngspice/ngspice.h"
#include "ngspice/cktdefs.h"
#include "vccsdefs.h"
#include "ngspice/sperror.h"
#include "ngspice/suffix.h"
int
VCCSfindBr (CKTcircuit *ckt, GENmodel *inModel, IFuid name)
{
VCCSmodel *model = (VCCSmodel *) inModel;
VCCSinstance *here;
for (; model; model = model->VCCSnextModel)
for (here = model->VCCSinstances; here; here = here->VCCSnextInstance)
if (here->VCCSname == name) {
if (!here->VCCSbranch) {
CKTnode *tmp;
int error;
error = CKTmkCur(ckt, &tmp, here->VCCSname, "branch");
if (error)
return error;
here->VCCSbranch = tmp->number;
}
return here->VCCSbranch;
}
return 0;
}

View File

@ -44,11 +44,11 @@ SPICEdev VCCSinfo = {
/* DEVmodParam */ NULL,
/* DEVload */ VCCSload,
/* DEVsetup */ VCCSsetup,
/* DEVunsetup */ NULL,
/* DEVunsetup */ VCCSunsetup,
/* DEVpzSetup */ VCCSsetup,
/* DEVtemperature*/ NULL,
/* DEVtrunc */ NULL,
/* DEVfindBranch */ NULL,
/* DEVfindBranch */ VCCSfindBr,
/* DEVacLoad */ VCCSload, /* ac and normal loads are identical */
/* DEVaccept */ NULL,
/* DEVdestroy */ VCCSdestroy,

View File

@ -31,10 +31,15 @@ VCCSload(GENmodel *inModel, CKTcircuit *ckt)
for (here = model->VCCSinstances; here != NULL ;
here=here->VCCSnextInstance) {
*(here->VCCSposContPosptr) += here->VCCScoeff ;
*(here->VCCSposContNegptr) -= here->VCCScoeff ;
*(here->VCCSposPrimeContPosptr) += here->VCCScoeff ;
*(here->VCCSposPrimeContNegptr) -= here->VCCScoeff ;
*(here->VCCSnegContPosptr) -= here->VCCScoeff ;
*(here->VCCSnegContNegptr) += here->VCCScoeff ;
if (here->VCCSbranch) {
*(here->VCCS_pos_ibr) += 1.0;
*(here->VCCS_posPrime_ibr) -= 1.0;
}
}
}
return(OK);

View File

@ -33,10 +33,15 @@ VCCSpzLoad(GENmodel *inModel, CKTcircuit *ckt, SPcomplex *s)
for (here = model->VCCSinstances; here != NULL ;
here=here->VCCSnextInstance) {
*(here->VCCSposContPosptr) += here->VCCScoeff ;
*(here->VCCSposContNegptr) -= here->VCCScoeff ;
*(here->VCCSposPrimeContPosptr) += here->VCCScoeff ;
*(here->VCCSposPrimeContNegptr) -= here->VCCScoeff ;
*(here->VCCSnegContPosptr) -= here->VCCScoeff ;
*(here->VCCSnegContNegptr) += here->VCCScoeff ;
if (here->VCCSbranch) {
*(here->VCCS_pos_ibr) += 1.0;
*(here->VCCS_posPrime_ibr) -= 1.0;
}
}
}
return(OK);

View File

@ -40,11 +40,37 @@ do { if((here->ptr = SMPmakeElt(matrix, here->first, here->second)) == NULL){\
return(E_NOMEM);\
} } while(0)
TSTALLOC(VCCSposContPosptr, VCCSposNode, VCCScontPosNode);
TSTALLOC(VCCSposContNegptr, VCCSposNode, VCCScontNegNode);
if (here->VCCSbranch == 0) {
here->VCCSposPrimeNode = here->VCCSposNode;
} else {
here->VCCSposPrimeNode = here->VCCSbranch;
TSTALLOC(VCCS_pos_ibr, VCCSposNode, VCCSbranch);
TSTALLOC(VCCS_posPrime_ibr, VCCSposPrimeNode, VCCSbranch);
}
TSTALLOC(VCCSposPrimeContPosptr, VCCSposPrimeNode, VCCScontPosNode);
TSTALLOC(VCCSposPrimeContNegptr, VCCSposPrimeNode, VCCScontNegNode);
TSTALLOC(VCCSnegContPosptr, VCCSnegNode, VCCScontPosNode);
TSTALLOC(VCCSnegContNegptr, VCCSnegNode, VCCScontNegNode);
}
}
return(OK);
}
int
VCCSunsetup(GENmodel *inModel, CKTcircuit *ckt)
{
VCCSmodel *model = (VCCSmodel *) inModel;
VCCSinstance *here;
for (; model; model = model->VCCSnextModel)
for (here = model->VCCSinstances; here; here = here->VCCSnextInstance)
if (here->VCCSbranch) {
CKTdltNNum(ckt, here->VCCSbranch);
here->VCCSbranch = 0;
here->VCCSposPrimeNode = 0;
}
return OK;
}