From 7345c3d03235e3b022d03e68026894b44af98e5c Mon Sep 17 00:00:00 2001 From: Francesco Lannutti Date: Thu, 6 Jun 2013 08:05:27 +0200 Subject: [PATCH] Implemented a new check for the KCL Verification, based on the maximum of the unknown current branches at each voltage node. Please note that this check introduces the theoretically correct check, but, since achieving this target involves the perfect knowledge of every model, we can use this suboptimal and practical check (to be extended with the other possible unknown current branches) --- src/spicelib/analysis/cktmkcurKCL.c | 21 ++++++++++++++++++++ src/spicelib/devices/ind/indnode.c | 29 ++++++++++++++++++++++++++++ src/spicelib/devices/vsrc/vsrcnode.c | 29 ++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 src/spicelib/analysis/cktmkcurKCL.c create mode 100644 src/spicelib/devices/ind/indnode.c create mode 100644 src/spicelib/devices/vsrc/vsrcnode.c diff --git a/src/spicelib/analysis/cktmkcurKCL.c b/src/spicelib/analysis/cktmkcurKCL.c new file mode 100644 index 000000000..4506af60c --- /dev/null +++ b/src/spicelib/analysis/cktmkcurKCL.c @@ -0,0 +1,21 @@ +/********** +Author: 2013 Francesco Lannutti +**********/ + +#include "ngspice/ngspice.h" +#include "ngspice/sperror.h" +#include "ngspice/cktdefs.h" + +int +CKTmkCurKCL (CKTcircuit *ckt, int i, double **node) +{ + CKTmkCurKCLnode *tempNode ; + + tempNode = TMALLOC (CKTmkCurKCLnode, 1) ; + tempNode->KCLcurrent = 0.0 ; + tempNode->next = ckt->CKTmkCurKCLarray [i] ; + ckt->CKTmkCurKCLarray [i] = tempNode ; + *node = &(tempNode->KCLcurrent) ; + + return (OK) ; +} diff --git a/src/spicelib/devices/ind/indnode.c b/src/spicelib/devices/ind/indnode.c new file mode 100644 index 000000000..bb1203981 --- /dev/null +++ b/src/spicelib/devices/ind/indnode.c @@ -0,0 +1,29 @@ +/********** +Author: 2013 Francesco Lannutti +**********/ + +#include "ngspice/ngspice.h" +#include "ngspice/cktdefs.h" +#include "inddefs.h" +#include "ngspice/sperror.h" + +int +INDnodeIsNonLinear (GENmodel *inModel, CKTcircuit *ckt) +{ + INDmodel *model = (INDmodel *)inModel ; + INDinstance *here ; + int error ; + + /* loop through all the IND models */ + for ( ; model != NULL ; model = model->INDnextModel) + { + /* loop through all the instances of the model */ + for (here = model->INDinstances ; here != NULL ; here = here->INDnextInstance) + { + error = CKTmkCurKCL (ckt, here->INDposNode, &(here->KCLcurrentPos)) ; + error = CKTmkCurKCL (ckt, here->INDnegNode, &(here->KCLcurrentNeg)) ; + } + } + + return (OK) ; +} diff --git a/src/spicelib/devices/vsrc/vsrcnode.c b/src/spicelib/devices/vsrc/vsrcnode.c new file mode 100644 index 000000000..fe733593c --- /dev/null +++ b/src/spicelib/devices/vsrc/vsrcnode.c @@ -0,0 +1,29 @@ +/********** +Author: 2013 Francesco Lannutti +**********/ + +#include "ngspice/ngspice.h" +#include "ngspice/cktdefs.h" +#include "vsrcdefs.h" +#include "ngspice/sperror.h" + +int +VSRCnodeIsNonLinear (GENmodel *inModel, CKTcircuit *ckt) +{ + VSRCmodel *model = (VSRCmodel *)inModel ; + VSRCinstance *here ; + int error ; + + /* loop through all the VSRC models */ + for ( ; model != NULL ; model = model->VSRCnextModel) + { + /* loop through all the instances of the model */ + for (here = model->VSRCinstances ; here != NULL ; here = here->VSRCnextInstance) + { + error = CKTmkCurKCL (ckt, here->VSRCposNode, &(here->KCLcurrentPos)) ; + error = CKTmkCurKCL (ckt, here->VSRCnegNode, &(here->KCLcurrentNeg)) ; + } + } + + return (OK) ; +}