From 72d78a2053eac8ce546558886325b2ea7a8e116d Mon Sep 17 00:00:00 2001 From: Francesco Lannutti Date: Tue, 16 Jun 2020 13:36:44 +0200 Subject: [PATCH] Added the KLU support to ADMS models --- .../adms/admst/ngspiceMODULEbindCSC.c.xml | 175 ++++++++++++++++++ .../adms/admst/ngspiceMODULEdefs.h.xml | 10 + .../devices/adms/admst/ngspiceMODULEext.h.xml | 6 + .../adms/admst/ngspiceMODULEinit.c.xml | 6 + .../devices/adms/admst/ngspiceMakefile.am.xml | 61 ++++++ 5 files changed, 258 insertions(+) create mode 100644 src/spicelib/devices/adms/admst/ngspiceMODULEbindCSC.c.xml diff --git a/src/spicelib/devices/adms/admst/ngspiceMODULEbindCSC.c.xml b/src/spicelib/devices/adms/admst/ngspiceMODULEbindCSC.c.xml new file mode 100644 index 000000000..7f42ba556 --- /dev/null +++ b/src/spicelib/devices/adms/admst/ngspiceMODULEbindCSC.c.xml @@ -0,0 +1,175 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +/********** +Author: 2020 Francesco Lannutti +**********/ + +#include "ngspice/ngspice.h" +#include "ngspice/cktdefs.h" +#include "$(module)defs.h" +#include "ngspice/sperror.h" +#include "ngspice/klu-binding.h" + +#include <stdlib.h> + +static +int +BindCompare (const void *a, const void *b) +{ + BindElement *A, *B ; + A = (BindElement *)a ; + B = (BindElement *)b ; + + return ((int)(A->Sparse - B->Sparse)) ; +} + +int +$(module)bindCSC (GENmodel *inModel, CKTcircuit *ckt) +{ + $(module)model *model = ($(module)model *)inModel ; + $(module)instance *here ; + double *i ; + BindElement *matched, *BindStruct ; + size_t nz ; + + BindStruct = ckt->CKTmatrix->CKTbindStruct ; + nz = (size_t)ckt->CKTmatrix->CKTklunz ; + + /* loop through all the $(module) models */ + for ( ; model != NULL ; model = $(module)nextModel(model)) + { + /* loop through all the instances of the model */ + for (here = $(module)instances(model); here != NULL ; here = $(module)nextInstance(here)) + { + + + + + + + + CREATE_KLU_BINDING_TABLE(PTR_J_%s_%s, $(module)%s%sBinding, %sNode, %sNode); + + } + } + + return (OK) ; +} + +int +$(module)bindCSCComplex (GENmodel *inModel, CKTcircuit *ckt) +{ + $(module)model *model = ($(module)model *)inModel ; + $(module)instance *here ; + + NG_IGNORE (ckt) ; + + /* loop through all the $(module) models */ + for ( ; model != NULL ; model = $(module)nextModel(model)) + { + /* loop through all the instances of the model */ + for (here = $(module)instances(model); here != NULL ; here = $(module)nextInstance(here)) + { + + + + + + + + CONVERT_KLU_BINDING_TABLE_TO_COMPLEX(PTR_J_%s_%s, $(module)%s%sBinding, %sNode, %sNode); + + } + } + + return (OK) ; +} + +int +$(module)bindCSCComplexToReal (GENmodel *inModel, CKTcircuit *ckt) +{ + $(module)model *model = ($(module)model *)inModel ; + $(module)instance *here ; + + NG_IGNORE (ckt) ; + + /* loop through all the $(module) models */ + for ( ; model != NULL ; model = $(module)nextModel(model)) + { + /* loop through all the instances of the model */ + for (here = $(module)instances(model); here != NULL ; here = $(module)nextInstance(here)) + { + + + + + + + + CONVERT_KLU_BINDING_TABLE_TO_REAL(PTR_J_%s_%s, $(module)%s%sBinding, %sNode, %sNode); + + } + } + + return (OK) ; +} + + + + + + + + + + + + + + + + + + + diff --git a/src/spicelib/devices/adms/admst/ngspiceMODULEdefs.h.xml b/src/spicelib/devices/adms/admst/ngspiceMODULEdefs.h.xml index 2364a9953..eca9991f1 100644 --- a/src/spicelib/devices/adms/admst/ngspiceMODULEdefs.h.xml +++ b/src/spicelib/devices/adms/admst/ngspiceMODULEdefs.h.xml @@ -280,6 +280,16 @@ typedef struct s$(module)instance { +#define $(module)numStates 0 + +#ifdef KLU + + + + BindElement *$(module)%s%sBinding ; + +#endif + } $(module)instance ; enum { diff --git a/src/spicelib/devices/adms/admst/ngspiceMODULEext.h.xml b/src/spicelib/devices/adms/admst/ngspiceMODULEext.h.xml index 1217fc866..f96de98f3 100644 --- a/src/spicelib/devices/adms/admst/ngspiceMODULEext.h.xml +++ b/src/spicelib/devices/adms/admst/ngspiceMODULEext.h.xml @@ -53,6 +53,12 @@ extern int $(module)trunc(GENmodel*,CKTcircuit*,double*); extern int $(module)unsetup(GENmodel*,CKTcircuit*); extern void $(module)destroy(void); +#ifdef KLU +extern int $(module)bindCSC (GENmodel*, CKTcircuit*) ; +extern int $(module)bindCSCComplex (GENmodel*, CKTcircuit*) ; +extern int $(module)bindCSCComplexToReal (GENmodel*, CKTcircuit*) ; +#endif + #endif diff --git a/src/spicelib/devices/adms/admst/ngspiceMODULEinit.c.xml b/src/spicelib/devices/adms/admst/ngspiceMODULEinit.c.xml index 83bde7ad1..9e39f7cbc 100644 --- a/src/spicelib/devices/adms/admst/ngspiceMODULEinit.c.xml +++ b/src/spicelib/devices/adms/admst/ngspiceMODULEinit.c.xml @@ -93,6 +93,12 @@ SPICEdev $(module)info = { .DEVdump = NULL, .DEVacct = NULL, #endif + +#ifdef KLU + .DEVbindCSC = $(module)bindCSC, + .DEVbindCSCComplex = $(module)bindCSCComplex, + .DEVbindCSCComplexToReal = $(module)bindCSCComplexToReal, +#endif }; diff --git a/src/spicelib/devices/adms/admst/ngspiceMakefile.am.xml b/src/spicelib/devices/adms/admst/ngspiceMakefile.am.xml index b799f115a..0751491b2 100644 --- a/src/spicelib/devices/adms/admst/ngspiceMakefile.am.xml +++ b/src/spicelib/devices/adms/admst/ngspiceMakefile.am.xml @@ -57,6 +57,10 @@ BUILT_SOURCES = \\ $(module)temp.c \\ $(module)trunc.c +if KLU_WANTED +BUILT_SOURCES += $(module)bindCSC.c +endif + lib$(module)_la_SOURCES = \\ \$(BUILT_SOURCES) @@ -84,6 +88,62 @@ MAINTAINERCLEANFILES = Makefile.in \\ DISTCLEANFILES = Makefile.am \\ Makefile.in +if KLU_WANTED +\%.c \%.hxx \\ + \%acld.c \%ask.c \%bindCSC.c \%defs.h \%del.c \%dest.c \%ext.h \%guesstopology.c \\ + \%init.c \%init.h \%itf.h \%load.c \%mask.c \%mdel.c \%mpar.c \%par.c \\ + \%pzld.c \%setup.c \%temp.c \%trunc.c \\ + : \$(srcdir)/admsva/\%.va \\ + \$(ADMSXMLINTERFACE)/ngspiceVersion.xml \\ + \$(ADMSXMLINTERFACE)/ngspiceMODULEbindCSC.c.xml \\ + \$(ADMSXMLINTERFACE)/ngspiceMODULEitf.h.xml \\ + \$(ADMSXMLINTERFACE)/ngspiceMODULEinit.c.xml \\ + \$(ADMSXMLINTERFACE)/ngspiceMODULEinit.h.xml \\ + \$(ADMSXMLINTERFACE)/ngspiceMODULEext.h.xml \\ + \$(ADMSXMLINTERFACE)/ngspiceMODULEdefs.h.xml \\ + \$(ADMSXMLINTERFACE)/ngspiceMODULEask.c.xml \\ + \$(ADMSXMLINTERFACE)/ngspiceMODULEmask.c.xml \\ + \$(ADMSXMLINTERFACE)/ngspiceMODULEpar.c.xml \\ + \$(ADMSXMLINTERFACE)/ngspiceMODULEmpar.c.xml \\ + \$(ADMSXMLINTERFACE)/ngspiceMODULEload.c.xml \\ + \$(ADMSXMLINTERFACE)/ngspiceMODULEacld.c.xml \\ + \$(ADMSXMLINTERFACE)/ngspiceMODULEpzld.c.xml \\ + \$(ADMSXMLINTERFACE)/ngspiceMODULEtemp.c.xml \\ + \$(ADMSXMLINTERFACE)/ngspiceMODULEtrunc.c.xml \\ + \$(ADMSXMLINTERFACE)/ngspiceMODULEsetup.c.xml \\ + \$(ADMSXMLINTERFACE)/ngspiceMODULEdel.c.xml \\ + \$(ADMSXMLINTERFACE)/ngspiceMODULEmdel.c.xml \\ + \$(ADMSXMLINTERFACE)/ngspiceMODULEdest.c.xml \\ + \$(ADMSXMLINTERFACE)/ngspiceMODULEnoise.c.xml \\ + \$(ADMSXMLINTERFACE)/ngspiceMODULEguesstopology.c.xml \\ + \$(ADMSXMLINTERFACE)/ngspiceMODULE.hxx.xml \\ + \$(ADMSXMLINTERFACE)/ngspiceMODULE.c.xml + \$(ADMSXML) -I\$(srcdir) -I\$(srcdir)/admsva \$< \\ + -e \$(ADMSXMLINTERFACE)/ngspiceVersion.xml \\ + -e \$(ADMSXMLINTERFACE)/ngspiceMODULEbindCSC.c.xml \\ + -e \$(ADMSXMLINTERFACE)/ngspiceMODULEitf.h.xml \\ + -e \$(ADMSXMLINTERFACE)/ngspiceMODULEinit.c.xml \\ + -e \$(ADMSXMLINTERFACE)/ngspiceMODULEinit.h.xml \\ + -e \$(ADMSXMLINTERFACE)/ngspiceMODULEext.h.xml \\ + -e \$(ADMSXMLINTERFACE)/ngspiceMODULEdefs.h.xml \\ + -e \$(ADMSXMLINTERFACE)/ngspiceMODULEask.c.xml \\ + -e \$(ADMSXMLINTERFACE)/ngspiceMODULEmask.c.xml \\ + -e \$(ADMSXMLINTERFACE)/ngspiceMODULEpar.c.xml \\ + -e \$(ADMSXMLINTERFACE)/ngspiceMODULEmpar.c.xml \\ + -e \$(ADMSXMLINTERFACE)/ngspiceMODULEload.c.xml \\ + -e \$(ADMSXMLINTERFACE)/ngspiceMODULEacld.c.xml \\ + -e \$(ADMSXMLINTERFACE)/ngspiceMODULEpzld.c.xml \\ + -e \$(ADMSXMLINTERFACE)/ngspiceMODULEtemp.c.xml \\ + -e \$(ADMSXMLINTERFACE)/ngspiceMODULEtrunc.c.xml \\ + -e \$(ADMSXMLINTERFACE)/ngspiceMODULEsetup.c.xml \\ + -e \$(ADMSXMLINTERFACE)/ngspiceMODULEdel.c.xml \\ + -e \$(ADMSXMLINTERFACE)/ngspiceMODULEmdel.c.xml \\ + -e \$(ADMSXMLINTERFACE)/ngspiceMODULEdest.c.xml \\ + -e \$(ADMSXMLINTERFACE)/ngspiceMODULEnoise.c.xml \\ + -e \$(ADMSXMLINTERFACE)/ngspiceMODULEguesstopology.c.xml \\ + -e \$(ADMSXMLINTERFACE)/ngspiceMODULE.hxx.xml \\ + -e \$(ADMSXMLINTERFACE)/ngspiceMODULE.c.xml +else \%.c \%.hxx \\ \%acld.c \%.analogfunction.c \%ask.c \%defs.h \%del.c \%dest.c \%ext.h \%guesstopology.c \\ \%init.c \%init.h \%itf.h \%load.c \%mask.c \%mdel.c \%mpar.c \%par.c \\ @@ -141,6 +201,7 @@ DISTCLEANFILES = Makefile.am \\ -e \$(ADMSXMLINTERFACE)/ngspiceMODULEguesstopology.c.xml \\ -e \$(ADMSXMLINTERFACE)/ngspiceMODULE.hxx.xml \\ -e \$(ADMSXMLINTERFACE)/ngspiceMODULE.c.xml +endif