From 7a023e466b51d5ebdea9bd75887f5a698a61a442 Mon Sep 17 00:00:00 2001 From: Markus Mueller Date: Sun, 9 Aug 2020 18:37:50 +0200 Subject: [PATCH] understanding spice interface --- src/spicelib/devices/hicum2/model_class.cpp | 45 ++++++------- src/spicelib/devices/hicum2/model_class.hpp | 73 ++++++++++++++++++--- 2 files changed, 85 insertions(+), 33 deletions(-) diff --git a/src/spicelib/devices/hicum2/model_class.cpp b/src/spicelib/devices/hicum2/model_class.cpp index c7bb54c84..8605791fc 100644 --- a/src/spicelib/devices/hicum2/model_class.cpp +++ b/src/spicelib/devices/hicum2/model_class.cpp @@ -74,13 +74,13 @@ double inf = std::numeric_limits::infinity(); SPICEdev * NGSpiceModel::get_model_info() { - SPICEdev model_info = { + this->model_info = { .DEVpublic = { - .name = this.name, - .description = "High Current Model for BJT", - .terms = &this->n_external_nodes, - .numNames = &HICUMnSize, - .termNames = HICUMnames, + .name = this->name, + .description = "High Current Model for BJT", + .terms = &this->n_external_nodes, + .numNames = &this->n_external_nodes, + .termNames = this->MODELnames, .numInstanceParms = &HICUMpTSize, .instanceParms = HICUMpTable, .numModelParms = &HICUMmPTSize, @@ -99,7 +99,7 @@ SPICEdev * NGSpiceModel::get_model_info() }, .DEVparam = HICUMparam, - .DEVmodParam = HICUMmParam, + .DEVmodParam = this->MODELmParam, .DEVload = HICUMload, .DEVsetup = HICUMsetup, .DEVunsetup = HICUMunsetup, @@ -121,24 +121,24 @@ SPICEdev * NGSpiceModel::get_model_info() .DEVsenLoad = NULL, .DEVsenUpdate = NULL, .DEVsenAcLoad = NULL, - .DEVsenPrint = NULL, - .DEVsenTrunc = NULL, - .DEVdisto = NULL, - .DEVnoise = HICUMnoise, - .DEVsoaCheck = HICUMsoaCheck, - .DEVinstSize = &HICUMiSize, - .DEVmodSize = &HICUMmSize, + .DEVsenPrint = NULL, + .DEVsenTrunc = NULL, + .DEVdisto = NULL, + .DEVnoise = HICUMnoise, + .DEVsoaCheck = HICUMsoaCheck, + .DEVinstSize = &this->instance_size, + .DEVmodSize = &this->model_size, #ifdef CIDER .DEVdump = NULL, .DEVacct = NULL, #endif }; - return &modelinfo; + return &(this->model_info); } HICUML2::HICUML2(){ - modelcard = { + this->spice_model_struct.modelcard = { {"c10",Parameter(2.0E-30, 0,1)}, {"qp0",Parameter(2.0E-14,0,1)}, {"ich",Parameter(0.0,0,inf)}, @@ -285,15 +285,10 @@ HICUML2::HICUML2(){ Node((char*)"S"), Node((char*)"T"), }; - external_nodes = { - Node((char*)"B"), - Node((char*)"C"), - Node((char*)"E"), - Node((char*)"S"), - Node((char*)"T"), - }; - this->n_external_nodes = static_cast(this->external_nodes.size()); - this->description = "High Current Model for BJT"; + // set model specific constants + this->n_external_nodes = sizeof(this->MODELnames); + this->model_size = sizeof(this->spice_model_struct); + this->instance_size = sizeof(this->spice_instance_struct); }; //HICUML2 hicumL2_example = HICUML2(); diff --git a/src/spicelib/devices/hicum2/model_class.hpp b/src/spicelib/devices/hicum2/model_class.hpp index 6429dd450..068cf1682 100644 --- a/src/spicelib/devices/hicum2/model_class.hpp +++ b/src/spicelib/devices/hicum2/model_class.hpp @@ -56,23 +56,80 @@ class Branch Branch(Node * node_from, Node * node_to, std::vector depends); }; +//SPICE model structure +typedef struct sGENmodel { + struct GENmodel gen; +#define GENmodType gen.GENmodType +#define GENnextModel(inst) ((struct sGENmodel *)((inst)->gen.GENnextModel)) +#define GENinstances(inst) ((GENinstance *)((inst)->gen.GENinstances)) +#define GENmodName gen.GENmodName + std::unordered_map modelcard; //the modelcard of the model +}; +// SPICE instance structure +typedef struct sGENinstance { + struct GENinstance gen; +#define MODELmodPtr(inst) ((struct sGENmodel *)((inst)->gen.GENmodPtr)) +#define MODELnextInstance(inst) ((struct sGENinstance *)((inst)->gen.GENnextInstance)) +#define MODELname gen.GENname +#define MODELstate gen.GENstate + //the external nodes in exactly the same order as they appear in the call to the model + //TODO -> how to generalize this + const int HICUMcollNode; /* number of collector node of hicum */ + const int HICUMbaseNode; /* number of base node of hicum */ + const int HICUMemitNode; /* number of emitter node of hicum */ + const int HICUMsubsNode; /* number of substrate node of hicum */ + const int HICUMtempNode; /* number of the temperature node of the hicum */ +}; + class NGSpiceModel { public: - std::unordered_map modelcard; //the modelcard of the model - std::vector nodes; //all nodes of the model, including internal and externals - std::vector external_nodes; //the external nodes of the model - std::vector branches; //the branches of the model - int n_external_nodes; //the name of the model - const char * name = "None"; //the name of the model + std::vector nodes; //all nodes of the model, including internal and externals + std::vector external_nodes; //the external nodes of the model + std::vector branches; //the branches of the model + int n_external_nodes; //the name of the model + int model_size; //the size of the model structure + int instance_size; //the size of the instance structure + char * name ; //the name of the model + const char * description ; //the description of the model + char *MODELnames[]; // array of the names of the external nodes + //spice data structures + sGENmodel spice_model_struct; + sGENinstance spice_instance_struct; + SPICEdev model_info; + //spice methods + SPICEdev * get_model_info(); + int MODELacLoad(GENmodel *,CKTcircuit*); + int MODELask(CKTcircuit *,GENinstance*,int,IFvalue*,IFvalue*); + int MODELconvTest(GENmodel*,CKTcircuit*); + int MODELdelete(GENinstance*); + int MODELgetic(GENmodel*,CKTcircuit*); + //extern int HICUMload(GENmodel*,CKTcircuit*);//moved to hicumL2.hpp + int MODELmAsk(CKTcircuit*,GENmodel*,int,IFvalue*); + int MODELmParam(int,IFvalue*,GENmodel*); + int MODELparam(int,IFvalue*,GENinstance*,IFvalue*); + int MODELpzLoad(GENmodel*, CKTcircuit*, SPcomplex*); + int MODELsetup(SMPmatrix*,GENmodel*,CKTcircuit*,int*); + int MODELunsetup(GENmodel*,CKTcircuit*); + // extern int HICUMtemp(GENmodel*,CKTcircuit*); // moved to hicum2temp.hpp + int MODELtrunc(GENmodel*,CKTcircuit*,double*); + int MODELnoise(int,int,GENmodel*,CKTcircuit*,Ndata*,double*); + int MODELsoaCheck(CKTcircuit *, GENmodel *); }; class HICUML2 : public NGSpiceModel { public: - const char * name = "hl2"; + const char * name = "hl2"; + const char * description = "high-speed HBT model"; //the description of the model + char *MODELnames[5] = { + "collector", + "base", + "emitter", + "substrate", + "temp" + }; HICUML2(); - SPICEdev * get_model_info(); // return the SPICEdev }; #endif