Adding capacitors, one per voltage node

This commit is contained in:
Holger Vogt 2021-04-02 23:37:59 +02:00
parent f8357dad88
commit 911b50fa8f
3 changed files with 82 additions and 0 deletions

View File

@ -60,6 +60,8 @@ libinp_la_SOURCES = \
inppas2.h \ inppas2.h \
inppas3.c \ inppas3.c \
inppas3.h \ inppas3.h \
inppas4.c \
inppas4.h \
inppname.c \ inppname.c \
inpptree.c \ inpptree.c \
inpptree-parser.y \ inpptree-parser.y \

View File

@ -0,0 +1,72 @@
/**********
Copyright 1990 Regents of the University of California. All rights reserved.
Author: 1985 Thomas L. Quarles
**********/
#include "ngspice/ngspice.h"
#include "ngspice/ifsim.h"
#include "ngspice/inpdefs.h"
#include "ngspice/inpmacs.h"
#include "ngspice/fteext.h"
#include "ngspice/iferrmsg.h"
#include "inppas4.h"
#include "inpxx.h"
#ifdef XSPICE
/* gtri - add - wbk - 11/9/90 - include function prototypes */
#include "ngspice/mifproto.h"
/* gtri - end - wbk - 11/9/90 */
#endif
/* uncomment to trace in this file */
/*#define TRACE*/
/* pass 4 - If option cshunt is given,
add a capacitor to each voltage node */
void INPpas4(CKTcircuit *ckt, INPtables * tab)
{
CKTnode* node;
int mytype = -1;
IFuid uid; /* uid for default cap model */
int error; /* error code temporary */
GENinstance* fast; /* pointer to the actual instance */
IFvalue ptemp; /* a value structure to package capacitance into */
int nadded = 0; /* capacitors added */
if ((mytype = INPtypelook("Capacitor")) < 0) {
fprintf(stderr, "Device type Capacitor not supported by this binary\n");
return;
}
if (!tab->defCmod) { /* create default C model */
IFnewUid(ckt, &uid, NULL, "C", UID_MODEL, NULL);
error = (*(ft_sim->newModel))(ckt, mytype, &(tab->defCmod), uid);
}
/* scan through all nodes, add a new C device for each voltage node */
for (node = ckt->CKTnodes; node; node = node->next) {
if (node->type == NODE_VOLTAGE && (node->number > 0)) {
int nn = node->number;
char* devname = tprintf("capac%dshunt", nn);
(*(ft_sim->newInstance))(ckt, tab->defCmod, &fast, devname);
/* the top node, second node is gnd automatically */
(*(ft_sim->bindNode))(ckt, fast, 1, node);
/* value of the capacitance */
ptemp.rValue = ft_curckt->ci_defTask->TSKcshunt;
error = INPpName("capacitance", &ptemp, ckt, mytype, fast);
/* add device numbers for statistics */
ckt->CKTstat->STATdevNum[mytype].instNum++;
ckt->CKTstat->STATtotalDev++;
tfree(devname);
nadded++;
}
}
printf("Option cshunt: %d capacitors added with %g F each\n", nadded, ft_curckt->ci_defTask->TSKcshunt);
}

View File

@ -0,0 +1,8 @@
#ifndef ngspice_INPPAS4_H
#define ngspice_INPPAS4_H
#include "ngspice/inpdefs.h"
#endif