From 66d9bf25c942efe7a1a78c6f7a2301b69f288fc8 Mon Sep 17 00:00:00 2001 From: dwarning Date: Wed, 1 Apr 2015 22:23:19 +0200 Subject: [PATCH] a first attempt to access branch current of rlc devices --- src/spicelib/devices/cap/capfindbr.c | 38 +++++++++++++++++++++++++++ src/spicelib/devices/ind/indfindbr.c | 30 +++++++++++++++++++++ src/spicelib/devices/res/resfindbr.c | 39 ++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 src/spicelib/devices/cap/capfindbr.c create mode 100644 src/spicelib/devices/ind/indfindbr.c create mode 100644 src/spicelib/devices/res/resfindbr.c diff --git a/src/spicelib/devices/cap/capfindbr.c b/src/spicelib/devices/cap/capfindbr.c new file mode 100644 index 000000000..e779eeaba --- /dev/null +++ b/src/spicelib/devices/cap/capfindbr.c @@ -0,0 +1,38 @@ +/*********************************** +* Author: Marcel Hendrix, Feb 2015 * +***********************************/ + +#include "ngspice/ngspice.h" +#include "ngspice/cktdefs.h" +#include "capdefs.h" +#include "ngspice/sperror.h" +#include "ngspice/suffix.h" + +/* macro to make elements with built-in test for out of memory */ +#define TSTALLOC(matrix, ptr, row, col) \ +do { if((ptr = SMPmakeElt(matrix, row, col)) == NULL){\ + return E_NOMEM;\ +} } while(0) + +int CAPfindBr (CKTcircuit *ckt, GENmodel *inModel, IFuid name) { + CAPmodel *model = (CAPmodel *)inModel; + CAPinstance *here; + int error; + CKTnode *tmp; + + for (; model != NULL; model = model->CAPnextModel) { + for (here = model->CAPinstances; here != NULL; here = here->CAPnextInstance) { + if (here->CAPname == name) { + if (here->CAPbrptr == NULL) { + error = CKTmkCur(ckt, &tmp, here->CAPname, "branch"); + if (error) return error; + here->CAPbrEq = tmp->number; + if (ckt->CKTmatrix != NULL) + TSTALLOC(ckt->CKTmatrix, here->CAPbrptr, here->CAPbrEq, here->CAPbrEq); + } + return here->CAPbrEq; + } + } + } + return 0; +} diff --git a/src/spicelib/devices/ind/indfindbr.c b/src/spicelib/devices/ind/indfindbr.c new file mode 100644 index 000000000..ec499a01c --- /dev/null +++ b/src/spicelib/devices/ind/indfindbr.c @@ -0,0 +1,30 @@ +/*********************************** +* Author: Marcel Hendrix, Feb 2015 * +***********************************/ + +#include "ngspice/ngspice.h" +#include "ngspice/cktdefs.h" +#include "inddefs.h" +#include "ngspice/sperror.h" +#include "ngspice/suffix.h" + +int INDfindBr (CKTcircuit *ckt, GENmodel *inModel, IFuid name) { + INDmodel *model = (INDmodel *)inModel; + INDinstance *here; + int error; + CKTnode *tmp; + + for (; model != NULL; model = model->INDnextModel) { + for (here = model->INDinstances; here != NULL; here = here->INDnextInstance) { + if (here->INDname == name) { + if (here->INDbrEq == 0) { + error = CKTmkCur(ckt, &tmp, here->INDname, "branch"); + if (error) return error; + here->INDbrEq = tmp->number; + } + return here->INDbrEq; + } + } + } + return 0; +} diff --git a/src/spicelib/devices/res/resfindbr.c b/src/spicelib/devices/res/resfindbr.c new file mode 100644 index 000000000..f8610805b --- /dev/null +++ b/src/spicelib/devices/res/resfindbr.c @@ -0,0 +1,39 @@ +/*********************************** +* Author: Marcel Hendrix, Feb 2015 * +***********************************/ + +#include "ngspice/ngspice.h" +#include "ngspice/cktdefs.h" +#include "resdefs.h" +#include "ngspice/sperror.h" +#include "ngspice/suffix.h" + +/* macro to make elements with built-in test for out of memory */ +#define TSTALLOC(matrix, ptr, row, col) \ +do { if((ptr = SMPmakeElt(matrix, row, col)) == NULL){\ + return E_NOMEM;\ +} } while(0) + + +int RESfindBr (CKTcircuit *ckt, GENmodel *inModel, IFuid name) { + RESmodel *model = (RESmodel *)inModel; + RESinstance *here; + int error; + CKTnode *tmp; + + for (; model != NULL; model = model->RESnextModel) { + for (here = model->RESinstances; here != NULL; here = here->RESnextInstance) { + if (here->RESname == name) { + if (here->RESbrptr == NULL) { + error = CKTmkCur(ckt, &tmp, here->RESname, "branch"); + if (error) return error; + here->RESbrEq = tmp->number; + if (ckt->CKTmatrix != NULL) + TSTALLOC(ckt->CKTmatrix, here->RESbrptr, here->RESbrEq, here->RESbrEq); + } + return here->RESbrEq; + } + } + } + return 0; +}