a first attempt to access branch current of rlc devices

This commit is contained in:
dwarning 2015-04-01 22:23:19 +02:00
parent 9c8766f65b
commit 66d9bf25c9
3 changed files with 107 additions and 0 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}