2024-08-18 16:17:00 +08:00
|
|
|
#ifndef DEVICES_HPP
|
|
|
|
|
#define DEVICES_HPP
|
|
|
|
|
|
2024-08-18 23:26:08 +08:00
|
|
|
#include <cmath>
|
|
|
|
|
#include <iostream>
|
2024-08-18 16:17:00 +08:00
|
|
|
|
|
|
|
|
struct Resistor
|
|
|
|
|
{
|
|
|
|
|
int node1, node2;
|
|
|
|
|
double resistance;
|
|
|
|
|
Resistor(int n1, int n2, double r)
|
|
|
|
|
: node1(n1), node2(n2), resistance(r) {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct CurrentSource
|
|
|
|
|
{
|
|
|
|
|
int node1, node2;
|
|
|
|
|
double current;
|
|
|
|
|
CurrentSource(int n1, int n2, double c)
|
|
|
|
|
: node1(n1), node2(n2), current(c) {}
|
|
|
|
|
};
|
|
|
|
|
struct Capacitor
|
|
|
|
|
{
|
|
|
|
|
int node1, node2;
|
|
|
|
|
double capacitance;
|
|
|
|
|
double voltage;
|
|
|
|
|
double last_rhs;
|
|
|
|
|
Capacitor(int n1, int n2, double c, double v, double last_rhs)
|
|
|
|
|
: node1(n1), node2(n2), capacitance(c), voltage(v), last_rhs(last_rhs) {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Inductor
|
|
|
|
|
{
|
|
|
|
|
int node1, node2;
|
|
|
|
|
double inductance;
|
|
|
|
|
double current;
|
|
|
|
|
double last_rhs;
|
|
|
|
|
Inductor(int n1, int n2, double l, double i, double last_rhs)
|
|
|
|
|
: node1(n1), node2(n2), inductance(l), current(i), last_rhs(last_rhs) {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct VoltageSource
|
|
|
|
|
{
|
|
|
|
|
int nodePos;
|
|
|
|
|
int nodeNeg;
|
|
|
|
|
double voltage;
|
|
|
|
|
double last_voltage;
|
2024-08-18 23:26:08 +08:00
|
|
|
std::string votage_cal;
|
2024-08-18 16:17:00 +08:00
|
|
|
|
2024-08-18 23:26:08 +08:00
|
|
|
VoltageSource(int pos, int neg, double v, std::string votage_cal)
|
|
|
|
|
: nodePos(pos), nodeNeg(neg), voltage(v), last_voltage(v), votage_cal(votage_cal) {}
|
2024-08-18 16:17:00 +08:00
|
|
|
};
|
2024-08-18 23:26:08 +08:00
|
|
|
double get_voltage(VoltageSource voltage, double time);
|
2024-08-18 16:17:00 +08:00
|
|
|
|
|
|
|
|
struct VCCS
|
|
|
|
|
{
|
|
|
|
|
int controlNodePos;
|
|
|
|
|
int controlNodeNeg;
|
|
|
|
|
int outputNodePos;
|
|
|
|
|
int outputNodeNeg;
|
|
|
|
|
double transconductance;
|
|
|
|
|
|
|
|
|
|
VCCS(int cnPos, int cnNeg, int onPos, int onNeg, double gm)
|
|
|
|
|
: controlNodePos(cnPos), controlNodeNeg(cnNeg), outputNodePos(onPos), outputNodeNeg(onNeg), transconductance(gm) {}
|
|
|
|
|
};
|
|
|
|
|
|
2024-08-18 23:26:08 +08:00
|
|
|
struct VCR
|
|
|
|
|
{
|
|
|
|
|
int controlNodePos;
|
|
|
|
|
int controlNodeNeg;
|
|
|
|
|
int outputNodePos;
|
|
|
|
|
int outputNodeNeg;
|
|
|
|
|
double transresistance;
|
|
|
|
|
std::string vcr_cal;
|
|
|
|
|
VCR(int cnPos, int cnNeg, int onPos, int onNeg, double rm, std::string vcr_cal)
|
|
|
|
|
: controlNodePos(cnPos), controlNodeNeg(cnNeg), outputNodePos(onPos), outputNodeNeg(onNeg), transresistance(rm),vcr_cal(vcr_cal) {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
double get_vcr_G(VCR vcr, double U);
|
|
|
|
|
|
2024-08-18 16:17:00 +08:00
|
|
|
struct VCVS
|
|
|
|
|
{
|
|
|
|
|
int controlNodePos;
|
|
|
|
|
int controlNodeNeg;
|
|
|
|
|
int outputNodePos;
|
|
|
|
|
int outputNodeNeg;
|
|
|
|
|
double gain;
|
|
|
|
|
|
|
|
|
|
VCVS(int cnPos, int cnNeg, int onPos, int onNeg, double g)
|
|
|
|
|
: controlNodePos(cnPos), controlNodeNeg(cnNeg), outputNodePos(onPos), outputNodeNeg(onNeg), gain(g) {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct CCCS
|
|
|
|
|
{
|
|
|
|
|
int controlNodePos;
|
|
|
|
|
int controlNodeNeg;
|
|
|
|
|
int outputNodePos;
|
|
|
|
|
int outputNodeNeg;
|
|
|
|
|
double gain;
|
|
|
|
|
double voltage;
|
|
|
|
|
|
2024-08-18 23:26:08 +08:00
|
|
|
CCCS(int cnPos, int cnNeg, int onPos, int onNeg, double g, double v)
|
|
|
|
|
: controlNodePos(cnPos), controlNodeNeg(cnNeg), outputNodePos(onPos), outputNodeNeg(onNeg), gain(g), voltage(v) {}
|
2024-08-18 16:17:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct CCVS
|
|
|
|
|
{
|
|
|
|
|
int controlNodePos;
|
|
|
|
|
int controlNodeNeg;
|
|
|
|
|
int outputNodePos;
|
|
|
|
|
int outputNodeNeg;
|
|
|
|
|
double gain;
|
|
|
|
|
double voltage;
|
|
|
|
|
|
|
|
|
|
CCVS(int cnPos, int cnNeg, int onPos, int onNeg, double g, double v)
|
2024-08-18 23:26:08 +08:00
|
|
|
: controlNodePos(cnPos), controlNodeNeg(cnNeg), outputNodePos(onPos), outputNodeNeg(onNeg), gain(g), voltage(v) {}
|
2024-08-18 16:17:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Diode
|
|
|
|
|
{
|
|
|
|
|
int nodeP;
|
|
|
|
|
int nodeN;
|
|
|
|
|
double Is;
|
|
|
|
|
double n;
|
|
|
|
|
Diode(int p, int n, double Is_, double n_) : nodeP(p), nodeN(n), Is(Is_), n(n_) {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum MosType
|
|
|
|
|
{
|
|
|
|
|
NMOS,
|
|
|
|
|
PMOS
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Mosfet
|
|
|
|
|
{
|
|
|
|
|
int gate;
|
|
|
|
|
int source;
|
|
|
|
|
int drain;
|
|
|
|
|
double Vth;
|
|
|
|
|
double K;
|
|
|
|
|
MosType type;
|
|
|
|
|
|
|
|
|
|
Mosfet(int g, int s, int d, double Vth_, double K_, MosType type_)
|
|
|
|
|
: gate(g), source(s), drain(d), Vth(Vth_), K(K_), type(type_) {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // DEVICES_HPP
|