add C++ node and branch

This commit is contained in:
Markus Mueller 2020-07-19 14:03:52 +02:00
parent 44252c0806
commit e20d887ee3
3 changed files with 112 additions and 15 deletions

View File

@ -40,20 +40,6 @@ HICUMmParam(int param, IFvalue *value, GENmodel *inModel)
};
setModelcardPara(HICUMinfo.DEVpublic.modelParms[para_found].keyword, value->rValue);
//printf("%s",HICUMinfo.DEVpublic.modelParms[para_found].keyword);
// static IFparm *
// find_model_parameter(const char *name, IFdevice *device)
// {
// IFparm *p = device->modelParms;
// IFparm *p_end = p + *(device->numModelParms);
// for (; p < p_end; p++)
// if (strcmp(name, p->keyword) == 0)
// return p;
// return NULL;
// }
switch(param) {

View File

@ -5,19 +5,98 @@
#include <limits>
#include <model_class.hpp>
#include <stdexcept>
extern "C" {
#include "ngspice/cktdefs.h"
#include "ngspice/ngspice.h"
#include "ngspice/smpdefs.h"
#include "ngspice/const.h"
#include "ngspice/sperror.h"
#include "ngspice/ifsim.h"
#include "ngspice/suffix.h"
}
Parameter::Parameter(double value_default, double min_value, double max_value) {
/* Modelcard parameter constructor.
Input
-----
value_default : double
Default value of the parameter.
min_value : double
Minimum value of the parameter.
max_value : double
Maximum value of the parameter.
*/
value_default = value_default;
value_min = min_value;
value_max = max_value;
};
void Parameter::setValue(double new_value){
/* Set the value of the parameter. TODO: check limits value_min/max
Input
-----
new_value : double
The new value to be set.
*/
value = new_value;
};
double Parameter::getValue(){
/* Return the value of the parameter.
Output
-----
value : double
The value of the parameter.
*/
return value;
};
Node::Node(CKTcircuit * ckt, NGSpiceModel * model , char * name){
/* Node constructor.
Output
-----
ckt : CKTcircuit *
The circuit in which the node shall be allocated.
model : NGSpiceModel *
The model that contains the node.
name : char *
The name of the node.
*/
int error = 0;
CKTnode *tmp;
ckt = ckt;
name = name;
//allocate the node
error = CKTmkVolt(ckt,&tmp, (char*)model->name, name);
//if(error) return(error); //why should there be an error?
id = tmp->number;
// what is the purpose of this?
// if (ckt->CKTcopyNodesets) {
// if (CKTinst2Node(ckt,here,2,&tmpNode,&tmpName)==OK) {
// if (tmpNode->nsGiven) {
// tmp->nodeset=tmpNode->nodeset;
// tmp->nsGiven=tmpNode->nsGiven;
// }
// }
// }
};
double Node::getPotential(){
/* Return the potential of the node from the RHSold.
*/
return *(ckt->CKTrhsOld+id);
};
Branch::Branch(Node * node_from,Node * node_to,std::vector<Node*> depends){
node_from = node_from;
node_to = node_to;
branch_dependencies = depends;
};
double inf = std::numeric_limits<double>::infinity();
HICUML2::HICUML2(){

View File

@ -5,7 +5,13 @@
//for the time beeing, HICUM is the first model to use this.
#ifdef __cplusplus
#include <unordered_map>
#include <vector>
#include <limits>
extern "C" {
#include "ngspice/cktdefs.h"
}
class NGSpiceModel;
class Parameter
{
@ -17,18 +23,44 @@ class Parameter
Parameter(double value_default, double min_value, double max_value);
void setValue(double new_value);
double getValue();
double getValue(); // -> maybe with operator overloading
};
class Node
{
public:
int id;
char * name;
CKTcircuit * ckt; //pointer to the circuit in which the node resides
double getPotential();
Node(CKTcircuit * ckt, NGSpiceModel * model, char * name);
};
class Branch
{
//A branch specifies a current that flows from node_from to node_to
public:
double value; //the current of the branch
std::unordered_map<int, double> derivatives; //a map whose keys are node ids and the value is the derivative with that node
std::vector<Node*> branch_dependencies; //all nodes for which a derivative is defined
Node * node_from; //the node where the current originates
Node * node_to; //the node where the current is flowing to
Branch(Node * node_from, Node * node_to, std::vector<Node*> depends);
};
class NGSpiceModel
{
public:
std::unordered_map<const char *, Parameter> modelcard; //the modelcard of the model
std::vector<Node> nodes; //the nodes of the model
std::vector<Branch> branches; //the branches of the model
const char * name = "None"; //the branches of the model
};
class HICUML2 : public NGSpiceModel
{
public:
const char * name = "hl2";
HICUML2();
};
#endif